texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[7525] parsetexi more on macros


From: gavinsmith0123
Subject: [7525] parsetexi more on macros
Date: Sun, 20 Nov 2016 21:06:21 +0000 (UTC)

Revision: 7525
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7525
Author:   gavin
Date:     2016-11-20 21:06:21 +0000 (Sun, 20 Nov 2016)
Log Message:
-----------
parsetexi more on macros

Modified Paths:
--------------
    trunk/tp/parsetexi/macro.c

Modified: trunk/tp/parsetexi/macro.c
===================================================================
--- trunk/tp/parsetexi/macro.c  2016-11-20 20:22:02 UTC (rev 7524)
+++ trunk/tp/parsetexi/macro.c  2016-11-20 21:06:21 UTC (rev 7525)
@@ -371,6 +371,7 @@
   int i; /* Index into macro contents. */
   char *macrobody;
   ELEMENT tmp;
+  char *ptext;
 
   memset (&tmp, 0, sizeof (ELEMENT));
   tmp.contents = macro->contents;
@@ -382,58 +383,53 @@
   if (!macrobody)
     return;
 
+  ptext = macrobody;
+  while (1)
     {
-      char *ptext;
+      /* At the start of this loop ptext is at the beginning or
+         just after the last backslash sequence. */
 
-      ptext = macrobody;
-      
-      while (1)
-        {
-          /* At the start of this loop ptext is at the beginning or
-             just after the last backslash sequence. */
+      char *bs; /* Pointer to next backslash. */
 
-          char *bs; /* Pointer to next backslash. */
+      bs = strchrnul (ptext, '\\');
+      text_append_n (expanded, ptext, bs - ptext);
+      if (!*bs)
+        break; /* End of line. */
 
-          bs = strchrnul (ptext, '\\');
-          text_append_n (expanded, ptext, bs - ptext);
-          if (!*bs)
-            break; /* End of line. */
+      ptext = bs + 1;
+      if (*ptext == '\\')
+        {
+          text_append_n (expanded, "\\", 1); /* Escaped backslash (\\). */
+          ptext++;
+        }
+      else
+        {
+          bs = strchr (ptext, '\\');
+          if (!bs)
+            {
+              // error - malformed
+              return;
+              abort ();
+            }
 
-          ptext = bs + 1;
-          if (*ptext == '\\')
+          *bs = '\0';
+          pos = lookup_macro_parameter (ptext, macro);
+          if (pos == -1)
             {
-              text_append_n (expanded, "\\", 1); /* Escaped backslash (\\). */
-              ptext++;
+              line_error ("\\ in @%s expansion followed `%s' instead of "
+                          "parameter name or \\",
+                          macro->args.list[0]->text.text,
+                          ptext);
+              text_append (expanded, "\\");
+              text_append (expanded, ptext);
             }
           else
             {
-              bs = strchr (ptext, '\\');
-              if (!bs)
-                {
-                  // error - malformed
-                  return;
-                  abort ();
-                }
-
-              *bs = '\0';
-              pos = lookup_macro_parameter (ptext, macro);
-              if (pos == -1)
-                {
-                  line_error ("\\ in @%s expansion followed `%s' instead of "
-                              "parameter name or \\",
-                              macro->args.list[0]->text.text,
-                              ptext);
-                  text_append (expanded, "\\");
-                  text_append (expanded, ptext);
-                }
-              else
-                {
-                  if (arguments && arguments[pos])
-                    text_append (expanded, arguments[pos]);
-                }
-              *bs = '\\';
-              ptext = bs + 1;
+              if (arguments && arguments[pos])
+                text_append (expanded, arguments[pos]);
             }
+          *bs = '\\';
+          ptext = bs + 1;
         }
     }
 }
@@ -544,6 +540,8 @@
   expand_macro_body (macro, arguments, &expanded);
   debug ("MACROBODY: %s||||||", expanded.text);
 
+  if (expanded.end > 0 && expanded.text[expanded.end - 1] == '\n')
+    expanded.text[--expanded.end] = '\0';
 
   if (input_number >= 1000)
     {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]