texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/ParserNonXS.pm (_next_text), tp/Texi


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (_next_text), tp/Texinfo/XS/parsetexi/input.c (next_text): move code related to end of text input to the same place as end of file input.
Date: Fri, 27 Jan 2023 11:06:48 -0500

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

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 63c1c9567e * tp/Texinfo/ParserNonXS.pm (_next_text), 
tp/Texinfo/XS/parsetexi/input.c (next_text): move code related to end of text 
input to the same place as end of file input.
63c1c9567e is described below

commit 63c1c9567e1c08a7e3c73c24cd429425692379e0
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Jan 27 17:06:38 2023 +0100

    * tp/Texinfo/ParserNonXS.pm (_next_text),
    tp/Texinfo/XS/parsetexi/input.c (next_text): move code related to
    end of text input to the same place as end of file input.
    
    * tp/Texinfo/ParserNonXS.pm (_next_text),
    tp/Texinfo/XS/parsetexi/input.c (next_text): rename $previous_input
    as $input, and i as input, and use input consistently in the XS parser.
---
 ChangeLog                       | 10 ++++++
 tp/Texinfo/ParserNonXS.pm       | 56 +++++++++++++++++----------------
 tp/Texinfo/XS/parsetexi/input.c | 70 ++++++++++++++++++++---------------------
 3 files changed, 74 insertions(+), 62 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4ba7bd938d..e532093d3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2023-01-27  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_next_text),
+       tp/Texinfo/XS/parsetexi/input.c (next_text): move code related to
+       end of text input to the same place as end of file input.
+
+       * tp/Texinfo/ParserNonXS.pm (_next_text),
+       tp/Texinfo/XS/parsetexi/input.c (next_text): rename $previous_input
+       as $input, and i as input, and use input consistently in the XS parser.
+
 2023-01-27  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Common.pm (@variable_string_settables): remove
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 327e809b43..b9116f7b0e 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -2284,19 +2284,7 @@ sub _next_text($;$)
     if (exists($input->{'th'})) {
       my $texthandle = $input->{'th'};
       my $next_line = <$texthandle>;
-      if (!defined($next_line)) {
-        if ($input->{'input_source_info'}->{'macro'} ne '') {
-          my $top_macro = shift @{$self->{'macro_stack'}};
-          print STDERR "SHIFT MACRO_STACK(@{$self->{'macro_stack'}}):"
-            ." $top_macro->{'args'}->[0]->{'text'}\n"
-              if ($self->{'DEBUG'});
-        } elsif (defined($input->{'value_flag'})) {
-          my $top_value = shift @{$self->{'value_stack'}};
-          print STDERR "SHIFT VALUE_STACK(@{$self->{'value_stack'}}):"
-            . "$top_value\n"
-              if ($self->{'DEBUG'});
-        }
-      } else {
+      if (defined($next_line)) {
         # need to decode to characters
         $next_line = Encode::decode('utf8', $next_line);
         $input->{'input_source_info'}->{'line_nr'} += 1
@@ -2339,19 +2327,33 @@ sub _next_text($;$)
         return ($line, { %{$input->{'input_source_info'}} });
       }
     }
-    my $previous_input = $self->{'input'}->[0];
+    # Top input source failed.  Close, pop, and try the next one.
+    if (exists($input->{'th'})) {
+      # End of text reached.
+      # FIXME close $input->{'th'} explicitly?
+      if ($input->{'input_source_info'}->{'macro'} ne '') {
+        my $top_macro = shift @{$self->{'macro_stack'}};
+        print STDERR "SHIFT MACRO_STACK(@{$self->{'macro_stack'}}):"
+          ." $top_macro->{'args'}->[0]->{'text'}\n"
+            if ($self->{'DEBUG'});
+      } elsif (defined($input->{'value_flag'})) {
+        my $top_value = shift @{$self->{'value_stack'}};
+        print STDERR "SHIFT VALUE_STACK(@{$self->{'value_stack'}}):"
+          . "$top_value\n"
+            if ($self->{'DEBUG'});
+      }
     # Don't close STDIN
-    if ($previous_input->{'fh'}
-        and $previous_input->{'input_source_info'}->{'file_name'} ne '-') {
-      if (!close($previous_input->{'fh'})) {
+    } elsif ($input->{'fh'}
+             and $input->{'input_source_info'}->{'file_name'} ne '-') {
+      if (!close($input->{'fh'})) {
         # need to decode for error message
         my $file_name_encoding;
-        if (defined($previous_input->{'file_name_encoding'})) {
-          $file_name_encoding = $previous_input->{'file_name_encoding'};
+        if (defined($input->{'file_name_encoding'})) {
+          $file_name_encoding = $input->{'file_name_encoding'};
         } else {
           $file_name_encoding = $self->get_conf('COMMAND_LINE_ENCODING');
         }
-        my $file_name = $previous_input->{'input_source_info'}->{'file_name'};
+        my $file_name = $input->{'input_source_info'}->{'file_name'};
         if (defined($file_name_encoding)) {
           $file_name = decode($file_name_encoding, $file_name);
         }
@@ -2359,19 +2361,19 @@ sub _next_text($;$)
                              sprintf(__("error on closing %s: %s"),
                                      $file_name, $!));
       }
-      delete $previous_input->{'fh'};
+      delete $input->{'fh'};
     }
 
-    if (defined($previous_input->{'input_source_mark'})) {
+    if (defined($input->{'input_source_mark'})) {
       my $end_source_mark
           = { 'sourcemark_type' =>
-               $previous_input->{'input_source_mark'}->{'sourcemark_type'},
+               $input->{'input_source_mark'}->{'sourcemark_type'},
               'counter' =>
-               $previous_input->{'input_source_mark'}->{'counter'},
+               $input->{'input_source_mark'}->{'counter'},
             };
       $end_source_mark->{'line'}
-        = $previous_input->{'input_source_mark'}->{'line'}
-          if (defined($previous_input->{'input_source_mark'}->{'line'}));
+        = $input->{'input_source_mark'}->{'line'}
+          if (defined($input->{'input_source_mark'}->{'line'}));
       $end_source_mark->{'status'} = 'end'
           if ($end_source_mark->{'sourcemark_type'} eq 'include');
       _register_source_mark($self, $current,
@@ -2381,7 +2383,7 @@ sub _next_text($;$)
     # source_info, even when nothing is returned and the first input
     # file is closed.
     if (scalar(@{$self->{'input'}}) == 1) {
-      return (undef, { %{$previous_input->{'input_source_info'}} });
+      return (undef, { %{$input->{'input_source_info'}} });
     } else {
       shift @{$self->{'input'}};
     }
diff --git a/tp/Texinfo/XS/parsetexi/input.c b/tp/Texinfo/XS/parsetexi/input.c
index 34f8c69543..4f7b4ba29e 100644
--- a/tp/Texinfo/XS/parsetexi/input.c
+++ b/tp/Texinfo/XS/parsetexi/input.c
@@ -409,43 +409,32 @@ next_text (ELEMENT *current)
   while (input_number > 0)
     {
       /* Check for pending input. */
-      INPUT *i = &input_stack[input_number - 1];
+      INPUT *input = &input_stack[input_number - 1];
 
-      switch (i->type)
+      switch (input->type)
         {
           char *p, *new;
         case IN_text:
-          if (!*i->ptext)
-            {
-              /* End of text reached. */
-              free (i->text);
-              if (i->value_flag)
-                {
-                  value_expansion_nr--;
-                  free (i->value_flag);
-                }
-              else if (i->source_info.macro)
-                macro_expansion_nr--;
-              break;
-            }
+          if (!*input->ptext)
+            break;
           /* Split off a line of input. */
-          p = strchrnul (i->ptext, '\n');
-          new = strndup (i->ptext, p - i->ptext + 1);
+          p = strchrnul (input->ptext, '\n');
+          new = strndup (input->ptext, p - input->ptext + 1);
           if (*p)
-            i->ptext = p + 1;
+            input->ptext = p + 1;
           else
-            i->ptext = p; /* The next time, we will pop the input source. */
+            input->ptext = p; /* The next time, we will pop the input source. 
*/
 
-          if (!i->source_info.macro && !i->value_flag)
-            i->source_info.line_nr++;
+          if (!input->source_info.macro && !input->value_flag)
+            input->source_info.line_nr++;
 
-          current_source_info = i->source_info;
+          current_source_info = input->source_info;
 
           return new;
 
           break;
         case IN_file:
-          input_file = input_stack[input_number - 1].file;
+          input_file = input->file;
           status = getline (&line, &n, input_file);
           if (status != -1)
             {
@@ -470,12 +459,13 @@ next_text (ELEMENT *current)
                     source_mark->line = convert_to_utf8 (strdup (comment+1));
                   else
                     source_mark->line = 0;
-                  input_push_text(strdup(""), i->source_info.line_nr, 0, 0);
+                  input_push_text(strdup(""),
+                                  input->source_info.line_nr, 0, 0);
                   set_input_source_mark(source_mark);
                 }
 
-              i->source_info.line_nr++;
-              current_source_info = i->source_info;
+              input->source_info.line_nr++;
+              current_source_info = input->source_info;
 
               return convert_to_utf8 (line);
             }
@@ -485,27 +475,37 @@ next_text (ELEMENT *current)
           fatal ("unknown input source type");
         }
 
-      /* Top input source failed.  Pop it and try the next one. */
-      
-      if (input_stack[input_number - 1].type == IN_file)
+      /* Top input source failed.  Close, pop, and try the next one. */
+      if (input->type == IN_file)
         {
-          FILE *file = input_stack[input_number - 1].file;
+          FILE *file = input->file;
 
           if (file != stdin)
             {
-              if (fclose (input_stack[input_number - 1].file) == EOF)
+              if (fclose (input->file) == EOF)
                 fprintf (stderr, "error on closing %s: %s",
-                        input_stack[input_number - 1].source_info.file_name,
+                        input->source_info.file_name,
                         strerror (errno));
             }
         }
+      else
+        {
+          /* End of text reached. */
+          free (input->text);
+          if (input->value_flag)
+            {
+              value_expansion_nr--;
+              free (input->value_flag);
+            }
+          else if (input->source_info.macro)
+            macro_expansion_nr--;
+        }
 
-      if (input_stack[input_number - 1].input_source_mark)
+      if (input->input_source_mark)
         {
           /* FIXME free the input_source_mark here, when it is not
              associated to an element, for delcomment for example */
-          SOURCE_MARK *input_source_mark
-            = input_stack[input_number - 1].input_source_mark;
+          SOURCE_MARK *input_source_mark = input->input_source_mark;
           SOURCE_MARK *end_include_source_mark
             = new_source_mark(input_source_mark->type);
           end_include_source_mark->counter = input_source_mark->counter;



reply via email to

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