texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Tue, 24 Dec 2024 03:38:21 -0500 (EST)

branch: master
commit 40e0b4e3483d81f233e4643e00fa25afcf54ec96
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Dec 23 14:42:54 2024 +0100

    * tp/texi2any.pl: use get_conf to determine if HTML_MATH and
    HIGHLIGHT_SYNTAX are set to load extensions.  Move code around.
    
    * tp/Texinfo/XS/teximakehtml.c (locate_and_load_extension_file)
    (main): load interpreter right after command-line options.
    Load extension files based on customization variables set.
    
    * tp/Texinfo/XS/teximakehtml.c (FORMAT_SPECIFICATION, main): handle
    format needing an init file.
---
 ChangeLog                    |  12 ++++
 tp/Texinfo/XS/teximakehtml.c | 135 ++++++++++++++++++++++++++++++-------------
 tp/texi2any.pl               |  21 +++----
 3 files changed, 119 insertions(+), 49 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d6283732b4..160696e31c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-12-23  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/texi2any.pl: use get_conf to determine if HTML_MATH and
+       HIGHLIGHT_SYNTAX are set to load extensions.  Move code around.
+
+       * tp/Texinfo/XS/teximakehtml.c (locate_and_load_extension_file)
+       (main): load interpreter right after command-line options.
+       Load extension files based on customization variables set.
+
+       * tp/Texinfo/XS/teximakehtml.c (FORMAT_SPECIFICATION, main): handle
+       format needing an init file.
+
 2024-12-23  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/texinfo.c (txi_set_base_default_options),
diff --git a/tp/Texinfo/XS/teximakehtml.c b/tp/Texinfo/XS/teximakehtml.c
index f0c921b3ec..2b8192cf5c 100644
--- a/tp/Texinfo/XS/teximakehtml.c
+++ b/tp/Texinfo/XS/teximakehtml.c
@@ -101,6 +101,7 @@ typedef struct FORMAT_SPECIFICATION {
     const char *converted_format;
     /* Perl module name */
     const char *module;
+    const char *init_file;
 } FORMAT_SPECIFICATION;
 
 static FORMAT_SPECIFICATION formats_table[] = {
@@ -109,10 +110,10 @@ static FORMAT_SPECIFICATION formats_table[] = {
            | STTF_no_warn_non_empty_parts
            | STTF_nodes_tree | STTF_floats | STTF_split
            | STTF_setup_index_entries_sort_strings,
-   NULL, "Texinfo::Convert::HTML"},
-  {"parse", 0, NULL, NULL},
-  {"structure", STTF_nodes_tree | STTF_floats | STTF_split, NULL, NULL},
-  {NULL, 0, NULL, NULL}
+   NULL, "Texinfo::Convert::HTML", NULL},
+  {"parse", 0, NULL, NULL, NULL},
+  {"structure", STTF_nodes_tree | STTF_floats | STTF_split, NULL, NULL, NULL},
+  {NULL, 0, NULL, NULL, NULL}
 };
 
 static VALUE_LIST values;
@@ -793,6 +794,38 @@ locate_and_load_init_file (const char *filename, 
STRING_LIST *directories,
     warn_deprecated_dirs (&deprecated_dirs_used);
 }
 
+static void
+locate_and_load_extension_file (const char *filename, STRING_LIST *directories)
+{
+  char *file = locate_file_in_dirs (filename, directories, 0, 0, 0);
+
+  if (file)
+    {
+#ifdef EMBED_PERL
+      if (embedded_interpreter)
+        {
+          call_config_GNUT_load_init_file (file);
+          loaded_init_files_nr++;
+        }
+      else
+#endif
+        {
+          char *decoded_filename = decode_input ((char *) filename);
+          fprintf (stderr, "No interpreter, cannot load: %s\n",
+                   filename);
+          free (decoded_filename);
+        }
+    }
+  else
+    {
+      char *decoded_filename = decode_input ((char *) filename);
+      document_warn ("could not read extension file %s", decoded_filename);
+
+      free (decoded_filename);
+      exit (EXIT_FAILURE);
+    }
+}
+
 const char *input_file_suffixes[] = {
 ".txi",".texinfo",".texi",".txinfo", "", NULL
 };
@@ -945,6 +978,8 @@ main (int argc, char *argv[], char *env[])
   char *top_srcdir;
   char *top_builddir;
   char *tp_builddir = 0;
+  OPTION *html_math_option;
+  OPTION *highlight_syntax_option;
   OPTION *test_option;
   OPTION *no_warn_option;
   OPTION *format_menu_option;
@@ -1726,6 +1761,54 @@ main (int argc, char *argv[], char *env[])
       store_value (&values, "TEXI2HTML", "1");
     }
 
+#ifdef EMBED_PERL
+  embedded_interpreter = 1;
+#endif
+
+  if (embed_interpreter_p == -1)
+    embedded_interpreter = 0;
+  else if (embed_interpreter_p == 1)
+    embedded_interpreter = 1;
+
+  if (!embedded_interpreter)
+    /* it is the best we have without an embedded interpreter */
+    add_option_value (&program_options, "XS_STRXFRM_COLLATION_LOCALE", 0,
+                      "en_US");
+
+#ifdef EMBED_PERL
+  if (embedded_interpreter)
+    {/* setup paths here to avoid memory management as much as possible
+        in Perl C */
+      char *load_modules_path;
+      if (conversion_paths_info.texinfo_uninstalled)
+        xasprintf (&load_modules_path, "%s/tp/%s.pl",
+                      conversion_paths_info.p.uninstalled.top_srcdir,
+                                       load_txi_modules_basename);
+      else
+        xasprintf (&load_modules_path, "%s/%s",
+                  conversion_paths_info.p.installed.converterdatadir,
+                   load_txi_modules_basename);
+      call_init_perl (&argc, &argv, &env, load_modules_path);
+      free (load_modules_path);
+    }
+#endif
+
+  html_math_option = get_conf (program_options.options->HTML_MATH.number);
+  if (html_math_option && html_math_option->o.string
+      && !strcmp (html_math_option->o.string, "l2h"))
+    locate_and_load_extension_file ("latex2html.pm", &internal_extension_dirs);
+
+  if (html_math_option && html_math_option->o.string
+      && !strcmp (html_math_option->o.string, "t4h"))
+    locate_and_load_extension_file ("tex4ht.pm", &internal_extension_dirs);
+
+  highlight_syntax_option
+    = get_conf (program_options.options->HIGHLIGHT_SYNTAX.number);
+  if (highlight_syntax_option && highlight_syntax_option->o.string
+      && strlen (highlight_syntax_option->o.string))
+    locate_and_load_extension_file ("highlight_syntax.pm",
+                                    &internal_extension_dirs);
+
   test_option = get_conf (program_options.options->TEST.number);
   if (test_option && test_option->o.integer > 0)
     test_mode_set = 1;
@@ -1754,6 +1837,10 @@ main (int argc, char *argv[], char *env[])
       free (format_name);
     }
 
+  output_format_option
+    = get_conf (program_options.options->TEXINFO_OUTPUT_FORMAT.number);
+  output_format = output_format_option->o.string;
+
   if (!test_mode_set
       && conversion_paths_info.texinfo_uninstalled
       && conversion_paths_info.p.uninstalled.top_srcdir)
@@ -1765,9 +1852,6 @@ main (int argc, char *argv[], char *env[])
       free (in_source_util_dir);
     }
 
-  output_format_option
-    = get_conf (program_options.options->TEXINFO_OUTPUT_FORMAT.number);
-  output_format = output_format_option->o.string;
 
   for (i = 0; formats_table[i].name; i++)
     {
@@ -1778,6 +1862,11 @@ main (int argc, char *argv[], char *env[])
         }
     }
 
+  /* for a format setup with an init file */
+  if (format_specification->init_file)
+    locate_and_load_extension_file (format_specification->init_file,
+                                    &internal_extension_dirs);
+
   if (format_specification->converted_format)
     converted_format = format_specification->converted_format;
   else
@@ -1801,38 +1890,6 @@ main (int argc, char *argv[], char *env[])
                           default_expanded_formats.list[i]);
     }
 
-#ifdef EMBED_PERL
-  embedded_interpreter = 1;
-#endif
-
-  if (embed_interpreter_p == -1)
-    embedded_interpreter = 0;
-  else if (embed_interpreter_p == 1)
-    embedded_interpreter = 1;
-
-  if (!embedded_interpreter)
-    /* it is the best we have without an embedded interpreter */
-    add_option_value (&program_options, "XS_STRXFRM_COLLATION_LOCALE", 0,
-                      "en_US");
-
-#ifdef EMBED_PERL
-  if (embedded_interpreter)
-    {/* setup paths here to avoid memory management as much as possible
-        in Perl C */
-      char *load_modules_path;
-      if (conversion_paths_info.texinfo_uninstalled)
-        xasprintf (&load_modules_path, "%s/tp/%s.pl",
-                      conversion_paths_info.p.uninstalled.top_srcdir,
-                                       load_txi_modules_basename);
-      else
-        xasprintf (&load_modules_path, "%s/%s",
-                  conversion_paths_info.p.installed.converterdatadir,
-                   load_txi_modules_basename);
-      call_init_perl (&argc, &argv, &env, load_modules_path);
-      free (load_modules_path);
-    }
-#endif
-
   /* corresponds to eval "require $module"; in texi2any.pl */
   txi_converter_output_format_setup (converted_format);
 
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index 5586259bf2..2f240b94ed 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -1348,19 +1348,19 @@ sub process_config($) {
 process_config($cmdline_options);
 
 my $latex2html_file = 'latex2html.pm';
-if (defined($cmdline_options->{'HTML_MATH'})
-      and $cmdline_options->{'HTML_MATH'} eq 'l2h') {
+my $html_math_option = get_conf('HTML_MATH');
+if (defined($html_math_option) and $html_math_option eq 'l2h') {
   locate_and_load_extension_file($latex2html_file, $internal_extension_dirs);
 }
 
 my $tex4ht_file = 'tex4ht.pm';
-if (defined($cmdline_options->{'HTML_MATH'})
-      and $cmdline_options->{'HTML_MATH'} eq 't4h') {
+if (defined($html_math_option) and $html_math_option eq 't4h') {
   locate_and_load_extension_file($tex4ht_file, $internal_extension_dirs);
 }
 
 my $highlight_syntax_file = 'highlight_syntax.pm';
-if ($cmdline_options->{'HIGHLIGHT_SYNTAX'}) {
+my $highlight_syntax_option = get_conf('HIGHLIGHT_SYNTAX');
+if (defined($highlight_syntax_option) and $highlight_syntax_option ne '') {
   locate_and_load_extension_file($highlight_syntax_file,
                                  $internal_extension_dirs);
 }
@@ -1413,11 +1413,6 @@ if (defined($ENV{'TEXINFO_OUTPUT_FORMAT'})
 }
 
 my $output_format = get_conf('TEXINFO_OUTPUT_FORMAT');
-# for a format setup with an init file
-if (defined ($formats_table{$output_format}->{'init_file'})) {
-  locate_and_load_extension_file($formats_table{$output_format}->{'init_file'},
-                                 $internal_extension_dirs);
-}
 
 if ($call_texi2dvi) {
   if (defined(get_conf('OUTFILE')) and @ARGV > 1) {
@@ -1555,6 +1550,12 @@ if (get_conf('TREE_TRANSFORMATIONS')) {
   }
 }
 
+# for a format setup with an init file
+if (defined ($formats_table{$output_format}->{'init_file'})) {
+  locate_and_load_extension_file($formats_table{$output_format}->{'init_file'},
+                                 $internal_extension_dirs);
+}
+
 # in general the format name is the format being converted.  If this is
 # not the case, the converted format is set here.  For example, for
 # the epub3 format, the converted format is html.  The converted format



reply via email to

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