Author: jilles
Date: Sun Sep 14 16:27:49 2014
New Revision: 271592
URL: http://svnweb.freebsd.org/changeset/base/271592

Log:
  sh: Make checkend() a real function instead of an emulated nested function.
  
  No functional change is intended, but the generated code is slightly
  different.

Modified:
  head/bin/sh/parser.c

Modified: head/bin/sh/parser.c
==============================================================================
--- head/bin/sh/parser.c        Sun Sep 14 16:12:43 2014        (r271591)
+++ head/bin/sh/parser.c        Sun Sep 14 16:27:49 2014        (r271592)
@@ -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 *initi
 
        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.
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to