mirror of https://github.com/mgba-emu/mgba.git
Make command line arguments more dynamic
This commit is contained in:
parent
7334b89833
commit
5b300bbcff
|
@ -15,12 +15,16 @@ static const char* _defaultFilename = "test.rom";
|
||||||
|
|
||||||
static const struct option _options[] = {
|
static const struct option _options[] = {
|
||||||
{ "bios", 1, 0, 'b' },
|
{ "bios", 1, 0, 'b' },
|
||||||
|
#ifdef USE_CLI_DEBUGGER
|
||||||
{ "debug", 1, 0, 'd' },
|
{ "debug", 1, 0, 'd' },
|
||||||
|
#endif
|
||||||
|
#ifdef USE_GDB_STUB
|
||||||
{ "gdb", 1, 0, 'g' },
|
{ "gdb", 1, 0, 'g' },
|
||||||
|
#endif
|
||||||
{ 0, 0, 0, 0 }
|
{ 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));
|
memset(opts, 0, sizeof(*opts));
|
||||||
opts->fd = -1;
|
opts->fd = -1;
|
||||||
opts->biosFd = -1;
|
opts->biosFd = -1;
|
||||||
|
@ -30,7 +34,19 @@ int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv) {
|
||||||
|
|
||||||
int multiplier = 1;
|
int multiplier = 1;
|
||||||
int ch;
|
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) {
|
switch (ch) {
|
||||||
case 'b':
|
case 'b':
|
||||||
opts->biosFd = open(optarg, O_RDONLY);
|
opts->biosFd = open(optarg, O_RDONLY);
|
||||||
|
@ -55,12 +71,21 @@ int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv) {
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case '2':
|
case '2':
|
||||||
|
if (multiplier != 1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
multiplier = 2;
|
multiplier = 2;
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '3':
|
||||||
|
if (multiplier != 1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
multiplier = 3;
|
multiplier = 3;
|
||||||
break;
|
break;
|
||||||
case '4':
|
case '4':
|
||||||
|
if (multiplier != 1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
multiplier = 4;
|
multiplier = 4;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -30,7 +30,7 @@ struct StartupOptions {
|
||||||
int debugAtStart;
|
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);
|
struct ARMDebugger* createDebugger(struct StartupOptions* opts);
|
||||||
void usage(const char* arg0);
|
void usage(const char* arg0);
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ int main(int argc, char** argv) {
|
||||||
GBAVideoSoftwareRendererCreate(&renderer.d);
|
GBAVideoSoftwareRendererCreate(&renderer.d);
|
||||||
|
|
||||||
struct StartupOptions opts;
|
struct StartupOptions opts;
|
||||||
if (!parseCommandArgs(&opts, argc, argv)) {
|
if (!parseCommandArgs(&opts, argc, argv, 1)) {
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue