all repos — mgba @ 6f24064f4f6ee35d7926a5dd347dc545e88dd5bf

mGBA Game Boy Advance Emulator

All: Add --help flag for command line programs
Jeffrey Pfau jeffrey@endrift.com
Sun, 10 May 2015 03:02:03 -0700
commit

6f24064f4f6ee35d7926a5dd347dc545e88dd5bf

parent

a651a91aa15d0ba99dc97eb84685221146cc1c03

M CHANGESCHANGES

@@ -63,6 +63,7 @@ - GBA: Add status log level

- GBA Thread: Add functionality for running callbacks on the GBA thread - Qt: Fast forward (held) option moved from Other to Emulation menu - GBA Memory: Soft-crash if jumping past the end of a ROM + - All: Add --help flag for command line programs 0.2.0: (2015-04-03) Features:
M src/platform/commandline.csrc/platform/commandline.c

@@ -43,6 +43,7 @@ #endif

#ifdef USE_GDB_STUB { "gdb", no_argument, 0, 'g' }, #endif + { "help", no_argument, 0, 'h' }, { "movie", required_argument, 0, 'v' }, { "patch", required_argument, 0, 'p' }, { 0, 0, 0, 0 }

@@ -53,7 +54,7 @@

bool parseArguments(struct GBAArguments* opts, struct GBAConfig* config, int argc, char* const* argv, struct SubParser* subparser) { int ch; char options[64] = - "b:c:Dl:p:s:v:" + "b:c:Dhl:p:s:v:" #ifdef USE_CLI_DEBUGGER "d" #endif

@@ -93,6 +94,9 @@ }

opts->debuggerType = DEBUGGER_GDB; break; #endif + case 'h': + opts->showHelp = true; + break; case 'l': GBAConfigSetDefaultValue(config, "logLevel", optarg); break;

@@ -117,7 +121,7 @@ }

argc -= optind; argv += optind; if (argc != 1) { - return false; + return opts->showHelp; } opts->fname = strdup(argv[0]); return true;
M src/platform/commandline.hsrc/platform/commandline.h

@@ -30,6 +30,7 @@ char* movie;

enum DebuggerType debuggerType; bool debugAtStart; + bool showHelp; }; struct SubParser {
M src/platform/perf-main.csrc/platform/perf-main.c

@@ -62,12 +62,13 @@ };

GBAConfigLoadDefaults(&config, &opts); struct GBAArguments args; - if (!parseArguments(&args, &config, argc, argv, &subparser)) { + bool parsed = parseArguments(&args, &config, argc, argv, &subparser); + if (!parsed || args.showHelp) { usage(argv[0], PERF_USAGE); freeArguments(&args); GBAConfigFreeOpts(&opts); GBAConfigDeinit(&config); - return 1; + return !parsed; } renderer.outputBuffer = malloc(256 * 256 * 4);
M src/platform/sdl/main.csrc/platform/sdl/main.c

@@ -59,12 +59,13 @@

struct SubParser subparser; initParserForGraphics(&subparser, &graphicsOpts); - if (!parseArguments(&args, &config, argc, argv, &subparser)) { + bool parsed = parseArguments(&args, &config, argc, argv, &subparser); + if (!parsed || args.showHelp) { usage(argv[0], subparser.usage); freeArguments(&args); GBAConfigFreeOpts(&opts); GBAConfigDeinit(&config); - return 1; + return !parsed; } GBAConfigMap(&config, &opts);