struct jmploc {
jmp_buf loc;
};
-static struct jmploc *handler;
+static struct jmploc *exception_handler;
static int exception;
/* exceptions */
#define EXINT 0 /* SIGINT received */
raise_exception(int e)
{
#if DEBUG
- if (handler == NULL)
+ if (exception_handler == NULL)
abort();
#endif
INT_OFF;
exception = e;
- longjmp(handler->loc, 1);
+ longjmp(exception_handler->loc, 1);
}
/*
indx = 0;
else
#endif
- if (U_C(c) >= U_C(CTLESC) && U_C(c) <= U_C(CTLQUOTEMARK))
- return CCTL;
+ if (U_C(c) >= U_C(CTLESC) && U_C(c) <= U_C(CTLQUOTEMARK))
+ return CCTL;
else {
s = strchr(spec_symbls, c);
- if (s == 0 || *s == 0)
+ if (s == NULL || *s == '\0')
return CWORD;
indx = syntax_index_table[(s - spec_symbls)];
}
struct stat st1, st2;
initvar();
- for (envp = environ ; envp && *envp ; envp++) {
+ for (envp = environ; envp && *envp; envp++) {
if (strchr(*envp, '=')) {
setvareq(*envp, VEXPORT|VTEXTFIXED);
}
setstackmark(&smark);
arglist.lastp = &arglist.list;
- for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
+ for (argp = n->nfor.args; argp; argp = argp->narg.next) {
expandarg(argp, &arglist, EXP_FULL | EXP_TILDE | EXP_RECORD);
/* XXX */
if (evalskip)
exitstatus = 0;
loopnest++;
flags &= EV_TESTED;
- for (sp = arglist.list ; sp ; sp = sp->next) {
+ for (sp = arglist.list; sp; sp = sp->next) {
setvar(n->nfor.var, sp->text, 0);
evaltree(n->nfor.body, flags);
if (evalskip) {
arglist.lastp = &arglist.list;
expandarg(n->ncase.expr, &arglist, EXP_TILDE);
exitstatus = 0;
- for (cp = n->ncase.cases ; cp && evalskip == 0 ; cp = cp->nclist.next) {
- for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
+ for (cp = n->ncase.cases; cp && evalskip == 0; cp = cp->nclist.next) {
+ for (patp = cp->nclist.pattern; patp; patp = patp->narg.next) {
if (casematch(patp, arglist.list->text)) {
if (evalskip == 0) {
evaltree(cp->nclist.body, flags);
{
union node *redir;
- for (redir = n ; redir ; redir = redir->nfile.next) {
+ for (redir = n; redir; redir = redir->nfile.next) {
struct arglist fn;
- memset(&fn, 0, sizeof(struct arglist));
+
+ memset(&fn, 0, sizeof(fn));
fn.lastp = &fn.list;
switch (redir->type) {
case NFROMTO:
case NTOFD:
if (redir->ndup.vname) {
expandarg(redir->ndup.vname, &fn, EXP_FULL | EXP_TILDE);
- if (fn.list != NULL)
- fixredir(redir, fn.list->text, 1);
- else
+ if (fn.list == NULL)
ash_msg_and_raise_error("redir error");
+ fixredir(redir, fn.list->text, 1);
}
break;
}
TRACE(("evalpipe(0x%lx) called\n", (long)n));
pipelen = 0;
- for (lp = n->npipe.cmdlist ; lp ; lp = lp->next)
+ for (lp = n->npipe.cmdlist; lp; lp = lp->next)
pipelen++;
flags |= EV_EXIT;
INT_OFF;
jp = makejob(n, pipelen);
prevfd = -1;
- for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
+ for (lp = n->npipe.cmdlist; lp; lp = lp->next) {
prehash(lp->n);
pip[1] = -1;
if (lp->next) {
}
argv = nargv = stalloc(sizeof(char *) * (argc + 1));
- for (sp = arglist.list ; sp ; sp = sp->next) {
+ for (sp = arglist.list; sp; sp = sp->next) {
TRACE(("evalcommand arg: %s\n", sp->text));
*nargv++ = sp->text;
}
if (i == EXINT || spclbltin > 0) {
raise:
- longjmp(handler->loc, 1);
+ longjmp(exception_handler->loc, 1);
}
FORCE_INT_ON;
}
i = setjmp(jmploc.loc);
if (i)
goto cmddone;
- savehandler = handler;
- handler = &jmploc;
+ savehandler = exception_handler;
+ exception_handler = &jmploc;
commandname = argv[0];
argptr = argv + 1;
optptr = NULL; /* initialize nextopt */
clearerr(stdout);
commandname = savecmdname;
exsig = 0;
- handler = savehandler;
+ exception_handler = savehandler;
return i;
}
goto funcdone;
}
INT_OFF;
- savehandler = handler;
- handler = &jmploc;
+ savehandler = exception_handler;
+ exception_handler = &jmploc;
localvars = NULL;
shellparam.malloc = 0;
func->count++;
localvars = savelocalvars;
freeparam(&shellparam);
shellparam = saveparam;
- handler = savehandler;
+ exception_handler = savehandler;
INT_ON;
evalskip &= ~SKIPFUNC;
return e;
* Exec a program. Never returns. If you change this routine, you may
* have to change the find_command routine as well.
*/
-
+static void shellexec(char **, const char *, int) ATTRIBUTE_NORETURN;
static void
shellexec(char **argv, const char *path, int idx)
{
if (*path == NULL)
return NULL;
start = *path;
- for (p = start ; *p && *p != ':' && *p != '%' ; p++);
+ for (p = start; *p && *p != ':' && *p != '%'; p++);
len = p - start + strlen(name) + 2; /* "2" is for '/' and '\0' */
while (stackblocksize() < len)
growstackblock();
return 0;
}
if (*argptr == NULL) {
- for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
- for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
+ for (pp = cmdtable; pp < &cmdtable[CMDTABLESIZE]; pp++) {
+ for (cmdp = *pp; cmdp; cmdp = cmdp->next) {
if (cmdp->cmdtype == CMDNORMAL)
printentry(cmdp);
}
struct tblentry **pp;
struct tblentry *cmdp;
- for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
- for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
+ for (pp = cmdtable; pp < &cmdtable[CMDTABLESIZE]; pp++) {
+ for (cmdp = *pp; cmdp; cmdp = cmdp->next) {
if (cmdp->cmdtype == CMDNORMAL || (
cmdp->cmdtype == CMDBUILTIN &&
!(IS_BUILTIN_REGULAR(cmdp->param.cmd)) &&
struct tblentry *cmdp;
INT_OFF;
- for (tblp = cmdtable ; tblp < &cmdtable[CMDTABLESIZE] ; tblp++) {
+ for (tblp = cmdtable; tblp < &cmdtable[CMDTABLESIZE]; tblp++) {
pp = tblp;
while ((cmdp = *pp) != NULL) {
if ((cmdp->cmdtype == CMDNORMAL &&
hashval += (unsigned char)*p++;
hashval &= 0x7FFF;
pp = &cmdtable[hashval % CMDTABLESIZE];
- for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
+ for (cmdp = *pp; cmdp; cmdp = cmdp->next) {
if (equal(cmdp->cmdname, name))
break;
pp = &cmdp->next;
static size_t esclen(const char *, const char *);
static char *scanleft(char *, char *, char *, char *, int, int);
static char *scanright(char *, char *, char *, char *, int, int);
-static void varunset(const char *, const char *, const char *, int)
- ATTRIBUTE_NORETURN;
+static void varunset(const char *, const char *, const char *, int) ATTRIBUTE_NORETURN;
#define pmatch(a, b) !fnmatch((a), (b), 0)
struct strlist *sp;
len = 0;
- for (sp = str ; sp ; sp = sp->next)
+ for (sp = str; sp; sp = sp->next)
len++;
return msort(str, len);
}
return list;
half = len >> 1;
p = list;
- for (n = half ; --n >= 0 ; ) {
+ for (n = half; --n >= 0; ) {
q = p;
p = p->next;
}
return len;
}
+static void varunset(const char *, const char *, const char *, int) ATTRIBUTE_NORETURN;
static void
varunset(const char *end, const char *var, const char *umsg, int varflags)
{
return 0;
}
name = get_signame(signo);
- if (isdigit(*name))
- out1fmt(snlfmt, name);
- else
+ if (!isdigit(*name))
ash_msg_and_raise_error("invalid signal number or exit status: %s", *argptr);
+ out1fmt(snlfmt, name);
return 0;
}
int i;
INT_OFF;
- for (i = jp->nprocs, ps = jp->ps ; --i >= 0 ; ps++) {
+ for (i = jp->nprocs, ps = jp->ps; --i >= 0; ps++) {
if (ps->cmd != nullstr)
free(ps->cmd);
}
int i;
struct job *jp;
- for (i = njobs, jp = jobtab ; ; jp++) {
+ for (i = njobs, jp = jobtab; ; jp++) {
if (--i < 0) {
jp = growjobtab();
break;
break;
if (*p == '\0')
continue;
- for (q = p ; *q ; q++);
+ for (q = p; *q; q++);
#if DEBUG
if (q[-1] != '/')
abort();
else
goto state4;
}
- handler = &jmploc;
+ exception_handler = &jmploc;
#if DEBUG
opentrace();
trputs("Shell args: "); trargs(argv);
static int
number(const char *s)
{
- if (! is_number(s))
+ if (!is_number(s))
ash_msg_and_raise_error(illnum, s);
return atoi(s);
}
is_number(const char *p)
{
do {
- if (! is_digit(*p))
+ if (!is_digit(*p))
return 0;
} while (*++p != '\0');
return 1;
char **ap;
int nparam;
- for (nparam = 0 ; argv[nparam] ; nparam++);
+ for (nparam = 0; argv[nparam]; nparam++);
ap = newparam = ckmalloc((nparam + 1) * sizeof(*ap));
while (*argv) {
*ap++ = savestr(*argv++);
char **ap;
if (param->malloc) {
- for (ap = param->p ; *ap ; ap++)
+ for (ap = param->p; *ap; ap++)
free(*ap);
free(param->p);
}
ash_msg_and_raise_error("can't shift that many");
INT_OFF;
shellparam.nparam -= n;
- for (ap1 = shellparam.p ; --n >= 0 ; ap1++) {
+ for (ap1 = shellparam.p; --n >= 0; ap1++) {
if (shellparam.malloc)
free(*ap1);
}
return '\0';
}
c = *p++;
- for (q = optstring ; *q != c ; ) {
+ for (q = optstring; *q != c; ) {
if (*q == '\0')
ash_msg_and_raise_error("Illegal option -%c", c);
if (*++q == ':')
n2->type = NNOT;
n2->nnot.com = n1;
return n2;
- } else
- return n1;
+ }
+ return n1;
}
char *p, *q;
p = line;
- for (q = eofmark + 1 ; *q && *p == *q ; p++, q++);
+ for (q = eofmark + 1; *q && *p == *q; p++, q++);
if (*p == '\n' && *q == '\0') {
c = PEOF;
plinno++;
if (str)
free(str);
parsebackquote = 0;
- handler = savehandler;
- longjmp(handler->loc, 1);
+ exception_handler = savehandler;
+ longjmp(exception_handler->loc, 1);
}
INT_OFF;
str = NULL;
str = ckmalloc(savelen);
memcpy(str, stackblock(), savelen);
}
- savehandler = handler;
- handler = &jmploc;
+ savehandler = exception_handler;
+ exception_handler = &jmploc;
INT_ON;
if (oldstyle) {
/* We must read until the closing backquote, giving special
INT_ON;
}
parsebackquote = savepbq;
- handler = savehandler;
+ exception_handler = savehandler;
if (arinest || dblquote)
USTPUTC(CTLBACKQ | CTLQUOTE, out);
else
if (redir->nfile.type == NTOFD || redir->nfile.type == NFROMFD) {
if (redir->ndup.dupfd >= 0) { /* if not ">&-" */
- copyfd(redir->ndup.dupfd, fd);
+ copyfd(redir->ndup.dupfd, fd);
}
return;
}
q->next = redirlist;
redirlist = q;
q->nullredirs = nullredirs - 1;
- for (i = 0 ; i < 10 ; i++)
+ for (i = 0; i < 10; i++)
q->renamed[i] = EMPTY;
nullredirs = 0;
sv = q;
return;
INT_OFF;
rp = redirlist;
- for (i = 0 ; i < 10 ; i++) {
+ for (i = 0; i < 10; i++) {
if (rp->renamed[i] != EMPTY) {
if (!drop) {
close(i);
if (newfd < 0) {
if (errno == EMFILE)
return EMPTY;
- else
- ash_msg_and_raise_error("%d: %m", from);
+ ash_msg_and_raise_error("%d: %m", from);
}
return newfd;
}
{
int err;
volatile int saveint;
- struct jmploc *volatile savehandler = handler;
+ struct jmploc *volatile savehandler = exception_handler;
struct jmploc jmploc;
SAVE_INT(saveint);
err = setjmp(jmploc.loc) * 2;
if (!err) {
- handler = &jmploc;
+ exception_handler = &jmploc;
redirect(redir, flags);
}
- handler = savehandler;
+ exception_handler = savehandler;
if (err && exception != EXERROR)
- longjmp(handler->loc, 1);
+ longjmp(exception_handler->loc, 1);
RESTORE_INT(saveint);
return err;
}
putc('\n', fp);
break;
case NPIPE:
- for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
+ for (lp = n->npipe.cmdlist; lp; lp = lp->next) {
shcmd(lp->n, fp);
if (lp->next)
fputs(" | ", fp);
int dftfd;
first = 1;
- for (np = cmd->ncmd.args ; np ; np = np->narg.next) {
+ for (np = cmd->ncmd.args; np; np = np->narg.next) {
if (! first)
putchar(' ');
sharg(np, fp);
first = 0;
}
- for (np = cmd->ncmd.redirect ; np ; np = np->nfile.next) {
+ for (np = cmd->ncmd.redirect; np; np = np->nfile.next) {
if (! first)
putchar(' ');
switch (np->nfile.type) {
- case NTO: s = ">"; dftfd = 1; break;
- case NCLOBBER: s = ">|"; dftfd = 1; break;
- case NAPPEND: s = ">>"; dftfd = 1; break;
- case NTOFD: s = ">&"; dftfd = 1; break;
- case NFROM: s = "<"; dftfd = 0; break;
- case NFROMFD: s = "<&"; dftfd = 0; break;
- case NFROMTO: s = "<>"; dftfd = 0; break;
- default: s = "*error*"; dftfd = 0; break;
+ case NTO: s = ">"; dftfd = 1; break;
+ case NCLOBBER: s = ">|"; dftfd = 1; break;
+ case NAPPEND: s = ">>"; dftfd = 1; break;
+ case NTOFD: s = ">&"; dftfd = 1; break;
+ case NFROM: s = "<"; dftfd = 0; break;
+ case NFROMFD: s = "<&"; dftfd = 0; break;
+ case NFROMTO: s = "<>"; dftfd = 0; break;
+ default: s = "*error*"; dftfd = 0; break;
}
if (np->nfile.fd != dftfd)
fprintf(fp, "%d", np->nfile.fd);
abort();
}
bqlist = arg->narg.backquote;
- for (p = arg->narg.text ; *p ; p++) {
+ for (p = arg->narg.text; *p; p++) {
switch (*p) {
case CTLESC:
putc(*++p, fp);
{
int i;
- for (i = 0 ; i < amount ; i++) {
+ for (i = 0; i < amount; i++) {
if (pfx && i == amount - 1)
fputs(pfx, fp);
putc('\t', fp);
if (debug != 1)
return;
putc('"', tracefile);
- for (p = s ; *p ; p++) {
+ for (p = s; *p; p++) {
switch (*p) {
case '\n': c = 'n'; goto backslash;
case '\t': c = 't'; goto backslash;
case '\\': c = '\\'; goto backslash;
case CTLESC: c = 'e'; goto backslash;
case CTLVAR: c = 'v'; goto backslash;
- case CTLVAR+CTLQUOTE: c = 'V'; goto backslash;
+ case CTLVAR+CTLQUOTE: c = 'V'; goto backslash;
case CTLBACKQ: c = 'q'; goto backslash;
- case CTLBACKQ+CTLQUOTE: c = 'Q'; goto backslash;
- backslash: putc('\\', tracefile);
+ case CTLBACKQ+CTLQUOTE: c = 'Q'; goto backslash;
+ backslash:
+ putc('\\', tracefile);
putc(c, tracefile);
break;
default:
nextopt(nullstr);
ap = argptr;
if (!*ap) {
- for (signo = 0 ; signo < NSIG ; signo++) {
+ for (signo = 0; signo < NSIG; signo++) {
if (trap[signo] != NULL) {
const char *sn;
{
char **tp;
- for (tp = trap ; tp < &trap[NSIG] ; tp++) {
+ for (tp = trap; tp < &trap[NSIG]; tp++) {
if (*tp && **tp) { /* trap not NULL or SIG_IGN */
INT_OFF;
free(*tp);
return;
}
if (act.sa_handler == SIG_IGN) {
- if (mflag && (signo == SIGTSTP || signo == SIGTTIN
- || signo == SIGTTOU)
+ if (mflag
+ && (signo == SIGTSTP || signo == SIGTTIN || signo == SIGTTOU)
) {
tsig = S_IGN; /* don't hard ignore these */
} else
for (i = 0, q = gotsig; i < NSIG - 1; i++, q++) {
if (!*q)
continue;
- *q = 0;
+ *q = '\0';
p = trap[i + 1];
if (!p)
setsignal(SIGQUIT);
setsignal(SIGTERM);
#if !ENABLE_FEATURE_SH_EXTRA_QUIET
- if (is_interactive > 1) {
- /* Looks like they want an interactive shell */
- static int do_banner;
-
- if (!do_banner) {
- out1fmt(
- "\n\n%s Built-in shell (ash)\n"
- "Enter 'help' for a list of built-in commands.\n\n",
- BB_BANNER);
- do_banner++;
- }
+ if (is_interactive > 1) {
+ /* Looks like they want an interactive shell */
+ static int do_banner;
+
+ if (!do_banner) {
+ out1fmt(
+ "\n\n"
+ "%s Built-in shell (ash)\n"
+ "Enter 'help' for a list of built-in commands."
+ "\n\n",
+ BB_BANNER);
+ do_banner++;
}
+ }
#endif
}
status = exitstatus;
goto out;
}
- handler = &loc;
+ exception_handler = &loc;
p = trap[0];
if (p) {
trap[0] = NULL;
{
int err;
volatile int saveint;
- struct jmploc *volatile savehandler = handler;
+ struct jmploc *volatile savehandler = exception_handler;
struct jmploc jmploc;
SAVE_INT(saveint);
if (setjmp(jmploc.loc))
err = 1;
else {
- handler = &jmploc;
+ exception_handler = &jmploc;
setvar(name, val, flags);
err = 0;
}
- handler = savehandler;
+ exception_handler = savehandler;
RESTORE_INT(saveint);
return err;
}
{
struct strlist *sp;
- for (sp = cmdenviron ; sp ; sp = sp->next) {
+ for (sp = cmdenviron; sp; sp = sp->next) {
if (varequal(sp->text, name))
return strchrnul(sp->text, '=') + 1;
}
vpp = vartab;
mask = on | off;
do {
- for (vp = *vpp ; vp ; vp = vp->next)
+ for (vp = *vpp; vp; vp = vp->next)
if ((vp->flags & mask) == on) {
if (ep == stackstrend())
ep = growstackstr();
const char *p;
char **aptr;
int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT;
- int notp;
- notp = nextopt("p") - 'p';
- if (notp && ((name = *(aptr = argptr)))) {
- do {
- p = strchr(name, '=');
- if (p != NULL) {
- p++;
- } else {
- vp = *findvar(hashvar(name), name);
- if (vp) {
- vp->flags |= flag;
- continue;
+ if (nextopt("p") != 'p') {
+ aptr = argptr;
+ name = *aptr;
+ if (name) {
+ do {
+ p = strchr(name, '=');
+ if (p != NULL) {
+ p++;
+ } else {
+ vp = *findvar(hashvar(name), name);
+ if (vp) {
+ vp->flags |= flag;
+ continue;
+ }
}
- }
- setvar(name, p, flag);
- } while ((name = *++aptr) != NULL);
- } else {
- showvars(argv[0], flag, 0);
+ setvar(name, p, flag);
+ } while ((name = *++aptr) != NULL);
+ return 0;
+ }
}
+ showvars(argv[0], flag, 0);
return 0;
}
flag = i;
}
- for (ap = argptr; *ap ; ap++) {
+ for (ap = argptr; *ap; ap++) {
if (flag != 'f') {
i = unsetvar(*ap);
ret |= i;
numstackptr++;
lasttok = TOK_NUM;
continue;
- } else if (is_digit(arithval)) {
+ }
+ if (is_digit(arithval)) {
numstackptr->var = NULL;
#if ENABLE_ASH_MATH_SUPPORT_64
numstackptr->val = strtoll(expr, (char **) &expr, 0);