texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/parsetexi/macro.c (handle_macro),


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/parsetexi/macro.c (handle_macro), tp/Texinfo/XS/parsetexi/menus.c (handle_menu_entry_separators) (end_line_menu_entry), tp/Texinfo/XS/parsetexi/parser.c (merge_text) (process_remaining_on_line), tp/Texinfo/XS/parsetexi/separator.c (handle_open_brace, handle_close_brace): add a text length argument to merge_text. Update merge_text and callers.
Date: Mon, 27 May 2024 13:52:05 -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 bf103fbbd0 * tp/Texinfo/XS/parsetexi/macro.c (handle_macro), 
tp/Texinfo/XS/parsetexi/menus.c (handle_menu_entry_separators) 
(end_line_menu_entry), tp/Texinfo/XS/parsetexi/parser.c (merge_text) 
(process_remaining_on_line), tp/Texinfo/XS/parsetexi/separator.c 
(handle_open_brace, handle_close_brace): add a text length argument to 
merge_text.  Update merge_text and callers.
bf103fbbd0 is described below

commit bf103fbbd0a7ded71af50cb02956fd8d7753cc0e
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon May 27 19:51:55 2024 +0200

    * tp/Texinfo/XS/parsetexi/macro.c (handle_macro),
    tp/Texinfo/XS/parsetexi/menus.c (handle_menu_entry_separators)
    (end_line_menu_entry), tp/Texinfo/XS/parsetexi/parser.c (merge_text)
    (process_remaining_on_line), tp/Texinfo/XS/parsetexi/separator.c
    (handle_open_brace, handle_close_brace): add a text length argument to
    merge_text.  Update merge_text and callers.
    
    * tp/Texinfo/XS/parsetexi/close.c (close_current): use text_append_n
    instead of text_append.
    
    * tp/Texinfo/XS/parsetexi/multitable.c (gather_previous_item): output
    REPARENT debug message only if there are contents in before_item.
---
 ChangeLog                            | 15 ++++++++
 tp/Texinfo/XS/parsetexi/close.c      |  2 +-
 tp/Texinfo/XS/parsetexi/macro.c      |  8 ++---
 tp/Texinfo/XS/parsetexi/menus.c      |  8 +++--
 tp/Texinfo/XS/parsetexi/multitable.c |  3 +-
 tp/Texinfo/XS/parsetexi/parser.c     | 66 ++++++++++++++++++++----------------
 tp/Texinfo/XS/parsetexi/parser.h     |  2 +-
 tp/Texinfo/XS/parsetexi/separator.c  |  6 ++--
 8 files changed, 68 insertions(+), 42 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a0a0dd11a7..32ca42028b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2024-05-27  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/parsetexi/macro.c (handle_macro),
+       tp/Texinfo/XS/parsetexi/menus.c (handle_menu_entry_separators)
+       (end_line_menu_entry), tp/Texinfo/XS/parsetexi/parser.c (merge_text)
+       (process_remaining_on_line), tp/Texinfo/XS/parsetexi/separator.c
+       (handle_open_brace, handle_close_brace): add a text length argument to
+       merge_text.  Update merge_text and callers.
+
+       * tp/Texinfo/XS/parsetexi/close.c (close_current): use text_append_n
+       instead of text_append.
+
+       * tp/Texinfo/XS/parsetexi/multitable.c (gather_previous_item): output
+       REPARENT debug message only if there are contents in before_item.
+
 2024-05-27  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/ParserNonXS.pm (_gather_previous_item),
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index 52c01244fd..3da17af218 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -456,7 +456,7 @@ close_current (ELEMENT *current,
              be at the end of the document after an empty line we
              do not want to modify */
           /* current = merge_text (current, "}", 0); */
-          text_append (&close_brace->text, "}");
+          text_append_n (&close_brace->text, "}", 1);
           add_to_element_contents (current, close_brace);
           current = current->parent;
           break;
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index 400d9d129b..bdcf34c0fa 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -937,13 +937,13 @@ handle_macro (ELEMENT *current, const char **line_inout, 
enum command_id cmd)
                       char *p = strchr (line, '\n');
                       if (!p)
                         {
-                          arg_elt = merge_text (arg_elt, line, 0);
-                          line += strlen (line);
+                          size_t line_len = strlen (line);
+                          arg_elt = merge_text (arg_elt, line, line_len, 0);
+                          line += line_len;
                         }
                       else
                         {
-                          *p = '\0';
-                          arg_elt = merge_text (arg_elt, line, 0);
+                          arg_elt = merge_text (arg_elt, line, (p - line), 0);
                           line = "\n";
                           break;
                         }
diff --git a/tp/Texinfo/XS/parsetexi/menus.c b/tp/Texinfo/XS/parsetexi/menus.c
index d866a8a673..7c83f29d99 100644
--- a/tp/Texinfo/XS/parsetexi/menus.c
+++ b/tp/Texinfo/XS/parsetexi/menus.c
@@ -242,7 +242,8 @@ handle_menu_entry_separators (ELEMENT **current_inout, 
const char **line_inout)
         {
           pop_element_from_contents (current);
           current = last_contents_child (current);
-          merge_text (current, last_child->text.text, last_child);
+          merge_text (current, last_child->text.text, last_child->text.end,
+                      last_child);
           destroy_element (last_child);
         }
       /* here we collect spaces following separators. */
@@ -395,7 +396,7 @@ end_line_menu_entry (ELEMENT *current)
         {
           ELEMENT *arg = contents_child_by_index (menu_entry, i);
           if (arg->text.end > 0)
-            current = merge_text (current, arg->text.text, arg);
+            current = merge_text (current, arg->text.text, arg->text.end, arg);
           else
             {
               ELEMENT *e;
@@ -404,7 +405,8 @@ end_line_menu_entry (ELEMENT *current)
                   e = contents_child_by_index (arg, j);
                   if (e->text.end > 0)
                     {
-                      current = merge_text (current, e->text.text, e);
+                      current = merge_text (current, e->text.text,
+                                            e->text.end, e);
                       destroy_element (e);
                     }
                   else
diff --git a/tp/Texinfo/XS/parsetexi/multitable.c 
b/tp/Texinfo/XS/parsetexi/multitable.c
index 37a2575dd0..ac45276002 100644
--- a/tp/Texinfo/XS/parsetexi/multitable.c
+++ b/tp/Texinfo/XS/parsetexi/multitable.c
@@ -150,7 +150,8 @@ gather_previous_item (ELEMENT *current, enum command_id 
next_command)
       remove_slice_from_contents (current, term_begin, begin);
       if (before_item)
         {
-          debug ("REPARENT before_item content");
+          if (before_item->contents.number > 0)
+            debug ("REPARENT before_item content");
           /* Reparent any trailing index entries in the before_item to the
              beginning of table term. */
           while (before_item->contents.number > 0
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index a11f19f73a..0fbb813021 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -652,14 +652,20 @@ end_preformatted (ELEMENT *current,
    from that element.
    */
 ELEMENT *
-merge_text (ELEMENT *current, const char *text, ELEMENT 
*transfer_marks_element)
+merge_text (ELEMENT *current, const char *text, size_t len_text,
+            ELEMENT *transfer_marks_element)
 {
   int no_merge_with_following_text = 0;
-  int leading_spaces = strspn (text, whitespace_chars);
+  int leading_spaces = 0;
   ELEMENT *last_child = last_contents_child (current);
 
+  /* determine the number of leading characters in whitespace_chars */
+  for (; leading_spaces < len_text
+         && strchr (whitespace_chars, text[leading_spaces]);
+       leading_spaces++);
+
   /* Is there a non-whitespace character in the line? */
-  if (text[leading_spaces])
+  if (leading_spaces < len_text)
     {
       char *additional = 0;
 
@@ -682,7 +688,10 @@ merge_text (ELEMENT *current, const char *text, ELEMENT 
*transfer_marks_element)
         }
 
       if (abort_empty_line (&current, additional))
-        text += leading_spaces;
+        {
+          text += leading_spaces;
+          len_text -= leading_spaces;
+        }
 
       free (additional);
 
@@ -718,22 +727,32 @@ merge_text (ELEMENT *current, const char *text, ELEMENT 
*transfer_marks_element)
           transfer_marks_element->source_mark_list.number = 0;
         }
 
-      debug_nonl ("MERGED TEXT: %s||| in ", text);
-      debug_parser_print_element (last_child, 0);
-      debug_nonl (" last of ");
-      debug_parser_print_element (current, 0); debug ("");
+      if (global_parser_conf.debug)
+        {
+          char *dbg_text = strndup (text, len_text);
+          debug_nonl ("MERGED TEXT: %s||| in ", dbg_text);
+          free (dbg_text);
+          debug_parser_print_element (last_child, 0);
+          debug_nonl (" last of ");
+          debug_parser_print_element (current, 0); debug ("");
+        }
 
       /* Append text */
-      text_append (&last_child->text, text);
+      text_append_n (&last_child->text, text, len_text);
     }
   else
     {
       ELEMENT *e = new_element (ET_NONE);
       if (transfer_marks_element)
         transfer_source_marks (transfer_marks_element, e);
-      text_append (&e->text, text);
+      text_append_n (&e->text, text, len_text);
       add_to_element_contents (current, e);
-      debug ("NEW TEXT (merge): %s|||", text);
+      if (global_parser_conf.debug)
+        {
+          char *dbg_text = strndup (text, len_text);
+          debug ("NEW TEXT (merge): %s|||", dbg_text);
+          free (dbg_text);
+        }
     }
 
   return current;
@@ -1963,14 +1982,10 @@ process_remaining_on_line (ELEMENT **current_inout, 
const char **line_inout)
                     /* do not consider the end of line to be possibly between
                        the @-command and the argument if at the end of a
                        line or block @-command. */
-                       char *space_text;
                        if (current->contents.number > 0)
                          gather_spaces_after_cmd_before_arg (current);
                        current = current->parent;
-                       /* TODO: Have a length argument to merge_text? */
-                       space_text = strndup (line, whitespaces_len);
-                       current = merge_text (current, space_text, 0);
-                       free (space_text);
+                       current = merge_text (current, line, whitespaces_len, 
0);
                        line += whitespaces_len;
                        isolate_last_space (current);
                        current = end_line (current);
@@ -2356,16 +2371,13 @@ process_remaining_on_line (ELEMENT **current_inout, 
const char **line_inout)
       else if (current->type == ET_line_arg && current->parent->cmd == CM_node)
         line_warn ("superfluous arguments for node");
       else
-        current = merge_text (current, ",", 0);
+        current = merge_text (current, ",", 1, 0);
     }
   else if (strchr (":\t.", *line))
     {
       /* merge menu separator (other than comma) */
-      char separator = *line++;
-      char t[2];
-      t[0] = separator;
-      t[1] = '\0';
-      current = merge_text (current, t, 0);
+      current = merge_text (current, line, 1, 0);
+      line++;
     }
   else if (*line == '\f')
     {
@@ -2385,7 +2397,7 @@ process_remaining_on_line (ELEMENT **current_inout, const 
char **line_inout)
           add_to_element_contents (current, e);
         }
       else
-       current = merge_text (current, "\f", 0);
+       current = merge_text (current, "\f", 1, 0);
     }
   /* Misc text except end of line. */
   else if (*line != '\n')
@@ -2394,12 +2406,8 @@ process_remaining_on_line (ELEMENT **current_inout, 
const char **line_inout)
 
       /* Output until next command, separator or newline. */
       {
-        char *sep_text;
         len = strcspn (line, "{}@,:\t.\n\f");
-        /* TODO: Have a length argument to merge_text? */
-        sep_text = strndup (line, len);
-        current = merge_text (current, sep_text, 0);
-        free (sep_text);
+        current = merge_text (current, line, len, 0);
         line += len;
       }
     }
@@ -2411,7 +2419,7 @@ process_remaining_on_line (ELEMENT **current_inout, const 
char **line_inout)
 
       if (*line == '\n')
         {
-          current = merge_text (current, "\n", 0);
+          current = merge_text (current, "\n", 1, 0);
           line++;
         }
       else
diff --git a/tp/Texinfo/XS/parsetexi/parser.h b/tp/Texinfo/XS/parsetexi/parser.h
index df4e080cae..c16f7fc77f 100644
--- a/tp/Texinfo/XS/parsetexi/parser.h
+++ b/tp/Texinfo/XS/parsetexi/parser.h
@@ -90,7 +90,7 @@ ELEMENT *end_preformatted (ELEMENT *current,
 char *read_command_name (const char **ptr);
 const char *read_comment (const char *line, int *has_comment);
 char *text_contents_to_plain_text (ELEMENT *e, int *superfluous_arg);
-ELEMENT *merge_text (ELEMENT *current, const char *text,
+ELEMENT *merge_text (ELEMENT *current, const char *text, size_t text_len,
                      ELEMENT *transfer_marks_element);
 void start_empty_line_after_command (ELEMENT *current, const char **line_inout,
                                      ELEMENT *command);
diff --git a/tp/Texinfo/XS/parsetexi/separator.c 
b/tp/Texinfo/XS/parsetexi/separator.c
index 9372066371..258e71c816 100644
--- a/tp/Texinfo/XS/parsetexi/separator.c
+++ b/tp/Texinfo/XS/parsetexi/separator.c
@@ -220,7 +220,7 @@ handle_open_brace (ELEMENT *current, const char 
**line_inout)
   else if (current->type == ET_rawpreformatted)
     {
       debug ("LONE OPEN BRACE in rawpreformatted");
-      current = merge_text (current, "{", 0);
+      current = merge_text (current, "{", 1, 0);
     }
   /* matching braces accepted in a rawpreformatted, inline raw or
      math.  Note that for rawpreformatted, it can only happen
@@ -287,7 +287,7 @@ handle_close_brace (ELEMENT *current, const char 
**line_inout)
 
   if (current->type == ET_balanced_braces)
     {
-      current = merge_text (current, "}", 0);
+      current = merge_text (current, "}", 1, 0);
       current = current->parent;
     }
   else if (current->type == ET_bracketed_arg)
@@ -592,7 +592,7 @@ handle_close_brace (ELEMENT *current, const char 
**line_inout)
   else if (current->type == ET_rawpreformatted)
     {
       /* lone right braces are accepted in a rawpreformatted */
-      current = merge_text (current, "}", 0);
+      current = merge_text (current, "}", 1, 0);
     }
   else
     {



reply via email to

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