texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Mon, 20 May 2024 17:48:41 -0400 (EDT)

branch: master
commit c228bb2a03d3ab1bc4e54a15a79c758a1f951f35
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon May 20 22:53:56 2024 +0200

    * tp/Texinfo/XS/main/tree.c, tp/Texinfo/XS/parsetexi/macro.c: add
    const.
---
 ChangeLog                       |  5 +++
 tp/Texinfo/XS/main/tree.c       |  6 ++--
 tp/Texinfo/XS/main/tree.h       |  6 ++--
 tp/Texinfo/XS/parsetexi/macro.c | 68 ++++++++++++++++++++---------------------
 tp/Texinfo/XS/parsetexi/macro.h |  8 ++---
 5 files changed, 48 insertions(+), 45 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 955689cd85..6e284d120d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-05-20  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/tree.c, tp/Texinfo/XS/parsetexi/macro.c: add
+       const.
+
 2024-05-20  Patrice Dumas  <pertusus@free.fr>
 
        Add const
diff --git a/tp/Texinfo/XS/main/tree.c b/tp/Texinfo/XS/main/tree.c
index 624ae1697c..4c87914c09 100644
--- a/tp/Texinfo/XS/main/tree.c
+++ b/tp/Texinfo/XS/main/tree.c
@@ -488,7 +488,7 @@ pop_element_from_contents (ELEMENT *parent)
 }
 
 ELEMENT *
-last_args_child (ELEMENT *current)
+last_args_child (const ELEMENT *current)
 {
   if (current->args.number == 0)
     return 0;
@@ -506,7 +506,7 @@ last_contents_child (const ELEMENT *current)
 }
 
 ELEMENT *
-contents_child_by_index (ELEMENT *e, int index)
+contents_child_by_index (const ELEMENT *e, int index)
 {
   if (index < 0)
     index = e->contents.number + index;
@@ -518,7 +518,7 @@ contents_child_by_index (ELEMENT *e, int index)
 }
 
 ELEMENT *
-args_child_by_index (ELEMENT *e, int index)
+args_child_by_index (const ELEMENT *e, int index)
 {
   if (index < 0)
     index = e->args.number + index;
diff --git a/tp/Texinfo/XS/main/tree.h b/tp/Texinfo/XS/main/tree.h
index b8419ab6dd..4f99b3794f 100644
--- a/tp/Texinfo/XS/main/tree.h
+++ b/tp/Texinfo/XS/main/tree.h
@@ -31,12 +31,12 @@ ELEMENT *remove_from_element_list (ELEMENT_LIST *list, int 
where);
 ELEMENT *remove_from_contents (ELEMENT *parent, int where);
 ELEMENT *remove_from_args (ELEMENT *parent, int where);
 void remove_slice_from_contents (ELEMENT *parent, int start, int end);
-ELEMENT *last_args_child (ELEMENT *current);
+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 (ELEMENT *e, int index);
-ELEMENT *args_child_by_index (ELEMENT *e, int index);
+ELEMENT *contents_child_by_index (const ELEMENT *e, int index);
+ELEMENT *args_child_by_index (const ELEMENT *e, int index);
 void destroy_list (ELEMENT_LIST *list);
 void destroy_element (ELEMENT *e);
 void destroy_element_and_children (ELEMENT *e);
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index 56a73dad21..7258666cd2 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -64,7 +64,7 @@ lookup_macro_and_slot (enum command_id cmd, size_t *free_slot)
 }
 
 void
-new_macro (char *name, ELEMENT *macro)
+new_macro (const char *name, const ELEMENT *macro)
 {
   enum command_id new;
   MACRO *m = 0;
@@ -267,20 +267,21 @@ parse_macro_command_line (enum command_id cmd, const char 
**line_inout,
 /* Return index into given arguments to look for the value of NAME.
    Return -1 if not found. */
 
-int
-lookup_macro_parameter (const char *name, ELEMENT *macro)
+static int
+lookup_macro_parameter (const char *name, const ELEMENT *macro)
 {
   int i, pos;
-  ELEMENT **args;
+  /* the args_list pointer is const not the ELEMENT */
+  ELEMENT *const *args_list;
 
   /* Find 'arg' in MACRO parameters. */
-  args = macro->args.list;
+  args_list = macro->args.list;
   pos = 0;
   for (i = 0; i < macro->args.number; i++)
     {
-      if (args[i]->type == ET_macro_arg)
+      if (args_list[i]->type == ET_macro_arg)
         {
-          if (!strcmp (args[i]->text.text, name))
+          if (!strcmp (args_list[i]->text.text, name))
             return pos;
           pos++;
         }
@@ -308,8 +309,8 @@ remove_empty_arg (ELEMENT *argument)
 /* LINE points the opening brace in a macro invocation.  CMD is the command
    identifier of the macro command.  Return array of the arguments.  Return
    value to be freed by caller.  */
-void
-expand_macro_arguments (ELEMENT *macro, const char **line_inout,
+static void
+expand_macro_arguments (const ELEMENT *macro, const char **line_inout,
                         enum command_id cmd, ELEMENT *current)
 {
   const char *line = *line_inout;
@@ -453,8 +454,8 @@ funexit:
   *line_inout = line;
 }
 
-void
-set_toplevel_braces_nr (COUNTER *counter, ELEMENT* element)
+static void
+set_toplevel_braces_nr (COUNTER *counter, ELEMENT *element)
 {
   int toplevel_braces_nr = counter_value (counter, element);
   if (toplevel_braces_nr)
@@ -462,8 +463,8 @@ set_toplevel_braces_nr (COUNTER *counter, ELEMENT* element)
   counter_pop (counter);
 }
 
-void
-expand_linemacro_arguments (ELEMENT *macro, const char **line_inout,
+static void
+expand_linemacro_arguments (const ELEMENT *macro, const char **line_inout,
                             enum command_id cmd, ELEMENT *current)
 {
   const char *line = *line_inout;
@@ -668,31 +669,29 @@ expand_linemacro_arguments (ELEMENT *macro, const char 
**line_inout,
 }
 /* ARGUMENTS element holds the arguments used in the macro invocation.
    EXPANDED gets the result of the expansion. */
-void
-expand_macro_body (MACRO *macro_record, ELEMENT *arguments, TEXT *expanded)
+static void
+expand_macro_body (const MACRO *macro_record, const ELEMENT *arguments,
+                   TEXT *expanded)
 {
   int pos; /* Index into arguments. */
-  ELEMENT *macro;
-  char *macrobody;
+  const ELEMENT *macro;
+  const char *macrobody;
   const char *ptext;
 
-  macro = macro_record->element;
-
   macrobody = macro_record->macrobody;
 
-  /* Initialize TEXT object. */
-  expanded->end = 0;
-
   if (!macrobody)
     return;
 
+  macro = macro_record->element;
+
   ptext = macrobody;
   while (1)
     {
       /* At the start of this loop ptext is at the beginning or
          just after the last backslash sequence. */
 
-      char *bs; /* Pointer to next backslash. */
+      const char *bs; /* Pointer to next backslash. */
 
       bs = strchrnul (ptext, '\\');
       text_append_n (expanded, ptext, bs - ptext);
@@ -707,6 +706,7 @@ expand_macro_body (MACRO *macro_record, ELEMENT *arguments, 
TEXT *expanded)
         }
       else
         {
+          char *name;
           bs = strchr (ptext, '\\');
           if (!bs)
             {
@@ -715,29 +715,29 @@ expand_macro_body (MACRO *macro_record, ELEMENT 
*arguments, TEXT *expanded)
               return;
             }
 
-          *bs = '\0';
-          pos = lookup_macro_parameter (ptext, macro);
+          name = strndup (ptext, bs - ptext);
+          pos = lookup_macro_parameter (name, macro);
           if (pos == -1)
             {
               line_error ("\\ in @%s expansion followed `%s' instead of "
                           "parameter name or \\",
-                          macro->args.list[0]->text.text,
-                          ptext);
+                          macro->args.list[0]->text.text, name);
               text_append (expanded, "\\");
-              text_append (expanded, ptext);
+              text_append (expanded, name);
             }
           else
             {
               if (arguments && pos < arguments->args.number)
                 {
-                  ELEMENT *argument = args_child_by_index (arguments, pos);
+                  const ELEMENT *argument
+                    = args_child_by_index (arguments, pos);
                   if (argument->contents.number > 0)
                     text_append (expanded,
                       last_contents_child (
                         args_child_by_index (arguments, pos))->text.text);
                 }
             }
-          *bs = '\\';
+          free (name);
           ptext = bs + 1;
         }
     }
@@ -771,7 +771,7 @@ unset_macro_record (MACRO *m)
 }
 
 void
-delete_macro (char *name)
+delete_macro (const char *name)
 {
   enum command_id cmd;
   MACRO *m;
@@ -804,7 +804,7 @@ handle_macro (ELEMENT *current, const char **line_inout, 
enum command_id cmd)
 {
   const char *line, *p;
   MACRO *macro_record;
-  ELEMENT *macro;
+  const ELEMENT *macro;
   TEXT expanded;
   char *expanded_macro_text;
   int args_number;
@@ -813,7 +813,6 @@ handle_macro (ELEMENT *current, const char **line_inout, 
enum command_id cmd)
   int error = 0;
 
   line = *line_inout;
-  text_init (&expanded);
 
   macro_record = lookup_macro (cmd);
   if (!macro_record)
@@ -961,9 +960,10 @@ handle_macro (ELEMENT *current, const char **line_inout, 
enum command_id cmd)
       goto funexit;
     }
 
+  text_init (&expanded);
   expand_macro_body (macro_record, macro_call_element, &expanded);
 
-  if (expanded.text && expanded.end > 0)
+  if (expanded.end > 0)
     {
       if (expanded.text[expanded.end - 1] == '\n')
         expanded.text[--expanded.end] = '\0';
diff --git a/tp/Texinfo/XS/parsetexi/macro.h b/tp/Texinfo/XS/parsetexi/macro.h
index eba5c366c4..71f2900474 100644
--- a/tp/Texinfo/XS/parsetexi/macro.h
+++ b/tp/Texinfo/XS/parsetexi/macro.h
@@ -27,20 +27,18 @@ typedef struct {
 
 typedef struct {
     char *macro_name;
-    ELEMENT *element;
+    const ELEMENT *element;
     enum command_id cmd;
     char *macrobody;
 } MACRO;
 
-void new_macro (char *name, ELEMENT *macro);
+void new_macro (const char *name, const ELEMENT *macro);
 ELEMENT *parse_macro_command_line (enum command_id, const char **line_inout,
                                    ELEMENT *parent);
 ELEMENT *handle_macro (ELEMENT *current, const char **line_inout,
                        enum command_id cmd_id);
-void delete_macro (char *name);
+void delete_macro (const char *name);
 void unset_macro_record (MACRO *m);
-void expand_macro_body (MACRO *macro_record, ELEMENT *arguments,
-                        TEXT *expanded);
 MACRO *lookup_macro (enum command_id cmd);
 void wipe_macros (void);
 



reply via email to

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