ash: fix indentation and style. no code changes

This commit is contained in:
Denis Vlasenko 2007-02-18 12:35:30 +00:00
parent d0762e3d52
commit a0f82e928a

View File

@ -1154,32 +1154,32 @@ static pointer funcblock; /* block to allocate function from */
static char *funcstring; /* block to allocate strings from */
static const short nodesize[26] = {
SHELL_ALIGN(sizeof (struct ncmd)),
SHELL_ALIGN(sizeof (struct npipe)),
SHELL_ALIGN(sizeof (struct nredir)),
SHELL_ALIGN(sizeof (struct nredir)),
SHELL_ALIGN(sizeof (struct nredir)),
SHELL_ALIGN(sizeof (struct nbinary)),
SHELL_ALIGN(sizeof (struct nbinary)),
SHELL_ALIGN(sizeof (struct nbinary)),
SHELL_ALIGN(sizeof (struct nif)),
SHELL_ALIGN(sizeof (struct nbinary)),
SHELL_ALIGN(sizeof (struct nbinary)),
SHELL_ALIGN(sizeof (struct nfor)),
SHELL_ALIGN(sizeof (struct ncase)),
SHELL_ALIGN(sizeof (struct nclist)),
SHELL_ALIGN(sizeof (struct narg)),
SHELL_ALIGN(sizeof (struct narg)),
SHELL_ALIGN(sizeof (struct nfile)),
SHELL_ALIGN(sizeof (struct nfile)),
SHELL_ALIGN(sizeof (struct nfile)),
SHELL_ALIGN(sizeof (struct nfile)),
SHELL_ALIGN(sizeof (struct nfile)),
SHELL_ALIGN(sizeof (struct ndup)),
SHELL_ALIGN(sizeof (struct ndup)),
SHELL_ALIGN(sizeof (struct nhere)),
SHELL_ALIGN(sizeof (struct nhere)),
SHELL_ALIGN(sizeof (struct nnot)),
SHELL_ALIGN(sizeof(struct ncmd)),
SHELL_ALIGN(sizeof(struct npipe)),
SHELL_ALIGN(sizeof(struct nredir)),
SHELL_ALIGN(sizeof(struct nredir)),
SHELL_ALIGN(sizeof(struct nredir)),
SHELL_ALIGN(sizeof(struct nbinary)),
SHELL_ALIGN(sizeof(struct nbinary)),
SHELL_ALIGN(sizeof(struct nbinary)),
SHELL_ALIGN(sizeof(struct nif)),
SHELL_ALIGN(sizeof(struct nbinary)),
SHELL_ALIGN(sizeof(struct nbinary)),
SHELL_ALIGN(sizeof(struct nfor)),
SHELL_ALIGN(sizeof(struct ncase)),
SHELL_ALIGN(sizeof(struct nclist)),
SHELL_ALIGN(sizeof(struct narg)),
SHELL_ALIGN(sizeof(struct narg)),
SHELL_ALIGN(sizeof(struct nfile)),
SHELL_ALIGN(sizeof(struct nfile)),
SHELL_ALIGN(sizeof(struct nfile)),
SHELL_ALIGN(sizeof(struct nfile)),
SHELL_ALIGN(sizeof(struct nfile)),
SHELL_ALIGN(sizeof(struct ndup)),
SHELL_ALIGN(sizeof(struct ndup)),
SHELL_ALIGN(sizeof(struct nhere)),
SHELL_ALIGN(sizeof(struct nhere)),
SHELL_ALIGN(sizeof(struct nnot)),
};
@ -1402,8 +1402,7 @@ struct cmdentry {
static const char *pathopt; /* set by padvance */
static void shellexec(char **, const char *, int)
ATTRIBUTE_NORETURN;
static void shellexec(char **, const char *, int) ATTRIBUTE_NORETURN;
static char *padvance(const char **, const char *);
static void find_command(char *, struct cmdentry *, int, const char *);
static struct builtincmd *find_builtin(const char *);
@ -1701,8 +1700,8 @@ static void init(void)
p = lookupvar("PWD");
if (p)
if (*p != '/' || stat(p, &st1) || stat(".", &st2) ||
st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino)
if (*p != '/' || stat(p, &st1) || stat(".", &st2)
|| st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino)
p = 0;
setpwd(p, 0);
}
@ -2092,7 +2091,6 @@ reset(void)
{
clearredir(0);
}
}
#ifdef CONFIG_ASH_ALIAS
@ -2118,7 +2116,7 @@ setalias(const char *name, const char *val)
ap->flag &= ~ALIASDEAD;
} else {
/* not found */
ap = ckmalloc(sizeof (struct alias));
ap = ckmalloc(sizeof(struct alias));
ap->name = savestr(name);
ap->val = savestr(val);
ap->flag = 0;
@ -2534,8 +2532,7 @@ setpwd(const char *val, int setold)
static void exverror(int, const char *, va_list)
ATTRIBUTE_NORETURN;
static void exverror(int, const char *, va_list) ATTRIBUTE_NORETURN;
/*
* Called to raise an exception. Since C doesn't include exceptions, we
@ -2670,7 +2667,7 @@ sh_warnx(const char *fmt, ...)
static const char *
errmsg(int e, const char *em)
{
if(e == ENOENT || e == ENOTDIR) {
if (e == ENOENT || e == ENOTDIR) {
return em;
}
@ -3297,7 +3294,7 @@ evalcommand(union node *cmd, int flags)
argc++;
}
argv = nargv = stalloc(sizeof (char *) * (argc + 1));
argv = nargv = stalloc(sizeof(char *) * (argc + 1));
for (sp = arglist.list ; sp ; sp = sp->next) {
TRACE(("evalcommand arg: %s\n", sp->text));
*nargv++ = sp->text;
@ -3338,11 +3335,11 @@ evalcommand(union node *cmd, int flags)
dprintf(preverrout_fd, p, expandstr(ps4val()));
sp = varlist.list;
for(n = 0; n < 2; n++) {
for (n = 0; n < 2; n++) {
while (sp) {
dprintf(preverrout_fd, p, sp->text);
sp = sp->next;
if(*p == '%') {
if (*p == '%') {
p--;
}
}
@ -3563,10 +3560,8 @@ prehash(union node *n)
{
struct cmdentry entry;
if (n->type == NCMD && n->ncmd.args)
if (goodname(n->ncmd.args->narg.text))
find_command(n->ncmd.args->narg.text, &entry, 0,
pathval());
if (n->type == NCMD && n->ncmd.args && goodname(n->ncmd.args->narg.text))
find_command(n->ncmd.args->narg.text, &entry, 0, pathval());
}
@ -4211,7 +4206,8 @@ clearcmdentry(int firstchange)
if ((cmdp->cmdtype == CMDNORMAL &&
cmdp->param.index >= firstchange)
|| (cmdp->cmdtype == CMDBUILTIN &&
builtinloc >= firstchange)) {
builtinloc >= firstchange)
) {
*pp = cmdp->next;
ckfree(cmdp);
} else {
@ -4257,7 +4253,7 @@ cmdlookup(const char *name, int add)
pp = &cmdp->next;
}
if (add && cmdp == NULL) {
cmdp = *pp = ckmalloc(sizeof (struct tblentry) - ARB
cmdp = *pp = ckmalloc(sizeof(struct tblentry) - ARB
+ strlen(name) + 1);
cmdp->next = NULL;
cmdp->cmdtype = CMDUNKNOWN;
@ -4351,8 +4347,8 @@ unsetfunc(const char *name)
{
struct tblentry *cmdp;
if ((cmdp = cmdlookup(name, 0)) != NULL &&
cmdp->cmdtype == CMDFUNCTION)
cmdp = cmdlookup(name, 0);
if (cmdp!= NULL && cmdp->cmdtype == CMDFUNCTION)
delete_cmd_entry();
}
@ -4641,7 +4637,7 @@ expandarg(union node *arg, struct arglist *arglist, int flag)
} else {
if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */
rmescapes(p);
sp = (struct strlist *)stalloc(sizeof (struct strlist));
sp = (struct strlist *)stalloc(sizeof(struct strlist));
sp->text = p;
*exparg.lastp = sp;
exparg.lastp = &sp->next;
@ -4985,7 +4981,7 @@ expbackq(union node *cmd, int quoted, int quotes)
read:
if (in.fd < 0)
break;
i = safe_read(in.fd, buf, sizeof buf);
i = safe_read(in.fd, buf, sizeof(buf));
TRACE(("expbackq: read returns %d\n", i));
if (i <= 0)
break;
@ -5202,8 +5198,7 @@ vsplus:
if (subtype == VSASSIGN || subtype == VSQUESTION) {
if (varlen < 0) {
if (subevalvar(p, var, 0, subtype, startloc,
varflags, 0)) {
if (subevalvar(p, var, 0, subtype, startloc, varflags, 0)) {
varflags &= ~VSNUL;
/*
* Remove any recorded regions beyond
@ -5450,7 +5445,7 @@ recordregion(int start, int end, int nulonly)
ifsp = &ifsfirst;
} else {
INTOFF;
ifsp = (struct ifsregion *)ckmalloc(sizeof (struct ifsregion));
ifsp = (struct ifsregion *)ckmalloc(sizeof(struct ifsregion));
ifsp->next = NULL;
ifslastp->next = ifsp;
INTON;
@ -5505,7 +5500,7 @@ ifsbreakup(char *string, struct arglist *arglist)
continue;
}
*q = '\0';
sp = (struct strlist *)stalloc(sizeof *sp);
sp = (struct strlist *)stalloc(sizeof(*sp));
sp->text = start;
*arglist->lastp = sp;
arglist->lastp = &sp->next;
@ -5546,7 +5541,7 @@ ifsbreakup(char *string, struct arglist *arglist)
return;
add:
sp = (struct strlist *)stalloc(sizeof *sp);
sp = (struct strlist *)stalloc(sizeof(*sp));
sp->text = start;
*arglist->lastp = sp;
arglist->lastp = &sp->next;
@ -5636,7 +5631,7 @@ addfname(const char *name)
{
struct strlist *sp;
sp = (struct strlist *)stalloc(sizeof *sp);
sp = (struct strlist *)stalloc(sizeof(*sp));
sp->text = sstrdup(name);
*exparg.lastp = sp;
exparg.lastp = &sp->next;
@ -5743,8 +5738,7 @@ out:
scopy(dp->d_name, enddir);
addfname(expdir);
} else {
for (p = enddir, cp = dp->d_name;
(*p++ = *cp++) != '\0';)
for (p = enddir, cp = dp->d_name; (*p++ = *cp++) != '\0';)
continue;
p[-1] = '/';
expmeta(p, endname);
@ -6226,7 +6220,7 @@ pushstring(char *s, void *ap)
INTOFF;
/*dprintf("*** calling pushstring: %s, %d\n", s, len);*/
if (parsefile->strpush) {
sp = ckmalloc(sizeof (struct strpush));
sp = ckmalloc(sizeof(struct strpush));
sp->prev = parsefile->strpush;
parsefile->strpush = sp;
} else
@ -6357,7 +6351,7 @@ pushfile(void)
parsefile->lleft = parselleft;
parsefile->nextc = parsenextc;
parsefile->linno = plinno;
pf = (struct parsefile *)ckmalloc(sizeof (struct parsefile));
pf = (struct parsefile *)ckmalloc(sizeof(struct parsefile));
pf->prev = parsefile;
pf->fd = -1;
pf->strpush = NULL;
@ -7102,7 +7096,7 @@ makejob(union node *node, int nprocs)
jp->used = 1;
jp->ps = &jp->ps0;
if (nprocs > 1) {
jp->ps = ckmalloc(nprocs * sizeof (struct procstat));
jp->ps = ckmalloc(nprocs * sizeof(struct procstat));
}
TRACE(("makejob(0x%lx, %d) returns %%%d\n", (long)node, nprocs,
jobno(jp)));
@ -7397,7 +7391,9 @@ dowait(int block, struct job *job)
sp = jp->ps;
do {
if (sp->pid == pid) {
TRACE(("Job %d: changing status of proc %d from 0x%x to 0x%x\n", jobno(jp), pid, sp->status, status));
TRACE(("Job %d: changing status of proc %d "
"from 0x%x to 0x%x\n",
jobno(jp), pid, sp->status, status));
sp->status = status;
thisjob = jp;
}
@ -7427,7 +7423,8 @@ gotjob:
thisjob->changed = 1;
if (thisjob->state != state) {
TRACE(("Job %d: changing state from %d to %d\n", jobno(thisjob), thisjob->state, state));
TRACE(("Job %d: changing state from %d to %d\n",
jobno(thisjob), thisjob->state, state));
thisjob->state = state;
#if JOBS
if (state == JOBSTOPPED) {
@ -7913,7 +7910,7 @@ int ash_main(int argc, char **argv)
#endif
#if PROFILE
monitor(4, etext, profile_buf, sizeof profile_buf, 50);
monitor(4, etext, profile_buf, sizeof(profile_buf), 50);
#endif
#if ENABLE_FEATURE_EDITING
@ -7966,7 +7963,7 @@ int ash_main(int argc, char **argv)
if (hp == NULL) {
hp = lookupvar("HOME");
if(hp != NULL) {
if (hp != NULL) {
char *defhp = concat_path_file(hp, ".ash_history");
setvar("HISTFILE", defhp, 0);
free(defhp);
@ -8680,6 +8677,7 @@ copynode(union node *n)
return NULL;
new = funcblock;
funcblock = (char *) funcblock + nodesize[n->type];
switch (n->type) {
case NCMD:
new->ncmd.redirect = copynode(n->ncmd.redirect);
@ -8769,8 +8767,7 @@ copynodelist(struct nodelist *lp)
lpp = &start;
while (lp) {
*lpp = funcblock;
funcblock = (char *) funcblock +
SHELL_ALIGN(sizeof(struct nodelist));
funcblock = (char *) funcblock + SHELL_ALIGN(sizeof(struct nodelist));
(*lpp)->n = copynode(lp->n);
lp = lp->next;
lpp = &(*lpp)->next;
@ -8981,7 +8978,7 @@ setparam(char **argv)
int nparam;
for (nparam = 0 ; argv[nparam] ; nparam++);
ap = newparam = ckmalloc((nparam + 1) * sizeof *ap);
ap = newparam = ckmalloc((nparam + 1) * sizeof(*ap));
while (*argv) {
*ap++ = savestr(*argv++);
}
@ -9096,7 +9093,7 @@ static void change_lc_ctype(const char *value)
/* Roughly copied from bash.. */
static void change_random(const char *value)
{
if(value == NULL) {
if (value == NULL) {
/* "get", generate */
char buf[16];
@ -9124,7 +9121,7 @@ getopts(char *optstr, char *optvar, char **optfirst, int *param_optind, int *opt
char s[12];
char **optnext;
if(*param_optind < 1)
if (*param_optind < 1)
return 1;
optnext = optfirst + *param_optind - 1;
@ -9446,7 +9443,7 @@ list(int nlflag)
n1 = n2;
}
else {
n3 = (union node *)stalloc(sizeof (struct nbinary));
n3 = (union node *)stalloc(sizeof(struct nbinary));
n3->type = NSEMI;
n3->nbinary.ch1 = n1;
n3->nbinary.ch2 = n2;
@ -9504,7 +9501,7 @@ andor(void)
}
checkkwd = CHKNL | CHKKWD | CHKALIAS;
n2 = pipeline();
n3 = (union node *)stalloc(sizeof (struct nbinary));
n3 = (union node *)stalloc(sizeof(struct nbinary));
n3->type = t;
n3->nbinary.ch1 = n1;
n3->nbinary.ch2 = n2;
@ -9530,15 +9527,15 @@ pipeline(void)
tokpushback++;
n1 = command();
if (readtoken() == TPIPE) {
pipenode = (union node *)stalloc(sizeof (struct npipe));
pipenode = (union node *)stalloc(sizeof(struct npipe));
pipenode->type = NPIPE;
pipenode->npipe.backgnd = 0;
lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
lp = (struct nodelist *)stalloc(sizeof(struct nodelist));
pipenode->npipe.cmdlist = lp;
lp->n = n1;
do {
prev = lp;
lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
lp = (struct nodelist *)stalloc(sizeof(struct nodelist));
checkkwd = CHKNL | CHKKWD | CHKALIAS;
lp->n = command();
prev->next = lp;
@ -9548,7 +9545,7 @@ pipeline(void)
}
tokpushback++;
if (negate) {
n2 = (union node *)stalloc(sizeof (struct nnot));
n2 = (union node *)stalloc(sizeof(struct nnot));
n2->type = NNOT;
n2->nnot.com = n1;
return n2;
@ -9576,7 +9573,7 @@ command(void)
synexpect(-1);
/* NOTREACHED */
case TIF:
n1 = (union node *)stalloc(sizeof (struct nif));
n1 = (union node *)stalloc(sizeof(struct nif));
n1->type = NIF;
n1->nif.test = list(0);
if (readtoken() != TTHEN)
@ -9584,7 +9581,7 @@ command(void)
n1->nif.ifpart = list(0);
n2 = n1;
while (readtoken() == TELIF) {
n2->nif.elsepart = (union node *)stalloc(sizeof (struct nif));
n2->nif.elsepart = (union node *)stalloc(sizeof(struct nif));
n2 = n2->nif.elsepart;
n2->type = NIF;
n2->nif.test = list(0);
@ -9603,7 +9600,7 @@ command(void)
case TWHILE:
case TUNTIL: {
int got;
n1 = (union node *)stalloc(sizeof (struct nbinary));
n1 = (union node *)stalloc(sizeof(struct nbinary));
n1->type = (lasttoken == TWHILE)? NWHILE : NUNTIL;
n1->nbinary.ch1 = list(0);
if ((got=readtoken()) != TDO) {
@ -9617,14 +9614,14 @@ TRACE(("expecting DO got %s %s\n", tokname(got), got == TWORD ? wordtext : ""));
case TFOR:
if (readtoken() != TWORD || quoteflag || ! goodname(wordtext))
synerror("Bad for loop variable");
n1 = (union node *)stalloc(sizeof (struct nfor));
n1 = (union node *)stalloc(sizeof(struct nfor));
n1->type = NFOR;
n1->nfor.var = wordtext;
checkkwd = CHKKWD | CHKALIAS;
if (readtoken() == TIN) {
app = &ap;
while (readtoken() == TWORD) {
n2 = (union node *)stalloc(sizeof (struct narg));
n2 = (union node *)stalloc(sizeof(struct narg));
n2->type = NARG;
n2->narg.text = wordtext;
n2->narg.backquote = backquotelist;
@ -9636,7 +9633,7 @@ TRACE(("expecting DO got %s %s\n", tokname(got), got == TWORD ? wordtext : ""));
if (lasttoken != TNL && lasttoken != TSEMI)
synexpect(-1);
} else {
n2 = (union node *)stalloc(sizeof (struct narg));
n2 = (union node *)stalloc(sizeof(struct narg));
n2->type = NARG;
n2->narg.text = (char *)dolatstr;
n2->narg.backquote = NULL;
@ -9656,11 +9653,11 @@ TRACE(("expecting DO got %s %s\n", tokname(got), got == TWORD ? wordtext : ""));
t = TDONE;
break;
case TCASE:
n1 = (union node *)stalloc(sizeof (struct ncase));
n1 = (union node *)stalloc(sizeof(struct ncase));
n1->type = NCASE;
if (readtoken() != TWORD)
synexpect(TWORD);
n1->ncase.expr = n2 = (union node *)stalloc(sizeof (struct narg));
n1->ncase.expr = n2 = (union node *)stalloc(sizeof(struct narg));
n2->type = NARG;
n2->narg.text = wordtext;
n2->narg.backquote = backquotelist;
@ -9674,14 +9671,14 @@ TRACE(("expecting DO got %s %s\n", tokname(got), got == TWORD ? wordtext : ""));
next_case:
checkkwd = CHKNL | CHKKWD;
t = readtoken();
while(t != TESAC) {
while (t != TESAC) {
if (lasttoken == TLP)
readtoken();
*cpp = cp = (union node *)stalloc(sizeof (struct nclist));
*cpp = cp = (union node *)stalloc(sizeof(struct nclist));
cp->type = NCLIST;
app = &cp->nclist.pattern;
for (;;) {
*app = ap = (union node *)stalloc(sizeof (struct narg));
*app = ap = (union node *)stalloc(sizeof(struct narg));
ap->type = NARG;
ap->narg.text = wordtext;
ap->narg.backquote = backquotelist;
@ -9708,7 +9705,7 @@ next_case:
*cpp = NULL;
goto redir;
case TLP:
n1 = (union node *)stalloc(sizeof (struct nredir));
n1 = (union node *)stalloc(sizeof(struct nredir));
n1->type = NSUBSHELL;
n1->nredir.n = list(0);
n1->nredir.redirect = NULL;
@ -9740,7 +9737,7 @@ redir:
*rpp = NULL;
if (redir) {
if (n1->type != NSUBSHELL) {
n2 = (union node *)stalloc(sizeof (struct nredir));
n2 = (union node *)stalloc(sizeof(struct nredir));
n2->type = NREDIR;
n2->nredir.n = n1;
n1 = n2;
@ -9772,7 +9769,7 @@ simplecmd(void) {
checkkwd = savecheckkwd;
switch (readtoken()) {
case TWORD:
n = (union node *)stalloc(sizeof (struct narg));
n = (union node *)stalloc(sizeof(struct narg));
n->type = NARG;
n->narg.text = wordtext;
n->narg.backquote = backquotelist;
@ -9824,7 +9821,7 @@ out:
*app = NULL;
*vpp = NULL;
*rpp = NULL;
n = (union node *)stalloc(sizeof (struct ncmd));
n = (union node *)stalloc(sizeof(struct ncmd));
n->type = NCMD;
n->ncmd.args = args;
n->ncmd.assign = vars;
@ -9837,7 +9834,7 @@ makename(void)
{
union node *n;
n = (union node *)stalloc(sizeof (struct narg));
n = (union node *)stalloc(sizeof(struct narg));
n->type = NARG;
n->narg.next = NULL;
n->narg.text = wordtext;
@ -9918,7 +9915,7 @@ parseheredoc(void)
}
readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX,
here->eofmark, here->striptabs);
n = (union node *)stalloc(sizeof (struct narg));
n = (union node *)stalloc(sizeof(struct narg));
n->narg.type = NARG;
n->narg.next = NULL;
n->narg.text = wordtext;
@ -10283,7 +10280,7 @@ readtoken1(int firstc, int syntax, char *eofmark, int striptabs)
break;
case CSQUOTE:
syntax = SQSYNTAX;
quotemark:
quotemark:
if (eofmark == NULL) {
USTPUTC(CTLQUOTEMARK, out);
}
@ -10293,8 +10290,9 @@ quotemark:
dblquote = 1;
goto quotemark;
case CENDQUOTE:
if (eofmark != NULL && arinest == 0 &&
varnest == 0) {
if (eofmark != NULL && arinest == 0
&& varnest == 0
) {
USTPUTC(c, out);
} else {
if (dqvarnest == 0) {
@ -10369,7 +10367,7 @@ quotemark:
c = pgetc_macro();
}
}
endword:
endword:
#ifdef CONFIG_ASH_MATH_SUPPORT
if (syntax == ARISYNTAX)
synerror("Missing '))'");
@ -10399,7 +10397,8 @@ endword:
backquotelist = bqlist;
grabstackblock(len);
wordtext = out;
return lasttoken = TWORD;
lasttoken = TWORD;
return lasttoken;
/* end of readtoken routine */
@ -10423,7 +10422,7 @@ checkend: {
}
}
if (c == *eofmark) {
if (pfgets(line, sizeof line) != NULL) {
if (pfgets(line, sizeof(line)) != NULL) {
char *p, *q;
p = line;
@ -10452,7 +10451,7 @@ parseredir: {
char fd = *out;
union node *np;
np = (union node *)stalloc(sizeof (struct nfile));
np = (union node *)stalloc(sizeof(struct nfile));
if (c == '>') {
np->nfile.fd = 1;
c = pgetc();
@ -10470,12 +10469,12 @@ parseredir: {
np->nfile.fd = 0;
switch (c = pgetc()) {
case '<':
if (sizeof (struct nfile) != sizeof (struct nhere)) {
np = (union node *)stalloc(sizeof (struct nhere));
if (sizeof(struct nfile) != sizeof(struct nhere)) {
np = (union node *)stalloc(sizeof(struct nhere));
np->nfile.fd = 0;
}
np->type = NHERE;
heredoc = (struct heredoc *)stalloc(sizeof (struct heredoc));
heredoc = (struct heredoc *)stalloc(sizeof(struct heredoc));
heredoc->here = np;
if ((c = pgetc()) == '-') {
heredoc->striptabs = 1;
@ -10562,13 +10561,11 @@ parsesub: {
STPUTC(c, out);
c = pgetc();
} while (is_digit(c));
}
else if (is_special(c)) {
} else if (is_special(c)) {
USTPUTC(c, out);
c = pgetc();
}
else
badsub: synerror("Bad substitution");
} else
badsub: synerror("Bad substitution");
STPUTC('=', out);
flags = 0;
@ -10721,7 +10718,7 @@ done:
nlpp = &bqlist;
while (*nlpp)
nlpp = &(*nlpp)->next;
*nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist));
*nlpp = (struct nodelist *)stalloc(sizeof(struct nodelist));
(*nlpp)->next = NULL;
parsebackquote = oldstyle;
@ -10776,7 +10773,6 @@ done:
* Parse an arithmetic expansion (indicate start of one and set state)
*/
parsearith: {
if (++arinest == 1) {
prevsyntax = syntax;
syntax = ARISYNTAX;
@ -10835,10 +10831,10 @@ endofname(const char *name)
char *p;
p = (char *) name;
if (! is_name(*p))
if (!is_name(*p))
return p;
while (*++p) {
if (! is_in_name(*p))
if (!is_in_name(*p))
break;
}
return p;
@ -10994,8 +10990,8 @@ static int noclobberopen(const char *fname)
* revealed that it was a regular file, and the file has not been
* replaced, return the file descriptor.
*/
if (fstat(fd, &finfo2) == 0 && !S_ISREG(finfo2.st_mode) &&
finfo.st_dev == finfo2.st_dev && finfo.st_ino == finfo2.st_ino)
if (fstat(fd, &finfo2) == 0 && !S_ISREG(finfo2.st_mode)
&& finfo.st_dev == finfo2.st_dev && finfo.st_ino == finfo2.st_ino)
return fd;
/* The file has been replaced. badness. */
@ -11145,7 +11141,7 @@ redirect(union node *redir, int flags)
INTOFF;
if (flags & REDIR_PUSH) {
struct redirtab *q;
q = ckmalloc(sizeof (struct redirtab));
q = ckmalloc(sizeof(struct redirtab));
q->next = redirlist;
redirlist = q;
q->nullredirs = nullredirs - 1;
@ -11157,8 +11153,8 @@ redirect(union node *redir, int flags)
n = redir;
do {
fd = n->nfile.fd;
if ((n->nfile.type == NTOFD || n->nfile.type == NFROMFD) &&
n->ndup.dupfd == fd)
if ((n->nfile.type == NTOFD || n->nfile.type == NFROMFD)
&& n->ndup.dupfd == fd)
continue; /* redirect from/to same file descriptor */
newfd = openredirect(n);
@ -11776,8 +11772,9 @@ setsignal(int signo)
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
tsig = S_HARD_IGN;
@ -11887,11 +11884,11 @@ setinteractive(int on)
setsignal(SIGQUIT);
setsignal(SIGTERM);
#if !ENABLE_FEATURE_SH_EXTRA_QUIET
if(is_interactive > 1) {
if (is_interactive > 1) {
/* Looks like they want an interactive shell */
static int do_banner;
if(!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",
@ -12083,7 +12080,7 @@ setvareq(char *s, int flags)
if (flags & VNOSET)
return;
/* not found */
vp = ckmalloc(sizeof (*vp));
vp = ckmalloc(sizeof(*vp));
vp->next = *vpp;
vp->func = NULL;
*vpp = vp;
@ -12131,10 +12128,10 @@ lookupvar(const char *name)
* As soon as they're unset, they're no longer dynamic, and dynamic
* lookup will no longer happen at that point. -- PFM.
*/
if((v->flags & VDYNAMIC))
if ((v->flags & VDYNAMIC))
(*v->func)(NULL);
#endif
if(!(v->flags & VUNSET))
if (!(v->flags & VUNSET))
return strchrnul(v->text, '=') + 1;
}
@ -12275,7 +12272,7 @@ static void mklocal(char *name)
struct var *vp;
INTOFF;
lvp = ckmalloc(sizeof (struct localvar));
lvp = ckmalloc(sizeof(struct localvar));
if (LONE_DASH(name)) {
char *p;
p = ckmalloc(sizeof(optlist));
@ -12568,7 +12565,7 @@ letcmd(int argc, char **argv)
arith_t i = 0;
ap = argv + 1;
if(!*ap)
if (!*ap)
sh_error("expression expected");
for (ap = argv + 1; *ap; ap++) {
i = dash_arith(*ap);
@ -12993,8 +12990,7 @@ ulimitcmd(int argc, char **argv)
else {
val = (rlim_t) 0;
while ((c = *p++) >= '0' && c <= '9')
{
while ((c = *p++) >= '0' && c <= '9') {
val = (val * 10) + (long)(c - '0');
if (val < (rlim_t) 0)
break;
@ -13158,7 +13154,7 @@ typedef unsigned char operator;
#define TOK_REM_ASSIGN tok_decl(3,2)
/* all assign is right associativity and precedence eq, but (7+3)<<5 > 256 */
#define convert_prec_is_assing(prec) do { if(prec == 3) prec = 2; } while(0)
#define convert_prec_is_assing(prec) do { if (prec == 3) prec = 2; } while (0)
/* conditional is right associativity too */
#define TOK_CONDITIONAL tok_decl(4,0)
@ -13231,8 +13227,8 @@ static int tok_have_assign(operator op)
static int is_right_associativity(operator prec)
{
return (prec == PREC(TOK_ASSIGN) || prec == PREC(TOK_EXPONENT) ||
prec == PREC(TOK_CONDITIONAL));
return (prec == PREC(TOK_ASSIGN) || prec == PREC(TOK_EXPONENT)
|| prec == PREC(TOK_CONDITIONAL));
}
@ -13255,18 +13251,18 @@ static chk_var_recursive_looped_t *prev_chk_var_recursive;
static int arith_lookup_val(v_n_t *t)
{
if(t->var) {
if (t->var) {
const char * p = lookupvar(t->var);
if(p) {
if (p) {
int errcode;
/* recursive try as expression */
chk_var_recursive_looped_t *cur;
chk_var_recursive_looped_t cur_save;
for(cur = prev_chk_var_recursive; cur; cur = cur->next) {
if(strcmp(cur->var, t->var) == 0) {
for (cur = prev_chk_var_recursive; cur; cur = cur->next) {
if (strcmp(cur->var, t->var) == 0) {
/* expression recursion loop detected */
return -5;
}
@ -13281,11 +13277,10 @@ static int arith_lookup_val(v_n_t *t)
/* restore previous ptr after recursiving */
prev_chk_var_recursive = cur;
return errcode;
} else {
}
/* allow undefined var as 0 */
t->val = 0;
}
}
return 0;
}
@ -13298,13 +13293,13 @@ static int arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr)
arith_t numptr_val, rez;
int ret_arith_lookup_val;
if (NUMPTR == numstack) goto err; /* There is no operator that can work
without arguments */
/* There is no operator that can work without arguments */
if (NUMPTR == numstack) goto err;
numptr_m1 = NUMPTR - 1;
/* check operand is var with noninteger value */
ret_arith_lookup_val = arith_lookup_val(numptr_m1);
if(ret_arith_lookup_val)
if (ret_arith_lookup_val)
return ret_arith_lookup_val;
rez = numptr_m1->val;
@ -13328,20 +13323,20 @@ static int arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr)
--NUMPTR;
numptr_val = rez;
if (op == TOK_CONDITIONAL) {
if(! numptr_m1->contidional_second_val_initialized) {
if (! numptr_m1->contidional_second_val_initialized) {
/* protect $((expr1 ? expr2)) without ": expr" */
goto err;
}
rez = numptr_m1->contidional_second_val;
} else if(numptr_m1->contidional_second_val_initialized) {
} else if (numptr_m1->contidional_second_val_initialized) {
/* protect $((expr1 : expr2)) without "expr ? " */
goto err;
}
numptr_m1 = NUMPTR - 1;
if(op != TOK_ASSIGN) {
if (op != TOK_ASSIGN) {
/* check operand is var with noninteger value for not '=' */
ret_arith_lookup_val = arith_lookup_val(numptr_m1);
if(ret_arith_lookup_val)
if (ret_arith_lookup_val)
return ret_arith_lookup_val;
}
if (op == TOK_CONDITIONAL) {
@ -13394,29 +13389,29 @@ static int arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr)
rez = rez ?
numptr_val : numptr_m1->contidional_second_val;
}
else if(op == TOK_EXPONENT) {
if(numptr_val < 0)
else if (op == TOK_EXPONENT) {
if (numptr_val < 0)
return -3; /* exponent less than 0 */
else {
arith_t c = 1;
if(numptr_val)
while(numptr_val--)
if (numptr_val)
while (numptr_val--)
c *= rez;
rez = c;
}
}
else if(numptr_val==0) /* zero divisor check */
else if (numptr_val==0) /* zero divisor check */
return -2;
else if (op == TOK_DIV || op == TOK_DIV_ASSIGN)
rez /= numptr_val;
else if (op == TOK_REM || op == TOK_REM_ASSIGN)
rez %= numptr_val;
}
if(tok_have_assign(op)) {
if (tok_have_assign(op)) {
char buf[32];
if(numptr_m1->var == NULL) {
if (numptr_m1->var == NULL) {
/* Hmm, 1=2 ? */
goto err;
}
@ -13428,9 +13423,9 @@ static int arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr)
#endif
setvar(numptr_m1->var, buf, 0);
/* after saving, make previous value for v++ or v-- */
if(op == TOK_POST_INC)
if (op == TOK_POST_INC)
rez--;
else if(op == TOK_POST_DEC)
else if (op == TOK_POST_DEC)
rez++;
}
numptr_m1->val = rez;
@ -13513,7 +13508,7 @@ static arith_t arith(const char *expr, int *perrcode)
*stackptr++ = lasttok = TOK_LPAREN; /* start off with a left paren */
*perrcode = errcode = 0;
while(1) {
while (1) {
if ((arithval = *expr) == 0) {
if (p == endexpression) {
/* Null expression. */
@ -13538,20 +13533,21 @@ static arith_t arith(const char *expr, int *perrcode)
err:
return (*perrcode = -1);
}
if(numstack->var) {
if (numstack->var) {
/* expression is $((var)) only, lookup now */
errcode = arith_lookup_val(numstack);
}
ret:
*perrcode = errcode;
return numstack->val;
} else {
}
/* Continue processing the expression. */
if (arith_isspace(arithval)) {
/* Skip whitespace */
goto prologue;
}
if((p = endofname(expr)) != expr) {
if ((p = endofname(expr)) != expr) {
size_t var_name_size = (p-expr) + 1; /* trailing zero */
numstackptr->var = alloca(var_name_size);
@ -13571,22 +13567,22 @@ static arith_t arith(const char *expr, int *perrcode)
#endif
goto num;
}
for(p = op_tokens; ; p++) {
for (p = op_tokens; ; p++) {
const char *o;
if(*p == 0) {
if (*p == 0) {
/* strange operator not found */
goto err;
}
for(o = expr; *p && *o == *p; p++)
for (o = expr; *p && *o == *p; p++)
o++;
if(! *p) {
if (! *p) {
/* found */
expr = o - 1;
break;
}
/* skip tail uncompared token */
while(*p)
while (*p)
p++;
/* skip zero delim */
p++;
@ -13594,7 +13590,7 @@ static arith_t arith(const char *expr, int *perrcode)
op = p[1];
/* post grammar: a++ reduce to num */
if(lasttok == TOK_POST_INC || lasttok == TOK_POST_DEC)
if (lasttok == TOK_POST_INC || lasttok == TOK_POST_DEC)
lasttok = TOK_NUM;
/* Plus and minus are binary (not unary) _only_ if the last
@ -13655,11 +13651,11 @@ static arith_t arith(const char *expr, int *perrcode)
if (prev_prec < prec)
break;
/* check right assoc */
if(prev_prec == prec && is_right_associativity(prec))
if (prev_prec == prec && is_right_associativity(prec))
break;
}
errcode = arith_apply(*--stackptr, numstack, &numstackptr);
if(errcode) goto ret;
if (errcode) goto ret;
}
if (op == TOK_RPAREN) {
goto err;
@ -13668,11 +13664,9 @@ static arith_t arith(const char *expr, int *perrcode)
/* Push this operator to the stack and remember it. */
*stackptr++ = lasttok = op;
prologue:
++expr;
}
}
} /* while */
}
#endif /* CONFIG_ASH_MATH_SUPPORT */