aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-09 03:06:34 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-09 03:06:34 +0000
commit95cb3263ae8f9afda0f6af3f777739506a0dfc62 (patch)
tree75c436e482fd19cee270df4a70adb00182807f73
parent32b633aa3f7e96bc1a31feb9d3937c0c340a7430 (diff)
downloadbusybox-w32-95cb3263ae8f9afda0f6af3f777739506a0dfc62.tar.gz
busybox-w32-95cb3263ae8f9afda0f6af3f777739506a0dfc62.tar.bz2
busybox-w32-95cb3263ae8f9afda0f6af3f777739506a0dfc62.zip
msh: smallish code shrinkage; cosmetics
-rw-r--r--shell/msh.c126
1 files changed, 58 insertions, 68 deletions
diff --git a/shell/msh.c b/shell/msh.c
index 50ec90b0b..3a5c85050 100644
--- a/shell/msh.c
+++ b/shell/msh.c
@@ -13,8 +13,8 @@
13 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 13 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
14 */ 14 */
15 15
16# include <sys/times.h> 16#include <sys/times.h>
17# include <setjmp.h> 17#include <setjmp.h>
18 18
19#ifdef STANDALONE 19#ifdef STANDALONE
20# ifndef _GNU_SOURCE 20# ifndef _GNU_SOURCE
@@ -291,15 +291,10 @@ static char flags['z' - 'a' + 1];
291/* this looks weird, but is OK ... we index flag with 'a'...'z' */ 291/* this looks weird, but is OK ... we index flag with 'a'...'z' */
292static char *flag = flags - 'a'; 292static char *flag = flags - 'a';
293 293
294static char *null; /* null value for variable */
295static int intr; /* interrupt pending */
296
297/* moved to G: static char *trap[_NSIG + 1]; */ 294/* moved to G: static char *trap[_NSIG + 1]; */
298/* moved to G: static char ourtrap[_NSIG + 1]; */ 295/* moved to G: static char ourtrap[_NSIG + 1]; */
299static int trapset; /* trap pending */ 296static int trapset; /* trap pending */
300 297
301static int heedint; /* heed interrupt signals */
302
303static int yynerrs; /* yacc */ 298static int yynerrs; /* yacc */
304 299
305/* moved to G: static char line[LINELIM]; */ 300/* moved to G: static char line[LINELIM]; */
@@ -615,55 +610,54 @@ struct res {
615 int r_val; 610 int r_val;
616}; 611};
617static const struct res restab[] = { 612static const struct res restab[] = {
618 {"for", FOR}, 613 { "for" , FOR },
619 {"case", CASE}, 614 { "case" , CASE },
620 {"esac", ESAC}, 615 { "esac" , ESAC },
621 {"while", WHILE}, 616 { "while", WHILE },
622 {"do", DO}, 617 { "do" , DO },
623 {"done", DONE}, 618 { "done" , DONE },
624 {"if", IF}, 619 { "if" , IF },
625 {"in", IN}, 620 { "in" , IN },
626 {"then", THEN}, 621 { "then" , THEN },
627 {"else", ELSE}, 622 { "else" , ELSE },
628 {"elif", ELIF}, 623 { "elif" , ELIF },
629 {"until", UNTIL}, 624 { "until", UNTIL },
630 {"fi", FI}, 625 { "fi" , FI },
631 {";;", BREAK}, 626 { ";;" , BREAK },
632 {"||", LOGOR}, 627 { "||" , LOGOR },
633 {"&&", LOGAND}, 628 { "&&" , LOGAND },
634 {"{", '{'}, 629 { "{" , '{' },
635 {"}", '}'}, 630 { "}" , '}' },
636 {".", DOT}, 631 { "." , DOT },
637 {0, 0}, 632 { NULL , 0 },
638}; 633};
639 634
640
641struct builtincmd { 635struct builtincmd {
642 const char *name; 636 const char *name;
643 int (*builtinfunc) (struct op * t); 637 int (*builtinfunc)(struct op *t);
644}; 638};
645static const struct builtincmd builtincmds[] = { 639static const struct builtincmd builtincmds[] = {
646 {".", dodot}, 640 { "." , dodot },
647 {":", dolabel}, 641 { ":" , dolabel },
648 {"break", dobreak}, 642 { "break" , dobreak },
649 {"cd", dochdir}, 643 { "cd" , dochdir },
650 {"continue", docontinue}, 644 { "continue", docontinue },
651 {"eval", doeval}, 645 { "eval" , doeval },
652 {"exec", doexec}, 646 { "exec" , doexec },
653 {"exit", doexit}, 647 { "exit" , doexit },
654 {"export", doexport}, 648 { "export" , doexport },
655 {"help", dohelp}, 649 { "help" , dohelp },
656 {"login", dologin}, 650 { "login" , dologin },
657 {"newgrp", dologin}, 651 { "newgrp" , dologin },
658 {"read", doread}, 652 { "read" , doread },
659 {"readonly", doreadonly}, 653 { "readonly", doreadonly },
660 {"set", doset}, 654 { "set" , doset },
661 {"shift", doshift}, 655 { "shift" , doshift },
662 {"times", dotimes}, 656 { "times" , dotimes },
663 {"trap", dotrap}, 657 { "trap" , dotrap },
664 {"umask", doumask}, 658 { "umask" , doumask },
665 {"wait", dowait}, 659 { "wait" , dowait },
666 {0, 0} 660 { NULL , NULL },
667}; 661};
668 662
669static struct op *scantree(struct op *); 663static struct op *scantree(struct op *);
@@ -697,11 +691,11 @@ static struct var *path; /* search path for commands */
697static struct var *shell; /* shell to interpret command files */ 691static struct var *shell; /* shell to interpret command files */
698static struct var *ifs; /* field separators */ 692static struct var *ifs; /* field separators */
699 693
700static int areanum; /* current allocation area */ 694static int areanum; /* current allocation area */
701static int intr; 695static int intr; /* interrupt pending */
702static int inparse; 696static int inparse;
703static char *null = (char*)""; 697static char *null = (char*)""; /* null value for variable */
704static int heedint = 1; 698static int heedint = 1; /* heed interrupt signals */
705static void (*qflag) (int) = SIG_IGN; 699static void (*qflag) (int) = SIG_IGN;
706static int startl; 700static int startl;
707static int peeksym; 701static int peeksym;
@@ -2693,7 +2687,7 @@ typedef int (*builtin_func_ptr)(struct op *);
2693static builtin_func_ptr inbuilt(const char *s) { 2687static builtin_func_ptr inbuilt(const char *s) {
2694 const struct builtincmd *bp; 2688 const struct builtincmd *bp;
2695 2689
2696 for (bp = builtincmds; bp->name != NULL; bp++) 2690 for (bp = builtincmds; bp->name; bp++)
2697 if (strcmp(bp->name, s) == 0) 2691 if (strcmp(bp->name, s) == 0)
2698 return bp->builtinfunc; 2692 return bp->builtinfunc;
2699 2693
@@ -3191,29 +3185,27 @@ static int dohelp(struct op *t)
3191 puts("\nBuilt-in commands:\n" 3185 puts("\nBuilt-in commands:\n"
3192 "-------------------"); 3186 "-------------------");
3193 3187
3194 for (col = 0, x = builtincmds; x->builtinfunc != NULL; x++) { 3188 col = 0;
3195 if (!x->name) 3189 x = builtincmds;
3196 continue; 3190 while (x->name) {
3197 col += printf("%s%s", ((col == 0) ? "\t" : " "), x->name); 3191 col += printf("%c%s", ((col == 0) ? '\t' : ' '), x->name);
3198 if (col > 60) { 3192 if (col > 60) {
3199 puts(""); 3193 puts("");
3200 col = 0; 3194 col = 0;
3201 } 3195 }
3196 x++;
3202 } 3197 }
3203#if ENABLE_FEATURE_SH_STANDALONE_SHELL 3198#if ENABLE_FEATURE_SH_STANDALONE_SHELL
3204 { 3199 {
3205 int i; 3200 const struct BB_applet *applet = applets;
3206 const struct BB_applet *applet;
3207 3201
3208 for (i = 0, applet = applets; i < NUM_APPLETS; applet++, i++) { 3202 while (applet->name) {
3209 if (!applet->name) 3203 col += printf("%c%s", ((col == 0) ? '\t' : ' '), applet->name);
3210 continue;
3211
3212 col += printf("%s%s", ((col == 0) ? "\t" : " "), applet->name);
3213 if (col > 60) { 3204 if (col > 60) {
3214 puts(""); 3205 puts("");
3215 col = 0; 3206 col = 0;
3216 } 3207 }
3208 applet++;
3217 } 3209 }
3218 } 3210 }
3219#endif 3211#endif
@@ -3221,8 +3213,6 @@ static int dohelp(struct op *t)
3221 return EXIT_SUCCESS; 3213 return EXIT_SUCCESS;
3222} 3214}
3223 3215
3224
3225
3226static int dolabel(struct op *t) 3216static int dolabel(struct op *t)
3227{ 3217{
3228 return 0; 3218 return 0;