summaryrefslogtreecommitdiffstats
path: root/apps/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/misc.c')
-rw-r--r--apps/misc.c35
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
return i;
}
+/* returns match index from option list
+ * returns -1 if option was not found
+ * option list is array of char pointers with the final item set to null
+ * ex - const char *option[] = { "op_a", "op_b", "op_c", NULL}
+ */
+
+int string_option(const char *option, const char *const oplist[], bool ignore_case)
+{
+ int i;
+ int ifound = -1;
+ const char *op;
+ if (ignore_case)
+ {
+ for (i=0; (op=oplist[i]) != NULL; i++)
+ {
+ if (strcasecmp(op, option) == 0)
+ {
+ ifound = i;
+ break;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; (op=oplist[i]) != NULL; i++)
+ {
+ if (strcmp(op, option) == 0)
+ {
+ ifound = i;
+ break;
+ }
+ }
+ }
+ return ifound;
+}
/** Open a UTF-8 file and set file descriptor to first byte after BOM.
* If no BOM is present this behaves like open().