summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2014-09-14 16:27:49 +0000
committerjilles <jilles@FreeBSD.org>2014-09-14 16:27:49 +0000
commit860c473214cf7b190e22f2237a121ee676076235 (patch)
tree602ccc9e96ea8f3103efd7d27f7f2c5912e8423e /bin
parent2b729668c7f67ce792762170d13ad244fb56c71d (diff)
downloadFreeBSD-src-860c473214cf7b190e22f2237a121ee676076235.zip
FreeBSD-src-860c473214cf7b190e22f2237a121ee676076235.tar.gz
sh: Make checkend() a real function instead of an emulated nested function.
No functional change is intended, but the generated code is slightly different.
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/parser.c75
1 files changed, 39 insertions, 36 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index dd3abb3..2b36f50 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.
OpenPOWER on IntegriCloud