[PATCH] ed stuff #1

Bernhard Fischer rep.nop at aon.at
Thu Jun 1 19:39:42 UTC 2006


Hi,

ed is a) bloated and b) broken.
The attached patchlet starts to look a tiny bit into a)

Comments? Ok to checkin?

   text    data     bss     dec     hex filename
 864338   10244  645924 1520506  17337a busybox_old
 864114   10244  645924 1520282  17329a busybox_unstripped

thanks,
-------------- next part --------------
Index: modutils/modprobe.c
===================================================================
--- modutils/modprobe.c	(revision 15260)
+++ modutils/modprobe.c	(working copy)
@@ -474,8 +474,7 @@
 			/* It's a dep description continuation */
 			p = buffer;
 
-		while ( p && *p && isblank(*p))
-			p++;
+		p = bb_skip_blank(p);
 
 		/* p points to the first dependable module; if NULL, no dependable module */
 		if ( p && *p ) {
@@ -485,7 +484,7 @@
 			char *next;
 			int ext = 0;
 
-			while ( isblank ( *end ) || ( *end == '\\' ))
+			while ( bb_isblank ( *end ) || ( *end == '\\' ))
 				end--;
 
 			do
@@ -506,8 +505,7 @@
 				if ( !deps || ( deps < p )) {
 					deps = p;
 
-					while ( isblank ( *deps ))
-						deps++;
+					deps = bb_skip_blank(deps);
 				}
 				else
 					deps++;
Index: coreutils/fold.c
===================================================================
--- coreutils/fold.c	(revision 15260)
+++ coreutils/fold.c	(working copy)
@@ -113,7 +113,7 @@
 					int logical_end;
 
 					for (logical_end = offset_out - 1; logical_end >= 0; logical_end--) {
-						if (isblank(line_out[logical_end])) {
+						if (bb_isblank(line_out[logical_end])) {
 							break;
 						}
 					}
Index: libbb/Makefile.in
===================================================================
--- libbb/Makefile.in	(revision 15260)
+++ libbb/Makefile.in	(working copy)
@@ -35,7 +35,7 @@
 	getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
 	perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \
 	warn_ignoring_args.c concat_subpath_file.c vfork_daemon_rexec.c \
-	bb_echo.c bb_do_delay.c
+	bb_echo.c bb_do_delay.c skip_blank.c
 
 # conditionally compiled objects:
 LIBBB-$(CONFIG_FEATURE_SHADOWPASSWDS)+=pwd2spwd.c
Index: libbb/skip_blank.c
===================================================================
--- libbb/skip_blank.c	(revision 0)
+++ libbb/skip_blank.c	(revision 0)
@@ -0,0 +1,20 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * skip_blank implementation for busybox
+ *
+ * Copyright (C) 2003  Manuel Novoa III  <mjn3 at codepoet.org>
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ */
+
+#include <ctype.h>
+#include "libbb.h"
+
+const char *bb_skip_blank(const char *s)
+{
+	while (s && (bb_isblank(*s))) {
+		++s;
+	}
+
+	return s;
+}
Index: libbb/skip_whitespace.c
===================================================================
--- libbb/skip_whitespace.c	(revision 15260)
+++ libbb/skip_whitespace.c	(working copy)
@@ -4,20 +4,7 @@
  *
  * Copyright (C) 2003  Manuel Novoa III  <mjn3 at codepoet.org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 
 #include <ctype.h>
Index: include/libbb.h
===================================================================
--- include/libbb.h	(revision 15260)
+++ include/libbb.h	(working copy)
@@ -190,6 +190,7 @@
 extern void chomp(char *s);
 extern void trim(char *s);
 extern const char *bb_skip_whitespace(const char *);
+extern const char *bb_skip_blank(const char *);
 
 extern struct BB_applet *find_applet_by_name(const char *name);
 void run_applet_by_name(const char *name, int argc, char **argv);
@@ -455,6 +456,7 @@
 extern ssize_t bb_xread(int fd, void *buf, size_t count);
 extern void bb_xread_all(int fd, void *buf, size_t count);
 extern unsigned char bb_xread_char(int fd);
+#define bb_isblank(ch) ((ch) == ' ' || (ch) == '\t')
 
 #ifndef COMM_LEN
 /*#include <sched.h> *//* Task command name length */
Index: findutils/xargs.c
===================================================================
--- findutils/xargs.c	(revision 15260)
+++ findutils/xargs.c	(working copy)
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * Mini xargs implementation for busybox
  * Options are supported: "-prtx -n max_arg -s max_chars -e[ouf_str]"
@@ -9,20 +10,8 @@
  * - Mike Rendell <michael at cs.mun.ca>
  * and David MacKenzie <djm at gnu.ai.mit.edu>.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
  * xargs is described in the Single Unix Specification v3 at
  * http://www.opengroup.org/onlinepubs/007904975/utilities/xargs.html
  *
@@ -95,16 +84,12 @@
 					bb_error_msg("%s: exited with status 255; aborting", args[0]);
 					return 124;
 				}
-				if (WIFSTOPPED(status)) {
-					bb_error_msg("%s: stopped by signal %d",
-						args[0], WSTOPSIG(status));
-					return 125;
+				if (WIFSTOPPED(status) || WIFSIGNALED(status)) {
+					bb_error_msg("%s: %sed by signal %d",
+						args[0],
+						WIFSTOPPED(status)?"stopp":"terminat",
+						WIFSTOPPED(status)?WSTOPSIG(status):WTERMSIG(status));
 				}
-				if (WIFSIGNALED(status)) {
-					bb_error_msg("%s: terminated by signal %d",
-						args[0], WTERMSIG(status));
-					return 125;
-				}
 				if (WEXITSTATUS(status) != 0)
 					return 123;
 				return 0;
@@ -124,8 +109,7 @@
 
 static int eof_stdin_detected;
 
-#define ISBLANK(c) ((c) == ' ' || (c) == '\t')
-#define ISSPACE(c) (ISBLANK (c) || (c) == '\n' || (c) == '\r' \
+#define ISSPACE(c) (bb_isblank (c) || (c) == '\n' || (c) == '\r' \
 		    || (c) == '\f' || (c) == '\v')
 
 #ifdef CONFIG_FEATURE_XARGS_SUPPORT_QUOTES
Index: editors/ed.c
===================================================================
--- editors/ed.c	(revision 15260)
+++ editors/ed.c	(working copy)
@@ -54,14 +54,8 @@
 		return EXIT_FAILURE;
 
 	if (argc > 1) {
-		fileName = strdup(argv[1]);
+		fileName = bb_xstrdup(argv[1]);
 
-		if (fileName == NULL) {
-			bb_error_msg("No memory");
-			termEdit();
-			return EXIT_SUCCESS;
-		}
-
 		if (!readLines(fileName, 1)) {
 			termEdit();
 			return EXIT_SUCCESS;
@@ -116,16 +110,13 @@
 			continue;
 		}
 
-		while ((endbuf > buf) && isblank(endbuf[-1]))
+		while ((endbuf > buf) && bb_isblank(endbuf[-1]))
 			endbuf--;
 
 		*endbuf = '\0';
 
-		cp = buf;
+		cp = bb_skip_blank(buf);
 
-		while (isblank(*cp))
-			cp++;
-
 		have1 = FALSE;
 		have2 = FALSE;
 
@@ -138,8 +129,7 @@
 		if (!getNum(&cp, &have1, &num1))
 			continue;
 
-		while (isblank(*cp))
-			cp++;
+		cp = bb_skip_blank(cp);
 
 		if (*cp == ',')
 		{
@@ -180,14 +170,13 @@
 				break;
 
 			case 'f':
-				if (*cp && !isblank(*cp))
+				if (*cp && !bb_isblank(*cp))
 				{
 					bb_error_msg("Bad file command");
 					break;
 				}
 
-				while (isblank(*cp))
-					cp++;
+				cp = bb_skip_blank(cp);
 
 				if (*cp == '\0')
 				{
@@ -218,8 +207,7 @@
 				break;
 
 			case 'k':
-				while (isblank(*cp))
-					cp++;
+				cp = bb_skip_blank(cp);
 
 				if ((*cp < 'a') || (*cp > 'a') || cp[1])
 				{
@@ -239,8 +227,7 @@
 				break;
 
 			case 'q':
-				while (isblank(*cp))
-					cp++;
+				cp = bb_skip_blank(cp);
 
 				if (have1 || *cp)
 				{
@@ -256,10 +243,8 @@
 
 				buf[0] = '\0';
 				fgets(buf, sizeof(buf), stdin);
-				cp = buf;
 
-				while (isblank(*cp))
-					cp++;
+				cp = bb_skip_blank(buf);
 
 				if ((*cp == 'y') || (*cp == 'Y'))
 					return;
@@ -267,14 +252,13 @@
 				break;
 
 			case 'r':
-				if (*cp && !isblank(*cp))
+				if (*cp && !bb_isblank(*cp))
 				{
 					bb_error_msg("Bad read command");
 					break;
 				}
 
-				while (isblank(*cp))
-					cp++;
+				cp = bb_skip_blank(cp);
 
 				if (*cp == '\0')
 				{
@@ -298,14 +282,13 @@
 				break;
 
 			case 'w':
-				if (*cp && !isblank(*cp))
+				if (*cp && !bb_isblank(*cp))
 				{
 					bb_error_msg("Bad write command");
 					break;
 				}
 
-				while (isblank(*cp))
-					cp++;
+				cp = bb_skip_blank(cp);
 
 				if (!have1) {
 					num1 = 1;
@@ -408,7 +391,7 @@
 	strcpy(buf, cmd);
 	cp = buf;
 
-	if (isblank(*cp) || (*cp == '\0'))
+	if (bb_isblank(*cp) || (*cp == '\0'))
 	{
 		bb_error_msg("Bad delimiter for substitute");
 
@@ -689,8 +672,7 @@
 
 	while (TRUE)
 	{
-		while (isblank(*cp))
-			cp++;
+		cp = bb_skip_blank(cp);
 
 		switch (*cp)
 		{
@@ -761,8 +743,7 @@
 
 		value += num * sign;
 
-		while (isblank(*cp))
-			cp++;
+		cp = bb_skip_blank(cp);
 
 		switch (*cp)
 		{
@@ -875,7 +856,6 @@
 	if (fd < 0)
 	{
 		perror(file);
-
 		return FALSE;
 	}
 
@@ -940,8 +920,7 @@
 		bufUsed += cc;
 		bufPtr = bufBase;
 
-	}
-	while (cc > 0);
+	} while (cc > 0);
 
 	if (cc < 0)
 	{


More information about the busybox mailing list