texinfo-commits
[Top][All Lists]
Advanced

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

[8440] parsetexi update for check_line_directive


From: gavinsmith0123
Subject: [8440] parsetexi update for check_line_directive
Date: Sun, 28 Oct 2018 07:31:58 -0400 (EDT)

Revision: 8440
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=8440
Author:   gavin
Date:     2018-10-28 07:31:57 -0400 (Sun, 28 Oct 2018)
Log Message:
-----------
parsetexi update for check_line_directive

Modified Paths:
--------------
    trunk/tp/Texinfo/XS/parsetexi/handle_commands.c
    trunk/tp/Texinfo/XS/parsetexi/input.c
    trunk/tp/Texinfo/XS/parsetexi/input.h
    trunk/tp/Texinfo/XS/parsetexi/macro.c
    trunk/tp/Texinfo/XS/parsetexi/parser.c
    trunk/tp/Texinfo/XS/parsetexi/separator.c

Modified: trunk/tp/Texinfo/XS/parsetexi/handle_commands.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/handle_commands.c     2018-10-28 10:24:49 UTC 
(rev 8439)
+++ trunk/tp/Texinfo/XS/parsetexi/handle_commands.c     2018-10-28 11:31:57 UTC 
(rev 8440)
@@ -273,7 +273,7 @@
             {
               char *line2;
               input_push_text (strdup (line), 0);
-              line2 = new_line (current);
+              line2 = new_line ();
               if (line2)
                 line = line2;
             }
@@ -385,7 +385,7 @@
           input_push_text (strdup (line), 0);
 
           save_ln = line_nr;
-          line2 = new_line (current);
+          line2 = new_line ();
           if (line2)
             {
               line = line2;
@@ -938,7 +938,7 @@
                   while (!is_end_current_command (current,
                                                   &line_dummy, &dummy))
                     {
-                      line = new_line (current);
+                      line = new_line ();
                       if (!line)
                         {
                           line = "";

Modified: trunk/tp/Texinfo/XS/parsetexi/input.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/input.c       2018-10-28 10:24:49 UTC (rev 
8439)
+++ trunk/tp/Texinfo/XS/parsetexi/input.c       2018-10-28 11:31:57 UTC (rev 
8440)
@@ -60,7 +60,19 @@
 /* Current filename and line number.  Used for reporting. */
 LINE_NR line_nr;
 
-// 1961
+/* Change the line number of filename of the top input source.  Used to
+   record a #line directive.  If FILENAME is non-null, it should hbae
+   been returned from save_string. */
+void
+save_line_directive (int line_nr, char *filename)
+{
+  INPUT *top = &input_stack[input_number - 1];
+  if (line_nr)
+    top->line_nr.line_nr = line_nr;
+  if (filename)
+    top->line_nr.file_name = filename;
+}
+
 /* Collect text from the input sources until a newline is found.  This is used 
    instead of next_text when we need to be sure we get an entire line of 
    Texinfo input (for example as a line argument to a command), which might 
not 
@@ -69,7 +81,7 @@
    Return value should not be freed by caller, and becomes invalid after
    a subsequent call. */
 char *
-new_line (ELEMENT *current)
+new_line (void)
 {
   static TEXT t;
   char *new = 0;
@@ -78,7 +90,7 @@
 
   while (1)
     {
-      new = next_text (current);
+      new = next_text ();
       if (!new)
         break;
       text_append (&t, new);
@@ -256,74 +268,9 @@
 
 char *save_string (char *string);
 
-/* Check for a #line directive.
-   FIXME: Really shouldn't have to be checking whether we are inside
-   @verb etc. all the way down in here.  Then we could avoid passing
-   CURRENT as an argument. */
-static int
-check_line_directive (char *line, ELEMENT *current, LINE_NR *line_nr)
-{
-  char *p = line, *q;
-  int line_no = 0;
-  char *filename = 0;
-
-  if (current && current->parent && current->parent->cmd == CM_verb)
-    return 0;
-  if (current && (command_flags(current) & CF_block)
-      && (command_data(current->cmd).data == BLOCK_raw
-          || command_data(current->cmd).data == BLOCK_conditional))
-    return 0;
-
-  p += strspn (p, " \t");
-  if (*p != '#')
-    return 0;
-  p++;
-
-  q = p + strspn (p, " \t");
-  if (!memcmp (q, "line", strlen ("line")))
-    p = q + strlen ("line");
-
-  if (!strchr (" \t", *p))
-    return 0;
-  p += strspn (p, " \t");
-
-  /* p should now be at the line number */
-  if (!strchr ("0123456789", *p))
-    return 0;
-  line_no = strtoul (p, &p, 10);
-
-  p += strspn (p, " \t");
-  if (*p == '"')
-    {
-      char c;
-      p++;
-      q = strchr (p, '"');
-      if (!q)
-        return 0;
-      c = *q;
-      *q = 0;
-      filename = save_string (p);
-      *q = c;
-      p = q + 1;
-      p += strspn (p, " \t");
-
-      p += strspn (p, "0123456789");
-      p += strspn (p, " \t");
-    }
-  if (*p && *p != '\n')
-    return 0; /* trailing text on line */
-
-  line_nr->line_nr = line_no;
-  if (filename)
-    {
-      line_nr->file_name = filename;
-    }
-  return 1;
-}
-
 /* Return value to be freed by caller.  Return null if we are out of input. */
 char *
-next_text (ELEMENT *current)
+next_text (void)
 {
   ssize_t status;
   char *line = 0;
@@ -381,12 +328,6 @@
               if (comment)
                 *comment = '\0';
 
-              if (conf.cpp_line_directives)
-                {
-                  if (check_line_directive (line, current, &i->line_nr))
-                    continue;
-                }
-
               i->line_nr.line_nr++;
               line_nr = i->line_nr;
 

Modified: trunk/tp/Texinfo/XS/parsetexi/input.h
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/input.h       2018-10-28 10:24:49 UTC (rev 
8439)
+++ trunk/tp/Texinfo/XS/parsetexi/input.h       2018-10-28 11:31:57 UTC (rev 
8440)
@@ -1,8 +1,10 @@
 #include <stdio.h>
 
-char *new_line (ELEMENT *current);
-char *next_text (ELEMENT *current);
+char *new_line (void);
+char *next_text (void);
 
+void save_line_directive (int line_nr, char *filename);
+
 void input_push (char *text, char *macro, char *filename, int line_number);
 void input_push_text (char *line, char *macro);
 void input_push_text_with_line_nos (char *text, int starting);

Modified: trunk/tp/Texinfo/XS/parsetexi/macro.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/macro.c       2018-10-28 10:24:49 UTC (rev 
8439)
+++ trunk/tp/Texinfo/XS/parsetexi/macro.c       2018-10-28 11:31:57 UTC (rev 
8440)
@@ -272,7 +272,7 @@
         {
           debug ("MACRO ARG end of line");
           text_append (&arg, pline);
-          line = new_line (macro);
+          line = new_line ();
           if (!line)
             {
               line_error ("@%s missing closing brace", command_name(cmd));
@@ -524,7 +524,7 @@
     {
       line = p;
       line++;
-      /* In the Perl version formfeed is excluded for some reason. */
+      /* FIXME: In the Perl version formfeed is excluded for some reason. */
       line += strspn (line, whitespace_chars);
       arguments = expand_macro_arguments (macro, &line, cmd);
     }
@@ -545,7 +545,7 @@
          input already, call new_line. */
       if (!strchr (line, '\n'))
         {
-          line = new_line (current);
+          line = new_line ();
           if (!line)
             line = "";
         }

Modified: trunk/tp/Texinfo/XS/parsetexi/parser.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/parser.c      2018-10-28 10:24:49 UTC (rev 
8439)
+++ trunk/tp/Texinfo/XS/parsetexi/parser.c      2018-10-28 11:31:57 UTC (rev 
8440)
@@ -328,7 +328,7 @@
       ELEMENT *l;
 
       free (line);
-      line = next_text (0);
+      line = next_text ();
       if (!line)
         break;
 
@@ -1161,7 +1161,7 @@
               /* Ignore until end of line */
               if (!strchr (line, '\n'))
                 {
-                  line = new_line (popped);
+                  line = new_line ();
                   debug ("IGNORE CLOSE LINE");
                 }
               destroy_element_and_children (popped);
@@ -1282,7 +1282,7 @@
          input in a static variable like allocated_text, to prevent
          memory leaks.  */
       free (allocated_text);
-      line = allocated_text = next_text (current);
+      line = allocated_text = next_text ();
 
       if (!line)
         {
@@ -1353,7 +1353,7 @@
       line = line_after_command;
       current = handle_macro (current, &line, cmd);
       free (allocated_line);
-      allocated_line = next_text (current);
+      allocated_line = next_text ();
       line = allocated_line;
     }
 
@@ -1768,8 +1768,67 @@
   return retval;
 }
 
+/* Check for a #line directive. */
+static int
+check_line_directive (char *line)
+{
+  char *p = line, *q;
+  int line_no = 0;
+  char *filename = 0;
+
+  if (!conf.cpp_line_directives)
+    return 0;
+
+  /* Check input is coming directly from a file. */
+  if (!line_nr.file_name || !line_nr.file_name
+      || (line_nr.macro && *line_nr.macro))
+    return 0;
+
+  p += strspn (p, " \t");
+  if (*p != '#')
+    return 0;
+  p++;
+
+  q = p + strspn (p, " \t");
+  if (!memcmp (q, "line", strlen ("line")))
+    p = q + strlen ("line");
+
+  if (!strchr (" \t", *p))
+    return 0;
+  p += strspn (p, " \t");
+
+  /* p should now be at the line number */
+  if (!strchr ("0123456789", *p))
+    return 0;
+  line_no = strtoul (p, &p, 10);
+
+  p += strspn (p, " \t");
+  if (*p == '"')
+    {
+      char c;
+      p++;
+      q = strchr (p, '"');
+      if (!q)
+        return 0;
+      c = *q;
+      *q = 0;
+      filename = save_string (p);
+      *q = c;
+      p = q + 1;
+      p += strspn (p, " \t");
+
+      p += strspn (p, "0123456789");
+      p += strspn (p, " \t");
+    }
+  if (*p && *p != '\n')
+    return 0; /* trailing text on line */
+
+  save_line_directive (line_no, filename);
+
+  return 1;
+}
+
 /* Pass in and return root of a "Texinfo tree". */
-/* 3676 */
 ELEMENT *
 parse_texi (ELEMENT *root_elt)
 {
@@ -1781,13 +1840,12 @@
   while (1)
     {
       free (allocated_line);
-      line = allocated_line = next_text (current);
+      line = allocated_line = next_text ();
       if (!allocated_line)
         break; /* Out of input. */
 
       debug_nonl ("NEW LINE %s", line);
 
-      // 3706
       /* If not in 'raw' or 'conditional' and parent isn't a 'verb', collect
          leading whitespace and save as an "ET_empty_line" element.  This
          element type can be changed in 'abort_empty_line' when more text is
@@ -1801,6 +1859,9 @@
           ELEMENT *e;
           int n;
           
+          if (check_line_directive (line))
+            continue;
+
           debug ("BEGIN LINE");
 
           if (current->contents.number > 0

Modified: trunk/tp/Texinfo/XS/parsetexi/separator.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/separator.c   2018-10-28 10:24:49 UTC (rev 
8439)
+++ trunk/tp/Texinfo/XS/parsetexi/separator.c   2018-10-28 11:31:57 UTC (rev 
8440)
@@ -670,10 +670,10 @@
                       brace_count--;
                       break;
                     default:
-                      line = next_text (current);
+                      line = next_text ();
                       if (!line)
                         {
-                          /* ERROR - unbalanced brace */
+                          /* FIXME: error - unbalanced brace */
                         }
                       continue;
                     }
@@ -719,10 +719,10 @@
                   break;
                 default:
                   free (alloc_line);
-                  alloc_line = line = next_text (current);
+                  alloc_line = line = next_text ();
                   if (!line)
                     {
-                      /* FIXME: ERROR - unbalanced brace */
+                      /* FIXME: error - unbalanced brace */
                     }
                   continue;
                 }




reply via email to

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