texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Fix #line directive early in file.


From: Gavin D. Smith
Subject: branch master updated: Fix #line directive early in file.
Date: Wed, 02 Mar 2022 14:11:29 -0500

This is an automated email from the git hooks/post-receive script.

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 5c942cdc7a Fix #line directive early in file.
5c942cdc7a is described below

commit 5c942cdc7a354d7ec06fd2aab02d190b8ac0808a
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Wed Mar 2 19:11:21 2022 +0000

    Fix #line directive early in file.
    
    * tp/Texinfo/XS/parsetexi/input.c (input_pushback): New function.
    (next_text): Return string passed to input_pushback before any
    other input.
    * tp/Texinfo/XS/parsetexi/parser.c (parse_texi_document): Call
    input_pushback after collecting 'preamble_before_beginning' element.
    This preserves the source line information when a #line directive
    appears immediately after the \input line.
---
 ChangeLog                                          | 12 ++++++++++++
 tp/Texinfo/XS/parsetexi/input.c                    | 19 +++++++++++++++++++
 tp/Texinfo/XS/parsetexi/input.h                    |  1 +
 tp/Texinfo/XS/parsetexi/parser.c                   |  5 ++---
 tp/t/results/include/cpp_line_before_first_node.pl |  4 ++--
 5 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 37ffd0656e..ec83e3e092 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2022-03-02  Gavin Smith  <gavinsmith0123@gmail.com>
+
+       Fix #line directive early in file.
+
+       * tp/Texinfo/XS/parsetexi/input.c (input_pushback): New function.
+       (next_text): Return string passed to input_pushback before any
+       other input.
+       * tp/Texinfo/XS/parsetexi/parser.c (parse_texi_document): Call
+       input_pushback after collecting 'preamble_before_beginning' element.
+       This preserves the source line information when a #line directive
+       appears immediately after the \input line.
+
 2022-03-01  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/Info.pm (output): encode directory name
diff --git a/tp/Texinfo/XS/parsetexi/input.c b/tp/Texinfo/XS/parsetexi/input.c
index 725f0881b0..71ca3a5ae5 100644
--- a/tp/Texinfo/XS/parsetexi/input.c
+++ b/tp/Texinfo/XS/parsetexi/input.c
@@ -50,6 +50,8 @@ typedef struct {
                     into lines. */
 } INPUT;
 
+static char *input_pushback_string;
+
 enum character_encoding input_encoding;
 
 static char *input_encoding_name;
@@ -338,6 +340,15 @@ expanding_macro (char *macro)
 
 char *save_string (char *string);
 
+void
+input_pushback (char *string)
+{
+  if (input_pushback_string)
+    fprintf (stderr,
+             "texi2any (XS module): bug: input_pushback called twice\n");
+  input_pushback_string = string;
+}
+
 /* Return value to be freed by caller.  Return null if we are out of input. */
 char *
 next_text (void)
@@ -347,6 +358,14 @@ next_text (void)
   size_t n;
   FILE *input_file;
 
+  if (input_pushback_string)
+    {
+      char *s;
+      s = input_pushback_string;
+      input_pushback_string = 0;
+      return s;
+    }
+
   while (input_number > 0)
     {
       /* Check for pending input. */
diff --git a/tp/Texinfo/XS/parsetexi/input.h b/tp/Texinfo/XS/parsetexi/input.h
index dee92b54e0..9f5cf9fc26 100644
--- a/tp/Texinfo/XS/parsetexi/input.h
+++ b/tp/Texinfo/XS/parsetexi/input.h
@@ -13,6 +13,7 @@ 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);
 int input_push_file (char *filename);
+void input_pushback (char *line);
 void input_reset_input_stack (void);
 int expanding_macro (char *macro);
 int top_file_index (void);
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 794d677ea7..adabf67fbf 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -377,9 +377,8 @@ parse_texi_document (void)
       if (*linep && !looking_at (linep, "\\input"))
         {
           /* This line is not part of the preamble_before_beginning.
-             Shove back into input stream. */
-          input_push (line, 0, current_source_info.file_name,
-                                   current_source_info.line_nr);
+             Push back into input stream. */
+          input_pushback (line);
           break;
         }
 
diff --git a/tp/t/results/include/cpp_line_before_first_node.pl 
b/tp/t/results/include/cpp_line_before_first_node.pl
index 58693bc47d..2d40ee8cfe 100644
--- a/tp/t/results/include/cpp_line_before_first_node.pl
+++ b/tp/t/results/include/cpp_line_before_first_node.pl
@@ -129,8 +129,8 @@ $result_errors{'cpp_line_before_first_node'} = [
   {
     'error_line' => 'unknown command `gggg\'
 ',
-    'file_name' => 'cpp_line_before_first_node.texi',
-    'line_nr' => 5,
+    'file_name' => 'foo.ptexi',
+    'line_nr' => 102,
     'macro' => '',
     'text' => 'unknown command `gggg\'',
     'type' => 'error'



reply via email to

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