From 2eb1bbdfd9019e409d2d796ca289aa63e9db326b Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sun, 14 Jan 2024 17:18:58 +0100 Subject: [PATCH] Extend User IO, OS_GetDate for linux --- build_tool/main.cpp | 4 ++-- core_library/filesystem.c | 12 +++++++++++- core_library/filesystem.h | 1 - standalone_libraries/io.c | 11 +++++------ standalone_libraries/io.h | 12 +++++++++--- standalone_libraries/preproc_env.h | 10 ++++++++++ 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/build_tool/main.cpp b/build_tool/main.cpp index 741da19..df036b6 100644 --- a/build_tool/main.cpp +++ b/build_tool/main.cpp @@ -33,7 +33,7 @@ int main(int argument_count, char **arguments) { } if (build_file.str == 0) { - IO_Printf("IDLE Nothing to do, couldnt find build file in current dir: %.*s, exiting ... \n", S8_Expand(working_dir)); + IO_Printf("Couldnt find build file in current dir: %.*s, exiting ... \n", S8_Expand(working_dir)); return 0; } } @@ -69,7 +69,7 @@ int main(int argument_count, char **arguments) { if (build_file.str) { int result = OS_SystemF(IF_WINDOWS_ELSE("", "./") "%.*s %.*s", S8_Expand(exe_name), S8_Expand(cmdline_args)); if (result != 0) { - printf("FAILED execution of the build file!\n"); + IO_Printf("FAILED execution of the build file!\n"); return 1; } } diff --git a/core_library/filesystem.c b/core_library/filesystem.c index 628fff3..4030c96 100644 --- a/core_library/filesystem.c +++ b/core_library/filesystem.c @@ -375,7 +375,7 @@ OS_API OS_Date OS_GetDate(void) { result.day = local.wDay; result.hour = local.wHour; result.second = local.wSecond; - result.milliseconds = local.wMilliseconds; + // result.milliseconds = local.wMilliseconds; return result; } @@ -557,7 +557,17 @@ OS_API int64_t OS_GetFileModTime(S8_String file) { } OS_API OS_Date OS_GetDate(void) { + time_t t = time(NULL); + struct tm date = *localtime(&t); + OS_Date s = {0}; + s.second = date.tm_sec; + s.year = date.tm_year; + s.month = date.tm_mon; + s.day = date.tm_mday; + s.hour = date.tm_hour; + s.minute = date.tm_min; + return s; } diff --git a/core_library/filesystem.h b/core_library/filesystem.h index a894443..b1c158a 100644 --- a/core_library/filesystem.h +++ b/core_library/filesystem.h @@ -25,7 +25,6 @@ struct OS_Date { uint32_t hour; uint32_t minute; uint32_t second; - uint32_t milliseconds; }; typedef struct OS_FileIter OS_FileIter; diff --git a/standalone_libraries/io.c b/standalone_libraries/io.c index 043601b..9a97f03 100644 --- a/standalone_libraries/io.c +++ b/standalone_libraries/io.c @@ -31,7 +31,7 @@ IO_StaticFunc int IO_Strlen(char *string) { return len; } -void (*IO_User_OutputMessage)(char *str, int len); +void (*IO_User_OutputMessage)(int kind, char *file, int line, char *str, int len); IO_API bool IO__FatalErrorf(const char *file, int line, const char *msg, ...) { va_list args1; @@ -83,7 +83,7 @@ IO_API bool IO__FatalErrorf(const char *file, int line, const char *msg, ...) { return ret == IO_ErrorResult_Break; } -IO_API void IO_Printf(const char *msg, ...) { +IO_API void IO__Printf(int kind, char *file, int line, const char *msg, ...) { // First try to use a static buffer. That can fail because the message // can be bigger then the buffer. Allocate enough memory to fit in that // case. @@ -107,7 +107,7 @@ IO_API void IO_Printf(const char *msg, ...) { va_end(args1); if (IO_User_OutputMessage) { - IO_User_OutputMessage(result, size); + IO_User_OutputMessage(kind, file, line, result, size); } else { IO_OutputMessage(result, size); @@ -127,10 +127,9 @@ IO_API bool IO__FatalError(char *msg) { return result == IO_ErrorResult_Break; } -IO_API void IO_Print(char *msg) { - int len = IO_Strlen(msg); +IO_API void IO_Print(int kind, char *file, int line, char *msg, int len) { if (IO_User_OutputMessage) { - IO_User_OutputMessage(msg, len); + IO_User_OutputMessage(kind, file, line, msg, len); } else { IO_OutputMessage(msg, len); diff --git a/standalone_libraries/io.h b/standalone_libraries/io.h index a328911..d38def7 100644 --- a/standalone_libraries/io.h +++ b/standalone_libraries/io.h @@ -31,7 +31,7 @@ typedef enum IO_ErrorResult { #define IO__PrintfFormat(fmt, va) #endif -extern void (*IO_User_OutputMessage)(char *str, int len); +extern void (*IO_User_OutputMessage)(int kind, char *file, int line, char *str, int len); #define IO__STRINGIFY(x) #x #define IO__TOSTRING(x) IO__STRINGIFY(x) @@ -74,10 +74,16 @@ extern void (*IO_User_OutputMessage)(char *str, int len); #define IO_Todo() IO_FatalError("This codepath is not implemented yet") IO_API bool IO__FatalErrorf(const char *file, int line, const char *msg, ...) IO__PrintfFormat(3, 4); -IO_API void IO_Printf(const char *msg, ...) IO__PrintfFormat(1, 2); +IO_API void IO__Printf(int kind, char *file, int line, const char *msg, ...) IO__PrintfFormat(4, 5); IO_API bool IO__FatalError(char *msg); -IO_API void IO_Print(char *msg); +IO_API void IO_Print(int kind, char *file, int line, char *msg, int len); IO_API void IO_OutputMessage(char *str, int len); IO_API IO_ErrorResult IO_OutputError(char *str, int len); IO_API void IO_Exit(int error_code); IO_API bool IO_IsDebuggerPresent(void); + +const int IO_KindPrintf = 1; +const int IO_KindWarningf = 2; + +#define IO_Printf(...) IO__Printf(IO_KindPrintf, __FILE__, __LINE__, __VA_ARGS__) +#define IO_Warningf(...) IO__Printf(IO_KindWarningf, __FILE__, __LINE__, __VA_ARGS__) \ No newline at end of file diff --git a/standalone_libraries/preproc_env.h b/standalone_libraries/preproc_env.h index 7b12e94..175d952 100644 --- a/standalone_libraries/preproc_env.h +++ b/standalone_libraries/preproc_env.h @@ -102,6 +102,16 @@ #define IF_LINUX_ELSE(x, y) y #endif +#if OS_WINDOWS + #define OS_NAME "Windows" +#elif OS_LINUX + #define OS_NAME "Linux" +#elif OS_MAC + #define OS_NAME "MacOS" +#else + #error couldn't figure out OS +#endif + // #if COMPILER_CLANG // #pragma clang diagnostic push // #pragma clang diagnostic ignored "-Wmicrosoft-enum-forward-reference"