all repos — mgba @ 5b300bbcff5d2dfb43671c203647ce78cd605465

mGBA Game Boy Advance Emulator

Make command line arguments more dynamic
Jeffrey Pfau jeffrey@endrift.com
Sun, 20 Apr 2014 21:41:21 -0700
commit

5b300bbcff5d2dfb43671c203647ce78cd605465

parent

7334b89833116c4784893eebbd373cf7eecccbfa

3 files changed, 29 insertions(+), 4 deletions(-)

jump to
M src/platform/commandline.csrc/platform/commandline.c

@@ -15,12 +15,16 @@ static const char* _defaultFilename = "test.rom";

static const struct option _options[] = { { "bios", 1, 0, 'b' }, +#ifdef USE_CLI_DEBUGGER { "debug", 1, 0, 'd' }, +#endif +#ifdef USE_GDB_STUB { "gdb", 1, 0, 'g' }, +#endif { 0, 0, 0, 0 } }; -int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv) { +int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, int hasGraphics) { memset(opts, 0, sizeof(*opts)); opts->fd = -1; opts->biosFd = -1;

@@ -30,7 +34,19 @@ opts->fullscreen = 0;

int multiplier = 1; int ch; - while ((ch = getopt_long(argc, argv, "234b:dfg", _options, 0)) != -1) { + char options[64] = + "b:" +#ifdef USE_CLI_DEBUGGER + "d" +#endif +#ifdef USE_GDB_STUB + "g" +#endif + ; + if (hasGraphics) { + strncat(options, "234f", sizeof(options) - strlen(options) - 1); + } + while ((ch = getopt_long(argc, argv, options, _options, 0)) != -1) { switch (ch) { case 'b': opts->biosFd = open(optarg, O_RDONLY);

@@ -55,12 +71,21 @@ opts->debuggerType = DEBUGGER_GDB;

break; #endif case '2': + if (multiplier != 1) { + return 0; + } multiplier = 2; break; case '3': + if (multiplier != 1) { + return 0; + } multiplier = 3; break; case '4': + if (multiplier != 1) { + return 0; + } multiplier = 4; break; default:
M src/platform/commandline.hsrc/platform/commandline.h

@@ -30,7 +30,7 @@ enum DebuggerType debuggerType;

int debugAtStart; }; -int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv); +int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, int hasGraphics); struct ARMDebugger* createDebugger(struct StartupOptions* opts); void usage(const char* arg0);
M src/platform/sdl/gl-main.csrc/platform/sdl/gl-main.c

@@ -62,7 +62,7 @@ struct GLSoftwareRenderer renderer;

GBAVideoSoftwareRendererCreate(&renderer.d); struct StartupOptions opts; - if (!parseCommandArgs(&opts, argc, argv)) { + if (!parseCommandArgs(&opts, argc, argv, 1)) { usage(argv[0]); return 1; }