aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/config.c b/src/config.c
index d841739..48d4208 100644
--- a/src/config.c
+++ b/src/config.c
@@ -13,8 +13,9 @@
#include "path.h"
static void usage(char const *name) {
- printf("Usage: %s [-c <carts>] [-S <mode>] [-v[v[v]]]\n"
+ printf("Usage: %s [-c <carts>] [-d] [-S <mode>] [-v[v[v]]]\n"
" -c <carts> Carts directory.\n"
+ " -d Print additional debug statistics.\n"
" -S <mode> Scale mode: 'pp' (default), 'fill' or 'stretch'.\n"
" -v[v[v]] Increasingly verbose logging.\n",
pw_basename(name));
@@ -78,6 +79,21 @@ static bool parse_log_priority(char const *s, SDL_LogPriority *l) {
return true;
}
+static bool parse_bool(char const *s, bool *b) {
+ struct named_value values[] = {
+ {"no", false}, {"false", false}, {"0", false},
+ {"yes", true}, {"true", true}, {"1", true},
+ };
+ int v;
+ if (!parse_named_value(values, SDL_arraysize(values), s, &v)) {
+ SDL_SetError("invalid boolean flag '%s'", s);
+ return false;
+ }
+
+ *b = (bool)v;
+ return true;
+}
+
static void parse_config_ini(struct pw_config *config) {
char ini[1024];
if (!pw_pathjoin(ini, sizeof(ini), config->carts, "config.ini", NULL)) {
@@ -109,7 +125,12 @@ static void parse_config_ini(struct pw_config *config) {
continue;
}
- if (!SDL_strcmp(key, "carts")) {
+ if (!SDL_strcmp(key, "debug")) {
+ if (!parse_bool(value, &config->debug)) {
+ SDL_LogWarn(0, "%s", SDL_GetError());
+ SDL_ClearError();
+ }
+ } else if (!SDL_strcmp(key, "carts")) {
if (config->carts) {
SDL_free(config->carts);
}
@@ -168,7 +189,7 @@ struct pw_config *pw_config_load(int argc, char **argv) {
#if defined(_POSIX_VERSION)
int c;
optind = 1;
- while ((c = getopt(argc, argv, ":hc:S:v")) != -1) {
+ while ((c = getopt(argc, argv, ":hc:dS:v")) != -1) {
switch (c) {
case 'h':
usage(name);
@@ -180,6 +201,9 @@ struct pw_config *pw_config_load(int argc, char **argv) {
}
config->carts = SDL_strdup(optarg);
break;
+ case 'd':
+ config->debug = true;
+ break;
case 'S':
if (!parse_scale_mode(optarg, &config->mode)) {
goto cleanup;