Переглянути джерело

Use own version of cmdline option function

Copy implementation from lws.
feature/data-structs
TheoryOfNekomata 2 роки тому
джерело
коміт
1421ff9efe
10 змінених файлів з 66 додано та 5 видалено
  1. +1
    -1
      src/packages/game/IZ_app.c
  2. +23
    -0
      src/packages/game/IZ_config.c
  3. +3
    -0
      src/packages/game/IZ_config.h
  4. +8
    -0
      src/packages/game/output/IZ_video.c
  5. +1
    -1
      src/packages/server/IZ_app.c
  6. +23
    -0
      src/packages/server/IZ_config.c
  7. +3
    -0
      src/packages/server/IZ_config.h
  8. +2
    -2
      src/packages/server/main.c
  9. +1
    -1
      src/packages/server/network/IZ_wsserver.c
  10. +1
    -0
      src/packages/server/network/IZ_wsserver.h

+ 1
- 1
src/packages/game/IZ_app.c Переглянути файл

@@ -81,7 +81,7 @@ IZ_ProcedureResult IZ_AppInitialize(IZ_App* app, u8 argc, const char* argv[]) {
const char* cmdline_buffer;
char config_path[128];
// TODO abstract command line args parsing
if ((cmdline_buffer = lws_cmdline_option(argc, argv, "-c"))) {
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) {
memcpy_s(config_path, 128, cmdline_buffer, 128);
} else {
IZ_ConfigGetDefaultPath(config_path, 128);


+ 23
- 0
src/packages/game/IZ_config.c Переглянути файл

@@ -6,3 +6,26 @@ void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) {
memcpy_s(config_path, string_size, config_path_dir, 128);
strcat_s(config_path, string_size, "config-game.ini");
}

const char* IZ_ConfigGetCommandlineOption(u8 argc, const char* argv[], const char* val) {
size_t n = strlen(val);
int c = argc;

while (--c > 0) {

if (!strncmp(argv[c], val, n)) {
if (!*(argv[c] + n) && c < argc - 1) {
/* coverity treats unchecked argv as "tainted" */
if (!argv[c + 1] || strlen(argv[c + 1]) > 1024)
return NULL;
return argv[c + 1];
}

if (argv[c][n] == '=')
return &argv[c][n + 1];
return argv[c] + n;
}
}

return NULL;
}

+ 3
- 0
src/packages/game/IZ_config.h Переглянути файл

@@ -3,8 +3,11 @@

#include <SDL_filesystem.h>
#include <string.h>
#include "IZ_common.h"

// TODO unify loading of config from cmdline and config file
void IZ_ConfigGetDefaultPath(const char*, size_t);

const char* IZ_ConfigGetCommandlineOption(u8, const char**, const char*);

#endif

+ 8
- 0
src/packages/game/output/IZ_video.c Переглянути файл

@@ -20,6 +20,13 @@ void IZ_VideoLoadConfig(IZ_VideoState* state, const char* config_path) {
state->config.max_fps = ini_getl("Video", "MaxFps", IZ_DEFAULT_VIDEO_STATE.config.max_fps, config_path);
}

void IZ_VideoOverrideConfig(IZ_VideoState* state, u8 argc, const char* argv[]) {
const char* cmdline_buffer;
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-f"))) {
state->config.max_fps = atoi(cmdline_buffer);
}
}

IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState* state, const char* config_path, u8 argc, const char* argv[]) {
SDL_memcpy(state, &IZ_DEFAULT_VIDEO_STATE, sizeof(IZ_VideoState));

@@ -27,6 +34,7 @@ IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState* state, const char* config_p
if (IZ_VideoSaveConfig(state, config_path)) {
// fprintf_s(stderr, "Error committing video config.\n");
}
IZ_VideoOverrideConfig(state, argc, argv);
state->last_update_at = 0u;

SDL_Window* window = SDL_CreateWindow(


+ 1
- 1
src/packages/server/IZ_app.c Переглянути файл

@@ -18,7 +18,7 @@ IZ_ProcedureResult IZ_AppInitialize(IZ_App *app, u8 argc, const char **argv) {
const char* cmdline_buffer;
char config_path[128];
// TODO abstract command line args parsing
if ((cmdline_buffer = lws_cmdline_option(argc, argv, "-c"))) {
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) {
memcpy_s(config_path, 128, cmdline_buffer, 128);
} else {
IZ_ConfigGetDefaultPath(config_path, 128);


+ 23
- 0
src/packages/server/IZ_config.c Переглянути файл

@@ -6,3 +6,26 @@ void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) {
memcpy_s(config_path, string_size, config_path_dir, 128);
strcat_s(config_path, string_size, "config-server.ini");
}

const char* IZ_ConfigGetCommandlineOption(u8 argc, const char* argv[], const char* val) {
size_t n = strlen(val);
int c = argc;

while (--c > 0) {

if (!strncmp(argv[c], val, n)) {
if (!*(argv[c] + n) && c < argc - 1) {
/* coverity treats unchecked argv as "tainted" */
if (!argv[c + 1] || strlen(argv[c + 1]) > 1024)
return NULL;
return argv[c + 1];
}

if (argv[c][n] == '=')
return &argv[c][n + 1];
return argv[c] + n;
}
}

return NULL;
}

+ 3
- 0
src/packages/server/IZ_config.h Переглянути файл

@@ -3,8 +3,11 @@

#include <SDL_filesystem.h>
#include <string.h>
#include "IZ_common.h"

// TODO unify loading of config from cmdline and config file
void IZ_ConfigGetDefaultPath(const char*, size_t);

const char* IZ_ConfigGetCommandlineOption(u8, const char**, const char*);

#endif

+ 2
- 2
src/packages/server/main.c Переглянути файл

@@ -1,6 +1,6 @@
#include "IZ_app.h"

IZ_ProcedureResult main(i32 argc, const char *argv[]) {
IZ_ProcedureResult main(i32 argc, char* argv[]) {
IZ_App app;
return IZ_AppRun(&app, argc, argv);
return IZ_AppRun(&app, argc, (const char**) argv);
}

+ 1
- 1
src/packages/server/network/IZ_wsserver.c Переглянути файл

@@ -39,7 +39,7 @@ void IZ_WSServerLoadConfig(IZ_WSServerState* state, const char* config_path, u8
// state->config.log_level = atoi(cmdline_buffer);
// }

if ((cmdline_buffer = lws_cmdline_option(argc, argv, "-p"))) {
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-p"))) {
state->config.port = atoi(cmdline_buffer);
}
}


+ 1
- 0
src/packages/server/network/IZ_wsserver.h Переглянути файл

@@ -4,6 +4,7 @@
#include "libwebsockets.h"
#include <string.h>
#include "../IZ_common.h"
#include "../IZ_config.h"
#include "IZ_websocket.h"

/* one of these is created for each client connecting to us */


Завантаження…
Відмінити
Зберегти