diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-01 06:00:38 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-01 06:00:38 +0000 |
commit | b1935f1c19c271354e49e37d24903d47ba5a9a85 (patch) | |
tree | 5805f241da3209c688019920bcc179cfad2b31f1 /shell | |
parent | 15dddf56d7f419be86f6d1aefa4dd5e1905c6151 (diff) | |
download | busybox-w32-b1935f1c19c271354e49e37d24903d47ba5a9a85.tar.gz busybox-w32-b1935f1c19c271354e49e37d24903d47ba5a9a85.tar.bz2 busybox-w32-b1935f1c19c271354e49e37d24903d47ba5a9a85.zip |
msh: double "static char line[LINELIM]" etc deleted.
massive amounts of assignments-in-ifs deleted
(some of which were VERY nasty)
git-svn-id: svn://busybox.net/trunk/busybox@17123 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'shell')
-rw-r--r-- | shell/msh.c | 225 |
1 files changed, 138 insertions, 87 deletions
diff --git a/shell/msh.c b/shell/msh.c index d4f534551..e43cb1875 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
@@ -138,7 +138,7 @@ struct op { | |||
138 | 138 | ||
139 | /* Strings for names to make debug easier */ | 139 | /* Strings for names to make debug easier */ |
140 | #ifdef MSHDEBUG | 140 | #ifdef MSHDEBUG |
141 | static char *T_CMD_NAMES[] = { | 141 | static const char *const T_CMD_NAMES[] = { |
142 | "PLACEHOLDER", | 142 | "PLACEHOLDER", |
143 | "TCOM", | 143 | "TCOM", |
144 | "TPAREN", | 144 | "TPAREN", |
@@ -448,11 +448,11 @@ struct io { | |||
448 | char task; /* reason for pushed IO */ | 448 | char task; /* reason for pushed IO */ |
449 | }; | 449 | }; |
450 | 450 | ||
451 | //static struct io iostack[NPUSH]; | 451 | //static struct io iostack[NPUSH]; |
452 | #define XOTHER 0 /* none of the below */ | 452 | #define XOTHER 0 /* none of the below */ |
453 | #define XDOLL 1 /* expanding ${} */ | 453 | #define XDOLL 1 /* expanding ${} */ |
454 | #define XGRAVE 2 /* expanding `'s */ | 454 | #define XGRAVE 2 /* expanding `'s */ |
455 | #define XIO 3 /* file IO */ | 455 | #define XIO 3 /* file IO */ |
456 | 456 | ||
457 | /* in substitution */ | 457 | /* in substitution */ |
458 | #define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL) | 458 | #define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL) |
@@ -694,8 +694,6 @@ static struct wdblock *iolist; | |||
694 | static char *trap[_NSIG + 1]; | 694 | static char *trap[_NSIG + 1]; |
695 | static char ourtrap[_NSIG + 1]; | 695 | static char ourtrap[_NSIG + 1]; |
696 | static int trapset; /* trap pending */ | 696 | static int trapset; /* trap pending */ |
697 | static int yynerrs; /* yacc */ | ||
698 | static char line[LINELIM]; | ||
699 | 697 | ||
700 | #ifdef MSHDEBUG | 698 | #ifdef MSHDEBUG |
701 | static struct var *mshdbg_var; | 699 | static struct var *mshdbg_var; |
@@ -746,7 +744,6 @@ static struct env e = { | |||
746 | }; | 744 | }; |
747 | 745 | ||
748 | #ifdef MSHDEBUG | 746 | #ifdef MSHDEBUG |
749 | void print_t(struct op *t); | ||
750 | void print_t(struct op *t) | 747 | void print_t(struct op *t) |
751 | { | 748 | { |
752 | DBGPRINTF(("T: t=%p, type %s, words=%p, IOword=%p\n", t, | 749 | DBGPRINTF(("T: t=%p, type %s, words=%p, IOword=%p\n", t, |
@@ -759,7 +756,6 @@ void print_t(struct op *t) | |||
759 | return; | 756 | return; |
760 | } | 757 | } |
761 | 758 | ||
762 | void print_tree(struct op *head); | ||
763 | void print_tree(struct op *head) | 759 | void print_tree(struct op *head) |
764 | { | 760 | { |
765 | if (head == NULL) { | 761 | if (head == NULL) { |
@@ -802,7 +798,8 @@ int msh_main(int argc, char **argv) | |||
802 | DBGPRINTF(("MSH_MAIN: argc %d, environ %p\n", argc, environ)); | 798 | DBGPRINTF(("MSH_MAIN: argc %d, environ %p\n", argc, environ)); |
803 | 799 | ||
804 | initarea(); | 800 | initarea(); |
805 | if ((ap = environ) != NULL) { | 801 | ap = environ; |
802 | if (ap != NULL) { | ||
806 | while (*ap) | 803 | while (*ap) |
807 | assign(*ap++, !COPYV); | 804 | assign(*ap++, !COPYV); |
808 | for (ap = environ; *ap;) | 805 | for (ap = environ; *ap;) |
@@ -989,7 +986,7 @@ static void setdash(void) | |||
989 | 986 | ||
990 | cp = m; | 987 | cp = m; |
991 | for (c = 'a'; c <= 'z'; c++) | 988 | for (c = 'a'; c <= 'z'; c++) |
992 | if (flag[(int) c]) | 989 | if (flag[c]) |
993 | *cp++ = c; | 990 | *cp++ = c; |
994 | *cp = 0; | 991 | *cp = 0; |
995 | setval(lookup("-"), m); | 992 | setval(lookup("-"), m); |
@@ -1105,7 +1102,8 @@ static void onecommand(void) | |||
1105 | leave(); | 1102 | leave(); |
1106 | } | 1103 | } |
1107 | 1104 | ||
1108 | if ((i = trapset) != 0) { | 1105 | i = trapset; |
1106 | if (i != 0) { | ||
1109 | trapset = 0; | 1107 | trapset = 0; |
1110 | runtrap(i); | 1108 | runtrap(i); |
1111 | } | 1109 | } |
@@ -1185,7 +1183,8 @@ static void quitenv(void) | |||
1185 | 1183 | ||
1186 | DBGPRINTF(("QUITENV: e.oenv=%p\n", e.oenv)); | 1184 | DBGPRINTF(("QUITENV: e.oenv=%p\n", e.oenv)); |
1187 | 1185 | ||
1188 | if ((ep = e.oenv) != NULL) { | 1186 | ep = e.oenv; |
1187 | if (ep != NULL) { | ||
1189 | fd = e.iofd; | 1188 | fd = e.iofd; |
1190 | e = *ep; | 1189 | e = *ep; |
1191 | /* should close `'d files */ | 1190 | /* should close `'d files */ |
@@ -1246,18 +1245,20 @@ static char *space(int n) | |||
1246 | { | 1245 | { |
1247 | char *cp; | 1246 | char *cp; |
1248 | 1247 | ||
1249 | if ((cp = getcell(n)) == 0) | 1248 | cp = getcell(n); |
1249 | if (cp == 0) | ||
1250 | err("out of string space"); | 1250 | err("out of string space"); |
1251 | return cp; | 1251 | return cp; |
1252 | } | 1252 | } |
1253 | 1253 | ||
1254 | static char *strsave(char *s, int a) | 1254 | static char *strsave(char *s, int a) |
1255 | { | 1255 | { |
1256 | char *cp, *xp; | 1256 | char *cp; |
1257 | 1257 | ||
1258 | if ((cp = space(strlen(s) + 1)) != NULL) { | 1258 | cp = space(strlen(s) + 1); |
1259 | setarea((char *) cp, a); | 1259 | if (cp != NULL) { |
1260 | for (xp = cp; (*xp++ = *s++) != '\0';); | 1260 | setarea(cp, a); |
1261 | strcpy(cp, s); | ||
1261 | return cp; | 1262 | return cp; |
1262 | } | 1263 | } |
1263 | return ""; | 1264 | return ""; |
@@ -1276,7 +1277,8 @@ static void runtrap(int i) | |||
1276 | { | 1277 | { |
1277 | char *trapstr; | 1278 | char *trapstr; |
1278 | 1279 | ||
1279 | if ((trapstr = trap[i]) == NULL) | 1280 | trapstr = trap[i]; |
1281 | if (trapstr == NULL) | ||
1280 | return; | 1282 | return; |
1281 | 1283 | ||
1282 | if (i == 0) | 1284 | if (i == 0) |
@@ -1488,7 +1490,8 @@ static int gmatch(char *s, char *p) | |||
1488 | sc = *s++ & QMASK; | 1490 | sc = *s++ & QMASK; |
1489 | switch (pc) { | 1491 | switch (pc) { |
1490 | case '[': | 1492 | case '[': |
1491 | if ((p = cclass(p, sc)) == NULL) | 1493 | p = cclass(p, sc); |
1494 | if (p == NULL) | ||
1492 | return 0; | 1495 | return 0; |
1493 | break; | 1496 | break; |
1494 | 1497 | ||
@@ -1633,7 +1636,8 @@ static void freecell(char *cp) | |||
1633 | { | 1636 | { |
1634 | struct region *p; | 1637 | struct region *p; |
1635 | 1638 | ||
1636 | if ((p = (struct region *) cp) != NULL) { | 1639 | p = (struct region *) cp; |
1640 | if (p != NULL) { | ||
1637 | p--; | 1641 | p--; |
1638 | if (p < areanxt) | 1642 | if (p < areanxt) |
1639 | areanxt = p; | 1643 | areanxt = p; |
@@ -1716,7 +1720,8 @@ static struct op *pipeline(int cf) | |||
1716 | 1720 | ||
1717 | if (t != NULL) { | 1721 | if (t != NULL) { |
1718 | while ((c = yylex(0)) == '|') { | 1722 | while ((c = yylex(0)) == '|') { |
1719 | if ((p = command(CONTIN)) == NULL) { | 1723 | p = command(CONTIN); |
1724 | if (p == NULL) { | ||
1720 | DBGPRINTF8(("PIPELINE: error!\n")); | 1725 | DBGPRINTF8(("PIPELINE: error!\n")); |
1721 | SYNTAXERR; | 1726 | SYNTAXERR; |
1722 | } | 1727 | } |
@@ -1748,7 +1753,8 @@ static struct op *andor(void) | |||
1748 | 1753 | ||
1749 | if (t != NULL) { | 1754 | if (t != NULL) { |
1750 | while ((c = yylex(0)) == LOGAND || c == LOGOR) { | 1755 | while ((c = yylex(0)) == LOGAND || c == LOGOR) { |
1751 | if ((p = pipeline(CONTIN)) == NULL) { | 1756 | p = pipeline(CONTIN); |
1757 | if (p == NULL) { | ||
1752 | DBGPRINTF8(("ANDOR: error!\n")); | 1758 | DBGPRINTF8(("ANDOR: error!\n")); |
1753 | SYNTAXERR; | 1759 | SYNTAXERR; |
1754 | } | 1760 | } |
@@ -1773,16 +1779,19 @@ static struct op *c_list(void) | |||
1773 | t = andor(); | 1779 | t = andor(); |
1774 | 1780 | ||
1775 | if (t != NULL) { | 1781 | if (t != NULL) { |
1776 | if ((peeksym = yylex(0)) == '&') | 1782 | peeksym = yylex(0); |
1783 | if (peeksym == '&') | ||
1777 | t = block(TASYNC, t, NOBLOCK, NOWORDS); | 1784 | t = block(TASYNC, t, NOBLOCK, NOWORDS); |
1778 | 1785 | ||
1779 | while ((c = yylex(0)) == ';' || c == '&' | 1786 | while ((c = yylex(0)) == ';' || c == '&' |
1780 | || (multiline && c == '\n')) { | 1787 | || (multiline && c == '\n')) { |
1781 | 1788 | ||
1782 | if ((p = andor()) == NULL) | 1789 | p = andor(); |
1790 | if (p== NULL) | ||
1783 | return t; | 1791 | return t; |
1784 | 1792 | ||
1785 | if ((peeksym = yylex(0)) == '&') | 1793 | peeksym = yylex(0); |
1794 | if (peeksym == '&') | ||
1786 | p = block(TASYNC, p, NOBLOCK, NOWORDS); | 1795 | p = block(TASYNC, p, NOBLOCK, NOWORDS); |
1787 | 1796 | ||
1788 | t = list(t, p); | 1797 | t = list(t, p); |
@@ -1803,7 +1812,8 @@ static int synio(int cf) | |||
1803 | 1812 | ||
1804 | DBGPRINTF7(("SYNIO: enter, cf=%d\n", cf)); | 1813 | DBGPRINTF7(("SYNIO: enter, cf=%d\n", cf)); |
1805 | 1814 | ||
1806 | if ((c = yylex(cf)) != '<' && c != '>') { | 1815 | c = yylex(cf); |
1816 | if (c != '<' && c != '>') { | ||
1807 | peeksym = c; | 1817 | peeksym = c; |
1808 | return 0; | 1818 | return 0; |
1809 | } | 1819 | } |
@@ -1892,7 +1902,8 @@ static struct op *command(int cf) | |||
1892 | switch (c) { | 1902 | switch (c) { |
1893 | default: | 1903 | default: |
1894 | peeksym = c; | 1904 | peeksym = c; |
1895 | if ((t = simple()) == NULL) { | 1905 | t = simple(); |
1906 | if (t == NULL) { | ||
1896 | if (iolist == NULL) | 1907 | if (iolist == NULL) |
1897 | return NULL; | 1908 | return NULL; |
1898 | t = newtp(); | 1909 | t = newtp(); |
@@ -1916,7 +1927,8 @@ static struct op *command(int cf) | |||
1916 | t->str = yylval.cp; | 1927 | t->str = yylval.cp; |
1917 | multiline++; | 1928 | multiline++; |
1918 | t->words = wordlist(); | 1929 | t->words = wordlist(); |
1919 | if ((c = yylex(0)) != '\n' && c != ';') | 1930 | c = yylex(0); |
1931 | if (c != '\n' && c != ';') | ||
1920 | peeksym = c; | 1932 | peeksym = c; |
1921 | t->left = dogroup(0); | 1933 | t->left = dogroup(0); |
1922 | multiline--; | 1934 | multiline--; |
@@ -2017,7 +2029,8 @@ static struct op *thenpart(void) | |||
2017 | int c; | 2029 | int c; |
2018 | struct op *t; | 2030 | struct op *t; |
2019 | 2031 | ||
2020 | if ((c = yylex(0)) != THEN) { | 2032 | c = yylex(0); |
2033 | if (c != THEN) { | ||
2021 | peeksym = c; | 2034 | peeksym = c; |
2022 | return NULL; | 2035 | return NULL; |
2023 | } | 2036 | } |
@@ -2037,7 +2050,8 @@ static struct op *elsepart(void) | |||
2037 | 2050 | ||
2038 | switch (c = yylex(0)) { | 2051 | switch (c = yylex(0)) { |
2039 | case ELSE: | 2052 | case ELSE: |
2040 | if ((t = c_list()) == NULL) | 2053 | t = c_list(); |
2054 | if (t == NULL) | ||
2041 | SYNTAXERR; | 2055 | SYNTAXERR; |
2042 | return t; | 2056 | return t; |
2043 | 2057 | ||
@@ -2079,7 +2093,8 @@ static struct op *casepart(void) | |||
2079 | t->words = pattern(); | 2093 | t->words = pattern(); |
2080 | musthave(')', 0); | 2094 | musthave(')', 0); |
2081 | t->left = c_list(); | 2095 | t->left = c_list(); |
2082 | if ((peeksym = yylex(CONTIN)) != ESAC) | 2096 | peeksym = yylex(CONTIN); |
2097 | if (peeksym != ESAC) | ||
2083 | musthave(BREAK, CONTIN); | 2098 | musthave(BREAK, CONTIN); |
2084 | 2099 | ||
2085 | DBGPRINTF7(("CASEPART: made newtp(TPAT, t=%p)\n", t)); | 2100 | DBGPRINTF7(("CASEPART: made newtp(TPAT, t=%p)\n", t)); |
@@ -2096,7 +2111,8 @@ static char **pattern(void) | |||
2096 | musthave(WORD, cf); | 2111 | musthave(WORD, cf); |
2097 | word(yylval.cp); | 2112 | word(yylval.cp); |
2098 | cf = 0; | 2113 | cf = 0; |
2099 | } while ((c = yylex(0)) == '|'); | 2114 | c = yylex(0); |
2115 | } while (c == '|'); | ||
2100 | peeksym = c; | 2116 | peeksym = c; |
2101 | word(NOWORD); | 2117 | word(NOWORD); |
2102 | 2118 | ||
@@ -2107,7 +2123,8 @@ static char **wordlist(void) | |||
2107 | { | 2123 | { |
2108 | int c; | 2124 | int c; |
2109 | 2125 | ||
2110 | if ((c = yylex(0)) != IN) { | 2126 | c = yylex(0); |
2127 | if (c != IN) { | ||
2111 | peeksym = c; | 2128 | peeksym = c; |
2112 | return NULL; | 2129 | return NULL; |
2113 | } | 2130 | } |
@@ -2210,7 +2227,6 @@ static struct op *namelist(struct op *t) | |||
2210 | word(NOWORD); | 2227 | word(NOWORD); |
2211 | t->words = copyw(); | 2228 | t->words = copyw(); |
2212 | 2229 | ||
2213 | |||
2214 | return t; | 2230 | return t; |
2215 | } | 2231 | } |
2216 | 2232 | ||
@@ -2270,7 +2286,8 @@ static int yylex(int cf) | |||
2270 | int c, c1; | 2286 | int c, c1; |
2271 | int atstart; | 2287 | int atstart; |
2272 | 2288 | ||
2273 | if ((c = peeksym) > 0) { | 2289 | c = peeksym; |
2290 | if (c > 0) { | ||
2274 | peeksym = 0; | 2291 | peeksym = 0; |
2275 | if (c == '\n') | 2292 | if (c == '\n') |
2276 | startl = 1; | 2293 | startl = 1; |
@@ -2475,7 +2492,8 @@ static char *tree(unsigned size) | |||
2475 | { | 2492 | { |
2476 | char *t; | 2493 | char *t; |
2477 | 2494 | ||
2478 | if ((t = getcell(size)) == NULL) { | 2495 | t = getcell(size); |
2496 | if (t == NULL) { | ||
2479 | DBGPRINTF2(("TREE: getcell(%d) failed!\n", size)); | 2497 | DBGPRINTF2(("TREE: getcell(%d) failed!\n", size)); |
2480 | prs("command line too complicated\n"); | 2498 | prs("command line too complicated\n"); |
2481 | fail(); | 2499 | fail(); |
@@ -2556,7 +2574,8 @@ static int execute(struct op *t, int *pin, int *pout, int act) | |||
2556 | { | 2574 | { |
2557 | int pv[2]; | 2575 | int pv[2]; |
2558 | 2576 | ||
2559 | if ((rv = openpipe(pv)) < 0) | 2577 | rv = openpipe(pv); |
2578 | if (rv < 0) | ||
2560 | break; | 2579 | break; |
2561 | pv[0] = remap(pv[0]); | 2580 | pv[0] = remap(pv[0]); |
2562 | pv[1] = remap(pv[1]); | 2581 | pv[1] = remap(pv[1]); |
@@ -2608,7 +2627,8 @@ static int execute(struct op *t, int *pin, int *pout, int act) | |||
2608 | case TOR: | 2627 | case TOR: |
2609 | case TAND: | 2628 | case TAND: |
2610 | rv = execute(t->left, pin, pout, 0); | 2629 | rv = execute(t->left, pin, pout, 0); |
2611 | if ((t1 = t->right) != NULL && (rv == 0) == (t->type == TAND)) | 2630 | t1 = t->right; |
2631 | if (t1 != NULL && (rv == 0) == (t->type == TAND)) | ||
2612 | rv = execute(t1, pin, pout, 0); | 2632 | rv = execute(t1, pin, pout, 0); |
2613 | break; | 2633 | break; |
2614 | 2634 | ||
@@ -2655,14 +2675,16 @@ static int execute(struct op *t, int *pin, int *pout, int act) | |||
2655 | break; | 2675 | break; |
2656 | 2676 | ||
2657 | case TCASE: | 2677 | case TCASE: |
2658 | if ((cp = evalstr(t->str, DOSUB | DOTRIM)) == 0) | 2678 | cp = evalstr(t->str, DOSUB | DOTRIM); |
2679 | if (cp == 0) | ||
2659 | cp = ""; | 2680 | cp = ""; |
2660 | 2681 | ||
2661 | DBGPRINTF7(("EXECUTE: TCASE, t->str is %s, cp is %s\n", | 2682 | DBGPRINTF7(("EXECUTE: TCASE, t->str is %s, cp is %s\n", |
2662 | ((t->str == NULL) ? "NULL" : t->str), | 2683 | ((t->str == NULL) ? "NULL" : t->str), |
2663 | ((cp == NULL) ? "NULL" : cp))); | 2684 | ((cp == NULL) ? "NULL" : cp))); |
2664 | 2685 | ||
2665 | if ((t1 = findcase(t->left, cp)) != NULL) { | 2686 | t1 = findcase(t->left, cp); |
2687 | if (t1 != NULL) { | ||
2666 | DBGPRINTF7(("EXECUTE: TCASE, calling execute(t=%p, t1=%p)...\n", t, t1)); | 2688 | DBGPRINTF7(("EXECUTE: TCASE, calling execute(t=%p, t1=%p)...\n", t, t1)); |
2667 | rv = execute(t1, pin, pout, 0); | 2689 | rv = execute(t1, pin, pout, 0); |
2668 | DBGPRINTF7(("EXECUTE: TCASE, back from execute(t=%p, t1=%p)...\n", t, t1)); | 2690 | DBGPRINTF7(("EXECUTE: TCASE, back from execute(t=%p, t1=%p)...\n", t, t1)); |
@@ -2695,7 +2717,8 @@ static int execute(struct op *t, int *pin, int *pout, int act) | |||
2695 | fail(); | 2717 | fail(); |
2696 | } | 2718 | } |
2697 | 2719 | ||
2698 | if ((i = trapset) != 0) { | 2720 | i = trapset; |
2721 | if (i != 0) { | ||
2699 | trapset = 0; | 2722 | trapset = 0; |
2700 | runtrap(i); | 2723 | runtrap(i); |
2701 | } | 2724 | } |
@@ -2852,7 +2875,8 @@ forkexec(struct op *t, int *pin, int *pout, int act, char **wp) | |||
2852 | closepipe(pout); | 2875 | closepipe(pout); |
2853 | } | 2876 | } |
2854 | 2877 | ||
2855 | if ((iopp = t->ioact) != NULL) { | 2878 | iopp = t->ioact; |
2879 | if (iopp != NULL) { | ||
2856 | if (shcom != NULL && shcom != doexec) { | 2880 | if (shcom != NULL && shcom != doexec) { |
2857 | prs(cp); | 2881 | prs(cp); |
2858 | err(": cannot redirect shell command"); | 2882 | err(": cannot redirect shell command"); |
@@ -3069,7 +3093,8 @@ static int waitfor(int lastpid, int canintr) | |||
3069 | if (errno != EINTR || canintr) | 3093 | if (errno != EINTR || canintr) |
3070 | break; | 3094 | break; |
3071 | } else { | 3095 | } else { |
3072 | if ((rv = WAITSIG(s)) != 0) { | 3096 | rv = WAITSIG(s); |
3097 | if (rv != 0) { | ||
3073 | if (rv < NSIGNAL) { | 3098 | if (rv < NSIGNAL) { |
3074 | if (signame[rv] != NULL) { | 3099 | if (signame[rv] != NULL) { |
3075 | if (pid != lastpid) { | 3100 | if (pid != lastpid) { |
@@ -3210,13 +3235,15 @@ static int run(struct ioarg *argp, int (*f) (struct ioarg *)) | |||
3210 | ofail = failpt; | 3235 | ofail = failpt; |
3211 | rv = -1; | 3236 | rv = -1; |
3212 | 3237 | ||
3213 | if (newenv(setjmp(errpt = ev)) == 0) { | 3238 | errpt = ev; |
3239 | if (newenv(setjmp(errpt)) == 0) { | ||
3214 | wdlist = 0; | 3240 | wdlist = 0; |
3215 | iolist = 0; | 3241 | iolist = 0; |
3216 | pushio(argp, f); | 3242 | pushio(argp, f); |
3217 | e.iobase = e.iop; | 3243 | e.iobase = e.iop; |
3218 | yynerrs = 0; | 3244 | yynerrs = 0; |
3219 | if (setjmp(failpt = rt) == 0 && yyparse() == 0) | 3245 | failpt = rt; |
3246 | if (setjmp(failpt) == 0 && yyparse() == 0) | ||
3220 | rv = execute(outtree, NOPIPE, NOPIPE, 0); | 3247 | rv = execute(outtree, NOPIPE, NOPIPE, 0); |
3221 | quitenv(); | 3248 | quitenv(); |
3222 | } else { | 3249 | } else { |
@@ -3287,7 +3314,8 @@ static int dochdir(struct op *t) | |||
3287 | { | 3314 | { |
3288 | char *cp, *er; | 3315 | char *cp, *er; |
3289 | 3316 | ||
3290 | if ((cp = t->words[1]) == NULL && (cp = homedir->value) == NULL) | 3317 | cp = t->words[1]; |
3318 | if (cp == NULL && (cp = homedir->value) == NULL) | ||
3291 | er = ": no home directory"; | 3319 | er = ": no home directory"; |
3292 | else if (chdir(cp) < 0) | 3320 | else if (chdir(cp) < 0) |
3293 | er = ": bad directory"; | 3321 | er = ": bad directory"; |
@@ -3337,7 +3365,8 @@ static int doumask(struct op *t) | |||
3337 | int i, n; | 3365 | int i, n; |
3338 | char *cp; | 3366 | char *cp; |
3339 | 3367 | ||
3340 | if ((cp = t->words[1]) == NULL) { | 3368 | cp = t->words[1]; |
3369 | if (cp == NULL) { | ||
3341 | i = umask(0); | 3370 | i = umask(0); |
3342 | umask(i); | 3371 | umask(i); |
3343 | for (n = 3 * 4; (n -= 3) >= 0;) | 3372 | for (n = 3 * 4; (n -= 3) >= 0;) |
@@ -3363,7 +3392,8 @@ static int doexec(struct op *t) | |||
3363 | return 1; | 3392 | return 1; |
3364 | execflg = 1; | 3393 | execflg = 1; |
3365 | ofail = failpt; | 3394 | ofail = failpt; |
3366 | if (setjmp(failpt = ex) == 0) | 3395 | failpt = ex; |
3396 | if (setjmp(failpt) == 0) | ||
3367 | execute(t, NOPIPE, NOPIPE, FEXEC); | 3397 | execute(t, NOPIPE, NOPIPE, FEXEC); |
3368 | failpt = ofail; | 3398 | failpt = ofail; |
3369 | execflg = 0; | 3399 | execflg = 0; |
@@ -3379,7 +3409,8 @@ static int dodot(struct op *t) | |||
3379 | 3409 | ||
3380 | DBGPRINTF(("DODOT: enter, t=%p, tleft %p, tright %p, e.linep is %s\n", t, t->left, t->right, ((e.linep == NULL) ? "NULL" : e.linep))); | 3410 | DBGPRINTF(("DODOT: enter, t=%p, tleft %p, tright %p, e.linep is %s\n", t, t->left, t->right, ((e.linep == NULL) ? "NULL" : e.linep))); |
3381 | 3411 | ||
3382 | if ((cp = t->words[1]) == NULL) { | 3412 | cp = t->words[1]; |
3413 | if (cp == NULL) { | ||
3383 | DBGPRINTF(("DODOT: bad args, ret 0\n")); | 3414 | DBGPRINTF(("DODOT: bad args, ret 0\n")); |
3384 | return 0; | 3415 | return 0; |
3385 | } else { | 3416 | } else { |
@@ -3402,7 +3433,8 @@ static int dodot(struct op *t) | |||
3402 | for (i = 0; (*tp++ = cp[i++]) != '\0';); | 3433 | for (i = 0; (*tp++ = cp[i++]) != '\0';); |
3403 | 3434 | ||
3404 | /* Original code */ | 3435 | /* Original code */ |
3405 | if ((i = open(e.linep, 0)) >= 0) { | 3436 | i = open(e.linep, 0); |
3437 | if (i >= 0) { | ||
3406 | exstat = 0; | 3438 | exstat = 0; |
3407 | maltmp = remap(i); | 3439 | maltmp = remap(i); |
3408 | DBGPRINTF(("DODOT: remap=%d, exstat=%d, e.iofd %d, i %d, e.linep is %s\n", maltmp, exstat, e.iofd, i, e.linep)); | 3440 | DBGPRINTF(("DODOT: remap=%d, exstat=%d, e.iofd %d, i %d, e.linep is %s\n", maltmp, exstat, e.iofd, i, e.linep)); |
@@ -3427,7 +3459,8 @@ static int dowait(struct op *t) | |||
3427 | int i; | 3459 | int i; |
3428 | char *cp; | 3460 | char *cp; |
3429 | 3461 | ||
3430 | if ((cp = t->words[1]) != NULL) { | 3462 | cp = t->words[1]; |
3463 | if (cp != NULL) { | ||
3431 | i = getn(cp); | 3464 | i = getn(cp); |
3432 | if (i == 0) | 3465 | if (i == 0) |
3433 | return 0; | 3466 | return 0; |
@@ -3448,10 +3481,14 @@ static int doread(struct op *t) | |||
3448 | return 1; | 3481 | return 1; |
3449 | } | 3482 | } |
3450 | for (wp = t->words + 1; *wp; wp++) { | 3483 | for (wp = t->words + 1; *wp; wp++) { |
3451 | for (cp = e.linep; !nl && cp < elinep - 1; cp++) | 3484 | for (cp = e.linep; !nl && cp < elinep - 1; cp++) { |
3452 | if ((nb = read(0, cp, sizeof(*cp))) != sizeof(*cp) || | 3485 | nb = read(0, cp, sizeof(*cp)); |
3453 | (nl = (*cp == '\n')) || (wp[1] && any(*cp, ifs->value))) | 3486 | if (nb != sizeof(*cp) || (nl = (*cp == '\n')) |
3487 | || (wp[1] && any(*cp, ifs->value)) | ||
3488 | ) { | ||
3454 | break; | 3489 | break; |
3490 | } | ||
3491 | } | ||
3455 | *cp = 0; | 3492 | *cp = 0; |
3456 | if (nb <= 0) | 3493 | if (nb <= 0) |
3457 | break; | 3494 | break; |
@@ -3508,7 +3545,8 @@ static int getsig(char *s) | |||
3508 | { | 3545 | { |
3509 | int n; | 3546 | int n; |
3510 | 3547 | ||
3511 | if ((n = getn(s)) < 0 || n > _NSIG) { | 3548 | n = getn(s); |
3549 | if (n < 0 || n > _NSIG) { | ||
3512 | err("trap: bad signal number"); | 3550 | err("trap: bad signal number"); |
3513 | n = 0; | 3551 | n = 0; |
3514 | } | 3552 | } |
@@ -3639,7 +3677,8 @@ static int doset(struct op *t) | |||
3639 | char *cp; | 3677 | char *cp; |
3640 | int n; | 3678 | int n; |
3641 | 3679 | ||
3642 | if ((cp = t->words[1]) == NULL) { | 3680 | cp = t->words[1]; |
3681 | if (cp == NULL) { | ||
3643 | for (vp = vlist; vp; vp = vp->next) | 3682 | for (vp = vlist; vp; vp = vp->next) |
3644 | varput(vp->name, 1); | 3683 | varput(vp->name, 1); |
3645 | return 0; | 3684 | return 0; |
@@ -3746,7 +3785,8 @@ static char **eval(char **ap, int f) | |||
3746 | wp = NULL; | 3785 | wp = NULL; |
3747 | wb = NULL; | 3786 | wb = NULL; |
3748 | wf = NULL; | 3787 | wf = NULL; |
3749 | if (newenv(setjmp(errpt = ev)) == 0) { | 3788 | errpt = ev; |
3789 | if (newenv(setjmp(errpt)) == 0) { | ||
3750 | while (*ap && isassign(*ap)) | 3790 | while (*ap && isassign(*ap)) |
3751 | expand(*ap++, &wb, f & ~DOGLOB); | 3791 | expand(*ap++, &wb, f & ~DOGLOB); |
3752 | if (flag['k']) { | 3792 | if (flag['k']) { |
@@ -3861,8 +3901,9 @@ static char *blank(int f) | |||
3861 | scanequals = f & DOKEY; | 3901 | scanequals = f & DOKEY; |
3862 | foundequals = 0; | 3902 | foundequals = 0; |
3863 | 3903 | ||
3864 | loop: | 3904 | loop: |
3865 | switch (c = subgetc('"', foundequals)) { | 3905 | c = subgetc('"', foundequals); |
3906 | switch (c) { | ||
3866 | case 0: | 3907 | case 0: |
3867 | if (sp == e.linep) | 3908 | if (sp == e.linep) |
3868 | return 0; | 3909 | return 0; |
@@ -3924,7 +3965,7 @@ static int subgetc(char ec, int quoted) | |||
3924 | 3965 | ||
3925 | DBGPRINTF3(("SUBGETC: enter, quoted=%d\n", quoted)); | 3966 | DBGPRINTF3(("SUBGETC: enter, quoted=%d\n", quoted)); |
3926 | 3967 | ||
3927 | again: | 3968 | again: |
3928 | c = my_getc(ec); | 3969 | c = my_getc(ec); |
3929 | if (!INSUB() && ec != '\'') { | 3970 | if (!INSUB() && ec != '\'') { |
3930 | if (c == '`') { | 3971 | if (c == '`') { |
@@ -4231,7 +4272,8 @@ static char *unquote(char *as) | |||
4231 | { | 4272 | { |
4232 | char *s; | 4273 | char *s; |
4233 | 4274 | ||
4234 | if ((s = as) != NULL) | 4275 | s = as; |
4276 | if (s != NULL) | ||
4235 | while (*s) | 4277 | while (*s) |
4236 | *s++ &= ~QUOTE; | 4278 | *s++ &= ~QUOTE; |
4237 | return as; | 4279 | return as; |
@@ -4406,7 +4448,8 @@ static struct wdblock *addword(char *wd, struct wdblock *wb) | |||
4406 | 4448 | ||
4407 | if (wb == NULL) | 4449 | if (wb == NULL) |
4408 | wb = newword(NSTART); | 4450 | wb = newword(NSTART); |
4409 | if ((nw = wb->w_nword) >= wb->w_bsize) { | 4451 | nw = wb->w_nword; |
4452 | if (nw >= wb->w_bsize) { | ||
4410 | wb2 = newword(nw * 2); | 4453 | wb2 = newword(nw * 2); |
4411 | memcpy((char *) wb2->w_words, (char *) wb->w_words, | 4454 | memcpy((char *) wb2->w_words, (char *) wb->w_words, |
4412 | nw * sizeof(char *)); | 4455 | nw * sizeof(char *)); |
@@ -4454,11 +4497,11 @@ static void glob1(char *base, char *lim) | |||
4454 | int c; | 4497 | int c; |
4455 | unsigned n; | 4498 | unsigned n; |
4456 | 4499 | ||
4457 | |||
4458 | v2 = globv; | 4500 | v2 = globv; |
4459 | 4501 | ||
4460 | top: | 4502 | top: |
4461 | if ((n = (int) (lim - base)) <= v2) | 4503 | n = (int) (lim - base); |
4504 | if (n <= v2) | ||
4462 | return; | 4505 | return; |
4463 | n = v2 * (n / (2 * v2)); | 4506 | n = v2 * (n / (2 * v2)); |
4464 | hptr = lptr = base + n; | 4507 | hptr = lptr = base + n; |
@@ -4466,7 +4509,8 @@ static void glob1(char *base, char *lim) | |||
4466 | j = lim - v2; | 4509 | j = lim - v2; |
4467 | for (;;) { | 4510 | for (;;) { |
4468 | if (i < lptr) { | 4511 | if (i < lptr) { |
4469 | if ((c = (*func) (i, lptr)) == 0) { | 4512 | c = (*func) (i, lptr); |
4513 | if (c == 0) { | ||
4470 | glob2(i, lptr -= v2); | 4514 | glob2(i, lptr -= v2); |
4471 | continue; | 4515 | continue; |
4472 | } | 4516 | } |
@@ -4476,9 +4520,10 @@ static void glob1(char *base, char *lim) | |||
4476 | } | 4520 | } |
4477 | } | 4521 | } |
4478 | 4522 | ||
4479 | begin: | 4523 | begin: |
4480 | if (j > hptr) { | 4524 | if (j > hptr) { |
4481 | if ((c = (*func) (hptr, j)) == 0) { | 4525 | c = (*func) (hptr, j); |
4526 | if (c == 0) { | ||
4482 | glob2(hptr += v2, j); | 4527 | glob2(hptr += v2, j); |
4483 | goto begin; | 4528 | goto begin; |
4484 | } | 4529 | } |
@@ -4595,7 +4640,8 @@ static int readc(void) | |||
4595 | 4640 | ||
4596 | for (; e.iop >= e.iobase; e.iop--) { | 4641 | for (; e.iop >= e.iobase; e.iop--) { |
4597 | RCPRINTF(("READC: e.iop %p, peekc 0x%x\n", e.iop, e.iop->peekc)); | 4642 | RCPRINTF(("READC: e.iop %p, peekc 0x%x\n", e.iop, e.iop->peekc)); |
4598 | if ((c = e.iop->peekc) != '\0') { | 4643 | c = e.iop->peekc; |
4644 | if (c != '\0') { | ||
4599 | e.iop->peekc = 0; | 4645 | e.iop->peekc = 0; |
4600 | return c; | 4646 | return c; |
4601 | } else { | 4647 | } else { |
@@ -4707,7 +4753,7 @@ static void pushio(struct ioarg *argp, int (*fn) (struct ioarg *)) | |||
4707 | if (fn == filechar || fn == linechar) | 4753 | if (fn == filechar || fn == linechar) |
4708 | e.iop->task = XIO; | 4754 | e.iop->task = XIO; |
4709 | else if (fn == (int (*)(struct ioarg *)) gravechar | 4755 | else if (fn == (int (*)(struct ioarg *)) gravechar |
4710 | || fn == (int (*)(struct ioarg *)) qgravechar) | 4756 | || fn == (int (*)(struct ioarg *)) qgravechar) |
4711 | e.iop->task = XGRAVE; | 4757 | e.iop->task = XGRAVE; |
4712 | else | 4758 | else |
4713 | e.iop->task = XOTHER; | 4759 | e.iop->task = XOTHER; |
@@ -4753,10 +4799,12 @@ static int wdchar(struct ioarg *ap) | |||
4753 | char c; | 4799 | char c; |
4754 | char **wl; | 4800 | char **wl; |
4755 | 4801 | ||
4756 | if ((wl = ap->awordlist) == NULL) | 4802 | wl = ap->awordlist; |
4803 | if (wl == NULL) | ||
4757 | return 0; | 4804 | return 0; |
4758 | if (*wl != NULL) { | 4805 | if (*wl != NULL) { |
4759 | if ((c = *(*wl)++) != 0) | 4806 | c = *(*wl)++; |
4807 | if (c != 0) | ||
4760 | return c & 0177; | 4808 | return c & 0177; |
4761 | ap->awordlist++; | 4809 | ap->awordlist++; |
4762 | return ' '; | 4810 | return ' '; |
@@ -4773,7 +4821,8 @@ static int dolchar(struct ioarg *ap) | |||
4773 | { | 4821 | { |
4774 | char *wp; | 4822 | char *wp; |
4775 | 4823 | ||
4776 | if ((wp = *ap->awordlist++) != NULL) { | 4824 | wp = *ap->awordlist++; |
4825 | if (wp != NULL) { | ||
4777 | PUSHIO(aword, wp, *ap->awordlist == NULL ? strchar : xxchar); | 4826 | PUSHIO(aword, wp, *ap->awordlist == NULL ? strchar : xxchar); |
4778 | return -1; | 4827 | return -1; |
4779 | } | 4828 | } |
@@ -4786,7 +4835,8 @@ static int xxchar(struct ioarg *ap) | |||
4786 | 4835 | ||
4787 | if (ap->aword == NULL) | 4836 | if (ap->aword == NULL) |
4788 | return 0; | 4837 | return 0; |
4789 | if ((c = *ap->aword++) == '\0') { | 4838 | c = *ap->aword++; |
4839 | if (c == '\0') { | ||
4790 | ap->aword = NULL; | 4840 | ap->aword = NULL; |
4791 | return ' '; | 4841 | return ' '; |
4792 | } | 4842 | } |
@@ -4798,11 +4848,9 @@ static int xxchar(struct ioarg *ap) | |||
4798 | */ | 4848 | */ |
4799 | static int strchar(struct ioarg *ap) | 4849 | static int strchar(struct ioarg *ap) |
4800 | { | 4850 | { |
4801 | int c; | 4851 | if (ap->aword == NULL) |
4802 | |||
4803 | if (ap->aword == NULL || (c = *ap->aword++) == 0) | ||
4804 | return 0; | 4852 | return 0; |
4805 | return c; | 4853 | return *ap->aword++; |
4806 | } | 4854 | } |
4807 | 4855 | ||
4808 | /* | 4856 | /* |
@@ -4812,7 +4860,7 @@ static int qstrchar(struct ioarg *ap) | |||
4812 | { | 4860 | { |
4813 | int c; | 4861 | int c; |
4814 | 4862 | ||
4815 | if (ap->aword == NULL || (c = *ap->aword++) == 0) | 4863 | if (ap->aword == NULL) || (c = *ap->aword++) == 0) |
4816 | return 0; | 4864 | return 0; |
4817 | return c | QUOTE; | 4865 | return c | QUOTE; |
4818 | } | 4866 | } |
@@ -4827,8 +4875,8 @@ static int filechar(struct ioarg *ap) | |||
4827 | struct iobuf *bp = ap->afbuf; | 4875 | struct iobuf *bp = ap->afbuf; |
4828 | 4876 | ||
4829 | if (ap->afid != AFID_NOBUF) { | 4877 | if (ap->afid != AFID_NOBUF) { |
4830 | if ((i = ap->afid != bp->id) || bp->bufp == bp->ebufp) { | 4878 | i = (ap->afid != bp->id); |
4831 | 4879 | if (i || bp->bufp == bp->ebufp) { | |
4832 | if (i) | 4880 | if (i) |
4833 | lseek(ap->afile, ap->afpos, SEEK_SET); | 4881 | lseek(ap->afile, ap->afpos, SEEK_SET); |
4834 | 4882 | ||
@@ -4840,7 +4888,8 @@ static int filechar(struct ioarg *ap) | |||
4840 | } | 4888 | } |
4841 | 4889 | ||
4842 | bp->id = ap->afid; | 4890 | bp->id = ap->afid; |
4843 | bp->ebufp = (bp->bufp = bp->buf) + i; | 4891 | bp->bufp = bp->buf; |
4892 | bp->ebufp = bp->bufp + i; | ||
4844 | } | 4893 | } |
4845 | 4894 | ||
4846 | ap->afpos++; | 4895 | ap->afpos++; |
@@ -4875,7 +4924,6 @@ static int herechar(struct ioarg *ap) | |||
4875 | { | 4924 | { |
4876 | char c; | 4925 | char c; |
4877 | 4926 | ||
4878 | |||
4879 | if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) { | 4927 | if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) { |
4880 | close(ap->afile); | 4928 | close(ap->afile); |
4881 | c = 0; | 4929 | c = 0; |
@@ -4892,7 +4940,8 @@ static int gravechar(struct ioarg *ap, struct io *iop) | |||
4892 | { | 4940 | { |
4893 | int c; | 4941 | int c; |
4894 | 4942 | ||
4895 | if ((c = qgravechar(ap, iop) & ~QUOTE) == '\n') | 4943 | c = qgravechar(ap, iop) & ~QUOTE; |
4944 | if (c == '\n') | ||
4896 | c = ' '; | 4945 | c = ' '; |
4897 | return c; | 4946 | return c; |
4898 | } | 4947 | } |
@@ -4930,7 +4979,8 @@ static int linechar(struct ioarg *ap) | |||
4930 | { | 4979 | { |
4931 | int c; | 4980 | int c; |
4932 | 4981 | ||
4933 | if ((c = filechar(ap)) == '\n') { | 4982 | c = filechar(ap); |
4983 | if (c == '\n') { | ||
4934 | if (!multiline) { | 4984 | if (!multiline) { |
4935 | closef(ap->afile); | 4985 | closef(ap->afile); |
4936 | ap->afile = -1; /* illegal value */ | 4986 | ap->afile = -1; /* illegal value */ |
@@ -4974,7 +5024,6 @@ static int remap(int fd) | |||
4974 | int map[NOFILE]; | 5024 | int map[NOFILE]; |
4975 | int newfd; | 5025 | int newfd; |
4976 | 5026 | ||
4977 | |||
4978 | DBGPRINTF(("REMAP: fd=%d, e.iofd=%d\n", fd, e.iofd)); | 5027 | DBGPRINTF(("REMAP: fd=%d, e.iofd=%d\n", fd, e.iofd)); |
4979 | 5028 | ||
4980 | if (fd < e.iofd) { | 5029 | if (fd < e.iofd) { |
@@ -5002,7 +5051,8 @@ static int openpipe(int *pv) | |||
5002 | { | 5051 | { |
5003 | int i; | 5052 | int i; |
5004 | 5053 | ||
5005 | if ((i = pipe(pv)) < 0) | 5054 | i = pipe(pv); |
5055 | if (i < 0) | ||
5006 | err("can't create pipe - try again"); | 5056 | err("can't create pipe - try again"); |
5007 | return i; | 5057 | return i; |
5008 | } | 5058 | } |
@@ -5089,7 +5139,8 @@ static void readhere(char **name, char *s, int ec) | |||
5089 | return; | 5139 | return; |
5090 | 5140 | ||
5091 | *name = strsave(tname, areanum); | 5141 | *name = strsave(tname, areanum); |
5092 | if (newenv(setjmp(errpt = ev)) != 0) | 5142 | errpt = ev; |
5143 | if (newenv(setjmp(errpt)) != 0) | ||
5093 | unlink(tname); | 5144 | unlink(tname); |
5094 | else { | 5145 | else { |
5095 | pushio(e.iop->argp, (int (*)(struct ioarg *)) e.iop->iofn); | 5146 | pushio(e.iop->argp, (int (*)(struct ioarg *)) e.iop->iofn); |