diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-24 22:42:29 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-24 22:42:29 +0000 |
commit | e5ce1e126132ffbbf5248401a080e4aca029094b (patch) | |
tree | 5b98c878f1634a2ba4d1a94ea4e58919667d26c4 /shell | |
parent | 51b8563a65ccbafee1bba47c025a93edd460fdfe (diff) | |
download | busybox-w32-e5ce1e126132ffbbf5248401a080e4aca029094b.tar.gz busybox-w32-e5ce1e126132ffbbf5248401a080e4aca029094b.tar.bz2 busybox-w32-e5ce1e126132ffbbf5248401a080e4aca029094b.zip |
inetd,ed,msh: data/bss reduction (in mss, more than 9k of it)
git-svn-id: svn://busybox.net/trunk/busybox@18234 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'shell')
-rw-r--r-- | shell/msh.c | 104 |
1 files changed, 61 insertions, 43 deletions
diff --git a/shell/msh.c b/shell/msh.c index d9dd3efb2..66b10f346 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
@@ -13,12 +13,13 @@ | |||
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> | ||
17 | # include <setjmp.h> | ||
18 | |||
16 | #ifdef STANDALONE | 19 | #ifdef STANDALONE |
17 | # ifndef _GNU_SOURCE | 20 | # ifndef _GNU_SOURCE |
18 | # define _GNU_SOURCE | 21 | # define _GNU_SOURCE |
19 | # endif | 22 | # endif |
20 | # include <setjmp.h> | ||
21 | # include <sys/times.h> | ||
22 | # include <sys/types.h> | 23 | # include <sys/types.h> |
23 | # include <sys/stat.h> | 24 | # include <sys/stat.h> |
24 | # include <sys/wait.h> | 25 | # include <sys/wait.h> |
@@ -82,8 +83,6 @@ static char *itoa(int n) | |||
82 | return local_buf; | 83 | return local_buf; |
83 | } | 84 | } |
84 | #else | 85 | #else |
85 | # include <setjmp.h> | ||
86 | # include <sys/times.h> | ||
87 | # include "busybox.h" | 86 | # include "busybox.h" |
88 | extern char **environ; | 87 | extern char **environ; |
89 | #endif | 88 | #endif |
@@ -162,12 +161,10 @@ int mshdbg_rc = 0; | |||
162 | */ | 161 | */ |
163 | typedef void xint; /* base type of jmp_buf, for not broken compilers */ | 162 | typedef void xint; /* base type of jmp_buf, for not broken compilers */ |
164 | 163 | ||
164 | |||
165 | /* | 165 | /* |
166 | * shell components | 166 | * shell components |
167 | */ | 167 | */ |
168 | |||
169 | #define QUOTE 0200 | ||
170 | |||
171 | #define NOBLOCK ((struct op *)NULL) | 168 | #define NOBLOCK ((struct op *)NULL) |
172 | #define NOWORD ((char *)NULL) | 169 | #define NOWORD ((char *)NULL) |
173 | #define NOWORDS ((char **)NULL) | 170 | #define NOWORDS ((char **)NULL) |
@@ -297,24 +294,21 @@ static char *flag = flags - 'a'; | |||
297 | static char *null; /* null value for variable */ | 294 | static char *null; /* null value for variable */ |
298 | static int intr; /* interrupt pending */ | 295 | static int intr; /* interrupt pending */ |
299 | 296 | ||
300 | static char *trap[_NSIG + 1]; | 297 | /* moved to G: static char *trap[_NSIG + 1]; */ |
301 | static char ourtrap[_NSIG + 1]; | 298 | /* moved to G: static char ourtrap[_NSIG + 1]; */ |
302 | static int trapset; /* trap pending */ | 299 | static int trapset; /* trap pending */ |
303 | 300 | ||
304 | static int heedint; /* heed interrupt signals */ | 301 | static int heedint; /* heed interrupt signals */ |
305 | 302 | ||
306 | static int yynerrs; /* yacc */ | 303 | static int yynerrs; /* yacc */ |
307 | 304 | ||
308 | static char line[LINELIM]; | 305 | /* moved to G: static char line[LINELIM]; */ |
309 | static char *elinep; | ||
310 | 306 | ||
311 | #if ENABLE_FEATURE_EDITING | 307 | #if ENABLE_FEATURE_EDITING |
312 | static char *current_prompt; | 308 | static char *current_prompt; |
313 | static line_input_t *line_input_state; | 309 | static line_input_t *line_input_state; |
314 | #endif | 310 | #endif |
315 | 311 | ||
316 | static int areanum; /* current allocation area */ | ||
317 | |||
318 | 312 | ||
319 | /* | 313 | /* |
320 | * other functions | 314 | * other functions |
@@ -483,30 +477,16 @@ struct io { | |||
483 | #define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL) | 477 | #define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL) |
484 | 478 | ||
485 | static struct ioarg temparg = { 0, 0, 0, AFID_NOBUF, 0 }; /* temporary for PUSHIO */ | 479 | static struct ioarg temparg = { 0, 0, 0, AFID_NOBUF, 0 }; /* temporary for PUSHIO */ |
486 | static struct ioarg ioargstack[NPUSH]; | 480 | /* moved to G: static struct ioarg ioargstack[NPUSH]; */ |
487 | static struct io iostack[NPUSH]; | 481 | static struct io iostack[NPUSH]; |
488 | static struct iobuf sharedbuf = { AFID_NOBUF }; | 482 | /* moved to G: static struct iobuf sharedbuf = { AFID_NOBUF }; */ |
489 | static struct iobuf mainbuf = { AFID_NOBUF }; | 483 | /* moved to G: static struct iobuf mainbuf = { AFID_NOBUF }; */ |
490 | static unsigned bufid = AFID_ID; /* buffer id counter */ | 484 | static unsigned bufid = AFID_ID; /* buffer id counter */ |
491 | 485 | ||
492 | #define PUSHIO(what,arg,gen) ((temparg.what = (arg)), pushio(&temparg,(gen))) | ||
493 | #define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen))) | 486 | #define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen))) |
494 | 487 | ||
495 | 488 | ||
496 | /* | 489 | /* |
497 | * parsing & execution environment | ||
498 | */ | ||
499 | static struct env { | ||
500 | char *linep; | ||
501 | struct io *iobase; | ||
502 | struct io *iop; | ||
503 | xint *errpt; /* void * */ | ||
504 | int iofd; | ||
505 | struct env *oenv; | ||
506 | } e; | ||
507 | |||
508 | |||
509 | /* | ||
510 | * input generators for IO structure | 490 | * input generators for IO structure |
511 | */ | 491 | */ |
512 | static int nlchar(struct ioarg *ap); | 492 | static int nlchar(struct ioarg *ap); |
@@ -537,6 +517,7 @@ static void ioecho(char c); | |||
537 | * IO control | 517 | * IO control |
538 | */ | 518 | */ |
539 | static void pushio(struct ioarg *argp, int (*f) (struct ioarg *)); | 519 | static void pushio(struct ioarg *argp, int (*f) (struct ioarg *)); |
520 | #define PUSHIO(what,arg,gen) ((temparg.what = (arg)), pushio(&temparg,(gen))) | ||
540 | static int remap(int fd); | 521 | static int remap(int fd); |
541 | static int openpipe(int *pv); | 522 | static int openpipe(int *pv); |
542 | static void closepipe(int *pv); | 523 | static void closepipe(int *pv); |
@@ -599,7 +580,6 @@ static int xstrcmp(char *p1, char *p2); | |||
599 | static void glob0(char *a0, unsigned a1, int a2, | 580 | static void glob0(char *a0, unsigned a1, int a2, |
600 | int (*a3) (char *, char *)); | 581 | int (*a3) (char *, char *)); |
601 | static void readhere(char **name, char *s, int ec); | 582 | static void readhere(char **name, char *s, int ec); |
602 | static void pushio(struct ioarg *argp, int (*f) (struct ioarg *)); | ||
603 | static int xxchar(struct ioarg *ap); | 583 | static int xxchar(struct ioarg *ap); |
604 | 584 | ||
605 | struct here { | 585 | struct here { |
@@ -705,9 +685,6 @@ static struct brkcon *brklist; | |||
705 | static int isbreak; | 685 | static int isbreak; |
706 | static struct wdblock *wdlist; | 686 | static struct wdblock *wdlist; |
707 | static struct wdblock *iolist; | 687 | static struct wdblock *iolist; |
708 | static char *trap[_NSIG + 1]; | ||
709 | static char ourtrap[_NSIG + 1]; | ||
710 | static int trapset; /* trap pending */ | ||
711 | 688 | ||
712 | #ifdef MSHDEBUG | 689 | #ifdef MSHDEBUG |
713 | static struct var *mshdbg_var; | 690 | static struct var *mshdbg_var; |
@@ -731,8 +708,7 @@ static int peeksym; | |||
731 | static int nlseen; | 708 | static int nlseen; |
732 | static int iounit = IODEFAULT; | 709 | static int iounit = IODEFAULT; |
733 | static YYSTYPE yylval; | 710 | static YYSTYPE yylval; |
734 | static char *elinep = line + sizeof(line) - 5; | 711 | static char *elinep; /* done in main(): = line + sizeof(line) - 5 */ |
735 | |||
736 | 712 | ||
737 | static struct here *inhere; /* list of hear docs while parsing */ | 713 | static struct here *inhere; /* list of hear docs while parsing */ |
738 | static struct here *acthere; /* list of active here documents */ | 714 | static struct here *acthere; /* list of active here documents */ |
@@ -742,8 +718,20 @@ static struct region *areanxt; /* starting point of scan */ | |||
742 | static void *brktop; | 718 | static void *brktop; |
743 | static void *brkaddr; | 719 | static void *brkaddr; |
744 | 720 | ||
721 | /* | ||
722 | * parsing & execution environment | ||
723 | */ | ||
724 | struct env { | ||
725 | char *linep; | ||
726 | struct io *iobase; | ||
727 | struct io *iop; | ||
728 | xint *errpt; /* void * */ | ||
729 | int iofd; | ||
730 | struct env *oenv; | ||
731 | }; | ||
732 | |||
745 | static struct env e = { | 733 | static struct env e = { |
746 | line, /* linep: char ptr */ | 734 | NULL /* set to line in main() */, /* linep: char ptr */ |
747 | iostack, /* iobase: struct io ptr */ | 735 | iostack, /* iobase: struct io ptr */ |
748 | iostack - 1, /* iop: struct io ptr */ | 736 | iostack - 1, /* iop: struct io ptr */ |
749 | (xint *) NULL, /* errpt: void ptr for errors? */ | 737 | (xint *) NULL, /* errpt: void ptr for errors? */ |
@@ -751,6 +739,29 @@ static struct env e = { | |||
751 | (struct env *) NULL /* oenv: struct env ptr */ | 739 | (struct env *) NULL /* oenv: struct env ptr */ |
752 | }; | 740 | }; |
753 | 741 | ||
742 | |||
743 | struct globals { | ||
744 | char ourtrap[_NSIG + 1]; | ||
745 | char *trap[_NSIG + 1]; | ||
746 | struct iobuf sharedbuf; /* in main(): set to { AFID_NOBUF } */ | ||
747 | struct iobuf mainbuf; /* in main(): set to { AFID_NOBUF } */ | ||
748 | struct ioarg ioargstack[NPUSH]; | ||
749 | char filechar_cmdbuf[BUFSIZ]; | ||
750 | char line[LINELIM]; | ||
751 | char child_cmd[LINELIM]; | ||
752 | }; | ||
753 | |||
754 | #define G (*ptr_to_globals) | ||
755 | #define ourtrap (G.ourtrap ) | ||
756 | #define trap (G.trap ) | ||
757 | #define sharedbuf (G.sharedbuf ) | ||
758 | #define mainbuf (G.mainbuf ) | ||
759 | #define ioargstack (G.ioargstack ) | ||
760 | #define filechar_cmdbuf (G.filechar_cmdbuf) | ||
761 | #define line (G.line ) | ||
762 | #define child_cmd (G.child_cmd ) | ||
763 | |||
764 | |||
754 | #ifdef MSHDEBUG | 765 | #ifdef MSHDEBUG |
755 | void print_t(struct op *t) | 766 | void print_t(struct op *t) |
756 | { | 767 | { |
@@ -1517,7 +1528,7 @@ static void onintr(int s) /* ANSI C requires a parameter */ | |||
1517 | 1528 | ||
1518 | #define CMASK 0377 | 1529 | #define CMASK 0377 |
1519 | #define QUOTE 0200 | 1530 | #define QUOTE 0200 |
1520 | #define QMASK (CMASK&~QUOTE) | 1531 | #define QMASK (CMASK & ~QUOTE) |
1521 | #define NOT '!' /* might use ^ */ | 1532 | #define NOT '!' /* might use ^ */ |
1522 | 1533 | ||
1523 | static const char *cclass(const char *p, int sub) | 1534 | static const char *cclass(const char *p, int sub) |
@@ -4011,11 +4022,12 @@ static int dollar(int quoted) | |||
4011 | 4022 | ||
4012 | static int grave(int quoted) | 4023 | static int grave(int quoted) |
4013 | { | 4024 | { |
4025 | /* moved to G: static char child_cmd[LINELIM]; */ | ||
4026 | |||
4014 | const char *cp; | 4027 | const char *cp; |
4015 | int i; | 4028 | int i; |
4016 | int j; | 4029 | int j; |
4017 | int pf[2]; | 4030 | int pf[2]; |
4018 | static char child_cmd[LINELIM]; | ||
4019 | const char *src; | 4031 | const char *src; |
4020 | char *dest; | 4032 | char *dest; |
4021 | int count; | 4033 | int count; |
@@ -4823,15 +4835,15 @@ static int filechar(struct ioarg *ap) | |||
4823 | } | 4835 | } |
4824 | #if ENABLE_FEATURE_EDITING | 4836 | #if ENABLE_FEATURE_EDITING |
4825 | if (interactive && isatty(ap->afile)) { | 4837 | if (interactive && isatty(ap->afile)) { |
4826 | static char mycommand[BUFSIZ]; | 4838 | /* moved to G: static char filechar_cmdbuf[BUFSIZ]; */ |
4827 | static int position = 0, size = 0; | 4839 | static int position = 0, size = 0; |
4828 | 4840 | ||
4829 | while (size == 0 || position >= size) { | 4841 | while (size == 0 || position >= size) { |
4830 | read_line_input(current_prompt, mycommand, BUFSIZ, line_input_state); | 4842 | read_line_input(current_prompt, filechar_cmdbuf, BUFSIZ, line_input_state); |
4831 | size = strlen(mycommand); | 4843 | size = strlen(filechar_cmdbuf); |
4832 | position = 0; | 4844 | position = 0; |
4833 | } | 4845 | } |
4834 | c = mycommand[position]; | 4846 | c = filechar_cmdbuf[position]; |
4835 | position++; | 4847 | position++; |
4836 | return c; | 4848 | return c; |
4837 | } | 4849 | } |
@@ -5176,6 +5188,12 @@ int msh_main(int argc, char **argv) | |||
5176 | char *name, **ap; | 5188 | char *name, **ap; |
5177 | int (*iof) (struct ioarg *); | 5189 | int (*iof) (struct ioarg *); |
5178 | 5190 | ||
5191 | PTR_TO_GLOBALS = xzalloc(sizeof(G)); | ||
5192 | sharedbuf.id = AFID_NOBUF; | ||
5193 | mainbuf.id = AFID_NOBUF; | ||
5194 | e.linep = line; | ||
5195 | elinep = line + sizeof(line) - 5; | ||
5196 | |||
5179 | #if ENABLE_FEATURE_EDITING | 5197 | #if ENABLE_FEATURE_EDITING |
5180 | line_input_state = new_line_input_t(FOR_SHELL); | 5198 | line_input_state = new_line_input_t(FOR_SHELL); |
5181 | #endif | 5199 | #endif |