From ccf7d2d470c3aef54401f4bde1fed13f7ee56352 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Sun, 3 Nov 2013 04:02:23 +0000 Subject: [PATCH] Allow -g, -x, -h, -j, and for the game, -d, to take their file name after a space. This allows quotes to be used with them properly. I updated the help windows to prefer these variants because they are superior to the -xSquished versions. Also, factor out the command-line processing code for the above, plus con/def modules and clipmaps. git-svn-id: https://svn.eduke32.com/eduke32@4128 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/common.h | 5 + polymer/eduke32/source/astub.c | 89 ++++++++++------ polymer/eduke32/source/common.c | 47 ++++++++ polymer/eduke32/source/common_game.h | 6 ++ polymer/eduke32/source/game.c | 142 ++++++++++++++----------- polymer/eduke32/source/game.h | 3 - 6 files changed, 194 insertions(+), 98 deletions(-) diff --git a/polymer/eduke32/build/include/common.h b/polymer/eduke32/build/include/common.h index 89efb1d1b..3ebced2c0 100644 --- a/polymer/eduke32/build/include/common.h +++ b/polymer/eduke32/build/include/common.h @@ -51,6 +51,11 @@ extern struct strllist *CommandPaths, *CommandGrps; //// FUNCTIONS void G_AddGroup(const char *buffer); void G_AddPath(const char *buffer); +void G_AddDef(const char *buffer); +void G_AddDefModule(const char *buffer); +#ifdef HAVE_CLIPSHAPE_FEATURE +void G_AddClipMap(const char *buffer); +#endif int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens); diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 86307bccc..83a557d3f 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -90,16 +90,6 @@ static int32_t spnoclip=1; static char *default_tiles_cfg = "tiles.cfg"; static int32_t pathsearchmode_oninit; -char **g_scriptModules = NULL; -int32_t g_scriptModulesNum = 0; -char **g_defModules = NULL; -int32_t g_defModulesNum = 0; - -#ifdef HAVE_CLIPSHAPE_FEATURE -char **g_clipMapFiles = NULL; -int32_t g_clipMapFilesNum = 0; -#endif - #ifdef LUNATIC static L_State g_EmState; #endif @@ -8449,12 +8439,12 @@ int32_t ExtPreSaveMap(void) static void G_ShowParameterHelp(void) { const char *s = "Usage: mapster32 [files] [options]\n\n" - "-g[file.grp], -grp [file.grp]\tLoad extra group file\n" - "-h[file.def]\t\tLoad an alternate definitions file\n" - "-x[game.con]\t\tLoad a custom CON script for getting sound definitions\n" + "-g [file.grp], -grp [file.grp]\tLoad extra group file\n" + "-h [file.def]\t\tLoad an alternate definitions file\n" + "-x [game.con]\t\tLoad a custom CON script for getting sound definitions\n" "-mh [file.def]\t\tInclude additional definitions module\n" "-mx [file.con]\t\tInclude additional CON module for getting sound definitions\n" - "-j[dir], -game_dir [dir]\n" + "-j [dir], -game_dir [dir]\n" "\t\t\tAdds a directory to the file path stack\n" "-cachesize #\t\tSets cache size, in Kb\n" "-check\t\t\tEnables map pointer checking when saving\n" @@ -8622,13 +8612,37 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) i++; continue; } + if (!Bstrcasecmp(c+1,"x")) + { + if (argc > i+1) + { + G_AddCon(argv[i+1]); + COPYARG(i); + COPYARG(i+1); + i++; + } + i++; + continue; + } if (!Bstrcasecmp(c+1,"mx")) { if (argc > i+1) { - g_scriptModules = (char **) Brealloc (g_scriptModules, (g_scriptModulesNum+1) * sizeof(char *)); - g_scriptModules[g_scriptModulesNum] = Bstrdup(argv[i+1]); - ++g_scriptModulesNum; + G_AddConModule(argv[i+1]); + COPYARG(i); + COPYARG(i+1); + i++; + } + i++; + continue; + } + if (!Bstrcasecmp(c+1,"h")) + { + if (argc > i+1) + { + G_AddDef(argv[i+1]); + COPYARG(i); + COPYARG(i+1); i++; } i++; @@ -8638,9 +8652,21 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) { if (argc > i+1) { - g_defModules = (char **) Brealloc (g_defModules, (g_defModulesNum+1) * sizeof(char *)); - g_defModules[g_defModulesNum] = Bstrdup(argv[i+1]); - ++g_defModulesNum; + G_AddDefModule(argv[i+1]); + COPYARG(i); + COPYARG(i+1); + i++; + } + i++; + continue; + } + if (!Bstrcasecmp(c+1,"j")) + { + if (argc > i+1) + { + G_AddPath(argv[i+1]); + COPYARG(i); + COPYARG(i+1); i++; } i++; @@ -8651,9 +8677,9 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) { if (argc > i+1) { - g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *)); - g_clipMapFiles[g_clipMapFilesNum] = Bstrdup(argv[i+1]); - ++g_clipMapFilesNum; + G_AddClipMap(argv[i+1]); + COPYARG(i); + COPYARG(i+1); i++; } i++; @@ -8743,10 +8769,8 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) c++; if (*c) { - clearDefNamePtr(); - g_defNamePtr = dup_filename(c); + G_AddDef(c); COPYARG(i); - initprintf("Using DEF file \"%s\".\n",g_defNamePtr); } break; case 'j': @@ -8768,9 +8792,8 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) c++; if (*c) { - clearScriptNamePtr(); - g_scriptNamePtr = dup_filename(c); - initprintf("Using CON file \"%s\".\n",g_scriptNamePtr); + G_AddCon(c); + COPYARG(i); } break; } @@ -8794,17 +8817,13 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) else if (!Bstrcasecmp(k,".def")) { COPYARG(i); - clearDefNamePtr(); - g_defNamePtr = dup_filename(argv[i++]); - initprintf("Using DEF file \"%s\".\n",g_defNamePtr); + G_AddDef(argv[i++]); continue; } else if (!Bstrcasecmp(k,".con")) { COPYARG(i); - clearScriptNamePtr(); - g_scriptNamePtr = dup_filename(argv[i++]); - initprintf("Using CON file \"%s\".\n",g_scriptNamePtr); + G_AddCon(argv[i++]); continue; } } diff --git a/polymer/eduke32/source/common.c b/polymer/eduke32/source/common.c index c395fb71e..46be65c91 100644 --- a/polymer/eduke32/source/common.c +++ b/polymer/eduke32/source/common.c @@ -359,6 +359,16 @@ void G_CleanupSearchPaths(void) struct strllist *CommandPaths, *CommandGrps; +char **g_scriptModules = NULL; +int32_t g_scriptModulesNum = 0; +char **g_defModules = NULL; +int32_t g_defModulesNum = 0; + +#ifdef HAVE_CLIPSHAPE_FEATURE +char **g_clipMapFiles = NULL; +int32_t g_clipMapFilesNum = 0; +#endif + void G_AddGroup(const char *buffer) { char buf[BMAX_PATH]; @@ -397,6 +407,43 @@ void G_AddPath(const char *buffer) CommandPaths = s; } +void G_AddDef(const char *buffer) +{ + clearDefNamePtr(); + g_defNamePtr = dup_filename(buffer); + initprintf("Using DEF file \"%s\".\n",g_defNamePtr); +} + +void G_AddDefModule(const char *buffer) +{ + g_defModules = (char **) Brealloc (g_defModules, (g_defModulesNum+1) * sizeof(char *)); + g_defModules[g_defModulesNum] = Bstrdup(buffer); + ++g_defModulesNum; +} + +#ifdef HAVE_CLIPSHAPE_FEATURE +void G_AddClipMap(const char *buffer) +{ + g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *)); + g_clipMapFiles[g_clipMapFilesNum] = Bstrdup(buffer); + ++g_clipMapFilesNum; +} +#endif + +void G_AddCon(const char *buffer) +{ + clearScriptNamePtr(); + g_scriptNamePtr = dup_filename(buffer); + initprintf("Using CON file \"%s\".\n",g_scriptNamePtr); +} + +void G_AddConModule(const char *buffer) +{ + g_scriptModules = (char **) Brealloc (g_scriptModules, (g_scriptModulesNum+1) * sizeof(char *)); + g_scriptModules[g_scriptModulesNum] = Bstrdup(buffer); + ++g_scriptModulesNum; +} + ////////// int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens) diff --git a/polymer/eduke32/source/common_game.h b/polymer/eduke32/source/common_game.h index ddf60bcfc..c884d3155 100644 --- a/polymer/eduke32/source/common_game.h +++ b/polymer/eduke32/source/common_game.h @@ -52,6 +52,12 @@ extern const char *G_GrpFile(void); extern const char *G_DefaultConFile(void); extern const char *G_ConFile(void); +extern char **g_scriptModules; +extern int32_t g_scriptModulesNum; + +extern void G_AddCon(const char *buffer); +extern void G_AddConModule(const char *buffer); + extern void clearGrpNamePtr(void); extern void clearDefNamePtr(void); extern void clearScriptNamePtr(void); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 2ff1415ac..2b124162b 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -138,18 +138,9 @@ const char *g_gameNamePtr = NULL; // g_rtsNamePtr can point to an argv[] element const char *g_rtsNamePtr = NULL; -char **g_scriptModules = NULL; -int32_t g_scriptModulesNum = 0; -char **g_defModules = NULL; -int32_t g_defModulesNum = 0; int32_t g_dependencyCRC = 0; int32_t g_usingAddon = 0; -#ifdef HAVE_CLIPSHAPE_FEATURE -char **g_clipMapFiles = NULL; -int32_t g_clipMapFilesNum = 0; -#endif - int32_t g_Shareware = 0; #define MAXUSERQUOTES 6 @@ -9009,10 +9000,10 @@ static void G_ShowParameterHelp(void) #endif "-connect [host]\tConnect to a multiplayer game\n" "-c#\t\tUse MP mode #, 1 = Dukematch, 2 = Coop, 3 = Dukematch(no spawn)\n" - "-d[file.edm or demonum]\tPlay a demo\n" - "-g[file.grp]\tLoad additional game data\n" - "-h[file.def]\tLoad an alternate definitions file\n" - "-j[dir]\t\tAdds a directory to EDuke32's search list\n" + "-d [file.edm or demonum]\tPlay a demo\n" + "-g [file.grp]\tLoad additional game data\n" + "-h [file.def]\tLoad an alternate definitions file\n" + "-j [dir]\t\tAdds a directory to EDuke32's search list\n" "-l#\t\tWarp to level #, see -v\n" "-map [file.map]\tLoads a map\n" "-mh [file.def]\tInclude an additional definitions module\n" @@ -9032,7 +9023,7 @@ static void G_ShowParameterHelp(void) "-u#########\tUser's favorite weapon order (default: 3425689071)\n" "-v#\t\tWarp to volume #, see -l\n" "-ww2gi\t\tRun in WWII GI compatibility mode\n" - "-x[game.con]\tLoad custom CON script\n" + "-x [game.con]\tLoad custom CON script\n" "-#\t\tLoad and run a game from slot # (0-9)\n" // "\n-?/--help\tDisplay this help message and exit\n" "\nSee eduke32 -debughelp for debug parameters" @@ -9531,6 +9522,36 @@ static int32_t G_CheckCmdSwitch(int32_t argc, const char **argv, const char *str return 0; } +static void G_AddDemo(const char* param) +{ + char * colon = (char *)Bstrchr(param, ':'); + int32_t framespertic=-1, numrepeats=1; + + if (colon && colon != param) + { + // -d:[,] + // profiling options + *(colon++) = 0; + Bsscanf(colon, "%u,%u", &framespertic, &numrepeats); + } + + Demo_SetFirst(param); + + if (framespertic < 0) + { + initprintf("Play demo %s.\n", g_firstDemoFile); + } + else + { + framespertic = clamp(framespertic, 0, 8)+1; + // TODO: repeat count and gathering statistics. + initprintf("Profile demo %s, %d frames/gametic, repeated 1x.\n", g_firstDemoFile, + framespertic-1); + Demo_PlayFirst(framespertic, 1); + g_noLogo = 1; + } +} + static void G_CheckCommandLine(int32_t argc, const char **argv) { int16_t i = 1, j; @@ -9799,13 +9820,31 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) i++; continue; } + if (!Bstrcasecmp(c+1,"x")) + { + if (argc > i+1) + { + G_AddCon(argv[i+1]); + i++; + } + i++; + continue; + } if (!Bstrcasecmp(c+1,"mx")) { if (argc > i+1) { - g_scriptModules = (char **) Brealloc (g_scriptModules, (g_scriptModulesNum+1) * sizeof(char *)); - g_scriptModules[g_scriptModulesNum] = Bstrdup(argv[i+1]); - ++g_scriptModulesNum; + G_AddConModule(argv[i+1]); + i++; + } + i++; + continue; + } + if (!Bstrcasecmp(c+1,"h")) + { + if (argc > i+1) + { + G_AddDef(argv[i+1]); i++; } i++; @@ -9815,9 +9854,27 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) { if (argc > i+1) { - g_defModules = (char **) Brealloc (g_defModules, (g_defModulesNum+1) * sizeof(char *)); - g_defModules[g_defModulesNum] = Bstrdup(argv[i+1]); - ++g_defModulesNum; + G_AddDefModule(argv[i+1]); + i++; + } + i++; + continue; + } + if (!Bstrcasecmp(c+1,"j")) + { + if (argc > i+1) + { + G_AddPath(argv[i+1]); + i++; + } + i++; + continue; + } + if (!Bstrcasecmp(c+1,"d")) + { + if (argc > i+1) + { + G_AddDemo(argv[i+1]); i++; } i++; @@ -9828,9 +9885,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) { if (argc > i+1) { - g_clipMapFiles = (char **) Brealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *)); - g_clipMapFiles[g_clipMapFilesNum] = Bstrdup(argv[i+1]); - ++g_clipMapFilesNum; + G_AddClipMap(argv[i+1]); i++; } i++; @@ -9933,34 +9988,9 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) break; case 'd': { - char * colon = (char *)Bstrchr(c, ':'); - int32_t framespertic=-1, numrepeats=1; - c++; - - if (colon && colon != c) - { - // -d:[,] - // profiling options - *(colon++) = 0; - Bsscanf(colon, "%u,%u", &framespertic, &numrepeats); - } - - Demo_SetFirst(c); - - if (framespertic < 0) - { - initprintf("Play demo %s.\n", g_firstDemoFile); - } - else - { - framespertic = clamp(framespertic, 0, 8)+1; - // TODO: repeat count and gathering statistics. - initprintf("Profile demo %s, %d frames/gametic, repeated 1x.\n", g_firstDemoFile, - framespertic-1); - Demo_PlayFirst(framespertic, 1); - g_noLogo = 1; - } + if (*c) + G_AddDemo(c); break; } #ifdef LUNATIC @@ -9975,11 +10005,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) case 'h': c++; if (*c) - { - clearDefNamePtr(); - g_defNamePtr = dup_filename(c); - initprintf("Using DEF file \"%s\".\n",g_defNamePtr); - } + G_AddDef(c); break; case 'j': c++; @@ -10127,11 +10153,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) case 'x': c++; if (*c) - { - clearScriptNamePtr(); - g_scriptNamePtr = dup_filename(c); - initprintf("Using CON file \"%s\".\n",g_scriptNamePtr); - } + G_AddCon(c); break; case '0': case '1': diff --git a/polymer/eduke32/source/game.h b/polymer/eduke32/source/game.h index 51e114b82..f1e3f1ef2 100644 --- a/polymer/eduke32/source/game.h +++ b/polymer/eduke32/source/game.h @@ -245,9 +245,6 @@ extern const char *s_buildDate; extern const char *g_gameNamePtr; extern const char *g_rtsNamePtr; -extern char **g_scriptModules; -extern int32_t g_scriptModulesNum; - extern char CheatStrings[][MAXCHEATLEN]; extern char boardfilename[BMAX_PATH], currentboardfilename[BMAX_PATH]; extern char boardfilename[BMAX_PATH];