From fb16492ac8b49cdb6949493e441874d06ce9c791 Mon Sep 17 00:00:00 2001 From: Matthew Kilgore Date: Tue, 13 Feb 2024 01:07:07 -0500 Subject: [PATCH] Move more date/time functions --- internal/c/libqb.cpp | 121 --------------------------- internal/c/libqb/include/datetime.h | 9 ++ internal/c/libqb/src/datetime.cpp | 123 ++++++++++++++++++++++++++++ internal/c/qbx.cpp | 4 - 4 files changed, 132 insertions(+), 125 deletions(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index bc9ab1c06..4811d4e3a 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -17519,127 +17519,6 @@ void sub_graphics_put(float x1f, float y1f, void *element, int32 option, uint32 */ } -void sub_date(qbs *date) { - if (is_error_pending()) - return; - return; // stub -} - -qbs *func_date() { - // mm-dd-yyyy - // 0123456789 - static time_t qb64_tm_val; - static tm *qb64_tm; - // struct tm { - // int tm_sec; /* seconds after the minute - [0,59] */ - // int tm_min; /* minutes after the hour - [0,59] */ - // int tm_hour; /* hours since midnight - [0,23] */ - // int tm_mday; /* day of the month - [1,31] */ - // int tm_mon; /* months since January - [0,11] */ - // int tm_year; /* years since 1900 */ - // int tm_wday; /* days since Sunday - [0,6] */ - // int tm_yday; /* days since January 1 - [0,365] */ - // int tm_isdst; /* daylight savings time flag */ - // }; - static int32 x, x2, i; - static qbs *str; - str = qbs_new(10, 1); - str->chr[2] = 45; - str->chr[5] = 45; //- - time(&qb64_tm_val); - if (qb64_tm_val == -1) { - error(5); - str->len = 0; - return str; - } - qb64_tm = localtime(&qb64_tm_val); - if (qb64_tm == NULL) { - error(5); - str->len = 0; - return str; - } - x = qb64_tm->tm_mon; - x++; - i = 0; - str->chr[i] = x / 10 + 48; - str->chr[i + 1] = x % 10 + 48; - x = qb64_tm->tm_mday; - i = 3; - str->chr[i] = x / 10 + 48; - str->chr[i + 1] = x % 10 + 48; - x = qb64_tm->tm_year; - x += 1900; - i = 6; - x2 = x / 1000; - x = x - x2 * 1000; - str->chr[i] = x2 + 48; - i++; - x2 = x / 100; - x = x - x2 * 100; - str->chr[i] = x2 + 48; - i++; - x2 = x / 10; - x = x - x2 * 10; - str->chr[i] = x2 + 48; - i++; - str->chr[i] = x + 48; - return str; -} - -void sub_time(qbs *str) { - if (is_error_pending()) - return; - return; // stub -} - -qbs *func_time() { - // 23:59:59 (hh:mm:ss) - // 01234567 - static time_t qb64_tm_val; - static tm *qb64_tm; - // struct tm { - // int tm_sec; /* seconds after the minute - [0,59] */ - // int tm_min; /* minutes after the hour - [0,59] */ - // int tm_hour; /* hours since midnight - [0,23] */ - // int tm_mday; /* day of the month - [1,31] */ - // int tm_mon; /* months since January - [0,11] */ - // int tm_year; /* years since 1900 */ - // int tm_wday; /* days since Sunday - [0,6] */ - // int tm_yday; /* days since January 1 - [0,365] */ - // int tm_isdst; /* daylight savings time flag */ - // }; - static int32 x, x2, i; - static qbs *str; - str = qbs_new(8, 1); - str->chr[2] = 58; - str->chr[5] = 58; //: - time(&qb64_tm_val); - if (qb64_tm_val == -1) { - error(5); - str->len = 0; - return str; - } - qb64_tm = localtime(&qb64_tm_val); - if (qb64_tm == NULL) { - error(5); - str->len = 0; - return str; - } - x = qb64_tm->tm_hour; - i = 0; - str->chr[i] = x / 10 + 48; - str->chr[i + 1] = x % 10 + 48; - x = qb64_tm->tm_min; - i = 3; - str->chr[i] = x / 10 + 48; - str->chr[i + 1] = x % 10 + 48; - x = qb64_tm->tm_sec; - i = 6; - str->chr[i] = x / 10 + 48; - str->chr[i + 1] = x % 10 + 48; - return str; -} - int32 func_csrlin() { #ifdef QB64_WINDOWS // Windows console CSRLIN support if (write_page->console) { diff --git a/internal/c/libqb/include/datetime.h b/internal/c/libqb/include/datetime.h index ca7302213..b4c4a6c9e 100644 --- a/internal/c/libqb/include/datetime.h +++ b/internal/c/libqb/include/datetime.h @@ -1,6 +1,9 @@ #ifndef INCLUDE_LIBQB_DATETIME_H #define INCLUDE_LIBQB_DATETIME_H +#include +#include "qbs.h" + int64_t GetTicks(); double func_timer(double accuracy, int32_t passed); @@ -12,4 +15,10 @@ void sub__limit(double fps); void Sleep(uint32_t milliseconds); #endif +qbs *func_time(); +void sub_time(qbs *str); + +qbs *func_date(); +void sub_date(qbs *date); + #endif diff --git a/internal/c/libqb/src/datetime.cpp b/internal/c/libqb/src/datetime.cpp index 18e9f0b4e..f7ca516de 100644 --- a/internal/c/libqb/src/datetime.cpp +++ b/internal/c/libqb/src/datetime.cpp @@ -10,6 +10,8 @@ #include "rounding.h" #include "event.h" +#include "error_handle.h" +#include "qbs.h" #include "datetime.h" #ifdef QB64_MACOSX @@ -194,3 +196,124 @@ recalculate: prev = now; } +void sub_date(qbs *date) { + if (is_error_pending()) + return; + return; // stub +} + +qbs *func_date() { + // mm-dd-yyyy + // 0123456789 + static time_t qb64_tm_val; + static tm *qb64_tm; + // struct tm { + // int tm_sec; /* seconds after the minute - [0,59] */ + // int tm_min; /* minutes after the hour - [0,59] */ + // int tm_hour; /* hours since midnight - [0,23] */ + // int tm_mday; /* day of the month - [1,31] */ + // int tm_mon; /* months since January - [0,11] */ + // int tm_year; /* years since 1900 */ + // int tm_wday; /* days since Sunday - [0,6] */ + // int tm_yday; /* days since January 1 - [0,365] */ + // int tm_isdst; /* daylight savings time flag */ + // }; + static int32_t x, x2, i; + static qbs *str; + str = qbs_new(10, 1); + str->chr[2] = 45; + str->chr[5] = 45; //- + time(&qb64_tm_val); + if (qb64_tm_val == -1) { + error(5); + str->len = 0; + return str; + } + qb64_tm = localtime(&qb64_tm_val); + if (qb64_tm == NULL) { + error(5); + str->len = 0; + return str; + } + x = qb64_tm->tm_mon; + x++; + i = 0; + str->chr[i] = x / 10 + 48; + str->chr[i + 1] = x % 10 + 48; + x = qb64_tm->tm_mday; + i = 3; + str->chr[i] = x / 10 + 48; + str->chr[i + 1] = x % 10 + 48; + x = qb64_tm->tm_year; + x += 1900; + i = 6; + x2 = x / 1000; + x = x - x2 * 1000; + str->chr[i] = x2 + 48; + i++; + x2 = x / 100; + x = x - x2 * 100; + str->chr[i] = x2 + 48; + i++; + x2 = x / 10; + x = x - x2 * 10; + str->chr[i] = x2 + 48; + i++; + str->chr[i] = x + 48; + return str; +} + +void sub_time(qbs *str) { + if (is_error_pending()) + return; + return; // stub +} + +qbs *func_time() { + // 23:59:59 (hh:mm:ss) + // 01234567 + static time_t qb64_tm_val; + static tm *qb64_tm; + // struct tm { + // int tm_sec; /* seconds after the minute - [0,59] */ + // int tm_min; /* minutes after the hour - [0,59] */ + // int tm_hour; /* hours since midnight - [0,23] */ + // int tm_mday; /* day of the month - [1,31] */ + // int tm_mon; /* months since January - [0,11] */ + // int tm_year; /* years since 1900 */ + // int tm_wday; /* days since Sunday - [0,6] */ + // int tm_yday; /* days since January 1 - [0,365] */ + // int tm_isdst; /* daylight savings time flag */ + // }; + static int32_t x, x2, i; + static qbs *str; + str = qbs_new(8, 1); + str->chr[2] = 58; + str->chr[5] = 58; //: + time(&qb64_tm_val); + if (qb64_tm_val == -1) { + error(5); + str->len = 0; + return str; + } + qb64_tm = localtime(&qb64_tm_val); + if (qb64_tm == NULL) { + error(5); + str->len = 0; + return str; + } + x = qb64_tm->tm_hour; + i = 0; + str->chr[i] = x / 10 + 48; + str->chr[i + 1] = x % 10 + 48; + x = qb64_tm->tm_min; + i = 3; + str->chr[i] = x / 10 + 48; + str->chr[i + 1] = x % 10 + 48; + x = qb64_tm->tm_sec; + i = 6; + str->chr[i] = x / 10 + 48; + str->chr[i + 1] = x % 10 + 48; + return str; +} + diff --git a/internal/c/qbx.cpp b/internal/c/qbx.cpp index cbe3acec5..ceb1a5efa 100755 --- a/internal/c/qbx.cpp +++ b/internal/c/qbx.cpp @@ -370,10 +370,6 @@ extern void sub_graphics_get(float x1f, float y1f, float x2f, float y2f, void *element, uint32 mask, int32 passed); extern void sub_graphics_put(float x1f, float y1f, void *element, int32 option, uint32 mask, int32 passed); -extern void sub_date(qbs *date); -extern qbs *func_date(); -extern void sub_time(qbs *str); -extern qbs *func_time(); extern int32 func_csrlin(); extern int32 func_pos(int32 ignore); extern double func_log(double value);