texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Replace parser_expanded_formats by const.expanded


From: Patrice Dumas
Subject: branch master updated: Replace parser_expanded_formats by const.expanded_formats
Date: Mon, 20 May 2024 03:36:57 -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 172b2495f9 Replace parser_expanded_formats by const.expanded_formats
172b2495f9 is described below

commit 172b2495f9b05a84310aa8e026ae70ebc1a3afd2
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon May 20 09:36:59 2024 +0200

    Replace parser_expanded_formats by const.expanded_formats
    
    * tp/Texinfo/XS/main/utils.h: rename expanded_formats as
    default_expanded_formats, make it const and extern.
    
    * tp/Texinfo/XS/parsetexi/Parsetexi.pm (parser),
    tp/Texinfo/XS/parsetexi/Parsetexi.xs (conf_clear_expanded_formats)
    (conf_add_expanded_format), tp/Texinfo/XS/parsetexi/api.c
    (reset_parser), tp/Texinfo/XS/parsetexi/conf.c (reset_conf)
    (conf_clear_expanded_formats, conf_add_expanded_format): add
    expanded_formats in CONF, add conf_clear_expanded_formats to clear,
    conf_add_expanded_format to add expanded formats and replace
    parser_expanded_formats by const.expanded_formats. Remove
    parser_clear_expanded_formats and parser_add_expanded_format.
    
    This changes the default expanded formats to be none, which matches
    Perl (and POD of Parser module).
---
 ChangeLog                                 | 20 ++++++++++++++++++++
 tp/Texinfo/XS/main/utils.c                | 20 +++++++++++++-------
 tp/Texinfo/XS/main/utils.h                |  2 ++
 tp/Texinfo/XS/parsetexi/Parsetexi.pm      |  4 ++--
 tp/Texinfo/XS/parsetexi/Parsetexi.xs      |  4 ++--
 tp/Texinfo/XS/parsetexi/api.c             | 13 -------------
 tp/Texinfo/XS/parsetexi/api.h             |  2 --
 tp/Texinfo/XS/parsetexi/conf.c            | 20 ++++++++++++++++++++
 tp/Texinfo/XS/parsetexi/conf.h            |  3 +++
 tp/Texinfo/XS/parsetexi/handle_commands.c | 24 +-----------------------
 tp/Texinfo/XS/parsetexi/handle_commands.h |  4 ----
 11 files changed, 63 insertions(+), 53 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3244a488cf..8f3a60c2c9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2024-05-20  Patrice Dumas  <pertusus@free.fr>
+
+       Replace parser_expanded_formats by const.expanded_formats
+
+       * tp/Texinfo/XS/main/utils.h: rename expanded_formats as
+       default_expanded_formats, make it const and extern.
+
+       * tp/Texinfo/XS/parsetexi/Parsetexi.pm (parser),
+       tp/Texinfo/XS/parsetexi/Parsetexi.xs (conf_clear_expanded_formats)
+       (conf_add_expanded_format), tp/Texinfo/XS/parsetexi/api.c
+       (reset_parser), tp/Texinfo/XS/parsetexi/conf.c (reset_conf)
+       (conf_clear_expanded_formats, conf_add_expanded_format): add
+       expanded_formats in CONF, add conf_clear_expanded_formats to clear,
+       conf_add_expanded_format to add expanded formats and replace
+       parser_expanded_formats by const.expanded_formats. Remove
+       parser_clear_expanded_formats and parser_add_expanded_format.
+
+       This changes the default expanded formats to be none, which matches
+       Perl (and POD of Parser module).
+
 2024-05-19  Patrice Dumas  <pertusus@free.fr>
 
        Replace parser_include_dirs_list by conf.include_directories
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index b886396ace..af10fb98d1 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -105,7 +105,9 @@ const char *command_location_names[]
   = {"before", "last", "preamble", "preamble_or_first", 0};
 
 /* duplicated when creating a new expanded_formats */
-EXPANDED_FORMAT expanded_formats[] = {
+/* NOTE if you add a format, increase the size of CONF.expanded_formats
+ */
+const EXPANDED_FORMAT default_expanded_formats[] = {
     "html", 0,
     "docbook", 0,
     "plaintext", 0,
@@ -544,7 +546,8 @@ void
 clear_expanded_formats (EXPANDED_FORMAT *formats)
 {
   int i;
-  for (i = 0; i < sizeof (expanded_formats)/sizeof (*expanded_formats);
+  for (i = 0; i < sizeof (default_expanded_formats)
+                            / sizeof (*default_expanded_formats);
        i++)
     {
       formats[i].expandedp = 0;
@@ -555,7 +558,8 @@ void
 add_expanded_format (EXPANDED_FORMAT *formats, const char *format)
 {
   int i;
-  for (i = 0; i < sizeof (expanded_formats)/sizeof (*expanded_formats);
+  for (i = 0; i < sizeof (default_expanded_formats)
+                      / sizeof (*default_expanded_formats);
        i++)
     {
       if (!strcmp (format, formats[i].format))
@@ -572,8 +576,8 @@ EXPANDED_FORMAT *
 new_expanded_formats (void)
 {
   EXPANDED_FORMAT *formats
-     = (EXPANDED_FORMAT *) malloc (sizeof (expanded_formats));
-  memcpy (formats, expanded_formats, sizeof (expanded_formats));
+     = (EXPANDED_FORMAT *) malloc (sizeof (default_expanded_formats));
+  memcpy (formats, default_expanded_formats, sizeof 
(default_expanded_formats));
 
   return formats;
 }
@@ -582,7 +586,8 @@ int
 format_expanded_p (const EXPANDED_FORMAT *formats, const char *format)
 {
   int i;
-  for (i = 0; i < sizeof (expanded_formats)/sizeof (*expanded_formats);
+  for (i = 0; i < sizeof (default_expanded_formats)
+                           / sizeof (*default_expanded_formats);
        i++)
     {
       if (!strcmp (format, formats[i].format))
@@ -594,7 +599,8 @@ format_expanded_p (const EXPANDED_FORMAT *formats, const 
char *format)
 int
 expanded_formats_number (void)
 {
-  return sizeof (expanded_formats)/sizeof (*expanded_formats);
+  return sizeof (default_expanded_formats)
+                          / sizeof (*default_expanded_formats);
 }
 
 void
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index 5ab90d07e1..2f3254599b 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -45,6 +45,8 @@ extern const char *command_location_names[];
 extern const char *html_button_direction_names[];
 extern char *html_command_text_type_name[];
 
+extern const EXPANDED_FORMAT default_expanded_formats[];
+
 typedef struct ENCODING_CONVERSION {
     char *encoding_name;
     iconv_t iconv;
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm 
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index 54564c9184..c7cee35e10 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -102,10 +102,10 @@ sub parser (;$$)
       } elsif ($key eq 'values') {
         parser_store_values($conf->{'values'});
       } elsif ($key eq 'EXPANDED_FORMATS') {
-        parser_clear_expanded_formats();
+        conf_clear_expanded_formats();
 
         for my $f (@{$conf->{$key}}) {
-          parser_add_expanded_format($f);
+          conf_add_expanded_format($f);
         }
       } elsif ($key eq 'documentlanguage') {
         if (defined ($conf->{$key})) {
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.xs 
b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
index b1e76e2fdf..07c63c18cb 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
@@ -152,10 +152,10 @@ parser_store_INCLUDE_DIRECTORIES (SV *directories)
           }
 
 void
-parser_clear_expanded_formats ()
+conf_clear_expanded_formats ()
 
 void
-parser_add_expanded_format (format)
+conf_add_expanded_format (format)
      char *format = (char *)SvPVutf8_nolen ($arg);
 
 void
diff --git a/tp/Texinfo/XS/parsetexi/api.c b/tp/Texinfo/XS/parsetexi/api.c
index 712b5b8273..25a3867ed9 100644
--- a/tp/Texinfo/XS/parsetexi/api.c
+++ b/tp/Texinfo/XS/parsetexi/api.c
@@ -96,7 +96,6 @@ reset_parser (int local_debug_output)
     fprintf (stderr,
           "!!!!!!!!!!!!!!!! RESETTING THE PARSER !!!!!!!!!!!!!!!!!!!!!\n");
 
-  clear_parser_expanded_formats ();
   reset_conf ();
 
   global_documentlanguage_fixed = 0;
@@ -246,18 +245,6 @@ parser_store_value (const char *name, const char *value)
   store_value (&conf.values, name, value);
 }
 
-void
-parser_clear_expanded_formats (void)
-{
-  clear_parser_expanded_formats ();
-}
-
-void
-parser_add_expanded_format (const char *format)
-{
-  add_parser_expanded_format (format);
-}
-
 void
 parser_set_accept_internalvalue (int value)
 {
diff --git a/tp/Texinfo/XS/parsetexi/api.h b/tp/Texinfo/XS/parsetexi/api.h
index d4adfa8072..480ad02388 100644
--- a/tp/Texinfo/XS/parsetexi/api.h
+++ b/tp/Texinfo/XS/parsetexi/api.h
@@ -13,8 +13,6 @@ void reset_parser (int debug_output);
 
 void parser_reset_values_conf (void);
 void parser_store_value (const char *name, const char *value);
-void parser_add_expanded_format (const char *format);
-void parser_clear_expanded_formats (void);
 void parser_set_accept_internalvalue (int value);
 void parser_set_DOC_ENCODING_FOR_INPUT_FILE_NAME (int i);
 void parser_set_input_file_name_encoding (const char *value);
diff --git a/tp/Texinfo/XS/parsetexi/conf.c b/tp/Texinfo/XS/parsetexi/conf.c
index f94d825ca9..16d968e170 100644
--- a/tp/Texinfo/XS/parsetexi/conf.c
+++ b/tp/Texinfo/XS/parsetexi/conf.c
@@ -84,6 +84,18 @@ conf_add_include_directory (const char *filename)
   add_include_directory (filename, &conf.include_directories);
 }
 
+void
+conf_clear_expanded_formats (void)
+{
+  clear_expanded_formats (conf.expanded_formats);
+}
+
+void
+conf_add_expanded_format (const char *format)
+{
+  add_expanded_format (conf.expanded_formats, format);
+}
+
 void
 reset_conf (void)
 {
@@ -98,6 +110,14 @@ reset_conf (void)
   conf.no_user_commands = 0;
   conf.show_menu = 1;
 
+  memcpy (conf.expanded_formats, default_expanded_formats,
+          sizeof (conf.expanded_formats));
+  /* It would have been cleaner to separate setting default values,
+     but it is not needed, as default_expanded_formats is already zeros,
+     so the call can be kept in comments
+  conf_clear_expanded_formats ();
+   */
+
   add_include_directory (".", &conf.include_directories);
 
   /* special value always returned as 1 to mark that @ifcommandnotdefined
diff --git a/tp/Texinfo/XS/parsetexi/conf.h b/tp/Texinfo/XS/parsetexi/conf.h
index 7434352aeb..5778ba04c5 100644
--- a/tp/Texinfo/XS/parsetexi/conf.h
+++ b/tp/Texinfo/XS/parsetexi/conf.h
@@ -28,6 +28,7 @@ typedef struct CONF {
     int no_user_commands;
     int show_menu;
 
+    EXPANDED_FORMAT expanded_formats[7];
     VALUE_LIST values;
 } CONF;
 
@@ -43,6 +44,8 @@ int conf_set_NO_INDEX (int i);
 int conf_set_NO_USER_COMMANDS (int i);
 void conf_clear_INCLUDE_DIRECTORIES (void);
 void conf_add_include_directory (const char *filename);
+void conf_clear_expanded_formats (void);
+void conf_add_expanded_format (const char *format);
 
 void reset_conf (void);
 
diff --git a/tp/Texinfo/XS/parsetexi/handle_commands.c 
b/tp/Texinfo/XS/parsetexi/handle_commands.c
index d9087be7bf..cf9d55e8c9 100644
--- a/tp/Texinfo/XS/parsetexi/handle_commands.c
+++ b/tp/Texinfo/XS/parsetexi/handle_commands.c
@@ -981,32 +981,10 @@ funexit:
   return current;
 }
 
-EXPANDED_FORMAT parser_expanded_formats[] = {
-    "html", 0,
-    "docbook", 0,
-    "plaintext", 1,
-    "tex", 0,
-    "xml", 0,
-    "info", 1,
-    "latex", 0,
-};
-
-void
-clear_parser_expanded_formats (void)
-{
-  clear_expanded_formats (parser_expanded_formats);
-}
-
-void
-add_parser_expanded_format (const char *format)
-{
-  add_expanded_format (parser_expanded_formats, format);
-}
-
 int
 parser_format_expanded_p (const char *format)
 {
-  return format_expanded_p (parser_expanded_formats, format);
+  return format_expanded_p (conf.expanded_formats, format);
 }
 
 /* A command name has been read that starts a multiline block, which should
diff --git a/tp/Texinfo/XS/parsetexi/handle_commands.h 
b/tp/Texinfo/XS/parsetexi/handle_commands.h
index ce9024b3ae..0c6de63d53 100644
--- a/tp/Texinfo/XS/parsetexi/handle_commands.h
+++ b/tp/Texinfo/XS/parsetexi/handle_commands.h
@@ -18,10 +18,6 @@ ELEMENT *handle_brace_command (ELEMENT *current, char 
**line_inout,
                              enum command_id cmd_id, ELEMENT 
**command_element);
 int check_no_text (const ELEMENT *current);
 
-void clear_parser_expanded_formats (void);
-void add_parser_expanded_format (const char *format);
 int parser_format_expanded_p (const char *format);
 
-extern EXPANDED_FORMAT parser_expanded_formats[7];
-
 #endif



reply via email to

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