diff options
author | Jilles Tjoelker <jilles@FreeBSD.org> | 2014-09-14 16:27:49 +0000 |
---|---|---|
committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2014-09-14 16:27:49 +0000 |
commit | 671a890e58654b089bc57d4977361a658ac5e825 (patch) | |
tree | 602ccc9e96ea8f3103efd7d27f7f2c5912e8423e /bin | |
parent | 20250ee1abed94fda4c1d5d11b0e7aed05c91195 (diff) | |
download | src-671a890e58654b089bc57d4977361a658ac5e825.tar.gz src-671a890e58654b089bc57d4977361a658ac5e825.zip |
sh: Make checkend() a real function instead of an emulated nested function.
No functional change is intended, but the generated code is slightly
different.
Notes
Notes:
svn path=/head/; revision=271592
Diffstat (limited to 'bin')
-rw-r--r-- | bin/sh/parser.c | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c index dd3abb31e2ad..2b36f50cadac 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -946,6 +946,42 @@ struct tokenstate /* + * Check to see whether we are at the end of the here document. When this + * is called, c is set to the first character of the next input line. If + * we are at the end of the here document, this routine sets the c to PEOF. + * The new value of c is returned. + */ + +static int +checkend(int c, const char *eofmark, char *line, size_t sizeof_line, + int striptabs) +{ + if (striptabs) { + while (c == '\t') + c = pgetc(); + } + if (c == *eofmark) { + if (pfgets(line, sizeof_line) != NULL) { + const char *p, *q; + + p = line; + for (q = eofmark + 1 ; *q && *p == *q ; p++, q++); + if ((*p == '\0' || *p == '\n') && *q == '\0') { + c = PEOF; + if (*p == '\n') { + plinno++; + needprompt = doprompt; + } + } else { + pushstring(line, strlen(line), NULL); + } + } + } + return (c); +} + + +/* * Called to parse command substitutions. */ @@ -1269,7 +1305,6 @@ readcstyleesc(char *out) * will run code that appears at the end of readtoken1. */ -#define CHECKEND() {goto checkend; checkend_return:;} #define PARSEREDIR() {goto parseredir; parseredir_return:;} #define PARSESUB() {goto parsesub; parsesub_return:;} #define PARSEARITH() {goto parsearith; parsearith_return:;} @@ -1303,7 +1338,9 @@ readtoken1(int firstc, char const *initialsyntax, const char *eofmark, STARTSTACKSTR(out); loop: { /* for each line, until end of word */ - CHECKEND(); /* set c to PEOF if at end of here document */ + if (eofmark) + /* set c to PEOF if at end of here document */ + c = checkend(c, eofmark, line, sizeof(line), striptabs); for (;;) { /* until end of line or end of word */ CHECKSTRSPACE(4, out); /* permit 4 calls to USTPUTC */ @@ -1484,40 +1521,6 @@ endword: /* - * Check to see whether we are at the end of the here document. When this - * is called, c is set to the first character of the next input line. If - * we are at the end of the here document, this routine sets the c to PEOF. - */ - -checkend: { - if (eofmark) { - if (striptabs) { - while (c == '\t') - c = pgetc(); - } - if (c == *eofmark) { - if (pfgets(line, sizeof line) != NULL) { - const char *p, *q; - - p = line; - for (q = eofmark + 1 ; *q && *p == *q ; p++, q++); - if ((*p == '\0' || *p == '\n') && *q == '\0') { - c = PEOF; - if (*p == '\n') { - plinno++; - needprompt = doprompt; - } - } else { - pushstring(line, strlen(line), NULL); - } - } - } - } - goto checkend_return; -} - - -/* * 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. |