--- SIDPlayer/src/prefs.cpp 2001/01/04 19:54:13 1.2 +++ SIDPlayer/src/prefs.cpp 2001/04/01 12:13:49 1.5 @@ -1,7 +1,7 @@ /* * prefs.cpp - Preferences handling * - * SIDPlayer (C) Copyright 1996-2000 Christian Bauer + * SIDPlayer (C) Copyright 1996-2001 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,60 +48,76 @@ static prefs_desc *find_prefs_desc(const * Initialize preferences */ -void PrefsInit(int argc, char **argv) +void PrefsInit(int &argc, char **&argv) { // Set defaults AddPrefsDefaults(); - // Override prefs with command line arguments - argc--; argv++; - for (; argc>0; argc--, argv++) { + // Override prefs with command line options + for (int i=1; i= argc) { + fprintf(stderr, "Option '%s' must be followed by a value\n", option); continue; } + const char *value = argv[i]; + argv[i] = NULL; // Add/replace prefs item switch (d->type) { case TYPE_STRING: - if (argc < 2) { - printf("WARNING: Argument '%s' must be followed by value\n", *argv); - break; - } - argc--; argv++; if (d->multiple) - PrefsAddString(keyword, *argv); + PrefsAddString(keyword, value); else - PrefsReplaceString(keyword, *argv); + PrefsReplaceString(keyword, value); break; - case TYPE_BOOLEAN: - if (argc > 1 && argv[1][0] != '-') { - argc--; argv++; - PrefsReplaceBool(keyword, !strcmp(*argv, "true") || !strcmp(*argv, "on")); - } else + case TYPE_BOOLEAN: { + if (!strcmp(value, "true") || !strcmp(value, "on") || !strcmp(value, "yes")) PrefsReplaceBool(keyword, true); + else if (!strcmp(value, "false") || !strcmp(value, "off") || !strcmp(value, "no")) + PrefsReplaceBool(keyword, false); + else + fprintf(stderr, "Value for option '%s' must be 'true' or 'false'\n", option); break; + } case TYPE_INT32: - if (argc < 2) { - printf("WARNING: Argument '%s' must be followed by value\n", *argv); - break; - } - argc--; argv++; - PrefsReplaceInt32(keyword, atoi(*argv)); + PrefsReplaceInt32(keyword, atoi(value)); break; default: break; } } + + // Remove processed arguments + for (int i=1; i i) { + k -= i; + for (int j=i+k; jtype != TYPE_END) { + if (list->help) { + const char *typestr, *defstr; + char numstr[32]; + switch (list->type) { + case TYPE_STRING: + typestr = "STRING"; + defstr = PrefsFindString(list->name); + if (defstr == NULL) + defstr = "none"; + break; + case TYPE_BOOLEAN: + typestr = "BOOL"; + if (PrefsFindBool(list->name)) + defstr = "true"; + else + defstr = "false"; + break; + case TYPE_INT32: + typestr = "NUMBER"; + sprintf(numstr, "%d", PrefsFindInt32(list->name)); + defstr = numstr; + break; + default: + typestr = ""; + defstr = "none"; + break; + } + printf(" --%s %s\n %s [default=%s]\n", list->name, typestr, list->help, defstr); + } + list++; + } +} + +void PrefsPrintUsage(void) +{ + printf("\nGeneral options:\n"); + print_options(common_prefs_items); + printf("\nBoolean options are specified as '--OPTION true|on|yes' or\n'--OPTION false|off|no'.\n"); +} + + +/* * Find preferences descriptor by keyword */ static prefs_desc *find_prefs_desc(const char *name, prefs_desc *list) { - while (list->type != TYPE_ANY) { + while (list->type != TYPE_END) { if (strcmp(list->name, name) == 0) return list; list++;