mirror of https://github.com/mgba-emu/mgba.git
Feature: Command line ability to override configuration values
This commit is contained in:
parent
bf716b947a
commit
d16df69790
1
CHANGES
1
CHANGES
|
@ -12,6 +12,7 @@ Features:
|
|||
- Add option for whether rewinding restores save games
|
||||
- Qt: German translation (by Lothar Serra Mari)
|
||||
- Savestates now contain any RTC override data
|
||||
- Command line ability to override configuration values
|
||||
Bugfixes:
|
||||
- LR35902: Fix core never exiting with certain event patterns
|
||||
- GB Timer: Improve DIV reset behavior
|
||||
|
|
|
@ -48,10 +48,27 @@ static const struct option _options[] = {
|
|||
static bool _parseGraphicsArg(struct mSubParser* parser, int option, const char* arg);
|
||||
static void _applyGraphicsArgs(struct mSubParser* parser, struct mCoreConfig* config);
|
||||
|
||||
static void _tableInsert(struct Table* table, const char* pair) {
|
||||
char* eq = strchr(pair, '=');
|
||||
if (eq) {
|
||||
char option[128] = "";
|
||||
strncpy(option, pair, eq - pair);
|
||||
option[sizeof(option) - 1] = '\0';
|
||||
HashTableInsert(table, option, strdup(&eq[1]));
|
||||
} else {
|
||||
HashTableInsert(table, pair, strdup("1"));
|
||||
}
|
||||
}
|
||||
|
||||
static void _tableApply(const char* key, void* value, void* user) {
|
||||
struct mCoreConfig* config = user;
|
||||
mCoreConfigSetOverrideValue(config, key, value);
|
||||
}
|
||||
|
||||
bool parseArguments(struct mArguments* args, int argc, char* const* argv, struct mSubParser* subparser) {
|
||||
int ch;
|
||||
char options[64] =
|
||||
"b:c:hl:p:s:v:"
|
||||
"b:c:C:hl:p:s:v:"
|
||||
#ifdef USE_EDITLINE
|
||||
"d"
|
||||
#endif
|
||||
|
@ -62,6 +79,7 @@ bool parseArguments(struct mArguments* args, int argc, char* const* argv, struct
|
|||
memset(args, 0, sizeof(*args));
|
||||
args->frameskip = -1;
|
||||
args->logLevel = INT_MIN;
|
||||
HashTableInit(&args->configOverrides, 0, free);
|
||||
if (subparser && subparser->extraOptions) {
|
||||
// TODO: modularize options to subparsers
|
||||
strncat(options, subparser->extraOptions, sizeof(options) - strlen(options) - 1);
|
||||
|
@ -83,6 +101,9 @@ bool parseArguments(struct mArguments* args, int argc, char* const* argv, struct
|
|||
case 'c':
|
||||
args->cheatsFile = strdup(optarg);
|
||||
break;
|
||||
case 'C':
|
||||
_tableInsert(&args->configOverrides, optarg);
|
||||
break;
|
||||
#ifdef USE_EDITLINE
|
||||
case 'd':
|
||||
if (args->debuggerType != DEBUGGER_NONE) {
|
||||
|
@ -145,6 +166,7 @@ void applyArguments(const struct mArguments* args, struct mSubParser* subparser,
|
|||
if (args->bios) {
|
||||
mCoreConfigSetOverrideValue(config, "bios", args->bios);
|
||||
}
|
||||
HashTableEnumerate(&args->configOverrides, _tableApply, config);
|
||||
if (subparser) {
|
||||
subparser->apply(subparser, config);
|
||||
}
|
||||
|
@ -165,6 +187,8 @@ void freeArguments(struct mArguments* args) {
|
|||
|
||||
free(args->bios);
|
||||
args->bios = 0;
|
||||
|
||||
HashTableDeinit(&args->configOverrides);
|
||||
}
|
||||
|
||||
void initParserForGraphics(struct mSubParser* parser, struct mGraphicsOpts* opts) {
|
||||
|
@ -212,6 +236,7 @@ void usage(const char* arg0, const char* extraOptions) {
|
|||
puts("\nGeneric options:");
|
||||
puts(" -b, --bios FILE GBA BIOS file to use");
|
||||
puts(" -c, --cheats FILE Apply cheat codes from a file");
|
||||
puts(" -C, --config OPTION=VALUE Override config value");
|
||||
#ifdef USE_EDITLINE
|
||||
puts(" -d, --debug Use command-line debugger");
|
||||
#endif
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
CXX_GUARD_START
|
||||
|
||||
#include <mgba-util/table.h>
|
||||
|
||||
#include <mgba/internal/debugger/debugger.h>
|
||||
|
||||
struct mArguments {
|
||||
|
@ -21,6 +23,8 @@ struct mArguments {
|
|||
int logLevel;
|
||||
int frameskip;
|
||||
|
||||
struct Table configOverrides;
|
||||
|
||||
enum mDebuggerType debuggerType;
|
||||
bool debugAtStart;
|
||||
bool showHelp;
|
||||
|
|
Loading…
Reference in New Issue