diff options
author | William Wilgus <wilgus.william@gmail.com> | 2022-03-13 14:31:02 -0400 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2022-03-13 14:31:02 -0400 |
commit | 2352cef6d0757a4d31a18561a09a10f031388e12 (patch) | |
tree | 81d555acb1f7382d7c8c7c4180cfb9aa5b028d8b /apps | |
parent | a62d36d9e7fd89adfd55ae2428fa9df4243bc435 (diff) | |
download | rockbox-2352cef6d0757a4d31a18561a09a10f031388e12.tar.gz rockbox-2352cef6d0757a4d31a18561a09a10f031388e12.zip |
replace more strcmp if then trees with string_option()
1
Change-Id: Ic89bbb2ab41068d09c7bd9caa5ba7f38749b9084
Diffstat (limited to 'apps')
-rw-r--r-- | apps/misc.c | 31 | ||||
-rw-r--r-- | apps/shortcuts.c | 14 |
2 files changed, 16 insertions, 29 deletions
diff --git a/apps/misc.c b/apps/misc.c index 350537dc31..a4958a59ea 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -1389,35 +1389,18 @@ int split_string(char *str, const char split_char, char *vector[], const int vec | |||
1389 | * option list is array of char pointers with the final item set to null | 1389 | * option list is array of char pointers with the final item set to null |
1390 | * ex - const char *option[] = { "op_a", "op_b", "op_c", NULL} | 1390 | * ex - const char *option[] = { "op_a", "op_b", "op_c", NULL} |
1391 | */ | 1391 | */ |
1392 | |||
1393 | int string_option(const char *option, const char *const oplist[], bool ignore_case) | 1392 | int string_option(const char *option, const char *const oplist[], bool ignore_case) |
1394 | { | 1393 | { |
1395 | int i; | ||
1396 | int ifound = -1; | ||
1397 | const char *op; | 1394 | const char *op; |
1398 | if (ignore_case) | 1395 | int (*cmp_fn)(const char*, const char*) = &strcasecmp; |
1396 | if (!ignore_case) | ||
1397 | cmp_fn = strcmp; | ||
1398 | for (int i=0; (op=oplist[i]) != NULL; i++) | ||
1399 | { | 1399 | { |
1400 | for (i=0; (op=oplist[i]) != NULL; i++) | 1400 | if (cmp_fn(op, option) == 0) |
1401 | { | 1401 | return i; |
1402 | if (strcasecmp(op, option) == 0) | ||
1403 | { | ||
1404 | ifound = i; | ||
1405 | break; | ||
1406 | } | ||
1407 | } | ||
1408 | } | ||
1409 | else | ||
1410 | { | ||
1411 | for (i=0; (op=oplist[i]) != NULL; i++) | ||
1412 | { | ||
1413 | if (strcmp(op, option) == 0) | ||
1414 | { | ||
1415 | ifound = i; | ||
1416 | break; | ||
1417 | } | ||
1418 | } | ||
1419 | } | 1402 | } |
1420 | return ifound; | 1403 | return -1; |
1421 | } | 1404 | } |
1422 | 1405 | ||
1423 | /** Open a UTF-8 file and set file descriptor to first byte after BOM. | 1406 | /** Open a UTF-8 file and set file descriptor to first byte after BOM. |
diff --git a/apps/shortcuts.c b/apps/shortcuts.c index f573d6fe4e..754bd83b80 100644 --- a/apps/shortcuts.c +++ b/apps/shortcuts.c | |||
@@ -312,18 +312,22 @@ static int readline_cb(int n, char *buf, void *parameters) | |||
312 | } | 312 | } |
313 | else if (sc && settings_parseline(buf, &name, &value)) | 313 | else if (sc && settings_parseline(buf, &name, &value)) |
314 | { | 314 | { |
315 | if (!strcmp(name, "type")) | 315 | static const char *nm_options[] = {"type", "name", "data", |
316 | "icon", "talkclip", NULL}; | ||
317 | int nm_op = string_option(name, nm_options, false); | ||
318 | |||
319 | if (nm_op == 0) /*type*/ | ||
316 | { | 320 | { |
317 | int t = 0; | 321 | int t = 0; |
318 | for (t=0; t<SHORTCUT_TYPE_COUNT && sc->type == SHORTCUT_UNDEFINED; t++) | 322 | for (t=0; t<SHORTCUT_TYPE_COUNT && sc->type == SHORTCUT_UNDEFINED; t++) |
319 | if (!strcmp(value, type_strings[t])) | 323 | if (!strcmp(value, type_strings[t])) |
320 | sc->type = t; | 324 | sc->type = t; |
321 | } | 325 | } |
322 | else if (!strcmp(name, "name")) | 326 | else if (nm_op == 1) /*name*/ |
323 | { | 327 | { |
324 | strlcpy(sc->name, value, MAX_SHORTCUT_NAME); | 328 | strlcpy(sc->name, value, MAX_SHORTCUT_NAME); |
325 | } | 329 | } |
326 | else if (!strcmp(name, "data")) | 330 | else if (nm_op == 2) /*data*/ |
327 | { | 331 | { |
328 | switch (sc->type) | 332 | switch (sc->type) |
329 | { | 333 | { |
@@ -357,7 +361,7 @@ static int readline_cb(int n, char *buf, void *parameters) | |||
357 | break; | 361 | break; |
358 | } | 362 | } |
359 | } | 363 | } |
360 | else if (!strcmp(name, "icon")) | 364 | else if (nm_op == 3) /*icon*/ |
361 | { | 365 | { |
362 | if (!strcmp(value, "filetype") && sc->type != SHORTCUT_SETTING && sc->u.path[0]) | 366 | if (!strcmp(value, "filetype") && sc->type != SHORTCUT_SETTING && sc->u.path[0]) |
363 | { | 367 | { |
@@ -368,7 +372,7 @@ static int readline_cb(int n, char *buf, void *parameters) | |||
368 | sc->icon = atoi(value); | 372 | sc->icon = atoi(value); |
369 | } | 373 | } |
370 | } | 374 | } |
371 | else if (!strcmp(name, "talkclip")) | 375 | else if (nm_op == 4) /*talkclip*/ |
372 | { | 376 | { |
373 | strlcpy(sc->talk_clip, value, MAX_PATH); | 377 | strlcpy(sc->talk_clip, value, MAX_PATH); |
374 | } | 378 | } |