summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2014-10-15 21:26:09 +0000
committerjilles <jilles@FreeBSD.org>2014-10-15 21:26:09 +0000
commit885ad60537698e3e279cf05fb6a77820ec5a0d34 (patch)
tree0c9f8c1a3705bea6f78a240027fe81de81bf7d17 /bin
parentcaaf5f0082866f41290fbcf8a5ae448bc7d71b37 (diff)
downloadFreeBSD-src-885ad60537698e3e279cf05fb6a77820ec5a0d34.zip
FreeBSD-src-885ad60537698e3e279cf05fb6a77820ec5a0d34.tar.gz
sh: Make parseredir() a proper function instead of an emulated nested
function.
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/parser.c117
1 files changed, 58 insertions, 59 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index 5e4c773..a8ecf03 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -977,6 +977,63 @@ checkend(int c, const char *eofmark, int striptabs)
/*
+ * Parse a redirection operator. The variable "out" points to a string
+ * specifying the fd to be redirected. The variable "c" contains the
+ * first character of the redirection operator.
+ */
+
+static void
+parseredir(char *out, int c)
+{
+ char fd = *out;
+ union node *np;
+
+ np = (union node *)stalloc(sizeof (struct nfile));
+ if (c == '>') {
+ np->nfile.fd = 1;
+ c = pgetc();
+ if (c == '>')
+ np->type = NAPPEND;
+ else if (c == '&')
+ np->type = NTOFD;
+ else if (c == '|')
+ np->type = NCLOBBER;
+ else {
+ np->type = NTO;
+ pungetc();
+ }
+ } else { /* c == '<' */
+ np->nfile.fd = 0;
+ c = pgetc();
+ if (c == '<') {
+ 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->here = np;
+ if ((c = pgetc()) == '-') {
+ heredoc->striptabs = 1;
+ } else {
+ heredoc->striptabs = 0;
+ pungetc();
+ }
+ } else if (c == '&')
+ np->type = NFROMFD;
+ else if (c == '>')
+ np->type = NFROMTO;
+ else {
+ np->type = NFROM;
+ pungetc();
+ }
+ }
+ if (fd != '\0')
+ np->nfile.fd = digit_val(fd);
+ redirnode = np;
+}
+
+/*
* Called to parse command substitutions.
*/
@@ -1306,7 +1363,6 @@ readcstyleesc(char *out)
* will run code that appears at the end of readtoken1.
*/
-#define PARSEREDIR() {goto parseredir; parseredir_return:;}
#define PARSESUB() {goto parsesub; parsesub_return:;}
#define PARSEARITH() {goto parsearith; parsearith_return:;}
@@ -1506,7 +1562,7 @@ endword:
&& quotef == 0
&& len <= 2
&& (*out == '\0' || is_digit(*out))) {
- PARSEREDIR();
+ parseredir(out, c);
return lasttoken = TREDIR;
} else {
pungetc();
@@ -1521,63 +1577,6 @@ endword:
/*
- * Parse a redirection operator. The variable "out" points to a string
- * specifying the fd to be redirected. The variable "c" contains the
- * first character of the redirection operator.
- */
-
-parseredir: {
- char fd = *out;
- union node *np;
-
- np = (union node *)stalloc(sizeof (struct nfile));
- if (c == '>') {
- np->nfile.fd = 1;
- c = pgetc();
- if (c == '>')
- np->type = NAPPEND;
- else if (c == '&')
- np->type = NTOFD;
- else if (c == '|')
- np->type = NCLOBBER;
- else {
- np->type = NTO;
- pungetc();
- }
- } else { /* c == '<' */
- np->nfile.fd = 0;
- c = pgetc();
- if (c == '<') {
- 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->here = np;
- if ((c = pgetc()) == '-') {
- heredoc->striptabs = 1;
- } else {
- heredoc->striptabs = 0;
- pungetc();
- }
- } else if (c == '&')
- np->type = NFROMFD;
- else if (c == '>')
- np->type = NFROMTO;
- else {
- np->type = NFROM;
- pungetc();
- }
- }
- if (fd != '\0')
- np->nfile.fd = digit_val(fd);
- redirnode = np;
- goto parseredir_return;
-}
-
-
-/*
* Parse a substitution. At this point, we have read the dollar sign
* and nothing else.
*/
OpenPOWER on IntegriCloud