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:23 -0500 (EST)

branch: master
commit 46e4ed997b123c02b70a08f2efa081a6f39a77b8
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Jan 26 10:06:02 2024 +0100

    * doc/texi2any_api.texi (Getting Constants), tp/Texinfo/Common.pm
    (set_constant, get_constant): add setting/getting constants.
    
    * tp/texi2any.pl: set PACKAGE* as constants.
    
    * tp/t/init/redefine_need.init (my_need_formatting): use constants by
    get_constant.
---
 ChangeLog                    | 10 +++++++++
 doc/texi2any_api.texi        | 29 +++++++++++++++++++++++++
 tp/Texinfo/Common.pm         | 51 ++++++++++++++++++++++++++++++++++++++++++--
 tp/t/init/redefine_need.init | 12 +++--------
 tp/texi2any.pl               | 15 ++++++-------
 5 files changed, 97 insertions(+), 20 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 051195ca7f..e7097c864b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-01-26  Patrice Dumas  <pertusus@free.fr>
+
+       * doc/texi2any_api.texi (Getting Constants), tp/Texinfo/Common.pm
+       (set_constant, get_constant): add setting/getting constants.
+
+       * tp/texi2any.pl: set PACKAGE* as constants.
+
+       * tp/t/init/redefine_need.init (my_need_formatting): use constants by
+       get_constant.
+
 2024-01-26  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/extra.c (add_associated_info_string_dup): add.
diff --git a/doc/texi2any_api.texi b/doc/texi2any_api.texi
index 3ceeea76dc..02940cd463 100644
--- a/doc/texi2any_api.texi
+++ b/doc/texi2any_api.texi
@@ -223,6 +223,35 @@ instead it is passed to functions defined in init files 
that are registered as
 functions to be called from the converter. @xref{User Defined Functions}.
 
 
+@node Getting Constants
+@section Getting Constants
+
+@cindex Constants
+
+Some constants are set independently of the output format.  They are available
+through @code{Texinfo::Common::get_constant}:
+
+@deftypefun {@var{$value} =} Texinfo::Common::get_constant (@var{$name})
+Retrieve constant @var{$name} value.
+@end deftypefun
+
+Available constants:
+
+@vtable @code
+@item PACKAGE
+@itemx PACKAGE_AND_VERSION
+@itemx PACKAGE_NAME
+@itemx PACKAGE_VERSION
+@itemx PACKAGE_URL
+
+Texinfo package name and versions. Values set by configure.
+
+Similar customization variables exist with @samp{_OPTION} prepended
+to their name and the same value set in the default case from the
+main program, with values that can be modified.
+@end vtable
+
+
 @node Managing Customization Variables
 @section Managing Customization Variables
 
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index aed460ed6d..1623f6c872 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -293,6 +293,25 @@ foreach my $output_format_command ('info', 'plaintext',
 }
 
 
+# constants.  Set by the main program.
+my %constants;
+
+sub set_constant($$)
+{
+  my $key = shift;
+  my $value = shift;
+
+  $constants{$key} = $value;
+}
+
+sub get_constant($)
+{
+  my $key = shift;
+
+  return $constants{$key};
+}
+
+
 # Tree transformations
 
 my %valid_tree_transformations;
@@ -2726,6 +2745,8 @@ Texinfo::Common - Texinfo modules common data and 
miscellaneous methods
     = Texinfo::Common::collect_commands_in_tree($document_root,
                                              \@commands_to_collect);
 
+  my $package_version = Texinfo::Common::get_constant('PACKAGE_AND_VERSION');
+
 =head1 NOTES
 
 The Texinfo Perl module main purpose is to be used in C<texi2any> to convert
@@ -2742,8 +2763,31 @@ methods.
 Hashes are defined as C<our> variables, and are therefore available
 outside of the module.
 
-TODO: undocumented
-%null_device_file %default_parser_customization_values 
%multiple_at_command_options %unique_at_command_options 
%converter_cmdline_options %default_main_program_customization_options 
%converter_customization_options %document_settable_at_commands %def_map 
%command_structuring_level %level_to_structuring_command 
%encoding_name_conversion_map
+Constants are available by calling C<get_constant>:
+
+=over
+
+=item $value = get_constant($name)
+
+The following constants are available:
+
+=over
+
+=item PACKAGE
+
+=item PACKAGE_AND_VERSION
+
+=item PACKAGE_NAME
+
+=item PACKAGE_VERSION
+
+=item PACKAGE_URL
+
+Texinfo package name and versions.  Values set by configure.
+
+=back
+
+=back
 
 =over
 
@@ -2756,6 +2800,9 @@ and C<plaintext>.
 
 =back
 
+TODO: undocumented
+%null_device_file %default_parser_customization_values 
%multiple_at_command_options %unique_at_command_options 
%converter_cmdline_options %default_main_program_customization_options 
%converter_customization_options %document_settable_at_commands %def_map 
%command_structuring_level %level_to_structuring_command 
%encoding_name_conversion_map
+
 =head1 @-COMMAND INFORMATION
 
 Hashes are defined as C<our> variables, and are therefore available
diff --git a/tp/t/init/redefine_need.init b/tp/t/init/redefine_need.init
index a2a02276df..d2207f4ae2 100644
--- a/tp/t/init/redefine_need.init
+++ b/tp/t/init/redefine_need.init
@@ -1,6 +1,7 @@
 use strict;
 
 use Texinfo::Convert::Text;
+use Texinfo::Common;
 
 texinfo_register_command_formatting('need', \&my_need_formatting);
 
@@ -10,15 +11,8 @@ 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'};
-    }
-  }
+  my $package_version = Texinfo::Common::get_constant('PACKAGE_AND_VERSION');
+  $package_version = '' if (!defined($package_version));
 
   if ($command->{'extra'} and $command->{'extra'}->{'misc_args'}
       and @{$command->{'extra'}->{'misc_args'}}) {
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index c687657272..30d525c486 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -339,6 +339,12 @@ my $main_program_set_options = {
     'LOCALE_ENCODING' => $locale_encoding
 };
 
+# set configure information as constants
+foreach my $configured_variable (keys(%$configured_information)) {
+  Texinfo::Common::set_constant($configured_variable,
+                       $configured_information->{$configured_variable});
+}
+
 # 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.
@@ -1499,15 +1505,6 @@ 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]