From ae9eb607a9d70b1e716a9cfe6ff805e51b6ab068 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 6 Mar 2019 23:27:48 +1100 Subject: [PATCH] use const in a few more places, reduce some compiler warnings --- src/LScreens.h | 2 ++ src/LWeb.h | 2 ++ src/LWidgets.h | 2 ++ src/Launcher.h | 2 ++ src/Platform.c | 20 ++++++++++++-------- src/Program.c | 7 +++++++ src/Resources.h | 3 ++- src/String.c | 6 +++--- src/String.h | 6 +++--- 9 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/LScreens.h b/src/LScreens.h index d2640f742..dab0a105a 100644 --- a/src/LScreens.h +++ b/src/LScreens.h @@ -11,6 +11,7 @@ struct LScreen; typedef void (*LScreen_Func)(struct LScreen* s); typedef void(*LWidget_Func)(struct LScreen* s, struct LWidget* w); +#ifndef CC_BUILD_WEB #define LScreen_Layout \ LScreen_Func Init; /* Initialises widgets and other data. */ \ @@ -45,3 +46,4 @@ struct LScreen* ServersScreen_MakeInstance(void); struct LScreen* SettingsScreen_MakeInstance(void); struct LScreen* UpdatesScreen_MakeInstance(void); #endif +#endif diff --git a/src/LWeb.h b/src/LWeb.h index 749129461..51bffd8b4 100644 --- a/src/LWeb.h +++ b/src/LWeb.h @@ -9,6 +9,7 @@ struct JsonContext; typedef void (*JsonOnValue)(struct JsonContext* ctx, const String* v); typedef void (*JsonOnNew)(struct JsonContext* ctx); +#ifndef CC_BUILD_WEB /* State for parsing JSON text */ struct JsonContext { @@ -118,3 +119,4 @@ Bitmap* Flags_Get(const String* name); /* Frees all flag bitmaps. */ void Flags_Free(void); #endif +#endif diff --git a/src/LWidgets.h b/src/LWidgets.h index ad3fef00b..f94a2d0d2 100644 --- a/src/LWidgets.h +++ b/src/LWidgets.h @@ -7,6 +7,7 @@ Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 */ +#ifndef CC_BUILD_WEB struct LWidgetVTABLE { /* Called to draw contents of this widget */ void (*Draw)(void* widget); @@ -193,3 +194,4 @@ void LTable_Sort(struct LTable* table); /* If selected row is not visible, adjusts top row so it does show. */ void LTable_ShowSelected(struct LTable* table); #endif +#endif diff --git a/src/Launcher.h b/src/Launcher.h index b69ffb459..d1a8e5b7b 100644 --- a/src/Launcher.h +++ b/src/Launcher.h @@ -7,6 +7,7 @@ */ struct LScreen; +#ifndef CC_BUILD_WEB /* Currently active screen/menu. */ extern struct LScreen* Launcher_Screen; /* The area/region of the window that needs to be redrawn and presented to the screen. */ @@ -70,3 +71,4 @@ void Launcher_Run(void); /* Starts the game from the given arguments. */ bool Launcher_StartGame(const String* user, const String* mppass, const String* ip, const String* port, const String* server); #endif +#endif diff --git a/src/Platform.c b/src/Platform.c index 3256bec1d..d7f2c6c09 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -1236,25 +1236,22 @@ static void* FT_ReallocWrapper(FT_Memory memory, long cur_size, long new_size, v #define FONT_CACHE_FILE "fontscache.txt" static void Font_Init(void) { -#ifdef CC_BUILD_WIN +#if defined CC_BUILD_WIN const static String dirs[2] = { String_FromConst("C:/Windows/Fonts"), String_FromConst("C:/WINNT/Fonts") }; -#endif -#ifdef CC_BUILD_UNIX +#elif defined CC_BUILD_UNIX const static String dirs[2] = { String_FromConst("/usr/share/fonts"), String_FromConst("/usr/local/share/fonts") }; -#endif -#ifdef CC_BUILD_OSX +#elif defined CC_BUILD_OSX const static String dirs[2] = { String_FromConst("/System/Library/Fonts"), String_FromConst("/Library/Fonts") }; -#endif -#ifdef CC_BUILD_WEB +#elif defined CC_BUILD_WEB /* TODO: Implement fonts */ const static String dirs[1] = { String_FromConst("Fonts") }; #endif @@ -1304,10 +1301,15 @@ ReturnCode Socket_Available(SocketHandle socket, uint32_t* available) { return Socket_ioctl(socket, FIONREAD, available); } ReturnCode Socket_SetBlocking(SocketHandle socket, bool blocking) { +#ifdef CC_BUILD_WEB + return ReturnCode_NotSupported; /* sockets always async */ +#else int blocking_raw = blocking ? 0 : -1; return Socket_ioctl(socket, FIONBIO, &blocking_raw); +#endif } + ReturnCode Socket_GetError(SocketHandle socket, ReturnCode* result) { int resultSize = sizeof(ReturnCode); return getsockopt(socket, SOL_SOCKET, SO_ERROR, result, &resultSize); @@ -1341,7 +1343,9 @@ ReturnCode Socket_Close(SocketHandle socket) { ReturnCode res = 0; ReturnCode res1, res2; -#ifdef CC_BUILD_WIN +#if defined CC_BUILD_WEB + res1 = 0; +#elif defined CC_BUILD_WIN res1 = shutdown(socket, SD_BOTH); #else res1 = shutdown(socket, SHUT_RDWR); diff --git a/src/Program.c b/src/Program.c index 6bea9d11e..107cdff99 100644 --- a/src/Program.c +++ b/src/Program.c @@ -65,6 +65,7 @@ static void Program_RunGame(void) { /* Attempts to set current/working directory to the directory exe file is in */ static void Program_SetCurrentDirectory(void) { +#ifndef CC_BUILD_WEB String path; char pathBuffer[FILENAME_SIZE]; int i; ReturnCode res; @@ -79,6 +80,7 @@ static void Program_SetCurrentDirectory(void) { } res = Platform_SetCurrentDirectory(&path); if (res) { Logger_Warn(res, "setting current directory"); return; } +#endif } /* Terminates the program due to an invalid command line argument */ @@ -137,7 +139,12 @@ int main(int argc, char** argv) { /* argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4); */ if (argsCount == 0) { +#ifdef CC_BUILD_WEB + String_AppendConst(&Game_Username, "WebTest!"); + Program_RunGame(); +#else Launcher_Run(); +#endif } else if (argsCount == 1) { String_Copy(&Game_Username, &args[0]); Program_RunGame(); diff --git a/src/Resources.h b/src/Resources.h index 9620baeef..05dbf4ea5 100644 --- a/src/Resources.h +++ b/src/Resources.h @@ -10,6 +10,7 @@ #define FLAG_GUI 0x04 /* file depends on patched gui.png */ #define FLAG_TERRAIN 0x08 /* file depends on patched terrain.png */ +#ifndef CC_BUILD_WEB extern struct ResourceFile { const char* Name; const char* Url; @@ -64,5 +65,5 @@ void Fetcher_Run(void); /* Checks if any resources have finished downloading. */ /* If any have, performs required patching and saving. */ void Fetcher_Update(void); - +#endif #endif diff --git a/src/String.c b/src/String.c index 3e00ba1fe..00990d561 100644 --- a/src/String.c +++ b/src/String.c @@ -561,7 +561,7 @@ int Convert_UnicodeToUtf8(Codepoint cp, uint8_t* data) { } } -void Convert_DecodeUtf16(String* value, Codepoint* chars, int numBytes) { +void Convert_DecodeUtf16(String* value, const Codepoint* chars, int numBytes) { int i; char c; for (i = 0; i < (numBytes >> 1); i++) { @@ -569,7 +569,7 @@ void Convert_DecodeUtf16(String* value, Codepoint* chars, int numBytes) { } } -void Convert_DecodeUtf8(String* value, uint8_t* chars, int numBytes) { +void Convert_DecodeUtf8(String* value, const uint8_t* chars, int numBytes) { int len; Codepoint cp; char c; for (; numBytes > 0; numBytes -= len) { @@ -581,7 +581,7 @@ void Convert_DecodeUtf8(String* value, uint8_t* chars, int numBytes) { } } -void Convert_DecodeAscii(String* value, uint8_t* chars, int numBytes) { +void Convert_DecodeAscii(String* value, const uint8_t* chars, int numBytes) { int i; char c; for (i = 0; i < numBytes; i++) { diff --git a/src/String.h b/src/String.h index cfdf879f3..84182033f 100644 --- a/src/String.h +++ b/src/String.h @@ -171,13 +171,13 @@ int Convert_UnicodeToUtf8(Codepoint cp, uint8_t* data); /* Attempts to append all characters from UTF16 encoded data to the given string. */ /* Characters not in code page 437 are omitted. */ -void Convert_DecodeUtf16(String* str, Codepoint* chars, int numBytes); +void Convert_DecodeUtf16(String* str, const Codepoint* chars, int numBytes); /* Attempts to append all characters from UTF8 encoded data to the given string. */ /* Characters not in code page 437 are omitted. */ -void Convert_DecodeUtf8(String* str, uint8_t* chars, int numBytes); +void Convert_DecodeUtf8(String* str, const uint8_t* chars, int numBytes); /* Attempts to append all characters from ASCII encoded data to the given string. */ /* Characters not in code page 437 are omitted. */ -void Convert_DecodeAscii(String* str, uint8_t* chars, int numBytes); +void Convert_DecodeAscii(String* str, const uint8_t* chars, int numBytes); /* Attempts to convert the given string into an unsigned 8 bit integer. */ CC_API bool Convert_ParseUInt8(const String* str, uint8_t* value);