aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-11-05 18:05:09 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-11-05 18:05:09 +0000
commitd8df0a9bd2e6fdc7a30156ed4114808b1ff1e3fb (patch)
tree8a5a2783a458269715a05dc48236cae8b1cb1ee0
parenta76b1a148dd871587bfc6a579a6b245684e6b5ce (diff)
downloadbusybox-w32-d8df0a9bd2e6fdc7a30156ed4114808b1ff1e3fb.tar.gz
busybox-w32-d8df0a9bd2e6fdc7a30156ed4114808b1ff1e3fb.tar.bz2
busybox-w32-d8df0a9bd2e6fdc7a30156ed4114808b1ff1e3fb.zip
rename: compare_string_array -> index_in_str_array
introduce index_in_substr_array and use it in iproute2 git-svn-id: svn://busybox.net/trunk/busybox@16515 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--archival/dpkg.c2
-rw-r--r--e2fsprogs/fsck.c4
-rw-r--r--include/libbb.h3
-rw-r--r--libbb/compare_string_array.c24
-rw-r--r--miscutils/devfsd.c8
-rw-r--r--networking/ip.c13
-rw-r--r--networking/libiproute/ipaddress.c19
-rw-r--r--networking/libiproute/iproute.c10
-rw-r--r--networking/libiproute/utils.c5
-rw-r--r--util-linux/mount.c6
10 files changed, 50 insertions, 44 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c
index 2b9c4b82d..9024d41d2 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -644,7 +644,7 @@ static unsigned int fill_package_struct(char *control_buffer)
644 goto fill_package_struct_cleanup; /* Oh no, the dreaded goto statement ! */ 644 goto fill_package_struct_cleanup; /* Oh no, the dreaded goto statement ! */
645 } 645 }
646 646
647 field_num = compare_string_array(field_names, field_name); 647 field_num = index_in_str_array(field_names, field_name);
648 switch (field_num) { 648 switch (field_num) {
649 case 0: /* Package */ 649 case 0: /* Package */
650 new_node->name = search_name_hashtable(field_value); 650 new_node->name = search_name_hashtable(field_value);
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c
index 53657fb25..66b78b624 100644
--- a/e2fsprogs/fsck.c
+++ b/e2fsprogs/fsck.c
@@ -996,11 +996,11 @@ static int ignore(struct fs_info *fs)
996 if (!fs_match(fs, &fs_type_compiled)) return 1; 996 if (!fs_match(fs, &fs_type_compiled)) return 1;
997 997
998 /* Are we ignoring this type? */ 998 /* Are we ignoring this type? */
999 if(compare_string_array(ignored_types, fs->type) >= 0) 999 if (index_in_str_array(ignored_types, fs->type) >= 0)
1000 return 1; 1000 return 1;
1001 1001
1002 /* Do we really really want to check this fs? */ 1002 /* Do we really really want to check this fs? */
1003 wanted = compare_string_array(really_wanted, fs->type) >= 0; 1003 wanted = index_in_str_array(really_wanted, fs->type) >= 0;
1004 1004
1005 /* See if the <fsck.fs> program is available. */ 1005 /* See if the <fsck.fs> program is available. */
1006 s = find_fsck(fs->type); 1006 s = find_fsck(fs->type);
diff --git a/include/libbb.h b/include/libbb.h
index 8c1d78434..ce4b9223c 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -477,7 +477,8 @@ extern void setup_environment(const char *shell, int loginshell, int changeenv,
477extern int correct_password(const struct passwd *pw); 477extern int correct_password(const struct passwd *pw);
478extern char *pw_encrypt(const char *clear, const char *salt); 478extern char *pw_encrypt(const char *clear, const char *salt);
479extern int obscure(const char *old, const char *newval, const struct passwd *pwdp); 479extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
480extern int compare_string_array(const char * const string_array[], const char *key); 480extern int index_in_str_array(const char * const string_array[], const char *key);
481extern int index_in_substr_array(const char * const string_array[], const char *key);
481extern void print_login_issue(const char *issue_file, const char *tty); 482extern void print_login_issue(const char *issue_file, const char *tty);
482extern void print_login_prompt(void); 483extern void print_login_prompt(void);
483#ifdef BB_NOMMU 484#ifdef BB_NOMMU
diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c
index cac93d995..d15578ca3 100644
--- a/libbb/compare_string_array.c
+++ b/libbb/compare_string_array.c
@@ -3,11 +3,11 @@
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 tarball for details.
4 */ 4 */
5 5
6#include <string.h>
7#include "libbb.h" 6#include "libbb.h"
8 7
9/* returns the array number of the string */ 8/* returns the array index of the string */
10int compare_string_array(const char * const string_array[], const char *key) 9/* (index of first match is returned, or -1) */
10int index_in_str_array(const char * const string_array[], const char *key)
11{ 11{
12 int i; 12 int i;
13 13
@@ -16,6 +16,22 @@ int compare_string_array(const char * const string_array[], const char *key)
16 return i; 16 return i;
17 } 17 }
18 } 18 }
19 return -i; 19 return -1;
20} 20}
21 21
22/* returns the array index of the string, even if it matches only a beginning */
23/* (index of first match is returned, or -1) */
24int index_in_substr_array(const char * const string_array[], const char *key)
25{
26 int i;
27 int len = strlen(key);
28 if (!len)
29 return -1;
30
31 for (i = 0; string_array[i] != 0; i++) {
32 if (strncmp(string_array[i], key, len) == 0) {
33 return i;
34 }
35 }
36 return -1;
37}
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c
index 32973d630..de046e818 100644
--- a/miscutils/devfsd.c
+++ b/miscutils/devfsd.c
@@ -627,7 +627,7 @@ static void process_config_line (const char *line, unsigned long *event_mask)
627 when, name, what, 627 when, name, what,
628 p[0], p[1], p[2], p[3], p[4], p[5], p[6]); 628 p[0], p[1], p[2], p[3], p[4], p[5], p[6]);
629 629
630 i = compare_string_array(options, when ); 630 i = index_in_str_array(options, when );
631 631
632 /*"CLEAR_CONFIG"*/ 632 /*"CLEAR_CONFIG"*/
633 if( i == 0) 633 if( i == 0)
@@ -673,7 +673,7 @@ static void process_config_line (const char *line, unsigned long *event_mask)
673 goto process_config_line_err; 673 goto process_config_line_err;
674 } 674 }
675 675
676 i = compare_string_array(options, what ); 676 i = index_in_str_array(options, what );
677 677
678 switch(i) 678 switch(i)
679 { 679 {
@@ -1313,8 +1313,8 @@ static const char *get_variable (const char *variable, void *info)
1313 /* Here on error we should do exit(RV_SYS_ERROR), instead we do exit(EXIT_FAILURE) */ 1313 /* Here on error we should do exit(RV_SYS_ERROR), instead we do exit(EXIT_FAILURE) */
1314 hostname[STRING_LENGTH - 1] = '\0'; 1314 hostname[STRING_LENGTH - 1] = '\0';
1315 1315
1316 /* compare_string_array returns i>=0 */ 1316 /* index_in_str_array returns i>=0 */
1317 i=compare_string_array(field_names, variable); 1317 i=index_in_str_array(field_names, variable);
1318 1318
1319 if ( i > 6 || i < 0 || (i > 1 && gv_info == NULL)) 1319 if ( i > 6 || i < 0 || (i > 1 && gv_info == NULL))
1320 return (NULL); 1320 return (NULL);
diff --git a/networking/ip.c b/networking/ip.c
index fe5714f16..636315597 100644
--- a/networking/ip.c
+++ b/networking/ip.c
@@ -12,20 +12,11 @@
12 * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses 12 * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
13 */ 13 */
14 14
15#include <stdio.h> 15#include "busybox.h"
16#include <stdlib.h>
17#include <unistd.h>
18#include <syslog.h>
19#include <fcntl.h>
20#include <sys/socket.h>
21#include <netinet/in.h>
22#include <string.h>
23 16
24#include "libiproute/utils.h" 17#include "libiproute/utils.h"
25#include "libiproute/ip_common.h" 18#include "libiproute/ip_common.h"
26 19
27#include "busybox.h"
28
29int ip_main(int argc, char **argv) 20int ip_main(int argc, char **argv)
30{ 21{
31 int ret = EXIT_FAILURE; 22 int ret = EXIT_FAILURE;
@@ -57,5 +48,5 @@ int ip_main(int argc, char **argv)
57 if (ret) { 48 if (ret) {
58 bb_show_usage(); 49 bb_show_usage();
59 } 50 }
60 return(EXIT_SUCCESS); 51 return EXIT_SUCCESS;
61} 52}
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index fdbe6117c..fc6cf7beb 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -441,7 +441,7 @@ int ipaddr_list_or_flush(int argc, char **argv, int flush)
441 } 441 }
442 442
443 while (argc > 0) { 443 while (argc > 0) {
444 const int option_num = compare_string_array(option, *argv); 444 const int option_num = index_in_str_array(option, *argv);
445 switch (option_num) { 445 switch (option_num) {
446 case 0: /* to */ 446 case 0: /* to */
447 NEXT_ARG(); 447 NEXT_ARG();
@@ -653,7 +653,7 @@ static int ipaddr_modify(int cmd, int argc, char **argv)
653 req.ifa.ifa_family = preferred_family; 653 req.ifa.ifa_family = preferred_family;
654 654
655 while (argc > 0) { 655 while (argc > 0) {
656 const int option_num = compare_string_array(option, *argv); 656 const int option_num = index_in_str_array(option, *argv);
657 switch (option_num) { 657 switch (option_num) {
658 case 0: /* peer */ 658 case 0: /* peer */
659 case 1: /* remote */ 659 case 1: /* remote */
@@ -800,25 +800,24 @@ static int ipaddr_modify(int cmd, int argc, char **argv)
800int do_ipaddr(int argc, char **argv) 800int do_ipaddr(int argc, char **argv)
801{ 801{
802 static const char *const commands[] = { 802 static const char *const commands[] = {
803 "add", "del", "delete", "list", "show", "lst", "flush", 0 803 "add", "delete", "list", "show", "lst", "flush", 0
804 }; 804 };
805 805
806 int command_num = 2; 806 int command_num = 2;
807 807
808 if (*argv) { 808 if (*argv) {
809 command_num = compare_string_array(commands, *argv); 809 command_num = index_in_substr_array(commands, *argv);
810 } 810 }
811 switch (command_num) { 811 switch (command_num) {
812 case 0: /* add */ 812 case 0: /* add */
813 return ipaddr_modify(RTM_NEWADDR, argc-1, argv+1); 813 return ipaddr_modify(RTM_NEWADDR, argc-1, argv+1);
814 case 1: /* del */ 814 case 1: /* delete */
815 case 2: /* delete */
816 return ipaddr_modify(RTM_DELADDR, argc-1, argv+1); 815 return ipaddr_modify(RTM_DELADDR, argc-1, argv+1);
817 case 3: /* list */ 816 case 2: /* list */
818 case 4: /* show */ 817 case 3: /* show */
819 case 5: /* lst */ 818 case 4: /* lst */
820 return ipaddr_list_or_flush(argc-1, argv+1, 0); 819 return ipaddr_list_or_flush(argc-1, argv+1, 0);
821 case 6: /* flush */ 820 case 5: /* flush */
822 return ipaddr_list_or_flush(argc-1, argv+1, 1); 821 return ipaddr_list_or_flush(argc-1, argv+1, 1);
823 } 822 }
824 bb_error_msg_and_die("unknown command %s", *argv); 823 bb_error_msg_and_die("unknown command %s", *argv);
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index 3b2a677d9..9c3b87040 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -670,7 +670,7 @@ static int iproute_get(int argc, char **argv)
670 req.r.rtm_tos = 0; 670 req.r.rtm_tos = 0;
671 671
672 while (argc > 0) { 672 while (argc > 0) {
673 switch (compare_string_array(options, *argv)) { 673 switch (index_in_str_array(options, *argv)) {
674 case 0: /* from */ 674 case 0: /* from */
675 { 675 {
676 inet_prefix addr; 676 inet_prefix addr;
@@ -811,14 +811,16 @@ static int iproute_get(int argc, char **argv)
811int do_iproute(int argc, char **argv) 811int do_iproute(int argc, char **argv)
812{ 812{
813 static const char * const ip_route_commands[] = 813 static const char * const ip_route_commands[] =
814 { "add", "append", "change", "chg", "delete", "del", "get", 814 { "add", "append", "change", "chg", "delete", "get",
815 "list", "show", "prepend", "replace", "test", "flush", 0 }; 815 "list", "show", "prepend", "replace", "test", "flush", 0 };
816 int command_num = 7; 816 int command_num = 6;
817 unsigned int flags = 0; 817 unsigned int flags = 0;
818 int cmd = RTM_NEWROUTE; 818 int cmd = RTM_NEWROUTE;
819 819
820 /* "Standard" 'ip r a' treats 'a' as 'add', not 'append' */
821 /* It probably means that it is using "first match" rule */
820 if (*argv) { 822 if (*argv) {
821 command_num = compare_string_array(ip_route_commands, *argv); 823 command_num = index_in_substr_array(ip_route_commands, *argv);
822 } 824 }
823 switch (command_num) { 825 switch (command_num) {
824 case 0: /* add*/ 826 case 0: /* add*/
diff --git a/networking/libiproute/utils.c b/networking/libiproute/utils.c
index 552f4bf77..f92179c40 100644
--- a/networking/libiproute/utils.c
+++ b/networking/libiproute/utils.c
@@ -263,10 +263,7 @@ int matches(char *cmd, char *pattern)
263{ 263{
264 int len = strlen(cmd); 264 int len = strlen(cmd);
265 265
266 if (len > strlen(pattern)) { 266 return strncmp(pattern, cmd, len);
267 return -1;
268 }
269 return memcmp(pattern, cmd, len);
270} 267}
271 268
272int inet_addr_match(inet_prefix * a, inet_prefix * b, int bits) 269int inet_addr_match(inet_prefix * a, inet_prefix * b, int bits)
diff --git a/util-linux/mount.c b/util-linux/mount.c
index a9464baee..4069416d9 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -898,7 +898,7 @@ static int nfsmount(struct mntent *mp, int vfsflags, char *filteropts)
898 }; 898 };
899 int val = xatoi_u(opteq + 1); 899 int val = xatoi_u(opteq + 1);
900 *opteq = '\0'; 900 *opteq = '\0';
901 switch (compare_string_array(options, opt)) { 901 switch (index_in_str_array(options, opt)) {
902 case 0: // "rsize" 902 case 0: // "rsize"
903 data.rsize = val; 903 data.rsize = val;
904 break; 904 break;
@@ -940,7 +940,7 @@ static int nfsmount(struct mntent *mp, int vfsflags, char *filteropts)
940 break; 940 break;
941 case 12: // "mounthost" 941 case 12: // "mounthost"
942 mounthost = xstrndup(opteq+1, 942 mounthost = xstrndup(opteq+1,
943 strcspn(opteq+1," \t\n\r,")); 943 strcspn(opteq+1," \t\n\r,"));
944 break; 944 break;
945 case 13: // "mountprog" 945 case 13: // "mountprog"
946 mountprog = val; 946 mountprog = val;
@@ -996,7 +996,7 @@ static int nfsmount(struct mntent *mp, int vfsflags, char *filteropts)
996 val = 0; 996 val = 0;
997 opt += 2; 997 opt += 2;
998 } 998 }
999 switch (compare_string_array(options, opt)) { 999 switch (index_in_str_array(options, opt)) {
1000 case 0: // "bg" 1000 case 0: // "bg"
1001 bg = val; 1001 bg = val;
1002 break; 1002 break;