svn commit: trunk/busybox: archival e2fsprogs include libbb miscuti etc...

vda at busybox.net vda at busybox.net
Sun Nov 5 18:05:11 UTC 2006


Author: vda
Date: 2006-11-05 10:05:09 -0800 (Sun, 05 Nov 2006)
New Revision: 16515

Log:
rename: compare_string_array -> index_in_str_array
introduce index_in_substr_array and use it in
iproute2


Modified:
   trunk/busybox/archival/dpkg.c
   trunk/busybox/e2fsprogs/fsck.c
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/compare_string_array.c
   trunk/busybox/miscutils/devfsd.c
   trunk/busybox/networking/ip.c
   trunk/busybox/networking/libiproute/ipaddress.c
   trunk/busybox/networking/libiproute/iproute.c
   trunk/busybox/networking/libiproute/utils.c
   trunk/busybox/util-linux/mount.c


Changeset:
Modified: trunk/busybox/archival/dpkg.c
===================================================================
--- trunk/busybox/archival/dpkg.c	2006-11-05 11:21:34 UTC (rev 16514)
+++ trunk/busybox/archival/dpkg.c	2006-11-05 18:05:09 UTC (rev 16515)
@@ -644,7 +644,7 @@
 			goto fill_package_struct_cleanup; /* Oh no, the dreaded goto statement ! */
 		}
 
-		field_num = compare_string_array(field_names, field_name);
+		field_num = index_in_str_array(field_names, field_name);
 		switch (field_num) {
 			case 0: /* Package */
 				new_node->name = search_name_hashtable(field_value);

Modified: trunk/busybox/e2fsprogs/fsck.c
===================================================================
--- trunk/busybox/e2fsprogs/fsck.c	2006-11-05 11:21:34 UTC (rev 16514)
+++ trunk/busybox/e2fsprogs/fsck.c	2006-11-05 18:05:09 UTC (rev 16515)
@@ -996,11 +996,11 @@
 	if (!fs_match(fs, &fs_type_compiled)) return 1;
 
 	/* Are we ignoring this type? */
-	if(compare_string_array(ignored_types, fs->type) >= 0)
+	if (index_in_str_array(ignored_types, fs->type) >= 0)
 		return 1;
 
 	/* Do we really really want to check this fs? */
-	wanted = compare_string_array(really_wanted, fs->type) >= 0;
+	wanted = index_in_str_array(really_wanted, fs->type) >= 0;
 
 	/* See if the <fsck.fs> program is available. */
 	s = find_fsck(fs->type);

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2006-11-05 11:21:34 UTC (rev 16514)
+++ trunk/busybox/include/libbb.h	2006-11-05 18:05:09 UTC (rev 16515)
@@ -477,7 +477,8 @@
 extern int correct_password(const struct passwd *pw);
 extern char *pw_encrypt(const char *clear, const char *salt);
 extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
-extern int compare_string_array(const char * const string_array[], const char *key);
+extern int index_in_str_array(const char * const string_array[], const char *key);
+extern int index_in_substr_array(const char * const string_array[], const char *key);
 extern void print_login_issue(const char *issue_file, const char *tty);
 extern void print_login_prompt(void);
 #ifdef BB_NOMMU

Modified: trunk/busybox/libbb/compare_string_array.c
===================================================================
--- trunk/busybox/libbb/compare_string_array.c	2006-11-05 11:21:34 UTC (rev 16514)
+++ trunk/busybox/libbb/compare_string_array.c	2006-11-05 18:05:09 UTC (rev 16515)
@@ -3,11 +3,11 @@
  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 
-#include <string.h>
 #include "libbb.h"
 
-/* returns the array number of the string */
-int compare_string_array(const char * const string_array[], const char *key)
+/* returns the array index of the string */
+/* (index of first match is returned, or -1) */
+int index_in_str_array(const char * const string_array[], const char *key)
 {
 	int i;
 
@@ -16,6 +16,22 @@
 			return i;
 		}
 	}
-	return -i;
+	return -1;
 }
 
+/* returns the array index of the string, even if it matches only a beginning */
+/* (index of first match is returned, or -1) */
+int index_in_substr_array(const char * const string_array[], const char *key)
+{
+	int i;
+	int len = strlen(key);
+	if (!len)
+		return -1;
+
+	for (i = 0; string_array[i] != 0; i++) {
+		if (strncmp(string_array[i], key, len) == 0) {
+			return i;
+		}
+	}
+	return -1;
+}

Modified: trunk/busybox/miscutils/devfsd.c
===================================================================
--- trunk/busybox/miscutils/devfsd.c	2006-11-05 11:21:34 UTC (rev 16514)
+++ trunk/busybox/miscutils/devfsd.c	2006-11-05 18:05:09 UTC (rev 16515)
@@ -627,7 +627,7 @@
 			when, name, what,
 			p[0], p[1], p[2], p[3], p[4], p[5], p[6]);
 
-	i = compare_string_array(options, when );
+	i = index_in_str_array(options, when );
 
 	/*"CLEAR_CONFIG"*/
 	if( i == 0)
@@ -673,7 +673,7 @@
 		goto process_config_line_err;
 	}
 
-	i = compare_string_array(options, what );
+	i = index_in_str_array(options, what );
 
 	switch(i)
 	{
@@ -1313,8 +1313,8 @@
 		/* Here on error we should do exit(RV_SYS_ERROR), instead we do exit(EXIT_FAILURE) */
 		hostname[STRING_LENGTH - 1] = '\0';
 
-	/* compare_string_array returns i>=0  */
-	i=compare_string_array(field_names, variable);
+	/* index_in_str_array returns i>=0  */
+	i=index_in_str_array(field_names, variable);
 
 	if ( i > 6 || i < 0 || (i > 1 && gv_info == NULL))
 			return (NULL);

Modified: trunk/busybox/networking/ip.c
===================================================================
--- trunk/busybox/networking/ip.c	2006-11-05 11:21:34 UTC (rev 16514)
+++ trunk/busybox/networking/ip.c	2006-11-05 18:05:09 UTC (rev 16515)
@@ -12,20 +12,11 @@
  * Rani Assaf <rani at magic.metawire.com> 980929:	resolve addresses
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <string.h>
+#include "busybox.h"
 
 #include "libiproute/utils.h"
 #include "libiproute/ip_common.h"
 
-#include "busybox.h"
-
 int ip_main(int argc, char **argv)
 {
 	int ret = EXIT_FAILURE;
@@ -57,5 +48,5 @@
 	if (ret) {
 		bb_show_usage();
 	}
-	return(EXIT_SUCCESS);
+	return EXIT_SUCCESS;
 }

Modified: trunk/busybox/networking/libiproute/ipaddress.c
===================================================================
--- trunk/busybox/networking/libiproute/ipaddress.c	2006-11-05 11:21:34 UTC (rev 16514)
+++ trunk/busybox/networking/libiproute/ipaddress.c	2006-11-05 18:05:09 UTC (rev 16515)
@@ -441,7 +441,7 @@
 	}
 
 	while (argc > 0) {
-		const int option_num = compare_string_array(option, *argv);
+		const int option_num = index_in_str_array(option, *argv);
 		switch (option_num) {
 			case 0: /* to */
 				NEXT_ARG();
@@ -653,7 +653,7 @@
 	req.ifa.ifa_family = preferred_family;
 
 	while (argc > 0) {
-		const int option_num = compare_string_array(option, *argv);
+		const int option_num = index_in_str_array(option, *argv);
 		switch (option_num) {
 			case 0: /* peer */
 			case 1: /* remote */
@@ -800,25 +800,24 @@
 int do_ipaddr(int argc, char **argv)
 {
 	static const char *const commands[] = {
-		"add", "del", "delete", "list", "show", "lst", "flush", 0
+		"add", "delete", "list", "show", "lst", "flush", 0
 	};
 
 	int command_num = 2;
 
 	if (*argv) {
-		command_num = compare_string_array(commands, *argv);
+		command_num = index_in_substr_array(commands, *argv);
 	}
 	switch (command_num) {
 		case 0: /* add */
 			return ipaddr_modify(RTM_NEWADDR, argc-1, argv+1);
-		case 1: /* del */
-		case 2: /* delete */
+		case 1: /* delete */
 			return ipaddr_modify(RTM_DELADDR, argc-1, argv+1);
-		case 3: /* list */
-		case 4: /* show */
-		case 5: /* lst */
+		case 2: /* list */
+		case 3: /* show */
+		case 4: /* lst */
 			return ipaddr_list_or_flush(argc-1, argv+1, 0);
-		case 6: /* flush */
+		case 5: /* flush */
 			return ipaddr_list_or_flush(argc-1, argv+1, 1);
 	}
 	bb_error_msg_and_die("unknown command %s", *argv);

Modified: trunk/busybox/networking/libiproute/iproute.c
===================================================================
--- trunk/busybox/networking/libiproute/iproute.c	2006-11-05 11:21:34 UTC (rev 16514)
+++ trunk/busybox/networking/libiproute/iproute.c	2006-11-05 18:05:09 UTC (rev 16515)
@@ -670,7 +670,7 @@
 	req.r.rtm_tos = 0;
 
 	while (argc > 0) {
-		switch (compare_string_array(options, *argv)) {
+		switch (index_in_str_array(options, *argv)) {
 			case 0: /* from */
 			{
 				inet_prefix addr;
@@ -811,14 +811,16 @@
 int do_iproute(int argc, char **argv)
 {
 	static const char * const ip_route_commands[] =
-		{ "add", "append", "change", "chg", "delete", "del", "get",
+		{ "add", "append", "change", "chg", "delete", "get",
 		"list", "show", "prepend", "replace", "test", "flush", 0 };
-	int command_num = 7;
+	int command_num = 6;
 	unsigned int flags = 0;
 	int cmd = RTM_NEWROUTE;
 
+	/* "Standard" 'ip r a' treats 'a' as 'add', not 'append' */
+	/* It probably means that it is using "first match" rule */
 	if (*argv) {
-		command_num = compare_string_array(ip_route_commands, *argv);
+		command_num = index_in_substr_array(ip_route_commands, *argv);
 	}
 	switch (command_num) {
 		case 0: /* add*/

Modified: trunk/busybox/networking/libiproute/utils.c
===================================================================
--- trunk/busybox/networking/libiproute/utils.c	2006-11-05 11:21:34 UTC (rev 16514)
+++ trunk/busybox/networking/libiproute/utils.c	2006-11-05 18:05:09 UTC (rev 16515)
@@ -263,10 +263,7 @@
 {
 	int len = strlen(cmd);
 
-	if (len > strlen(pattern)) {
-		return -1;
-	}
-	return memcmp(pattern, cmd, len);
+	return strncmp(pattern, cmd, len);
 }
 
 int inet_addr_match(inet_prefix * a, inet_prefix * b, int bits)

Modified: trunk/busybox/util-linux/mount.c
===================================================================
--- trunk/busybox/util-linux/mount.c	2006-11-05 11:21:34 UTC (rev 16514)
+++ trunk/busybox/util-linux/mount.c	2006-11-05 18:05:09 UTC (rev 16515)
@@ -898,7 +898,7 @@
 			};
 			int val = xatoi_u(opteq + 1);
 			*opteq = '\0';
-			switch (compare_string_array(options, opt)) {
+			switch (index_in_str_array(options, opt)) {
 			case 0: // "rsize"
 				data.rsize = val;
 				break;
@@ -940,7 +940,7 @@
 				break;
 			case 12: // "mounthost"
 				mounthost = xstrndup(opteq+1,
-						  strcspn(opteq+1," \t\n\r,"));
+						strcspn(opteq+1," \t\n\r,"));
 				break;
 			case 13: // "mountprog"
 				mountprog = val;
@@ -996,7 +996,7 @@
 				val = 0;
 				opt += 2;
 			}
-			switch (compare_string_array(options, opt)) {
+			switch (index_in_str_array(options, opt)) {
 			case 0: // "bg"
 				bg = val;
 				break;




More information about the busybox-cvs mailing list