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/misc.c | |
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/misc.c')
-rw-r--r-- | apps/misc.c | 31 |
1 files changed, 7 insertions, 24 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. |