svn commit: trunk/busybox: networking/libiproute shell

vda at busybox.net vda at busybox.net
Mon Jan 1 06:00:39 UTC 2007


Author: vda
Date: 2006-12-31 22:00:38 -0800 (Sun, 31 Dec 2006)
New Revision: 17123

Log:
msh: double "static char line[LINELIM]" etc deleted.
massive amounts of assignments-in-ifs deleted
(some of which were VERY nasty)


Modified:
   trunk/busybox/networking/libiproute/rt_names.c
   trunk/busybox/shell/msh.c


Changeset:
Modified: trunk/busybox/networking/libiproute/rt_names.c
===================================================================
--- trunk/busybox/networking/libiproute/rt_names.c	2006-12-31 20:40:20 UTC (rev 17122)
+++ trunk/busybox/networking/libiproute/rt_names.c	2007-01-01 06:00:38 UTC (rev 17123)
@@ -228,7 +228,7 @@
 #if ENABLE_FEATURE_IP_RULE
 const char* rtnl_rtrealm_n2a(int id, char *buf, int len)
 {
-	if (id<0 || id>=256) {
+	if (id < 0 || id >= 256) {
 		snprintf(buf, len, "%d", id);
 		return buf;
 	}
@@ -257,7 +257,7 @@
 
 const char * rtnl_dsfield_n2a(int id, char *buf, int len)
 {
-	if (id<0 || id>=256) {
+	if (id < 0 || id >= 256) {
 		snprintf(buf, len, "%d", id);
 		return buf;
 	}

Modified: trunk/busybox/shell/msh.c
===================================================================
--- trunk/busybox/shell/msh.c	2006-12-31 20:40:20 UTC (rev 17122)
+++ trunk/busybox/shell/msh.c	2007-01-01 06:00:38 UTC (rev 17123)
@@ -138,7 +138,7 @@
 
 /* Strings for names to make debug easier */
 #ifdef MSHDEBUG
-static char *T_CMD_NAMES[] = {
+static const char *const T_CMD_NAMES[] = {
 	"PLACEHOLDER",
 	"TCOM",
 	"TPAREN",
@@ -448,11 +448,11 @@
 	char task;					/* reason for pushed IO */
 };
 
-//static    struct  io  iostack[NPUSH];
+//static struct io iostack[NPUSH];
 #define	XOTHER	0				/* none of the below */
 #define	XDOLL	1				/* expanding ${} */
 #define	XGRAVE	2				/* expanding `'s */
-#define	XIO	3					/* file IO */
+#define	XIO	3				/* file IO */
 
 /* in substitution */
 #define	INSUB()	(e.iop->task == XGRAVE || e.iop->task == XDOLL)
@@ -694,8 +694,6 @@
 static char *trap[_NSIG + 1];
 static char ourtrap[_NSIG + 1];
 static int trapset;				/* trap pending */
-static int yynerrs;				/* yacc */
-static char line[LINELIM];
 
 #ifdef MSHDEBUG
 static struct var *mshdbg_var;
@@ -746,7 +744,6 @@
 };
 
 #ifdef MSHDEBUG
-void print_t(struct op *t);
 void print_t(struct op *t)
 {
 	DBGPRINTF(("T: t=%p, type %s, words=%p, IOword=%p\n", t,
@@ -759,7 +756,6 @@
 	return;
 }
 
-void print_tree(struct op *head);
 void print_tree(struct op *head)
 {
 	if (head == NULL) {
@@ -802,7 +798,8 @@
 	DBGPRINTF(("MSH_MAIN: argc %d, environ %p\n", argc, environ));
 
 	initarea();
-	if ((ap = environ) != NULL) {
+	ap = environ;
+	if (ap != NULL) {
 		while (*ap)
 			assign(*ap++, !COPYV);
 		for (ap = environ; *ap;)
@@ -989,7 +986,7 @@
 
 	cp = m;
 	for (c = 'a'; c <= 'z'; c++)
-		if (flag[(int) c])
+		if (flag[c])
 			*cp++ = c;
 	*cp = 0;
 	setval(lookup("-"), m);
@@ -1105,7 +1102,8 @@
 		leave();
 	}
 
-	if ((i = trapset) != 0) {
+	i = trapset;
+	if (i != 0) {
 		trapset = 0;
 		runtrap(i);
 	}
@@ -1185,7 +1183,8 @@
 
 	DBGPRINTF(("QUITENV: e.oenv=%p\n", e.oenv));
 
-	if ((ep = e.oenv) != NULL) {
+	ep = e.oenv;
+	if (ep != NULL) {
 		fd = e.iofd;
 		e = *ep;
 		/* should close `'d files */
@@ -1246,18 +1245,20 @@
 {
 	char *cp;
 
-	if ((cp = getcell(n)) == 0)
+	cp = getcell(n);
+	if (cp == 0)
 		err("out of string space");
 	return cp;
 }
 
 static char *strsave(char *s, int a)
 {
-	char *cp, *xp;
+	char *cp;
 
-	if ((cp = space(strlen(s) + 1)) != NULL) {
-		setarea((char *) cp, a);
-		for (xp = cp; (*xp++ = *s++) != '\0';);
+	cp = space(strlen(s) + 1);
+	if (cp != NULL) {
+		setarea(cp, a);
+		strcpy(cp, s);
 		return cp;
 	}
 	return "";
@@ -1276,7 +1277,8 @@
 {
 	char *trapstr;
 
-	if ((trapstr = trap[i]) == NULL)
+	trapstr = trap[i];
+	if (trapstr == NULL)
 		return;
 
 	if (i == 0)
@@ -1488,7 +1490,8 @@
 		sc = *s++ & QMASK;
 		switch (pc) {
 		case '[':
-			if ((p = cclass(p, sc)) == NULL)
+			p = cclass(p, sc);
+			if (p == NULL)
 				return 0;
 			break;
 
@@ -1633,7 +1636,8 @@
 {
 	struct region *p;
 
-	if ((p = (struct region *) cp) != NULL) {
+	p = (struct region *) cp;
+	if (p != NULL) {
 		p--;
 		if (p < areanxt)
 			areanxt = p;
@@ -1716,7 +1720,8 @@
 
 	if (t != NULL) {
 		while ((c = yylex(0)) == '|') {
-			if ((p = command(CONTIN)) == NULL) {
+			p = command(CONTIN);
+			if (p == NULL) {
 				DBGPRINTF8(("PIPELINE: error!\n"));
 				SYNTAXERR;
 			}
@@ -1748,7 +1753,8 @@
 
 	if (t != NULL) {
 		while ((c = yylex(0)) == LOGAND || c == LOGOR) {
-			if ((p = pipeline(CONTIN)) == NULL) {
+			p = pipeline(CONTIN);
+			if (p == NULL) {
 				DBGPRINTF8(("ANDOR: error!\n"));
 				SYNTAXERR;
 			}
@@ -1773,16 +1779,19 @@
 	t = andor();
 
 	if (t != NULL) {
-		if ((peeksym = yylex(0)) == '&')
+		peeksym = yylex(0);
+		if (peeksym == '&')
 			t = block(TASYNC, t, NOBLOCK, NOWORDS);
 
 		while ((c = yylex(0)) == ';' || c == '&'
 			   || (multiline && c == '\n')) {
 
-			if ((p = andor()) == NULL)
+			p = andor();
+			if (p== NULL)
 				return t;
 
-			if ((peeksym = yylex(0)) == '&')
+			peeksym = yylex(0);
+			if (peeksym == '&')
 				p = block(TASYNC, p, NOBLOCK, NOWORDS);
 
 			t = list(t, p);
@@ -1803,7 +1812,8 @@
 
 	DBGPRINTF7(("SYNIO: enter, cf=%d\n", cf));
 
-	if ((c = yylex(cf)) != '<' && c != '>') {
+	c = yylex(cf);
+	if (c != '<' && c != '>') {
 		peeksym = c;
 		return 0;
 	}
@@ -1892,7 +1902,8 @@
 	switch (c) {
 	default:
 		peeksym = c;
-		if ((t = simple()) == NULL) {
+		t = simple();
+		if (t == NULL) {
 			if (iolist == NULL)
 				return NULL;
 			t = newtp();
@@ -1916,7 +1927,8 @@
 		t->str = yylval.cp;
 		multiline++;
 		t->words = wordlist();
-		if ((c = yylex(0)) != '\n' && c != ';')
+		c = yylex(0);
+		if (c != '\n' && c != ';')
 			peeksym = c;
 		t->left = dogroup(0);
 		multiline--;
@@ -2017,7 +2029,8 @@
 	int c;
 	struct op *t;
 
-	if ((c = yylex(0)) != THEN) {
+	c = yylex(0);
+	if (c != THEN) {
 		peeksym = c;
 		return NULL;
 	}
@@ -2037,7 +2050,8 @@
 
 	switch (c = yylex(0)) {
 	case ELSE:
-		if ((t = c_list()) == NULL)
+		t = c_list();
+		if (t == NULL)
 			SYNTAXERR;
 		return t;
 
@@ -2079,7 +2093,8 @@
 	t->words = pattern();
 	musthave(')', 0);
 	t->left = c_list();
-	if ((peeksym = yylex(CONTIN)) != ESAC)
+	peeksym = yylex(CONTIN);
+	if (peeksym != ESAC)
 		musthave(BREAK, CONTIN);
 
 	DBGPRINTF7(("CASEPART: made newtp(TPAT, t=%p)\n", t));
@@ -2096,7 +2111,8 @@
 		musthave(WORD, cf);
 		word(yylval.cp);
 		cf = 0;
-	} while ((c = yylex(0)) == '|');
+		c = yylex(0);
+	} while (c == '|');
 	peeksym = c;
 	word(NOWORD);
 
@@ -2107,7 +2123,8 @@
 {
 	int c;
 
-	if ((c = yylex(0)) != IN) {
+	c = yylex(0);
+	if (c != IN) {
 		peeksym = c;
 		return NULL;
 	}
@@ -2210,7 +2227,6 @@
 	word(NOWORD);
 	t->words = copyw();
 
-
 	return t;
 }
 
@@ -2270,7 +2286,8 @@
 	int c, c1;
 	int atstart;
 
-	if ((c = peeksym) > 0) {
+	c = peeksym;
+	if (c > 0) {
 		peeksym = 0;
 		if (c == '\n')
 			startl = 1;
@@ -2475,7 +2492,8 @@
 {
 	char *t;
 
-	if ((t = getcell(size)) == NULL) {
+	t = getcell(size);
+	if (t == NULL) {
 		DBGPRINTF2(("TREE: getcell(%d) failed!\n", size));
 		prs("command line too complicated\n");
 		fail();
@@ -2556,7 +2574,8 @@
 		{
 			int pv[2];
 
-			if ((rv = openpipe(pv)) < 0)
+			rv = openpipe(pv);
+			if (rv < 0)
 				break;
 			pv[0] = remap(pv[0]);
 			pv[1] = remap(pv[1]);
@@ -2608,7 +2627,8 @@
 	case TOR:
 	case TAND:
 		rv = execute(t->left, pin, pout, 0);
-		if ((t1 = t->right) != NULL && (rv == 0) == (t->type == TAND))
+		t1 = t->right;
+		if (t1 != NULL && (rv == 0) == (t->type == TAND))
 			rv = execute(t1, pin, pout, 0);
 		break;
 
@@ -2655,14 +2675,16 @@
 		break;
 
 	case TCASE:
-		if ((cp = evalstr(t->str, DOSUB | DOTRIM)) == 0)
+		cp = evalstr(t->str, DOSUB | DOTRIM);
+		if (cp == 0)
 			cp = "";
 
 		DBGPRINTF7(("EXECUTE: TCASE, t->str is %s, cp is %s\n",
 					((t->str == NULL) ? "NULL" : t->str),
 					((cp == NULL) ? "NULL" : cp)));
 
-		if ((t1 = findcase(t->left, cp)) != NULL) {
+		t1 = findcase(t->left, cp);
+		if (t1 != NULL) {
 			DBGPRINTF7(("EXECUTE: TCASE, calling execute(t=%p, t1=%p)...\n", t, t1));
 			rv = execute(t1, pin, pout, 0);
 			DBGPRINTF7(("EXECUTE: TCASE, back from execute(t=%p, t1=%p)...\n", t, t1));
@@ -2695,7 +2717,8 @@
 		fail();
 	}
 
-	if ((i = trapset) != 0) {
+	i = trapset;
+	if (i != 0) {
 		trapset = 0;
 		runtrap(i);
 	}
@@ -2852,7 +2875,8 @@
 		closepipe(pout);
 	}
 
-	if ((iopp = t->ioact) != NULL) {
+	iopp = t->ioact;
+	if (iopp != NULL) {
 		if (shcom != NULL && shcom != doexec) {
 			prs(cp);
 			err(": cannot redirect shell command");
@@ -3069,7 +3093,8 @@
 			if (errno != EINTR || canintr)
 				break;
 		} else {
-			if ((rv = WAITSIG(s)) != 0) {
+			rv = WAITSIG(s);
+			if (rv != 0) {
 				if (rv < NSIGNAL) {
 					if (signame[rv] != NULL) {
 						if (pid != lastpid) {
@@ -3210,13 +3235,15 @@
 	ofail = failpt;
 	rv = -1;
 
-	if (newenv(setjmp(errpt = ev)) == 0) {
+	errpt = ev;
+	if (newenv(setjmp(errpt)) == 0) {
 		wdlist = 0;
 		iolist = 0;
 		pushio(argp, f);
 		e.iobase = e.iop;
 		yynerrs = 0;
-		if (setjmp(failpt = rt) == 0 && yyparse() == 0)
+		failpt = rt;
+		if (setjmp(failpt) == 0 && yyparse() == 0)
 			rv = execute(outtree, NOPIPE, NOPIPE, 0);
 		quitenv();
 	} else {
@@ -3287,7 +3314,8 @@
 {
 	char *cp, *er;
 
-	if ((cp = t->words[1]) == NULL && (cp = homedir->value) == NULL)
+	cp = t->words[1];
+	if (cp == NULL && (cp = homedir->value) == NULL)
 		er = ": no home directory";
 	else if (chdir(cp) < 0)
 		er = ": bad directory";
@@ -3337,7 +3365,8 @@
 	int i, n;
 	char *cp;
 
-	if ((cp = t->words[1]) == NULL) {
+	cp = t->words[1];
+	if (cp == NULL) {
 		i = umask(0);
 		umask(i);
 		for (n = 3 * 4; (n -= 3) >= 0;)
@@ -3363,7 +3392,8 @@
 		return 1;
 	execflg = 1;
 	ofail = failpt;
-	if (setjmp(failpt = ex) == 0)
+	failpt = ex;
+	if (setjmp(failpt) == 0)
 		execute(t, NOPIPE, NOPIPE, FEXEC);
 	failpt = ofail;
 	execflg = 0;
@@ -3379,7 +3409,8 @@
 
 	DBGPRINTF(("DODOT: enter, t=%p, tleft %p, tright %p, e.linep is %s\n", t, t->left, t->right, ((e.linep == NULL) ? "NULL" : e.linep)));
 
-	if ((cp = t->words[1]) == NULL) {
+	cp = t->words[1];
+	if (cp == NULL) {
 		DBGPRINTF(("DODOT: bad args, ret 0\n"));
 		return 0;
 	} else {
@@ -3402,7 +3433,8 @@
 		for (i = 0; (*tp++ = cp[i++]) != '\0';);
 
 		/* Original code */
-		if ((i = open(e.linep, 0)) >= 0) {
+		i = open(e.linep, 0);
+		if (i >= 0) {
 			exstat = 0;
 			maltmp = remap(i);
 			DBGPRINTF(("DODOT: remap=%d, exstat=%d, e.iofd %d, i %d, e.linep is %s\n", maltmp, exstat, e.iofd, i, e.linep));
@@ -3427,7 +3459,8 @@
 	int i;
 	char *cp;
 
-	if ((cp = t->words[1]) != NULL) {
+	cp = t->words[1];
+	if (cp != NULL) {
 		i = getn(cp);
 		if (i == 0)
 			return 0;
@@ -3448,10 +3481,14 @@
 		return 1;
 	}
 	for (wp = t->words + 1; *wp; wp++) {
-		for (cp = e.linep; !nl && cp < elinep - 1; cp++)
-			if ((nb = read(0, cp, sizeof(*cp))) != sizeof(*cp) ||
-				(nl = (*cp == '\n')) || (wp[1] && any(*cp, ifs->value)))
+		for (cp = e.linep; !nl && cp < elinep - 1; cp++) {
+			nb = read(0, cp, sizeof(*cp));
+			if (nb != sizeof(*cp) || (nl = (*cp == '\n'))
+			 || (wp[1] && any(*cp, ifs->value))
+			) {
 				break;
+			}
+		}
 		*cp = 0;
 		if (nb <= 0)
 			break;
@@ -3508,7 +3545,8 @@
 {
 	int n;
 
-	if ((n = getn(s)) < 0 || n > _NSIG) {
+	n = getn(s);
+	if (n < 0 || n > _NSIG) {
 		err("trap: bad signal number");
 		n = 0;
 	}
@@ -3639,7 +3677,8 @@
 	char *cp;
 	int n;
 
-	if ((cp = t->words[1]) == NULL) {
+	cp = t->words[1];
+	if (cp == NULL) {
 		for (vp = vlist; vp; vp = vp->next)
 			varput(vp->name, 1);
 		return 0;
@@ -3746,7 +3785,8 @@
 	wp = NULL;
 	wb = NULL;
 	wf = NULL;
-	if (newenv(setjmp(errpt = ev)) == 0) {
+	errpt = ev;
+	if (newenv(setjmp(errpt)) == 0) {
 		while (*ap && isassign(*ap))
 			expand(*ap++, &wb, f & ~DOGLOB);
 		if (flag['k']) {
@@ -3861,8 +3901,9 @@
 	scanequals = f & DOKEY;
 	foundequals = 0;
 
-  loop:
-	switch (c = subgetc('"', foundequals)) {
+ loop:
+	c = subgetc('"', foundequals);
+	switch (c) {
 	case 0:
 		if (sp == e.linep)
 			return 0;
@@ -3924,7 +3965,7 @@
 
 	DBGPRINTF3(("SUBGETC: enter, quoted=%d\n", quoted));
 
-  again:
+ again:
 	c = my_getc(ec);
 	if (!INSUB() && ec != '\'') {
 		if (c == '`') {
@@ -4231,7 +4272,8 @@
 {
 	char *s;
 
-	if ((s = as) != NULL)
+	s = as;
+	if (s != NULL)
 		while (*s)
 			*s++ &= ~QUOTE;
 	return as;
@@ -4406,7 +4448,8 @@
 
 	if (wb == NULL)
 		wb = newword(NSTART);
-	if ((nw = wb->w_nword) >= wb->w_bsize) {
+	nw = wb->w_nword;
+	if (nw >= wb->w_bsize) {
 		wb2 = newword(nw * 2);
 		memcpy((char *) wb2->w_words, (char *) wb->w_words,
 			   nw * sizeof(char *));
@@ -4454,11 +4497,11 @@
 	int c;
 	unsigned n;
 
-
 	v2 = globv;
 
-  top:
-	if ((n = (int) (lim - base)) <= v2)
+ top:
+	n = (int) (lim - base);
+	if (n <= v2)
 		return;
 	n = v2 * (n / (2 * v2));
 	hptr = lptr = base + n;
@@ -4466,7 +4509,8 @@
 	j = lim - v2;
 	for (;;) {
 		if (i < lptr) {
-			if ((c = (*func) (i, lptr)) == 0) {
+			c = (*func) (i, lptr);
+			if (c == 0) {
 				glob2(i, lptr -= v2);
 				continue;
 			}
@@ -4476,9 +4520,10 @@
 			}
 		}
 
-	  begin:
+ begin:
 		if (j > hptr) {
-			if ((c = (*func) (hptr, j)) == 0) {
+			c = (*func) (hptr, j);
+			if (c == 0) {
 				glob2(hptr += v2, j);
 				goto begin;
 			}
@@ -4595,7 +4640,8 @@
 
 	for (; e.iop >= e.iobase; e.iop--) {
 		RCPRINTF(("READC: e.iop %p, peekc 0x%x\n", e.iop, e.iop->peekc));
-		if ((c = e.iop->peekc) != '\0') {
+		c = e.iop->peekc;
+		if (c != '\0') {
 			e.iop->peekc = 0;
 			return c;
 		} else {
@@ -4707,7 +4753,7 @@
 	if (fn == filechar || fn == linechar)
 		e.iop->task = XIO;
 	else if (fn == (int (*)(struct ioarg *)) gravechar
-			 || fn == (int (*)(struct ioarg *)) qgravechar)
+	 || fn == (int (*)(struct ioarg *)) qgravechar)
 		e.iop->task = XGRAVE;
 	else
 		e.iop->task = XOTHER;
@@ -4753,10 +4799,12 @@
 	char c;
 	char **wl;
 
-	if ((wl = ap->awordlist) == NULL)
+	wl = ap->awordlist;
+	if (wl == NULL)
 		return 0;
 	if (*wl != NULL) {
-		if ((c = *(*wl)++) != 0)
+		c = *(*wl)++;
+		if (c != 0)
 			return c & 0177;
 		ap->awordlist++;
 		return ' ';
@@ -4773,7 +4821,8 @@
 {
 	char *wp;
 
-	if ((wp = *ap->awordlist++) != NULL) {
+	wp = *ap->awordlist++;
+	if (wp != NULL) {
 		PUSHIO(aword, wp, *ap->awordlist == NULL ? strchar : xxchar);
 		return -1;
 	}
@@ -4786,7 +4835,8 @@
 
 	if (ap->aword == NULL)
 		return 0;
-	if ((c = *ap->aword++) == '\0') {
+	c = *ap->aword++;
+	if (c == '\0') {
 		ap->aword = NULL;
 		return ' ';
 	}
@@ -4798,11 +4848,9 @@
  */
 static int strchar(struct ioarg *ap)
 {
-	int c;
-
-	if (ap->aword == NULL || (c = *ap->aword++) == 0)
+	if (ap->aword == NULL)
 		return 0;
-	return c;
+	return *ap->aword++;
 }
 
 /*
@@ -4812,7 +4860,7 @@
 {
 	int c;
 
-	if (ap->aword == NULL || (c = *ap->aword++) == 0)
+	if (ap->aword == NULL) || (c = *ap->aword++) == 0)
 		return 0;
 	return c | QUOTE;
 }
@@ -4827,8 +4875,8 @@
 	struct iobuf *bp = ap->afbuf;
 
 	if (ap->afid != AFID_NOBUF) {
-		if ((i = ap->afid != bp->id) || bp->bufp == bp->ebufp) {
-
+		i = (ap->afid != bp->id);
+		if (i || bp->bufp == bp->ebufp) {
 			if (i)
 				lseek(ap->afile, ap->afpos, SEEK_SET);
 
@@ -4840,7 +4888,8 @@
 			}
 
 			bp->id = ap->afid;
-			bp->ebufp = (bp->bufp = bp->buf) + i;
+			bp->bufp = bp->buf;
+			bp->ebufp = bp->bufp + i;
 		}
 
 		ap->afpos++;
@@ -4875,7 +4924,6 @@
 {
 	char c;
 
-
 	if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) {
 		close(ap->afile);
 		c = 0;
@@ -4892,7 +4940,8 @@
 {
 	int c;
 
-	if ((c = qgravechar(ap, iop) & ~QUOTE) == '\n')
+	c = qgravechar(ap, iop) & ~QUOTE;
+	if (c == '\n')
 		c = ' ';
 	return c;
 }
@@ -4930,7 +4979,8 @@
 {
 	int c;
 
-	if ((c = filechar(ap)) == '\n') {
+	c = filechar(ap);
+	if (c == '\n') {
 		if (!multiline) {
 			closef(ap->afile);
 			ap->afile = -1;		/* illegal value */
@@ -4974,7 +5024,6 @@
 	int map[NOFILE];
 	int newfd;
 
-
 	DBGPRINTF(("REMAP: fd=%d, e.iofd=%d\n", fd, e.iofd));
 
 	if (fd < e.iofd) {
@@ -5002,7 +5051,8 @@
 {
 	int i;
 
-	if ((i = pipe(pv)) < 0)
+	i = pipe(pv);
+	if (i < 0)
 		err("can't create pipe - try again");
 	return i;
 }
@@ -5089,7 +5139,8 @@
 		return;
 
 	*name = strsave(tname, areanum);
-	if (newenv(setjmp(errpt = ev)) != 0)
+	errpt = ev;
+	if (newenv(setjmp(errpt)) != 0)
 		unlink(tname);
 	else {
 		pushio(e.iop->argp, (int (*)(struct ioarg *)) e.iop->iofn);



More information about the busybox-cvs mailing list