aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2001-09-11 01:14:02 +0000
committerManuel Novoa III <mjn3@codepoet.org>2001-09-11 01:14:02 +0000
commit8d0afde412791c1bc35ced42a56ee27602678991 (patch)
tree246cc6cc93ca220b007d0e6442b6524ebe534d7a
parent6a9d1f652b20f53dfd64e260d2796d55ad973c98 (diff)
downloadbusybox-w32-8d0afde412791c1bc35ced42a56ee27602678991.tar.gz
busybox-w32-8d0afde412791c1bc35ced42a56ee27602678991.tar.bz2
busybox-w32-8d0afde412791c1bc35ced42a56ee27602678991.zip
Commit my changes to xxreadtoken() to reduce code size. Also set defines
so that the table implementations of copynode, calcsize, and cmdtxt are used. Hopefully this will result in wider testing. ;-) If it breaks, just unset the appropriate defines.
-rw-r--r--ash.c90
-rw-r--r--shell/ash.c90
2 files changed, 170 insertions, 10 deletions
diff --git a/ash.c b/ash.c
index 9b3f83ef6..8a213d876 100644
--- a/ash.c
+++ b/ash.c
@@ -7294,7 +7294,7 @@ cmdputs(const char *s)
7294 cmdnextc = q; 7294 cmdnextc = q;
7295} 7295}
7296 7296
7297//#define CMDTXT_TABLE 7297#define CMDTXT_TABLE
7298#ifdef CMDTXT_TABLE 7298#ifdef CMDTXT_TABLE
7299/* 7299/*
7300 * To collect a lot of redundant code in cmdtxt() case statements, we 7300 * To collect a lot of redundant code in cmdtxt() case statements, we
@@ -8710,8 +8710,8 @@ static void sizenodelist (const struct nodelist *);
8710static struct nodelist *copynodelist (const struct nodelist *); 8710static struct nodelist *copynodelist (const struct nodelist *);
8711static char *nodesavestr (const char *); 8711static char *nodesavestr (const char *);
8712 8712
8713//#define CALCSIZE_TABLE 8713#define CALCSIZE_TABLE
8714//#define COPYNODE_TABLE 8714#define COPYNODE_TABLE
8715#if defined(CALCSIZE_TABLE) || defined(COPYNODE_TABLE) 8715#if defined(CALCSIZE_TABLE) || defined(COPYNODE_TABLE)
8716/* 8716/*
8717 * To collect a lot of redundant code in case statements for copynode() 8717 * To collect a lot of redundant code in case statements for copynode()
@@ -10337,6 +10337,86 @@ out:
10337 * have parseword (readtoken1?) handle both words and redirection.] 10337 * have parseword (readtoken1?) handle both words and redirection.]
10338 */ 10338 */
10339 10339
10340#define NEW_xxreadtoken
10341#ifdef NEW_xxreadtoken
10342
10343static const char xxreadtoken_chars[] = "\n()&|;"; /* singles must be first! */
10344static const char xxreadtoken_tokens[] = {
10345 TNL, TLP, TRP, /* only single occurrence allowed */
10346 TBACKGND, TPIPE, TSEMI, /* if single occurrence */
10347 TEOF, /* corresponds to trailing nul */
10348 TAND, TOR, TENDCASE, /* if double occurrence */
10349};
10350
10351#define xxreadtoken_doubles \
10352 (sizeof(xxreadtoken_tokens) - sizeof(xxreadtoken_chars))
10353#define xxreadtoken_singles \
10354 (sizeof(xxreadtoken_chars) - xxreadtoken_doubles - 1)
10355
10356static int
10357xxreadtoken() {
10358 int c;
10359
10360 if (tokpushback) {
10361 tokpushback = 0;
10362 return lasttoken;
10363 }
10364 if (needprompt) {
10365 setprompt(2);
10366 needprompt = 0;
10367 }
10368 startlinno = plinno;
10369 for (;;) { /* until token or start of word found */
10370 c = pgetc_macro();
10371
10372 if ((c!=' ') && (c!='\t')
10373#ifdef ASH_ALIAS
10374 && (c!=PEOA)
10375#endif
10376 ) {
10377 if (c=='#') {
10378 while ((c = pgetc()) != '\n' && c != PEOF);
10379 pungetc();
10380 } else if (c=='\\') {
10381 if (pgetc() != '\n') {
10382 pungetc();
10383 goto READTOKEN1;
10384 }
10385 startlinno = ++plinno;
10386 setprompt(doprompt ? 2 : 0);
10387 } else {
10388 const char *p
10389 = xxreadtoken_chars + sizeof(xxreadtoken_chars) - 1;
10390
10391 if (c!=PEOF) {
10392 if (c=='\n') {
10393 plinno++;
10394 needprompt = doprompt;
10395 }
10396
10397 p = strchr(xxreadtoken_chars, c);
10398 if (p == NULL) {
10399 READTOKEN1:
10400 return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
10401 }
10402
10403 if (p-xxreadtoken_chars >= xxreadtoken_singles) {
10404 if (pgetc() == *p) { /* double occurrence? */
10405 p += xxreadtoken_doubles + 1;
10406 } else {
10407 pungetc();
10408 }
10409 }
10410 }
10411
10412 return lasttoken = xxreadtoken_tokens[p-xxreadtoken_chars];
10413 }
10414 }
10415 }
10416}
10417
10418
10419#else
10340#define RETURN(token) return lasttoken = token 10420#define RETURN(token) return lasttoken = token
10341 10421
10342static int 10422static int
@@ -10408,7 +10488,7 @@ breakloop:
10408 return readtoken1(c, BASESYNTAX, (char *)NULL, 0); 10488 return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
10409#undef RETURN 10489#undef RETURN
10410} 10490}
10411 10491#endif
10412 10492
10413 10493
10414/* 10494/*
@@ -12681,7 +12761,7 @@ findvar(struct var **vpp, const char *name)
12681/* 12761/*
12682 * Copyright (c) 1999 Herbert Xu <herbert@debian.org> 12762 * Copyright (c) 1999 Herbert Xu <herbert@debian.org>
12683 * This file contains code for the times builtin. 12763 * This file contains code for the times builtin.
12684 * $Id: ash.c,v 1.24 2001/09/06 18:00:41 andersen Exp $ 12764 * $Id: ash.c,v 1.25 2001/09/11 01:14:02 mjn3 Exp $
12685 */ 12765 */
12686static int timescmd (int argc, char **argv) 12766static int timescmd (int argc, char **argv)
12687{ 12767{
diff --git a/shell/ash.c b/shell/ash.c
index 9b3f83ef6..8a213d876 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -7294,7 +7294,7 @@ cmdputs(const char *s)
7294 cmdnextc = q; 7294 cmdnextc = q;
7295} 7295}
7296 7296
7297//#define CMDTXT_TABLE 7297#define CMDTXT_TABLE
7298#ifdef CMDTXT_TABLE 7298#ifdef CMDTXT_TABLE
7299/* 7299/*
7300 * To collect a lot of redundant code in cmdtxt() case statements, we 7300 * To collect a lot of redundant code in cmdtxt() case statements, we
@@ -8710,8 +8710,8 @@ static void sizenodelist (const struct nodelist *);
8710static struct nodelist *copynodelist (const struct nodelist *); 8710static struct nodelist *copynodelist (const struct nodelist *);
8711static char *nodesavestr (const char *); 8711static char *nodesavestr (const char *);
8712 8712
8713//#define CALCSIZE_TABLE 8713#define CALCSIZE_TABLE
8714//#define COPYNODE_TABLE 8714#define COPYNODE_TABLE
8715#if defined(CALCSIZE_TABLE) || defined(COPYNODE_TABLE) 8715#if defined(CALCSIZE_TABLE) || defined(COPYNODE_TABLE)
8716/* 8716/*
8717 * To collect a lot of redundant code in case statements for copynode() 8717 * To collect a lot of redundant code in case statements for copynode()
@@ -10337,6 +10337,86 @@ out:
10337 * have parseword (readtoken1?) handle both words and redirection.] 10337 * have parseword (readtoken1?) handle both words and redirection.]
10338 */ 10338 */
10339 10339
10340#define NEW_xxreadtoken
10341#ifdef NEW_xxreadtoken
10342
10343static const char xxreadtoken_chars[] = "\n()&|;"; /* singles must be first! */
10344static const char xxreadtoken_tokens[] = {
10345 TNL, TLP, TRP, /* only single occurrence allowed */
10346 TBACKGND, TPIPE, TSEMI, /* if single occurrence */
10347 TEOF, /* corresponds to trailing nul */
10348 TAND, TOR, TENDCASE, /* if double occurrence */
10349};
10350
10351#define xxreadtoken_doubles \
10352 (sizeof(xxreadtoken_tokens) - sizeof(xxreadtoken_chars))
10353#define xxreadtoken_singles \
10354 (sizeof(xxreadtoken_chars) - xxreadtoken_doubles - 1)
10355
10356static int
10357xxreadtoken() {
10358 int c;
10359
10360 if (tokpushback) {
10361 tokpushback = 0;
10362 return lasttoken;
10363 }
10364 if (needprompt) {
10365 setprompt(2);
10366 needprompt = 0;
10367 }
10368 startlinno = plinno;
10369 for (;;) { /* until token or start of word found */
10370 c = pgetc_macro();
10371
10372 if ((c!=' ') && (c!='\t')
10373#ifdef ASH_ALIAS
10374 && (c!=PEOA)
10375#endif
10376 ) {
10377 if (c=='#') {
10378 while ((c = pgetc()) != '\n' && c != PEOF);
10379 pungetc();
10380 } else if (c=='\\') {
10381 if (pgetc() != '\n') {
10382 pungetc();
10383 goto READTOKEN1;
10384 }
10385 startlinno = ++plinno;
10386 setprompt(doprompt ? 2 : 0);
10387 } else {
10388 const char *p
10389 = xxreadtoken_chars + sizeof(xxreadtoken_chars) - 1;
10390
10391 if (c!=PEOF) {
10392 if (c=='\n') {
10393 plinno++;
10394 needprompt = doprompt;
10395 }
10396
10397 p = strchr(xxreadtoken_chars, c);
10398 if (p == NULL) {
10399 READTOKEN1:
10400 return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
10401 }
10402
10403 if (p-xxreadtoken_chars >= xxreadtoken_singles) {
10404 if (pgetc() == *p) { /* double occurrence? */
10405 p += xxreadtoken_doubles + 1;
10406 } else {
10407 pungetc();
10408 }
10409 }
10410 }
10411
10412 return lasttoken = xxreadtoken_tokens[p-xxreadtoken_chars];
10413 }
10414 }
10415 }
10416}
10417
10418
10419#else
10340#define RETURN(token) return lasttoken = token 10420#define RETURN(token) return lasttoken = token
10341 10421
10342static int 10422static int
@@ -10408,7 +10488,7 @@ breakloop:
10408 return readtoken1(c, BASESYNTAX, (char *)NULL, 0); 10488 return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
10409#undef RETURN 10489#undef RETURN
10410} 10490}
10411 10491#endif
10412 10492
10413 10493
10414/* 10494/*
@@ -12681,7 +12761,7 @@ findvar(struct var **vpp, const char *name)
12681/* 12761/*
12682 * Copyright (c) 1999 Herbert Xu <herbert@debian.org> 12762 * Copyright (c) 1999 Herbert Xu <herbert@debian.org>
12683 * This file contains code for the times builtin. 12763 * This file contains code for the times builtin.
12684 * $Id: ash.c,v 1.24 2001/09/06 18:00:41 andersen Exp $ 12764 * $Id: ash.c,v 1.25 2001/09/11 01:14:02 mjn3 Exp $
12685 */ 12765 */
12686static int timescmd (int argc, char **argv) 12766static int timescmd (int argc, char **argv)
12687{ 12767{