From 74df3ba2d823fde29b28ae3975e4ddfe09e4d69e Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sun, 13 Mar 2022 03:35:18 -0400 Subject: add function string_option to misc.c use in skin_parser.c function string_option allows a string to be found in a supplied list of options Change-Id: If9134090406b74ab11f4ef9ed6517a4b99b9d73e --- apps/misc.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'apps/misc.c') 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(). -- cgit v1.2.3