mirror of
https://git.FreeBSD.org/src.git
synced 2024-10-19 02:29:40 +00:00
sh: Remove more gotos.
This commit is contained in:
parent
711b48fe17
commit
622fdf3236
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=273152
@ -884,24 +884,22 @@ varvalue(const char *name, int quoted, int subtype, int flag)
|
||||
switch (*name) {
|
||||
case '$':
|
||||
num = rootpid;
|
||||
goto numvar;
|
||||
break;
|
||||
case '?':
|
||||
num = oexitstatus;
|
||||
goto numvar;
|
||||
break;
|
||||
case '#':
|
||||
num = shellparam.nparam;
|
||||
goto numvar;
|
||||
break;
|
||||
case '!':
|
||||
num = backgndpidval();
|
||||
numvar:
|
||||
expdest = cvtnum(num, expdest);
|
||||
break;
|
||||
case '-':
|
||||
for (i = 0 ; i < NOPTS ; i++) {
|
||||
if (optlist[i].val)
|
||||
STPUTC(optlist[i].letter, expdest);
|
||||
}
|
||||
break;
|
||||
return;
|
||||
case '@':
|
||||
if (flag & EXP_FULL && quoted) {
|
||||
for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
|
||||
@ -909,7 +907,7 @@ varvalue(const char *name, int quoted, int subtype, int flag)
|
||||
if (*ap)
|
||||
STPUTC('\0', expdest);
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
case '*':
|
||||
@ -924,7 +922,7 @@ varvalue(const char *name, int quoted, int subtype, int flag)
|
||||
if (sep || (flag & EXP_FULL && !quoted && **ap != '\0'))
|
||||
STPUTC(sep, expdest);
|
||||
}
|
||||
break;
|
||||
return;
|
||||
default:
|
||||
if (is_digit(*name)) {
|
||||
num = atoi(name);
|
||||
@ -933,11 +931,12 @@ varvalue(const char *name, int quoted, int subtype, int flag)
|
||||
else if (num > 0 && num <= shellparam.nparam)
|
||||
p = shellparam.p[num - 1];
|
||||
else
|
||||
break;
|
||||
return;
|
||||
strtodest(p, flag, subtype, quoted);
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
expdest = cvtnum(num, expdest);
|
||||
}
|
||||
|
||||
|
||||
@ -1105,24 +1104,23 @@ expandmeta(struct strlist *str, int flag __unused)
|
||||
/* TODO - EXP_REDIR */
|
||||
|
||||
while (str) {
|
||||
if (fflag)
|
||||
goto nometa;
|
||||
p = str->text;
|
||||
for (;;) { /* fast check for meta chars */
|
||||
if ((c = *p++) == '\0')
|
||||
goto nometa;
|
||||
if (c == '*' || c == '?' || c == '[')
|
||||
break;
|
||||
}
|
||||
savelastp = exparg.lastp;
|
||||
INTOFF;
|
||||
expmeta(expdir, str->text);
|
||||
INTON;
|
||||
if (!fflag) {
|
||||
p = str->text;
|
||||
for (; (c = *p) != '\0'; p++) {
|
||||
/* fast check for meta chars */
|
||||
if (c == '*' || c == '?' || c == '[') {
|
||||
INTOFF;
|
||||
expmeta(expdir, str->text);
|
||||
INTON;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (exparg.lastp == savelastp) {
|
||||
/*
|
||||
* no matches
|
||||
*/
|
||||
nometa:
|
||||
*exparg.lastp = str;
|
||||
rmescapes(str->text);
|
||||
exparg.lastp = &str->next;
|
||||
|
@ -592,23 +592,23 @@ getjob_nonotfound(const char *name)
|
||||
|
||||
if (name == NULL) {
|
||||
#if JOBS
|
||||
currentjob: if ((jp = getcurjob(NULL)) == NULL)
|
||||
error("No current job");
|
||||
return (jp);
|
||||
name = "%+";
|
||||
#else
|
||||
error("No current job");
|
||||
#endif
|
||||
} else if (name[0] == '%') {
|
||||
}
|
||||
if (name[0] == '%') {
|
||||
if (is_digit(name[1])) {
|
||||
jobno = number(name + 1);
|
||||
if (jobno > 0 && jobno <= njobs
|
||||
&& jobtab[jobno - 1].used != 0)
|
||||
return &jobtab[jobno - 1];
|
||||
#if JOBS
|
||||
} else if (name[1] == '%' && name[2] == '\0') {
|
||||
goto currentjob;
|
||||
} else if (name[1] == '+' && name[2] == '\0') {
|
||||
goto currentjob;
|
||||
} else if ((name[1] == '%' || name[1] == '+') &&
|
||||
name[2] == '\0') {
|
||||
if ((jp = getcurjob(NULL)) == NULL)
|
||||
error("No current job");
|
||||
return (jp);
|
||||
} else if (name[1] == '-' && name[2] == '\0') {
|
||||
if ((jp = getcurjob(NULL)) == NULL ||
|
||||
(jp = getcurjob(jp)) == NULL)
|
||||
@ -1287,14 +1287,44 @@ commandtext(union node *n)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cmdtxtdogroup(union node *n)
|
||||
{
|
||||
cmdputs("; do ");
|
||||
cmdtxt(n);
|
||||
cmdputs("; done");
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cmdtxtredir(union node *n, const char *op, int deffd)
|
||||
{
|
||||
char s[2];
|
||||
|
||||
if (n->nfile.fd != deffd) {
|
||||
s[0] = n->nfile.fd + '0';
|
||||
s[1] = '\0';
|
||||
cmdputs(s);
|
||||
}
|
||||
cmdputs(op);
|
||||
if (n->type == NTOFD || n->type == NFROMFD) {
|
||||
if (n->ndup.dupfd >= 0)
|
||||
s[0] = n->ndup.dupfd + '0';
|
||||
else
|
||||
s[0] = '-';
|
||||
s[1] = '\0';
|
||||
cmdputs(s);
|
||||
} else {
|
||||
cmdtxt(n->nfile.fname);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cmdtxt(union node *n)
|
||||
{
|
||||
union node *np;
|
||||
struct nodelist *lp;
|
||||
const char *p;
|
||||
int i;
|
||||
char s[2];
|
||||
|
||||
if (n == NULL)
|
||||
return;
|
||||
@ -1339,14 +1369,13 @@ cmdtxt(union node *n)
|
||||
break;
|
||||
case NWHILE:
|
||||
cmdputs("while ");
|
||||
goto until;
|
||||
cmdtxt(n->nbinary.ch1);
|
||||
cmdtxtdogroup(n->nbinary.ch2);
|
||||
break;
|
||||
case NUNTIL:
|
||||
cmdputs("until ");
|
||||
until:
|
||||
cmdtxt(n->nbinary.ch1);
|
||||
cmdputs("; do ");
|
||||
cmdtxt(n->nbinary.ch2);
|
||||
cmdputs("; done");
|
||||
cmdtxtdogroup(n->nbinary.ch2);
|
||||
break;
|
||||
case NFOR:
|
||||
cmdputs("for ");
|
||||
@ -1381,36 +1410,25 @@ cmdtxt(union node *n)
|
||||
cmdputs(n->narg.text);
|
||||
break;
|
||||
case NTO:
|
||||
p = ">"; i = 1; goto redir;
|
||||
cmdtxtredir(n, ">", 1);
|
||||
break;
|
||||
case NAPPEND:
|
||||
p = ">>"; i = 1; goto redir;
|
||||
cmdtxtredir(n, ">>", 1);
|
||||
break;
|
||||
case NTOFD:
|
||||
p = ">&"; i = 1; goto redir;
|
||||
cmdtxtredir(n, ">&", 1);
|
||||
break;
|
||||
case NCLOBBER:
|
||||
p = ">|"; i = 1; goto redir;
|
||||
cmdtxtredir(n, ">|", 1);
|
||||
break;
|
||||
case NFROM:
|
||||
p = "<"; i = 0; goto redir;
|
||||
cmdtxtredir(n, "<", 0);
|
||||
break;
|
||||
case NFROMTO:
|
||||
p = "<>"; i = 0; goto redir;
|
||||
cmdtxtredir(n, "<>", 0);
|
||||
break;
|
||||
case NFROMFD:
|
||||
p = "<&"; i = 0; goto redir;
|
||||
redir:
|
||||
if (n->nfile.fd != i) {
|
||||
s[0] = n->nfile.fd + '0';
|
||||
s[1] = '\0';
|
||||
cmdputs(s);
|
||||
}
|
||||
cmdputs(p);
|
||||
if (n->type == NTOFD || n->type == NFROMFD) {
|
||||
if (n->ndup.dupfd >= 0)
|
||||
s[0] = n->ndup.dupfd + '0';
|
||||
else
|
||||
s[0] = '-';
|
||||
s[1] = '\0';
|
||||
cmdputs(s);
|
||||
} else {
|
||||
cmdtxt(n->nfile.fname);
|
||||
}
|
||||
cmdtxtredir(n, "<&", 0);
|
||||
break;
|
||||
case NHERE:
|
||||
case NXHERE:
|
||||
|
@ -889,7 +889,9 @@ xxreadtoken(void)
|
||||
continue;
|
||||
}
|
||||
pungetc();
|
||||
goto breakloop;
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
|
||||
case '\n':
|
||||
plinno++;
|
||||
needprompt = doprompt;
|
||||
@ -918,12 +920,8 @@ xxreadtoken(void)
|
||||
RETURN(TLP);
|
||||
case ')':
|
||||
RETURN(TRP);
|
||||
default:
|
||||
goto breakloop;
|
||||
}
|
||||
}
|
||||
breakloop:
|
||||
return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
|
||||
#undef RETURN
|
||||
}
|
||||
|
||||
@ -1039,10 +1037,10 @@ parsebackq(char *out, struct nodelist **pbqlist,
|
||||
needprompt = 0;
|
||||
}
|
||||
CHECKSTRSPACE(2, oout);
|
||||
switch (c = pgetc()) {
|
||||
case '`':
|
||||
goto done;
|
||||
|
||||
c = pgetc();
|
||||
if (c == '`')
|
||||
break;
|
||||
switch (c) {
|
||||
case '\\':
|
||||
if ((c = pgetc()) == '\n') {
|
||||
plinno++;
|
||||
@ -1078,7 +1076,6 @@ parsebackq(char *out, struct nodelist **pbqlist,
|
||||
}
|
||||
USTPUTC(c, oout);
|
||||
}
|
||||
done:
|
||||
USTPUTC('\0', oout);
|
||||
olen = oout - stackblock();
|
||||
INTOFF;
|
||||
|
Loading…
Reference in New Issue
Block a user