[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Config.pm, texi2any.pl, tp/Texinfo/C
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/Config.pm, texi2any.pl, tp/Texinfo/Convert/HTML.pm, tp/Makefile.am (dist_modules_DATA): put Texinfo::Config namespace in a separate file. This is not perfect as Texinfo::Config is still entangled with Texinfo::Convert::HTML. In particular delayed loading of converter modules in texi2any.pl is now ineffective for Texinfo::Convert::HTML. |
Date: |
Wed, 01 Sep 2021 05:21:27 -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 df5cddd * tp/Texinfo/Config.pm, texi2any.pl,
tp/Texinfo/Convert/HTML.pm, tp/Makefile.am (dist_modules_DATA): put
Texinfo::Config namespace in a separate file. This is not perfect as
Texinfo::Config is still entangled with Texinfo::Convert::HTML. In particular
delayed loading of converter modules in texi2any.pl is now ineffective for
Texinfo::Convert::HTML.
df5cddd is described below
commit df5cdddf527af1bbadbd51244cd730eb14f93bc5
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Sep 1 11:21:17 2021 +0200
* tp/Texinfo/Config.pm, texi2any.pl, tp/Texinfo/Convert/HTML.pm,
tp/Makefile.am (dist_modules_DATA): put Texinfo::Config namespace
in a separate file. This is not perfect as Texinfo::Config is still
entangled with Texinfo::Convert::HTML. In particular delayed loading
of converter modules in texi2any.pl is now ineffective for
Texinfo::Convert::HTML.
---
ChangeLog | 9 +++
tp/Makefile.am | 1 +
tp/Texinfo/Config.pm | 177 +++++++++++++++++++++++++++++++++++++++++++++
tp/Texinfo/Convert/HTML.pm | 64 ++--------------
tp/t/test_utils.pl | 16 +---
tp/texi2any.pl | 96 +-----------------------
6 files changed, 197 insertions(+), 166 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 40c7675..309e517 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2021-09-01 Patrice Dumas <pertusus@free.fr>
+ * tp/Texinfo/Config.pm, texi2any.pl, tp/Texinfo/Convert/HTML.pm,
+ tp/Makefile.am (dist_modules_DATA): put Texinfo::Config namespace
+ in a separate file. This is not perfect as Texinfo::Config is still
+ entangled with Texinfo::Convert::HTML. In particular delayed loading
+ of converter modules in texi2any.pl is now ineffective for
+ Texinfo::Convert::HTML.
+
+2021-09-01 Patrice Dumas <pertusus@free.fr>
+
* tp/Makefile.am (dist_converters_DATA, test_files),
tp/tests/formatting/Makefile.am, tp/tests/indices/Makefile.am: add
new files.
diff --git a/tp/Makefile.am b/tp/Makefile.am
index 74ddef2..53dfcf4 100644
--- a/tp/Makefile.am
+++ b/tp/Makefile.am
@@ -64,6 +64,7 @@ makeinfo: texi2any
modulesdir = $(pkgdatadir)/Texinfo
dist_modules_DATA = \
+ Texinfo/Config.pm \
Texinfo/Parser.pm \
Texinfo/ParserNonXS.pm \
Texinfo/Report.pm \
diff --git a/tp/Texinfo/Config.pm b/tp/Texinfo/Config.pm
new file mode 100644
index 0000000..928c074
--- /dev/null
+++ b/tp/Texinfo/Config.pm
@@ -0,0 +1,177 @@
+# Config.pm: namespace used for user configuration (init files) evaluation
+#
+# Copyright 2010-2019 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License,
+# or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Original author: Patrice Dumas <pertusus@free.fr>
+
+package Texinfo::Config;
+
+# for %Texinfo::Convert::HTML::default_formatting_references
+use Texinfo::Convert::HTML;
+
+# for carp
+use Carp;
+
+# not that there is no use strict to avoid warnings for users code
+
+# eval init file in the Texinfo::Config namespace. Needed functions are in
+# the Texinfo::Convert::HTML Texinfo::Config package namespace code.
+sub _load_init_file($) {
+ my $file = shift;
+ eval { require($file) ;};
+ my $e = $@;
+ if ($e ne '') {
+ main::document_warn(sprintf(main::__("error loading %s: %s\n"),
+ $file, $e));
+ }
+}
+
+# used in main program
+our $options = {};
+my $cmdline_options;
+my $default_options;
+
+sub _load_config($$) {
+ $default_options = shift;
+ $cmdline_options = shift;
+ #print STDERR "cmdline_options: ".join('|',keys(%$cmdline_options))."\n";
+}
+
+# FIXME: maybe use an opaque return status that can be used to retrieve
+# an error message?
+#
+# Called from init files to set configuration options.
+sub set_from_init_file($$) {
+ my $var = shift;
+ my $value = shift;
+ if (!Texinfo::Common::valid_option($var)) {
+ # carp may be better, but infortunately, it points to the routine that
+ # loads the file, and not to the init file.
+ main::document_warn(sprintf(main::__("%s: unknown variable %s"),
+ 'set_from_init_file', $var));
+ return 0;
+ }
+ return 0 if (defined($cmdline_options->{$var}));
+ delete $default_options->{$var};
+ $options->{$var} = $value;
+ return 1;
+}
+
+# set option from the command line. Highest precedence.
+sub set_from_cmdline($$) {
+ my $var = shift;
+ my $value = shift;
+ delete $options->{$var};
+ delete $default_options->{$var};
+ if (!Texinfo::Common::valid_option($var)) {
+ main::document_warn(sprintf(main::__("%s: unknown variable %s\n"),
+ 'set_from_cmdline', $var));
+ return 0;
+ }
+ $cmdline_options->{$var} = $value;
+ return 1;
+}
+
+# This also could get and set some @-command results.
+# FIXME But it does not take into account what happens during conversion,
+# for that something like $converter->get_conf(...) has to be used.
+sub get_conf($) {
+ my $var = shift;
+ if (exists($cmdline_options->{$var})) {
+ return $cmdline_options->{$var};
+ } elsif (exists($options->{$var})) {
+ return $options->{$var};
+ } elsif (exists($default_options->{$var})) {
+ return $default_options->{$var};
+ } else {
+ return undef;
+ }
+}
+
+# to dynamically add options from init files
+sub texinfo_add_valid_option($)
+{
+ my $option = shift;
+ return Texinfo::Common::add_valid_option($option);
+}
+
+# FIXME this is unclean, but it is texi2any.pl that loads init files
+# so it needs to knwow the %default_formatting_references for
+# texinfo_register_formatting_function.
+my %default_formatting_references =
%Texinfo::Convert::HTML::default_formatting_references;
+
+# FIXME would be better to do the reverse, but Texinfo::Convert::HTML
+# is loaded first
+#our @possible_stages = ('setup', 'structure', 'init', 'finish');
+my @possible_stages = @Texinfo::Convert::HTML::possible_stages;
+my %possible_stages;
+foreach my $stage (@possible_stages) {
+ $possible_stages{$stage} = 1;
+}
+
+my $default_priority = 'default';
+
+# Note that these variables are available for the Texinfo modules
+# but, in general should not be accessed directly by the users who
+# customize formatting and should use the associated functions,
+# such as texinfo_register_handler(), texinfo_register_formatting_function(),
+# texinfo_register_command_formatting() or texinfo_register_type_formatting().
+use vars qw(%texinfo_default_stage_handlers %texinfo_formatting_references
+ %texinfo_commands_conversion %texinfo_types_conversion);
+
+sub texinfo_register_handler($$;$)
+{
+ my $stage = shift;
+ my $handler = shift;
+ my $priority = shift;
+
+ if (!$possible_stages{$stage}) {
+ carp ("Unknown stage $stage\n");
+ return 0;
+ }
+ $priority = $default_priority if (!defined($priority));
+ push @{$texinfo_default_stage_handlers{$stage}->{$priority}}, $handler;
+ return 1;
+}
+
+sub texinfo_register_formatting_function($$)
+{
+ my $thing = shift;
+ my $handler = shift;
+ if (!$default_formatting_references{$thing}) {
+ carp ("Unknown formatting type $thing\n");
+ return 0;
+ }
+ $texinfo_formatting_references{$thing} = $handler;
+}
+
+sub texinfo_register_command_formatting($$)
+{
+ my $command = shift;
+ my $reference = shift;
+ $texinfo_commands_conversion{$command} = $reference;
+}
+
+sub texinfo_register_type_formatting($$)
+{
+ my $command = shift;
+ my $reference = shift;
+ $texinfo_types_conversion{$command} = $reference;
+}
+
+
+
+1;
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index f65ed78..682dc2a 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -4951,7 +4951,8 @@ sub _new_document_context($$)
}
# Functions accessed with e.g. 'format_heading_text'.
-my %default_formatting_references = (
+# used in Texinfo::Config
+our %default_formatting_references = (
'format_heading_text' => \&_default_format_heading_text,
'format_comment' => \&_default_format_comment,
'format_protect_text' => \&_default_format_protect_text,
@@ -7281,7 +7282,10 @@ sub output_internal_links($)
}
}
-my @possible_stages = ('setup', 'structure', 'init', 'finish');
+use Texinfo::Config;
+
+#my @possible_stages = @Texinfo::Config::possible_stages;
+our @possible_stages = ('setup', 'structure', 'init', 'finish');
my %possible_stages;
foreach my $stage (@possible_stages) {
$possible_stages{$stage} = 1;
@@ -7317,62 +7321,6 @@ sub run_stage_handlers($$$)
return 1;
}
-my $default_priority = 'default';
-
-{
-package Texinfo::Config;
-
-# Note that these variables are available for the Texinfo modules
-# but, in general should not be accessed directly by the users who
-# customize formatting and should use the associated functions,
-# such as texinfo_register_handler(), texinfo_register_formatting_function(),
-# texinfo_register_command_formatting() or texinfo_register_type_formatting().
-use vars qw(%texinfo_default_stage_handlers %texinfo_formatting_references
- %texinfo_commands_conversion %texinfo_types_conversion);
-
-sub texinfo_register_handler($$;$)
-{
- my $stage = shift;
- my $handler = shift;
- my $priority = shift;
-
- if (!$possible_stages{$stage}) {
- carp ("Unknown stage $stage\n");
- return 0;
- }
- $priority = $default_priority if (!defined($priority));
- push @{$texinfo_default_stage_handlers{$stage}->{$priority}}, $handler;
- return 1;
-}
-
-sub texinfo_register_formatting_function($$)
-{
- my $thing = shift;
- my $handler = shift;
- if (!$default_formatting_references{$thing}) {
- carp ("Unknown formatting type $thing\n");
- return 0;
- }
- $texinfo_formatting_references{$thing} = $handler;
-}
-
-sub texinfo_register_command_formatting($$)
-{
- my $command = shift;
- my $reference = shift;
- $texinfo_commands_conversion{$command} = $reference;
-}
-
-sub texinfo_register_type_formatting($$)
-{
- my $command = shift;
- my $reference = shift;
- $texinfo_types_conversion{$command} = $reference;
-}
-
-
-}
-
# Main function for outputting a manual in HTML.
# $SELF is the output converter object of class Texinfo::Convert::HTML (this
# module), and $ROOT is the Texinfo tree from the parser.
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index 583def2..c6ef3af 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -43,6 +43,7 @@ use Texinfo::Convert::HTML;
use Texinfo::Convert::TexinfoXML;
use Texinfo::Convert::DocBook;
use Texinfo::Convert::LaTeX;
+use Texinfo::Config;
use File::Basename;
use File::Copy;
use File::Compare; # standard since 5.004
@@ -729,21 +730,6 @@ sub convert_to_latex($$$$$$;$)
return ($errors, $result);
}
-{
-# eval init file in the Texinfo::Config namespace. Needed functions are in
-# the Texinfo::Convert::HTML Texinfo::Config package namespace code.
-package Texinfo::Config;
-sub _load_init_file($) {
- my $file = shift;
- require Texinfo::Convert::HTML;
- eval { require($file) ;};
- my $e = $@;
- if ($e ne '') {
- warn (sprintf("error loading %s: %s\n", $file, $e));
- }
-}
-}
-
# Run a single test case. Each test case is an array
# [TEST_NAME, TEST_TEXT, PARSER_OPTIONS, CONVERTER_OPTIONS]
sub test($$)
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index 2965393..30c2010 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -318,99 +318,9 @@ foreach my $texinfo_config_dir (@language_config_dirs) {
push @program_init_dirs, File::Spec->catdir($texinfo_config_dir, 'init');
}
-# Namespace for configuration
-{
-package Texinfo::Config;
-
-#use Carp;
-
-
-
-# passed from main program through _load_config
-my $cmdline_options;
-my $default_options;
-# used in main program
-our $options = {};
-
-sub _load_config($$) {
- $default_options = shift;
- $cmdline_options = shift;
- #print STDERR "cmdline_options: ".join('|',keys(%$cmdline_options))."\n";
-}
-
-# eval init file in the Texinfo::Config namespace. Needed functions are in
-# the Texinfo::Convert::HTML Texinfo::Config package namespace code.
-sub _load_init_file($) {
- my $file = shift;
- require Texinfo::Convert::HTML;
- eval { require($file) ;};
- my $e = $@;
- if ($e ne '') {
- main::document_warn(sprintf(main::__("error loading %s: %s\n"),
- $file, $e));
- }
-}
-
-# FIXME: maybe use an opaque return status that can be used to retrieve
-# an error message?
-#
-# Called from init files to set configuration options.
-sub set_from_init_file($$) {
- my $var = shift;
- my $value = shift;
- if (!Texinfo::Common::valid_option($var)) {
- # carp may be better, but infortunately, it points to the routine that
- # loads the file, and not to the init file.
- main::document_warn(sprintf(main::__("%s: unknown variable %s"),
- 'set_from_init_file', $var));
- return 0;
- }
- return 0 if (defined($cmdline_options->{$var}));
- delete $default_options->{$var};
- $options->{$var} = $value;
- return 1;
-}
-
-# set option from the command line. Highest precedence.
-sub set_from_cmdline($$) {
- my $var = shift;
- my $value = shift;
- delete $options->{$var};
- delete $default_options->{$var};
- if (!Texinfo::Common::valid_option($var)) {
- main::document_warn(sprintf(main::__("%s: unknown variable %s\n"),
- 'set_from_cmdline', $var));
- return 0;
- }
- $cmdline_options->{$var} = $value;
- return 1;
-}
-
-# This also could get and set some @-command results.
-# FIXME But it does not take into account what happens during conversion,
-# for that something like $converter->get_conf(...) has to be used.
-sub get_conf($) {
- my $var = shift;
- if (exists($cmdline_options->{$var})) {
- return $cmdline_options->{$var};
- } elsif (exists($options->{$var})) {
- return $options->{$var};
- } elsif (exists($default_options->{$var})) {
- return $default_options->{$var};
- } else {
- return undef;
- }
-}
-
-# to dynamically add options from init files
-sub texinfo_add_valid_option($)
-{
- my $option = shift;
- return Texinfo::Common::add_valid_option($option);
-}
-
-}
-# back in main program namespace
+# FIXME this in turns uses Texinfo::Convert::HTML which defeats the delayed
+# loading of Texinfo converter modules.
+use Texinfo::Config;
sub locate_and_load_init_file($$)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Config.pm, texi2any.pl, tp/Texinfo/Convert/HTML.pm, tp/Makefile.am (dist_modules_DATA): put Texinfo::Config namespace in a separate file. This is not perfect as Texinfo::Config is still entangled with Texinfo::Convert::HTML. In particular delayed loading of converter modules in texi2any.pl is now ineffective for Texinfo::Convert::HTML.,
Patrice Dumas <=
- Prev by Date:
branch master updated: * tp/Makefile.am (dist_converters_DATA, test_files), tp/tests/formatting/Makefile.am, tp/tests/indices/Makefile.am: add new files.
- Next by Date:
branch master updated: * tp/Texinfo/Config.pm, texi2any.pl, tp/init/*.pm, tp/t/init/*.init: rename _load_init_file as GNUT_load_init_file, _load_config as GNUT_load_config, set_from_init_file as texinfo_set_from_init_file, set_from_cmdline as GNUT_set_from_cmdline and get_conf as texinfo_get_conf to follow the convention that functions that should not be called by user init files codes are prefixed by GNUT_ while functions that can be called by user init files codes are prefixed by texinfo_.
- Previous by thread:
branch master updated: * tp/Makefile.am (dist_converters_DATA, test_files), tp/tests/formatting/Makefile.am, tp/tests/indices/Makefile.am: add new files.
- Next by thread:
branch master updated: * tp/Texinfo/Config.pm, texi2any.pl, tp/init/*.pm, tp/t/init/*.init: rename _load_init_file as GNUT_load_init_file, _load_config as GNUT_load_config, set_from_init_file as texinfo_set_from_init_file, set_from_cmdline as GNUT_set_from_cmdline and get_conf as texinfo_get_conf to follow the convention that functions that should not be called by user init files codes are prefixed by GNUT_ while functions that can be called by user init files codes are prefixed by texinfo_.
- Index(es):