diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-12-16 17:21:29 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-12-16 17:21:29 +0000 |
commit | c794c51a1aa23d2edcff8e1ab4edf96194d3208c (patch) | |
tree | aabc303b512f9e7869f17c35ad705ef7d486a9fc | |
parent | 0163111325009ea10979105508bb294d4d67680c (diff) | |
download | busybox-w32-c794c51a1aa23d2edcff8e1ab4edf96194d3208c.tar.gz busybox-w32-c794c51a1aa23d2edcff8e1ab4edf96194d3208c.tar.bz2 busybox-w32-c794c51a1aa23d2edcff8e1ab4edf96194d3208c.zip |
msh: reduce global data/bss usage
(add/remove: 1/5 grow/shrink: 28/6 up/down: 464/-394) Total: 70 bytes
text data bss dec hex filename
778077 908 7568 786553 c0079 busybox_old
778330 860 7408 786598 c00a6 busybox_unstripped
-rw-r--r-- | shell/msh.c | 453 |
1 files changed, 225 insertions, 228 deletions
diff --git a/shell/msh.c b/shell/msh.c index 9f95fe28a..9edf793ab 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
@@ -202,24 +202,24 @@ struct op { | |||
202 | char *str; /* identifier for case and for */ | 202 | char *str; /* identifier for case and for */ |
203 | }; | 203 | }; |
204 | 204 | ||
205 | #define TCOM 1 /* command */ | 205 | #define TCOM 1 /* command */ |
206 | #define TPAREN 2 /* (c-list) */ | 206 | #define TPAREN 2 /* (c-list) */ |
207 | #define TPIPE 3 /* a | b */ | 207 | #define TPIPE 3 /* a | b */ |
208 | #define TLIST 4 /* a [&;] b */ | 208 | #define TLIST 4 /* a [&;] b */ |
209 | #define TOR 5 /* || */ | 209 | #define TOR 5 /* || */ |
210 | #define TAND 6 /* && */ | 210 | #define TAND 6 /* && */ |
211 | #define TFOR 7 | 211 | #define TFOR 7 |
212 | #define TDO 8 | 212 | #define TDO 8 |
213 | #define TCASE 9 | 213 | #define TCASE 9 |
214 | #define TIF 10 | 214 | #define TIF 10 |
215 | #define TWHILE 11 | 215 | #define TWHILE 11 |
216 | #define TUNTIL 12 | 216 | #define TUNTIL 12 |
217 | #define TELIF 13 | 217 | #define TELIF 13 |
218 | #define TPAT 14 /* pattern in case */ | 218 | #define TPAT 14 /* pattern in case */ |
219 | #define TBRACE 15 /* {c-list} */ | 219 | #define TBRACE 15 /* {c-list} */ |
220 | #define TASYNC 16 /* c & */ | 220 | #define TASYNC 16 /* c & */ |
221 | /* Added to support "." file expansion */ | 221 | /* Added to support "." file expansion */ |
222 | #define TDOT 17 | 222 | #define TDOT 17 |
223 | 223 | ||
224 | /* Strings for names to make debug easier */ | 224 | /* Strings for names to make debug easier */ |
225 | #ifdef MSHDEBUG | 225 | #ifdef MSHDEBUG |
@@ -270,22 +270,6 @@ struct brkcon { | |||
270 | }; | 270 | }; |
271 | 271 | ||
272 | 272 | ||
273 | /* | ||
274 | * flags: | ||
275 | * -e: quit on error | ||
276 | * -k: look for name=value everywhere on command line | ||
277 | * -n: no execution | ||
278 | * -t: exit after reading and executing one command | ||
279 | * -v: echo as read | ||
280 | * -x: trace | ||
281 | * -u: unset variables net diagnostic | ||
282 | */ | ||
283 | static char flags['z' - 'a' + 1] ALIGN1; | ||
284 | /* this looks weird, but is OK ... we index FLAG with 'a'...'z' */ | ||
285 | #define FLAG (flags - 'a') | ||
286 | |||
287 | /* moved to G: static char *trap[_NSIG + 1]; */ | ||
288 | /* moved to G: static char ourtrap[_NSIG + 1]; */ | ||
289 | static int trapset; /* trap pending */ | 273 | static int trapset; /* trap pending */ |
290 | 274 | ||
291 | static int yynerrs; /* yacc */ | 275 | static int yynerrs; /* yacc */ |
@@ -422,10 +406,6 @@ static int yyparse(void); | |||
422 | static int execute(struct op *t, int *pin, int *pout, int act); | 406 | static int execute(struct op *t, int *pin, int *pout, int act); |
423 | 407 | ||
424 | 408 | ||
425 | #define AFID_NOBUF (~0) | ||
426 | #define AFID_ID 0 | ||
427 | |||
428 | |||
429 | /* -------- io.h -------- */ | 409 | /* -------- io.h -------- */ |
430 | /* io buffer */ | 410 | /* io buffer */ |
431 | struct iobuf { | 411 | struct iobuf { |
@@ -455,23 +435,11 @@ struct io { | |||
455 | char xchar; /* for `'s */ | 435 | char xchar; /* for `'s */ |
456 | char task; /* reason for pushed IO */ | 436 | char task; /* reason for pushed IO */ |
457 | }; | 437 | }; |
458 | 438 | /* ->task: */ | |
459 | #define XOTHER 0 /* none of the below */ | 439 | #define XOTHER 0 /* none of the below */ |
460 | #define XDOLL 1 /* expanding ${} */ | 440 | #define XDOLL 1 /* expanding ${} */ |
461 | #define XGRAVE 2 /* expanding `'s */ | 441 | #define XGRAVE 2 /* expanding `'s */ |
462 | #define XIO 3 /* file IO */ | 442 | #define XIO 3 /* file IO */ |
463 | |||
464 | /* in substitution */ | ||
465 | #define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL) | ||
466 | |||
467 | static struct ioarg temparg = { 0, 0, 0, AFID_NOBUF, 0 }; /* temporary for PUSHIO */ | ||
468 | /* moved to G: static struct ioarg ioargstack[NPUSH]; */ | ||
469 | static struct io iostack[NPUSH]; | ||
470 | /* moved to G: static struct iobuf sharedbuf = { AFID_NOBUF }; */ | ||
471 | /* moved to G: static struct iobuf mainbuf = { AFID_NOBUF }; */ | ||
472 | static unsigned bufid = AFID_ID; /* buffer id counter */ | ||
473 | |||
474 | #define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen))) | ||
475 | 443 | ||
476 | 444 | ||
477 | /* | 445 | /* |
@@ -597,33 +565,6 @@ static const char *const signame[] = { | |||
597 | }; | 565 | }; |
598 | 566 | ||
599 | 567 | ||
600 | struct res { | ||
601 | const char *r_name; | ||
602 | int r_val; | ||
603 | }; | ||
604 | static const struct res restab[] = { | ||
605 | { "for" , FOR }, | ||
606 | { "case" , CASE }, | ||
607 | { "esac" , ESAC }, | ||
608 | { "while", WHILE }, | ||
609 | { "do" , DO }, | ||
610 | { "done" , DONE }, | ||
611 | { "if" , IF }, | ||
612 | { "in" , IN }, | ||
613 | { "then" , THEN }, | ||
614 | { "else" , ELSE }, | ||
615 | { "elif" , ELIF }, | ||
616 | { "until", UNTIL }, | ||
617 | { "fi" , FI }, | ||
618 | { ";;" , BREAK }, | ||
619 | { "||" , LOGOR }, | ||
620 | { "&&" , LOGAND }, | ||
621 | { "{" , '{' }, | ||
622 | { "}" , '}' }, | ||
623 | { "." , DOT }, | ||
624 | { NULL , 0 }, | ||
625 | }; | ||
626 | |||
627 | struct builtincmd { | 568 | struct builtincmd { |
628 | const char *name; | 569 | const char *name; |
629 | int (*builtinfunc)(struct op *t); | 570 | int (*builtinfunc)(struct op *t); |
@@ -704,6 +645,10 @@ static struct region *areanxt; /* starting point of scan */ | |||
704 | static void *brktop; | 645 | static void *brktop; |
705 | static void *brkaddr; | 646 | static void *brkaddr; |
706 | 647 | ||
648 | #define AFID_NOBUF (~0) | ||
649 | #define AFID_ID 0 | ||
650 | |||
651 | |||
707 | /* | 652 | /* |
708 | * parsing & execution environment | 653 | * parsing & execution environment |
709 | */ | 654 | */ |
@@ -716,44 +661,68 @@ struct env { | |||
716 | struct env *oenv; | 661 | struct env *oenv; |
717 | }; | 662 | }; |
718 | 663 | ||
719 | static struct env e = { | ||
720 | NULL /* set to line in main() */, /* linep: char ptr */ | ||
721 | iostack, /* iobase: struct io ptr */ | ||
722 | iostack - 1, /* iop: struct io ptr */ | ||
723 | (xint *) NULL, /* errpt: void ptr for errors? */ | ||
724 | FDBASE, /* iofd: file desc */ | ||
725 | (struct env *) NULL /* oenv: struct env ptr */ | ||
726 | }; | ||
727 | |||
728 | 664 | ||
729 | struct globals { | 665 | struct globals { |
666 | struct env global_env; | ||
667 | struct ioarg temparg; // = { .afid = AFID_NOBUF }; /* temporary for PUSHIO */ | ||
668 | unsigned bufid; // = AFID_ID; /* buffer id counter */ | ||
730 | char ourtrap[_NSIG + 1]; | 669 | char ourtrap[_NSIG + 1]; |
731 | char *trap[_NSIG + 1]; | 670 | char *trap[_NSIG + 1]; |
732 | struct iobuf sharedbuf; /* in main(): set to { AFID_NOBUF } */ | 671 | struct iobuf sharedbuf; /* in main(): set to { AFID_NOBUF } */ |
733 | struct iobuf mainbuf; /* in main(): set to { AFID_NOBUF } */ | 672 | struct iobuf mainbuf; /* in main(): set to { AFID_NOBUF } */ |
734 | struct ioarg ioargstack[NPUSH]; | 673 | struct ioarg ioargstack[NPUSH]; |
674 | /* | ||
675 | * flags: | ||
676 | * -e: quit on error | ||
677 | * -k: look for name=value everywhere on command line | ||
678 | * -n: no execution | ||
679 | * -t: exit after reading and executing one command | ||
680 | * -v: echo as read | ||
681 | * -x: trace | ||
682 | * -u: unset variables net diagnostic | ||
683 | */ | ||
684 | char flags['z' - 'a' + 1]; | ||
735 | char filechar_cmdbuf[BUFSIZ]; | 685 | char filechar_cmdbuf[BUFSIZ]; |
736 | char line[LINELIM]; | 686 | char line[LINELIM]; |
737 | char child_cmd[LINELIM]; | 687 | char child_cmd[LINELIM]; |
738 | 688 | ||
689 | struct io iostack[NPUSH]; | ||
690 | |||
739 | char grave__var_name[LINELIM]; | 691 | char grave__var_name[LINELIM]; |
740 | char grave__alt_value[LINELIM]; | 692 | char grave__alt_value[LINELIM]; |
741 | }; | 693 | }; |
742 | 694 | ||
743 | #define G (*ptr_to_globals) | 695 | #define G (*ptr_to_globals) |
696 | #define global_env (G.global_env ) | ||
697 | #define temparg (G.temparg ) | ||
698 | #define bufid (G.bufid ) | ||
744 | #define ourtrap (G.ourtrap ) | 699 | #define ourtrap (G.ourtrap ) |
745 | #define trap (G.trap ) | 700 | #define trap (G.trap ) |
746 | #define sharedbuf (G.sharedbuf ) | 701 | #define sharedbuf (G.sharedbuf ) |
747 | #define mainbuf (G.mainbuf ) | 702 | #define mainbuf (G.mainbuf ) |
748 | #define ioargstack (G.ioargstack ) | 703 | #define ioargstack (G.ioargstack ) |
704 | /* this looks weird, but is OK ... we index FLAG with 'a'...'z' */ | ||
705 | #define FLAG (G.flags - 'a' ) | ||
749 | #define filechar_cmdbuf (G.filechar_cmdbuf) | 706 | #define filechar_cmdbuf (G.filechar_cmdbuf) |
750 | #define line (G.line ) | 707 | #define line (G.line ) |
751 | #define child_cmd (G.child_cmd ) | 708 | #define child_cmd (G.child_cmd ) |
709 | #define iostack (G.iostack ) | ||
752 | #define INIT_G() do { \ | 710 | #define INIT_G() do { \ |
753 | PTR_TO_GLOBALS = xzalloc(sizeof(G)); \ | 711 | PTR_TO_GLOBALS = xzalloc(sizeof(G)); \ |
712 | global_env.linep = line; \ | ||
713 | global_env.iobase = iostack; \ | ||
714 | global_env.iop = iostack - 1; \ | ||
715 | global_env.iofd = FDBASE; \ | ||
716 | temparg.afid = AFID_NOBUF; \ | ||
717 | bufid = AFID_ID; \ | ||
754 | } while (0) | 718 | } while (0) |
755 | 719 | ||
756 | 720 | ||
721 | /* in substitution */ | ||
722 | #define INSUB() (global_env.iop->task == XGRAVE || global_env.iop->task == XDOLL) | ||
723 | |||
724 | #define RUN(what, arg, gen) ((temparg.what = (arg)), run(&temparg, (gen))) | ||
725 | |||
757 | #ifdef MSHDEBUG | 726 | #ifdef MSHDEBUG |
758 | void print_t(struct op *t) | 727 | void print_t(struct op *t) |
759 | { | 728 | { |
@@ -867,10 +836,10 @@ static void err(const char *s) | |||
867 | return; | 836 | return; |
868 | if (!interactive) | 837 | if (!interactive) |
869 | leave(); | 838 | leave(); |
870 | if (e.errpt) | 839 | if (global_env.errpt) |
871 | longjmp(e.errpt, 1); | 840 | longjmp(global_env.errpt, 1); |
872 | closeall(); | 841 | closeall(); |
873 | e.iop = e.iobase = iostack; | 842 | global_env.iop = global_env.iobase = iostack; |
874 | } | 843 | } |
875 | 844 | ||
876 | 845 | ||
@@ -1364,7 +1333,7 @@ static void onecommand(void) | |||
1364 | 1333 | ||
1365 | DBGPRINTF(("ONECOMMAND: enter, outtree=%p\n", outtree)); | 1334 | DBGPRINTF(("ONECOMMAND: enter, outtree=%p\n", outtree)); |
1366 | 1335 | ||
1367 | while (e.oenv) | 1336 | while (global_env.oenv) |
1368 | quitenv(); | 1337 | quitenv(); |
1369 | 1338 | ||
1370 | areanum = 1; | 1339 | areanum = 1; |
@@ -1373,8 +1342,8 @@ static void onecommand(void) | |||
1373 | garbage(); | 1342 | garbage(); |
1374 | wdlist = 0; | 1343 | wdlist = 0; |
1375 | iolist = 0; | 1344 | iolist = 0; |
1376 | e.errpt = 0; | 1345 | global_env.errpt = 0; |
1377 | e.linep = line; | 1346 | global_env.linep = line; |
1378 | yynerrs = 0; | 1347 | yynerrs = 0; |
1379 | multiline = 0; | 1348 | multiline = 0; |
1380 | inparse = 1; | 1349 | inparse = 1; |
@@ -1387,7 +1356,7 @@ static void onecommand(void) | |||
1387 | if (setjmp(failpt) || yyparse() || intr) { | 1356 | if (setjmp(failpt) || yyparse() || intr) { |
1388 | DBGPRINTF(("ONECOMMAND: this is not good.\n")); | 1357 | DBGPRINTF(("ONECOMMAND: this is not good.\n")); |
1389 | 1358 | ||
1390 | while (e.oenv) | 1359 | while (global_env.oenv) |
1391 | quitenv(); | 1360 | quitenv(); |
1392 | scraphere(); | 1361 | scraphere(); |
1393 | if (!interactive && intr) | 1362 | if (!interactive && intr) |
@@ -1433,13 +1402,13 @@ static int newenv(int f) | |||
1433 | 1402 | ||
1434 | ep = (struct env *) space(sizeof(*ep)); | 1403 | ep = (struct env *) space(sizeof(*ep)); |
1435 | if (ep == NULL) { | 1404 | if (ep == NULL) { |
1436 | while (e.oenv) | 1405 | while (global_env.oenv) |
1437 | quitenv(); | 1406 | quitenv(); |
1438 | fail(); | 1407 | fail(); |
1439 | } | 1408 | } |
1440 | *ep = e; | 1409 | *ep = global_env; |
1441 | e.oenv = ep; | 1410 | global_env.oenv = ep; |
1442 | e.errpt = errpt; | 1411 | global_env.errpt = errpt; |
1443 | 1412 | ||
1444 | return 0; | 1413 | return 0; |
1445 | } | 1414 | } |
@@ -1449,15 +1418,15 @@ static void quitenv(void) | |||
1449 | struct env *ep; | 1418 | struct env *ep; |
1450 | int fd; | 1419 | int fd; |
1451 | 1420 | ||
1452 | DBGPRINTF(("QUITENV: e.oenv=%p\n", e.oenv)); | 1421 | DBGPRINTF(("QUITENV: global_env.oenv=%p\n", global_env.oenv)); |
1453 | 1422 | ||
1454 | ep = e.oenv; | 1423 | ep = global_env.oenv; |
1455 | if (ep != NULL) { | 1424 | if (ep != NULL) { |
1456 | fd = e.iofd; | 1425 | fd = global_env.iofd; |
1457 | e = *ep; | 1426 | global_env = *ep; |
1458 | /* should close `'d files */ | 1427 | /* should close `'d files */ |
1459 | DELETE(ep); | 1428 | DELETE(ep); |
1460 | while (--fd >= e.iofd) | 1429 | while (--fd >= global_env.iofd) |
1461 | close(fd); | 1430 | close(fd); |
1462 | } | 1431 | } |
1463 | } | 1432 | } |
@@ -1593,7 +1562,7 @@ static void yyerror(const char *s) ATTRIBUTE_NORETURN; | |||
1593 | static void yyerror(const char *s) | 1562 | static void yyerror(const char *s) |
1594 | { | 1563 | { |
1595 | yynerrs++; | 1564 | yynerrs++; |
1596 | if (interactive && e.iop <= iostack) { | 1565 | if (interactive && global_env.iop <= iostack) { |
1597 | multiline = 0; | 1566 | multiline = 0; |
1598 | while (eofc() == 0 && yylex(0) != '\n'); | 1567 | while (eofc() == 0 && yylex(0) != '\n'); |
1599 | } | 1568 | } |
@@ -2085,11 +2054,38 @@ static struct op *block(int type, struct op *t1, struct op *t2, char **wp) | |||
2085 | /* See if given string is a shell multiline (FOR, IF, etc) */ | 2054 | /* See if given string is a shell multiline (FOR, IF, etc) */ |
2086 | static int rlookup(char *n) | 2055 | static int rlookup(char *n) |
2087 | { | 2056 | { |
2057 | struct res { | ||
2058 | char r_name[6]; | ||
2059 | int16_t r_val; | ||
2060 | }; | ||
2061 | static const struct res restab[] = { | ||
2062 | { "for" , FOR }, | ||
2063 | { "case" , CASE }, | ||
2064 | { "esac" , ESAC }, | ||
2065 | { "while", WHILE }, | ||
2066 | { "do" , DO }, | ||
2067 | { "done" , DONE }, | ||
2068 | { "if" , IF }, | ||
2069 | { "in" , IN }, | ||
2070 | { "then" , THEN }, | ||
2071 | { "else" , ELSE }, | ||
2072 | { "elif" , ELIF }, | ||
2073 | { "until", UNTIL }, | ||
2074 | { "fi" , FI }, | ||
2075 | { ";;" , BREAK }, | ||
2076 | { "||" , LOGOR }, | ||
2077 | { "&&" , LOGAND }, | ||
2078 | { "{" , '{' }, | ||
2079 | { "}" , '}' }, | ||
2080 | { "." , DOT }, | ||
2081 | { }, | ||
2082 | }; | ||
2083 | |||
2088 | const struct res *rp; | 2084 | const struct res *rp; |
2089 | 2085 | ||
2090 | DBGPRINTF7(("RLOOKUP: enter, n is %s\n", n)); | 2086 | DBGPRINTF7(("RLOOKUP: enter, n is %s\n", n)); |
2091 | 2087 | ||
2092 | for (rp = restab; rp->r_name; rp++) | 2088 | for (rp = restab; rp->r_name[0]; rp++) |
2093 | if (strcmp(rp->r_name, n) == 0) { | 2089 | if (strcmp(rp->r_name, n) == 0) { |
2094 | DBGPRINTF7(("RLOOKUP: match, returning %d\n", rp->r_val)); | 2090 | DBGPRINTF7(("RLOOKUP: match, returning %d\n", rp->r_val)); |
2095 | return rp->r_val; /* Return numeric code for shell multiline */ | 2091 | return rp->r_val; /* Return numeric code for shell multiline */ |
@@ -2194,7 +2190,7 @@ static int yylex(int cf) | |||
2194 | atstart = startl; | 2190 | atstart = startl; |
2195 | startl = 0; | 2191 | startl = 0; |
2196 | yylval.i = 0; | 2192 | yylval.i = 0; |
2197 | e.linep = line; | 2193 | global_env.linep = line; |
2198 | 2194 | ||
2199 | /* MALAMO */ | 2195 | /* MALAMO */ |
2200 | line[LINELIM - 1] = '\0'; | 2196 | line[LINELIM - 1] = '\0'; |
@@ -2212,7 +2208,7 @@ static int yylex(int cf) | |||
2212 | iounit = c - '0'; | 2208 | iounit = c - '0'; |
2213 | goto loop; | 2209 | goto loop; |
2214 | } | 2210 | } |
2215 | *e.linep++ = c; | 2211 | *global_env.linep++ = c; |
2216 | c = c1; | 2212 | c = c1; |
2217 | } | 2213 | } |
2218 | break; | 2214 | break; |
@@ -2228,7 +2224,7 @@ static int yylex(int cf) | |||
2228 | 2224 | ||
2229 | case '$': | 2225 | case '$': |
2230 | DBGPRINTF9(("YYLEX: found $\n")); | 2226 | DBGPRINTF9(("YYLEX: found $\n")); |
2231 | *e.linep++ = c; | 2227 | *global_env.linep++ = c; |
2232 | c = my_getc(0); | 2228 | c = my_getc(0); |
2233 | if (c == '{') { | 2229 | if (c == '{') { |
2234 | c = collect(c, '}'); | 2230 | c = collect(c, '}'); |
@@ -2269,7 +2265,7 @@ static int yylex(int cf) | |||
2269 | gethere(); | 2265 | gethere(); |
2270 | startl = 1; | 2266 | startl = 1; |
2271 | if (multiline || cf & CONTIN) { | 2267 | if (multiline || cf & CONTIN) { |
2272 | if (interactive && e.iop <= iostack) { | 2268 | if (interactive && global_env.iop <= iostack) { |
2273 | #if ENABLE_FEATURE_EDITING | 2269 | #if ENABLE_FEATURE_EDITING |
2274 | current_prompt = cprompt->value; | 2270 | current_prompt = cprompt->value; |
2275 | #else | 2271 | #else |
@@ -2291,10 +2287,10 @@ static int yylex(int cf) | |||
2291 | 2287 | ||
2292 | pack: | 2288 | pack: |
2293 | while ((c = my_getc(0)) != '\0' && !any(c, "`$ '\"\t;&<>()|^\n")) { | 2289 | while ((c = my_getc(0)) != '\0' && !any(c, "`$ '\"\t;&<>()|^\n")) { |
2294 | if (e.linep >= elinep) | 2290 | if (global_env.linep >= elinep) |
2295 | err("word too long"); | 2291 | err("word too long"); |
2296 | else | 2292 | else |
2297 | *e.linep++ = c; | 2293 | *global_env.linep++ = c; |
2298 | }; | 2294 | }; |
2299 | 2295 | ||
2300 | unget(c); | 2296 | unget(c); |
@@ -2302,7 +2298,7 @@ static int yylex(int cf) | |||
2302 | if (any(c, "\"'`$")) | 2298 | if (any(c, "\"'`$")) |
2303 | goto loop; | 2299 | goto loop; |
2304 | 2300 | ||
2305 | *e.linep++ = '\0'; | 2301 | *global_env.linep++ = '\0'; |
2306 | 2302 | ||
2307 | if (atstart) { | 2303 | if (atstart) { |
2308 | c = rlookup(line); | 2304 | c = rlookup(line); |
@@ -2323,7 +2319,7 @@ static int collect(int c, int c1) | |||
2323 | 2319 | ||
2324 | DBGPRINTF8(("COLLECT: enter, c=%d, c1=%d\n", c, c1)); | 2320 | DBGPRINTF8(("COLLECT: enter, c=%d, c1=%d\n", c, c1)); |
2325 | 2321 | ||
2326 | *e.linep++ = c; | 2322 | *global_env.linep++ = c; |
2327 | while ((c = my_getc(c1)) != c1) { | 2323 | while ((c = my_getc(c1)) != c1) { |
2328 | if (c == 0) { | 2324 | if (c == 0) { |
2329 | unget(c); | 2325 | unget(c); |
@@ -2333,17 +2329,17 @@ static int collect(int c, int c1) | |||
2333 | yyerror(s); | 2329 | yyerror(s); |
2334 | return YYERRCODE; | 2330 | return YYERRCODE; |
2335 | } | 2331 | } |
2336 | if (interactive && c == '\n' && e.iop <= iostack) { | 2332 | if (interactive && c == '\n' && global_env.iop <= iostack) { |
2337 | #if ENABLE_FEATURE_EDITING | 2333 | #if ENABLE_FEATURE_EDITING |
2338 | current_prompt = cprompt->value; | 2334 | current_prompt = cprompt->value; |
2339 | #else | 2335 | #else |
2340 | prs(cprompt->value); | 2336 | prs(cprompt->value); |
2341 | #endif | 2337 | #endif |
2342 | } | 2338 | } |
2343 | *e.linep++ = c; | 2339 | *global_env.linep++ = c; |
2344 | } | 2340 | } |
2345 | 2341 | ||
2346 | *e.linep++ = c; | 2342 | *global_env.linep++ = c; |
2347 | 2343 | ||
2348 | DBGPRINTF8(("COLLECT: return 0, line is %s\n", line)); | 2344 | DBGPRINTF8(("COLLECT: return 0, line is %s\n", line)); |
2349 | 2345 | ||
@@ -3077,7 +3073,7 @@ static const char *rexecve(char *c, char **v, char **envp) | |||
3077 | asis = (*sp == '\0'); | 3073 | asis = (*sp == '\0'); |
3078 | while (asis || *sp != '\0') { | 3074 | while (asis || *sp != '\0') { |
3079 | asis = 0; | 3075 | asis = 0; |
3080 | tp = e.linep; | 3076 | tp = global_env.linep; |
3081 | for (; *sp != '\0'; tp++) { | 3077 | for (; *sp != '\0'; tp++) { |
3082 | *tp = *sp++; | 3078 | *tp = *sp++; |
3083 | if (*tp == ':') { | 3079 | if (*tp == ':') { |
@@ -3085,19 +3081,19 @@ static const char *rexecve(char *c, char **v, char **envp) | |||
3085 | break; | 3081 | break; |
3086 | } | 3082 | } |
3087 | } | 3083 | } |
3088 | if (tp != e.linep) | 3084 | if (tp != global_env.linep) |
3089 | *tp++ = '/'; | 3085 | *tp++ = '/'; |
3090 | for (i = 0; (*tp++ = c[i++]) != '\0';); | 3086 | for (i = 0; (*tp++ = c[i++]) != '\0';); |
3091 | 3087 | ||
3092 | DBGPRINTF3(("REXECVE: e.linep is %s\n", e.linep)); | 3088 | DBGPRINTF3(("REXECVE: global_env.linep is %s\n", global_env.linep)); |
3093 | 3089 | ||
3094 | execve(e.linep, v, envp); | 3090 | execve(global_env.linep, v, envp); |
3095 | 3091 | ||
3096 | switch (errno) { | 3092 | switch (errno) { |
3097 | case ENOEXEC: | 3093 | case ENOEXEC: |
3098 | *v = e.linep; | 3094 | *v = global_env.linep; |
3099 | tp = *--v; | 3095 | tp = *--v; |
3100 | *v = e.linep; | 3096 | *v = global_env.linep; |
3101 | execve(DEFAULT_SHELL, v, envp); | 3097 | execve(DEFAULT_SHELL, v, envp); |
3102 | *v = tp; | 3098 | *v = tp; |
3103 | return "no Shell"; | 3099 | return "no Shell"; |
@@ -3149,7 +3145,7 @@ static int run(struct ioarg *argp, int (*f) (struct ioarg *)) | |||
3149 | wdlist = 0; | 3145 | wdlist = 0; |
3150 | iolist = 0; | 3146 | iolist = 0; |
3151 | pushio(argp, f); | 3147 | pushio(argp, f); |
3152 | e.iobase = e.iop; | 3148 | global_env.iobase = global_env.iop; |
3153 | yynerrs = 0; | 3149 | yynerrs = 0; |
3154 | failpt = rt; | 3150 | failpt = rt; |
3155 | if (setjmp(failpt) == 0 && yyparse() == 0) | 3151 | if (setjmp(failpt) == 0 && yyparse() == 0) |
@@ -3319,7 +3315,8 @@ static int dodot(struct op *t) | |||
3319 | char *cp; | 3315 | char *cp; |
3320 | int maltmp; | 3316 | int maltmp; |
3321 | 3317 | ||
3322 | 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))); | 3318 | DBGPRINTF(("DODOT: enter, t=%p, tleft %p, tright %p, global_env.linep is %s\n", |
3319 | t, t->left, t->right, ((global_env.linep == NULL) ? "NULL" : global_env.linep))); | ||
3323 | 3320 | ||
3324 | cp = t->words[1]; | 3321 | cp = t->words[1]; |
3325 | if (cp == NULL) { | 3322 | if (cp == NULL) { |
@@ -3330,25 +3327,26 @@ static int dodot(struct op *t) | |||
3330 | 3327 | ||
3331 | sp = any('/', cp) ? ":" : path->value; | 3328 | sp = any('/', cp) ? ":" : path->value; |
3332 | 3329 | ||
3333 | DBGPRINTF(("DODOT: sp is %s, e.linep is %s\n", | 3330 | DBGPRINTF(("DODOT: sp is %s, global_env.linep is %s\n", |
3334 | ((sp == NULL) ? "NULL" : sp), | 3331 | ((sp == NULL) ? "NULL" : sp), |
3335 | ((e.linep == NULL) ? "NULL" : e.linep))); | 3332 | ((global_env.linep == NULL) ? "NULL" : global_env.linep))); |
3336 | 3333 | ||
3337 | while (*sp) { | 3334 | while (*sp) { |
3338 | tp = e.linep; | 3335 | tp = global_env.linep; |
3339 | while (*sp && (*tp = *sp++) != ':') | 3336 | while (*sp && (*tp = *sp++) != ':') |
3340 | tp++; | 3337 | tp++; |
3341 | if (tp != e.linep) | 3338 | if (tp != global_env.linep) |
3342 | *tp++ = '/'; | 3339 | *tp++ = '/'; |
3343 | 3340 | ||
3344 | for (i = 0; (*tp++ = cp[i++]) != '\0';); | 3341 | for (i = 0; (*tp++ = cp[i++]) != '\0';); |
3345 | 3342 | ||
3346 | /* Original code */ | 3343 | /* Original code */ |
3347 | i = open(e.linep, O_RDONLY); | 3344 | i = open(global_env.linep, O_RDONLY); |
3348 | if (i >= 0) { | 3345 | if (i >= 0) { |
3349 | exstat = 0; | 3346 | exstat = 0; |
3350 | maltmp = remap(i); | 3347 | maltmp = remap(i); |
3351 | DBGPRINTF(("DODOT: remap=%d, exstat=%d, e.iofd %d, i %d, e.linep is %s\n", maltmp, exstat, e.iofd, i, e.linep)); | 3348 | DBGPRINTF(("DODOT: remap=%d, exstat=%d, global_env.iofd %d, i %d, global_env.linep is %s\n", |
3349 | maltmp, exstat, global_env.iofd, i, global_env.linep)); | ||
3352 | 3350 | ||
3353 | next(maltmp); /* Basically a PUSHIO */ | 3351 | next(maltmp); /* Basically a PUSHIO */ |
3354 | 3352 | ||
@@ -3391,7 +3389,7 @@ static int doread(struct op *t) | |||
3391 | return 1; | 3389 | return 1; |
3392 | } | 3390 | } |
3393 | for (wp = t->words + 1; *wp; wp++) { | 3391 | for (wp = t->words + 1; *wp; wp++) { |
3394 | for (cp = e.linep; !nl && cp < elinep - 1; cp++) { | 3392 | for (cp = global_env.linep; !nl && cp < elinep - 1; cp++) { |
3395 | nb = read(0, cp, sizeof(*cp)); | 3393 | nb = read(0, cp, sizeof(*cp)); |
3396 | if (nb != sizeof(*cp)) | 3394 | if (nb != sizeof(*cp)) |
3397 | break; | 3395 | break; |
@@ -3402,7 +3400,7 @@ static int doread(struct op *t) | |||
3402 | *cp = '\0'; | 3400 | *cp = '\0'; |
3403 | if (nb <= 0) | 3401 | if (nb <= 0) |
3404 | break; | 3402 | break; |
3405 | setval(lookup(*wp), e.linep); | 3403 | setval(lookup(*wp), global_env.linep); |
3406 | } | 3404 | } |
3407 | return nb <= 0; | 3405 | return nb <= 0; |
3408 | } | 3406 | } |
@@ -3760,9 +3758,9 @@ static int expand(const char *cp, struct wdblock **wbp, int f) | |||
3760 | errpt = ev; | 3758 | errpt = ev; |
3761 | if (newenv(setjmp(errpt)) == 0) { | 3759 | if (newenv(setjmp(errpt)) == 0) { |
3762 | PUSHIO(aword, cp, strchar); | 3760 | PUSHIO(aword, cp, strchar); |
3763 | e.iobase = e.iop; | 3761 | global_env.iobase = global_env.iop; |
3764 | while ((xp = blank(f)) && gflg == 0) { | 3762 | while ((xp = blank(f)) && gflg == 0) { |
3765 | e.linep = xp; | 3763 | global_env.linep = xp; |
3766 | xp = strsave(xp, areanum); | 3764 | xp = strsave(xp, areanum); |
3767 | if ((f & DOGLOB) == 0) { | 3765 | if ((f & DOGLOB) == 0) { |
3768 | if (f & DOTRIM) | 3766 | if (f & DOTRIM) |
@@ -3811,7 +3809,7 @@ static char *blank(int f) | |||
3811 | 3809 | ||
3812 | DBGPRINTF3(("BLANK: enter, f=%d\n", f)); | 3810 | DBGPRINTF3(("BLANK: enter, f=%d\n", f)); |
3813 | 3811 | ||
3814 | sp = e.linep; | 3812 | sp = global_env.linep; |
3815 | scanequals = f & DOKEY; | 3813 | scanequals = f & DOKEY; |
3816 | foundequals = 0; | 3814 | foundequals = 0; |
3817 | 3815 | ||
@@ -3819,9 +3817,9 @@ static char *blank(int f) | |||
3819 | c = subgetc('"', foundequals); | 3817 | c = subgetc('"', foundequals); |
3820 | switch (c) { | 3818 | switch (c) { |
3821 | case 0: | 3819 | case 0: |
3822 | if (sp == e.linep) | 3820 | if (sp == global_env.linep) |
3823 | return 0; | 3821 | return 0; |
3824 | *e.linep++ = 0; | 3822 | *global_env.linep++ = 0; |
3825 | return sp; | 3823 | return sp; |
3826 | 3824 | ||
3827 | default: | 3825 | default: |
@@ -3839,7 +3837,7 @@ static char *blank(int f) | |||
3839 | break; | 3837 | break; |
3840 | if (c == '\'' || !any(c, "$`\"")) | 3838 | if (c == '\'' || !any(c, "$`\"")) |
3841 | c |= QUOTE; | 3839 | c |= QUOTE; |
3842 | *e.linep++ = c; | 3840 | *global_env.linep++ = c; |
3843 | } | 3841 | } |
3844 | c = 0; | 3842 | c = 0; |
3845 | } | 3843 | } |
@@ -3864,9 +3862,9 @@ static char *blank(int f) | |||
3864 | } else if (!isalnum(c) && c != '_') | 3862 | } else if (!isalnum(c) && c != '_') |
3865 | scanequals = 0; | 3863 | scanequals = 0; |
3866 | } | 3864 | } |
3867 | *e.linep++ = c; | 3865 | *global_env.linep++ = c; |
3868 | } | 3866 | } |
3869 | *e.linep++ = 0; | 3867 | *global_env.linep++ = 0; |
3870 | return sp; | 3868 | return sp; |
3871 | } | 3869 | } |
3872 | 3870 | ||
@@ -3885,13 +3883,13 @@ static int subgetc(char ec, int quoted) | |||
3885 | if (c == '`') { | 3883 | if (c == '`') { |
3886 | if (grave(quoted) == 0) | 3884 | if (grave(quoted) == 0) |
3887 | return 0; | 3885 | return 0; |
3888 | e.iop->task = XGRAVE; | 3886 | global_env.iop->task = XGRAVE; |
3889 | goto again; | 3887 | goto again; |
3890 | } | 3888 | } |
3891 | if (c == '$') { | 3889 | if (c == '$') { |
3892 | c = dollar(quoted); | 3890 | c = dollar(quoted); |
3893 | if (c == 0) { | 3891 | if (c == 0) { |
3894 | e.iop->task = XDOLL; | 3892 | global_env.iop->task = XDOLL; |
3895 | goto again; | 3893 | goto again; |
3896 | } | 3894 | } |
3897 | } | 3895 | } |
@@ -3913,38 +3911,38 @@ static int dollar(int quoted) | |||
3913 | DBGPRINTF3(("DOLLAR: enter, quoted=%d\n", quoted)); | 3911 | DBGPRINTF3(("DOLLAR: enter, quoted=%d\n", quoted)); |
3914 | 3912 | ||
3915 | c = readc(); | 3913 | c = readc(); |
3916 | s = e.linep; | 3914 | s = global_env.linep; |
3917 | if (c != '{') { | 3915 | if (c != '{') { |
3918 | *e.linep++ = c; | 3916 | *global_env.linep++ = c; |
3919 | if (isalpha(c) || c == '_') { | 3917 | if (isalpha(c) || c == '_') { |
3920 | while ((c = readc()) != 0 && (isalnum(c) || c == '_')) | 3918 | while ((c = readc()) != 0 && (isalnum(c) || c == '_')) |
3921 | if (e.linep < elinep) | 3919 | if (global_env.linep < elinep) |
3922 | *e.linep++ = c; | 3920 | *global_env.linep++ = c; |
3923 | unget(c); | 3921 | unget(c); |
3924 | } | 3922 | } |
3925 | c = 0; | 3923 | c = 0; |
3926 | } else { | 3924 | } else { |
3927 | oiop = e.iop; | 3925 | oiop = global_env.iop; |
3928 | otask = e.iop->task; | 3926 | otask = global_env.iop->task; |
3929 | 3927 | ||
3930 | e.iop->task = XOTHER; | 3928 | global_env.iop->task = XOTHER; |
3931 | while ((c = subgetc('"', 0)) != 0 && c != '}' && c != '\n') | 3929 | while ((c = subgetc('"', 0)) != 0 && c != '}' && c != '\n') |
3932 | if (e.linep < elinep) | 3930 | if (global_env.linep < elinep) |
3933 | *e.linep++ = c; | 3931 | *global_env.linep++ = c; |
3934 | if (oiop == e.iop) | 3932 | if (oiop == global_env.iop) |
3935 | e.iop->task = otask; | 3933 | global_env.iop->task = otask; |
3936 | if (c != '}') { | 3934 | if (c != '}') { |
3937 | err("unclosed ${"); | 3935 | err("unclosed ${"); |
3938 | gflg++; | 3936 | gflg++; |
3939 | return c; | 3937 | return c; |
3940 | } | 3938 | } |
3941 | } | 3939 | } |
3942 | if (e.linep >= elinep) { | 3940 | if (global_env.linep >= elinep) { |
3943 | err("string in ${} too long"); | 3941 | err("string in ${} too long"); |
3944 | gflg++; | 3942 | gflg++; |
3945 | e.linep -= 10; | 3943 | global_env.linep -= 10; |
3946 | } | 3944 | } |
3947 | *e.linep = 0; | 3945 | *global_env.linep = 0; |
3948 | if (*s) | 3946 | if (*s) |
3949 | for (cp = s + 1; *cp; cp++) | 3947 | for (cp = s + 1; *cp; cp++) |
3950 | if (any(*cp, "=-+?")) { | 3948 | if (any(*cp, "=-+?")) { |
@@ -3956,7 +3954,7 @@ static int dollar(int quoted) | |||
3956 | if (dolc > 1) { | 3954 | if (dolc > 1) { |
3957 | /* currently this does not distinguish $* and $@ */ | 3955 | /* currently this does not distinguish $* and $@ */ |
3958 | /* should check dollar */ | 3956 | /* should check dollar */ |
3959 | e.linep = s; | 3957 | global_env.linep = s; |
3960 | PUSHIO(awordlist, dolv + 1, dolchar); | 3958 | PUSHIO(awordlist, dolv + 1, dolchar); |
3961 | return 0; | 3959 | return 0; |
3962 | } else { /* trap the nasty ${=} */ | 3960 | } else { /* trap the nasty ${=} */ |
@@ -3998,7 +3996,7 @@ static int dollar(int quoted) | |||
3998 | err(s); | 3996 | err(s); |
3999 | gflg++; | 3997 | gflg++; |
4000 | } | 3998 | } |
4001 | e.linep = s; | 3999 | global_env.linep = s; |
4002 | PUSHIO(aword, dolp, quoted ? qstrchar : strchar); | 4000 | PUSHIO(aword, dolp, quoted ? qstrchar : strchar); |
4003 | return 0; | 4001 | return 0; |
4004 | } | 4002 | } |
@@ -4028,7 +4026,7 @@ static int grave(int quoted) | |||
4028 | (void) &cp; | 4026 | (void) &cp; |
4029 | #endif | 4027 | #endif |
4030 | 4028 | ||
4031 | for (cp = e.iop->argp->aword; *cp != '`'; cp++) { | 4029 | for (cp = global_env.iop->argp->aword; *cp != '`'; cp++) { |
4032 | if (*cp == 0) { | 4030 | if (*cp == 0) { |
4033 | err("no closing `"); | 4031 | err("no closing `"); |
4034 | return 0; | 4032 | return 0; |
@@ -4036,7 +4034,7 @@ static int grave(int quoted) | |||
4036 | } | 4034 | } |
4037 | 4035 | ||
4038 | /* string copy with dollar expansion */ | 4036 | /* string copy with dollar expansion */ |
4039 | src = e.iop->argp->aword; | 4037 | src = global_env.iop->argp->aword; |
4040 | dest = child_cmd; | 4038 | dest = child_cmd; |
4041 | count = 0; | 4039 | count = 0; |
4042 | ignore = 0; | 4040 | ignore = 0; |
@@ -4165,7 +4163,7 @@ static int grave(int quoted) | |||
4165 | } | 4163 | } |
4166 | if (i != 0) { | 4164 | if (i != 0) { |
4167 | waitpid(i, NULL, 0); | 4165 | waitpid(i, NULL, 0); |
4168 | e.iop->argp->aword = ++cp; | 4166 | global_env.iop->argp->aword = ++cp; |
4169 | close(pf[1]); | 4167 | close(pf[1]); |
4170 | PUSHIO(afile, remap(pf[0]), | 4168 | PUSHIO(afile, remap(pf[0]), |
4171 | (int (*)(struct ioarg *)) ((quoted) ? qgravechar : gravechar)); | 4169 | (int (*)(struct ioarg *)) ((quoted) ? qgravechar : gravechar)); |
@@ -4535,14 +4533,14 @@ static int my_getc(int ec) | |||
4535 | { | 4533 | { |
4536 | int c; | 4534 | int c; |
4537 | 4535 | ||
4538 | if (e.linep > elinep) { | 4536 | if (global_env.linep > elinep) { |
4539 | while ((c = readc()) != '\n' && c); | 4537 | while ((c = readc()) != '\n' && c); |
4540 | err("input line too long"); | 4538 | err("input line too long"); |
4541 | gflg++; | 4539 | gflg++; |
4542 | return c; | 4540 | return c; |
4543 | } | 4541 | } |
4544 | c = readc(); | 4542 | c = readc(); |
4545 | if ((ec != '\'') && (ec != '`') && (e.iop->task != XGRAVE)) { | 4543 | if ((ec != '\'') && (ec != '`') && (global_env.iop->task != XGRAVE)) { |
4546 | if (c == '\\') { | 4544 | if (c == '\\') { |
4547 | c = readc(); | 4545 | c = readc(); |
4548 | if (c == '\n' && ec != '\"') | 4546 | if (c == '\n' && ec != '\"') |
@@ -4555,53 +4553,53 @@ static int my_getc(int ec) | |||
4555 | 4553 | ||
4556 | static void unget(int c) | 4554 | static void unget(int c) |
4557 | { | 4555 | { |
4558 | if (e.iop >= e.iobase) | 4556 | if (global_env.iop >= global_env.iobase) |
4559 | e.iop->peekc = c; | 4557 | global_env.iop->peekc = c; |
4560 | } | 4558 | } |
4561 | 4559 | ||
4562 | static int eofc(void) | 4560 | static int eofc(void) |
4563 | { | 4561 | { |
4564 | return e.iop < e.iobase || (e.iop->peekc == 0 && e.iop->prev == 0); | 4562 | return global_env.iop < global_env.iobase || (global_env.iop->peekc == 0 && global_env.iop->prev == 0); |
4565 | } | 4563 | } |
4566 | 4564 | ||
4567 | static int readc(void) | 4565 | static int readc(void) |
4568 | { | 4566 | { |
4569 | int c; | 4567 | int c; |
4570 | 4568 | ||
4571 | RCPRINTF(("READC: e.iop %p, e.iobase %p\n", e.iop, e.iobase)); | 4569 | RCPRINTF(("READC: global_env.iop %p, global_env.iobase %p\n", global_env.iop, global_env.iobase)); |
4572 | 4570 | ||
4573 | for (; e.iop >= e.iobase; e.iop--) { | 4571 | for (; global_env.iop >= global_env.iobase; global_env.iop--) { |
4574 | RCPRINTF(("READC: e.iop %p, peekc 0x%x\n", e.iop, e.iop->peekc)); | 4572 | RCPRINTF(("READC: global_env.iop %p, peekc 0x%x\n", global_env.iop, global_env.iop->peekc)); |
4575 | c = e.iop->peekc; | 4573 | c = global_env.iop->peekc; |
4576 | if (c != '\0') { | 4574 | if (c != '\0') { |
4577 | e.iop->peekc = 0; | 4575 | global_env.iop->peekc = 0; |
4578 | return c; | 4576 | return c; |
4579 | } | 4577 | } |
4580 | if (e.iop->prev != 0) { | 4578 | if (global_env.iop->prev != 0) { |
4581 | c = (*e.iop->iofn)(e.iop->argp, e.iop); | 4579 | c = (*global_env.iop->iofn)(global_env.iop->argp, global_env.iop); |
4582 | if (c != '\0') { | 4580 | if (c != '\0') { |
4583 | if (c == -1) { | 4581 | if (c == -1) { |
4584 | e.iop++; | 4582 | global_env.iop++; |
4585 | continue; | 4583 | continue; |
4586 | } | 4584 | } |
4587 | if (e.iop == iostack) | 4585 | if (global_env.iop == iostack) |
4588 | ioecho(c); | 4586 | ioecho(c); |
4589 | e.iop->prev = c; | 4587 | global_env.iop->prev = c; |
4590 | return e.iop->prev; | 4588 | return global_env.iop->prev; |
4591 | } | 4589 | } |
4592 | if (e.iop->task == XIO && e.iop->prev != '\n') { | 4590 | if (global_env.iop->task == XIO && global_env.iop->prev != '\n') { |
4593 | e.iop->prev = 0; | 4591 | global_env.iop->prev = 0; |
4594 | if (e.iop == iostack) | 4592 | if (global_env.iop == iostack) |
4595 | ioecho('\n'); | 4593 | ioecho('\n'); |
4596 | return '\n'; | 4594 | return '\n'; |
4597 | } | 4595 | } |
4598 | } | 4596 | } |
4599 | if (e.iop->task == XIO) { | 4597 | if (global_env.iop->task == XIO) { |
4600 | if (multiline) { | 4598 | if (multiline) { |
4601 | e.iop->prev = 0; | 4599 | global_env.iop->prev = 0; |
4602 | return e.iop->prev; | 4600 | return global_env.iop->prev; |
4603 | } | 4601 | } |
4604 | if (interactive && e.iop == iostack + 1) { | 4602 | if (interactive && global_env.iop == iostack + 1) { |
4605 | #if ENABLE_FEATURE_EDITING | 4603 | #if ENABLE_FEATURE_EDITING |
4606 | current_prompt = prompt->value; | 4604 | current_prompt = prompt->value; |
4607 | #else | 4605 | #else |
@@ -4611,8 +4609,8 @@ static int readc(void) | |||
4611 | } | 4609 | } |
4612 | } /* FOR */ | 4610 | } /* FOR */ |
4613 | 4611 | ||
4614 | if (e.iop >= iostack) { | 4612 | if (global_env.iop >= iostack) { |
4615 | RCPRINTF(("READC: return 0, e.iop %p\n", e.iop)); | 4613 | RCPRINTF(("READC: return 0, global_env.iop %p\n", global_env.iop)); |
4616 | return 0; | 4614 | return 0; |
4617 | } | 4615 | } |
4618 | 4616 | ||
@@ -4632,12 +4630,12 @@ static void ioecho(char c) | |||
4632 | 4630 | ||
4633 | static void pushio(struct ioarg *argp, int (*fn) (struct ioarg *)) | 4631 | static void pushio(struct ioarg *argp, int (*fn) (struct ioarg *)) |
4634 | { | 4632 | { |
4635 | DBGPRINTF(("PUSHIO: argp %p, argp->afid 0x%x, e.iop %p\n", argp, | 4633 | DBGPRINTF(("PUSHIO: argp %p, argp->afid 0x%x, global_env.iop %p\n", argp, |
4636 | argp->afid, e.iop)); | 4634 | argp->afid, global_env.iop)); |
4637 | 4635 | ||
4638 | /* Set env ptr for io source to next array spot and check for array overflow */ | 4636 | /* Set env ptr for io source to next array spot and check for array overflow */ |
4639 | if (++e.iop >= &iostack[NPUSH]) { | 4637 | if (++global_env.iop >= &iostack[NPUSH]) { |
4640 | e.iop--; | 4638 | global_env.iop--; |
4641 | err("Shell input nested too deeply"); | 4639 | err("Shell input nested too deeply"); |
4642 | gflg++; | 4640 | gflg++; |
4643 | return; | 4641 | return; |
@@ -4645,60 +4643,60 @@ static void pushio(struct ioarg *argp, int (*fn) (struct ioarg *)) | |||
4645 | 4643 | ||
4646 | /* We did not overflow the NPUSH array spots so setup data structs */ | 4644 | /* We did not overflow the NPUSH array spots so setup data structs */ |
4647 | 4645 | ||
4648 | e.iop->iofn = (int (*)(struct ioarg *, struct io *)) fn; /* Store data source func ptr */ | 4646 | global_env.iop->iofn = (int (*)(struct ioarg *, struct io *)) fn; /* Store data source func ptr */ |
4649 | 4647 | ||
4650 | if (argp->afid != AFID_NOBUF) | 4648 | if (argp->afid != AFID_NOBUF) |
4651 | e.iop->argp = argp; | 4649 | global_env.iop->argp = argp; |
4652 | else { | 4650 | else { |
4653 | 4651 | ||
4654 | e.iop->argp = ioargstack + (e.iop - iostack); /* MAL - index into stack */ | 4652 | global_env.iop->argp = ioargstack + (global_env.iop - iostack); /* MAL - index into stack */ |
4655 | *e.iop->argp = *argp; /* copy data from temp area into stack spot */ | 4653 | *global_env.iop->argp = *argp; /* copy data from temp area into stack spot */ |
4656 | 4654 | ||
4657 | /* MAL - mainbuf is for 1st data source (command line?) and all nested use a single shared buffer? */ | 4655 | /* MAL - mainbuf is for 1st data source (command line?) and all nested use a single shared buffer? */ |
4658 | 4656 | ||
4659 | if (e.iop == &iostack[0]) | 4657 | if (global_env.iop == &iostack[0]) |
4660 | e.iop->argp->afbuf = &mainbuf; | 4658 | global_env.iop->argp->afbuf = &mainbuf; |
4661 | else | 4659 | else |
4662 | e.iop->argp->afbuf = &sharedbuf; | 4660 | global_env.iop->argp->afbuf = &sharedbuf; |
4663 | 4661 | ||
4664 | /* MAL - if not a termimal AND (commandline OR readable file) then give it a buffer id? */ | 4662 | /* MAL - if not a termimal AND (commandline OR readable file) then give it a buffer id? */ |
4665 | /* This line appears to be active when running scripts from command line */ | 4663 | /* This line appears to be active when running scripts from command line */ |
4666 | if ((isatty(e.iop->argp->afile) == 0) | 4664 | if ((isatty(global_env.iop->argp->afile) == 0) |
4667 | && (e.iop == &iostack[0] | 4665 | && (global_env.iop == &iostack[0] |
4668 | || lseek(e.iop->argp->afile, 0L, SEEK_CUR) != -1)) { | 4666 | || lseek(global_env.iop->argp->afile, 0L, SEEK_CUR) != -1)) { |
4669 | if (++bufid == AFID_NOBUF) /* counter rollover check, AFID_NOBUF = 11111111 */ | 4667 | if (++bufid == AFID_NOBUF) /* counter rollover check, AFID_NOBUF = 11111111 */ |
4670 | bufid = AFID_ID; /* AFID_ID = 0 */ | 4668 | bufid = AFID_ID; /* AFID_ID = 0 */ |
4671 | 4669 | ||
4672 | e.iop->argp->afid = bufid; /* assign buffer id */ | 4670 | global_env.iop->argp->afid = bufid; /* assign buffer id */ |
4673 | } | 4671 | } |
4674 | 4672 | ||
4675 | DBGPRINTF(("PUSHIO: iostack %p, e.iop %p, afbuf %p\n", | 4673 | DBGPRINTF(("PUSHIO: iostack %p, global_env.iop %p, afbuf %p\n", |
4676 | iostack, e.iop, e.iop->argp->afbuf)); | 4674 | iostack, global_env.iop, global_env.iop->argp->afbuf)); |
4677 | DBGPRINTF(("PUSHIO: mbuf %p, sbuf %p, bid %d, e.iop %p\n", | 4675 | DBGPRINTF(("PUSHIO: mbuf %p, sbuf %p, bid %d, global_env.iop %p\n", |
4678 | &mainbuf, &sharedbuf, bufid, e.iop)); | 4676 | &mainbuf, &sharedbuf, bufid, global_env.iop)); |
4679 | 4677 | ||
4680 | } | 4678 | } |
4681 | 4679 | ||
4682 | e.iop->prev = ~'\n'; | 4680 | global_env.iop->prev = ~'\n'; |
4683 | e.iop->peekc = 0; | 4681 | global_env.iop->peekc = 0; |
4684 | e.iop->xchar = 0; | 4682 | global_env.iop->xchar = 0; |
4685 | e.iop->nlcount = 0; | 4683 | global_env.iop->nlcount = 0; |
4686 | 4684 | ||
4687 | if (fn == filechar || fn == linechar) | 4685 | if (fn == filechar || fn == linechar) |
4688 | e.iop->task = XIO; | 4686 | global_env.iop->task = XIO; |
4689 | else if (fn == (int (*)(struct ioarg *)) gravechar | 4687 | else if (fn == (int (*)(struct ioarg *)) gravechar |
4690 | || fn == (int (*)(struct ioarg *)) qgravechar) | 4688 | || fn == (int (*)(struct ioarg *)) qgravechar) |
4691 | e.iop->task = XGRAVE; | 4689 | global_env.iop->task = XGRAVE; |
4692 | else | 4690 | else |
4693 | e.iop->task = XOTHER; | 4691 | global_env.iop->task = XOTHER; |
4694 | } | 4692 | } |
4695 | 4693 | ||
4696 | static struct io *setbase(struct io *ip) | 4694 | static struct io *setbase(struct io *ip) |
4697 | { | 4695 | { |
4698 | struct io *xp; | 4696 | struct io *xp; |
4699 | 4697 | ||
4700 | xp = e.iobase; | 4698 | xp = global_env.iobase; |
4701 | e.iobase = ip; | 4699 | global_env.iobase = ip; |
4702 | return xp; | 4700 | return xp; |
4703 | } | 4701 | } |
4704 | 4702 | ||
@@ -4929,9 +4927,9 @@ static int remap(int fd) | |||
4929 | int map[NOFILE]; | 4927 | int map[NOFILE]; |
4930 | int newfd; | 4928 | int newfd; |
4931 | 4929 | ||
4932 | DBGPRINTF(("REMAP: fd=%d, e.iofd=%d\n", fd, e.iofd)); | 4930 | DBGPRINTF(("REMAP: fd=%d, global_env.iofd=%d\n", fd, global_env.iofd)); |
4933 | 4931 | ||
4934 | if (fd < e.iofd) { | 4932 | if (fd < global_env.iofd) { |
4935 | for (i = 0; i < NOFILE; i++) | 4933 | for (i = 0; i < NOFILE; i++) |
4936 | map[i] = 0; | 4934 | map[i] = 0; |
4937 | 4935 | ||
@@ -4939,7 +4937,7 @@ static int remap(int fd) | |||
4939 | map[fd] = 1; | 4937 | map[fd] = 1; |
4940 | newfd = dup(fd); | 4938 | newfd = dup(fd); |
4941 | fd = newfd; | 4939 | fd = newfd; |
4942 | } while (fd >= 0 && fd < e.iofd); | 4940 | } while (fd >= 0 && fd < global_env.iofd); |
4943 | 4941 | ||
4944 | for (i = 0; i < NOFILE; i++) | 4942 | for (i = 0; i < NOFILE; i++) |
4945 | if (map[i]) | 4943 | if (map[i]) |
@@ -5052,10 +5050,10 @@ static void readhere(char **name, char *s, int ec) | |||
5052 | if (newenv(setjmp(errpt)) != 0) | 5050 | if (newenv(setjmp(errpt)) != 0) |
5053 | unlink(tname); | 5051 | unlink(tname); |
5054 | else { | 5052 | else { |
5055 | pushio(e.iop->argp, (int (*)(struct ioarg *)) e.iop->iofn); | 5053 | pushio(global_env.iop->argp, (int (*)(struct ioarg *)) global_env.iop->iofn); |
5056 | e.iobase = e.iop; | 5054 | global_env.iobase = global_env.iop; |
5057 | for (;;) { | 5055 | for (;;) { |
5058 | if (interactive && e.iop <= iostack) { | 5056 | if (interactive && global_env.iop <= iostack) { |
5059 | #if ENABLE_FEATURE_EDITING | 5057 | #if ENABLE_FEATURE_EDITING |
5060 | current_prompt = cprompt->value; | 5058 | current_prompt = cprompt->value; |
5061 | #else | 5059 | #else |
@@ -5121,7 +5119,7 @@ static int herein(char *hname, int xdoll) | |||
5121 | errpt = ev; | 5119 | errpt = ev; |
5122 | if (newenv(setjmp(errpt)) == 0) { | 5120 | if (newenv(setjmp(errpt)) == 0) { |
5123 | PUSHIO(afile, hf, herechar); | 5121 | PUSHIO(afile, hf, herechar); |
5124 | setbase(e.iop); | 5122 | setbase(global_env.iop); |
5125 | while ((c = subgetc(0, 0)) != 0) { | 5123 | while ((c = subgetc(0, 0)) != 0) { |
5126 | c &= ~QUOTE; | 5124 | c &= ~QUOTE; |
5127 | write(tf, &c, sizeof c); | 5125 | write(tf, &c, sizeof c); |
@@ -5189,7 +5187,6 @@ int msh_main(int argc, char **argv) | |||
5189 | 5187 | ||
5190 | sharedbuf.id = AFID_NOBUF; | 5188 | sharedbuf.id = AFID_NOBUF; |
5191 | mainbuf.id = AFID_NOBUF; | 5189 | mainbuf.id = AFID_NOBUF; |
5192 | e.linep = line; | ||
5193 | elinep = line + sizeof(line) - 5; | 5190 | elinep = line + sizeof(line) - 5; |
5194 | 5191 | ||
5195 | #if ENABLE_FEATURE_EDITING | 5192 | #if ENABLE_FEATURE_EDITING |
@@ -5321,7 +5318,7 @@ int msh_main(int argc, char **argv) | |||
5321 | setdash(); | 5318 | setdash(); |
5322 | 5319 | ||
5323 | /* This won't be true if PUSHIO has been called, say from newfile() above */ | 5320 | /* This won't be true if PUSHIO has been called, say from newfile() above */ |
5324 | if (e.iop < iostack) { | 5321 | if (global_env.iop < iostack) { |
5325 | PUSHIO(afile, 0, iof); | 5322 | PUSHIO(afile, 0, iof); |
5326 | if (isatty(0) && isatty(1) && !cflag) { | 5323 | if (isatty(0) && isatty(1) && !cflag) { |
5327 | interactive++; | 5324 | interactive++; |
@@ -5366,10 +5363,10 @@ int msh_main(int argc, char **argv) | |||
5366 | } | 5363 | } |
5367 | setval(lookup("#"), putn((--dolc < 0) ? (dolc = 0) : dolc)); | 5364 | setval(lookup("#"), putn((--dolc < 0) ? (dolc = 0) : dolc)); |
5368 | 5365 | ||
5369 | DBGPRINTF(("MSH_MAIN: begin FOR loop, interactive %d, e.iop %p, iostack %p\n", interactive, e.iop, iostack)); | 5366 | DBGPRINTF(("MSH_MAIN: begin FOR loop, interactive %d, global_env.iop %p, iostack %p\n", interactive, global_env.iop, iostack)); |
5370 | 5367 | ||
5371 | for (;;) { | 5368 | for (;;) { |
5372 | if (interactive && e.iop <= iostack) { | 5369 | if (interactive && global_env.iop <= iostack) { |
5373 | #if ENABLE_FEATURE_EDITING | 5370 | #if ENABLE_FEATURE_EDITING |
5374 | current_prompt = prompt->value; | 5371 | current_prompt = prompt->value; |
5375 | #else | 5372 | #else |