All: Add --version flag

This commit is contained in:
Jeffrey Pfau 2015-10-20 22:27:27 -07:00
parent c82f0ba5de
commit cd2443356b
6 changed files with 41 additions and 2 deletions

View File

@ -46,6 +46,7 @@ Misc:
- GBA Config: Add "override" layer for better one-time configuration - GBA Config: Add "override" layer for better one-time configuration
- SDL: Allow GBASDLAudio to be used without a thread context - SDL: Allow GBASDLAudio to be used without a thread context
- All: Improved PowerPC support - All: Improved PowerPC support
- All: Add --version flag
0.3.0: (2015-08-16) 0.3.0: (2015-08-16)
Features: Features:

View File

@ -47,6 +47,7 @@ static const struct option _options[] = {
{ "help", no_argument, 0, 'h' }, { "help", no_argument, 0, 'h' },
{ "movie", required_argument, 0, 'v' }, { "movie", required_argument, 0, 'v' },
{ "patch", required_argument, 0, 'p' }, { "patch", required_argument, 0, 'p' },
{ "version", no_argument, 0, '\0' },
{ 0, 0, 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 // TODO: modularize options to subparsers
strncat(options, subparser->extraOptions, sizeof(options) - strlen(options) - 1); 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) { switch (ch) {
case '\0':
if (strcmp(opt->name, "version") == 0) {
opts->showVersion = true;
} else {
return false;
}
break;
case 'b': case 'b':
GBAConfigSetOverrideValue(config, "bios", optarg); GBAConfigSetOverrideValue(config, "bios", optarg);
break; break;
@ -122,7 +132,7 @@ bool parseArguments(struct GBAArguments* opts, struct GBAConfig* config, int arg
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (argc != 1) { if (argc != 1) {
return opts->showHelp; return opts->showHelp || opts->showVersion;
} }
opts->fname = strdup(argv[0]); opts->fname = strdup(argv[0]);
return true; 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(" -v, --movie FILE Play back a movie of recorded input");
puts(" -p, --patch FILE Apply a specified patch file when running"); puts(" -p, --patch FILE Apply a specified patch file when running");
puts(" -s, --frameskip N Skip every N frames"); puts(" -s, --frameskip N Skip every N frames");
puts(" --version Print version and exit");
if (extraOptions) { if (extraOptions) {
puts(extraOptions); puts(extraOptions);
} }
} }
void version(const char* arg0) {
printf("%s %s (%s)\n", arg0, projectVersion, gitCommit);
}

View File

@ -31,6 +31,7 @@ struct GBAArguments {
enum DebuggerType debuggerType; enum DebuggerType debuggerType;
bool debugAtStart; bool debugAtStart;
bool showHelp; bool showHelp;
bool showVersion;
}; };
struct SubParser { struct SubParser {
@ -52,6 +53,7 @@ bool parseArguments(struct GBAArguments* opts, struct GBAConfig* config, int arg
void freeArguments(struct GBAArguments* opts); void freeArguments(struct GBAArguments* opts);
void usage(const char* arg0, const char* extraOptions); void usage(const char* arg0, const char* extraOptions);
void version(const char* arg0);
void initParserForGraphics(struct SubParser* parser, struct GraphicsOpts* opts); void initParserForGraphics(struct SubParser* parser, struct GraphicsOpts* opts);
struct ARMDebugger* createDebugger(struct GBAArguments* opts, struct GBAThread* context); struct ARMDebugger* createDebugger(struct GBAArguments* opts, struct GBAThread* context);

View File

@ -67,6 +67,13 @@ int main(int argc, char** argv) {
GBAConfigDeinit(&config); GBAConfigDeinit(&config);
return !parsed; return !parsed;
} }
if (args.showVersion) {
version(argv[0]);
freeArguments(&args);
GBAConfigFreeOpts(&opts);
GBAConfigDeinit(&config);
return 0;
}
GBAConfigMap(&config, &opts); GBAConfigMap(&config, &opts);

View File

@ -67,6 +67,13 @@ int main(int argc, char** argv) {
GBAContextDeinit(&context); GBAContextDeinit(&context);
return !parsed; return !parsed;
} }
if (args.showVersion) {
version(argv[0]);
freeArguments(&args);
GBAConfigFreeOpts(&opts);
GBAConfigDeinit(&config);
return 0;
}
struct GBAVideoSoftwareRenderer renderer; struct GBAVideoSoftwareRenderer renderer;
renderer.outputBuffer = 0; renderer.outputBuffer = 0;

View File

@ -77,6 +77,13 @@ int main(int argc, char** argv) {
GBAConfigDeinit(&config); GBAConfigDeinit(&config);
return !parsed; return !parsed;
} }
if (args.showVersion) {
version(argv[0]);
freeArguments(&args);
GBAConfigFreeOpts(&opts);
GBAConfigDeinit(&config);
return 0;
}
renderer.outputBuffer = malloc(256 * 256 * 4); renderer.outputBuffer = malloc(256 * 256 * 4);
renderer.outputBufferStride = 256; renderer.outputBufferStride = 256;