diff --git a/CHANGES b/CHANGES index 86bfa462a..f0954bd87 100644 --- a/CHANGES +++ b/CHANGES @@ -46,6 +46,7 @@ Misc: - GBA Config: Add "override" layer for better one-time configuration - SDL: Allow GBASDLAudio to be used without a thread context - All: Improved PowerPC support + - All: Add --version flag 0.3.0: (2015-08-16) Features: diff --git a/src/platform/commandline.c b/src/platform/commandline.c index 1a62c222c..dfea7de7a 100644 --- a/src/platform/commandline.c +++ b/src/platform/commandline.c @@ -47,6 +47,7 @@ static const struct option _options[] = { { "help", no_argument, 0, 'h' }, { "movie", required_argument, 0, 'v' }, { "patch", required_argument, 0, 'p' }, + { "version", no_argument, 0, '\0' }, { 0, 0, 0, 0 } }; @@ -68,8 +69,17 @@ bool parseArguments(struct GBAArguments* opts, struct GBAConfig* config, int arg // TODO: modularize options to subparsers strncat(options, subparser->extraOptions, sizeof(options) - strlen(options) - 1); } - while ((ch = getopt_long(argc, argv, options, _options, 0)) != -1) { + int index = 0; + while ((ch = getopt_long(argc, argv, options, _options, &index)) != -1) { + const struct option* opt = &_options[index]; switch (ch) { + case '\0': + if (strcmp(opt->name, "version") == 0) { + opts->showVersion = true; + } else { + return false; + } + break; case 'b': GBAConfigSetOverrideValue(config, "bios", optarg); break; @@ -122,7 +132,7 @@ bool parseArguments(struct GBAArguments* opts, struct GBAConfig* config, int arg argc -= optind; argv += optind; if (argc != 1) { - return opts->showHelp; + return opts->showHelp || opts->showVersion; } opts->fname = strdup(argv[0]); return true; @@ -228,7 +238,12 @@ void usage(const char* arg0, const char* extraOptions) { puts(" -v, --movie FILE Play back a movie of recorded input"); puts(" -p, --patch FILE Apply a specified patch file when running"); puts(" -s, --frameskip N Skip every N frames"); + puts(" --version Print version and exit"); if (extraOptions) { puts(extraOptions); } } + +void version(const char* arg0) { + printf("%s %s (%s)\n", arg0, projectVersion, gitCommit); +} diff --git a/src/platform/commandline.h b/src/platform/commandline.h index bb1bfb874..5f45f444a 100644 --- a/src/platform/commandline.h +++ b/src/platform/commandline.h @@ -31,6 +31,7 @@ struct GBAArguments { enum DebuggerType debuggerType; bool debugAtStart; bool showHelp; + bool showVersion; }; struct SubParser { @@ -52,6 +53,7 @@ bool parseArguments(struct GBAArguments* opts, struct GBAConfig* config, int arg void freeArguments(struct GBAArguments* opts); void usage(const char* arg0, const char* extraOptions); +void version(const char* arg0); void initParserForGraphics(struct SubParser* parser, struct GraphicsOpts* opts); struct ARMDebugger* createDebugger(struct GBAArguments* opts, struct GBAThread* context); diff --git a/src/platform/sdl/main.c b/src/platform/sdl/main.c index 9ab62b6df..d1c883707 100644 --- a/src/platform/sdl/main.c +++ b/src/platform/sdl/main.c @@ -67,6 +67,13 @@ int main(int argc, char** argv) { GBAConfigDeinit(&config); return !parsed; } + if (args.showVersion) { + version(argv[0]); + freeArguments(&args); + GBAConfigFreeOpts(&opts); + GBAConfigDeinit(&config); + return 0; + } GBAConfigMap(&config, &opts); diff --git a/src/platform/test/fuzz-main.c b/src/platform/test/fuzz-main.c index 4fa86d575..33041e740 100644 --- a/src/platform/test/fuzz-main.c +++ b/src/platform/test/fuzz-main.c @@ -67,6 +67,13 @@ int main(int argc, char** argv) { GBAContextDeinit(&context); return !parsed; } + if (args.showVersion) { + version(argv[0]); + freeArguments(&args); + GBAConfigFreeOpts(&opts); + GBAConfigDeinit(&config); + return 0; + } struct GBAVideoSoftwareRenderer renderer; renderer.outputBuffer = 0; diff --git a/src/platform/test/perf-main.c b/src/platform/test/perf-main.c index c99ef6177..58bfdcb93 100644 --- a/src/platform/test/perf-main.c +++ b/src/platform/test/perf-main.c @@ -77,6 +77,13 @@ int main(int argc, char** argv) { GBAConfigDeinit(&config); return !parsed; } + if (args.showVersion) { + version(argv[0]); + freeArguments(&args); + GBAConfigFreeOpts(&opts); + GBAConfigDeinit(&config); + return 0; + } renderer.outputBuffer = malloc(256 * 256 * 4); renderer.outputBufferStride = 256;