texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Sat, 18 May 2024 19:23:59 -0400 (EDT)

branch: master
commit 1c2debced62c21779fc05e1fb95540115d8c867c
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun May 19 01:23:55 2024 +0200

    * tp/Texinfo/XS/main/document_types.h (VALUE, VALUE_LIST): move VALUE
    definition to document_types.h, define VALUE_LIST.
    
    * tp/Texinfo/XS/parsetexi/macro.c (wipe_values): wipe values from a
    VALUE_LIST passed in argument.
    
    * tp/Texinfo/XS/parsetexi/macro.c (store_value, store_parser_value),
    (parser_values, clear_value, fetch_value),
    tp/Texinfo/XS/parsetexi/handle_commands.c (parse_rawline_command):
    modify store_value to store in a VALUE_LIST passed in argument.  Add
    the parser_values VALUE_LIST variable for the parser, replacing
    value_list, value_number and value_space that are removed.  Add
    store_parser_value that does the same as store_value previously by
    calling store_value with parser_values.  Update fetch_value and
    clear_value to use parser_values.
    
    * tp/Texinfo/XS/parsetexi/Parsetexi.pm (parser),
    tp/Texinfo/XS/parsetexi/Parsetexi.xs (parser_store_values),
    tp/Texinfo/XS/parsetexi/api.c (parser_reset_values_conf)
    (reset_parser_except_conf, reset_parser, parser_store_value),
    tp/Texinfo/XS/parsetexi/conf.c (reset_conf),
    tp/Texinfo/XS/parsetexi/conf.h (CONF), tp/Texinfo/XS/parsetexi/macro.c
    (init_values): add values field in CONF to store default values and
    values from parser initialization.  Pass all the values from Perl hash
    at once through parser_store_values.  Reset the default values in CONF
    in parser_store_values by calling parser_reset_values_conf before
    setting customization values.  Modify reset_conf to set the default for
    CONF values, setting txicommandconditionals.
    Add init_values to initialize the parser values by copying CONF
    values.  Call init_values in reset_parser_except_conf.
    Do not call wipe_values in reset_parser, init_values now initialize
    the parser values based on configuration.
    
    * tp/Texinfo/XS/parsetexi/macro.c (fetch_value): remove the special
    case for txicommandconditionals, it should be set in reset_conf or
    from Perl through parser_store_values.
---
 ChangeLog                                 | 39 +++++++++++++++
 tp/Texinfo/XS/main/document_types.h       | 13 ++++-
 tp/Texinfo/XS/parsetexi/Parsetexi.pm      |  6 +--
 tp/Texinfo/XS/parsetexi/Parsetexi.xs      | 25 ++++++++--
 tp/Texinfo/XS/parsetexi/api.c             | 12 +++--
 tp/Texinfo/XS/parsetexi/api.h             |  1 +
 tp/Texinfo/XS/parsetexi/conf.c            |  3 ++
 tp/Texinfo/XS/parsetexi/conf.h            |  3 ++
 tp/Texinfo/XS/parsetexi/handle_commands.c |  4 +-
 tp/Texinfo/XS/parsetexi/macro.c           | 79 +++++++++++++++++++------------
 tp/Texinfo/XS/parsetexi/macro.h           |  7 ++-
 11 files changed, 145 insertions(+), 47 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b088d936e5..2bcc1edaf5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,42 @@
+2024-05-18  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/document_types.h (VALUE, VALUE_LIST): move VALUE
+       definition to document_types.h, define VALUE_LIST.
+
+       * tp/Texinfo/XS/parsetexi/macro.c (wipe_values): wipe values from a
+       VALUE_LIST passed in argument.
+
+       * tp/Texinfo/XS/parsetexi/macro.c (store_value, store_parser_value),
+       (parser_values, clear_value, fetch_value),
+       tp/Texinfo/XS/parsetexi/handle_commands.c (parse_rawline_command):
+       modify store_value to store in a VALUE_LIST passed in argument.  Add
+       the parser_values VALUE_LIST variable for the parser, replacing
+       value_list, value_number and value_space that are removed.  Add
+       store_parser_value that does the same as store_value previously by
+       calling store_value with parser_values.  Update fetch_value and
+       clear_value to use parser_values.  
+
+       * tp/Texinfo/XS/parsetexi/Parsetexi.pm (parser),
+       tp/Texinfo/XS/parsetexi/Parsetexi.xs (parser_store_values),
+       tp/Texinfo/XS/parsetexi/api.c (parser_reset_values_conf)
+       (reset_parser_except_conf, reset_parser, parser_store_value),
+       tp/Texinfo/XS/parsetexi/conf.c (reset_conf),
+       tp/Texinfo/XS/parsetexi/conf.h (CONF), tp/Texinfo/XS/parsetexi/macro.c
+       (init_values): add values field in CONF to store default values and
+       values from parser initialization.  Pass all the values from Perl hash
+       at once through parser_store_values.  Reset the default values in CONF
+       in parser_store_values by calling parser_reset_values_conf before
+       setting customization values.  Modify reset_conf to set the default for
+       CONF values, setting txicommandconditionals.
+       Add init_values to initialize the parser values by copying CONF
+       values.  Call init_values in reset_parser_except_conf.
+       Do not call wipe_values in reset_parser, init_values now initialize
+       the parser values based on configuration.
+
+       * tp/Texinfo/XS/parsetexi/macro.c (fetch_value): remove the special
+       case for txicommandconditionals, it should be set in reset_conf or
+       from Perl through parser_store_values.
+
 2024-05-18  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/parsetexi/api.c (reset_parser, parse_file): call
diff --git a/tp/Texinfo/XS/main/document_types.h 
b/tp/Texinfo/XS/main/document_types.h
index e1a73a07b1..95cb07e535 100644
--- a/tp/Texinfo/XS/main/document_types.h
+++ b/tp/Texinfo/XS/main/document_types.h
@@ -206,10 +206,21 @@ typedef struct DOCUMENT {
     unsigned long modified_information;
 } DOCUMENT;
 
-/* not in document, but used in parser */
+/* following not in document, but used in parser */
 typedef struct EXPANDED_FORMAT {
     char *format;
     int expandedp;
 } EXPANDED_FORMAT;
 
+typedef struct {
+    char *name;
+    char *value;
+} VALUE;
+
+typedef struct {
+    size_t number;
+    size_t space;
+    VALUE *list;
+} VALUE_LIST;
+
 #endif
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm 
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index 8dcaa1295d..6b29e3cd26 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -105,11 +105,7 @@ sub parser (;$$)
           parser_add_include_directory ($d);
         }
       } elsif ($key eq 'values') {
-        for my $flag (keys %{$conf->{'values'}}) {
-          my $bytes_flag = Encode::encode('utf-8', $flag);
-          my $bytes_value = Encode::encode('utf-8', 
$conf->{'values'}->{$flag});
-          parser_store_value ($bytes_flag, $bytes_value);
-        }
+        parser_store_values($conf->{'values'});
       } elsif ($key eq 'EXPANDED_FORMATS') {
         parser_clear_expanded_formats ();
 
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.xs 
b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
index 3ab533de41..7eff083c9f 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
@@ -104,9 +104,28 @@ void
 pass_document_parser_errors_to_registrar (int document_descriptor, SV 
*parser_sv)
 
 void
-parser_store_value (name, value)
-        char *name = (char *)SvPVbyte_nolen($arg);
-        char *value = (char *)SvPVbyte_nolen($arg);
+parser_store_values (SV *values)
+      CODE:
+        parser_reset_values_conf ();
+        if (SvOK (values))
+          {
+            I32 i;
+            HV *values_hv = (HV *)SvRV (values);
+            I32 hv_number = hv_iterinit (values_hv);
+
+            for (i = 0; i < hv_number; i++)
+              {
+                HE *next = hv_iternext (values_hv);
+                SV *flag_sv = hv_iterkeysv (next);
+                char *key = SvPVutf8_nolen (flag_sv);
+                SV *value_sv = hv_iterval (values_hv, next);
+                if (value_sv && SvOK (value_sv))
+                  {
+                    char *value_text = SvPVutf8_nolen (value_sv);
+                    parser_store_value (key, value_text);
+                  }
+              }
+          }
 
 # file path, can be in any encoding
 void
diff --git a/tp/Texinfo/XS/parsetexi/api.c b/tp/Texinfo/XS/parsetexi/api.c
index cb318a5f4e..e74f284de4 100644
--- a/tp/Texinfo/XS/parsetexi/api.c
+++ b/tp/Texinfo/XS/parsetexi/api.c
@@ -38,7 +38,7 @@
 #include "context_stack.h"
 /* for clear_parser_expanded_formats and add_parser_expanded_format */
 #include "handle_commands.h"
-/* for wipe_macros and store_value */
+/* for wipe_macros store_value init_values */
 #include "macro.h"
 #include "document.h"
 /* for reset_conf */
@@ -52,6 +52,7 @@ reset_parser_except_conf (void)
 
   wipe_user_commands ();
   wipe_macros ();
+  init_values ();
 
   reset_context_stack ();
   reset_command_stack (&nesting_context.basic_inline_stack);
@@ -85,7 +86,6 @@ reset_parser (int local_debug_output)
     fprintf (stderr,
           "!!!!!!!!!!!!!!!! RESETTING THE PARSER !!!!!!!!!!!!!!!!!!!!!\n");
 
-  wipe_values ();
   clear_parser_expanded_formats ();
   parser_clear_include_directories ();
   reset_conf ();
@@ -242,10 +242,16 @@ parser_set_locale_encoding (const char *value)
   set_locale_encoding (value);
 }
 
+void
+parser_reset_values_conf (void)
+{
+  conf.values.number = 0;
+}
+
 void
 parser_store_value (const char *name, const char *value)
 {
-  store_value (name, value);
+  store_value (&conf.values, name, value);
 }
 
 void
diff --git a/tp/Texinfo/XS/parsetexi/api.h b/tp/Texinfo/XS/parsetexi/api.h
index 83df805a76..690e1ae858 100644
--- a/tp/Texinfo/XS/parsetexi/api.h
+++ b/tp/Texinfo/XS/parsetexi/api.h
@@ -13,6 +13,7 @@ void reset_parser (int debug_output);
 void reset_parser_except_conf (void);
 
 int parser_set_debug (int value);
+void parser_reset_values_conf (void);
 void parser_store_value (const char *name, const char *value);
 void parser_add_include_directory (const char *filename);
 void parser_add_expanded_format (const char *format);
diff --git a/tp/Texinfo/XS/parsetexi/conf.c b/tp/Texinfo/XS/parsetexi/conf.c
index 4842af566c..aa186cc763 100644
--- a/tp/Texinfo/XS/parsetexi/conf.c
+++ b/tp/Texinfo/XS/parsetexi/conf.c
@@ -17,6 +17,7 @@
 #include <string.h>
 
 #include "tree_types.h"
+#include "macro.h"
 #include "conf.h"
 
 /* Configuration values. */
@@ -70,4 +71,6 @@ reset_conf (void)
   conf.cpp_line_directives = 1;
   conf.ignore_space_after_braced_command_name = 1;
   conf.max_macro_call_nesting = 100000;
+  conf.values.number = 0;
+  store_value (&conf.values, "txicommandconditionals", "1");
 }
diff --git a/tp/Texinfo/XS/parsetexi/conf.h b/tp/Texinfo/XS/parsetexi/conf.h
index 0fd6dd8fb2..57cfe2c1e7 100644
--- a/tp/Texinfo/XS/parsetexi/conf.h
+++ b/tp/Texinfo/XS/parsetexi/conf.h
@@ -16,6 +16,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
+#include "document_types.h"
+
 typedef struct CONF {
     int show_menu;
     int cpp_line_directives;
@@ -23,6 +25,7 @@ typedef struct CONF {
     int max_macro_call_nesting;
     int no_index;
     int no_user_commands;
+    VALUE_LIST values;
 } CONF;
 
 extern CONF conf;
diff --git a/tp/Texinfo/XS/parsetexi/handle_commands.c 
b/tp/Texinfo/XS/parsetexi/handle_commands.c
index efe67acf8c..d9087be7bf 100644
--- a/tp/Texinfo/XS/parsetexi/handle_commands.c
+++ b/tp/Texinfo/XS/parsetexi/handle_commands.c
@@ -221,8 +221,8 @@ parse_rawline_command (char *line, enum command_id cmd,
       else
         ADD_ARG("", 0);
 
-      store_value (args->contents.list[0]->text.text,
-                   args->contents.list[1]->text.text);
+      store_parser_value (args->contents.list[0]->text.text,
+                          args->contents.list[1]->text.text);
 
       break;
     set_no_name:
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index 79c5d6b7a2..5ae27bab64 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -24,6 +24,8 @@
 #include "utils.h"
 #include "tree.h"
 #include "tree_types.h"
+/* for VALUE */
+#include "document_types.h"
 #include "debug_parser.h"
 #include "errors_parser.h"
 #include "text.h"
@@ -1005,29 +1007,39 @@ handle_macro (ELEMENT *current, char **line_inout, enum 
command_id cmd)
 
 /* @set and @value */
 
-typedef struct {
-    char *name;
-    char *value;
-} VALUE;
+static VALUE_LIST parser_values;
 
-static VALUE *value_list;
-static size_t value_number;
-static size_t value_space;
+void
+wipe_values (VALUE_LIST *values)
+{
+  size_t i;
+  for (i = 0; i < values->number; i++)
+    {
+      free (values->list[i].name);
+      free (values->list[i].value);
+    }
+  values->number = 0;
+}
 
 void
-wipe_values (void)
+init_values (void)
 {
   size_t i;
-  for (i = 0; i < value_number; i++)
+
+  parser_values.number = 0;
+  if (parser_values.space < conf.values.number)
     {
-      free (value_list[i].name);
-      free (value_list[i].value);
+      parser_values.space = conf.values.number;
+      parser_values.list = realloc (parser_values.list,
+                                    parser_values.space * sizeof (VALUE));
     }
-  value_number = 0;
+  for (i = 0; i < conf.values.number; i++)
+    store_value (&parser_values, conf.values.list[i].name,
+                 conf.values.list[i].value);
 }
 
 void
-store_value (const char *name, const char *value)
+store_value (VALUE_LIST *values, const char *name, const char *value)
 {
   int i;
   VALUE *v = 0;
@@ -1036,11 +1048,12 @@ store_value (const char *name, const char *value)
   len = strlen (name);
 
   /* Check if already defined. */
-  for (i = 0; i < value_number; i++)
+  for (i = 0; i < values->number; i++)
     {
-      if (!strncmp (value_list[i].name, name, len) && !value_list[i].name[len])
+      if (!strncmp (values->list[i].name, name, len)
+          && !values->list[i].name[len])
         {
-          v = &value_list[i];
+          v = &values->list[i];
           free (v->name); free (v->value);
           break;
         }
@@ -1048,11 +1061,12 @@ store_value (const char *name, const char *value)
 
   if (!v)
     {
-      if (value_number == value_space)
+      if (values->number == values->space)
         {
-          value_list = realloc (value_list, (value_space += 5) * sizeof 
(VALUE));
+          values->list = realloc (values->list,
+                                  (values->space += 5) * sizeof (VALUE));
         }
-      v = &value_list[value_number++];
+      v = &values->list[values->number++];
     }
 
   v->name = strdup (name);
@@ -1078,16 +1092,23 @@ store_value (const char *name, const char *value)
     }
 }
 
+void
+store_parser_value (const char *name, const char *value)
+{
+  store_value (&parser_values, name, value);
+}
+
 void
 clear_value (char *name)
 {
   int i;
-  for (i = 0; i < value_number; i++)
+  VALUE_LIST *values = &parser_values;
+  for (i = 0; i < values->number; i++)
     {
-      if (!strcmp (value_list[i].name, name))
+      if (!strcmp (values->list[i].name, name))
         {
-          value_list[i].name[0] = '\0';
-          value_list[i].value[0] = '\0';
+          values->list[i].name[0] = '\0';
+          values->list[i].value[0] = '\0';
         }
     }
   /* Internal Texinfo flag */
@@ -1113,17 +1134,13 @@ char *
 fetch_value (char *name)
 {
   int i;
-  for (i = 0; i < value_number; i++)
+  VALUE_LIST *values = &parser_values;
+  for (i = 0; i < values->number; i++)
     {
-      if (!strcmp (value_list[i].name, name))
-        return value_list[i].value;
+      if (!strcmp (values->list[i].name, name))
+        return values->list[i].value;
     }
 
-  /* special value always returned as 1 to mark that @ifcommandnotdefined
-      is implemented.  Note that in most cases it is also set from perl
-      using the configuration passed to the parser */
-  if (!strcmp (name, "txicommandconditionals"))
-    return "1";
   return 0;
 }
 
diff --git a/tp/Texinfo/XS/parsetexi/macro.h b/tp/Texinfo/XS/parsetexi/macro.h
index 91f659ac68..a3b500777b 100644
--- a/tp/Texinfo/XS/parsetexi/macro.h
+++ b/tp/Texinfo/XS/parsetexi/macro.h
@@ -17,6 +17,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "tree_types.h"
+#include "document_types.h"
 
 typedef struct {
     enum command_id cmd;
@@ -43,10 +44,12 @@ void expand_macro_body (MACRO *macro_record, ELEMENT 
*arguments,
 MACRO *lookup_macro (enum command_id cmd);
 void wipe_macros (void);
 
-void store_value (const char *name, const char *value);
+void store_value (VALUE_LIST *values, const char *name, const char *value);
 char *fetch_value (char *name);
 void clear_value (char *name);
-void wipe_values (void);
+void wipe_values (VALUE_LIST *values);
+void init_values (void);
+void store_parser_value (const char *name, const char *value);
 
 INFO_ENCLOSE *lookup_infoenclose (enum command_id cmd);
 void add_infoenclose (enum command_id cmd, char *begin, char *end);



reply via email to

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