aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-02-01 01:39:24 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-02-01 01:39:24 +0000
commit00ccf95bc8c6433a176ab09c4812063e33df2240 (patch)
tree696d2101c137c3b49a71527214de7ea6793a61ea
parent71d8abf30cee76141fbb86f5e80f97de284041a6 (diff)
downloadbusybox-w32-00ccf95bc8c6433a176ab09c4812063e33df2240.tar.gz
busybox-w32-00ccf95bc8c6433a176ab09c4812063e33df2240.tar.bz2
busybox-w32-00ccf95bc8c6433a176ab09c4812063e33df2240.zip
msh: cleaning up for -Wwrite-strings
-rw-r--r--shell/msh.c432
1 files changed, 236 insertions, 196 deletions
diff --git a/shell/msh.c b/shell/msh.c
index 584668607..b71066abc 100644
--- a/shell/msh.c
+++ b/shell/msh.c
@@ -13,9 +13,9 @@
13 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 13 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
14 */ 14 */
15 15
16#include "busybox.h"
17#include <setjmp.h> 16#include <setjmp.h>
18#include <sys/times.h> 17#include <sys/times.h>
18#include "busybox.h"
19 19
20 20
21/*#define MSHDEBUG 1*/ 21/*#define MSHDEBUG 1*/
@@ -42,18 +42,18 @@ int mshdbg_rc = 0;
42#else 42#else
43 43
44#define DBGPRINTF(x) 44#define DBGPRINTF(x)
45#define DBGPRINTF0(x) 45#define DBGPRINTF0(x) ((void)0)
46#define DBGPRINTF1(x) 46#define DBGPRINTF1(x) ((void)0)
47#define DBGPRINTF2(x) 47#define DBGPRINTF2(x) ((void)0)
48#define DBGPRINTF3(x) 48#define DBGPRINTF3(x) ((void)0)
49#define DBGPRINTF4(x) 49#define DBGPRINTF4(x) ((void)0)
50#define DBGPRINTF5(x) 50#define DBGPRINTF5(x) ((void)0)
51#define DBGPRINTF6(x) 51#define DBGPRINTF6(x) ((void)0)
52#define DBGPRINTF7(x) 52#define DBGPRINTF7(x) ((void)0)
53#define DBGPRINTF8(x) 53#define DBGPRINTF8(x) ((void)0)
54#define DBGPRINTF9(x) 54#define DBGPRINTF9(x) ((void)0)
55 55
56#define RCPRINTF(x) 56#define RCPRINTF(x) ((void)0)
57 57
58#endif /* MSHDEBUG */ 58#endif /* MSHDEBUG */
59 59
@@ -258,7 +258,8 @@ static char *elinep;
258/* 258/*
259 * other functions 259 * other functions
260 */ 260 */
261static int (*inbuilt(char *s)) (struct op *); 261typedef int (*builtin_func_ptr)(struct op *);
262static builtin_func_ptr inbuilt(char *s);
262 263
263static char *rexecve(char *c, char **v, char **envp); 264static char *rexecve(char *c, char **v, char **envp);
264static char *space(int n); 265static char *space(int n);
@@ -577,7 +578,7 @@ static void globname(char *we, char *pp);
577static char *generate(char *start1, char *end1, char *middle, char *end); 578static char *generate(char *start1, char *end1, char *middle, char *end);
578static int anyspcl(struct wdblock *wb); 579static int anyspcl(struct wdblock *wb);
579static int xstrcmp(char *p1, char *p2); 580static int xstrcmp(char *p1, char *p2);
580static void glob0(char *a0, unsigned int a1, int a2, 581static void glob0(char *a0, unsigned a1, int a2,
581 int (*a3) (char *, char *)); 582 int (*a3) (char *, char *));
582static void glob1(char *base, char *lim); 583static void glob1(char *base, char *lim);
583static void glob2(char *i, char *j); 584static void glob2(char *i, char *j);
@@ -596,7 +597,7 @@ struct here {
596static const char * const signame[] = { 597static const char * const signame[] = {
597 "Signal 0", 598 "Signal 0",
598 "Hangup", 599 "Hangup",
599 (char *) NULL, /* interrupt */ 600 NULL, /* interrupt */
600 "Quit", 601 "Quit",
601 "Illegal instruction", 602 "Illegal instruction",
602 "Trace/BPT trap", 603 "Trace/BPT trap",
@@ -607,7 +608,7 @@ static const char * const signame[] = {
607 "SIGUSR1", 608 "SIGUSR1",
608 "SIGSEGV", 609 "SIGSEGV",
609 "SIGUSR2", 610 "SIGUSR2",
610 (char *) NULL, /* broken pipe */ 611 NULL, /* broken pipe */
611 "Alarm clock", 612 "Alarm clock",
612 "Terminated", 613 "Terminated",
613}; 614};
@@ -725,21 +726,21 @@ static struct iobuf sharedbuf = { AFID_NOBUF };
725static struct iobuf mainbuf = { AFID_NOBUF }; 726static struct iobuf mainbuf = { AFID_NOBUF };
726static unsigned bufid = AFID_ID; /* buffer id counter */ 727static unsigned bufid = AFID_ID; /* buffer id counter */
727 728
728static struct here *inhere; /* list of hear docs while parsing */ 729static struct here *inhere; /* list of hear docs while parsing */
729static struct here *acthere; /* list of active here documents */ 730static struct here *acthere; /* list of active here documents */
730static struct region *areabot; /* bottom of area */ 731static struct region *areabot; /* bottom of area */
731static struct region *areatop; /* top of area */ 732static struct region *areatop; /* top of area */
732static struct region *areanxt; /* starting point of scan */ 733static struct region *areanxt; /* starting point of scan */
733static void *brktop; 734static void *brktop;
734static void *brkaddr; 735static void *brkaddr;
735 736
736static struct env e = { 737static struct env e = {
737 line, /* linep: char ptr */ 738 line, /* linep: char ptr */
738 iostack, /* iobase: struct io ptr */ 739 iostack, /* iobase: struct io ptr */
739 iostack - 1, /* iop: struct io ptr */ 740 iostack - 1, /* iop: struct io ptr */
740 (xint *) NULL, /* errpt: void ptr for errors? */ 741 (xint *) NULL, /* errpt: void ptr for errors? */
741 FDBASE, /* iofd: file desc */ 742 FDBASE, /* iofd: file desc */
742 (struct env *) NULL /* oenv: struct env ptr */ 743 (struct env *) NULL /* oenv: struct env ptr */
743}; 744};
744 745
745#ifdef MSHDEBUG 746#ifdef MSHDEBUG
@@ -751,8 +752,6 @@ void print_t(struct op *t)
751 if (t->words) { 752 if (t->words) {
752 DBGPRINTF(("T: W1: %s", t->words[0])); 753 DBGPRINTF(("T: W1: %s", t->words[0]));
753 } 754 }
754
755 return;
756} 755}
757 756
758void print_tree(struct op *head) 757void print_tree(struct op *head)
@@ -770,8 +769,6 @@ void print_tree(struct op *head)
770 769
771 if (head->right) 770 if (head->right)
772 print_tree(head->right); 771 print_tree(head->right);
773
774 return;
775} 772}
776#endif /* MSHDEBUG */ 773#endif /* MSHDEBUG */
777 774
@@ -917,7 +914,8 @@ int msh_main(int argc, char **argv)
917#endif 914#endif
918 DBGPRINTF(("MSH_MAIN: calling newfile()\n")); 915 DBGPRINTF(("MSH_MAIN: calling newfile()\n"));
919 916
920 if (newfile(name = *++argv)) 917 name = *++argv;
918 if (newfile(name))
921 exit(1); /* Exit on error */ 919 exit(1); /* Exit on error */
922 } 920 }
923 } 921 }
@@ -943,9 +941,11 @@ int msh_main(int argc, char **argv)
943 signal(SIGQUIT, qflag); 941 signal(SIGQUIT, qflag);
944 if (name && name[0] == '-') { 942 if (name && name[0] == '-') {
945 interactive++; 943 interactive++;
946 if ((f = open(".profile", 0)) >= 0) 944 f = open(".profile", 0);
945 if (f >= 0)
947 next(remap(f)); 946 next(remap(f));
948 if ((f = open("/etc/profile", 0)) >= 0) 947 f = open("/etc/profile", 0);
948 if (f >= 0)
949 next(remap(f)); 949 next(remap(f));
950 } 950 }
951 if (interactive) 951 if (interactive)
@@ -958,7 +958,8 @@ int msh_main(int argc, char **argv)
958 dolv[0] = name; 958 dolv[0] = name;
959 if (dolc > 1) { 959 if (dolc > 1) {
960 for (ap = ++argv; --argc > 0;) { 960 for (ap = ++argv; --argc > 0;) {
961 if (assign(*ap = *argv++, !COPYV)) { 961 *ap = *argv++;
962 if (assign(*ap, !COPYV)) {
962 dolc--; /* keyword */ 963 dolc--; /* keyword */
963 } else { 964 } else {
964 ap++; 965 ap++;
@@ -995,7 +996,7 @@ static void setdash(void)
995 for (c = 'a'; c <= 'z'; c++) 996 for (c = 'a'; c <= 'z'; c++)
996 if (flag[c]) 997 if (flag[c])
997 *cp++ = c; 998 *cp++ = c;
998 *cp = 0; 999 *cp = '\0';
999 setval(lookup("-"), m); 1000 setval(lookup("-"), m);
1000} 1001}
1001 1002
@@ -1005,6 +1006,7 @@ static int newfile(char *s)
1005 1006
1006 DBGPRINTF7(("NEWFILE: opening %s\n", s)); 1007 DBGPRINTF7(("NEWFILE: opening %s\n", s));
1007 1008
1009 f = 0;
1008 if (NOT_LONE_DASH(s)) { 1010 if (NOT_LONE_DASH(s)) {
1009 DBGPRINTF(("NEWFILE: s is %s\n", s)); 1011 DBGPRINTF(("NEWFILE: s is %s\n", s));
1010 f = open(s, 0); 1012 f = open(s, 0);
@@ -1013,8 +1015,7 @@ static int newfile(char *s)
1013 err(": cannot open"); 1015 err(": cannot open");
1014 return 1; 1016 return 1;
1015 } 1017 }
1016 } else 1018 }
1017 f = 0;
1018 1019
1019 next(remap(f)); 1020 next(remap(f));
1020 return 0; 1021 return 0;
@@ -1078,8 +1079,10 @@ static void onecommand(void)
1078 intr = 0; 1079 intr = 0;
1079 execflg = 0; 1080 execflg = 0;
1080 1081
1081 setjmp(failpt = m1); /* Bruce Evans' fix */ 1082 failpt = m1;
1082 if (setjmp(failpt = m1) || yyparse() || intr) { 1083 setjmp(failpt); /* Bruce Evans' fix */
1084 failpt = m1;
1085 if (setjmp(failpt) || yyparse() || intr) {
1083 1086
1084 DBGPRINTF(("ONECOMMAND: this is not good.\n")); 1087 DBGPRINTF(("ONECOMMAND: this is not good.\n"));
1085 1088
@@ -1253,7 +1256,7 @@ static char *space(int n)
1253 char *cp; 1256 char *cp;
1254 1257
1255 cp = getcell(n); 1258 cp = getcell(n);
1256 if (cp == 0) 1259 if (cp == '\0')
1257 err("out of string space"); 1260 err("out of string space");
1258 return cp; 1261 return cp;
1259} 1262}
@@ -1289,7 +1292,7 @@ static void runtrap(int i)
1289 return; 1292 return;
1290 1293
1291 if (i == 0) 1294 if (i == 0)
1292 trap[i] = 0; 1295 trap[i] = NULL;
1293 1296
1294 RUN(aword, trapstr, nlchar); 1297 RUN(aword, trapstr, nlchar);
1295} 1298}
@@ -1329,7 +1332,7 @@ static struct var *lookup(char *n)
1329 for (cp = vp->name; (*cp = *n++) && *cp != '='; cp++); 1332 for (cp = vp->name; (*cp = *n++) && *cp != '='; cp++);
1330 if (*cp == 0) 1333 if (*cp == 0)
1331 *cp = '='; 1334 *cp = '=';
1332 *++cp = 0; 1335 *++cp = '\0';
1333 setarea((char *) vp, 0); 1336 setarea((char *) vp, 0);
1334 setarea((char *) vp->name, 0); 1337 setarea((char *) vp->name, 0);
1335 vp->value = null; 1338 vp->value = null;
@@ -1369,13 +1372,13 @@ static void nameval(struct var *vp, char *val, char *name)
1369 fl = 0; 1372 fl = 0;
1370 if (name == NULL) { 1373 if (name == NULL) {
1371 xp = space(strlen(vp->name) + strlen(val) + 2); 1374 xp = space(strlen(vp->name) + strlen(val) + 2);
1372 if (xp == 0) 1375 if (xp == NULL)
1373 return; 1376 return;
1374 /* make string: name=value */ 1377 /* make string: name=value */
1375 setarea((char *) xp, 0); 1378 setarea((char *) xp, 0);
1376 name = xp; 1379 name = xp;
1377 for (cp = vp->name; (*xp = *cp++) && *xp != '='; xp++); 1380 for (cp = vp->name; (*xp = *cp++) && *xp != '='; xp++);
1378 if (*xp++ == 0) 1381 if (*xp++ == '\0')
1379 xp[-1] = '='; 1382 xp[-1] = '=';
1380 nv = xp; 1383 nv = xp;
1381 for (cp = val; (*xp++ = *cp++) != '\0';); 1384 for (cp = val; (*xp++ = *cp++) != '\0';);
@@ -1407,7 +1410,7 @@ static int isassign(char *s)
1407 if (!isalpha((int) *s) && *s != '_') 1410 if (!isalpha((int) *s) && *s != '_')
1408 return 0; 1411 return 0;
1409 for (; *s != '='; s++) 1412 for (; *s != '='; s++)
1410 if (*s == 0 || (!isalnum(*s) && *s != '_')) 1413 if (*s == '\0' || (!isalnum(*s) && *s != '_'))
1411 return 0; 1414 return 0;
1412 1415
1413 return 1; 1416 return 1;
@@ -1423,7 +1426,7 @@ static int assign(char *s, int cf)
1423 if (!isalpha(*s) && *s != '_') 1426 if (!isalpha(*s) && *s != '_')
1424 return 0; 1427 return 0;
1425 for (cp = s; *cp != '='; cp++) 1428 for (cp = s; *cp != '='; cp++)
1426 if (*cp == 0 || (!isalnum(*cp) && *cp != '_')) 1429 if (*cp == '\0' || (!isalnum(*cp) && *cp != '_'))
1427 return 0; 1430 return 0;
1428 vp = lookup(s); 1431 vp = lookup(s);
1429 nameval(vp, ++cp, cf == COPYV ? (char *) NULL : s); 1432 nameval(vp, ++cp, cf == COPYV ? (char *) NULL : s);
@@ -1461,10 +1464,10 @@ static void putvlist(int f, int out)
1461 1464
1462static int eqname(char *n1, char *n2) 1465static int eqname(char *n1, char *n2)
1463{ 1466{
1464 for (; *n1 != '=' && *n1 != 0; n1++) 1467 for (; *n1 != '=' && *n1 != '\0'; n1++)
1465 if (*n2++ != *n1) 1468 if (*n2++ != *n1)
1466 return 0; 1469 return 0;
1467 return *n2 == 0 || *n2 == '='; 1470 return *n2 == '\0' || *n2 == '=';
1468} 1471}
1469 1472
1470static char *findeq(char *cp) 1473static char *findeq(char *cp)
@@ -1520,14 +1523,15 @@ static int gmatch(char *s, char *p)
1520 return 0; 1523 return 0;
1521 } 1524 }
1522 } 1525 }
1523 return *s == 0; 1526 return *s == '\0';
1524} 1527}
1525 1528
1526static char *cclass(char *p, int sub) 1529static char *cclass(char *p, int sub)
1527{ 1530{
1528 int c, d, not, found; 1531 int c, d, not, found;
1529 1532
1530 if ((not = *p == NOT) != 0) 1533 not = (*p == NOT);
1534 if (not != 0)
1531 p++; 1535 p++;
1532 found = not; 1536 found = not;
1533 do { 1537 do {
@@ -1554,7 +1558,14 @@ static char *cclass(char *p, int sub)
1554 * It is assumed that sbrk() and brk() manipulate the high end. 1558 * It is assumed that sbrk() and brk() manipulate the high end.
1555 */ 1559 */
1556 1560
1557#define sbrk(X) ({ void * __q = (void *)-1; if (brkaddr + (int)(X) < brktop) { __q = brkaddr; brkaddr+=(int)(X); } __q;}) 1561#define sbrk(X) ({ \
1562 void * __q = (void *)-1; \
1563 if (brkaddr + (int)(X) < brktop) { \
1564 __q = brkaddr; \
1565 brkaddr += (int)(X); \
1566 } \
1567 __q; \
1568})
1558 1569
1559static void initarea(void) 1570static void initarea(void)
1560{ 1571{
@@ -1666,7 +1677,8 @@ static void setarea(char *cp, int a)
1666{ 1677{
1667 struct region *p; 1678 struct region *p;
1668 1679
1669 if ((p = (struct region *) cp) != NULL) 1680 p = (struct region *) cp;
1681 if (p != NULL)
1670 (p - 1)->area = a; 1682 (p - 1)->area = a;
1671} 1683}
1672 1684
@@ -1839,7 +1851,8 @@ static int synio(int cf)
1839 1851
1840static void musthave(int c, int cf) 1852static void musthave(int c, int cf)
1841{ 1853{
1842 if ((peeksym = yylex(cf)) != c) { 1854 peeksym = yylex(cf);
1855 if (peeksym != c) {
1843 DBGPRINTF7(("MUSTHAVE: error!\n")); 1856 DBGPRINTF7(("MUSTHAVE: error!\n"));
1844 SYNTAXERR; 1857 SYNTAXERR;
1845 } 1858 }
@@ -2301,7 +2314,6 @@ static int yylex(int cf)
2301 return c; 2314 return c;
2302 } 2315 }
2303 2316
2304
2305 nlseen = 0; 2317 nlseen = 0;
2306 atstart = startl; 2318 atstart = startl;
2307 startl = 0; 2319 startl = 0;
@@ -2311,14 +2323,15 @@ static int yylex(int cf)
2311/* MALAMO */ 2323/* MALAMO */
2312 line[LINELIM - 1] = '\0'; 2324 line[LINELIM - 1] = '\0';
2313 2325
2314 loop: 2326 loop:
2315 while ((c = my_getc(0)) == ' ' || c == '\t') /* Skip whitespace */ 2327 while ((c = my_getc(0)) == ' ' || c == '\t') /* Skip whitespace */
2316 ; 2328 ;
2317 2329
2318 switch (c) { 2330 switch (c) {
2319 default: 2331 default:
2320 if (any(c, "0123456789")) { 2332 if (any(c, "0123456789")) {
2321 unget(c1 = my_getc(0)); 2333 c1 = my_getc(0);
2334 unget(c1);
2322 if (c1 == '<' || c1 == '>') { 2335 if (c1 == '<' || c1 == '>') {
2323 iounit = c - '0'; 2336 iounit = c - '0';
2324 goto loop; 2337 goto loop;
@@ -2329,7 +2342,7 @@ static int yylex(int cf)
2329 break; 2342 break;
2330 2343
2331 case '#': /* Comment, skip to next newline or End-of-string */ 2344 case '#': /* Comment, skip to next newline or End-of-string */
2332 while ((c = my_getc(0)) != 0 && c != '\n'); 2345 while ((c = my_getc(0)) != '\0' && c != '\n');
2333 unget(c); 2346 unget(c);
2334 goto loop; 2347 goto loop;
2335 2348
@@ -2340,8 +2353,10 @@ static int yylex(int cf)
2340 case '$': 2353 case '$':
2341 DBGPRINTF9(("YYLEX: found $\n")); 2354 DBGPRINTF9(("YYLEX: found $\n"));
2342 *e.linep++ = c; 2355 *e.linep++ = c;
2343 if ((c = my_getc(0)) == '{') { 2356 c = my_getc(0);
2344 if ((c = collect(c, '}')) != '\0') 2357 if (c == '{') {
2358 c = collect(c, '}');
2359 if (c != '\0')
2345 return c; 2360 return c;
2346 goto pack; 2361 goto pack;
2347 } 2362 }
@@ -2350,7 +2365,8 @@ static int yylex(int cf)
2350 case '`': 2365 case '`':
2351 case '\'': 2366 case '\'':
2352 case '"': 2367 case '"':
2353 if ((c = collect(c, c)) != '\0') 2368 c = collect(c, c);
2369 if (c != '\0')
2354 return c; 2370 return c;
2355 goto pack; 2371 goto pack;
2356 2372
@@ -2359,10 +2375,10 @@ static int yylex(int cf)
2359 case ';': 2375 case ';':
2360 startl = 1; 2376 startl = 1;
2361 /* If more chars process them, else return NULL char */ 2377 /* If more chars process them, else return NULL char */
2362 if ((c1 = dual(c)) != '\0') 2378 c1 = dual(c);
2379 if (c1 != '\0')
2363 return c1; 2380 return c1;
2364 else 2381 return c;
2365 return c;
2366 2382
2367 case '^': 2383 case '^':
2368 startl = 1; 2384 startl = 1;
@@ -2397,8 +2413,8 @@ static int yylex(int cf)
2397 2413
2398 unget(c); 2414 unget(c);
2399 2415
2400 pack: 2416 pack:
2401 while ((c = my_getc(0)) != 0 && !any(c, "`$ '\"\t;&<>()|^\n")) { 2417 while ((c = my_getc(0)) != '\0' && !any(c, "`$ '\"\t;&<>()|^\n")) {
2402 if (e.linep >= elinep) 2418 if (e.linep >= elinep)
2403 err("word too long"); 2419 err("word too long");
2404 else 2420 else
@@ -2412,9 +2428,12 @@ static int yylex(int cf)
2412 2428
2413 *e.linep++ = '\0'; 2429 *e.linep++ = '\0';
2414 2430
2415 if (atstart && (c = rlookup(line)) != 0) { 2431 if (atstart) {
2416 startl = 1; 2432 c = rlookup(line);
2417 return c; 2433 if (c != 0) {
2434 startl = 1;
2435 return c;
2436 }
2418 } 2437 }
2419 2438
2420 yylval.cp = strsave(line, areanum); 2439 yylval.cp = strsave(line, areanum);
@@ -2464,15 +2483,15 @@ static int dual(int c)
2464 2483
2465 DBGPRINTF8(("DUAL: enter, c=%d\n", c)); 2484 DBGPRINTF8(("DUAL: enter, c=%d\n", c));
2466 2485
2467 *cp++ = c; /* c is the given "peek" char */ 2486 *cp++ = c; /* c is the given "peek" char */
2468 *cp++ = my_getc(0); /* get next char of input */ 2487 *cp++ = my_getc(0); /* get next char of input */
2469 *cp = 0; /* add EOS marker */ 2488 *cp = '\0'; /* add EOS marker */
2470 2489
2471 c = rlookup(s); /* see if 2 chars form a shell multiline */ 2490 c = rlookup(s); /* see if 2 chars form a shell multiline */
2472 if (c == 0) 2491 if (c == 0)
2473 unget(*--cp); /* String is not a shell multiline, put peek char back */ 2492 unget(*--cp); /* String is not a shell multiline, put peek char back */
2474 2493
2475 return c; /* String is multiline, return numeric multiline (restab) code */ 2494 return c; /* String is multiline, return numeric multiline (restab) code */
2476} 2495}
2477 2496
2478static void diag(int ec) 2497static void diag(int ec)
@@ -2485,10 +2504,10 @@ static void diag(int ec)
2485 if (c == '>' || c == '<') { 2504 if (c == '>' || c == '<') {
2486 if (c != ec) 2505 if (c != ec)
2487 zzerr(); 2506 zzerr();
2488 yylval.i = ec == '>' ? IOWRITE | IOCAT : IOHERE; 2507 yylval.i = (ec == '>' ? IOWRITE | IOCAT : IOHERE);
2489 c = my_getc(0); 2508 c = my_getc(0);
2490 } else 2509 } else
2491 yylval.i = ec == '>' ? IOWRITE : IOREAD; 2510 yylval.i = (ec == '>' ? IOWRITE : IOREAD);
2492 if (c != '&' || yylval.i == IOHERE) 2511 if (c != '&' || yylval.i == IOHERE)
2493 unget(c); 2512 unget(c);
2494 else 2513 else
@@ -2603,20 +2622,7 @@ static int execute(struct op *t, int *pin, int *pout, int act)
2603 DBGPRINTF7(("EXECUTE: TASYNC clause, calling vfork()...\n")); 2622 DBGPRINTF7(("EXECUTE: TASYNC clause, calling vfork()...\n"));
2604 2623
2605 i = vfork(); 2624 i = vfork();
2606 if (i != 0) { 2625 if (i == 0) { /* child */
2607 interactive = hinteractive;
2608 if (i != -1) {
2609 setval(lookup("!"), putn(i));
2610 if (pin != NULL)
2611 closepipe(pin);
2612 if (interactive) {
2613 prs(putn(i));
2614 prs("\n");
2615 }
2616 } else
2617 rv = -1;
2618 setstatus(rv);
2619 } else {
2620 signal(SIGINT, SIG_IGN); 2626 signal(SIGINT, SIG_IGN);
2621 signal(SIGQUIT, SIG_IGN); 2627 signal(SIGQUIT, SIG_IGN);
2622 if (interactive) 2628 if (interactive)
@@ -2628,6 +2634,18 @@ static int execute(struct op *t, int *pin, int *pout, int act)
2628 } 2634 }
2629 _exit(execute(t->left, pin, pout, FEXEC)); 2635 _exit(execute(t->left, pin, pout, FEXEC));
2630 } 2636 }
2637 interactive = hinteractive;
2638 if (i != -1) {
2639 setval(lookup("!"), putn(i));
2640 if (pin != NULL)
2641 closepipe(pin);
2642 if (interactive) {
2643 prs(putn(i));
2644 prs("\n");
2645 }
2646 } else
2647 rv = -1;
2648 setstatus(rv);
2631 } 2649 }
2632 break; 2650 break;
2633 2651
@@ -2642,7 +2660,8 @@ static int execute(struct op *t, int *pin, int *pout, int act)
2642 case TFOR: 2660 case TFOR:
2643 if (wp == NULL) { 2661 if (wp == NULL) {
2644 wp = dolv + 1; 2662 wp = dolv + 1;
2645 if ((i = dolc) < 0) 2663 i = dolc;
2664 if (i < 0)
2646 i = 0; 2665 i = 0;
2647 } else { 2666 } else {
2648 i = -1; 2667 i = -1;
@@ -2683,7 +2702,7 @@ static int execute(struct op *t, int *pin, int *pout, int act)
2683 2702
2684 case TCASE: 2703 case TCASE:
2685 cp = evalstr(t->str, DOSUB | DOTRIM); 2704 cp = evalstr(t->str, DOSUB | DOTRIM);
2686 if (cp == 0) 2705 if (cp == NULL)
2687 cp = ""; 2706 cp = "";
2688 2707
2689 DBGPRINTF7(("EXECUTE: TCASE, t->str is %s, cp is %s\n", 2708 DBGPRINTF7(("EXECUTE: TCASE, t->str is %s, cp is %s\n",
@@ -2700,15 +2719,20 @@ static int execute(struct op *t, int *pin, int *pout, int act)
2700 2719
2701 case TBRACE: 2720 case TBRACE:
2702/* 2721/*
2703 if (iopp = t->ioact) 2722 iopp = t->ioact;
2723 if (i)
2704 while (*iopp) 2724 while (*iopp)
2705 if (iosetup(*iopp++, pin!=NULL, pout!=NULL)) { 2725 if (iosetup(*iopp++, pin!=NULL, pout!=NULL)) {
2706 rv = -1; 2726 rv = -1;
2707 break; 2727 break;
2708 } 2728 }
2709*/ 2729*/
2710 if (rv >= 0 && (t1 = t->left)) 2730 if (rv >= 0) {
2711 rv = execute(t1, pin, pout, 0); 2731 t1 = t->left;
2732 if (t1) {
2733 rv = execute(t1, pin, pout, 0);
2734 }
2735 }
2712 break; 2736 break;
2713 2737
2714 }; 2738 };
@@ -2739,7 +2763,7 @@ forkexec(struct op *t, int *pin, int *pout, int act, char **wp)
2739{ 2763{
2740 pid_t newpid; 2764 pid_t newpid;
2741 int i, rv; 2765 int i, rv;
2742 int (*shcom) (struct op *) = NULL; 2766 builtin_func_ptr shcom = NULL;
2743 int f; 2767 int f;
2744 char *cp = NULL; 2768 char *cp = NULL;
2745 struct ioword **iopp; 2769 struct ioword **iopp;
@@ -2787,10 +2811,12 @@ forkexec(struct op *t, int *pin, int *pout, int act, char **wp)
2787 } 2811 }
2788 2812
2789 if (cp == NULL && t->ioact == NULL) { 2813 if (cp == NULL && t->ioact == NULL) {
2790 while ((cp = *owp++) != NULL && assign(cp, COPYV)); 2814 while ((cp = *owp++) != NULL && assign(cp, COPYV))
2815 /**/;
2791 DBGPRINTF(("FORKEXEC: returning setstatus()\n")); 2816 DBGPRINTF(("FORKEXEC: returning setstatus()\n"));
2792 return setstatus(0); 2817 return setstatus(0);
2793 } else if (cp != NULL) { 2818 }
2819 if (cp != NULL) {
2794 shcom = inbuilt(cp); 2820 shcom = inbuilt(cp);
2795 } 2821 }
2796 } 2822 }
@@ -2820,7 +2846,6 @@ forkexec(struct op *t, int *pin, int *pout, int act, char **wp)
2820 return -1; 2846 return -1;
2821 } 2847 }
2822 2848
2823
2824 if (newpid > 0) { /* Parent */ 2849 if (newpid > 0) { /* Parent */
2825 2850
2826 /* Restore values */ 2851 /* Restore values */
@@ -2858,7 +2883,6 @@ forkexec(struct op *t, int *pin, int *pout, int act, char **wp)
2858 execflg = 0; 2883 execflg = 0;
2859 } 2884 }
2860 2885
2861
2862 if (owp != NULL) 2886 if (owp != NULL)
2863 while ((cp = *owp++) != NULL && assign(cp, COPYV)) 2887 while ((cp = *owp++) != NULL && assign(cp, COPYV))
2864 if (shcom == NULL) 2888 if (shcom == NULL)
@@ -2957,8 +2981,9 @@ static int iosetup(struct ioword *iop, int pipein, int pipeout)
2957 2981
2958 msg = iop->io_flag & (IOREAD | IOHERE) ? "open" : "create"; 2982 msg = iop->io_flag & (IOREAD | IOHERE) ? "open" : "create";
2959 if ((iop->io_flag & IOHERE) == 0) { 2983 if ((iop->io_flag & IOHERE) == 0) {
2960 cp = iop->io_name; 2984 cp = iop->io_name; /* huh?? */
2961 if ((cp = evalstr(cp, DOSUB | DOTRIM)) == NULL) 2985 cp = evalstr(cp, DOSUB | DOTRIM);
2986 if (cp == NULL)
2962 return 1; 2987 return 1;
2963 } 2988 }
2964 2989
@@ -2984,7 +3009,8 @@ static int iosetup(struct ioword *iop, int pipein, int pipeout)
2984 break; 3009 break;
2985 3010
2986 case IOWRITE | IOCAT: 3011 case IOWRITE | IOCAT:
2987 if ((u = open(cp, 1)) >= 0) { 3012 u = open(cp, 1);
3013 if (u >= 0) {
2988 lseek(u, (long) 0, SEEK_END); 3014 lseek(u, (long) 0, SEEK_END);
2989 break; 3015 break;
2990 } 3016 }
@@ -3005,11 +3031,10 @@ static int iosetup(struct ioword *iop, int pipein, int pipeout)
3005 prs(": cannot "); 3031 prs(": cannot ");
3006 warn(msg); 3032 warn(msg);
3007 return 1; 3033 return 1;
3008 } else { 3034 }
3009 if (u != iop->io_unit) { 3035 if (u != iop->io_unit) {
3010 dup2(u, iop->io_unit); 3036 dup2(u, iop->io_unit);
3011 close(u); 3037 close(u);
3012 }
3013 } 3038 }
3014 return 0; 3039 return 0;
3015} 3040}
@@ -3033,7 +3058,6 @@ static struct op **find1case(struct op *t, char *w)
3033 struct op **tp; 3058 struct op **tp;
3034 char **wp, *cp; 3059 char **wp, *cp;
3035 3060
3036
3037 if (t == NULL) { 3061 if (t == NULL) {
3038 DBGPRINTF3(("FIND1CASE: enter, t==NULL, returning.\n")); 3062 DBGPRINTF3(("FIND1CASE: enter, t==NULL, returning.\n"));
3039 return NULL; 3063 return NULL;
@@ -3043,7 +3067,8 @@ static struct op **find1case(struct op *t, char *w)
3043 T_CMD_NAMES[t->type])); 3067 T_CMD_NAMES[t->type]));
3044 3068
3045 if (t->type == TLIST) { 3069 if (t->type == TLIST) {
3046 if ((tp = find1case(t->left, w)) != NULL) { 3070 tp = find1case(t->left, w);
3071 if (tp != NULL) {
3047 DBGPRINTF3(("FIND1CASE: found one to the left, returning tp=%p\n", tp)); 3072 DBGPRINTF3(("FIND1CASE: found one to the left, returning tp=%p\n", tp));
3048 return tp; 3073 return tp;
3049 } 3074 }
@@ -3051,12 +3076,14 @@ static struct op **find1case(struct op *t, char *w)
3051 } else 3076 } else
3052 t1 = t; 3077 t1 = t;
3053 3078
3054 for (wp = t1->words; *wp;) 3079 for (wp = t1->words; *wp;) {
3055 if ((cp = evalstr(*wp++, DOSUB)) && gmatch(w, cp)) { 3080 cp = evalstr(*wp++, DOSUB);
3081 if (cp && gmatch(w, cp)) {
3056 DBGPRINTF3(("FIND1CASE: returning &t1->left= %p.\n", 3082 DBGPRINTF3(("FIND1CASE: returning &t1->left= %p.\n",
3057 &t1->left)); 3083 &t1->left));
3058 return &t1->left; 3084 return &t1->left;
3059 } 3085 }
3086 }
3060 3087
3061 DBGPRINTF(("FIND1CASE: returning NULL\n")); 3088 DBGPRINTF(("FIND1CASE: returning NULL\n"));
3062 return NULL; 3089 return NULL;
@@ -3178,11 +3205,13 @@ static char *rexecve(char *c, char **v, char **envp)
3178 while (asis || *sp != '\0') { 3205 while (asis || *sp != '\0') {
3179 asis = 0; 3206 asis = 0;
3180 tp = e.linep; 3207 tp = e.linep;
3181 for (; *sp != '\0'; tp++) 3208 for (; *sp != '\0'; tp++) {
3182 if ((*tp = *sp++) == ':') { 3209 *tp = *sp++;
3183 asis = *sp == '\0'; 3210 if (*tp == ':') {
3211 asis = (*sp == '\0');
3184 break; 3212 break;
3185 } 3213 }
3214 }
3186 if (tp != e.linep) 3215 if (tp != e.linep)
3187 *tp++ = '/'; 3216 *tp++ = '/';
3188 for (i = 0; (*tp++ = c[i++]) != '\0';); 3217 for (i = 0; (*tp++ = c[i++]) != '\0';);
@@ -3322,9 +3351,11 @@ static int dochdir(struct op *t)
3322 char *cp, *er; 3351 char *cp, *er;
3323 3352
3324 cp = t->words[1]; 3353 cp = t->words[1];
3325 if (cp == NULL && (cp = homedir->value) == NULL) 3354 if (cp == NULL) {
3326 er = ": no home directory"; 3355 cp = homedir->value;
3327 else if (chdir(cp) < 0) 3356 if (cp == NULL)
3357 er = ": no home directory";
3358 } else if (chdir(cp) < 0)
3328 er = ": bad directory"; 3359 er = ": bad directory";
3329 else 3360 else
3330 return 0; 3361 return 0;
@@ -3380,6 +3411,7 @@ static int doumask(struct op *t)
3380 putc('0' + ((i >> n) & 07), stderr); 3411 putc('0' + ((i >> n) & 07), stderr);
3381 putc('\n', stderr); 3412 putc('\n', stderr);
3382 } else { 3413 } else {
3414/* huh??? '8','9' are not allowed! */
3383 for (n = 0; *cp >= '0' && *cp <= '9'; cp++) 3415 for (n = 0; *cp >= '0' && *cp <= '9'; cp++)
3384 n = n * 8 + (*cp - '0'); 3416 n = n * 8 + (*cp - '0');
3385 umask(n); 3417 umask(n);
@@ -3420,9 +3452,8 @@ static int dodot(struct op *t)
3420 if (cp == NULL) { 3452 if (cp == NULL) {
3421 DBGPRINTF(("DODOT: bad args, ret 0\n")); 3453 DBGPRINTF(("DODOT: bad args, ret 0\n"));
3422 return 0; 3454 return 0;
3423 } else {
3424 DBGPRINTF(("DODOT: cp is %s\n", cp));
3425 } 3455 }
3456 DBGPRINTF(("DODOT: cp is %s\n", cp));
3426 3457
3427 sp = any('/', cp) ? ":" : path->value; 3458 sp = any('/', cp) ? ":" : path->value;
3428 3459
@@ -3452,8 +3483,7 @@ static int dodot(struct op *t)
3452 3483
3453 return exstat; 3484 return exstat;
3454 } 3485 }
3455 3486 } /* while */
3456 } /* While */
3457 3487
3458 prs(cp); 3488 prs(cp);
3459 err(": not found"); 3489 err(": not found");
@@ -3490,13 +3520,13 @@ static int doread(struct op *t)
3490 for (wp = t->words + 1; *wp; wp++) { 3520 for (wp = t->words + 1; *wp; wp++) {
3491 for (cp = e.linep; !nl && cp < elinep - 1; cp++) { 3521 for (cp = e.linep; !nl && cp < elinep - 1; cp++) {
3492 nb = read(0, cp, sizeof(*cp)); 3522 nb = read(0, cp, sizeof(*cp));
3493 if (nb != sizeof(*cp) || (nl = (*cp == '\n')) 3523 if (nb != sizeof(*cp))
3494 || (wp[1] && any(*cp, ifs->value)) 3524 break;
3495 ) { 3525 nl = (*cp == '\n');
3526 if (nl || (wp[1] && any(*cp, ifs->value)))
3496 break; 3527 break;
3497 }
3498 } 3528 }
3499 *cp = 0; 3529 *cp = '\0';
3500 if (nb <= 0) 3530 if (nb <= 0)
3501 break; 3531 break;
3502 setval(lookup(*wp), e.linep); 3532 setval(lookup(*wp), e.linep);
@@ -3609,7 +3639,8 @@ static int brkcontin(char *cp, int val)
3609 if (nl <= 0) 3639 if (nl <= 0)
3610 nl = 999; 3640 nl = 999;
3611 do { 3641 do {
3612 if ((bc = brklist) == NULL) 3642 bc = brklist;
3643 if (bc == NULL)
3613 break; 3644 break;
3614 brklist = bc->nextlev; 3645 brklist = bc->nextlev;
3615 } while (--nl); 3646 } while (--nl);
@@ -3627,7 +3658,8 @@ static int doexit(struct op *t)
3627 char *cp; 3658 char *cp;
3628 3659
3629 execflg = 0; 3660 execflg = 0;
3630 if ((cp = t->words[1]) != NULL) 3661 cp = t->words[1];
3662 if (cp != NULL)
3631 setstatus(getn(cp)); 3663 setstatus(getn(cp));
3632 3664
3633 DBGPRINTF(("DOEXIT: calling leave(), t=%p\n", t)); 3665 DBGPRINTF(("DOEXIT: calling leave(), t=%p\n", t));
@@ -3695,8 +3727,8 @@ static int doset(struct op *t)
3695 for (n = 0; (t->words[n] = t->words[n + 1]) != NULL; n++); 3727 for (n = 0; (t->words[n] = t->words[n + 1]) != NULL; n++);
3696 if (*++cp == 0) 3728 if (*++cp == 0)
3697 flag['x'] = flag['v'] = 0; 3729 flag['x'] = flag['v'] = 0;
3698 else 3730 else {
3699 for (; *cp; cp++) 3731 for (; *cp; cp++) {
3700 switch (*cp) { 3732 switch (*cp) {
3701 case 'e': 3733 case 'e':
3702 if (!interactive) 3734 if (!interactive)
@@ -3708,6 +3740,8 @@ static int doset(struct op *t)
3708 flag[(int) *cp]++; 3740 flag[(int) *cp]++;
3709 break; 3741 break;
3710 } 3742 }
3743 }
3744 }
3711 setdash(); 3745 setdash();
3712 } 3746 }
3713 if (t->words[1]) { 3747 if (t->words[1]) {
@@ -3738,7 +3772,7 @@ static void varput(char *s, int out)
3738static int dotimes(struct op *t) 3772static int dotimes(struct op *t)
3739{ 3773{
3740 struct tms buf; 3774 struct tms buf;
3741 long int clk_tck = sysconf(_SC_CLK_TCK); 3775 long clk_tck = sysconf(_SC_CLK_TCK);
3742 3776
3743 times(&buf); 3777 times(&buf);
3744 printf("%dm%fs %dm%fs\n%dm%fs %dm%fs\n", 3778 printf("%dm%fs %dm%fs\n%dm%fs %dm%fs\n",
@@ -3754,7 +3788,7 @@ static int dotimes(struct op *t)
3754} 3788}
3755 3789
3756 3790
3757static int (*inbuilt(char *s)) (struct op *) { 3791static builtin_func_ptr inbuilt(char *s) {
3758 const struct builtincmd *bp; 3792 const struct builtincmd *bp;
3759 3793
3760 for (bp = builtincmds; bp->name != NULL; bp++) 3794 for (bp = builtincmds; bp->name != NULL; bp++)
@@ -3874,7 +3908,8 @@ static int expand(char *cp, struct wdblock **wbp, int f)
3874 *wbp = addword(cp, *wbp); 3908 *wbp = addword(cp, *wbp);
3875 return 1; 3909 return 1;
3876 } 3910 }
3877 if (newenv(setjmp(errpt = ev)) == 0) { 3911 errpt = ev;
3912 if (newenv(setjmp(errpt)) == 0) {
3878 PUSHIO(aword, cp, strchar); 3913 PUSHIO(aword, cp, strchar);
3879 e.iobase = e.iop; 3914 e.iobase = e.iop;
3880 while ((cp = blank(f)) && gflg == 0) { 3915 while ((cp = blank(f)) && gflg == 0) {
@@ -3981,9 +4016,12 @@ static int subgetc(char ec, int quoted)
3981 e.iop->task = XGRAVE; 4016 e.iop->task = XGRAVE;
3982 goto again; 4017 goto again;
3983 } 4018 }
3984 if (c == '$' && (c = dollar(quoted)) == 0) { 4019 if (c == '$') {
3985 e.iop->task = XDOLL; 4020 c = dollar(quoted);
3986 goto again; 4021 if (c == 0) {
4022 e.iop->task = XDOLL;
4023 goto again;
4024 }
3987 } 4025 }
3988 } 4026 }
3989 return c; 4027 return c;
@@ -4051,11 +4089,12 @@ static int dollar(int quoted)
4051 return 0; 4089 return 0;
4052 } else { /* trap the nasty ${=} */ 4090 } else { /* trap the nasty ${=} */
4053 s[0] = '1'; 4091 s[0] = '1';
4054 s[1] = 0; 4092 s[1] = '\0';
4055 } 4093 }
4056 } 4094 }
4057 vp = lookup(s); 4095 vp = lookup(s);
4058 if ((dolp = vp->value) == null) { 4096 dolp = vp->value;
4097 if (dolp == null) {
4059 switch (c) { 4098 switch (c) {
4060 case '=': 4099 case '=':
4061 if (isdigit(*s)) { 4100 if (isdigit(*s)) {
@@ -4313,8 +4352,7 @@ static struct wdblock *glob(char *cp, struct wdblock *wb)
4313 else if (!any(*pp & ~QUOTE, spcl)) 4352 else if (!any(*pp & ~QUOTE, spcl))
4314 *pp &= ~QUOTE; 4353 *pp &= ~QUOTE;
4315 if (i != 0) { 4354 if (i != 0) {
4316 for (cl = addword(scopy(cp), (struct wdblock *) 0); anyspcl(cl); 4355 for (cl = addword(scopy(cp), NULL); anyspcl(cl); cl = nl) {
4317 cl = nl) {
4318 nl = newword(cl->w_nword * 2); 4356 nl = newword(cl->w_nword * 2);
4319 for (i = 0; i < cl->w_nword; i++) { /* for each argument */ 4357 for (i = 0; i < cl->w_nword; i++) { /* for each argument */
4320 for (pp = cl->w_words[i]; *pp; pp++) 4358 for (pp = cl->w_words[i]; *pp; pp++)
@@ -4374,7 +4412,7 @@ static void globname(char *we, char *pp)
4374 /* XXX Hmmm... What this could be? (abial) */ 4412 /* XXX Hmmm... What this could be? (abial) */
4375 /* 4413 /*
4376 if (ent[j].d_ino == 0) 4414 if (ent[j].d_ino == 0)
4377 continue; 4415 continue;
4378 */ 4416 */
4379 strncpy(dname, de->d_name, NAME_MAX); 4417 strncpy(dname, de->d_name, NAME_MAX);
4380 if (dname[0] == '.') 4418 if (dname[0] == '.')
@@ -4409,8 +4447,7 @@ static char *generate(char *start1, char *end1, char *middle, char *end)
4409 char *p; 4447 char *p;
4410 char *op, *xp; 4448 char *op, *xp;
4411 4449
4412 p = op = 4450 p = op = space((int)(end1 - start1) + strlen(middle) + strlen(end) + 2);
4413 space((int) (end1 - start1) + strlen(middle) + strlen(end) + 2);
4414 for (xp = start1; xp != end1;) 4451 for (xp = start1; xp != end1;)
4415 *op++ = *xp++; 4452 *op++ = *xp++;
4416 for (xp = middle; (*op++ = *xp++) != '\0';); 4453 for (xp = middle; (*op++ = *xp++) != '\0';);
@@ -4518,7 +4555,8 @@ static void glob1(char *base, char *lim)
4518 if (i < lptr) { 4555 if (i < lptr) {
4519 c = (*func) (i, lptr); 4556 c = (*func) (i, lptr);
4520 if (c == 0) { 4557 if (c == 0) {
4521 glob2(i, lptr -= v2); 4558 lptr -= v2;
4559 glob2(i, lptr);
4522 continue; 4560 continue;
4523 } 4561 }
4524 if (c < 0) { 4562 if (c < 0) {
@@ -4531,13 +4569,15 @@ static void glob1(char *base, char *lim)
4531 if (j > hptr) { 4569 if (j > hptr) {
4532 c = (*func) (hptr, j); 4570 c = (*func) (hptr, j);
4533 if (c == 0) { 4571 if (c == 0) {
4534 glob2(hptr += v2, j); 4572 hptr += v2;
4573 glob2(hptr, j);
4535 goto begin; 4574 goto begin;
4536 } 4575 }
4537 if (c > 0) { 4576 if (c > 0) {
4538 if (i == lptr) { 4577 if (i == lptr) {
4539 glob3(i, hptr += v2, j); 4578 hptr += v2;
4540 i = lptr += v2; 4579 glob3(i, hptr, j);
4580 i = (lptr += v2);
4541 goto begin; 4581 goto begin;
4542 } 4582 }
4543 glob2(i, j); 4583 glob2(i, j);
@@ -4561,9 +4601,9 @@ static void glob1(char *base, char *lim)
4561 goto top; 4601 goto top;
4562 } 4602 }
4563 4603
4564 4604 lptr -= v2;
4565 glob3(j, lptr -= v2, i); 4605 glob3(j, lptr, i);
4566 j = hptr -= v2; 4606 j = (hptr -= v2);
4567 } 4607 }
4568} 4608}
4569 4609
@@ -4651,37 +4691,39 @@ static int readc(void)
4651 if (c != '\0') { 4691 if (c != '\0') {
4652 e.iop->peekc = 0; 4692 e.iop->peekc = 0;
4653 return c; 4693 return c;
4654 } else { 4694 }
4655 if (e.iop->prev != 0) { 4695 if (e.iop->prev != 0) {
4656 if ((c = (*e.iop->iofn) (e.iop->argp, e.iop)) != '\0') { 4696 c = (*e.iop->iofn)(e.iop->argp, e.iop);
4657 if (c == -1) { 4697 if (c != '\0') {
4658 e.iop++; 4698 if (c == -1) {
4659 continue; 4699 e.iop++;
4660 } 4700 continue;
4661 if (e.iop == iostack)
4662 ioecho(c);
4663 return (e.iop->prev = c);
4664 } else if (e.iop->task == XIO && e.iop->prev != '\n') {
4665 e.iop->prev = 0;
4666 if (e.iop == iostack)
4667 ioecho('\n');
4668 return '\n';
4669 } 4701 }
4702 if (e.iop == iostack)
4703 ioecho(c);
4704 e.iop->prev = c;
4705 return e.iop->prev;
4670 } 4706 }
4671 if (e.iop->task == XIO) { 4707 if (e.iop->task == XIO && e.iop->prev != '\n') {
4672 if (multiline) { 4708 e.iop->prev = 0;
4673 return e.iop->prev = 0; 4709 if (e.iop == iostack)
4674 } 4710 ioecho('\n');
4675 if (interactive && e.iop == iostack + 1) { 4711 return '\n';
4712 }
4713 }
4714 if (e.iop->task == XIO) {
4715 if (multiline) {
4716 e.iop->prev = 0;
4717 return e.iop->prev;
4718 }
4719 if (interactive && e.iop == iostack + 1) {
4676#if ENABLE_FEATURE_EDITING 4720#if ENABLE_FEATURE_EDITING
4677 current_prompt = prompt->value; 4721 current_prompt = prompt->value;
4678#else 4722#else
4679 prs(prompt->value); 4723 prs(prompt->value);
4680#endif 4724#endif
4681 }
4682 } 4725 }
4683 } 4726 }
4684
4685 } /* FOR */ 4727 } /* FOR */
4686 4728
4687 if (e.iop >= iostack) { 4729 if (e.iop >= iostack) {
@@ -4764,8 +4806,6 @@ static void pushio(struct ioarg *argp, int (*fn) (struct ioarg *))
4764 e.iop->task = XGRAVE; 4806 e.iop->task = XGRAVE;
4765 else 4807 else
4766 e.iop->task = XOTHER; 4808 e.iop->task = XOTHER;
4767
4768 return;
4769} 4809}
4770 4810
4771static struct io *setbase(struct io *ip) 4811static struct io *setbase(struct io *ip)
@@ -4790,7 +4830,8 @@ static int nlchar(struct ioarg *ap)
4790 4830
4791 if (ap->aword == NULL) 4831 if (ap->aword == NULL)
4792 return 0; 4832 return 0;
4793 if ((c = *ap->aword++) == 0) { 4833 c = *ap->aword++;
4834 if (c == 0) {
4794 ap->aword = NULL; 4835 ap->aword = NULL;
4795 return '\n'; 4836 return '\n';
4796 } 4837 }
@@ -4891,7 +4932,6 @@ static int filechar(struct ioarg *ap)
4891 lseek(ap->afile, ap->afpos, SEEK_SET); 4932 lseek(ap->afile, ap->afpos, SEEK_SET);
4892 4933
4893 i = safe_read(ap->afile, bp->buf, sizeof(bp->buf)); 4934 i = safe_read(ap->afile, bp->buf, sizeof(bp->buf));
4894
4895 if (i <= 0) { 4935 if (i <= 0) {
4896 closef(ap->afile); 4936 closef(ap->afile);
4897 return 0; 4937 return 0;
@@ -4918,12 +4958,10 @@ static int filechar(struct ioarg *ap)
4918 c = mycommand[position]; 4958 c = mycommand[position];
4919 position++; 4959 position++;
4920 return c; 4960 return c;
4921 } else
4922#endif
4923 {
4924 i = safe_read(ap->afile, &c, sizeof(c));
4925 return i == sizeof(c) ? (c & 0x7f) : (closef(ap->afile), 0);
4926 } 4961 }
4962#endif
4963 i = safe_read(ap->afile, &c, sizeof(c));
4964 return i == sizeof(c) ? (c & 0x7f) : (closef(ap->afile), 0);
4927} 4965}
4928 4966
4929/* 4967/*
@@ -4935,10 +4973,9 @@ static int herechar(struct ioarg *ap)
4935 4973
4936 if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) { 4974 if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) {
4937 close(ap->afile); 4975 close(ap->afile);
4938 c = 0; 4976 c = '\0';
4939 } 4977 }
4940 return c; 4978 return c;
4941
4942} 4979}
4943 4980
4944/* 4981/*
@@ -5087,7 +5124,7 @@ static void markhere(char *s, struct ioword *iop)
5087 DBGPRINTF7(("MARKHERE: enter, s=%p\n", s)); 5124 DBGPRINTF7(("MARKHERE: enter, s=%p\n", s));
5088 5125
5089 h = (struct here *) space(sizeof(struct here)); 5126 h = (struct here *) space(sizeof(struct here));
5090 if (h == 0) 5127 if (h == NULL)
5091 return; 5128 return;
5092 5129
5093 h->h_tag = evalstr(s, DOSUB); 5130 h->h_tag = evalstr(s, DOSUB);
@@ -5099,18 +5136,21 @@ static void markhere(char *s, struct ioword *iop)
5099 h->h_next = NULL; 5136 h->h_next = NULL;
5100 if (inhere == 0) 5137 if (inhere == 0)
5101 inhere = h; 5138 inhere = h;
5102 else 5139 else {
5103 for (lh = inhere; lh != NULL; lh = lh->h_next) 5140 for (lh = inhere; lh != NULL; lh = lh->h_next) {
5104 if (lh->h_next == 0) { 5141 if (lh->h_next == 0) {
5105 lh->h_next = h; 5142 lh->h_next = h;
5106 break; 5143 break;
5107 } 5144 }
5145 }
5146 }
5108 iop->io_flag |= IOHERE | IOXHERE; 5147 iop->io_flag |= IOHERE | IOXHERE;
5109 for (s = h->h_tag; *s; s++) 5148 for (s = h->h_tag; *s; s++) {
5110 if (*s & QUOTE) { 5149 if (*s & QUOTE) {
5111 iop->io_flag &= ~IOXHERE; 5150 iop->io_flag &= ~IOXHERE;
5112 *s &= ~QUOTE; 5151 *s &= ~QUOTE;
5113 } 5152 }
5153 }
5114 h->h_dosub = iop->io_flag & IOXHERE; 5154 h->h_dosub = iop->io_flag & IOXHERE;
5115} 5155}
5116 5156
@@ -5218,7 +5258,8 @@ static int herein(char *hname, int xdoll)
5218 tf = mkstemp(tname); 5258 tf = mkstemp(tname);
5219 if (tf < 0) 5259 if (tf < 0)
5220 return -1; 5260 return -1;
5221 if (newenv(setjmp(errpt = ev)) == 0) { 5261 errpt = ev;
5262 if (newenv(setjmp(errpt)) == 0) {
5222 PUSHIO(afile, hf, herechar); 5263 PUSHIO(afile, hf, herechar);
5223 setbase(e.iop); 5264 setbase(e.iop);
5224 while ((c = subgetc(0, 0)) != 0) { 5265 while ((c = subgetc(0, 0)) != 0) {
@@ -5232,8 +5273,8 @@ static int herein(char *hname, int xdoll)
5232 tf = open(tname, 0); 5273 tf = open(tname, 0);
5233 unlink(tname); 5274 unlink(tname);
5234 return tf; 5275 return tf;
5235 } else 5276 }
5236 return hf; 5277 return hf;
5237} 5278}
5238 5279
5239static void scraphere(void) 5280static void scraphere(void)
@@ -5270,7 +5311,6 @@ static void freehere(int area)
5270} 5311}
5271 5312
5272 5313
5273
5274/* 5314/*
5275 * Copyright (c) 1987,1997, Prentice Hall 5315 * Copyright (c) 1987,1997, Prentice Hall
5276 * All rights reserved. 5316 * All rights reserved.