diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-02 12:49:39 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-02 12:49:39 +0000 |
| commit | 509697f00df5286674fdbdf7b02a57fea83636d0 (patch) | |
| tree | 8c66aaf36eb6248bb8a212dfff05ea96608d93c8 /shell | |
| parent | da8ae753400906fdd236699bfcb60975ec659aa7 (diff) | |
| download | busybox-w32-509697f00df5286674fdbdf7b02a57fea83636d0.tar.gz busybox-w32-509697f00df5286674fdbdf7b02a57fea83636d0.tar.bz2 busybox-w32-509697f00df5286674fdbdf7b02a57fea83636d0.zip | |
msh: renames: ->words => ->op_words, space() => get_space()
msh: simplify glob0/glob1/glob2/glob3
get_space - 26 +26
glob3 35 34 -1
glob2 28 27 -1
strsave 55 53 -2
globv 4 - -4
func 4 - -4
xstrcmp 25 12 -13
dodot 178 164 -14
rexecve 272 257 -15
space 26 - -26
glob1 292 256 -36
expand 2246 2209 -37
------------------------------------------------------------------------------
(add/remove: 1/3 grow/shrink: 0/8 up/down: 26/-153) Total: -127 bytes
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/msh.c | 206 |
1 files changed, 99 insertions, 107 deletions
diff --git a/shell/msh.c b/shell/msh.c index e98c6017a..cde18d08f 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
| @@ -90,7 +90,7 @@ static char *itoa(int n) | |||
| 90 | //#define MSHDEBUG 4 | 90 | //#define MSHDEBUG 4 |
| 91 | 91 | ||
| 92 | #ifdef MSHDEBUG | 92 | #ifdef MSHDEBUG |
| 93 | int mshdbg = MSHDEBUG; | 93 | static int mshdbg = MSHDEBUG; |
| 94 | 94 | ||
| 95 | #define DBGPRINTF(x) if (mshdbg>0) printf x | 95 | #define DBGPRINTF(x) if (mshdbg>0) printf x |
| 96 | #define DBGPRINTF0(x) if (mshdbg>0) printf x | 96 | #define DBGPRINTF0(x) if (mshdbg>0) printf x |
| @@ -104,7 +104,7 @@ int mshdbg = MSHDEBUG; | |||
| 104 | #define DBGPRINTF8(x) if (mshdbg>8) printf x | 104 | #define DBGPRINTF8(x) if (mshdbg>8) printf x |
| 105 | #define DBGPRINTF9(x) if (mshdbg>9) printf x | 105 | #define DBGPRINTF9(x) if (mshdbg>9) printf x |
| 106 | 106 | ||
| 107 | int mshdbg_rc = 0; | 107 | static int mshdbg_rc = 0; |
| 108 | 108 | ||
| 109 | #define RCPRINTF(x) if (mshdbg_rc) printf x | 109 | #define RCPRINTF(x) if (mshdbg_rc) printf x |
| 110 | 110 | ||
| @@ -195,7 +195,7 @@ struct ioword { | |||
| 195 | */ | 195 | */ |
| 196 | struct op { | 196 | struct op { |
| 197 | smallint type; /* operation type, see Txxxx below */ | 197 | smallint type; /* operation type, see Txxxx below */ |
| 198 | char **words; /* arguments to a command */ | 198 | char **op_words; /* arguments to a command */ |
| 199 | struct ioword **ioact; /* IO actions (eg, < > >>) */ | 199 | struct ioword **ioact; /* IO actions (eg, < > >>) */ |
| 200 | struct op *left; | 200 | struct op *left; |
| 201 | struct op *right; | 201 | struct op *right; |
| @@ -528,8 +528,8 @@ static void globname(char *we, char *pp); | |||
| 528 | static char *generate(char *start1, char *end1, char *middle, char *end); | 528 | static char *generate(char *start1, char *end1, char *middle, char *end); |
| 529 | static int anyspcl(struct wdblock *wb); | 529 | static int anyspcl(struct wdblock *wb); |
| 530 | static int xstrcmp(char *p1, char *p2); | 530 | static int xstrcmp(char *p1, char *p2); |
| 531 | static void glob0(char *a0, unsigned a1, int a2, | 531 | static void glob0(char *a0, unsigned a1 |
| 532 | int (*a3) (char *, char *)); | 532 | /*, int item_sz, int (*f)(char *, char *) */); |
| 533 | static void readhere(char **name, char *s, int ec); | 533 | static void readhere(char **name, char *s, int ec); |
| 534 | static int xxchar(struct ioarg *ap); | 534 | static int xxchar(struct ioarg *ap); |
| 535 | 535 | ||
| @@ -722,17 +722,7 @@ struct globals { | |||
| 722 | #define RUN(what, arg, gen) ((temparg.what = (arg)), run(&temparg, (gen))) | 722 | #define RUN(what, arg, gen) ((temparg.what = (arg)), run(&temparg, (gen))) |
| 723 | 723 | ||
| 724 | #ifdef MSHDEBUG | 724 | #ifdef MSHDEBUG |
| 725 | void print_t(struct op *t) | 725 | static void print_tree(struct op *head) |
| 726 | { | ||
| 727 | DBGPRINTF(("T: t=%p, type %s, words=%p, IOword=%p\n", t, | ||
| 728 | T_CMD_NAMES[t->type], t->words, t->ioact)); | ||
| 729 | |||
| 730 | if (t->words) { | ||
| 731 | DBGPRINTF(("T: W1: %s", t->words[0])); | ||
| 732 | } | ||
| 733 | } | ||
| 734 | |||
| 735 | void print_tree(struct op *head) | ||
| 736 | { | 726 | { |
| 737 | if (head == NULL) { | 727 | if (head == NULL) { |
| 738 | DBGPRINTF(("PRINT_TREE: no tree\n")); | 728 | DBGPRINTF(("PRINT_TREE: no tree\n")); |
| @@ -1002,7 +992,7 @@ static void garbage(void) | |||
| 1002 | #endif | 992 | #endif |
| 1003 | } | 993 | } |
| 1004 | 994 | ||
| 1005 | static char *space(int n) | 995 | static void *get_space(int n) |
| 1006 | { | 996 | { |
| 1007 | char *cp; | 997 | char *cp; |
| 1008 | 998 | ||
| @@ -1016,7 +1006,7 @@ static char *strsave(const char *s, int a) | |||
| 1016 | { | 1006 | { |
| 1017 | char *cp; | 1007 | char *cp; |
| 1018 | 1008 | ||
| 1019 | cp = space(strlen(s) + 1); | 1009 | cp = get_space(strlen(s) + 1); |
| 1020 | if (cp == NULL) { | 1010 | if (cp == NULL) { |
| 1021 | // FIXME: I highly doubt this is good. | 1011 | // FIXME: I highly doubt this is good. |
| 1022 | return (char*)""; | 1012 | return (char*)""; |
| @@ -1074,8 +1064,8 @@ static struct var *lookup(const char *n) | |||
| 1074 | return vp; | 1064 | return vp; |
| 1075 | 1065 | ||
| 1076 | cp = findeq(n); | 1066 | cp = findeq(n); |
| 1077 | vp = (struct var *) space(sizeof(*vp)); | 1067 | vp = get_space(sizeof(*vp)); |
| 1078 | if (vp == 0 || (vp->name = space((int) (cp - n) + 2)) == 0) { | 1068 | if (vp == 0 || (vp->name = get_space((int) (cp - n) + 2)) == NULL) { |
| 1079 | dummy.name = dummy.value = (char*)""; | 1069 | dummy.name = dummy.value = (char*)""; |
| 1080 | return &dummy; | 1070 | return &dummy; |
| 1081 | } | 1071 | } |
| @@ -1116,7 +1106,7 @@ static void nameval(struct var *vp, const char *val, const char *name) | |||
| 1116 | } | 1106 | } |
| 1117 | fl = 0; | 1107 | fl = 0; |
| 1118 | if (name == NULL) { | 1108 | if (name == NULL) { |
| 1119 | xp = space(strlen(vp->name) + strlen(val) + 2); | 1109 | xp = get_space(strlen(vp->name) + strlen(val) + 2); |
| 1120 | if (xp == NULL) | 1110 | if (xp == NULL) |
| 1121 | return; | 1111 | return; |
| 1122 | /* make string: name=value */ | 1112 | /* make string: name=value */ |
| @@ -1310,12 +1300,12 @@ struct op *scantree(struct op *head) | |||
| 1310 | return dotnode; | 1300 | return dotnode; |
| 1311 | } | 1301 | } |
| 1312 | 1302 | ||
| 1313 | if (head->words == NULL) | 1303 | if (head->op_words == NULL) |
| 1314 | return NULL; | 1304 | return NULL; |
| 1315 | 1305 | ||
| 1316 | DBGPRINTF5(("SCANTREE: checking node %p\n", head)); | 1306 | DBGPRINTF5(("SCANTREE: checking node %p\n", head)); |
| 1317 | 1307 | ||
| 1318 | if ((head->type != TDOT) && LONE_CHAR(head->words[0], '.')) { | 1308 | if ((head->type != TDOT) && LONE_CHAR(head->op_words[0], '.')) { |
| 1319 | DBGPRINTF5(("SCANTREE: dot found in node %p\n", head)); | 1309 | DBGPRINTF5(("SCANTREE: dot found in node %p\n", head)); |
| 1320 | return head; | 1310 | return head; |
| 1321 | } | 1311 | } |
| @@ -1398,7 +1388,7 @@ static int newenv(int f) | |||
| 1398 | return 1; | 1388 | return 1; |
| 1399 | } | 1389 | } |
| 1400 | 1390 | ||
| 1401 | ep = (struct env *) space(sizeof(*ep)); | 1391 | ep = get_space(sizeof(*ep)); |
| 1402 | if (ep == NULL) { | 1392 | if (ep == NULL) { |
| 1403 | while (global_env.oenv) | 1393 | while (global_env.oenv) |
| 1404 | quitenv(); | 1394 | quitenv(); |
| @@ -1664,8 +1654,8 @@ static struct op *c_list(void) | |||
| 1664 | t = block(TASYNC, t, NOBLOCK, NOWORDS); | 1654 | t = block(TASYNC, t, NOBLOCK, NOWORDS); |
| 1665 | 1655 | ||
| 1666 | while ((c = yylex(0)) == ';' || c == '&' | 1656 | while ((c = yylex(0)) == ';' || c == '&' |
| 1667 | || (multiline && c == '\n')) { | 1657 | || (multiline && c == '\n') |
| 1668 | 1658 | ) { | |
| 1669 | p = andor(); | 1659 | p = andor(); |
| 1670 | if (p== NULL) | 1660 | if (p== NULL) |
| 1671 | return t; | 1661 | return t; |
| @@ -1807,7 +1797,7 @@ static struct op *command(int cf) | |||
| 1807 | startl = 1; | 1797 | startl = 1; |
| 1808 | t->str = yylval.cp; | 1798 | t->str = yylval.cp; |
| 1809 | multiline++; | 1799 | multiline++; |
| 1810 | t->words = wordlist(); | 1800 | t->op_words = wordlist(); |
| 1811 | c = yylex(0); | 1801 | c = yylex(0); |
| 1812 | if (c != '\n' && c != ';') | 1802 | if (c != '\n' && c != ';') |
| 1813 | peeksym = c; | 1803 | peeksym = c; |
| @@ -1822,7 +1812,7 @@ static struct op *command(int cf) | |||
| 1822 | t->type = (c == WHILE ? TWHILE : TUNTIL); | 1812 | t->type = (c == WHILE ? TWHILE : TUNTIL); |
| 1823 | t->left = c_list(); | 1813 | t->left = c_list(); |
| 1824 | t->right = dogroup(1); | 1814 | t->right = dogroup(1); |
| 1825 | /* t->words = NULL; - newtp() did this */ | 1815 | /* t->op_words = NULL; - newtp() did this */ |
| 1826 | multiline--; | 1816 | multiline--; |
| 1827 | break; | 1817 | break; |
| 1828 | 1818 | ||
| @@ -1856,17 +1846,18 @@ static struct op *command(int cf) | |||
| 1856 | t = newtp(); | 1846 | t = newtp(); |
| 1857 | t->type = TDOT; | 1847 | t->type = TDOT; |
| 1858 | 1848 | ||
| 1859 | musthave(WORD, 0); /* gets name of file */ | 1849 | musthave(WORD, 0); /* gets name of file */ |
| 1860 | DBGPRINTF7(("COMMAND: DOT clause, yylval.cp is %s\n", yylval.cp)); | 1850 | DBGPRINTF7(("COMMAND: DOT clause, yylval.cp is %s\n", yylval.cp)); |
| 1861 | 1851 | ||
| 1862 | word(yylval.cp); /* add word to wdlist */ | 1852 | word(yylval.cp); /* add word to wdlist */ |
| 1863 | word(NOWORD); /* terminate wdlist */ | 1853 | word(NOWORD); /* terminate wdlist */ |
| 1864 | t->words = copyw(); /* dup wdlist */ | 1854 | t->op_words = copyw(); /* dup wdlist */ |
| 1865 | break; | 1855 | break; |
| 1866 | 1856 | ||
| 1867 | } | 1857 | } |
| 1868 | 1858 | ||
| 1869 | while (synio(0)); | 1859 | while (synio(0)) |
| 1860 | continue; | ||
| 1870 | 1861 | ||
| 1871 | t = namelist(t); | 1862 | t = namelist(t); |
| 1872 | iolist = iosave; | 1863 | iolist = iosave; |
| @@ -1971,7 +1962,7 @@ static struct op *casepart(void) | |||
| 1971 | 1962 | ||
| 1972 | t = newtp(); | 1963 | t = newtp(); |
| 1973 | t->type = TPAT; | 1964 | t->type = TPAT; |
| 1974 | t->words = pattern(); | 1965 | t->op_words = pattern(); |
| 1975 | musthave(')', 0); | 1966 | musthave(')', 0); |
| 1976 | t->left = c_list(); | 1967 | t->left = c_list(); |
| 1977 | peeksym = yylex(CONTIN); | 1968 | peeksym = yylex(CONTIN); |
| @@ -2042,7 +2033,7 @@ static struct op *block(int type, struct op *t1, struct op *t2, char **wp) | |||
| 2042 | t->type = type; | 2033 | t->type = type; |
| 2043 | t->left = t1; | 2034 | t->left = t1; |
| 2044 | t->right = t2; | 2035 | t->right = t2; |
| 2045 | t->words = wp; | 2036 | t->op_words = wp; |
| 2046 | 2037 | ||
| 2047 | DBGPRINTF7(("BLOCK: inserted %p between %p and %p\n", t, t1, t2)); | 2038 | DBGPRINTF7(("BLOCK: inserted %p between %p and %p\n", t, t1, t2)); |
| 2048 | 2039 | ||
| @@ -2126,7 +2117,7 @@ static struct op *namelist(struct op *t) | |||
| 2126 | } | 2117 | } |
| 2127 | 2118 | ||
| 2128 | word(NOWORD); | 2119 | word(NOWORD); |
| 2129 | t->words = copyw(); | 2120 | t->op_words = copyw(); |
| 2130 | 2121 | ||
| 2131 | return t; | 2122 | return t; |
| 2132 | } | 2123 | } |
| @@ -2190,7 +2181,7 @@ static int yylex(int cf) | |||
| 2190 | 2181 | ||
| 2191 | loop: | 2182 | loop: |
| 2192 | while ((c = my_getc(0)) == ' ' || c == '\t') /* Skip whitespace */ | 2183 | while ((c = my_getc(0)) == ' ' || c == '\t') /* Skip whitespace */ |
| 2193 | ; | 2184 | continue; |
| 2194 | 2185 | ||
| 2195 | switch (c) { | 2186 | switch (c) { |
| 2196 | default: | 2187 | default: |
| @@ -2207,7 +2198,8 @@ static int yylex(int cf) | |||
| 2207 | break; | 2198 | break; |
| 2208 | 2199 | ||
| 2209 | case '#': /* Comment, skip to next newline or End-of-string */ | 2200 | case '#': /* Comment, skip to next newline or End-of-string */ |
| 2210 | while ((c = my_getc(0)) != '\0' && c != '\n'); | 2201 | while ((c = my_getc(0)) != '\0' && c != '\n') |
| 2202 | continue; | ||
| 2211 | unget(c); | 2203 | unget(c); |
| 2212 | goto loop; | 2204 | goto loop; |
| 2213 | 2205 | ||
| @@ -2424,7 +2416,7 @@ static struct op **find1case(struct op *t, const char *w) | |||
| 2424 | } else | 2416 | } else |
| 2425 | t1 = t; | 2417 | t1 = t; |
| 2426 | 2418 | ||
| 2427 | for (wp = t1->words; *wp;) { | 2419 | for (wp = t1->op_words; *wp;) { |
| 2428 | cp = evalstr(*wp++, DOSUB); | 2420 | cp = evalstr(*wp++, DOSUB); |
| 2429 | if (cp && gmatch(w, cp)) { | 2421 | if (cp && gmatch(w, cp)) { |
| 2430 | DBGPRINTF3(("FIND1CASE: returning &t1->left= %p.\n", | 2422 | DBGPRINTF3(("FIND1CASE: returning &t1->left= %p.\n", |
| @@ -2469,13 +2461,13 @@ static int execute(struct op *t, int *pin, int *pout, int no_fork) | |||
| 2469 | return 0; | 2461 | return 0; |
| 2470 | } | 2462 | } |
| 2471 | 2463 | ||
| 2472 | DBGPRINTF(("EXECUTE: t=%p, t->type=%d (%s), t->words is %s\n", t, | 2464 | DBGPRINTF(("EXECUTE: t=%p, t->type=%d (%s), t->op_words is %s\n", t, |
| 2473 | t->type, T_CMD_NAMES[t->type], | 2465 | t->type, T_CMD_NAMES[t->type], |
| 2474 | ((t->words == NULL) ? "NULL" : t->words[0]))); | 2466 | ((t->op_words == NULL) ? "NULL" : t->op_words[0]))); |
| 2475 | 2467 | ||
| 2476 | rv = 0; | 2468 | rv = 0; |
| 2477 | a = areanum++; | 2469 | a = areanum++; |
| 2478 | wp2 = t->words; | 2470 | wp2 = t->op_words; |
| 2479 | wp = (wp2 != NULL) | 2471 | wp = (wp2 != NULL) |
| 2480 | ? eval(wp2, t->type == TCOM ? DOALL : DOALL & ~DOKEY) | 2472 | ? eval(wp2, t->type == TCOM ? DOALL : DOALL & ~DOKEY) |
| 2481 | : NULL; | 2473 | : NULL; |
| @@ -2486,7 +2478,7 @@ static int execute(struct op *t, int *pin, int *pout, int no_fork) | |||
| 2486 | 2478 | ||
| 2487 | outtree_save = outtree; | 2479 | outtree_save = outtree; |
| 2488 | 2480 | ||
| 2489 | newfile(evalstr(t->words[0], DOALL)); | 2481 | newfile(evalstr(t->op_words[0], DOALL)); |
| 2490 | 2482 | ||
| 2491 | t->left = dowholefile(TLIST, 0); | 2483 | t->left = dowholefile(TLIST, 0); |
| 2492 | t->right = NULL; | 2484 | t->right = NULL; |
| @@ -2575,7 +2567,8 @@ static int execute(struct op *t, int *pin, int *pout, int no_fork) | |||
| 2575 | i = 0; | 2567 | i = 0; |
| 2576 | } else { | 2568 | } else { |
| 2577 | i = -1; | 2569 | i = -1; |
| 2578 | while (*wp++ != NULL); | 2570 | while (*wp++ != NULL) |
| 2571 | continue; | ||
| 2579 | } | 2572 | } |
| 2580 | vp = lookup(t->str); | 2573 | vp = lookup(t->str); |
| 2581 | while (setjmp(bc.brkpt)) | 2574 | while (setjmp(bc.brkpt)) |
| @@ -2648,7 +2641,9 @@ static int execute(struct op *t, int *pin, int *pout, int no_fork) | |||
| 2648 | }; | 2641 | }; |
| 2649 | 2642 | ||
| 2650 | broken: | 2643 | broken: |
| 2651 | t->words = wp2; | 2644 | // Restoring op_words is most likely not needed now: see comment in forkexec() |
| 2645 | // (also take a look at exec builtin (doexec) - it touches t->op_words) | ||
| 2646 | t->op_words = wp2; | ||
| 2652 | isbreak = 0; | 2647 | isbreak = 0; |
| 2653 | freehere(areanum); | 2648 | freehere(areanum); |
| 2654 | freearea(areanum); | 2649 | freearea(areanum); |
| @@ -2711,8 +2706,8 @@ static int forkexec(struct op *t, int *pin, int *pout, int no_fork, char **wp) | |||
| 2711 | 2706 | ||
| 2712 | DBGPRINTF(("FORKEXEC: t=%p, pin %p, pout %p, no_fork %d\n", t, pin, | 2707 | DBGPRINTF(("FORKEXEC: t=%p, pin %p, pout %p, no_fork %d\n", t, pin, |
| 2713 | pout, no_fork)); | 2708 | pout, no_fork)); |
| 2714 | DBGPRINTF7(("FORKEXEC: t->words is %s\n", | 2709 | DBGPRINTF7(("FORKEXEC: t->op_words is %s\n", |
| 2715 | ((t->words == NULL) ? "NULL" : t->words[0]))); | 2710 | ((t->op_words == NULL) ? "NULL" : t->op_words[0]))); |
| 2716 | owp = wp; | 2711 | owp = wp; |
| 2717 | resetsig = 0; | 2712 | resetsig = 0; |
| 2718 | if (t->type == TCOM) { | 2713 | if (t->type == TCOM) { |
| @@ -2742,12 +2737,12 @@ static int forkexec(struct op *t, int *pin, int *pout, int no_fork, char **wp) | |||
| 2742 | } | 2737 | } |
| 2743 | 2738 | ||
| 2744 | forked = 0; | 2739 | forked = 0; |
| 2745 | // We were pointing t->words to temporary (expanded) arg list: | 2740 | // We were pointing t->op_words to temporary (expanded) arg list: |
| 2746 | // t->words = wp; | 2741 | // t->op_words = wp; |
| 2747 | // and restored it later (in execute()), but "break" | 2742 | // and restored it later (in execute()), but "break" |
| 2748 | // longjmps away (at "Run builtin" below), leaving t->words clobbered! | 2743 | // longjmps away (at "Run builtin" below), leaving t->op_words clobbered! |
| 2749 | // See http://bugs.busybox.net/view.php?id=846. | 2744 | // See http://bugs.busybox.net/view.php?id=846. |
| 2750 | // Now we do not touch t->words, but separately pass wp as param list | 2745 | // Now we do not touch t->op_words, but separately pass wp as param list |
| 2751 | // to builtins | 2746 | // to builtins |
| 2752 | DBGPRINTF(("FORKEXEC: bltin %p, no_fork %d, owp %p\n", bltin, | 2747 | DBGPRINTF(("FORKEXEC: bltin %p, no_fork %d, owp %p\n", bltin, |
| 2753 | no_fork, owp)); | 2748 | no_fork, owp)); |
| @@ -3050,7 +3045,6 @@ static int setstatus(int s) | |||
| 3050 | */ | 3045 | */ |
| 3051 | static const char *rexecve(char *c, char **v, char **envp) | 3046 | static const char *rexecve(char *c, char **v, char **envp) |
| 3052 | { | 3047 | { |
| 3053 | int i; | ||
| 3054 | const char *sp; | 3048 | const char *sp; |
| 3055 | char *tp; | 3049 | char *tp; |
| 3056 | int asis = 0; | 3050 | int asis = 0; |
| @@ -3081,7 +3075,9 @@ static const char *rexecve(char *c, char **v, char **envp) | |||
| 3081 | } | 3075 | } |
| 3082 | if (tp != global_env.linep) | 3076 | if (tp != global_env.linep) |
| 3083 | *tp++ = '/'; | 3077 | *tp++ = '/'; |
| 3084 | for (i = 0; (*tp++ = c[i++]) != '\0';); | 3078 | strcpy(tp, c); |
| 3079 | //for (i = 0; (*tp++ = c[i++]) != '\0';) | ||
| 3080 | // continue; | ||
| 3085 | 3081 | ||
| 3086 | DBGPRINTF3(("REXECVE: global_env.linep is %s\n", global_env.linep)); | 3082 | DBGPRINTF3(("REXECVE: global_env.linep is %s\n", global_env.linep)); |
| 3087 | 3083 | ||
| @@ -3090,11 +3086,12 @@ static const char *rexecve(char *c, char **v, char **envp) | |||
| 3090 | switch (errno) { | 3086 | switch (errno) { |
| 3091 | case ENOEXEC: | 3087 | case ENOEXEC: |
| 3092 | *v = global_env.linep; | 3088 | *v = global_env.linep; |
| 3093 | tp = *--v; | 3089 | v--; |
| 3090 | tp = *v; | ||
| 3094 | *v = global_env.linep; | 3091 | *v = global_env.linep; |
| 3095 | execve(DEFAULT_SHELL, v, envp); | 3092 | execve(DEFAULT_SHELL, v, envp); |
| 3096 | *v = tp; | 3093 | *v = tp; |
| 3097 | return "no Shell"; | 3094 | return "no shell"; |
| 3098 | 3095 | ||
| 3099 | case ENOMEM: | 3096 | case ENOMEM: |
| 3100 | return (char *) bb_msg_memory_exhausted; | 3097 | return (char *) bb_msg_memory_exhausted; |
| @@ -3295,14 +3292,14 @@ static int doexec(struct op *t, char **args) | |||
| 3295 | ofail = failpt; | 3292 | ofail = failpt; |
| 3296 | failpt = ex; | 3293 | failpt = ex; |
| 3297 | 3294 | ||
| 3298 | sv_words = t->words; | 3295 | sv_words = t->op_words; |
| 3299 | t->words = args + 1; | 3296 | t->op_words = args + 1; |
| 3300 | // TODO: test what will happen with "exec break" - | 3297 | // TODO: test what will happen with "exec break" - |
| 3301 | // will it leave t->words pointing to garbage? | 3298 | // will it leave t->op_words pointing to garbage? |
| 3302 | // (see http://bugs.busybox.net/view.php?id=846) | 3299 | // (see http://bugs.busybox.net/view.php?id=846) |
| 3303 | if (setjmp(failpt) == 0) | 3300 | if (setjmp(failpt) == 0) |
| 3304 | execute(t, NOPIPE, NOPIPE, /* no_fork: */ 1); | 3301 | execute(t, NOPIPE, NOPIPE, /* no_fork: */ 1); |
| 3305 | t->words = sv_words; | 3302 | t->op_words = sv_words; |
| 3306 | 3303 | ||
| 3307 | failpt = ofail; | 3304 | failpt = ofail; |
| 3308 | execflg = 0; | 3305 | execflg = 0; |
| @@ -3340,8 +3337,7 @@ static int dodot(struct op *t, char **args) | |||
| 3340 | tp++; | 3337 | tp++; |
| 3341 | if (tp != global_env.linep) | 3338 | if (tp != global_env.linep) |
| 3342 | *tp++ = '/'; | 3339 | *tp++ = '/'; |
| 3343 | 3340 | strcpy(tp, cp); | |
| 3344 | for (i = 0; (*tp++ = cp[i++]) != '\0';); | ||
| 3345 | 3341 | ||
| 3346 | /* Original code */ | 3342 | /* Original code */ |
| 3347 | i = open(global_env.linep, O_RDONLY); | 3343 | i = open(global_env.linep, O_RDONLY); |
| @@ -3566,7 +3562,8 @@ static void rdexp(char **wp, void (*f) (struct var *), int key) | |||
| 3566 | char *cp; | 3562 | char *cp; |
| 3567 | 3563 | ||
| 3568 | assign(*wp, COPYV); | 3564 | assign(*wp, COPYV); |
| 3569 | for (cp = *wp; *cp != '='; cp++); | 3565 | for (cp = *wp; *cp != '='; cp++) |
| 3566 | continue; | ||
| 3570 | *cp = '\0'; | 3567 | *cp = '\0'; |
| 3571 | } | 3568 | } |
| 3572 | if (checkname(*wp)) | 3569 | if (checkname(*wp)) |
| @@ -4173,7 +4170,8 @@ static int grave(int quoted) | |||
| 4173 | if (openpipe(pf) < 0) | 4170 | if (openpipe(pf) < 0) |
| 4174 | return 0; | 4171 | return 0; |
| 4175 | 4172 | ||
| 4176 | while ((i = vfork()) == -1 && errno == EAGAIN); | 4173 | while ((i = vfork()) == -1 && errno == EAGAIN) |
| 4174 | continue; | ||
| 4177 | 4175 | ||
| 4178 | DBGPRINTF3(("GRAVE: i is %p\n", io)); | 4176 | DBGPRINTF3(("GRAVE: i is %p\n", io)); |
| 4179 | 4177 | ||
| @@ -4273,7 +4271,7 @@ static struct wdblock *glob(char *cp, struct wdblock *wb) | |||
| 4273 | } | 4271 | } |
| 4274 | for (i = 0; i < cl->w_nword; i++) | 4272 | for (i = 0; i < cl->w_nword; i++) |
| 4275 | unquote(cl->w_words[i]); | 4273 | unquote(cl->w_words[i]); |
| 4276 | glob0((char *) cl->w_words, cl->w_nword, sizeof(char *), xstrcmp); | 4274 | glob0((char *) cl->w_words, cl->w_nword /*, sizeof(char *), xstrcmp*/); |
| 4277 | if (cl->w_nword) { | 4275 | if (cl->w_nword) { |
| 4278 | for (i = 0; i < cl->w_nword; i++) | 4276 | for (i = 0; i < cl->w_nword; i++) |
| 4279 | wb = addword(cl->w_words[i], wb); | 4277 | wb = addword(cl->w_words[i], wb); |
| @@ -4298,11 +4296,11 @@ static void globname(char *we, char *pp) | |||
| 4298 | for (np = we; np != pp; pp--) | 4296 | for (np = we; np != pp; pp--) |
| 4299 | if (pp[-1] == '/') | 4297 | if (pp[-1] == '/') |
| 4300 | break; | 4298 | break; |
| 4301 | for (dp = cp = space((int) (pp - np) + 3); np < pp;) | 4299 | for (dp = cp = get_space((int) (pp - np) + 3); np < pp;) |
| 4302 | *cp++ = *np++; | 4300 | *cp++ = *np++; |
| 4303 | *cp++ = '.'; | 4301 | *cp++ = '.'; |
| 4304 | *cp = '\0'; | 4302 | *cp = '\0'; |
| 4305 | for (gp = cp = space(strlen(pp) + 1); *np && *np != '/';) | 4303 | for (gp = cp = get_space(strlen(pp) + 1); *np && *np != '/';) |
| 4306 | *cp++ = *np++; | 4304 | *cp++ = *np++; |
| 4307 | *cp = '\0'; | 4305 | *cp = '\0'; |
| 4308 | dirp = opendir(dp); | 4306 | dirp = opendir(dp); |
| @@ -4351,12 +4349,14 @@ static char *generate(char *start1, char *end1, char *middle, char *end) | |||
| 4351 | char *p; | 4349 | char *p; |
| 4352 | char *op, *xp; | 4350 | char *op, *xp; |
| 4353 | 4351 | ||
| 4354 | p = op = space((int)(end1 - start1) + strlen(middle) + strlen(end) + 2); | 4352 | p = op = get_space((int)(end1 - start1) + strlen(middle) + strlen(end) + 2); |
| 4355 | for (xp = start1; xp != end1;) | 4353 | xp = start1; |
| 4354 | while (xp != end1) | ||
| 4355 | *op++ = *xp++; | ||
| 4356 | xp = middle; | ||
| 4357 | while (*xp != '\0') | ||
| 4356 | *op++ = *xp++; | 4358 | *op++ = *xp++; |
| 4357 | for (xp = middle; (*op++ = *xp++) != '\0';); | 4359 | strcpy(op, end); |
| 4358 | op--; | ||
| 4359 | for (xp = end; (*op++ = *xp++) != '\0';); | ||
| 4360 | return p; | 4360 | return p; |
| 4361 | } | 4361 | } |
| 4362 | 4362 | ||
| @@ -4384,7 +4384,7 @@ static struct wdblock *newword(int nw) | |||
| 4384 | { | 4384 | { |
| 4385 | struct wdblock *wb; | 4385 | struct wdblock *wb; |
| 4386 | 4386 | ||
| 4387 | wb = (struct wdblock *) space(sizeof(*wb) + nw * sizeof(char *)); | 4387 | wb = get_space(sizeof(*wb) + nw * sizeof(char *)); |
| 4388 | wb->w_bsize = nw; | 4388 | wb->w_bsize = nw; |
| 4389 | wb->w_nword = 0; | 4389 | wb->w_nword = 0; |
| 4390 | return wb; | 4390 | return wb; |
| @@ -4421,43 +4421,34 @@ static char **getwords(struct wdblock *wb) | |||
| 4421 | DELETE(wb); | 4421 | DELETE(wb); |
| 4422 | return NULL; | 4422 | return NULL; |
| 4423 | } | 4423 | } |
| 4424 | wd = (char **) space(nb = sizeof(*wd) * wb->w_nword); | 4424 | nb = sizeof(*wd) * wb->w_nword; |
| 4425 | wd = get_space(nb); | ||
| 4425 | memcpy((char *) wd, (char *) wb->w_words, nb); | 4426 | memcpy((char *) wd, (char *) wb->w_words, nb); |
| 4426 | DELETE(wb); /* perhaps should done by caller */ | 4427 | DELETE(wb); /* perhaps should done by caller */ |
| 4427 | return wd; | 4428 | return wd; |
| 4428 | } | 4429 | } |
| 4429 | 4430 | ||
| 4430 | static int (*func) (char *, char *); | 4431 | /*static int (*cmp_func) (char *, char *);*/ |
| 4431 | static int globv; | 4432 | /*static int glob_item_sz;*/ |
| 4433 | #define cmp_func xstrcmp | ||
| 4434 | enum { glob_item_sz = sizeof(char *) }; | ||
| 4432 | 4435 | ||
| 4433 | static void glob3(char *i, char *j, char *k) | 4436 | static void glob3(char *index1, char *index2, char *index3) |
| 4434 | { | 4437 | { |
| 4435 | char *index1, *index2, *index3; | 4438 | int m = glob_item_sz; |
| 4436 | int c; | ||
| 4437 | int m; | ||
| 4438 | |||
| 4439 | m = globv; | ||
| 4440 | index1 = i; | ||
| 4441 | index2 = j; | ||
| 4442 | index3 = k; | ||
| 4443 | do { | 4439 | do { |
| 4444 | c = *index1; | 4440 | char c = *index1; |
| 4445 | *index1++ = *index3; | 4441 | *index1++ = *index3; |
| 4446 | *index3++ = *index2; | 4442 | *index3++ = *index2; |
| 4447 | *index2++ = c; | 4443 | *index2++ = c; |
| 4448 | } while (--m); | 4444 | } while (--m); |
| 4449 | } | 4445 | } |
| 4450 | 4446 | ||
| 4451 | static void glob2(char *i, char *j) | 4447 | static void glob2(char *index1, char *index2) |
| 4452 | { | 4448 | { |
| 4453 | char *index1, *index2, c; | 4449 | int m = glob_item_sz; |
| 4454 | int m; | ||
| 4455 | |||
| 4456 | m = globv; | ||
| 4457 | index1 = i; | ||
| 4458 | index2 = j; | ||
| 4459 | do { | 4450 | do { |
| 4460 | c = *index1; | 4451 | char c = *index1; |
| 4461 | *index1++ = *index2; | 4452 | *index1++ = *index2; |
| 4462 | *index2++ = c; | 4453 | *index2++ = c; |
| 4463 | } while (--m); | 4454 | } while (--m); |
| @@ -4471,8 +4462,7 @@ static void glob1(char *base, char *lim) | |||
| 4471 | int c; | 4462 | int c; |
| 4472 | unsigned n; | 4463 | unsigned n; |
| 4473 | 4464 | ||
| 4474 | v2 = globv; | 4465 | v2 = glob_item_sz; |
| 4475 | |||
| 4476 | top: | 4466 | top: |
| 4477 | n = (int) (lim - base); | 4467 | n = (int) (lim - base); |
| 4478 | if (n <= v2) | 4468 | if (n <= v2) |
| @@ -4483,7 +4473,7 @@ static void glob1(char *base, char *lim) | |||
| 4483 | j = lim - v2; | 4473 | j = lim - v2; |
| 4484 | for (;;) { | 4474 | for (;;) { |
| 4485 | if (i < lptr) { | 4475 | if (i < lptr) { |
| 4486 | c = (*func) (i, lptr); | 4476 | c = cmp_func(i, lptr); |
| 4487 | if (c == 0) { | 4477 | if (c == 0) { |
| 4488 | lptr -= v2; | 4478 | lptr -= v2; |
| 4489 | glob2(i, lptr); | 4479 | glob2(i, lptr); |
| @@ -4494,10 +4484,9 @@ static void glob1(char *base, char *lim) | |||
| 4494 | continue; | 4484 | continue; |
| 4495 | } | 4485 | } |
| 4496 | } | 4486 | } |
| 4497 | |||
| 4498 | begin: | 4487 | begin: |
| 4499 | if (j > hptr) { | 4488 | if (j > hptr) { |
| 4500 | c = (*func) (hptr, j); | 4489 | c = cmp_func(hptr, j); |
| 4501 | if (c == 0) { | 4490 | if (c == 0) { |
| 4502 | hptr += v2; | 4491 | hptr += v2; |
| 4503 | glob2(hptr, j); | 4492 | glob2(hptr, j); |
| @@ -4507,7 +4496,8 @@ static void glob1(char *base, char *lim) | |||
| 4507 | if (i == lptr) { | 4496 | if (i == lptr) { |
| 4508 | hptr += v2; | 4497 | hptr += v2; |
| 4509 | glob3(i, hptr, j); | 4498 | glob3(i, hptr, j); |
| 4510 | i = (lptr += v2); | 4499 | lptr += v2; |
| 4500 | i = lptr; | ||
| 4511 | goto begin; | 4501 | goto begin; |
| 4512 | } | 4502 | } |
| 4513 | glob2(i, j); | 4503 | glob2(i, j); |
| @@ -4519,7 +4509,6 @@ static void glob1(char *base, char *lim) | |||
| 4519 | goto begin; | 4509 | goto begin; |
| 4520 | } | 4510 | } |
| 4521 | 4511 | ||
| 4522 | |||
| 4523 | if (i == lptr) { | 4512 | if (i == lptr) { |
| 4524 | if (lptr - base >= lim - hptr) { | 4513 | if (lptr - base >= lim - hptr) { |
| 4525 | glob1(hptr + v2, lim); | 4514 | glob1(hptr + v2, lim); |
| @@ -4533,15 +4522,17 @@ static void glob1(char *base, char *lim) | |||
| 4533 | 4522 | ||
| 4534 | lptr -= v2; | 4523 | lptr -= v2; |
| 4535 | glob3(j, lptr, i); | 4524 | glob3(j, lptr, i); |
| 4536 | j = (hptr -= v2); | 4525 | hptr -= v2; |
| 4526 | j = hptr; | ||
| 4537 | } | 4527 | } |
| 4538 | } | 4528 | } |
| 4539 | 4529 | ||
| 4540 | static void glob0(char *a0, unsigned a1, int a2, int (*a3) (char *, char *)) | 4530 | static void glob0(char *a0, unsigned a1 |
| 4531 | /*, int item_sz, int (*f) (char *, char *) */) | ||
| 4541 | { | 4532 | { |
| 4542 | func = a3; | 4533 | /*cmp_func = f; - always xstrcmp */ |
| 4543 | globv = a2; | 4534 | /*glob_item_sz = item_sz; - always sizeof(char*) */ |
| 4544 | glob1(a0, a0 + a1 * a2); | 4535 | glob1(a0, a0 + a1 * /*item_sz:*/ sizeof(char*)); |
| 4545 | } | 4536 | } |
| 4546 | 4537 | ||
| 4547 | 4538 | ||
| @@ -4556,7 +4547,8 @@ static int my_getc(int ec) | |||
| 4556 | int c; | 4547 | int c; |
| 4557 | 4548 | ||
| 4558 | if (global_env.linep > elinep) { | 4549 | if (global_env.linep > elinep) { |
| 4559 | while ((c = readc()) != '\n' && c); | 4550 | while ((c = readc()) != '\n' && c) |
| 4551 | continue; | ||
| 4560 | err("input line too long"); | 4552 | err("input line too long"); |
| 4561 | gflg = 1; | 4553 | gflg = 1; |
| 4562 | return c; | 4554 | return c; |
| @@ -5003,7 +4995,7 @@ static void markhere(char *s, struct ioword *iop) | |||
| 5003 | 4995 | ||
| 5004 | DBGPRINTF7(("MARKHERE: enter, s=%p\n", s)); | 4996 | DBGPRINTF7(("MARKHERE: enter, s=%p\n", s)); |
| 5005 | 4997 | ||
| 5006 | h = (struct here *) space(sizeof(struct here)); | 4998 | h = get_space(sizeof(struct here)); |
| 5007 | if (h == NULL) | 4999 | if (h == NULL) |
| 5008 | return; | 5000 | return; |
| 5009 | 5001 | ||
