Date: Wed, 15 Oct 2014 21:20:57 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273152 - head/bin/sh Message-ID: <201410152120.s9FLKv8P071066@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Wed Oct 15 21:20:56 2014 New Revision: 273152 URL: https://svnweb.freebsd.org/changeset/base/273152 Log: sh: Remove more gotos. Modified: head/bin/sh/expand.c head/bin/sh/jobs.c head/bin/sh/parser.c Modified: head/bin/sh/expand.c ============================================================================== --- head/bin/sh/expand.c Wed Oct 15 20:28:31 2014 (r273151) +++ head/bin/sh/expand.c Wed Oct 15 21:20:56 2014 (r273152) @@ -884,24 +884,22 @@ varvalue(const char *name, int quoted, i 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 @@ numvar: if (*ap) STPUTC('\0', expdest); } - break; + return; } /* FALLTHROUGH */ case '*': @@ -924,7 +922,7 @@ numvar: 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 @@ numvar: 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 /* 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; Modified: head/bin/sh/jobs.c ============================================================================== --- head/bin/sh/jobs.c Wed Oct 15 20:28:31 2014 (r273151) +++ head/bin/sh/jobs.c Wed Oct 15 21:20:56 2014 (r273152) @@ -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) @@ -1288,13 +1288,43 @@ 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 @@ until: 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: Modified: head/bin/sh/parser.c ============================================================================== --- head/bin/sh/parser.c Wed Oct 15 20:28:31 2014 (r273151) +++ head/bin/sh/parser.c Wed Oct 15 21:20:56 2014 (r273152) @@ -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 ** 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 ** } USTPUTC(c, oout); } -done: USTPUTC('\0', oout); olen = oout - stackblock(); INTOFF;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410152120.s9FLKv8P071066>