From 6f24064f4f6ee35d7926a5dd347dc545e88dd5bf Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 10 May 2015 03:02:03 -0700 Subject: [PATCH] All: Add --help flag for command line programs --- CHANGES | 1 + src/platform/commandline.c | 8 ++++++-- src/platform/commandline.h | 1 + src/platform/perf-main.c | 5 +++-- src/platform/sdl/main.c | 5 +++-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index eb8f60bbf..e41600c86 100644 --- a/CHANGES +++ b/CHANGES @@ -63,6 +63,7 @@ Misc: - 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: diff --git a/src/platform/commandline.c b/src/platform/commandline.c index 3a4456202..21591983c 100644 --- a/src/platform/commandline.c +++ b/src/platform/commandline.c @@ -43,6 +43,7 @@ static const struct option _options[] = { #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 _parseGraphicsArg(struct SubParser* parser, struct GBAConfig* config, int o 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 @@ bool parseArguments(struct GBAArguments* opts, struct GBAConfig* config, int arg opts->debuggerType = DEBUGGER_GDB; break; #endif + case 'h': + opts->showHelp = true; + break; case 'l': GBAConfigSetDefaultValue(config, "logLevel", optarg); break; @@ -117,7 +121,7 @@ bool parseArguments(struct GBAArguments* opts, struct GBAConfig* config, int arg argc -= optind; argv += optind; if (argc != 1) { - return false; + return opts->showHelp; } opts->fname = strdup(argv[0]); return true; diff --git a/src/platform/commandline.h b/src/platform/commandline.h index 97ac22240..c789e70ac 100644 --- a/src/platform/commandline.h +++ b/src/platform/commandline.h @@ -30,6 +30,7 @@ struct GBAArguments { enum DebuggerType debuggerType; bool debugAtStart; + bool showHelp; }; struct SubParser { diff --git a/src/platform/perf-main.c b/src/platform/perf-main.c index e22e513de..940a5ae4d 100644 --- a/src/platform/perf-main.c +++ b/src/platform/perf-main.c @@ -62,12 +62,13 @@ int main(int argc, char** argv) { 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); diff --git a/src/platform/sdl/main.c b/src/platform/sdl/main.c index d192a97ae..123202f77 100644 --- a/src/platform/sdl/main.c +++ b/src/platform/sdl/main.c @@ -59,12 +59,13 @@ int main(int argc, char** argv) { 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);