/* Strings for names to make debug easier */
#ifdef MSHDEBUG
-static char *T_CMD_NAMES[] = {
+static const char *const T_CMD_NAMES[] = {
"PLACEHOLDER",
"TCOM",
"TPAREN",
char task; /* reason for pushed IO */
};
-//static struct io iostack[NPUSH];
+//static struct io iostack[NPUSH];
#define XOTHER 0 /* none of the below */
#define XDOLL 1 /* expanding ${} */
#define XGRAVE 2 /* expanding `'s */
-#define XIO 3 /* file IO */
+#define XIO 3 /* file IO */
/* in substitution */
#define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL)
static char *trap[_NSIG + 1];
static char ourtrap[_NSIG + 1];
static int trapset; /* trap pending */
-static int yynerrs; /* yacc */
-static char line[LINELIM];
#ifdef MSHDEBUG
static struct var *mshdbg_var;
};
#ifdef MSHDEBUG
-void print_t(struct op *t);
void print_t(struct op *t)
{
DBGPRINTF(("T: t=%p, type %s, words=%p, IOword=%p\n", t,
return;
}
-void print_tree(struct op *head);
void print_tree(struct op *head)
{
if (head == NULL) {
DBGPRINTF(("MSH_MAIN: argc %d, environ %p\n", argc, environ));
initarea();
- if ((ap = environ) != NULL) {
+ ap = environ;
+ if (ap != NULL) {
while (*ap)
assign(*ap++, !COPYV);
for (ap = environ; *ap;)
cp = m;
for (c = 'a'; c <= 'z'; c++)
- if (flag[(int) c])
+ if (flag[c])
*cp++ = c;
*cp = 0;
setval(lookup("-"), m);
leave();
}
- if ((i = trapset) != 0) {
+ i = trapset;
+ if (i != 0) {
trapset = 0;
runtrap(i);
}
DBGPRINTF(("QUITENV: e.oenv=%p\n", e.oenv));
- if ((ep = e.oenv) != NULL) {
+ ep = e.oenv;
+ if (ep != NULL) {
fd = e.iofd;
e = *ep;
/* should close `'d files */
{
char *cp;
- if ((cp = getcell(n)) == 0)
+ cp = getcell(n);
+ if (cp == 0)
err("out of string space");
return cp;
}
static char *strsave(char *s, int a)
{
- char *cp, *xp;
+ char *cp;
- if ((cp = space(strlen(s) + 1)) != NULL) {
- setarea((char *) cp, a);
- for (xp = cp; (*xp++ = *s++) != '\0';);
+ cp = space(strlen(s) + 1);
+ if (cp != NULL) {
+ setarea(cp, a);
+ strcpy(cp, s);
return cp;
}
return "";
{
char *trapstr;
- if ((trapstr = trap[i]) == NULL)
+ trapstr = trap[i];
+ if (trapstr == NULL)
return;
if (i == 0)
sc = *s++ & QMASK;
switch (pc) {
case '[':
- if ((p = cclass(p, sc)) == NULL)
+ p = cclass(p, sc);
+ if (p == NULL)
return 0;
break;
{
struct region *p;
- if ((p = (struct region *) cp) != NULL) {
+ p = (struct region *) cp;
+ if (p != NULL) {
p--;
if (p < areanxt)
areanxt = p;
if (t != NULL) {
while ((c = yylex(0)) == '|') {
- if ((p = command(CONTIN)) == NULL) {
+ p = command(CONTIN);
+ if (p == NULL) {
DBGPRINTF8(("PIPELINE: error!\n"));
SYNTAXERR;
}
if (t != NULL) {
while ((c = yylex(0)) == LOGAND || c == LOGOR) {
- if ((p = pipeline(CONTIN)) == NULL) {
+ p = pipeline(CONTIN);
+ if (p == NULL) {
DBGPRINTF8(("ANDOR: error!\n"));
SYNTAXERR;
}
t = andor();
if (t != NULL) {
- if ((peeksym = yylex(0)) == '&')
+ peeksym = yylex(0);
+ if (peeksym == '&')
t = block(TASYNC, t, NOBLOCK, NOWORDS);
while ((c = yylex(0)) == ';' || c == '&'
|| (multiline && c == '\n')) {
- if ((p = andor()) == NULL)
+ p = andor();
+ if (p== NULL)
return t;
- if ((peeksym = yylex(0)) == '&')
+ peeksym = yylex(0);
+ if (peeksym == '&')
p = block(TASYNC, p, NOBLOCK, NOWORDS);
t = list(t, p);
DBGPRINTF7(("SYNIO: enter, cf=%d\n", cf));
- if ((c = yylex(cf)) != '<' && c != '>') {
+ c = yylex(cf);
+ if (c != '<' && c != '>') {
peeksym = c;
return 0;
}
switch (c) {
default:
peeksym = c;
- if ((t = simple()) == NULL) {
+ t = simple();
+ if (t == NULL) {
if (iolist == NULL)
return NULL;
t = newtp();
t->str = yylval.cp;
multiline++;
t->words = wordlist();
- if ((c = yylex(0)) != '\n' && c != ';')
+ c = yylex(0);
+ if (c != '\n' && c != ';')
peeksym = c;
t->left = dogroup(0);
multiline--;
int c;
struct op *t;
- if ((c = yylex(0)) != THEN) {
+ c = yylex(0);
+ if (c != THEN) {
peeksym = c;
return NULL;
}
switch (c = yylex(0)) {
case ELSE:
- if ((t = c_list()) == NULL)
+ t = c_list();
+ if (t == NULL)
SYNTAXERR;
return t;
t->words = pattern();
musthave(')', 0);
t->left = c_list();
- if ((peeksym = yylex(CONTIN)) != ESAC)
+ peeksym = yylex(CONTIN);
+ if (peeksym != ESAC)
musthave(BREAK, CONTIN);
DBGPRINTF7(("CASEPART: made newtp(TPAT, t=%p)\n", t));
musthave(WORD, cf);
word(yylval.cp);
cf = 0;
- } while ((c = yylex(0)) == '|');
+ c = yylex(0);
+ } while (c == '|');
peeksym = c;
word(NOWORD);
{
int c;
- if ((c = yylex(0)) != IN) {
+ c = yylex(0);
+ if (c != IN) {
peeksym = c;
return NULL;
}
word(NOWORD);
t->words = copyw();
-
return t;
}
int c, c1;
int atstart;
- if ((c = peeksym) > 0) {
+ c = peeksym;
+ if (c > 0) {
peeksym = 0;
if (c == '\n')
startl = 1;
{
char *t;
- if ((t = getcell(size)) == NULL) {
+ t = getcell(size);
+ if (t == NULL) {
DBGPRINTF2(("TREE: getcell(%d) failed!\n", size));
prs("command line too complicated\n");
fail();
{
int pv[2];
- if ((rv = openpipe(pv)) < 0)
+ rv = openpipe(pv);
+ if (rv < 0)
break;
pv[0] = remap(pv[0]);
pv[1] = remap(pv[1]);
case TOR:
case TAND:
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);
break;
break;
case TCASE:
- if ((cp = evalstr(t->str, DOSUB | DOTRIM)) == 0)
+ cp = evalstr(t->str, DOSUB | DOTRIM);
+ if (cp == 0)
cp = "";
DBGPRINTF7(("EXECUTE: TCASE, t->str is %s, cp is %s\n",
((t->str == NULL) ? "NULL" : t->str),
((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));
rv = execute(t1, pin, pout, 0);
DBGPRINTF7(("EXECUTE: TCASE, back from execute(t=%p, t1=%p)...\n", t, t1));
fail();
}
- if ((i = trapset) != 0) {
+ i = trapset;
+ if (i != 0) {
trapset = 0;
runtrap(i);
}
closepipe(pout);
}
- if ((iopp = t->ioact) != NULL) {
+ iopp = t->ioact;
+ if (iopp != NULL) {
if (shcom != NULL && shcom != doexec) {
prs(cp);
err(": cannot redirect shell command");
if (errno != EINTR || canintr)
break;
} else {
- if ((rv = WAITSIG(s)) != 0) {
+ rv = WAITSIG(s);
+ if (rv != 0) {
if (rv < NSIGNAL) {
if (signame[rv] != NULL) {
if (pid != lastpid) {
ofail = failpt;
rv = -1;
- if (newenv(setjmp(errpt = ev)) == 0) {
+ errpt = ev;
+ if (newenv(setjmp(errpt)) == 0) {
wdlist = 0;
iolist = 0;
pushio(argp, f);
e.iobase = e.iop;
yynerrs = 0;
- if (setjmp(failpt = rt) == 0 && yyparse() == 0)
+ failpt = rt;
+ if (setjmp(failpt) == 0 && yyparse() == 0)
rv = execute(outtree, NOPIPE, NOPIPE, 0);
quitenv();
} else {
{
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";
else if (chdir(cp) < 0)
er = ": bad directory";
int i, n;
char *cp;
- if ((cp = t->words[1]) == NULL) {
+ cp = t->words[1];
+ if (cp == NULL) {
i = umask(0);
umask(i);
for (n = 3 * 4; (n -= 3) >= 0;)
return 1;
execflg = 1;
ofail = failpt;
- if (setjmp(failpt = ex) == 0)
+ failpt = ex;
+ if (setjmp(failpt) == 0)
execute(t, NOPIPE, NOPIPE, FEXEC);
failpt = ofail;
execflg = 0;
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"));
return 0;
} else {
for (i = 0; (*tp++ = cp[i++]) != '\0';);
/* Original code */
- if ((i = open(e.linep, 0)) >= 0) {
+ i = open(e.linep, 0);
+ if (i >= 0) {
exstat = 0;
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));
int i;
char *cp;
- if ((cp = t->words[1]) != NULL) {
+ cp = t->words[1];
+ if (cp != NULL) {
i = getn(cp);
if (i == 0)
return 0;
return 1;
}
for (wp = t->words + 1; *wp; wp++) {
- for (cp = e.linep; !nl && cp < elinep - 1; cp++)
- if ((nb = read(0, cp, sizeof(*cp))) != sizeof(*cp) ||
- (nl = (*cp == '\n')) || (wp[1] && any(*cp, ifs->value)))
+ for (cp = e.linep; !nl && cp < elinep - 1; cp++) {
+ nb = read(0, cp, sizeof(*cp));
+ if (nb != sizeof(*cp) || (nl = (*cp == '\n'))
+ || (wp[1] && any(*cp, ifs->value))
+ ) {
break;
+ }
+ }
*cp = 0;
if (nb <= 0)
break;
{
int n;
- if ((n = getn(s)) < 0 || n > _NSIG) {
+ n = getn(s);
+ if (n < 0 || n > _NSIG) {
err("trap: bad signal number");
n = 0;
}
char *cp;
int n;
- if ((cp = t->words[1]) == NULL) {
+ cp = t->words[1];
+ if (cp == NULL) {
for (vp = vlist; vp; vp = vp->next)
varput(vp->name, 1);
return 0;
wp = NULL;
wb = NULL;
wf = NULL;
- if (newenv(setjmp(errpt = ev)) == 0) {
+ errpt = ev;
+ if (newenv(setjmp(errpt)) == 0) {
while (*ap && isassign(*ap))
expand(*ap++, &wb, f & ~DOGLOB);
if (flag['k']) {
scanequals = f & DOKEY;
foundequals = 0;
- loop:
- switch (c = subgetc('"', foundequals)) {
+ loop:
+ c = subgetc('"', foundequals);
+ switch (c) {
case 0:
if (sp == e.linep)
return 0;
DBGPRINTF3(("SUBGETC: enter, quoted=%d\n", quoted));
- again:
+ again:
c = my_getc(ec);
if (!INSUB() && ec != '\'') {
if (c == '`') {
{
char *s;
- if ((s = as) != NULL)
+ s = as;
+ if (s != NULL)
while (*s)
*s++ &= ~QUOTE;
return as;
if (wb == NULL)
wb = newword(NSTART);
- if ((nw = wb->w_nword) >= wb->w_bsize) {
+ nw = wb->w_nword;
+ if (nw >= wb->w_bsize) {
wb2 = newword(nw * 2);
memcpy((char *) wb2->w_words, (char *) wb->w_words,
nw * sizeof(char *));
int c;
unsigned n;
-
v2 = globv;
- top:
- if ((n = (int) (lim - base)) <= v2)
+ top:
+ n = (int) (lim - base);
+ if (n <= v2)
return;
n = v2 * (n / (2 * v2));
hptr = lptr = base + n;
j = lim - v2;
for (;;) {
if (i < lptr) {
- if ((c = (*func) (i, lptr)) == 0) {
+ c = (*func) (i, lptr);
+ if (c == 0) {
glob2(i, lptr -= v2);
continue;
}
}
}
- begin:
+ begin:
if (j > hptr) {
- if ((c = (*func) (hptr, j)) == 0) {
+ c = (*func) (hptr, j);
+ if (c == 0) {
glob2(hptr += v2, j);
goto begin;
}
for (; e.iop >= e.iobase; e.iop--) {
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;
return c;
} else {
if (fn == filechar || fn == linechar)
e.iop->task = XIO;
else if (fn == (int (*)(struct ioarg *)) gravechar
- || fn == (int (*)(struct ioarg *)) qgravechar)
+ || fn == (int (*)(struct ioarg *)) qgravechar)
e.iop->task = XGRAVE;
else
e.iop->task = XOTHER;
char c;
char **wl;
- if ((wl = ap->awordlist) == NULL)
+ wl = ap->awordlist;
+ if (wl == NULL)
return 0;
if (*wl != NULL) {
- if ((c = *(*wl)++) != 0)
+ c = *(*wl)++;
+ if (c != 0)
return c & 0177;
ap->awordlist++;
return ' ';
{
char *wp;
- if ((wp = *ap->awordlist++) != NULL) {
+ wp = *ap->awordlist++;
+ if (wp != NULL) {
PUSHIO(aword, wp, *ap->awordlist == NULL ? strchar : xxchar);
return -1;
}
if (ap->aword == NULL)
return 0;
- if ((c = *ap->aword++) == '\0') {
+ c = *ap->aword++;
+ if (c == '\0') {
ap->aword = NULL;
return ' ';
}
*/
static int strchar(struct ioarg *ap)
{
- int c;
-
- if (ap->aword == NULL || (c = *ap->aword++) == 0)
+ if (ap->aword == NULL)
return 0;
- return c;
+ return *ap->aword++;
}
/*
{
int c;
- if (ap->aword == NULL || (c = *ap->aword++) == 0)
+ if (ap->aword == NULL) || (c = *ap->aword++) == 0)
return 0;
return c | QUOTE;
}
struct iobuf *bp = ap->afbuf;
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)
lseek(ap->afile, ap->afpos, SEEK_SET);
}
bp->id = ap->afid;
- bp->ebufp = (bp->bufp = bp->buf) + i;
+ bp->bufp = bp->buf;
+ bp->ebufp = bp->bufp + i;
}
ap->afpos++;
{
char c;
-
if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) {
close(ap->afile);
c = 0;
{
int c;
- if ((c = qgravechar(ap, iop) & ~QUOTE) == '\n')
+ c = qgravechar(ap, iop) & ~QUOTE;
+ if (c == '\n')
c = ' ';
return c;
}
{
int c;
- if ((c = filechar(ap)) == '\n') {
+ c = filechar(ap);
+ if (c == '\n') {
if (!multiline) {
closef(ap->afile);
ap->afile = -1; /* illegal value */
int map[NOFILE];
int newfd;
-
DBGPRINTF(("REMAP: fd=%d, e.iofd=%d\n", fd, e.iofd));
if (fd < e.iofd) {
{
int i;
- if ((i = pipe(pv)) < 0)
+ i = pipe(pv);
+ if (i < 0)
err("can't create pipe - try again");
return i;
}
return;
*name = strsave(tname, areanum);
- if (newenv(setjmp(errpt = ev)) != 0)
+ errpt = ev;
+ if (newenv(setjmp(errpt)) != 0)
unlink(tname);
else {
pushio(e.iop->argp, (int (*)(struct ioarg *)) e.iop->iofn);