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 (_abort_empty_line),


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (_abort_empty_line), tp/Texinfo/XS/parsetexi/parser.c (abort_empty_line): different debug message if additional_spaces are added or not.
Date: Mon, 27 May 2024 14:59:51 -0400

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 864700b039 * tp/Texinfo/ParserNonXS.pm (_abort_empty_line), 
tp/Texinfo/XS/parsetexi/parser.c (abort_empty_line): different debug message if 
additional_spaces are added or not.
864700b039 is described below

commit 864700b03913b2cce5061f77b1e3d943dd7a53a5
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon May 27 20:59:24 2024 +0200

    * tp/Texinfo/ParserNonXS.pm (_abort_empty_line),
    tp/Texinfo/XS/parsetexi/parser.c (abort_empty_line): different debug
    message if additional_spaces are added or not.
    
    * tp/Texinfo/XS/parsetexi/parser.c (abort_empty_line),
    tp/Texinfo/XS/parsetexi/parser.c (merge_text): add a length
    argument for additional_spaces length.  Update callers.
---
 ChangeLog                           | 10 +++++++
 tp/Texinfo/ParserNonXS.pm           | 17 +++++++-----
 tp/Texinfo/XS/parsetexi/close.c     |  2 +-
 tp/Texinfo/XS/parsetexi/menus.c     |  2 +-
 tp/Texinfo/XS/parsetexi/parser.c    | 53 ++++++++++++++++++-------------------
 tp/Texinfo/XS/parsetexi/parser.h    |  3 ++-
 tp/Texinfo/XS/parsetexi/separator.c | 12 ++++-----
 7 files changed, 56 insertions(+), 43 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 32ca42028b..87792a4489 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-05-27  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_abort_empty_line),
+       tp/Texinfo/XS/parsetexi/parser.c (abort_empty_line): different debug
+       message if additional_spaces are added or not.
+
+       * tp/Texinfo/XS/parsetexi/parser.c (abort_empty_line),
+       tp/Texinfo/XS/parsetexi/parser.c (merge_text): add a length
+       argument for additional_spaces length.  Update callers.
+
 2024-05-27  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/parsetexi/macro.c (handle_macro),
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 36e9ba948c..bc3baf2387 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -2965,13 +2965,16 @@ sub _abort_empty_line {
 
     my $spaces_element = $current->{'contents'}->[-1];
 
-    print STDERR "ABORT EMPTY in "
-      .Texinfo::Common::debug_print_element($current)."(p:".
-       (!$no_paragraph_contexts{$self->_top_context()} ? 1 : 0)."): "
-      .$spaces_element->{'type'}
-      ."; add |$additional_spaces|"
-      ." to |$spaces_element->{'text'}|\n"
-        if ($self->{'conf'}->{'DEBUG'});
+    if ($self->{'conf'}->{'DEBUG'}) {
+      print STDERR "ABORT EMPTY in "
+        .Texinfo::Common::debug_print_element($current)."(p:".
+          (!$no_paragraph_contexts{$self->_top_context()} ? 1 : 0)."): "
+         .$spaces_element->{'type'}."; ";
+      if ($additional_spaces ne '') {
+        print STDERR "add |$additional_spaces| to ";
+      }
+      print STDERR "|$spaces_element->{'text'}|\n";
+    }
 
     $spaces_element->{'text'} .= $additional_spaces;
 
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index 3da17af218..a4ba8636c9 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -467,7 +467,7 @@ close_current (ELEMENT *current,
                  == ET_internal_spaces_before_argument)
             {
               /* remove spaces element from tree and update extra values */
-              abort_empty_line (&current, 0);
+              abort_empty_line (&current, NULL, 0);
             }
           current = current->parent;
           break;
diff --git a/tp/Texinfo/XS/parsetexi/menus.c b/tp/Texinfo/XS/parsetexi/menus.c
index 7c83f29d99..1e815efed3 100644
--- a/tp/Texinfo/XS/parsetexi/menus.c
+++ b/tp/Texinfo/XS/parsetexi/menus.c
@@ -130,7 +130,7 @@ handle_menu_entry_separators (ELEMENT **current_inout, 
const char **line_inout)
       ELEMENT *star;
 
       debug ("MENU STAR");
-      abort_empty_line (&current, 0);
+      abort_empty_line (&current, NULL, 0);
       line++; /* Past the '*'. */
 
       star = new_element (ET_internal_menu_star);
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 0fbb813021..a8ef4e2a31 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -678,16 +678,7 @@ merge_text (ELEMENT *current, const char *text, size_t 
len_text,
           no_merge_with_following_text = 1;
         }
 
-      if (leading_spaces)
-        {
-          additional = malloc (leading_spaces + 1);
-          if (!additional)
-            fatal ("malloc failed");
-          memcpy (additional, text, leading_spaces);
-          additional[leading_spaces] = '\0';
-        }
-
-      if (abort_empty_line (&current, additional))
+      if (abort_empty_line (&current, text, leading_spaces))
         {
           text += leading_spaces;
           len_text -= leading_spaces;
@@ -761,16 +752,14 @@ merge_text (ELEMENT *current, const char *text, size_t 
len_text,
 /* If last contents child of CURRENT is an empty line element, remove
    or merge text, and return true. */
 int
-abort_empty_line (ELEMENT **current_inout, char *additional_spaces)
+abort_empty_line (ELEMENT **current_inout, const char *additional_spaces,
+                  size_t len_text)
 {
   ELEMENT *current = *current_inout;
   int retval;
 
   ELEMENT *last_child = last_contents_child (current);
 
-  if (!additional_spaces)
-    additional_spaces = "";
-
   if (last_child
       && (last_child->type == ET_empty_line
           || last_child->type == ET_ignorable_spaces_after_command
@@ -779,15 +768,25 @@ abort_empty_line (ELEMENT **current_inout, char 
*additional_spaces)
           || last_child->type == ET_spaces_after_close_brace))
     {
       retval = 1;
-      debug_nonl ("ABORT EMPTY in ");
-      debug_parser_print_element (current, 0);
-      debug_nonl ("(p:%d): %s; add |%s| to |%s|",
-                  in_paragraph_context (current_context ()),
-                  element_type_names[last_child->type], additional_spaces,
-                  last_child->text.end > 0 ? last_child->text.text : "");
-      debug ("");
+      if (global_parser_conf.debug)
+        {
+          debug_nonl ("ABORT EMPTY in ");
+          debug_parser_print_element (current, 0);
+          debug_nonl ("(p:%d): %s; ", in_paragraph_context (current_context 
()),
+                      element_type_names[last_child->type]);
+          if (len_text)
+            {
+              char *additional_text_dbg = strndup (additional_spaces, 
len_text);
+              debug_nonl ("add |%s| to ", additional_text_dbg);
+              free (additional_text_dbg);
+            }
+          debug_nonl ("|%s|",
+                      last_child->text.end > 0 ? last_child->text.text : "");
+          debug ("");
+        }
 
-      text_append (&last_child->text, additional_spaces);
+      if (len_text)
+        text_append_n (&last_child->text, additional_spaces, len_text);
 
       /* Remove element altogether if it's empty. */
       if (last_child->text.end == 0)
@@ -2154,7 +2153,7 @@ process_remaining_on_line (ELEMENT **current_inout, const 
char **line_inout)
                        for the converters to handle */
                       ELEMENT *value_elt;
 
-                      abort_empty_line (&current, NULL);
+                      abort_empty_line (&current, NULL, 0);
 
                       line_warn ("undefined flag: %s", flag);
 
@@ -2178,7 +2177,7 @@ process_remaining_on_line (ELEMENT **current_inout, const 
char **line_inout)
                 { /* CM_txiinternalvalue */
                   ELEMENT *txiinternalvalue_elt;
 
-                  abort_empty_line (&current, NULL);
+                  abort_empty_line (&current, NULL, 0);
 
                   txiinternalvalue_elt = new_value_element (cmd, flag,
                                                             spaces_element);
@@ -2227,7 +2226,7 @@ process_remaining_on_line (ELEMENT **current_inout, const 
char **line_inout)
       /* warn on not appearing at line beginning.  Need to do before closing
          paragraph as it also closes the empty line */
       if (!def_line_continuation
-          && !abort_empty_line (&current, NULL)
+          && !abort_empty_line (&current, NULL, 0)
           && ((cmd == CM_node || cmd == CM_bye)
               || (command_data(cmd).flags & CF_block)
               || ((command_data(cmd).flags & CF_line)
@@ -2516,7 +2515,7 @@ parse_texi (ELEMENT *root_elt, ELEMENT *current_elt)
                  == ET_internal_spaces_before_argument)
             {
               /* Remove this element and update 'info' values. */
-              abort_empty_line (&current, 0);
+              abort_empty_line (&current, NULL, 0);
             }
 
           e = new_element (ET_empty_line);
@@ -2545,7 +2544,7 @@ parse_texi (ELEMENT *root_elt, ELEMENT *current_elt)
           if (!line)
             {
               debug ("END LINE in line loop STILL_MORE_TO_PROCESS");
-              abort_empty_line (&current, NULL);
+              abort_empty_line (&current, NULL, 0);
               current = end_line (current);
               break;
             }
diff --git a/tp/Texinfo/XS/parsetexi/parser.h b/tp/Texinfo/XS/parsetexi/parser.h
index c16f7fc77f..23bcba7c2b 100644
--- a/tp/Texinfo/XS/parsetexi/parser.h
+++ b/tp/Texinfo/XS/parsetexi/parser.h
@@ -75,7 +75,8 @@ CONDITIONAL_STACK_ITEM *pop_conditional_stack (void);
 CONDITIONAL_STACK_ITEM *top_conditional_stack (void);
 extern size_t conditional_number;
 
-int abort_empty_line (ELEMENT **current_inout, char *additional);
+int abort_empty_line (ELEMENT **current_inout, const char *additional_spaces,
+                      size_t len_text);
 ELEMENT *end_paragraph (ELEMENT *current,
                         enum command_id closed_block_command,
                         enum command_id interrupting_command);
diff --git a/tp/Texinfo/XS/parsetexi/separator.c 
b/tp/Texinfo/XS/parsetexi/separator.c
index 258e71c816..8ddd0bef85 100644
--- a/tp/Texinfo/XS/parsetexi/separator.c
+++ b/tp/Texinfo/XS/parsetexi/separator.c
@@ -202,7 +202,7 @@ handle_open_brace (ELEMENT *current, const char 
**line_inout)
                                || current->parent->type == ET_linemacro_call))
     {
       ELEMENT *b, *e;
-      abort_empty_line (&current, NULL);
+      abort_empty_line (&current, NULL, 0);
       b = new_element (ET_bracketed_arg);
       add_to_element_contents (current, b);
       current = b;
@@ -232,7 +232,7 @@ handle_open_brace (ELEMENT *current, const char 
**line_inout)
     {
       ELEMENT *b = new_element (ET_balanced_braces);
       ELEMENT *open_brace = new_element (ET_NONE);
-      abort_empty_line (&current, NULL);
+      abort_empty_line (&current, NULL, 0);
       b->source_info = current_source_info;
       add_to_element_contents (current, b);
       current = b;
@@ -280,7 +280,7 @@ handle_close_brace (ELEMENT *current, const char 
**line_inout)
   if (current->parent && current->parent->type == ET_brace_command_context
       && current->type == ET_paragraph)
     {
-      abort_empty_line (&current, NULL);
+      abort_empty_line (&current, NULL, 0);
       debug ("IN BRACE_COMMAND_CONTEXT end paragraph");
       current = end_paragraph (current, 0, 0);
     }
@@ -292,14 +292,14 @@ handle_close_brace (ELEMENT *current, const char 
**line_inout)
     }
   else if (current->type == ET_bracketed_arg)
     {
-      abort_empty_line (&current, NULL);
+      abort_empty_line (&current, NULL, 0);
       current = current->parent;
     }
   else if (command_flags(current->parent) & CF_brace)
     {
       enum command_id closed_command;
 
-      abort_empty_line (&current, NULL);
+      abort_empty_line (&current, NULL, 0);
 
       /* determine if trailing spaces are ignored */
       if (command_data(current->parent->cmd).data == BRACE_arguments)
@@ -612,7 +612,7 @@ handle_comma (ELEMENT *current, const char **line_inout)
   enum element_type type;
   ELEMENT *new_arg, *e;
 
-  abort_empty_line (&current, NULL);
+  abort_empty_line (&current, NULL, 0);
   isolate_last_space (current);
 
   type = current->type;



reply via email to

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