texinfo-commits
[Top][All Lists]
Advanced

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

[7173] parsetexi update


From: gavinsmith0123
Subject: [7173] parsetexi update
Date: Wed, 18 May 2016 18:26:47 +0000 (UTC)

Revision: 7173
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7173
Author:   gavin
Date:     2016-05-18 18:26:47 +0000 (Wed, 18 May 2016)
Log Message:
-----------
parsetexi update

Modified Paths:
--------------
    trunk/tp/parsetexi/input.c
    trunk/tp/parsetexi/input.h
    trunk/tp/parsetexi/macro.c
    trunk/tp/parsetexi/parser.c

Modified: trunk/tp/parsetexi/input.c
===================================================================
--- trunk/tp/parsetexi/input.c  2016-05-16 19:28:31 UTC (rev 7172)
+++ trunk/tp/parsetexi/input.c  2016-05-18 18:26:47 UTC (rev 7173)
@@ -39,8 +39,8 @@
 } INPUT;
 
 static INPUT *input_stack = 0;
-size_t input_number = 0;
-static size_t input_space = 0;
+int input_number = 0;
+int input_space = 0;
 
 /* Current filename and line number.  Used for reporting. */
 LINE_NR line_nr;
@@ -205,7 +205,8 @@
 void
 input_push_text (char *text, char *macro)
 {
-  input_push (text, macro, 0, line_nr.line_nr);
+  if (text)
+    input_push (text, macro, 0, line_nr.line_nr);
 }
 
 /* Used in tests - like input_push_text, but the lines from the text have

Modified: trunk/tp/parsetexi/input.h
===================================================================
--- trunk/tp/parsetexi/input.h  2016-05-16 19:28:31 UTC (rev 7172)
+++ trunk/tp/parsetexi/input.h  2016-05-18 18:26:47 UTC (rev 7173)
@@ -9,3 +9,5 @@
 void input_push_file (char *filename);
 
 extern LINE_NR line_nr;
+
+extern int input_number;

Modified: trunk/tp/parsetexi/macro.c
===================================================================
--- trunk/tp/parsetexi/macro.c  2016-05-16 19:28:31 UTC (rev 7172)
+++ trunk/tp/parsetexi/macro.c  2016-05-18 18:26:47 UTC (rev 7173)
@@ -118,9 +118,10 @@
   args_ptr++;
 
   index = 0;
-  do
+  while (1)
     {
-      /* args_ptr is after a '{' or ','. */
+      /* args_ptr is after a '{' or ','.  INDEX holds the number of
+         the macro argument */
 
       char *q, *q2;
       ELEMENT *arg;
@@ -148,29 +149,32 @@
           // 1126 - argument is completely whitespace
           if (index == 0)
             break; /* Empty arg list, like "@macro m { }". */
-          abort ();
+          line_error ("bad or empty @%s formal argument:",
+                      command_name(cmd));
         }
+      else
+        {
+          arg = new_element (ET_macro_arg);
+          text_append_n (&arg->text, args_ptr, q2 - args_ptr);
+          add_to_element_args (macro, arg);
 
-      arg = new_element (ET_macro_arg);
-      text_append_n (&arg->text, args_ptr, q2 - args_ptr);
-      add_to_element_args (macro, arg);
-
-      /* Check the argument name. */
-      {
-      char *p;
-      for (p = args_ptr; p < q2; p++)
-        {
-          if (!isalnum (*p) && *p != '_' && *p != '-')
+          /* Check the argument name. */
             {
-              char c = *q2; *q2 = 0;
-              line_error ("bad or empty @%s formal argument: %s",
-                          command_name(cmd), args_ptr);
-              *q2 = c;
-              add_extra_string (macro, "invalid_syntax", "1");
-              break;
+              char *p;
+              for (p = args_ptr; p < q2; p++)
+                {
+                  if (!isalnum (*p) && *p != '_' && *p != '-')
+                    {
+                      char c = *q2; *q2 = 0;
+                      line_error ("bad or empty @%s formal argument: %s",
+                                  command_name(cmd), args_ptr);
+                      *q2 = c;
+                      add_extra_string (macro, "invalid_syntax", "1");
+                      break;
+                    }
+                }
             }
         }
-      }
 
       args_ptr = q + 1;
 
@@ -179,7 +183,6 @@
 
       index++;
     }
-  while (1);
   line = args_ptr;
 
   /* FIXME: What if there is stuff after the '}'? */
@@ -193,7 +196,9 @@
 
 /* Macro use. */
 
-/* Return index into given arguments to look for the value of NAME. */
+/* Return index into given arguments to look for the value of NAME.
+   Return -1 if not found. */
+
 int
 lookup_macro_parameter (char *name, ELEMENT *macro)
 {
@@ -212,7 +217,6 @@
           pos++;
         }
     }
-  abort ();
   return -1;
 }
 
@@ -263,9 +267,15 @@
       switch (*sep)
         {
         case '\\':
-          if (*pline)
-            text_append_n (&arg, pline, 1);
-          pline = sep + 1;
+          if (!strchr ("\\{}", sep[1]))
+            text_append_n (&arg, sep, 1);
+          if (sep[1])
+            {
+              text_append_n (&arg, &sep[1], 1);
+              pline = sep + 2;
+            }
+          else
+            pline = sep + 1;
           break;
         case '{':
           braces_level++;
@@ -326,6 +336,7 @@
   return arg_list;
 }
 
+// 2063
 /* ARGUMENTS are the arguments used in the macro invocation.  EXPANDED gets 
the 
    result of the expansion. */
 static void
@@ -388,7 +399,8 @@
                 abort ();
               *bs = '\\';
 
-              text_append (expanded, arguments[pos]);
+              if (arguments && arguments[pos])
+                text_append (expanded, arguments[pos]);
               ptext = bs + 1;
             }
         }
@@ -473,6 +485,15 @@
   expand_macro_body (macro, arguments, &expanded);
   debug ("MACROBODY: %s||||||", expanded.text);
 
+
+  if (input_number >= 1000)
+    {
+      line_warn (
+         "macro call nested too deeply "
+         "(set MAX_NESTED_MACROS to override; current value %d)", 1000);
+      goto funexit;
+    }
+
   /* Free arguments. */
   if (arguments)
     {
@@ -493,6 +514,7 @@
   line = strchr (line, '\0');
   input_push_text (expanded.text, command_name(cmd));
 
+funexit:
   *line_inout = line;
   return current;
 }

Modified: trunk/tp/parsetexi/parser.c
===================================================================
--- trunk/tp/parsetexi/parser.c 2016-05-16 19:28:31 UTC (rev 7172)
+++ trunk/tp/parsetexi/parser.c 2016-05-18 18:26:47 UTC (rev 7173)
@@ -649,6 +649,9 @@
     return 0;
 
   linep += strspn (linep, whitespace_chars);
+  if (!*linep)
+    return 0;
+
   cmdname = read_command_name (&linep);
   *end_cmd = lookup_command (cmdname);
   free (cmdname);
@@ -1414,6 +1417,8 @@
         {
           if (!process_remaining_on_line (&current, &line))
             break;
+          if (!line)
+            break;
         }
     }
 




reply via email to

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