Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/libbb/compare_string_array.c

    r821 r1765  
    1 /* vi:set ts=4:*/
     1/* vi: set sw=4 ts=4: */
    22/*
    33 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    44 */
    55
    6 #include <string.h>
    76#include "libbb.h"
    87
    9 /* returns the array number of the string */
    10 int compare_string_array(const char * const string_array[], const char *key)
     8/* returns the array index of the string */
     9/* (index of first match is returned, or -1) */
     10int index_in_str_array(const char *const string_array[], const char *key)
    1111{
    1212    int i;
     
    1717        }
    1818    }
    19     return -i;
     19    return -1;
    2020}
    2121
     22int index_in_strings(const char *strings, const char *key)
     23{
     24    int idx = 0;
     25
     26    while (strings[0]) {
     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 */
     37/* (index of first match is returned, or -1) */
     38#ifdef UNUSED
     39int index_in_substr_array(const char *const string_array[], const char *key)
     40{
     41    int i;
     42    int len = strlen(key);
     43    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
     54int 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[0]) {
     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;
     69}
Note: See TracChangeset for help on using the changeset viewer.