texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Fri, 4 Oct 2024 06:29:44 -0400 (EDT)

branch: master
commit 54955d9f9272ea6356bb675c135f95f310e07473
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Aug 12 11:32:28 2024 +0200

    * tp/Texinfo/XS/parsetexi/menus.c (handle_menu_entry_separators):
    determine a positive index for entry_name.
    
    * tp/Texinfo/XS/parsetexi/menus.c (end_line_menu_entry): use the
    position just after the index in loop.
    
    * tp/Texinfo/XS/parsetexi/parser.c (begin_paragraph): use a for loop
    to find preceding @*indent.
    
    * tp/Texinfo/XS/main/tree.c (contents_child_by_index)
    (args_child_by_index): use size_t for indices.  Remove the possibility
    to add at the end with a negative index, the caller should be able to
    compute the index.
---
 ChangeLog                        | 16 ++++++++++++++++
 tp/Texinfo/XS/main/tree.c        | 14 ++++----------
 tp/Texinfo/XS/main/tree.h        |  4 ++--
 tp/Texinfo/XS/parsetexi/menus.c  | 11 ++++++-----
 tp/Texinfo/XS/parsetexi/parser.c |  9 ++++-----
 5 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7dc4f70b1a..90c17d42a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2024-08-12  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/parsetexi/menus.c (handle_menu_entry_separators):
+       determine a positive index for entry_name.
+
+       * tp/Texinfo/XS/parsetexi/menus.c (end_line_menu_entry): use the
+       position just after the index in loop.
+
+       * tp/Texinfo/XS/parsetexi/parser.c (begin_paragraph): use a for loop
+       to find preceding @*indent.
+
+       * tp/Texinfo/XS/main/tree.c (contents_child_by_index)
+       (args_child_by_index): use size_t for indices.  Remove the possibility
+       to add at the end with a negative index, the caller should be able to
+       compute the index.
+
 2024-08-12  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/parsetexi/def.c (gather_def_item): start indices from
diff --git a/tp/Texinfo/XS/main/tree.c b/tp/Texinfo/XS/main/tree.c
index d14ec324c1..741b673c29 100644
--- a/tp/Texinfo/XS/main/tree.c
+++ b/tp/Texinfo/XS/main/tree.c
@@ -630,24 +630,18 @@ last_contents_child (const ELEMENT *current)
 }
 
 ELEMENT *
-contents_child_by_index (const ELEMENT *e, int index)
+contents_child_by_index (const ELEMENT *e, size_t index)
 {
-  if (index < 0)
-    index = e->e.c->contents.number + index;
-
-  if (index < 0 || index >= e->e.c->contents.number)
+  if (index >= e->e.c->contents.number)
     return 0;
 
   return e->e.c->contents.list[index];
 }
 
 ELEMENT *
-args_child_by_index (const ELEMENT *e, int index)
+args_child_by_index (const ELEMENT *e, size_t index)
 {
-  if (index < 0)
-    index = e->e.c->args.number + index;
-
-  if (index < 0 || index >= e->e.c->args.number)
+  if (index >= e->e.c->args.number)
     return 0;
 
   return e->e.c->args.list[index];
diff --git a/tp/Texinfo/XS/main/tree.h b/tp/Texinfo/XS/main/tree.h
index f02cc23b37..16cc50513b 100644
--- a/tp/Texinfo/XS/main/tree.h
+++ b/tp/Texinfo/XS/main/tree.h
@@ -42,8 +42,8 @@ ELEMENT *last_args_child (const ELEMENT *current);
 ELEMENT *last_contents_child (const ELEMENT *current);
 ELEMENT *pop_element_from_args (ELEMENT *parent);
 ELEMENT *pop_element_from_contents (ELEMENT *parent);
-ELEMENT *contents_child_by_index (const ELEMENT *e, int index);
-ELEMENT *args_child_by_index (const ELEMENT *e, int index);
+ELEMENT *contents_child_by_index (const ELEMENT *e, size_t index);
+ELEMENT *args_child_by_index (const ELEMENT *e, size_t index);
 void destroy_list (ELEMENT_LIST *list);
 void destroy_const_element_list (CONST_ELEMENT_LIST *list);
 void destroy_element (ELEMENT *e);
diff --git a/tp/Texinfo/XS/parsetexi/menus.c b/tp/Texinfo/XS/parsetexi/menus.c
index f22fced747..3573803a09 100644
--- a/tp/Texinfo/XS/parsetexi/menus.c
+++ b/tp/Texinfo/XS/parsetexi/menus.c
@@ -246,7 +246,7 @@ handle_menu_entry_separators (ELEMENT **current_inout, 
const char **line_inout)
       /* here we collect spaces following separators. */
       else if (strchr (whitespace_chars_except_newline, *line))
         {
-          int n;
+          size_t n;
 
           n = strspn (line, whitespace_chars_except_newline);
           text_append_n (last_element->e.text, line, n);
@@ -258,7 +258,8 @@ handle_menu_entry_separators (ELEMENT **current_inout, 
const char **line_inout)
           ELEMENT *entry_name;
 
           debug ("MENU NODE done (change from menu entry name) %s", separator);
-          entry_name = contents_child_by_index (current, -2);
+          entry_name = contents_child_by_index (current,
+                                            current->e.c->contents.number - 2);
 
           /* Change from menu_entry_name (i.e. a label)
              to a menu entry node */
@@ -335,12 +336,12 @@ end_line_menu_entry (ELEMENT *current)
           && last_contents_child (menu)->type == ET_menu_entry)
         {
           ELEMENT *entry, *description = 0;
-          int j;
+          size_t j;
 
           entry = last_contents_child (menu);
-          for (j = entry->e.c->contents.number - 1; j >= 0; j--)
+          for (j = entry->e.c->contents.number; j > 0; j--)
             {
-              ELEMENT *e = contents_child_by_index (entry, j);
+              ELEMENT *e = contents_child_by_index (entry, j - 1);
               if (e->type == ET_menu_entry_description)
                 {
                   description = e;
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index b1ec5722c4..352eb1cced 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -588,15 +588,15 @@ begin_paragraph (ELEMENT *current)
 {
   ELEMENT *e;
   enum command_id indent = 0;
+  size_t j;
 
   /* Check if an @indent precedes the paragraph (to record it
      in the 'extra' key). */
   if (current->e.c->contents.number > 0)
     {
-      int i = current->e.c->contents.number - 1;
-      while (i >= 0)
+      for (j = current->e.c->contents.number; j > 0; j--)
         {
-          ELEMENT *child = contents_child_by_index (current, i);
+          ELEMENT *child = contents_child_by_index (current, j - 1);
           if (child->type == ET_empty_line
               || child->type == ET_paragraph)
             break;
@@ -622,7 +622,6 @@ begin_paragraph (ELEMENT *current)
             fprintf(stderr, "INDENT search skipping through %s\n",
                     print_element_debug_parser(child, 0));
             */
-          i--;
         }
     }
 
@@ -1528,7 +1527,7 @@ process_macro_block_contents (ELEMENT *current, const 
char **line_out)
                   ELEMENT *e;
                   char *name;
                   enum command_id existing;
-                  int n;
+                  size_t n;
 
                   n = strspn (line, whitespace_chars);
 



reply via email to

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