Skip to content

Commit

Permalink
removed 'inih' dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
CommonLoon102 committed Apr 20, 2021
1 parent 59576f4 commit b69ba4a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion 3p/inih
Submodule inih deleted from 75fe6b
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
48 changes: 42 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
#if !defined(PSP) && !defined(WII)
#include <SDL.h>
#endif
#include <ctype.h>
#include <getopt.h>
#include <sys/stat.h>

#include "3p/inih/ini.h"

#include "game.h"
#include "menu.h"
#include "mixer.h"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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[]) {
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit b69ba4a

Please sign in to comment.