msh: double "static char line[LINELIM]" etc deleted.

massive amounts of assignments-in-ifs deleted
(some of which were VERY nasty)
This commit is contained in:
Denis Vlasenko 2007-01-01 06:00:38 +00:00
parent d1a302b52f
commit e27f15615f
2 changed files with 140 additions and 89 deletions

View File

@ -138,7 +138,7 @@ struct op {
/* Strings for names to make debug easier */ /* Strings for names to make debug easier */
#ifdef MSHDEBUG #ifdef MSHDEBUG
static char *T_CMD_NAMES[] = { static const char *const T_CMD_NAMES[] = {
"PLACEHOLDER", "PLACEHOLDER",
"TCOM", "TCOM",
"TPAREN", "TPAREN",
@ -694,8 +694,6 @@ static struct wdblock *iolist;
static char *trap[_NSIG + 1]; static char *trap[_NSIG + 1];
static char ourtrap[_NSIG + 1]; static char ourtrap[_NSIG + 1];
static int trapset; /* trap pending */ static int trapset; /* trap pending */
static int yynerrs; /* yacc */
static char line[LINELIM];
#ifdef MSHDEBUG #ifdef MSHDEBUG
static struct var *mshdbg_var; static struct var *mshdbg_var;
@ -746,7 +744,6 @@ static struct env e = {
}; };
#ifdef MSHDEBUG #ifdef MSHDEBUG
void print_t(struct op *t);
void print_t(struct op *t) void print_t(struct op *t)
{ {
DBGPRINTF(("T: t=%p, type %s, words=%p, IOword=%p\n", t, DBGPRINTF(("T: t=%p, type %s, words=%p, IOword=%p\n", t,
@ -759,7 +756,6 @@ void print_t(struct op *t)
return; return;
} }
void print_tree(struct op *head);
void print_tree(struct op *head) void print_tree(struct op *head)
{ {
if (head == NULL) { if (head == NULL) {
@ -802,7 +798,8 @@ int msh_main(int argc, char **argv)
DBGPRINTF(("MSH_MAIN: argc %d, environ %p\n", argc, environ)); DBGPRINTF(("MSH_MAIN: argc %d, environ %p\n", argc, environ));
initarea(); initarea();
if ((ap = environ) != NULL) { ap = environ;
if (ap != NULL) {
while (*ap) while (*ap)
assign(*ap++, !COPYV); assign(*ap++, !COPYV);
for (ap = environ; *ap;) for (ap = environ; *ap;)
@ -989,7 +986,7 @@ static void setdash(void)
cp = m; cp = m;
for (c = 'a'; c <= 'z'; c++) for (c = 'a'; c <= 'z'; c++)
if (flag[(int) c]) if (flag[c])
*cp++ = c; *cp++ = c;
*cp = 0; *cp = 0;
setval(lookup("-"), m); setval(lookup("-"), m);
@ -1105,7 +1102,8 @@ static void onecommand(void)
leave(); leave();
} }
if ((i = trapset) != 0) { i = trapset;
if (i != 0) {
trapset = 0; trapset = 0;
runtrap(i); runtrap(i);
} }
@ -1185,7 +1183,8 @@ static void quitenv(void)
DBGPRINTF(("QUITENV: e.oenv=%p\n", e.oenv)); DBGPRINTF(("QUITENV: e.oenv=%p\n", e.oenv));
if ((ep = e.oenv) != NULL) { ep = e.oenv;
if (ep != NULL) {
fd = e.iofd; fd = e.iofd;
e = *ep; e = *ep;
/* should close `'d files */ /* should close `'d files */
@ -1246,18 +1245,20 @@ static char *space(int n)
{ {
char *cp; char *cp;
if ((cp = getcell(n)) == 0) cp = getcell(n);
if (cp == 0)
err("out of string space"); err("out of string space");
return cp; return cp;
} }
static char *strsave(char *s, int a) static char *strsave(char *s, int a)
{ {
char *cp, *xp; char *cp;
if ((cp = space(strlen(s) + 1)) != NULL) { cp = space(strlen(s) + 1);
setarea((char *) cp, a); if (cp != NULL) {
for (xp = cp; (*xp++ = *s++) != '\0';); setarea(cp, a);
strcpy(cp, s);
return cp; return cp;
} }
return ""; return "";
@ -1276,7 +1277,8 @@ static void runtrap(int i)
{ {
char *trapstr; char *trapstr;
if ((trapstr = trap[i]) == NULL) trapstr = trap[i];
if (trapstr == NULL)
return; return;
if (i == 0) if (i == 0)
@ -1488,7 +1490,8 @@ static int gmatch(char *s, char *p)
sc = *s++ & QMASK; sc = *s++ & QMASK;
switch (pc) { switch (pc) {
case '[': case '[':
if ((p = cclass(p, sc)) == NULL) p = cclass(p, sc);
if (p == NULL)
return 0; return 0;
break; break;
@ -1633,7 +1636,8 @@ static void freecell(char *cp)
{ {
struct region *p; struct region *p;
if ((p = (struct region *) cp) != NULL) { p = (struct region *) cp;
if (p != NULL) {
p--; p--;
if (p < areanxt) if (p < areanxt)
areanxt = p; areanxt = p;
@ -1716,7 +1720,8 @@ static struct op *pipeline(int cf)
if (t != NULL) { if (t != NULL) {
while ((c = yylex(0)) == '|') { while ((c = yylex(0)) == '|') {
if ((p = command(CONTIN)) == NULL) { p = command(CONTIN);
if (p == NULL) {
DBGPRINTF8(("PIPELINE: error!\n")); DBGPRINTF8(("PIPELINE: error!\n"));
SYNTAXERR; SYNTAXERR;
} }
@ -1748,7 +1753,8 @@ static struct op *andor(void)
if (t != NULL) { if (t != NULL) {
while ((c = yylex(0)) == LOGAND || c == LOGOR) { while ((c = yylex(0)) == LOGAND || c == LOGOR) {
if ((p = pipeline(CONTIN)) == NULL) { p = pipeline(CONTIN);
if (p == NULL) {
DBGPRINTF8(("ANDOR: error!\n")); DBGPRINTF8(("ANDOR: error!\n"));
SYNTAXERR; SYNTAXERR;
} }
@ -1773,16 +1779,19 @@ static struct op *c_list(void)
t = andor(); t = andor();
if (t != NULL) { if (t != NULL) {
if ((peeksym = yylex(0)) == '&') peeksym = yylex(0);
if (peeksym == '&')
t = block(TASYNC, t, NOBLOCK, NOWORDS); t = block(TASYNC, t, NOBLOCK, NOWORDS);
while ((c = yylex(0)) == ';' || c == '&' while ((c = yylex(0)) == ';' || c == '&'
|| (multiline && c == '\n')) { || (multiline && c == '\n')) {
if ((p = andor()) == NULL) p = andor();
if (p== NULL)
return t; return t;
if ((peeksym = yylex(0)) == '&') peeksym = yylex(0);
if (peeksym == '&')
p = block(TASYNC, p, NOBLOCK, NOWORDS); p = block(TASYNC, p, NOBLOCK, NOWORDS);
t = list(t, p); t = list(t, p);
@ -1803,7 +1812,8 @@ static int synio(int cf)
DBGPRINTF7(("SYNIO: enter, cf=%d\n", cf)); DBGPRINTF7(("SYNIO: enter, cf=%d\n", cf));
if ((c = yylex(cf)) != '<' && c != '>') { c = yylex(cf);
if (c != '<' && c != '>') {
peeksym = c; peeksym = c;
return 0; return 0;
} }
@ -1892,7 +1902,8 @@ static struct op *command(int cf)
switch (c) { switch (c) {
default: default:
peeksym = c; peeksym = c;
if ((t = simple()) == NULL) { t = simple();
if (t == NULL) {
if (iolist == NULL) if (iolist == NULL)
return NULL; return NULL;
t = newtp(); t = newtp();
@ -1916,7 +1927,8 @@ static struct op *command(int cf)
t->str = yylval.cp; t->str = yylval.cp;
multiline++; multiline++;
t->words = wordlist(); t->words = wordlist();
if ((c = yylex(0)) != '\n' && c != ';') c = yylex(0);
if (c != '\n' && c != ';')
peeksym = c; peeksym = c;
t->left = dogroup(0); t->left = dogroup(0);
multiline--; multiline--;
@ -2017,7 +2029,8 @@ static struct op *thenpart(void)
int c; int c;
struct op *t; struct op *t;
if ((c = yylex(0)) != THEN) { c = yylex(0);
if (c != THEN) {
peeksym = c; peeksym = c;
return NULL; return NULL;
} }
@ -2037,7 +2050,8 @@ static struct op *elsepart(void)
switch (c = yylex(0)) { switch (c = yylex(0)) {
case ELSE: case ELSE:
if ((t = c_list()) == NULL) t = c_list();
if (t == NULL)
SYNTAXERR; SYNTAXERR;
return t; return t;
@ -2079,7 +2093,8 @@ static struct op *casepart(void)
t->words = pattern(); t->words = pattern();
musthave(')', 0); musthave(')', 0);
t->left = c_list(); t->left = c_list();
if ((peeksym = yylex(CONTIN)) != ESAC) peeksym = yylex(CONTIN);
if (peeksym != ESAC)
musthave(BREAK, CONTIN); musthave(BREAK, CONTIN);
DBGPRINTF7(("CASEPART: made newtp(TPAT, t=%p)\n", t)); DBGPRINTF7(("CASEPART: made newtp(TPAT, t=%p)\n", t));
@ -2096,7 +2111,8 @@ static char **pattern(void)
musthave(WORD, cf); musthave(WORD, cf);
word(yylval.cp); word(yylval.cp);
cf = 0; cf = 0;
} while ((c = yylex(0)) == '|'); c = yylex(0);
} while (c == '|');
peeksym = c; peeksym = c;
word(NOWORD); word(NOWORD);
@ -2107,7 +2123,8 @@ static char **wordlist(void)
{ {
int c; int c;
if ((c = yylex(0)) != IN) { c = yylex(0);
if (c != IN) {
peeksym = c; peeksym = c;
return NULL; return NULL;
} }
@ -2210,7 +2227,6 @@ static struct op *namelist(struct op *t)
word(NOWORD); word(NOWORD);
t->words = copyw(); t->words = copyw();
return t; return t;
} }
@ -2270,7 +2286,8 @@ static int yylex(int cf)
int c, c1; int c, c1;
int atstart; int atstart;
if ((c = peeksym) > 0) { c = peeksym;
if (c > 0) {
peeksym = 0; peeksym = 0;
if (c == '\n') if (c == '\n')
startl = 1; startl = 1;
@ -2475,7 +2492,8 @@ static char *tree(unsigned size)
{ {
char *t; char *t;
if ((t = getcell(size)) == NULL) { t = getcell(size);
if (t == NULL) {
DBGPRINTF2(("TREE: getcell(%d) failed!\n", size)); DBGPRINTF2(("TREE: getcell(%d) failed!\n", size));
prs("command line too complicated\n"); prs("command line too complicated\n");
fail(); fail();
@ -2556,7 +2574,8 @@ static int execute(struct op *t, int *pin, int *pout, int act)
{ {
int pv[2]; int pv[2];
if ((rv = openpipe(pv)) < 0) rv = openpipe(pv);
if (rv < 0)
break; break;
pv[0] = remap(pv[0]); pv[0] = remap(pv[0]);
pv[1] = remap(pv[1]); pv[1] = remap(pv[1]);
@ -2608,7 +2627,8 @@ static int execute(struct op *t, int *pin, int *pout, int act)
case TOR: case TOR:
case TAND: case TAND:
rv = execute(t->left, pin, pout, 0); rv = execute(t->left, pin, pout, 0);
if ((t1 = t->right) != NULL && (rv == 0) == (t->type == TAND)) t1 = t->right;
if (t1 != NULL && (rv == 0) == (t->type == TAND))
rv = execute(t1, pin, pout, 0); rv = execute(t1, pin, pout, 0);
break; break;
@ -2655,14 +2675,16 @@ static int execute(struct op *t, int *pin, int *pout, int act)
break; break;
case TCASE: case TCASE:
if ((cp = evalstr(t->str, DOSUB | DOTRIM)) == 0) cp = evalstr(t->str, DOSUB | DOTRIM);
if (cp == 0)
cp = ""; cp = "";
DBGPRINTF7(("EXECUTE: TCASE, t->str is %s, cp is %s\n", DBGPRINTF7(("EXECUTE: TCASE, t->str is %s, cp is %s\n",
((t->str == NULL) ? "NULL" : t->str), ((t->str == NULL) ? "NULL" : t->str),
((cp == NULL) ? "NULL" : cp))); ((cp == NULL) ? "NULL" : cp)));
if ((t1 = findcase(t->left, cp)) != NULL) { t1 = findcase(t->left, cp);
if (t1 != NULL) {
DBGPRINTF7(("EXECUTE: TCASE, calling execute(t=%p, t1=%p)...\n", t, t1)); DBGPRINTF7(("EXECUTE: TCASE, calling execute(t=%p, t1=%p)...\n", t, t1));
rv = execute(t1, pin, pout, 0); rv = execute(t1, pin, pout, 0);
DBGPRINTF7(("EXECUTE: TCASE, back from execute(t=%p, t1=%p)...\n", t, t1)); 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)
fail(); fail();
} }
if ((i = trapset) != 0) { i = trapset;
if (i != 0) {
trapset = 0; trapset = 0;
runtrap(i); runtrap(i);
} }
@ -2852,7 +2875,8 @@ forkexec(struct op *t, int *pin, int *pout, int act, char **wp)
closepipe(pout); closepipe(pout);
} }
if ((iopp = t->ioact) != NULL) { iopp = t->ioact;
if (iopp != NULL) {
if (shcom != NULL && shcom != doexec) { if (shcom != NULL && shcom != doexec) {
prs(cp); prs(cp);
err(": cannot redirect shell command"); err(": cannot redirect shell command");
@ -3069,7 +3093,8 @@ static int waitfor(int lastpid, int canintr)
if (errno != EINTR || canintr) if (errno != EINTR || canintr)
break; break;
} else { } else {
if ((rv = WAITSIG(s)) != 0) { rv = WAITSIG(s);
if (rv != 0) {
if (rv < NSIGNAL) { if (rv < NSIGNAL) {
if (signame[rv] != NULL) { if (signame[rv] != NULL) {
if (pid != lastpid) { if (pid != lastpid) {
@ -3210,13 +3235,15 @@ static int run(struct ioarg *argp, int (*f) (struct ioarg *))
ofail = failpt; ofail = failpt;
rv = -1; rv = -1;
if (newenv(setjmp(errpt = ev)) == 0) { errpt = ev;
if (newenv(setjmp(errpt)) == 0) {
wdlist = 0; wdlist = 0;
iolist = 0; iolist = 0;
pushio(argp, f); pushio(argp, f);
e.iobase = e.iop; e.iobase = e.iop;
yynerrs = 0; yynerrs = 0;
if (setjmp(failpt = rt) == 0 && yyparse() == 0) failpt = rt;
if (setjmp(failpt) == 0 && yyparse() == 0)
rv = execute(outtree, NOPIPE, NOPIPE, 0); rv = execute(outtree, NOPIPE, NOPIPE, 0);
quitenv(); quitenv();
} else { } else {
@ -3287,7 +3314,8 @@ static int dochdir(struct op *t)
{ {
char *cp, *er; char *cp, *er;
if ((cp = t->words[1]) == NULL && (cp = homedir->value) == NULL) cp = t->words[1];
if (cp == NULL && (cp = homedir->value) == NULL)
er = ": no home directory"; er = ": no home directory";
else if (chdir(cp) < 0) else if (chdir(cp) < 0)
er = ": bad directory"; er = ": bad directory";
@ -3337,7 +3365,8 @@ static int doumask(struct op *t)
int i, n; int i, n;
char *cp; char *cp;
if ((cp = t->words[1]) == NULL) { cp = t->words[1];
if (cp == NULL) {
i = umask(0); i = umask(0);
umask(i); umask(i);
for (n = 3 * 4; (n -= 3) >= 0;) for (n = 3 * 4; (n -= 3) >= 0;)
@ -3363,7 +3392,8 @@ static int doexec(struct op *t)
return 1; return 1;
execflg = 1; execflg = 1;
ofail = failpt; ofail = failpt;
if (setjmp(failpt = ex) == 0) failpt = ex;
if (setjmp(failpt) == 0)
execute(t, NOPIPE, NOPIPE, FEXEC); execute(t, NOPIPE, NOPIPE, FEXEC);
failpt = ofail; failpt = ofail;
execflg = 0; execflg = 0;
@ -3379,7 +3409,8 @@ static int dodot(struct op *t)
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))); 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)));
if ((cp = t->words[1]) == NULL) { cp = t->words[1];
if (cp == NULL) {
DBGPRINTF(("DODOT: bad args, ret 0\n")); DBGPRINTF(("DODOT: bad args, ret 0\n"));
return 0; return 0;
} else { } else {
@ -3402,7 +3433,8 @@ static int dodot(struct op *t)
for (i = 0; (*tp++ = cp[i++]) != '\0';); for (i = 0; (*tp++ = cp[i++]) != '\0';);
/* Original code */ /* Original code */
if ((i = open(e.linep, 0)) >= 0) { i = open(e.linep, 0);
if (i >= 0) {
exstat = 0; exstat = 0;
maltmp = remap(i); maltmp = remap(i);
DBGPRINTF(("DODOT: remap=%d, exstat=%d, e.iofd %d, i %d, e.linep is %s\n", maltmp, exstat, e.iofd, i, e.linep)); 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)
int i; int i;
char *cp; char *cp;
if ((cp = t->words[1]) != NULL) { cp = t->words[1];
if (cp != NULL) {
i = getn(cp); i = getn(cp);
if (i == 0) if (i == 0)
return 0; return 0;
@ -3448,10 +3481,14 @@ static int doread(struct op *t)
return 1; return 1;
} }
for (wp = t->words + 1; *wp; wp++) { for (wp = t->words + 1; *wp; wp++) {
for (cp = e.linep; !nl && cp < elinep - 1; cp++) for (cp = e.linep; !nl && cp < elinep - 1; cp++) {
if ((nb = read(0, cp, sizeof(*cp))) != sizeof(*cp) || nb = read(0, cp, sizeof(*cp));
(nl = (*cp == '\n')) || (wp[1] && any(*cp, ifs->value))) if (nb != sizeof(*cp) || (nl = (*cp == '\n'))
|| (wp[1] && any(*cp, ifs->value))
) {
break; break;
}
}
*cp = 0; *cp = 0;
if (nb <= 0) if (nb <= 0)
break; break;
@ -3508,7 +3545,8 @@ static int getsig(char *s)
{ {
int n; int n;
if ((n = getn(s)) < 0 || n > _NSIG) { n = getn(s);
if (n < 0 || n > _NSIG) {
err("trap: bad signal number"); err("trap: bad signal number");
n = 0; n = 0;
} }
@ -3639,7 +3677,8 @@ static int doset(struct op *t)
char *cp; char *cp;
int n; int n;
if ((cp = t->words[1]) == NULL) { cp = t->words[1];
if (cp == NULL) {
for (vp = vlist; vp; vp = vp->next) for (vp = vlist; vp; vp = vp->next)
varput(vp->name, 1); varput(vp->name, 1);
return 0; return 0;
@ -3746,7 +3785,8 @@ static char **eval(char **ap, int f)
wp = NULL; wp = NULL;
wb = NULL; wb = NULL;
wf = NULL; wf = NULL;
if (newenv(setjmp(errpt = ev)) == 0) { errpt = ev;
if (newenv(setjmp(errpt)) == 0) {
while (*ap && isassign(*ap)) while (*ap && isassign(*ap))
expand(*ap++, &wb, f & ~DOGLOB); expand(*ap++, &wb, f & ~DOGLOB);
if (flag['k']) { if (flag['k']) {
@ -3862,7 +3902,8 @@ static char *blank(int f)
foundequals = 0; foundequals = 0;
loop: loop:
switch (c = subgetc('"', foundequals)) { c = subgetc('"', foundequals);
switch (c) {
case 0: case 0:
if (sp == e.linep) if (sp == e.linep)
return 0; return 0;
@ -4231,7 +4272,8 @@ static char *unquote(char *as)
{ {
char *s; char *s;
if ((s = as) != NULL) s = as;
if (s != NULL)
while (*s) while (*s)
*s++ &= ~QUOTE; *s++ &= ~QUOTE;
return as; return as;
@ -4406,7 +4448,8 @@ static struct wdblock *addword(char *wd, struct wdblock *wb)
if (wb == NULL) if (wb == NULL)
wb = newword(NSTART); wb = newword(NSTART);
if ((nw = wb->w_nword) >= wb->w_bsize) { nw = wb->w_nword;
if (nw >= wb->w_bsize) {
wb2 = newword(nw * 2); wb2 = newword(nw * 2);
memcpy((char *) wb2->w_words, (char *) wb->w_words, memcpy((char *) wb2->w_words, (char *) wb->w_words,
nw * sizeof(char *)); nw * sizeof(char *));
@ -4454,11 +4497,11 @@ static void glob1(char *base, char *lim)
int c; int c;
unsigned n; unsigned n;
v2 = globv; v2 = globv;
top: top:
if ((n = (int) (lim - base)) <= v2) n = (int) (lim - base);
if (n <= v2)
return; return;
n = v2 * (n / (2 * v2)); n = v2 * (n / (2 * v2));
hptr = lptr = base + n; hptr = lptr = base + n;
@ -4466,7 +4509,8 @@ static void glob1(char *base, char *lim)
j = lim - v2; j = lim - v2;
for (;;) { for (;;) {
if (i < lptr) { if (i < lptr) {
if ((c = (*func) (i, lptr)) == 0) { c = (*func) (i, lptr);
if (c == 0) {
glob2(i, lptr -= v2); glob2(i, lptr -= v2);
continue; continue;
} }
@ -4478,7 +4522,8 @@ static void glob1(char *base, char *lim)
begin: begin:
if (j > hptr) { if (j > hptr) {
if ((c = (*func) (hptr, j)) == 0) { c = (*func) (hptr, j);
if (c == 0) {
glob2(hptr += v2, j); glob2(hptr += v2, j);
goto begin; goto begin;
} }
@ -4595,7 +4640,8 @@ static int readc(void)
for (; e.iop >= e.iobase; e.iop--) { for (; e.iop >= e.iobase; e.iop--) {
RCPRINTF(("READC: e.iop %p, peekc 0x%x\n", e.iop, e.iop->peekc)); RCPRINTF(("READC: e.iop %p, peekc 0x%x\n", e.iop, e.iop->peekc));
if ((c = e.iop->peekc) != '\0') { c = e.iop->peekc;
if (c != '\0') {
e.iop->peekc = 0; e.iop->peekc = 0;
return c; return c;
} else { } else {
@ -4753,10 +4799,12 @@ static int wdchar(struct ioarg *ap)
char c; char c;
char **wl; char **wl;
if ((wl = ap->awordlist) == NULL) wl = ap->awordlist;
if (wl == NULL)
return 0; return 0;
if (*wl != NULL) { if (*wl != NULL) {
if ((c = *(*wl)++) != 0) c = *(*wl)++;
if (c != 0)
return c & 0177; return c & 0177;
ap->awordlist++; ap->awordlist++;
return ' '; return ' ';
@ -4773,7 +4821,8 @@ static int dolchar(struct ioarg *ap)
{ {
char *wp; char *wp;
if ((wp = *ap->awordlist++) != NULL) { wp = *ap->awordlist++;
if (wp != NULL) {
PUSHIO(aword, wp, *ap->awordlist == NULL ? strchar : xxchar); PUSHIO(aword, wp, *ap->awordlist == NULL ? strchar : xxchar);
return -1; return -1;
} }
@ -4786,7 +4835,8 @@ static int xxchar(struct ioarg *ap)
if (ap->aword == NULL) if (ap->aword == NULL)
return 0; return 0;
if ((c = *ap->aword++) == '\0') { c = *ap->aword++;
if (c == '\0') {
ap->aword = NULL; ap->aword = NULL;
return ' '; return ' ';
} }
@ -4798,11 +4848,9 @@ static int xxchar(struct ioarg *ap)
*/ */
static int strchar(struct ioarg *ap) static int strchar(struct ioarg *ap)
{ {
int c; if (ap->aword == NULL)
if (ap->aword == NULL || (c = *ap->aword++) == 0)
return 0; return 0;
return c; return *ap->aword++;
} }
/* /*
@ -4812,7 +4860,7 @@ static int qstrchar(struct ioarg *ap)
{ {
int c; int c;
if (ap->aword == NULL || (c = *ap->aword++) == 0) if (ap->aword == NULL) || (c = *ap->aword++) == 0)
return 0; return 0;
return c | QUOTE; return c | QUOTE;
} }
@ -4827,8 +4875,8 @@ static int filechar(struct ioarg *ap)
struct iobuf *bp = ap->afbuf; struct iobuf *bp = ap->afbuf;
if (ap->afid != AFID_NOBUF) { if (ap->afid != AFID_NOBUF) {
if ((i = ap->afid != bp->id) || bp->bufp == bp->ebufp) { i = (ap->afid != bp->id);
if (i || bp->bufp == bp->ebufp) {
if (i) if (i)
lseek(ap->afile, ap->afpos, SEEK_SET); lseek(ap->afile, ap->afpos, SEEK_SET);
@ -4840,7 +4888,8 @@ static int filechar(struct ioarg *ap)
} }
bp->id = ap->afid; bp->id = ap->afid;
bp->ebufp = (bp->bufp = bp->buf) + i; bp->bufp = bp->buf;
bp->ebufp = bp->bufp + i;
} }
ap->afpos++; ap->afpos++;
@ -4875,7 +4924,6 @@ static int herechar(struct ioarg *ap)
{ {
char c; char c;
if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) { if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) {
close(ap->afile); close(ap->afile);
c = 0; c = 0;
@ -4892,7 +4940,8 @@ static int gravechar(struct ioarg *ap, struct io *iop)
{ {
int c; int c;
if ((c = qgravechar(ap, iop) & ~QUOTE) == '\n') c = qgravechar(ap, iop) & ~QUOTE;
if (c == '\n')
c = ' '; c = ' ';
return c; return c;
} }
@ -4930,7 +4979,8 @@ static int linechar(struct ioarg *ap)
{ {
int c; int c;
if ((c = filechar(ap)) == '\n') { c = filechar(ap);
if (c == '\n') {
if (!multiline) { if (!multiline) {
closef(ap->afile); closef(ap->afile);
ap->afile = -1; /* illegal value */ ap->afile = -1; /* illegal value */
@ -4974,7 +5024,6 @@ static int remap(int fd)
int map[NOFILE]; int map[NOFILE];
int newfd; int newfd;
DBGPRINTF(("REMAP: fd=%d, e.iofd=%d\n", fd, e.iofd)); DBGPRINTF(("REMAP: fd=%d, e.iofd=%d\n", fd, e.iofd));
if (fd < e.iofd) { if (fd < e.iofd) {
@ -5002,7 +5051,8 @@ static int openpipe(int *pv)
{ {
int i; int i;
if ((i = pipe(pv)) < 0) i = pipe(pv);
if (i < 0)
err("can't create pipe - try again"); err("can't create pipe - try again");
return i; return i;
} }
@ -5089,7 +5139,8 @@ static void readhere(char **name, char *s, int ec)
return; return;
*name = strsave(tname, areanum); *name = strsave(tname, areanum);
if (newenv(setjmp(errpt = ev)) != 0) errpt = ev;
if (newenv(setjmp(errpt)) != 0)
unlink(tname); unlink(tname);
else { else {
pushio(e.iop->argp, (int (*)(struct ioarg *)) e.iop->iofn); pushio(e.iop->argp, (int (*)(struct ioarg *)) e.iop->iofn);