1 /* vi: set sw=4 ts=4: */
3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 /* returns the array index of the string */
9 /* (index of first match is returned, or -1) */
10 int FAST_FUNC index_in_str_array(const char *const string_array[], const char *key)
14 for (i = 0; string_array[i] != 0; i++) {
15 if (strcmp(string_array[i], key) == 0) {
22 int FAST_FUNC index_in_strings(const char *strings, const char *key)
27 if (strcmp(strings, key) == 0) {
30 strings += strlen(strings) + 1; /* skip NUL */
36 /* returns the array index of the string, even if it matches only a beginning */
37 /* (index of first match is returned, or -1) */
39 int FAST_FUNC index_in_substr_array(const char *const string_array[], const char *key)
42 int len = strlen(key);
44 for (i = 0; string_array[i] != 0; i++) {
45 if (strncmp(string_array[i], key, len) == 0) {
54 int FAST_FUNC index_in_substrings(const char *strings, const char *key)
57 const int len = strlen(key);
62 if (strncmp(strings, key, len) == 0) {
63 if (strings[len] == '\0')
64 return idx; /* exact match */
66 return -1; /* ambiguous match */
69 strings += strlen(strings) + 1; /* skip NUL */
76 const char* FAST_FUNC nth_string(const char *strings, int n)
80 strings += strlen(strings) + 1;
85 #ifdef UNUSED_SO_FAR /* only brctl.c needs it yet */
86 /* Returns 0 for no, 1 for yes or a negative value on error. */
87 smallint FAST_FUNC yesno(const char *str)
89 static const char no_yes[] ALIGN1 =
92 int ret = index_in_substrings(no_yes, str);