svn commit: trunk/busybox: editors networking shell

vda at busybox.net vda at busybox.net
Sat Mar 24 22:42:29 UTC 2007


Author: vda
Date: 2007-03-24 15:42:29 -0700 (Sat, 24 Mar 2007)
New Revision: 18234

Log:
inetd,ed,msh: data/bss reduction (in mss, more than 9k of it)


Modified:
   trunk/busybox/editors/ed.c
   trunk/busybox/networking/inetd.c
   trunk/busybox/shell/msh.c


Changeset:
Modified: trunk/busybox/editors/ed.c
===================================================================
--- trunk/busybox/editors/ed.c	2007-03-24 20:49:07 UTC (rev 18233)
+++ trunk/busybox/editors/ed.c	2007-03-24 22:42:29 UTC (rev 18234)
@@ -9,8 +9,12 @@
 
 #include "busybox.h"
 
-#define	USERSIZE	1024	/* max line length typed in by user */
-#define	INITBUF_SIZE	1024	/* initial buffer size */
+enum {
+	USERSIZE = sizeof(bb_common_bufsiz1) > 1024 ? 1024
+	         : sizeof(bb_common_bufsiz1) - 1, /* max line length typed in by user */
+	INITBUF_SIZE = 1024, /* initial buffer size */
+};
+
 typedef struct LINE {
 	struct LINE *next;
 	struct LINE *prev;
@@ -18,9 +22,11 @@
 	char data[1];
 } LINE;
 
+#define searchString bb_common_bufsiz1
+
 static LINE lines, *curLine;
 static int curNum, lastNum, marks[26], dirty;
-static char *bufBase, *bufPtr, *fileName, searchString[USERSIZE];
+static char *bufBase, *bufPtr, *fileName;
 static int bufUsed, bufSize;
 
 static void doCommands(void);

Modified: trunk/busybox/networking/inetd.c
===================================================================
--- trunk/busybox/networking/inetd.c	2007-03-24 20:49:07 UTC (rev 18233)
+++ trunk/busybox/networking/inetd.c	2007-03-24 22:42:29 UTC (rev 18234)
@@ -172,7 +172,6 @@
 #include <rpc/pmap_clnt.h>
 #endif
 
-#define _PATH_INETDCONF "/etc/inetd.conf"
 #define _PATH_INETDPID  "/var/run/inetd.pid"
 
 
@@ -327,10 +326,9 @@
 static struct servent *sp;
 static uid_t uid;
 
-static const char *CONFIG = _PATH_INETDCONF;
+static const char *config_filename = "/etc/inetd.conf";
 
 static FILE *fconfig;
-static char line[1024];
 static char *defhost;
 
 /* xstrdup(NULL) returns NULL, but this one
@@ -350,7 +348,7 @@
 		fseek(fconfig, 0L, SEEK_SET);
 		return 1;
 	}
-	fconfig = fopen(CONFIG, "r");
+	fconfig = fopen(config_filename, "r");
 	return (fconfig != NULL);
 }
 
@@ -511,6 +509,8 @@
 
 static char *nextline(void)
 {
+#define line bb_common_bufsiz1
+
 	char *cp;
 	FILE *fd = fconfig;
 
@@ -541,10 +541,12 @@
 		int c;
 
 		c = getc(fconfig);
-		(void) ungetc(c, fconfig);
-		if (c == ' ' || c == '\t')
-			if ((cp = nextline()))
+		ungetc(c, fconfig);
+		if (c == ' ' || c == '\t') {
+			cp = nextline();
+			if (cp)
 				goto again;
+		}
 		*cpp = NULL;
 		/* goto erp; */
 		return NULL;
@@ -924,7 +926,7 @@
 	char protoname[10];
 
 	if (!setconfig()) {
-		bb_perror_msg("%s", CONFIG);
+		bb_perror_msg("%s", config_filename);
 		return;
 	}
 	for (sep = servtab; sep; sep = sep->se_next)
@@ -1281,10 +1283,10 @@
 
 	uid = getuid();
 	if (uid != 0)
-		CONFIG = NULL;
+		config_filename = NULL;
 	if (argc > 0)
-		CONFIG = argv[0];
-	if (CONFIG == NULL)
+		config_filename = argv[0];
+	if (config_filename == NULL)
 		bb_error_msg_and_die("non-root must specify a config file");
 
 #ifdef BB_NOMMU

Modified: trunk/busybox/shell/msh.c
===================================================================
--- trunk/busybox/shell/msh.c	2007-03-24 20:49:07 UTC (rev 18233)
+++ trunk/busybox/shell/msh.c	2007-03-24 22:42:29 UTC (rev 18234)
@@ -13,12 +13,13 @@
  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 
+# include <sys/times.h>
+# include <setjmp.h>
+
 #ifdef STANDALONE
 # ifndef _GNU_SOURCE
 #  define _GNU_SOURCE
 # endif
-# include <setjmp.h>
-# include <sys/times.h>
 # include <sys/types.h>
 # include <sys/stat.h>
 # include <sys/wait.h>
@@ -82,8 +83,6 @@
 	return local_buf;
 }
 #else
-# include <setjmp.h>
-# include <sys/times.h>
 # include "busybox.h"
 extern char **environ;
 #endif
@@ -162,12 +161,10 @@
  */
 typedef void xint;				/* base type of jmp_buf, for not broken compilers */
 
+
 /*
  * shell components
  */
-
-#define	QUOTE	0200
-
 #define	NOBLOCK	((struct op *)NULL)
 #define	NOWORD	((char *)NULL)
 #define	NOWORDS	((char **)NULL)
@@ -297,25 +294,22 @@
 static char *null;				/* null value for variable */
 static int intr;				/* interrupt pending */
 
-static char *trap[_NSIG + 1];
-static char ourtrap[_NSIG + 1];
+/* moved to G: static char *trap[_NSIG + 1]; */
+/* moved to G: static char ourtrap[_NSIG + 1]; */
 static int trapset;				/* trap pending */
 
 static int heedint;				/* heed interrupt signals */
 
 static int yynerrs;				/* yacc */
 
-static char line[LINELIM];
-static char *elinep;
+/* moved to G: static char line[LINELIM]; */
 
 #if ENABLE_FEATURE_EDITING
 static char *current_prompt;
 static line_input_t *line_input_state;
 #endif
 
-static int areanum;				/* current allocation area */
 
-
 /*
  * other functions
  */
@@ -483,30 +477,16 @@
 #define	INSUB()	(e.iop->task == XGRAVE || e.iop->task == XDOLL)
 
 static struct ioarg temparg = { 0, 0, 0, AFID_NOBUF, 0 };	/* temporary for PUSHIO */
-static struct ioarg ioargstack[NPUSH];
+/* moved to G: static struct ioarg ioargstack[NPUSH]; */
 static struct io iostack[NPUSH];
-static struct iobuf sharedbuf = { AFID_NOBUF };
-static struct iobuf mainbuf = { AFID_NOBUF };
+/* moved to G: static struct iobuf sharedbuf = { AFID_NOBUF }; */
+/* moved to G: static struct iobuf mainbuf = { AFID_NOBUF }; */
 static unsigned bufid = AFID_ID;	/* buffer id counter */
 
-#define	PUSHIO(what,arg,gen) ((temparg.what = (arg)), pushio(&temparg,(gen)))
 #define	RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen)))
 
 
 /*
- * parsing & execution environment
- */
-static struct env {
-	char *linep;
-	struct io *iobase;
-	struct io *iop;
-	xint *errpt;				/* void * */
-	int iofd;
-	struct env *oenv;
-} e;
-
-
-/*
  * input generators for IO structure
  */
 static int nlchar(struct ioarg *ap);
@@ -537,6 +517,7 @@
  * IO control
  */
 static void pushio(struct ioarg *argp, int (*f) (struct ioarg *));
+#define PUSHIO(what,arg,gen) ((temparg.what = (arg)), pushio(&temparg,(gen)))
 static int remap(int fd);
 static int openpipe(int *pv);
 static void closepipe(int *pv);
@@ -599,7 +580,6 @@
 static void glob0(char *a0, unsigned a1, int a2,
 				  int (*a3) (char *, char *));
 static void readhere(char **name, char *s, int ec);
-static void pushio(struct ioarg *argp, int (*f) (struct ioarg *));
 static int xxchar(struct ioarg *ap);
 
 struct here {
@@ -705,9 +685,6 @@
 static int isbreak;
 static struct wdblock *wdlist;
 static struct wdblock *iolist;
-static char *trap[_NSIG + 1];
-static char ourtrap[_NSIG + 1];
-static int trapset;				/* trap pending */
 
 #ifdef MSHDEBUG
 static struct var *mshdbg_var;
@@ -731,9 +708,8 @@
 static int nlseen;
 static int iounit = IODEFAULT;
 static YYSTYPE yylval;
-static char *elinep = line + sizeof(line) - 5;
+static char *elinep; /* done in main(): = line + sizeof(line) - 5 */
 
-
 static struct here *inhere;     /* list of hear docs while parsing */
 static struct here *acthere;    /* list of active here documents */
 static struct region *areabot;  /* bottom of area */
@@ -742,8 +718,20 @@
 static void *brktop;
 static void *brkaddr;
 
+/*
+ * parsing & execution environment
+ */
+struct env {
+	char *linep;
+	struct io *iobase;
+	struct io *iop;
+	xint *errpt;		/* void * */
+	int iofd;
+	struct env *oenv;
+};
+
 static struct env e = {
-	line,                   /* linep:  char ptr */
+	NULL /* set to line in main() */, /* linep:  char ptr */
 	iostack,                /* iobase:  struct io ptr */
 	iostack - 1,            /* iop:  struct io ptr */
 	(xint *) NULL,          /* errpt:  void ptr for errors? */
@@ -751,6 +739,29 @@
 	(struct env *) NULL     /* oenv:  struct env ptr */
 };
 
+
+struct globals {
+	char ourtrap[_NSIG + 1];
+	char *trap[_NSIG + 1];
+	struct iobuf sharedbuf; /* in main(): set to { AFID_NOBUF } */
+	struct iobuf mainbuf; /* in main(): set to { AFID_NOBUF } */
+	struct ioarg ioargstack[NPUSH];
+	char filechar_cmdbuf[BUFSIZ];
+	char line[LINELIM];
+	char child_cmd[LINELIM];
+};
+
+#define G (*ptr_to_globals)
+#define ourtrap         (G.ourtrap        )
+#define trap            (G.trap           )
+#define sharedbuf       (G.sharedbuf      )
+#define mainbuf         (G.mainbuf        )
+#define ioargstack      (G.ioargstack     )
+#define filechar_cmdbuf (G.filechar_cmdbuf)
+#define line            (G.line           )
+#define child_cmd       (G.child_cmd      )
+
+
 #ifdef MSHDEBUG
 void print_t(struct op *t)
 {
@@ -1517,7 +1528,7 @@
 
 #define	CMASK	0377
 #define	QUOTE	0200
-#define	QMASK	(CMASK&~QUOTE)
+#define	QMASK	(CMASK & ~QUOTE)
 #define	NOT	'!'					/* might use ^ */
 
 static const char *cclass(const char *p, int sub)
@@ -4011,11 +4022,12 @@
 
 static int grave(int quoted)
 {
+	/* moved to G: static char child_cmd[LINELIM]; */
+
 	const char *cp;
 	int i;
 	int j;
 	int pf[2];
-	static char child_cmd[LINELIM];
 	const char *src;
 	char *dest;
 	int count;
@@ -4823,15 +4835,15 @@
 	}
 #if ENABLE_FEATURE_EDITING
 	if (interactive && isatty(ap->afile)) {
-		static char mycommand[BUFSIZ];
+		/* moved to G: static char filechar_cmdbuf[BUFSIZ]; */
 		static int position = 0, size = 0;
 
 		while (size == 0 || position >= size) {
-			read_line_input(current_prompt, mycommand, BUFSIZ, line_input_state);
-			size = strlen(mycommand);
+			read_line_input(current_prompt, filechar_cmdbuf, BUFSIZ, line_input_state);
+			size = strlen(filechar_cmdbuf);
 			position = 0;
 		}
-		c = mycommand[position];
+		c = filechar_cmdbuf[position];
 		position++;
 		return c;
 	}
@@ -5176,6 +5188,12 @@
 	char *name, **ap;
 	int (*iof) (struct ioarg *);
 
+	PTR_TO_GLOBALS = xzalloc(sizeof(G));
+	sharedbuf.id = AFID_NOBUF;
+	mainbuf.id = AFID_NOBUF;
+	e.linep = line;
+	elinep = line + sizeof(line) - 5;
+
 #if ENABLE_FEATURE_EDITING
 	line_input_state = new_line_input_t(FOR_SHELL);
 #endif




More information about the busybox-cvs mailing list