aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-12 06:04:06 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-12 06:04:06 +0000
commit648b44fd785f8d23e363886ff306e8ef70d148ba (patch)
treeedff6d790ab04e2c5221b34e2a6f65409614e491 /shell
parenta5f2cd30c9308b3cec359acdf79d60958d6d5834 (diff)
downloadbusybox-w32-648b44fd785f8d23e363886ff306e8ef70d148ba.tar.gz
busybox-w32-648b44fd785f8d23e363886ff306e8ef70d148ba.tar.bz2
busybox-w32-648b44fd785f8d23e363886ff306e8ef70d148ba.zip
msh: shrink, mainly by using smallints
function old new delta synio 251 263 +12 filechar 310 315 +5 subgetc 781 785 +4 brkcontin 106 109 +3 ... yylex 981 976 -5 execute 2513 2508 -5 waitfor 321 315 -6 onintr 103 97 -6 doset 332 326 -6 doexec 186 180 -6 yyparse 65 57 -8 thenpart 135 126 -9 forkexec 1379 1370 -9 onecommand 457 433 -24 newtp 52 28 -24 command 1086 1061 -25 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 7/23 up/down: 27/-163) Total: -136 bytes
Diffstat (limited to 'shell')
-rw-r--r--shell/msh.c118
1 files changed, 57 insertions, 61 deletions
diff --git a/shell/msh.c b/shell/msh.c
index f05028f26..99b03947e 100644
--- a/shell/msh.c
+++ b/shell/msh.c
@@ -158,7 +158,7 @@ int mshdbg_rc = 0;
158/* 158/*
159 * library and system definitions 159 * library and system definitions
160 */ 160 */
161typedef void xint; /* base type of jmp_buf, for not broken compilers */ 161typedef void xint; /* base type of jmp_buf, for not broken compilers */
162 162
163/* 163/*
164 * shell components 164 * shell components
@@ -172,20 +172,20 @@ typedef void xint; /* base type of jmp_buf, for not broken compilers */
172 * redirection 172 * redirection
173 */ 173 */
174struct ioword { 174struct ioword {
175 short io_unit; /* unit affected */ 175 short io_unit; /* unit affected */
176 short io_flag; /* action (below) */ 176 short io_flag; /* action (below) */
177 char *io_name; /* file name */ 177 char *io_name; /* file name */
178}; 178};
179 179
180#define IOREAD 1 /* < */ 180#define IOREAD 1 /* < */
181#define IOHERE 2 /* << (here file) */ 181#define IOHERE 2 /* << (here file) */
182#define IOWRITE 4 /* > */ 182#define IOWRITE 4 /* > */
183#define IOCAT 8 /* >> */ 183#define IOCAT 8 /* >> */
184#define IOXHERE 16 /* ${}, ` in << */ 184#define IOXHERE 16 /* ${}, ` in << */
185#define IODUP 32 /* >&digit */ 185#define IODUP 32 /* >&digit */
186#define IOCLOSE 64 /* >&- */ 186#define IOCLOSE 64 /* >&- */
187 187
188#define IODEFAULT (-1) /* token for default IO unit */ 188#define IODEFAULT (-1) /* token for default IO unit */
189 189
190 190
191/* 191/*
@@ -193,12 +193,12 @@ struct ioword {
193 * Might eventually use a union. 193 * Might eventually use a union.
194 */ 194 */
195struct op { 195struct op {
196 int type; /* operation type, see below */ 196 smallint type; /* operation type, see Txxxx below */
197 char **words; /* arguments to a command */ 197 char **words; /* arguments to a command */
198 struct ioword **ioact; /* IO actions (eg, < > >>) */ 198 struct ioword **ioact; /* IO actions (eg, < > >>) */
199 struct op *left; 199 struct op *left;
200 struct op *right; 200 struct op *right;
201 char *str; /* identifier for case and for */ 201 char *str; /* identifier for case and for */
202}; 202};
203 203
204#define TCOM 1 /* command */ 204#define TCOM 1 /* command */
@@ -269,9 +269,9 @@ struct brkcon {
269}; 269};
270 270
271 271
272static int trapset; /* trap pending */ 272static smallint trapset; /* trap pending (signal number) */
273 273
274static int yynerrs; /* yacc */ 274static smallint yynerrs; /* yacc (flag) */
275 275
276/* moved to G: static char line[LINELIM]; */ 276/* moved to G: static char line[LINELIM]; */
277 277
@@ -420,7 +420,7 @@ struct ioarg {
420 char **awordlist; 420 char **awordlist;
421 int afile; /* file descriptor */ 421 int afile; /* file descriptor */
422 unsigned afid; /* buffer id */ 422 unsigned afid; /* buffer id */
423 long afpos; /* file position */ 423 off_t afpos; /* file position */
424 struct iobuf *afbuf; /* buffer for this file */ 424 struct iobuf *afbuf; /* buffer for this file */
425}; 425};
426 426
@@ -539,7 +539,7 @@ static int xxchar(struct ioarg *ap);
539 539
540struct here { 540struct here {
541 char *h_tag; 541 char *h_tag;
542 int h_dosub; 542 char h_dosub;
543 struct ioword *h_iop; 543 struct ioword *h_iop;
544 struct here *h_next; 544 struct here *h_next;
545}; 545};
@@ -600,15 +600,15 @@ static struct op *dowholefile(int, int);
600static char **dolv; 600static char **dolv;
601static int dolc; 601static int dolc;
602static int exstat; 602static int exstat;
603static char gflg; 603static smallint gflg; /* (seems to be a parse error indicator) */
604static int interactive; /* Is this an interactive shell */ 604static smallint interactive; /* Is this an interactive shell */
605static int execflg; 605static smallint execflg;
606static int multiline; /* \n changed to ; */ 606static smallint isbreak; /* "break" statement was seen */
607static struct op *outtree; /* result from parser */ 607static int multiline; /* '\n' changed to ';' (counter) */
608static struct op *outtree; /* result from parser */
608static xint *failpt; 609static xint *failpt;
609static xint *errpt; 610static xint *errpt;
610static struct brkcon *brklist; 611static struct brkcon *brklist;
611static int isbreak;
612static struct wdblock *wdlist; 612static struct wdblock *wdlist;
613static struct wdblock *iolist; 613static struct wdblock *iolist;
614 614
@@ -624,10 +624,10 @@ static struct var *shell; /* shell to interpret command files */
624static struct var *ifs; /* field separators */ 624static struct var *ifs; /* field separators */
625 625
626static int areanum; /* current allocation area */ 626static int areanum; /* current allocation area */
627static int intr; /* interrupt pending */ 627static smallint intr; /* interrupt pending (bool) */
628static smallint heedint = 1; /* heed interrupt signals (bool) */
628static int inparse; 629static int inparse;
629static char *null = (char*)""; /* null value for variable */ 630static char *null = (char*)""; /* null value for variable */
630static int heedint = 1; /* heed interrupt signals */
631static void (*qflag)(int) = SIG_IGN; 631static void (*qflag)(int) = SIG_IGN;
632static int startl; 632static int startl;
633static int peeksym; 633static int peeksym;
@@ -1560,10 +1560,11 @@ static int gmatch(const char *s, const char *p)
1560static void yyerror(const char *s) ATTRIBUTE_NORETURN; 1560static void yyerror(const char *s) ATTRIBUTE_NORETURN;
1561static void yyerror(const char *s) 1561static void yyerror(const char *s)
1562{ 1562{
1563 yynerrs++; 1563 yynerrs = 1;
1564 if (interactive && global_env.iop <= iostack) { 1564 if (interactive && global_env.iop <= iostack) {
1565 multiline = 0; 1565 multiline = 0;
1566 while (eofc() == 0 && yylex(0) != '\n'); 1566 while (eofc() == 0 && yylex(0) != '\n')
1567 continue;
1567 } 1568 }
1568 err(s); 1569 err(s);
1569 fail(); 1570 fail();
@@ -1584,7 +1585,7 @@ int yyparse(void)
1584 yynerrs = 0; 1585 yynerrs = 0;
1585 outtree = c_list(); 1586 outtree = c_list();
1586 musthave('\n', 0); 1587 musthave('\n', 0);
1587 return (yynerrs != 0); 1588 return yynerrs; /* 0/1 */
1588} 1589}
1589 1590
1590static struct op *pipeline(int cf) 1591static struct op *pipeline(int cf)
@@ -1819,7 +1820,7 @@ static struct op *command(int cf)
1819 case UNTIL: 1820 case UNTIL:
1820 multiline++; 1821 multiline++;
1821 t = newtp(); 1822 t = newtp();
1822 t->type = c == WHILE ? TWHILE : TUNTIL; 1823 t->type = (c == WHILE ? TWHILE : TUNTIL);
1823 t->left = c_list(); 1824 t->left = c_list();
1824 t->right = dogroup(1); 1825 t->right = dogroup(1);
1825 t->words = NULL; 1826 t->words = NULL;
@@ -1916,7 +1917,7 @@ static struct op *thenpart(void)
1916 return NULL; 1917 return NULL;
1917 } 1918 }
1918 t = newtp(); 1919 t = newtp();
1919 t->type = 0; 1920 /*t->type = 0; - newtp() did this */
1920 t->left = c_list(); 1921 t->left = c_list();
1921 if (t->left == NULL) 1922 if (t->left == NULL)
1922 zzerr(); 1923 zzerr();
@@ -2044,8 +2045,7 @@ static struct op *block(int type, struct op *t1, struct op *t2, char **wp)
2044 t->right = t2; 2045 t->right = t2;
2045 t->words = wp; 2046 t->words = wp;
2046 2047
2047 DBGPRINTF7(("BLOCK: inserted %p between %p and %p\n", t, t1, 2048 DBGPRINTF7(("BLOCK: inserted %p between %p and %p\n", t, t1, t2));
2048 t2));
2049 2049
2050 return t; 2050 return t;
2051} 2051}
@@ -2099,12 +2099,7 @@ static struct op *newtp(void)
2099 struct op *t; 2099 struct op *t;
2100 2100
2101 t = (struct op *) tree(sizeof(*t)); 2101 t = (struct op *) tree(sizeof(*t));
2102 t->type = 0; 2102 memset(t, 0, sizeof(*t));
2103 t->words = NULL;
2104 t->ioact = NULL;
2105 t->left = NULL;
2106 t->right = NULL;
2107 t->str = NULL;
2108 2103
2109 DBGPRINTF3(("NEWTP: allocated %p\n", t)); 2104 DBGPRINTF3(("NEWTP: allocated %p\n", t));
2110 2105
@@ -2481,7 +2476,8 @@ static int execute(struct op *t, int *pin, int *pout, int act)
2481 2476
2482 rv = 0; 2477 rv = 0;
2483 a = areanum++; 2478 a = areanum++;
2484 wp = (wp2 = t->words) != NULL 2479 wp2 = t->words;
2480 wp = (wp2 != NULL)
2485 ? eval(wp2, t->type == TCOM ? DOALL : DOALL & ~DOKEY) 2481 ? eval(wp2, t->type == TCOM ? DOALL : DOALL & ~DOKEY)
2486 : NULL; 2482 : NULL;
2487 2483
@@ -2533,7 +2529,7 @@ static int execute(struct op *t, int *pin, int *pout, int act)
2533 2529
2534 case TASYNC: 2530 case TASYNC:
2535 { 2531 {
2536 int hinteractive = interactive; 2532 smallint hinteractive = interactive;
2537 2533
2538 DBGPRINTF7(("EXECUTE: TASYNC clause, calling vfork()...\n")); 2534 DBGPRINTF7(("EXECUTE: TASYNC clause, calling vfork()...\n"));
2539 2535
@@ -2700,10 +2696,10 @@ static int forkexec(struct op *t, int *pin, int *pout, int act, char **wp)
2700 int *hpin = pin; 2696 int *hpin = pin;
2701 int *hpout = pout; 2697 int *hpout = pout;
2702 char *hwp; 2698 char *hwp;
2703 int hinteractive; 2699 smallint hinteractive;
2704 int hintr; 2700 smallint hintr;
2701 smallint hexecflg;
2705 struct brkcon *hbrklist; 2702 struct brkcon *hbrklist;
2706 int hexecflg;
2707 2703
2708#if __GNUC__ 2704#if __GNUC__
2709 /* Avoid longjmp clobbering */ 2705 /* Avoid longjmp clobbering */
@@ -2993,7 +2989,7 @@ static int waitfor(int lastpid, int canintr)
2993{ 2989{
2994 int pid, rv; 2990 int pid, rv;
2995 int s; 2991 int s;
2996 int oheedint = heedint; 2992 smallint oheedint = heedint;
2997 2993
2998 heedint = 0; 2994 heedint = 0;
2999 rv = 0; 2995 rv = 0;
@@ -3521,7 +3517,7 @@ static int brkcontin(char *cp, int val)
3521 err("bad break/continue level"); 3517 err("bad break/continue level");
3522 return 1; 3518 return 1;
3523 } 3519 }
3524 isbreak = val; 3520 isbreak = (val != 0);
3525 longjmp(bc->brkpt, 1); 3521 longjmp(bc->brkpt, 1);
3526 /* NOTREACHED */ 3522 /* NOTREACHED */
3527} 3523}
@@ -3699,7 +3695,7 @@ static char **eval(char **ap, int f)
3699 expand(*wf, &wb, f & ~DOGLOB); 3695 expand(*wf, &wb, f & ~DOGLOB);
3700 } 3696 }
3701 } 3697 }
3702 for (wb = addword((char *) 0, wb); *ap; ap++) { 3698 for (wb = addword((char *) NULL, wb); *ap; ap++) {
3703 if (!FLAG['k'] || !isassign(*ap)) 3699 if (!FLAG['k'] || !isassign(*ap))
3704 expand(*ap, &wb, f & ~DOKEY); 3700 expand(*ap, &wb, f & ~DOKEY);
3705 } 3701 }
@@ -3935,13 +3931,13 @@ static int dollar(int quoted)
3935 global_env.iop->task = otask; 3931 global_env.iop->task = otask;
3936 if (c != '}') { 3932 if (c != '}') {
3937 err("unclosed ${"); 3933 err("unclosed ${");
3938 gflg++; 3934 gflg = 1;
3939 return c; 3935 return c;
3940 } 3936 }
3941 } 3937 }
3942 if (global_env.linep >= elinep) { 3938 if (global_env.linep >= elinep) {
3943 err("string in ${} too long"); 3939 err("string in ${} too long");
3944 gflg++; 3940 gflg = 1;
3945 global_env.linep -= 10; 3941 global_env.linep -= 10;
3946 } 3942 }
3947 *global_env.linep = 0; 3943 *global_env.linep = 0;
@@ -3971,7 +3967,7 @@ static int dollar(int quoted)
3971 case '=': 3967 case '=':
3972 if (isdigit(*s)) { 3968 if (isdigit(*s)) {
3973 err("cannot use ${...=...} with $n"); 3969 err("cannot use ${...=...} with $n");
3974 gflg++; 3970 gflg = 1;
3975 break; 3971 break;
3976 } 3972 }
3977 setval(vp, cp); 3973 setval(vp, cp);
@@ -3988,7 +3984,7 @@ static int dollar(int quoted)
3988 err(s); 3984 err(s);
3989 } else 3985 } else
3990 err(cp); 3986 err(cp);
3991 gflg++; 3987 gflg = 1;
3992 break; 3988 break;
3993 } 3989 }
3994 } else if (c == '+') 3990 } else if (c == '+')
@@ -3996,7 +3992,7 @@ static int dollar(int quoted)
3996 if (FLAG['u'] && dolp == null) { 3992 if (FLAG['u'] && dolp == null) {
3997 prs("unset variable: "); 3993 prs("unset variable: ");
3998 err(s); 3994 err(s);
3999 gflg++; 3995 gflg = 1;
4000 } 3996 }
4001 global_env.linep = s; 3997 global_env.linep = s;
4002 PUSHIO(aword, dolp, quoted ? qstrchar : strchar); 3998 PUSHIO(aword, dolp, quoted ? qstrchar : strchar);
@@ -4539,7 +4535,7 @@ static int my_getc(int ec)
4539 if (global_env.linep > elinep) { 4535 if (global_env.linep > elinep) {
4540 while ((c = readc()) != '\n' && c); 4536 while ((c = readc()) != '\n' && c);
4541 err("input line too long"); 4537 err("input line too long");
4542 gflg++; 4538 gflg = 1;
4543 return c; 4539 return c;
4544 } 4540 }
4545 c = readc(); 4541 c = readc();
@@ -4638,7 +4634,7 @@ static void pushio(struct ioarg *argp, int (*fn) (struct ioarg *))
4638 if (++global_env.iop >= &iostack[NPUSH]) { 4634 if (++global_env.iop >= &iostack[NPUSH]) {
4639 global_env.iop--; 4635 global_env.iop--;
4640 err("Shell input nested too deeply"); 4636 err("Shell input nested too deeply");
4641 gflg++; 4637 gflg = 1;
4642 return; 4638 return;
4643 } 4639 }
4644 4640
@@ -5012,7 +5008,7 @@ static void markhere(char *s, struct ioword *iop)
5012 *s &= ~QUOTE; 5008 *s &= ~QUOTE;
5013 } 5009 }
5014 } 5010 }
5015 h->h_dosub = iop->io_flag & IOXHERE; 5011 h->h_dosub = ((iop->io_flag & IOXHERE) ? '\0' : '\'');
5016} 5012}
5017 5013
5018static void gethere(void) 5014static void gethere(void)
@@ -5023,7 +5019,7 @@ static void gethere(void)
5023 5019
5024 /* Scan here files first leaving inhere list in place */ 5020 /* Scan here files first leaving inhere list in place */
5025 for (hp = h = inhere; h != NULL; hp = h, h = h->h_next) 5021 for (hp = h = inhere; h != NULL; hp = h, h = h->h_next)
5026 readhere(&h->h_iop->io_name, h->h_tag, h->h_dosub ? 0 : '\''); 5022 readhere(&h->h_iop->io_name, h->h_tag, h->h_dosub /* NUL or ' */);
5027 5023
5028 /* Make inhere list active - keep list intact for scraphere */ 5024 /* Make inhere list active - keep list intact for scraphere */
5029 if (hp != NULL) { 5025 if (hp != NULL) {
@@ -5288,7 +5284,7 @@ int msh_main(int argc, char **argv)
5288 break; 5284 break;
5289 5285
5290 case 'i': 5286 case 'i':
5291 interactive++; 5287 interactive = 1;
5292 default: 5288 default:
5293 if (*s >= 'a' && *s <= 'z') 5289 if (*s >= 'a' && *s <= 'z')
5294 FLAG[(int) *s]++; 5290 FLAG[(int) *s]++;
@@ -5324,7 +5320,7 @@ int msh_main(int argc, char **argv)
5324 if (global_env.iop < iostack) { 5320 if (global_env.iop < iostack) {
5325 PUSHIO(afile, 0, iof); 5321 PUSHIO(afile, 0, iof);
5326 if (isatty(0) && isatty(1) && !cflag) { 5322 if (isatty(0) && isatty(1) && !cflag) {
5327 interactive++; 5323 interactive = 1;
5328#if !ENABLE_FEATURE_SH_EXTRA_QUIET 5324#if !ENABLE_FEATURE_SH_EXTRA_QUIET
5329#ifdef MSHDEBUG 5325#ifdef MSHDEBUG
5330 printf("\n\n%s built-in shell (msh with debug)\n", bb_banner); 5326 printf("\n\n%s built-in shell (msh with debug)\n", bb_banner);
@@ -5338,7 +5334,7 @@ int msh_main(int argc, char **argv)
5338 5334
5339 signal(SIGQUIT, qflag); 5335 signal(SIGQUIT, qflag);
5340 if (name && name[0] == '-') { 5336 if (name && name[0] == '-') {
5341 interactive++; 5337 interactive = 1;
5342 f = open(".profile", O_RDONLY); 5338 f = open(".profile", O_RDONLY);
5343 if (f >= 0) 5339 if (f >= 0)
5344 next(remap(f)); 5340 next(remap(f));