diff options
Diffstat (limited to 'apps/misc.c')
-rw-r--r-- | apps/misc.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/apps/misc.c b/apps/misc.c index 2668ba714d..350537dc31 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -1384,6 +1384,41 @@ int split_string(char *str, const char split_char, char *vector[], const int vec | |||
1384 | return i; | 1384 | return i; |
1385 | } | 1385 | } |
1386 | 1386 | ||
1387 | /* returns match index from option list | ||
1388 | * returns -1 if option was not found | ||
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} | ||
1391 | */ | ||
1392 | |||
1393 | int string_option(const char *option, const char *const oplist[], bool ignore_case) | ||
1394 | { | ||
1395 | int i; | ||
1396 | int ifound = -1; | ||
1397 | const char *op; | ||
1398 | if (ignore_case) | ||
1399 | { | ||
1400 | for (i=0; (op=oplist[i]) != NULL; i++) | ||
1401 | { | ||
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 | } | ||
1420 | return ifound; | ||
1421 | } | ||
1387 | 1422 | ||
1388 | /** Open a UTF-8 file and set file descriptor to first byte after BOM. | 1423 | /** Open a UTF-8 file and set file descriptor to first byte after BOM. |
1389 | * If no BOM is present this behaves like open(). | 1424 | * If no BOM is present this behaves like open(). |