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, 26 Jan 2024 04:06:22 -0500 (EST)

branch: master
commit 68dbddab89b567719db28ce89e91296531e2bf57
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Jan 26 09:26:39 2024 +0100

    * tp/Texinfo/XS/main/extra.c (add_associated_info_string_dup): add.
    
    * tp/Texinfo/XS/main/DocumentXS.xs (set_document_global_info),
    tp/Texinfo/XS/main/build_perl_info.c (store_additional_info)
    (build_additional_info, build_global_info),
    tp/Texinfo/XS/main/document_types.h (GLOBAL_INFO),
    tp/Texinfo/XS/main/utils.c (delete_global_info): split
    build_additional_info out of store_additional_info, to build
    additional info on a passed hash.  Pass other set document global info
    in a associated_info.
    
    * tp/texi2any.pl: set configured_information PACKAGE* variables and
    pass them as set_document_global_info.
    
    * tp/t/init/redefine_need.init (my_need_formatting): test getting
    PACKAGE_AND_VERSION.
---
 ChangeLog                                          | 19 ++++++++++
 tp/Texinfo/XS/main/DocumentXS.xs                   |  7 ++++
 tp/Texinfo/XS/main/build_perl_info.c               | 43 +++++++++++++++-------
 tp/Texinfo/XS/main/document_types.h                |  3 ++
 tp/Texinfo/XS/main/extra.c                         |  8 ++++
 tp/Texinfo/XS/main/extra.h                         |  2 +
 tp/Texinfo/XS/main/utils.c                         |  2 +
 tp/t/init/redefine_need.init                       | 12 +++++-
 tp/t/results/init_files_tests/redefined_need.pl    |  2 +-
 .../res_parser/test_redefine_need/test_need.html   |  4 +-
 tp/texi2any.pl                                     | 29 ++++++++++++---
 11 files changed, 108 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5e802327a9..051195ca7f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2024-01-26  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/extra.c (add_associated_info_string_dup): add.
+
+       * tp/Texinfo/XS/main/DocumentXS.xs (set_document_global_info),
+       tp/Texinfo/XS/main/build_perl_info.c (store_additional_info)
+       (build_additional_info, build_global_info),
+       tp/Texinfo/XS/main/document_types.h (GLOBAL_INFO),
+       tp/Texinfo/XS/main/utils.c (delete_global_info): split
+       build_additional_info out of store_additional_info, to build
+       additional info on a passed hash.  Pass other set document global info
+       in a associated_info.
+
+       * tp/texi2any.pl: set configured_information PACKAGE* variables and
+       pass them as set_document_global_info.
+
+       * tp/t/init/redefine_need.init (my_need_formatting): test getting
+       PACKAGE_AND_VERSION.
+
 2024-01-25  Patrice Dumas  <pertusus@free.fr>
 
        * tp/t/test_utils.pl (set_converter_option_defaults, convert_to_*)
diff --git a/tp/Texinfo/XS/main/DocumentXS.xs b/tp/Texinfo/XS/main/DocumentXS.xs
index 5db1f4098c..0f9e62f9d0 100644
--- a/tp/Texinfo/XS/main/DocumentXS.xs
+++ b/tp/Texinfo/XS/main/DocumentXS.xs
@@ -33,6 +33,7 @@
 #include "options_types.h"
 #include "tree_types.h"
 #include "document_types.h"
+#include "extra.h"
 #include "document.h"
 #include "translations.h"
 #include "get_perl_info.h"
@@ -112,6 +113,12 @@ set_document_global_info (SV *document_in, char *key, SV 
*value_sv)
                 document->global_info->input_perl_encoding
                    = strdup ((char *)SvPVbyte_nolen(value_sv));
               }
+            else
+              {
+                add_associated_info_string_dup (
+                          &document->global_info->other_info,
+                          key, (char *)SvPVutf8_nolen(value_sv));
+              }
           }
 
 SV *
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 89d8b221a6..0e4ed18616 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -238,21 +238,16 @@ newSVpv_byte (const char *str, STRLEN len)
 }
 
 static void
-store_additional_info (const ELEMENT *e, ASSOCIATED_INFO* a, char *key,
-                       int avoid_recursion)
+build_additional_info (HV *extra, ASSOCIATED_INFO *a, int avoid_recursion,
+                       int *nr_info)
 {
   dTHX;
 
+  *nr_info = 0; /* number of info type stored */
+
   if (a->info_number > 0)
     {
-      HV *extra;
       int i;
-      int nr_info = 0; /* number of info type stored */
-
-
-      /* Use sv_2mortal so that reference count is decremented if
-         the hash is not saved. */
-      extra = (HV *) sv_2mortal((SV *)newHV ());
 
       for (i = 0; i < a->info_number; i++)
         {
@@ -263,7 +258,7 @@ store_additional_info (const ELEMENT *e, ASSOCIATED_INFO* 
a, char *key,
 
           if (k->type == extra_deleted)
             continue;
-          nr_info++;
+          (*nr_info)++;
 
           switch (k->type)
             {
@@ -376,13 +371,30 @@ store_additional_info (const ELEMENT *e, ASSOCIATED_INFO* 
a, char *key,
             }
         }
 #undef STORE
-
-      if (nr_info > 0)
-        hv_store (e->hv, key, strlen (key),
-                  newRV_inc((SV *)extra), 0);
     }
 }
 
+static void
+store_additional_info (const ELEMENT *e, ASSOCIATED_INFO *a, char *key,
+                       int avoid_recursion)
+{
+  int nr_info;
+  HV *additional_info_hv;
+
+  dTHX;
+
+  /* Use sv_2mortal so that reference count is decremented if
+         the hash is not saved. */
+  additional_info_hv = (HV *) sv_2mortal((SV *)newHV ());
+
+
+  build_additional_info (additional_info_hv, a, avoid_recursion, &nr_info);
+
+  if (nr_info > 0)
+    hv_store (e->hv, key, strlen (key),
+              newRV_inc((SV *)additional_info_hv), 0);
+}
+
 static void
 store_source_mark_list (ELEMENT *e)
 {
@@ -886,6 +898,7 @@ build_global_info (GLOBAL_INFO *global_info_ref,
   GLOBAL_INFO global_info = *global_info_ref;
   GLOBAL_COMMANDS global_commands = *global_commands_ref;
   ELEMENT *document_language;
+  int nr_info;
 
   dTHX;
 
@@ -919,6 +932,8 @@ build_global_info (GLOBAL_INFO *global_info_ref,
                 newSVpv (language, 0), 0);
     }
 
+  build_additional_info (hv, &global_info.other_info, 0, &nr_info);
+
   return hv;
 }
 
diff --git a/tp/Texinfo/XS/main/document_types.h 
b/tp/Texinfo/XS/main/document_types.h
index 7ce19de6ae..c3f9c56622 100644
--- a/tp/Texinfo/XS/main/document_types.h
+++ b/tp/Texinfo/XS/main/document_types.h
@@ -58,6 +58,9 @@ typedef struct GLOBAL_INFO {
     /* Ignored characters for index sort key */
     IGNORED_CHARS ignored_chars;
 
+    /* remaining, in general passed to/from perl but not used in C */
+    ASSOCIATED_INFO other_info;
+
     /* perl specific */
     char *input_perl_encoding;
 } GLOBAL_INFO;
diff --git a/tp/Texinfo/XS/main/extra.c b/tp/Texinfo/XS/main/extra.c
index 0dbc3553c1..0b36c9765a 100644
--- a/tp/Texinfo/XS/main/extra.c
+++ b/tp/Texinfo/XS/main/extra.c
@@ -169,6 +169,14 @@ add_associated_info_integer (ASSOCIATED_INFO *a, const 
char *key, int value)
   k->integer = value;
 }
 
+void
+add_associated_info_string_dup (ASSOCIATED_INFO *a, const char *key,
+                                const char *value)
+{
+  KEY_PAIR *k = get_associated_info_key (a, key, extra_string);
+  k->string = strdup (value);
+}
+
 void
 add_extra_integer (ELEMENT *e, char *key, long value)
 {
diff --git a/tp/Texinfo/XS/main/extra.h b/tp/Texinfo/XS/main/extra.h
index 5d3adcfce0..484969af2d 100644
--- a/tp/Texinfo/XS/main/extra.h
+++ b/tp/Texinfo/XS/main/extra.h
@@ -34,6 +34,8 @@ void add_info_string_dup (ELEMENT *e, const char *key, const 
char *value);
 void add_info_element_oot (ELEMENT *e, char *key, ELEMENT *value);
 void add_associated_info_integer (ASSOCIATED_INFO *a,
                                   const char *key, int value);
+void add_associated_info_string_dup (ASSOCIATED_INFO *a, const char *key,
+                                     const char *value);
 KEY_PAIR *lookup_extra (const ELEMENT *e, const char *key);
 KEY_PAIR *lookup_info (const ELEMENT *e, const char *key);
 ELEMENT *lookup_extra_element (const ELEMENT *e, const char *key);
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 82311881d1..b2fbe5aeb3 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -1014,6 +1014,8 @@ delete_global_info (GLOBAL_INFO *global_info_ref)
   free (global_info.input_file_name);
   free (global_info.input_directory);
 
+  destroy_associated_info (&global_info.other_info);
+
   /* perl specific information */
   free (global_info.input_perl_encoding);
 }
diff --git a/tp/t/init/redefine_need.init b/tp/t/init/redefine_need.init
index 2defe12c35..a2a02276df 100644
--- a/tp/t/init/redefine_need.init
+++ b/tp/t/init/redefine_need.init
@@ -10,6 +10,16 @@ sub my_need_formatting($$$)
   my $cmdname = shift;
   my $command = shift;
 
+  my $package_version = '';
+
+  my $document = $converter->get_info('document');
+  if ($document) {
+    my $document_info = $document->global_information();
+    if ($document_info and defined($document_info->{'PACKAGE_AND_VERSION'})) {
+      $package_version = $document_info->{'PACKAGE_AND_VERSION'};
+    }
+  }
+
   if ($command->{'extra'} and $command->{'extra'}->{'misc_args'}
       and @{$command->{'extra'}->{'misc_args'}}) {
     $converter->converter_line_warn(
@@ -26,5 +36,5 @@ sub my_need_formatting($$$)
     $arg_text = '';
   }
   return (&{$converter->formatting_function('format_comment')}($converter,
-                                                      "$cmdname: $arg_text"));
+                                   "$cmdname: $arg_text ($package_version)"));
 }
diff --git a/tp/t/results/init_files_tests/redefined_need.pl 
b/tp/t/results/init_files_tests/redefined_need.pl
index d83256dfa6..02c2898532 100644
--- a/tp/t/results/init_files_tests/redefined_need.pl
+++ b/tp/t/results/init_files_tests/redefined_need.pl
@@ -79,7 +79,7 @@ $result_converted{'html'}->{'redefined_need'} = '<!DOCTYPE 
html>
 </head>
 
 <body lang="en">
-<!-- need: 0.1 -->
+<!-- need: 0.1 () -->
 
 
 
diff --git 
a/tp/tests/customization/res_parser/test_redefine_need/test_need.html 
b/tp/tests/customization/res_parser/test_redefine_need/test_need.html
index 51a1632c62..b9d3a41535 100644
--- a/tp/tests/customization/res_parser/test_redefine_need/test_need.html
+++ b/tp/tests/customization/res_parser/test_redefine_need/test_need.html
@@ -28,8 +28,8 @@ span:hover a.copiable-link {visibility: visible}
 <div class="top-level-extent" id="Top">
 <h1 class="top" id="Test-need"><span>Test need<a class="copiable-link" 
href="#Test-need"> &para;</a></span></h1>
 
-<p>@need </p><!-- need: 0.1 on line following -->
-<p>@need </p><!-- need: 0.1 -->
+<p>@need </p><!-- need: 0.1 on line following (Texinfo 7.1dev+dev) -->
+<p>@need </p><!-- need: 0.1 (Texinfo 7.1dev+dev) -->
 
 
 </div>
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index 5054b3896b..c687657272 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -322,13 +322,16 @@ if (!defined($locale_encoding) and $^O eq 'MSWin32') {
 $texinfo_dtd_version = $configured_version
   if (!defined($texinfo_dtd_version));
 
+my $configured_information = {
+    'PACKAGE_VERSION' => $configured_version,
+    'PACKAGE' => $configured_package,
+    'PACKAGE_NAME' => $configured_name,
+    'PACKAGE_AND_VERSION' => $configured_name_version,
+    'PACKAGE_URL' => $configured_url,
+};
+
 # options set in the main program.
 my $main_program_set_options = {
-    'PACKAGE_VERSION_OPTION' => $configured_version,
-    'PACKAGE_OPTION' => $configured_package,
-    'PACKAGE_NAME_OPTION' => $configured_name,
-    'PACKAGE_AND_VERSION_OPTION' => $configured_name_version,
-    'PACKAGE_URL_OPTION' => $configured_url,
     'PROGRAM' => $real_command_name,
     'TEXINFO_DTD_VERSION' => $texinfo_dtd_version,
     'COMMAND_LINE_ENCODING' => $locale_encoding,
@@ -336,6 +339,14 @@ my $main_program_set_options = {
     'LOCALE_ENCODING' => $locale_encoding
 };
 
+# here set configure information with _OPTION prepended, to mark that
+# these are customization variables that may be modified in init files
+# or on the command line.
+foreach my $configured_variable (keys(%$configured_information)) {
+  $main_program_set_options->{$configured_variable . '_OPTION'}
+    = $configured_information->{$configured_variable};
+}
+
 # In Windows, a character in file name is encoded according to the current
 # codepage, and converted to/from UTF-16 in the filesystem.  If a file name is
 # not encoded in the current codepage, the file name will appear with erroneous
@@ -1488,6 +1499,14 @@ while(@input_files) {
     next;
   }
 
+  # set as global information, not as customization variables,
+  # customization variables have _OPTION prepended
+  # FIXME does not need to be associated to a document, could be
+  # a common constant
+  foreach my $configured_variable (keys(%$configured_information)) {
+    $document->set_document_global_info($configured_variable,
+                       $configured_information->{$configured_variable});
+  }
 
   if ($tree_transformations{'fill_gaps_in_sectioning'}) {
     Texinfo::Transformations::fill_gaps_in_sectioning($tree);



reply via email to

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