texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: XS interface for Texinfo::Convert::Converter::set


From: Patrice Dumas
Subject: branch master updated: XS interface for Texinfo::Convert::Converter::set_global_document_commands
Date: Sun, 10 Mar 2024 06:52:37 -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 7fe6bd8b21 XS interface for 
Texinfo::Convert::Converter::set_global_document_commands
7fe6bd8b21 is described below

commit 7fe6bd8b21cd8070aa0aa72ef78212f610acd04a
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Mar 10 11:52:22 2024 +0100

    XS interface for Texinfo::Convert::Converter::set_global_document_commands
    
    * tp/Texinfo/Convert/Converter.pm (%XS_overrides),
    tp/Texinfo/XS/convert/ConvertXS.xs
    (converter_set_global_document_commands): add an XS interface for
    set_global_document_commands.
---
 ChangeLog                          |  9 ++++++
 tp/Texinfo/Convert/Converter.pm    |  2 ++
 tp/Texinfo/XS/convert/ConvertXS.xs | 60 ++++++++++++++++++++++++++++++++++++++
 tp/Texinfo/XS/main/utils.c         |  2 +-
 4 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index d2556701f4..a6b1b9fc65 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-03-10  Patrice Dumas  <pertusus@free.fr>
+
+       XS interface for 
Texinfo::Convert::Converter::set_global_document_commands
+
+       * tp/Texinfo/Convert/Converter.pm (%XS_overrides),
+       tp/Texinfo/XS/convert/ConvertXS.xs
+       (converter_set_global_document_commands): add an XS interface for
+       set_global_document_commands.
+
 2024-03-10  Patrice Dumas  <pertusus@free.fr>
 
        Put dircategory_direntry in global_commands
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index e348538f32..6df9d30cfd 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -112,6 +112,8 @@ my %XS_overrides = (
    => "Texinfo::Convert::ConvertXS::get_converter_indices_sorted_by_letter",
   "Texinfo::Convert::Converter::get_converter_indices_sorted_by_index"
    => "Texinfo::Convert::ConvertXS::get_converter_indices_sorted_by_index",
+  "Texinfo::Convert::Converter::set_global_document_commands"
+   => "Texinfo::Convert::ConvertXS::converter_set_global_document_commands",
 
   # XS only
   "Texinfo::Convert::Converter::reset_converter"
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 15e52b818c..86ec51a8e0 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -182,6 +182,66 @@ converter_document_warn (SV *converter_in, text, ...)
                       self->conf, MSG_document_warning, continuation, text);
            }
 
+void
+converter_set_global_document_commands (SV *converter_in, char 
*commands_location_string, SV *selected_commands)
+      PREINIT:
+         CONVERTER *self;
+      CODE:
+         self = get_sv_converter (converter_in, 0);
+         if (self)
+           {
+             int command_location = -1;
+             int i;
+             AV *selected_commands_av = (AV *) SvRV (selected_commands);
+             SSize_t in_commands_nr = av_top_index (selected_commands_av) +1;
+             enum command_id *cmd_list = (enum command_id *) malloc
+                           ((in_commands_nr+1) * sizeof (enum command_id));
+             /* actual command index/number without unknown commands */
+             int command_nr = 0;
+
+             for (i = 0; command_location_names[i]; i++)
+               {
+                 if (!strcmp (commands_location_string,
+                              command_location_names[i]))
+                   {
+                     command_location = i;
+                     break;
+                   }
+               }
+             if (command_location < 0)
+               {
+                 fprintf (stderr,
+                          "ERROR: unknown command location: %s\n",
+                          commands_location_string);
+                 return;
+               }
+
+             for (i = 0; i < in_commands_nr; i++)
+               {
+                 SV** command_sv = av_fetch (selected_commands_av, i, 0);
+                 if (command_sv)
+                   {
+                     const char *command_name = SvPV_nolen (*command_sv);
+                     enum command_id cmd
+                        = lookup_builtin_command (command_name);
+                     if (cmd <= 0)
+                       {
+                         fprintf (stderr,
+                                  "ERROR: unknown command (%d): %s\n",
+                                  i, command_name);
+                       }
+                     else
+                       {
+                         cmd_list[command_nr] = cmd;
+                         command_nr++;
+                       }
+                   }
+               }
+             cmd_list[command_nr] = 0;
+             set_global_document_commands (self, command_location, cmd_list);
+             free (cmd_list);
+           }
+
 SV *
 get_converter_indices_sorted_by_index (SV *converter_sv)
      PREINIT:
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 86bcb2817f..41a203a891 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -102,7 +102,7 @@ ENCODING_CONVERSION_LIST input_conversions = {0, 0, 0, 1};
 
 /* to keep synchronized with enum command_location */
 const char *command_location_names[]
-  = {"before", "last", "preamble", "preamble_or_first"};
+  = {"before", "last", "preamble", "preamble_or_first", 0};
 
 /* duplicated when creating a new expanded_formats */
 EXPANDED_FORMAT expanded_formats[] = {



reply via email to

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