From b69ba4af7b926f42669d4db88b60d367b055589a Mon Sep 17 00:00:00 2001 From: CommonLoon102 Date: Tue, 20 Apr 2021 10:59:38 +0200 Subject: [PATCH] removed 'inih' dependency --- .gitmodules | 4 ---- 3p/inih | 1 - Makefile | 4 ++-- main.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 44 insertions(+), 13 deletions(-) delete mode 160000 3p/inih diff --git a/.gitmodules b/.gitmodules index 8b2eb2e..2dedfa5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,3 @@ -[submodule "3p/inih"] - path = 3p/inih - url = https://github.com/benhoyt/inih.git - ignore = dirty [submodule "3p/libxbr-standalone"] path = 3p/libxbr-standalone url = https://github.com/Treeki/libxbr-standalone.git diff --git a/3p/inih b/3p/inih deleted file mode 160000 index 75fe6b1..0000000 --- a/3p/inih +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 75fe6b1a03d99a9728b9924f9af30729e51357c2 diff --git a/Makefile b/Makefile index a2eb586..3c3ba0a 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,8 @@ SRCS = andy.cpp benchmark.cpp fileio.cpp fs_posix.cpp game.cpp \ SCALERS := scaler_nearest.cpp scaler_xbr.cpp -OBJS = $(SRCS:.cpp=.o) $(SCALERS:.cpp=.o) 3p/inih/ini.o 3p/libxbr-standalone/xbr.o -DEPS = $(SRCS:.cpp=.d) $(SCALERS:.cpp=.d) 3p/inih/ini.d 3p/libxbr-standalone/xbr.d +OBJS = $(SRCS:.cpp=.o) $(SCALERS:.cpp=.o) 3p/libxbr-standalone/xbr.o +DEPS = $(SRCS:.cpp=.d) $(SCALERS:.cpp=.d) 3p/libxbr-standalone/xbr.d all: hode diff --git a/main.cpp b/main.cpp index 62d6ade..d0c3554 100644 --- a/main.cpp +++ b/main.cpp @@ -6,11 +6,10 @@ #if !defined(PSP) && !defined(WII) #include #endif +#include #include #include -#include "3p/inih/ini.h" - #include "game.h" #include "menu.h" #include "mixer.h" @@ -90,8 +89,7 @@ static bool configBool(const char *value) { return strcasecmp(value, "true") == 0 || (strlen(value) == 2 && (value[0] == 't' || value[0] == '1')); } -static int handleConfigIni(void *userdata, const char *section, const char *name, const char *value) { - Game *g = (Game *)userdata; +static void handleConfigIni(Game *g, const char *section, const char *name, const char *value) { // fprintf(stdout, "config.ini: section '%s' name '%s' value '%s'\n", section, name, value); if (strcmp(section, "engine") == 0) { if (strcmp(name, "disable_paf") == 0) { @@ -127,7 +125,45 @@ static int handleConfigIni(void *userdata, const char *section, const char *name _widescreen = configBool(value); } } - return 0; +} + +static void readConfigIni(const char *filename, Game *g) { + FILE *fp = fopen(filename, "rb"); + if (fp) { + char *section = 0; + char buf[256]; + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#') { + continue; + } + if (buf[0] == '[') { + char *p = strchr(&buf[1], ']'); + if (p) { + *p = 0; + free(section); + section = strdup(&buf[1]); + } + continue; + } + char *p = strchr(buf, '='); + if (!p) { + continue; + } + *p++ = 0; + while (*p && isspace(*p)) { + ++p; + } + if (*p) { + char *q = p + strlen(p) - 1; + while (q > p && isspace(*q)) { + *q-- = 0; + } + handleConfigIni(g, section, buf, p); + } + } + free(section); + fclose(fp); + } } int main(int argc, char *argv[]) { @@ -225,7 +261,7 @@ int main(int argc, char *argv[]) { } } Game *g = new Game(dataPath ? dataPath : _defaultDataPath, savePath ? savePath : _defaultSavePath, cheats); - ini_parse(_configIni, handleConfigIni, g); + readConfigIni(_configIni, g); if (_runBenchmark) { g->benchmarkCpu(); }