From 0dbe2342dc95b0133d812759b8927fbb6d956f06 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sat, 4 Feb 2023 11:55:37 +0800 Subject: [PATCH] Update code for macOS Fix CMake lib dependencies for crypto/SSL. Also ensure websockets work on macOS for both client and server. --- CMakeLists.txt | 44 +++++++++++++++++++++----------- src/packages/compat/IZ_windows.h | 8 ++++++ src/packages/config/IZ_config.c | 10 +++++--- src/packages/game/IZ_app_input.c | 18 ++++++++++--- src/packages/io/IZ_io.c | 10 +------- src/packages/io/IZ_io.h | 5 ++-- src/packages/midi/IZ_midi.c | 3 +-- src/packages/string/IZ_string.c | 22 ++++++++++++---- src/packages/string/IZ_string.h | 3 ++- 9 files changed, 81 insertions(+), 42 deletions(-) create mode 100644 src/packages/compat/IZ_windows.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 57ae3ab..600ce4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,7 +151,7 @@ add_executable( src/packages/string/IZ_string.h src/packages/io/IZ_io.c src/packages/io/IZ_io.h - src/packages/log/IZ_log.c src/packages/log/IZ_log.h src/packages/timer/IZ_timer.c src/packages/timer/IZ_timer.h) + src/packages/log/IZ_log.c src/packages/log/IZ_log.h src/packages/timer/IZ_timer.c src/packages/timer/IZ_timer.h src/packages/compat/IZ_windows.h) if (WIN32) target_link_libraries( @@ -173,9 +173,8 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") SDL2_image SDL2_ttf portmidi -# FIXME -# libcrypto -# libssl + crypto + ssl websockets ) endif() @@ -265,8 +264,8 @@ add_executable( dependencies/sqlite/sqlite3.c dependencies/minIni/dev/minIni.h dependencies/minIni/dev/minIni.c - src/packages/log/IZ_intercept.h - src/packages/log/IZ_intercept.c + src/packages/log/IZ_intercept.h + src/packages/log/IZ_intercept.c src/packages/server/main.c src/packages/server/IZ_app.c src/packages/server/IZ_app.h @@ -287,17 +286,32 @@ add_executable( src/packages/string/IZ_string.h src/packages/io/IZ_io.c src/packages/io/IZ_io.h - src/packages/log/IZ_log.c src/packages/log/IZ_log.h src/packages/timer/IZ_timer.c src/packages/timer/IZ_timer.h) - -target_link_libraries( - server - SDL2main - SDL2 - libcrypto - libssl - websockets + src/packages/log/IZ_log.c + src/packages/log/IZ_log.h + src/packages/timer/IZ_timer.c + src/packages/timer/IZ_timer.h ) +if (WIN32) + target_link_libraries( + server + SDL2main + SDL2 + libcrypto + libssl + websockets + ) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + target_link_libraries( + server + SDL2main + SDL2 + crypto + ssl + websockets + ) +endif() + add_executable( asset-inv dependencies/minIni/dev/minIni.h diff --git a/src/packages/compat/IZ_windows.h b/src/packages/compat/IZ_windows.h new file mode 100644 index 0000000..098c01e --- /dev/null +++ b/src/packages/compat/IZ_windows.h @@ -0,0 +1,8 @@ +#ifndef IZ_WINDOWS_H +#define IZ_WINDOWS_H + +#ifndef IZ_WIN64 +typedef int errno_t; +#endif + +#endif //IZ_WINDOWS_H diff --git a/src/packages/config/IZ_config.c b/src/packages/config/IZ_config.c index 3d1db27..7cd66f9 100644 --- a/src/packages/config/IZ_config.c +++ b/src/packages/config/IZ_config.c @@ -200,16 +200,18 @@ void IZ_ConfigLoadGuid(IZ_ConfigItem* item, const char* config_path) { default_value = *((SDL_GUID *) item->default_value); } - char buffer[128]; + char buffer[33]; if (item->transformer.deserialize && item->transformer.serialize) { IZ_ConfigDeserializeGUID* deserialize = item->transformer.deserialize; IZ_ConfigSerializeGUID* serialize = item->transformer.serialize; - const char serialized_default_value[128]; + const char serialized_default_value[33]; serialize(default_value, serialized_default_value); - ini_gets(item->section, item->key, serialized_default_value, buffer, 128, config_path); + ini_gets(item->section, item->key, serialized_default_value, buffer, 33, config_path); raw_value = deserialize(buffer); } else { - ini_gets(item->section, item->key, "00000000000000000000000000000000", buffer, 128, config_path); + char guid_string_default_value[33]; + SDL_GUIDToString(default_value, guid_string_default_value, 33); + ini_gets(item->section, item->key, guid_string_default_value, buffer, 33, config_path); raw_value = SDL_GUIDFromString(buffer); } IZ_ConfigEnsureValidGuid(item, raw_value, default_value); diff --git a/src/packages/game/IZ_app_input.c b/src/packages/game/IZ_app_input.c index b00e26c..f193920 100644 --- a/src/packages/game/IZ_app_input.c +++ b/src/packages/game/IZ_app_input.c @@ -1,5 +1,15 @@ #include "IZ_app_input.h" +#ifdef IZ_WIN64 + #define IZ_DEBUG_CONNECT SDLK_PAGEUP + #define IZ_DEBUG_DISCONNECT SDLK_PAGEDOWN + #define IZ_DEBUG_SEND_MESSAGE SDLK_INSERT +#elif IZ_MACOS + #define IZ_DEBUG_CONNECT SDLK_EQUALS + #define IZ_DEBUG_DISCONNECT SDLK_MINUS + #define IZ_DEBUG_SEND_MESSAGE SDLK_BACKSLASH +#endif + IZ_ProcedureResult IZ_AppHandleSDLEvents(struct IZ_App* app) { SDL_Event e; IZ_InputState* input_state = IZ_AppGetInputState(app); @@ -10,8 +20,9 @@ IZ_ProcedureResult IZ_AppHandleSDLEvents(struct IZ_App* app) { return 1; } +#ifdef IZ_DEBUG if (e.type == SDL_KEYDOWN) { - if (e.key.keysym.sym == SDLK_PAGEUP) { + if (e.key.keysym.sym == IZ_DEBUG_CONNECT) { IZ_NetClientConnect( net_state, (IZ_WSClientInitializeParams) { @@ -20,12 +31,13 @@ IZ_ProcedureResult IZ_AppHandleSDLEvents(struct IZ_App* app) { .port = 42069, } ); - } else if (e.key.keysym.sym == SDLK_PAGEDOWN) { + } else if (e.key.keysym.sym == IZ_DEBUG_DISCONNECT) { IZ_NetClientDisconnect(net_state); - } else if (e.key.keysym.sym == SDLK_INSERT) { + } else if (e.key.keysym.sym == IZ_DEBUG_SEND_MESSAGE) { IZ_NetClientSendTextMessage(net_state, "hello", 5); } } +#endif IZ_InputHandleSDLEvents(input_state, e); } diff --git a/src/packages/io/IZ_io.c b/src/packages/io/IZ_io.c index 5e612ac..9d4763b 100644 --- a/src/packages/io/IZ_io.c +++ b/src/packages/io/IZ_io.c @@ -16,7 +16,7 @@ int IZ_sprintf(char* buffer, size_t buffer_size, const char* format, ...) { #endif } -errno_t IZ_fopen(struct _iobuf** file, const char* filename, const char* mode) { +errno_t IZ_fopen(FILE** file, const char* filename, const char* mode) { #if defined IZ_WIN64 return fopen_s(file, filename, mode); #else @@ -24,11 +24,3 @@ errno_t IZ_fopen(struct _iobuf** file, const char* filename, const char* mode) { return *file == NULL ? 1 : 0; #endif } - -errno_t IZ_vsprintf(char* buffer, size_t buffer_size, const char* format, va_list args) { -#if defined IZ_WIN64 - return vsprintf_s(buffer, buffer_size, format, args); -#else - return vsprintf(buffer, format, args); -#endif -} diff --git a/src/packages/io/IZ_io.h b/src/packages/io/IZ_io.h index 3780a13..8ac0777 100644 --- a/src/packages/io/IZ_io.h +++ b/src/packages/io/IZ_io.h @@ -3,11 +3,10 @@ #include #include +#include "../compat/IZ_windows.h" int IZ_sprintf(char*, size_t, const char*, ...); -errno_t IZ_fopen(struct _iobuf**, const char*, const char*); - -errno_t IZ_vsprintf(char* buffer, size_t buffer_size, const char* format, va_list); +errno_t IZ_fopen(FILE**, const char*, const char*); #endif diff --git a/src/packages/midi/IZ_midi.c b/src/packages/midi/IZ_midi.c index b61398f..06f596f 100644 --- a/src/packages/midi/IZ_midi.c +++ b/src/packages/midi/IZ_midi.c @@ -25,8 +25,7 @@ char* IZ_MIDIGetNoteName(unsigned char midi_note) { unsigned char IZ_MIDIGetNoteFromName(const char* name) { char name_copy[8]; - IZ_memcpy(name_copy, 8, name, 8); - IZ_strlwr(name_copy, 8); + IZ_strlwr(name_copy, name, 8); unsigned char octave; const char base_pitch_name[] = "c d ef g a b"; diff --git a/src/packages/string/IZ_string.c b/src/packages/string/IZ_string.c index 1f4ff76..4642e1c 100644 --- a/src/packages/string/IZ_string.c +++ b/src/packages/string/IZ_string.c @@ -4,7 +4,8 @@ errno_t IZ_memcpy(void* const dest, const rsize_t dest_size, const void* const s #if defined IZ_WIN64 return memcpy_s(dest, dest_size, source, source_size); #else - return memcpy(dest, source, dest_size - 1); + memcpy(dest, source, dest_size); + return 0; #endif } @@ -12,15 +13,26 @@ errno_t IZ_strcat(char* dest, rsize_t source_size, const char* source) { #if defined IZ_WIN64 return strcat_s(dest, source_size, source); #else - return strcat(dest, source); + strcat(dest, source); + return 0; #endif } -errno_t IZ_strlwr(char* str, rsize_t str_size) { +errno_t IZ_strlwr(char* dest, const char* str, rsize_t str_size) { #if defined IZ_WIN64 - return _strlwr_s(str, str_size); + errno_t copy_result = memcpy_s(dest, str_size, str, str_size); + if (copy_result) { + return copy_result; + } + return _strlwr_s(dest, str_size); #else - return _strlwr(str); + memcpy(dest, str, str_size -1); + for (unsigned int i = 0; i < str_size; i += 1) { + if ('A' <= dest[i] && dest[i] <= 'Z') { + dest[i] += 0x20; + } + } + return 0; #endif } diff --git a/src/packages/string/IZ_string.h b/src/packages/string/IZ_string.h index 975b33a..04f7bba 100644 --- a/src/packages/string/IZ_string.h +++ b/src/packages/string/IZ_string.h @@ -2,12 +2,13 @@ #define IZ_STRING_H #include +#include "../compat/IZ_windows.h" errno_t IZ_memcpy(void*, rsize_t, const void*, rsize_t); errno_t IZ_strcat(char*, rsize_t, const char*); -errno_t IZ_strlwr(char*, rsize_t); +errno_t IZ_strlwr(char*, const char*, rsize_t); void* IZ_memset(void*, int, rsize_t);