Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/libbb/compare_string_array.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 532 by niro, Sat Sep 1 22:45:15 2007 UTC revision 816 by niro, Fri Apr 24 18:33:46 2009 UTC
# Line 7  Line 7 
7    
8  /* returns the array index of the string */  /* returns the array index of the string */
9  /* (index of first match is returned, or -1) */  /* (index of first match is returned, or -1) */
10  int index_in_str_array(const char * const string_array[], const char *key)  int FAST_FUNC index_in_str_array(const char *const string_array[], const char *key)
11  {  {
12   int i;   int i;
13    
# Line 19  int index_in_str_array(const char * cons Line 19  int index_in_str_array(const char * cons
19   return -1;   return -1;
20  }  }
21    
22    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  /* returns the array index of the string, even if it matches only a beginning */  /* returns the array index of the string, even if it matches only a beginning */
37  /* (index of first match is returned, or -1) */  /* (index of first match is returned, or -1) */
38  int index_in_substr_array(const char * const string_array[], const char *key)  #ifdef UNUSED
39    int FAST_FUNC index_in_substr_array(const char *const string_array[], const char *key)
40  {  {
41   int i;   int i;
42   int len = strlen(key);   int len = strlen(key);
43   if (!len)   if (len) {
44   return -1;   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    
54    int FAST_FUNC index_in_substrings(const char *strings, const char *key)
55    {
56     int len = strlen(key);
57    
58   for (i = 0; string_array[i] != 0; i++) {   if (len) {
59   if (strncmp(string_array[i], key, len) == 0) {   int idx = 0;
60   return i;   while (*strings) {
61     if (strncmp(strings, key, len) == 0) {
62     return idx;
63     }
64     strings += strlen(strings) + 1; /* skip NUL */
65     idx++;
66   }   }
67   }   }
68   return -1;   return -1;
69  }  }
70    
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    }

Legend:
Removed from v.532  
changed lines
  Added in v.816