1 |
|
/* |
2 |
|
* prefs.cpp - Preferences handling |
3 |
|
* |
4 |
< |
* SIDPlayer (C) Copyright 1996-2000 Christian Bauer |
4 |
> |
* SIDPlayer (C) Copyright 1996-2001 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
61 |
|
if (strlen(*argv) < 3 || argv[0][0] != '-' || argv[0][1] != '-') |
62 |
|
continue; |
63 |
|
const char *keyword = *argv + 2; |
64 |
+ |
|
65 |
+ |
// Find descriptor for keyword |
66 |
|
const prefs_desc *d = find_prefs_desc(keyword); |
67 |
+ |
bool negated_bool = false; |
68 |
|
if (d == NULL) { |
69 |
< |
printf("WARNING: Unrecognized argument '%s'\n", *argv); |
70 |
< |
continue; |
69 |
> |
// We also accept boolean arguments in the form '--nokeyword' |
70 |
> |
if (strncmp(keyword, "no", 2) == 0) { |
71 |
> |
negated_bool = true; |
72 |
> |
keyword += 2; |
73 |
> |
d = find_prefs_desc(keyword); |
74 |
> |
} |
75 |
> |
if (d == NULL) { |
76 |
> |
printf("WARNING: Unrecognized argument '%s'\n", *argv); |
77 |
> |
continue; |
78 |
> |
} |
79 |
|
} |
80 |
|
|
81 |
|
// Add/replace prefs item |
92 |
|
PrefsReplaceString(keyword, *argv); |
93 |
|
break; |
94 |
|
|
95 |
< |
case TYPE_BOOLEAN: |
96 |
< |
if (argc > 1 && argv[1][0] != '-') { |
97 |
< |
argc--; argv++; |
98 |
< |
PrefsReplaceBool(keyword, !strcmp(*argv, "true") || !strcmp(*argv, "on")); |
95 |
> |
case TYPE_BOOLEAN: { |
96 |
> |
bool new_value; |
97 |
> |
if (negated_bool) |
98 |
> |
new_value = false; |
99 |
> |
else if (argc > 1 && argv[1][0] != '-') { |
100 |
> |
if (!strcmp(argv[1], "true") || !strcmp(argv[1], "on") || !strcmp(argv[1], "yes")) { |
101 |
> |
new_value = true; |
102 |
> |
argc--; argv++; |
103 |
> |
} else if (!strcmp(argv[1], "false") || !strcmp(argv[1], "off") || !strcmp(argv[1], "no")) { |
104 |
> |
new_value = false; |
105 |
> |
argc--; argv++; |
106 |
> |
} else |
107 |
> |
new_value = true; |
108 |
|
} else |
109 |
< |
PrefsReplaceBool(keyword, true); |
109 |
> |
new_value = true; |
110 |
> |
PrefsReplaceBool(keyword, new_value); |
111 |
|
break; |
112 |
+ |
} |
113 |
|
|
114 |
|
case TYPE_INT32: |
115 |
|
if (argc < 2) { |
146 |
|
|
147 |
|
|
148 |
|
/* |
149 |
+ |
* Print preferences options help |
150 |
+ |
*/ |
151 |
+ |
|
152 |
+ |
static void print_options(const prefs_desc *list) |
153 |
+ |
{ |
154 |
+ |
while (list->type != TYPE_END) { |
155 |
+ |
if (list->help) { |
156 |
+ |
const char *typestr, *defstr; |
157 |
+ |
char numstr[32]; |
158 |
+ |
switch (list->type) { |
159 |
+ |
case TYPE_STRING: |
160 |
+ |
typestr = "STRING"; |
161 |
+ |
defstr = PrefsFindString(list->name); |
162 |
+ |
if (defstr == NULL) |
163 |
+ |
defstr = "none"; |
164 |
+ |
break; |
165 |
+ |
case TYPE_BOOLEAN: |
166 |
+ |
typestr = "BOOL"; |
167 |
+ |
if (PrefsFindBool(list->name)) |
168 |
+ |
defstr = "true"; |
169 |
+ |
else |
170 |
+ |
defstr = "false"; |
171 |
+ |
break; |
172 |
+ |
case TYPE_INT32: |
173 |
+ |
typestr = "NUMBER"; |
174 |
+ |
sprintf(numstr, "%d", PrefsFindInt32(list->name)); |
175 |
+ |
defstr = numstr; |
176 |
+ |
break; |
177 |
+ |
default: |
178 |
+ |
typestr = "<unknown>"; |
179 |
+ |
defstr = "none"; |
180 |
+ |
break; |
181 |
+ |
} |
182 |
+ |
printf(" --%s %s\n %s [default=%s]\n", list->name, typestr, list->help, defstr); |
183 |
+ |
} |
184 |
+ |
list++; |
185 |
+ |
} |
186 |
+ |
} |
187 |
+ |
|
188 |
+ |
void PrefsPrintUsage(void) |
189 |
+ |
{ |
190 |
+ |
printf("\nGeneral options:\n"); |
191 |
+ |
print_options(common_prefs_items); |
192 |
+ |
printf("\nBoolean options can be specified as '--OPTION true|on|yes' and\n'--OPTION false|off|no', or as '--OPTION' and '--noOPTION'.\n"); |
193 |
+ |
} |
194 |
+ |
|
195 |
+ |
|
196 |
+ |
/* |
197 |
|
* Find preferences descriptor by keyword |
198 |
|
*/ |
199 |
|
|
200 |
|
static prefs_desc *find_prefs_desc(const char *name, prefs_desc *list) |
201 |
|
{ |
202 |
< |
while (list->type != TYPE_ANY) { |
202 |
> |
while (list->type != TYPE_END) { |
203 |
|
if (strcmp(list->name, name) == 0) |
204 |
|
return list; |
205 |
|
list++; |