Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/compare_string_array.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/libbb/compare_string_array.c
r1765 r2725 1 1 /* vi: set sw=4 ts=4: */ 2 2 /* 3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.3 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 4 4 */ 5 5 … … 8 8 /* returns the array index of the string */ 9 9 /* (index of first match is returned, or -1) */ 10 int index_in_str_array(const char *const string_array[], const char *key)10 int FAST_FUNC index_in_str_array(const char *const string_array[], const char *key) 11 11 { 12 12 int i; … … 20 20 } 21 21 22 int index_in_strings(const char *strings, const char *key)22 int FAST_FUNC index_in_strings(const char *strings, const char *key) 23 23 { 24 24 int idx = 0; 25 25 26 while ( strings[0]) {26 while (*strings) { 27 27 if (strcmp(strings, key) == 0) { 28 28 return idx; … … 37 37 /* (index of first match is returned, or -1) */ 38 38 #ifdef UNUSED 39 int index_in_substr_array(const char *const string_array[], const char *key)39 int FAST_FUNC index_in_substr_array(const char *const string_array[], const char *key) 40 40 { 41 41 int i; … … 52 52 #endif 53 53 54 int index_in_substrings(const char *strings, const char *key)54 int FAST_FUNC index_in_substrings(const char *strings, const char *key) 55 55 { 56 int len = strlen(key); 56 int matched_idx = -1; 57 const int len = strlen(key); 57 58 58 59 if (len) { 59 60 int idx = 0; 60 while ( strings[0]) {61 while (*strings) { 61 62 if (strncmp(strings, key, len) == 0) { 62 return idx; 63 if (strings[len] == '\0') 64 return idx; /* exact match */ 65 if (matched_idx >= 0) 66 return -1; /* ambiguous match */ 67 matched_idx = idx; 63 68 } 64 69 strings += strlen(strings) + 1; /* skip NUL */ … … 66 71 } 67 72 } 68 return -1;73 return matched_idx; 69 74 } 75 76 const char* FAST_FUNC nth_string(const char *strings, int n) 77 { 78 while (n) { 79 n--; 80 strings += strlen(strings) + 1; 81 } 82 return strings; 83 } 84 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) 88 { 89 static const char no_yes[] ALIGN1 = 90 "0\0" "off\0" "no\0" 91 "1\0" "on\0" "yes\0"; 92 int ret = index_in_substrings(no_yes, str); 93 return ret / 3; 94 } 95 #endif
Note:
See TracChangeset
for help on using the changeset viewer.