all repos — mgba @ 3c0c8a8f54a4798e61dd3a67645e91b91d2b0725

mGBA Game Boy Advance Emulator

Core: Add enumeration over config items
Vicki Pfau vi@endrift.com
Sun, 05 Mar 2017 17:23:32 -0800
commit

3c0c8a8f54a4798e61dd3a67645e91b91d2b0725

parent

6363a0817886183fefdcd544b190ef809bbb951d

2 files changed, 31 insertions(+), 0 deletions(-)

jump to
M include/mgba/core/config.hinclude/mgba/core/config.h

@@ -19,6 +19,12 @@ struct Configuration overridesTable;

char* port; }; +enum mCoreConfigLevel { + mCONFIG_LEVEL_DEFAULT = 0, + mCONFIG_LEVEL_CUSTOM, + mCONFIG_LEVEL_OVERRIDE, +}; + struct mCoreOptions { char* bios; bool skipBios;

@@ -89,6 +95,8 @@ void mCoreConfigCopyValue(struct mCoreConfig* config, const struct mCoreConfig* src, const char* key);

void mCoreConfigMap(const struct mCoreConfig* config, struct mCoreOptions* opts); void mCoreConfigLoadDefaults(struct mCoreConfig* config, const struct mCoreOptions* opts); + +void mCoreConfigEnumerate(const struct mCoreConfig* config, const char* prefix, void (*handler)(const char* key, const char* value, enum mCoreConfigLevel type, void* user), void* user); struct Configuration* mCoreConfigGetInput(struct mCoreConfig*); struct Configuration* mCoreConfigGetOverrides(struct mCoreConfig*);
M src/core/config.csrc/core/config.c

@@ -29,6 +29,13 @@ #endif

#define SECTION_NAME_MAX 128 +struct mCoreConfigEnumerateData { + void (*handler)(const char* key, const char* value, enum mCoreConfigLevel type, void* user); + const char* prefix; + void* user; + enum mCoreConfigLevel level; +}; + static const char* _lookupValue(const struct mCoreConfig* config, const char* key) { const char* value; if (config->port) {

@@ -391,6 +398,22 @@ ConfigurationSetIntValue(&config->defaultsTable, 0, "mute", opts->mute);

ConfigurationSetIntValue(&config->defaultsTable, 0, "lockAspectRatio", opts->lockAspectRatio); ConfigurationSetIntValue(&config->defaultsTable, 0, "resampleVideo", opts->resampleVideo); ConfigurationSetIntValue(&config->defaultsTable, 0, "suspendScreensaver", opts->suspendScreensaver); +} + +static void _configEnum(const char* key, const char* value, void* user) { + struct mCoreConfigEnumerateData* data = user; + if (!data->prefix || startswith(key, data->prefix)) { + data->handler(key, value, data->level, data->user); + } +} + +void mCoreConfigEnumerate(const struct mCoreConfig* config, const char* prefix, void (*handler)(const char* key, const char* value, enum mCoreConfigLevel type, void* user), void* user) { + struct mCoreConfigEnumerateData handlerData = { handler, prefix, user, mCONFIG_LEVEL_DEFAULT }; + ConfigurationEnumerate(&config->defaultsTable, config->port, _configEnum, &handlerData); + handlerData.level = mCONFIG_LEVEL_CUSTOM; + ConfigurationEnumerate(&config->configTable, config->port, _configEnum, &handlerData); + handlerData.level = mCONFIG_LEVEL_OVERRIDE; + ConfigurationEnumerate(&config->overridesTable, config->port, _configEnum, &handlerData); } // These two are basically placeholders in case the internal layout changes, e.g. for loading separate files