Annotation of /tags/mkinitrd-6_2_0/libbb/compare_string_array.c
Parent Directory | Revision Log
Revision 816 -
(hide annotations)
(download)
Fri Apr 24 18:33:46 2009 UTC (15 years, 5 months ago) by niro
Original Path: trunk/mkinitrd-magellan/busybox/libbb/compare_string_array.c
File MIME type: text/plain
File size: 1524 byte(s)
Fri Apr 24 18:33:46 2009 UTC (15 years, 5 months ago) by niro
Original Path: trunk/mkinitrd-magellan/busybox/libbb/compare_string_array.c
File MIME type: text/plain
File size: 1524 byte(s)
-updated to busybox-1.13.4
1 | niro | 532 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||
3 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
4 | */ | ||
5 | |||
6 | #include "libbb.h" | ||
7 | |||
8 | /* returns the array index of the string */ | ||
9 | /* (index of first match is returned, or -1) */ | ||
10 | niro | 816 | int FAST_FUNC index_in_str_array(const char *const string_array[], const char *key) |
11 | niro | 532 | { |
12 | int i; | ||
13 | |||
14 | for (i = 0; string_array[i] != 0; i++) { | ||
15 | if (strcmp(string_array[i], key) == 0) { | ||
16 | return i; | ||
17 | } | ||
18 | } | ||
19 | return -1; | ||
20 | } | ||
21 | |||
22 | niro | 816 | int FAST_FUNC index_in_strings(const char *strings, const char *key) |
23 | { | ||
24 | int idx = 0; | ||
25 | |||
26 | while (*strings) { | ||
27 | if (strcmp(strings, key) == 0) { | ||
28 | return idx; | ||
29 | } | ||
30 | strings += strlen(strings) + 1; /* skip NUL */ | ||
31 | idx++; | ||
32 | } | ||
33 | return -1; | ||
34 | } | ||
35 | |||
36 | niro | 532 | /* returns the array index of the string, even if it matches only a beginning */ |
37 | /* (index of first match is returned, or -1) */ | ||
38 | niro | 816 | #ifdef UNUSED |
39 | int FAST_FUNC index_in_substr_array(const char *const string_array[], const char *key) | ||
40 | niro | 532 | { |
41 | int i; | ||
42 | int len = strlen(key); | ||
43 | niro | 816 | if (len) { |
44 | for (i = 0; string_array[i] != 0; i++) { | ||
45 | if (strncmp(string_array[i], key, len) == 0) { | ||
46 | return i; | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | return -1; | ||
51 | } | ||
52 | #endif | ||
53 | niro | 532 | |
54 | niro | 816 | int FAST_FUNC index_in_substrings(const char *strings, const char *key) |
55 | { | ||
56 | int len = strlen(key); | ||
57 | |||
58 | if (len) { | ||
59 | int idx = 0; | ||
60 | while (*strings) { | ||
61 | if (strncmp(strings, key, len) == 0) { | ||
62 | return idx; | ||
63 | } | ||
64 | strings += strlen(strings) + 1; /* skip NUL */ | ||
65 | idx++; | ||
66 | niro | 532 | } |
67 | } | ||
68 | return -1; | ||
69 | } | ||
70 | niro | 816 | |
71 | const char* FAST_FUNC nth_string(const char *strings, int n) | ||
72 | { | ||
73 | while (n) { | ||
74 | n--; | ||
75 | strings += strlen(strings) + 1; | ||
76 | } | ||
77 | return strings; | ||
78 | } |