svn commit: trunk/busybox: editors miscutils modutils networking sh etc...

vda at busybox.net vda at busybox.net
Wed Oct 25 12:46:04 UTC 2006


Author: vda
Date: 2006-10-25 05:46:03 -0700 (Wed, 25 Oct 2006)
New Revision: 16435

Log:
use skip_whitespace where appropriate


Modified:
   trunk/busybox/editors/awk.c
   trunk/busybox/editors/sed.c
   trunk/busybox/miscutils/dc.c
   trunk/busybox/modutils/modprobe.c
   trunk/busybox/networking/ifupdown.c
   trunk/busybox/networking/wget.c
   trunk/busybox/shell/bbsh.c
   trunk/busybox/util-linux/mount.c


Changeset:
Modified: trunk/busybox/editors/awk.c
===================================================================
--- trunk/busybox/editors/awk.c	2006-10-25 08:10:26 UTC (rev 16434)
+++ trunk/busybox/editors/awk.c	2006-10-25 12:46:03 UTC (rev 16435)
@@ -1470,7 +1470,7 @@
 		}
 	} else {				/* space split */
 		while (*s) {
-			while (isspace(*s)) s++;
+			s = skip_whitespace(s);
 			if (! *s) break;
 			n++;
 			while (*s && !isspace(*s))

Modified: trunk/busybox/editors/sed.c
===================================================================
--- trunk/busybox/editors/sed.c	2006-10-25 08:10:26 UTC (rev 16434)
+++ trunk/busybox/editors/sed.c	2006-10-25 12:46:03 UTC (rev 16435)
@@ -63,29 +63,29 @@
 
 /* Each sed command turns into one of these structures. */
 typedef struct sed_cmd_s {
-    /* Ordered by alignment requirements: currently 36 bytes on x86 */
+	/* Ordered by alignment requirements: currently 36 bytes on x86 */
 
-    /* address storage */
-    regex_t *beg_match;	/* sed -e '/match/cmd' */
-    regex_t *end_match;	/* sed -e '/match/,/end_match/cmd' */
-    regex_t *sub_match;	/* For 's/sub_match/string/' */
-    int beg_line;		/* 'sed 1p'   0 == apply commands to all lines */
-    int end_line;		/* 'sed 1,3p' 0 == one line only. -1 = last line ($) */
+	/* address storage */
+	regex_t *beg_match;     /* sed -e '/match/cmd' */
+	regex_t *end_match;     /* sed -e '/match/,/end_match/cmd' */
+	regex_t *sub_match;     /* For 's/sub_match/string/' */
+	int beg_line;           /* 'sed 1p'   0 == apply commands to all lines */
+	int end_line;           /* 'sed 1,3p' 0 == one line only. -1 = last line ($) */
 
-    FILE *file;			/* File (sw) command writes to, -1 for none. */
-    char *string;		/* Data string for (saicytb) commands. */
+	FILE *file;             /* File (sw) command writes to, -1 for none. */
+	char *string;           /* Data string for (saicytb) commands. */
 
-    unsigned short which_match;		/* (s) Which match to replace (0 for all) */
+	unsigned short which_match;     /* (s) Which match to replace (0 for all) */
 
-    /* Bitfields (gcc won't group them if we don't) */
-    unsigned int invert:1;			/* the '!' after the address */
-    unsigned int in_match:1;		/* Next line also included in match? */
-    unsigned int no_newline:1;		/* Last line written by (sw) had no '\n' */
-    unsigned int sub_p:1;			/* (s) print option */
+	/* Bitfields (gcc won't group them if we don't) */
+	unsigned int invert:1;          /* the '!' after the address */
+	unsigned int in_match:1;        /* Next line also included in match? */
+	unsigned int no_newline:1;      /* Last line written by (sw) had no '\n' */
+	unsigned int sub_p:1;           /* (s) print option */
 
-    /* GENERAL FIELDS */
-    char cmd;				/* The command char: abcdDgGhHilnNpPqrstwxy:={} */
-    struct sed_cmd_s *next;	/* Next command (linked list, NULL terminated) */
+	/* GENERAL FIELDS */
+	char cmd;               /* The command char: abcdDgGhHilnNpPqrstwxy:={} */
+	struct sed_cmd_s *next; /* Next command (linked list, NULL terminated) */
 } sed_cmd_t;
 
 static const char *const semicolon_whitespace = "; \n\r\t\v";
@@ -162,7 +162,7 @@
 
 static void cleanup_outname(void)
 {
-  if(bbg.outname) unlink(bbg.outname);
+	if(bbg.outname) unlink(bbg.outname);
 }
 
 /* strdup, replacing "\n" with '\n', and "\delimiter" with 'delimiter' */
@@ -343,37 +343,37 @@
 		if(isspace(substr[idx])) continue;
 
 		switch (substr[idx]) {
-			/* Replace all occurrences */
-			case 'g':
-				if (match[0] != '^') sed_cmd->which_match = 0;
-				break;
-			/* Print pattern space */
-			case 'p':
-				sed_cmd->sub_p = 1;
-				break;
-			/* Write to file */
-			case 'w':
-			{
-				char *temp;
-				idx+=parse_file_cmd(sed_cmd,substr+idx,&temp);
+		/* Replace all occurrences */
+		case 'g':
+			if (match[0] != '^') sed_cmd->which_match = 0;
+			break;
+		/* Print pattern space */
+		case 'p':
+			sed_cmd->sub_p = 1;
+			break;
+		/* Write to file */
+		case 'w':
+		{
+			char *temp;
+			idx+=parse_file_cmd(sed_cmd,substr+idx,&temp);
 
-				break;
-			}
-			/* Ignore case (gnu exension) */
-			case 'I':
-				cflags |= REG_ICASE;
-				break;
-			/* Comment */
-			case '#':
-				while(substr[++idx]);
-				/* Fall through */
-			/* End of command */
-			case ';':
-			case '}':
-				goto out;
-			default:
-				bb_error_msg_and_die("bad option in substitution expression");
+			break;
 		}
+		/* Ignore case (gnu exension) */
+		case 'I':
+			cflags |= REG_ICASE;
+			break;
+		/* Comment */
+		case '#':
+			while(substr[++idx]);
+			/* Fall through */
+		/* End of command */
+		case ';':
+		case '}':
+			goto out;
+		default:
+			bb_error_msg_and_die("bad option in substitution expression");
+		}
 	}
 out:
 	/* compile the match string into a regex */
@@ -420,7 +420,7 @@
 	} else if (strchr(":btT", sed_cmd->cmd)) {
 		int length;
 
-		while(isspace(*cmdstr)) cmdstr++;
+		cmdstr = skip_whitespace(cmdstr);
 		length = strcspn(cmdstr, semicolon_whitespace);
 		if (length) {
 			sed_cmd->string = xstrndup(cmdstr, length);
@@ -517,7 +517,7 @@
 		}
 
 		/* skip whitespace before the command */
-		while (isspace(*cmdstr)) cmdstr++;
+		cmdstr = skip_whitespace(cmdstr);
 
 		/* Check for inversion flag */
 		if (*cmdstr == '!') {
@@ -525,7 +525,7 @@
 			cmdstr++;
 
 			/* skip whitespace before the command */
-			while (isspace(*cmdstr)) cmdstr++;
+			cmdstr = skip_whitespace(cmdstr);
 		}
 
 		/* last part (mandatory) will be a command */
@@ -724,7 +724,7 @@
 	fputs(s,file);
 	if(!no_newline) fputc('\n',file);
 
-    if(ferror(file)) {
+	if(ferror(file)) {
 		xfunc_error_retval = 4;  /* It's what gnu sed exits with... */
 		bb_error_msg_and_die(bb_msg_write_error);
 	}
@@ -1167,40 +1167,43 @@
 		FILE *file;
 
 		for (i = optind; i < argc; i++) {
+			struct stat statbuf;
+			int nonstdoutfd;
+
 			if(!strcmp(argv[i], "-") && !bbg.in_place) {
 				add_input_file(stdin);
 				process_files();
-			} else {
-				file = bb_wfopen(argv[i], "r");
-				if (file) {
-					if(bbg.in_place) {
-						struct stat statbuf;
-						int nonstdoutfd;
+				continue;
+			}
+			file = bb_wfopen(argv[i], "r");
+			if (!file) {
+				status = EXIT_FAILURE;
+				continue;
+			}
+			if(!bbg.in_place) {
+				add_input_file(file);
+				continue;
+			}
 
-						bbg.outname=xstrndup(argv[i],strlen(argv[i])+6);
-						strcat(bbg.outname,"XXXXXX");
-						if(-1==(nonstdoutfd=mkstemp(bbg.outname)))
-							bb_error_msg_and_die("no temp file");
-						bbg.nonstdout=fdopen(nonstdoutfd,"w");
+			bbg.outname=xstrndup(argv[i],strlen(argv[i])+6);
+			strcat(bbg.outname,"XXXXXX");
+			if(-1==(nonstdoutfd=mkstemp(bbg.outname)))
+				bb_error_msg_and_die("no temp file");
+			bbg.nonstdout=fdopen(nonstdoutfd,"w");
 
-						/* Set permissions of output file */
+			/* Set permissions of output file */
 
-						fstat(fileno(file),&statbuf);
-						fchmod(nonstdoutfd,statbuf.st_mode);
-						add_input_file(file);
-						process_files();
-						fclose(bbg.nonstdout);
+			fstat(fileno(file),&statbuf);
+			fchmod(nonstdoutfd,statbuf.st_mode);
+			add_input_file(file);
+			process_files();
+			fclose(bbg.nonstdout);
 
-						bbg.nonstdout=stdout;
-						unlink(argv[i]);
-						rename(bbg.outname,argv[i]);
-						free(bbg.outname);
-						bbg.outname=0;
-					} else add_input_file(file);
-				} else {
-					status = EXIT_FAILURE;
-				}
-			}
+			bbg.nonstdout=stdout;
+			unlink(argv[i]);
+			rename(bbg.outname,argv[i]);
+			free(bbg.outname);
+			bbg.outname=0;
 		}
 		if(bbg.input_file_count>bbg.current_input_file) process_files();
 	}

Modified: trunk/busybox/miscutils/dc.c
===================================================================
--- trunk/busybox/miscutils/dc.c	2006-10-25 08:10:26 UTC (rev 16434)
+++ trunk/busybox/miscutils/dc.c	2006-10-25 12:46:03 UTC (rev 16435)
@@ -179,10 +179,10 @@
  */
 static char *get_token(char **buffer)
 {
-	char *start   = NULL;
-	char *current = *buffer;
+	char *start = NULL;
+	char *current;
 
-	while (isspace(*current)) { current++; }
+	current = skip_whitespace(*buffer);
 	if (*current != 0) {
 		start = current;
 		while (!isspace(*current) && *current != 0) { current++; }

Modified: trunk/busybox/modutils/modprobe.c
===================================================================
--- trunk/busybox/modutils/modprobe.c	2006-10-25 08:10:26 UTC (rev 16434)
+++ trunk/busybox/modutils/modprobe.c	2006-10-25 12:46:03 UTC (rev 16435)
@@ -76,15 +76,13 @@
 {
 	char *tag, *value;
 
-	while ( isspace ( *buffer ))
-		buffer++;
+	buffer = skip_whitespace ( buffer );
 	tag = value = buffer;
 	while ( !isspace ( *value ))
 		if (!*value) return 0;
 		else value++;
 	*value++ = 0;
-	while ( isspace ( *value ))
-		value++;
+	value = skip_whitespace ( value );
 	if (!*value) return 0;
 
 	*ptag = tag;
@@ -311,12 +309,10 @@
 				}
 			}
 			else if (( strncmp ( buffer, "include", 7 ) == 0 ) && isspace ( buffer [7] )) {
+				int fdi; char *filename;
 
-				int fdi; char *filename = buffer + 8;
+				filename = skip_whitespace ( buffer + 8 );
 
-				while ( isspace ( *filename ))
-					filename++;
-
 				if (( fdi = open ( filename, O_RDONLY )) >= 0 ) {
 					include_conf(first, current, buffer, buflen, fdi);
 					close(fdi);

Modified: trunk/busybox/networking/ifupdown.c
===================================================================
--- trunk/busybox/networking/ifupdown.c	2006-10-25 08:10:26 UTC (rev 16434)
+++ trunk/busybox/networking/ifupdown.c	2006-10-25 12:46:03 UTC (rev 16435)
@@ -572,10 +572,7 @@
 	}
 
 	/* Skip over leading whitespace */
-	word = *buf;
-	while (isspace(*word)) {
-		++word;
-	}
+	word = skip_whitespace(*buf);
 
 	/* Skip over comments */
 	if (*word == '#') {
@@ -712,9 +709,7 @@
 			}
 
 			/* ship any trailing whitespace */
-			while (isspace(*buf_ptr)) {
-				++buf_ptr;
-			}
+			buf_ptr = skip_whitespace(buf_ptr);
 
 			if (buf_ptr[0] != '\0') {
 				bb_error_msg("too many parameters \"%s\"", buf);

Modified: trunk/busybox/networking/wget.c
===================================================================
--- trunk/busybox/networking/wget.c	2006-10-25 08:10:26 UTC (rev 16434)
+++ trunk/busybox/networking/wget.c	2006-10-25 12:46:03 UTC (rev 16435)
@@ -302,7 +302,7 @@
 
 			s = buf;
 			while (*s != '\0' && !isspace(*s)) ++s;
-			while (isspace(*s)) ++s;
+			s = skip_whitespace(s);
 			// FIXME: no error check
 			// xatou wouldn't work: "200 OK"
 			status = atoi(s);

Modified: trunk/busybox/shell/bbsh.c
===================================================================
--- trunk/busybox/shell/bbsh.c	2006-10-25 08:10:26 UTC (rev 16434)
+++ trunk/busybox/shell/bbsh.c	2006-10-25 12:46:03 UTC (rev 16435)
@@ -119,7 +119,7 @@
 		char *end;
 
 		// Skip leading whitespace and detect end of line.
-		while (isspace(*start)) start++;
+		start = skip_whitespace(start);
 		if (!*start || *start=='#') {
 			if (ENABLE_BBSH_JOBCTL) line->cmdlinelen = start-cmdline;
 			return 0;

Modified: trunk/busybox/util-linux/mount.c
===================================================================
--- trunk/busybox/util-linux/mount.c	2006-10-25 08:10:26 UTC (rev 16434)
+++ trunk/busybox/util-linux/mount.c	2006-10-25 12:46:03 UTC (rev 16435)
@@ -203,8 +203,7 @@
 		while ((buf = xmalloc_getline(f)) != 0) {
 			if (!strncmp(buf, "nodev", 5) && isspace(buf[5]))
 				continue;
-			fs = buf;
-			while (isspace(*fs)) fs++;
+			fs = skip_whitespace(buf);
 			if (*fs=='#' || *fs=='*' || !*fs) continue;
 
 			llist_add_to_end(&list, xstrdup(fs));




More information about the busybox-cvs mailing list