texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/convert/converter.c (find_format_


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/convert/converter.c (find_format_data_index): add to find the enum converter_format of a format string.
Date: Thu, 03 Oct 2024 17:17:08 -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 a271295e87 * tp/Texinfo/XS/convert/converter.c 
(find_format_data_index): add to find the enum converter_format of a format 
string.
a271295e87 is described below

commit a271295e87df5b57cbb3f5c3ac78151215c70e07
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Aug 8 23:09:31 2024 +0200

    * tp/Texinfo/XS/convert/converter.c (find_format_data_index): add
    to find the enum converter_format of a format string.
    
    * tp/Texinfo/XS/Makefile.am (libtexinfo_convert_la_SOURCES),
    tp/Texinfo/XS/convert/txi_converter_api.c (setup_html_format_parser)
    (parse_texi_file_for_format, complete_document, converter_for_format),
    tp/Texinfo/XS/teximakehtml.c: add txi_converter_api.c implementing a
    high level API for Texinfo parsing, structure and transformations and
    converter initialization.  Move add_option_value and
    initialize_option_value to txi_converter_api.c.
    
    * tp/Texinfo/XS/teximakehtml.c (main): call setup_html_format_parser,
    parse_texi_file_for_format, complete_document and
    converter_for_format.
    
    * tp/Texinfo/XS/main/translations.c: add const.
    
    * tp/Texinfo/XS/teximakehtml.c (main, print_errors): move
    clear_error_message_list call to print_errors.
    
    * tp/Texinfo/XS/convert/txi_converter_api.c (txi_setup),
    tp/Texinfo/XS/teximakehtml.c (main): rename
    setup_html_format_parser as txi_setup and call
    configure_output_strings_translations in txi_setup.
    
    * tp/Texinfo/XS/convert/txi_converter_api.c (txi_parser),
    tp/Texinfo/XS/teximakehtml.c (main): rename parse_texi_file_for_format
    as txi_parser and do not call parse_file in txi_parser.
    
    * tp/Texinfo/XS/convert/txi_converter_api.c (txi_complete_document)
    (txi_converter), tp/Texinfo/XS/teximakehtml.c (main):
    rename complete_document as txi_complete_document and
    converter_for_format as txi_converter.
    
    * tp/Texinfo/XS/convert/txi_converter_api.c (txi_html_output),
    tp/Texinfo/XS/teximakehtml.c (main): implement HTML output as a
    function, based on teximakehtml.c and ConvertXS.xs code.
    
    * tp/Texinfo/XS/teximakehtml.c (main): call
    remove_document_descriptor in the end.
---
 .gitignore                                         |   6 +-
 ChangeLog                                          |  45 +++
 tp/Texinfo/XS/Makefile.am                          |   4 +-
 tp/Texinfo/XS/convert/converter.c                  |  12 +
 tp/Texinfo/XS/convert/converter.h                  |   2 +
 .../txi_converter_api.c}                           | 369 +++++++++------------
 tp/Texinfo/XS/convert/txi_converter_api.h          |  41 +++
 tp/Texinfo/XS/main/translations.c                  |   8 +-
 tp/Texinfo/XS/main/translations.h                  |   4 +-
 tp/Texinfo/XS/teximakehtml.c                       | 268 ++-------------
 10 files changed, 306 insertions(+), 453 deletions(-)

diff --git a/.gitignore b/.gitignore
index 0c33fbcbf0..8660dc334b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -101,10 +101,14 @@ gnulib/po/remove-potcdate.sed
 gnulib/po/stamp-po
 gnulib/po/texinfo-gnulib.pot
 
-tp/Texinfo/XS/gnulib/lib/float.h
+tp/Texinfo/XS/teximakehtml
+
 tp/Texinfo/XS/gnulib/lib/locale.h
 tp/Texinfo/XS/gnulib/lib/iconv.h
 tp/Texinfo/XS/gnulib/lib/inttypes.h
+tp/Texinfo/XS/gnulib/lib/error.h
+tp/Texinfo/XS/gnulib/lib/float.h
+tp/Texinfo/XS/gnulib/lib/fcntl.h
 tp/Texinfo/XS/gnulib/lib/obstack.h
 tp/Texinfo/XS/gnulib/lib/stdckdint.h
 tp/Texinfo/XS/gnulib/lib/stdlib.h
diff --git a/ChangeLog b/ChangeLog
index 598268fc78..e1f3faab0d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,48 @@
+2024-08-09  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/translations.c: add const.
+
+       * tp/Texinfo/XS/teximakehtml.c (main, print_errors): move
+       clear_error_message_list call to print_errors.
+
+       * tp/Texinfo/XS/convert/txi_converter_api.c (txi_setup),
+       tp/Texinfo/XS/teximakehtml.c (main): rename
+       setup_html_format_parser as txi_setup and call
+       configure_output_strings_translations in txi_setup.
+
+       * tp/Texinfo/XS/convert/txi_converter_api.c (txi_parser),
+       tp/Texinfo/XS/teximakehtml.c (main): rename parse_texi_file_for_format
+       as txi_parser and do not call parse_file in txi_parser.
+
+       * tp/Texinfo/XS/convert/txi_converter_api.c (txi_complete_document)
+       (txi_converter), tp/Texinfo/XS/teximakehtml.c (main):
+       rename complete_document as txi_complete_document and
+       converter_for_format as txi_converter.
+
+       * tp/Texinfo/XS/convert/txi_converter_api.c (txi_html_output),
+       tp/Texinfo/XS/teximakehtml.c (main): implement HTML output as a
+       function, based on teximakehtml.c and ConvertXS.xs code.
+
+       * tp/Texinfo/XS/teximakehtml.c (main): call
+       remove_document_descriptor in the end.
+
+2024-08-08  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/converter.c (find_format_data_index): add
+       to find the enum converter_format of a format string.
+
+       * tp/Texinfo/XS/Makefile.am (libtexinfo_convert_la_SOURCES),
+       tp/Texinfo/XS/convert/txi_converter_api.c (setup_html_format_parser)
+       (parse_texi_file_for_format, complete_document, converter_for_format),
+       tp/Texinfo/XS/teximakehtml.c: add txi_converter_api.c implementing a
+       high level API for Texinfo parsing, structure and transformations and
+       converter initialization.  Move add_option_value and
+       initialize_option_value to txi_converter_api.c.
+
+       * tp/Texinfo/XS/teximakehtml.c (main): call setup_html_format_parser,
+       parse_texi_file_for_format, complete_document and
+       converter_for_format.
+
 2024-08-08  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/manipulate_indices.c (get_sort_key): initialize
diff --git a/tp/Texinfo/XS/Makefile.am b/tp/Texinfo/XS/Makefile.am
index b667728675..a608fed007 100644
--- a/tp/Texinfo/XS/Makefile.am
+++ b/tp/Texinfo/XS/Makefile.am
@@ -385,7 +385,9 @@ C_libtexinfo_convert_sources = \
                        convert/converters_defaults.c \
                        convert/converters_defaults.h \
                        convert/html_converter_init_options.c \
-                       convert/html_converter_init_options.h
+                       convert/html_converter_init_options.h \
+                       convert/txi_converter_api.c \
+                       convert/txi_converter_api.h
 
 XS_libtexinfo_convert_sources = \
                        convert/build_html_perl_state.h \
diff --git a/tp/Texinfo/XS/convert/converter.c 
b/tp/Texinfo/XS/convert/converter.c
index a4e7efe2f5..875346f457 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -169,6 +169,18 @@ converter_setup (int texinfo_uninstalled, const char 
*tp_builddir,
 
 
 
+enum converter_format
+find_format_data_index (const char *format)
+{
+  int i;
+
+  for (i = 0; i < TXI_CONVERSION_FORMAT_NR; i++)
+    if (!strcmp (converter_format_data[i].output_format, format))
+      return i;
+
+  return COF_none;
+}
+
 CONVERTER *
 retrieve_converter (int converter_descriptor)
 {
diff --git a/tp/Texinfo/XS/convert/converter.h 
b/tp/Texinfo/XS/convert/converter.h
index 29876712e7..9e9b9fc779 100644
--- a/tp/Texinfo/XS/convert/converter.h
+++ b/tp/Texinfo/XS/convert/converter.h
@@ -125,6 +125,8 @@ extern CONVERTER_FORMAT_DATA converter_format_data[];
 void converter_setup (int texinfo_uninstalled, const char *tp_builddir,
                       const char *pkgdatadir, const char *top_srcdir);
 
+enum converter_format find_format_data_index (const char *format);
+
 CONVERTER *retrieve_converter (int converter_descriptor);
 size_t new_converter (void);
 void unregister_converter_descriptor (int converter_descriptor);
diff --git a/tp/Texinfo/XS/teximakehtml.c 
b/tp/Texinfo/XS/convert/txi_converter_api.c
similarity index 53%
copy from tp/Texinfo/XS/teximakehtml.c
copy to tp/Texinfo/XS/convert/txi_converter_api.c
index 6a5f97e86d..7f4ea8e19f 100644
--- a/tp/Texinfo/XS/teximakehtml.c
+++ b/tp/Texinfo/XS/convert/txi_converter_api.c
@@ -1,79 +1,144 @@
-/* teximakehtml.c -- simplistic conversion of Texinfo to HTML
-
-   Copyright 2010-2024 Free Software Foundation, Inc.
+/* Copyright 2010-2024 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/>.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <config.h>
 
 #include <stdlib.h>
 #include <stddef.h>
-#include <stdio.h>
 #include <string.h>
-#include <langinfo.h>
-#include <locale.h>
-#ifdef ENABLE_NLS
-#include <libintl.h>
-#endif
+#include <stdio.h>
 
-#include "text.h"
 #include "document_types.h"
 #include "api.h"
 #include "conf.h"
-#include "errors.h"
-/* parse_file_path */
+/* parse_file_path */ 
 #include "utils.h"
-#include "convert_to_texinfo.h"
 #include "document.h"
-#include "transformations.h"
-#include "structuring.h"
 #include "translations.h"
-/* enum converter_format */
+#include "structuring.h"
+#include "transformations.h"
 #include "converter.h"
 #include "convert_html.h"
+#include "txi_converter_api.h"
 
-#define LOCALEDIR DATADIR "/locale"
+void
+txi_setup (const char *localesdir, int texinfo_uninstalled,
+                 const char *tp_builddir,
+                 const char *pkgdatadir, const char *top_srcdir)
+{
+  if (localesdir)
+    configure_output_strings_translations (localesdir, 0);
 
-static void
-print_errors (const ERROR_MESSAGE_LIST *error_messages)
+  converter_setup (texinfo_uninstalled, tp_builddir, pkgdatadir, top_srcdir);
+  html_format_setup ();
+}
+
+/* TODO should pass other options, in particular prepended and appended
+   directories, values, expanded formats list, and maybe OPTIONS_LIST
+   for other options known by the parser */
+void
+txi_parser (const char *file_path, const char *locale_encoding,
+            const char **expanded_formats)
 {
+  char *input_file_name_and_directory[2];
+  char *input_directory;
+  size_t document_descriptor = 0;
   int i;
 
-  TEXT text;
-  text_init (&text);
+  reset_parser (0);
 
-  for (i = 0; i < error_messages->number; i++)
+  if (file_path)
     {
-      const ERROR_MESSAGE *error_msg = &error_messages->list[i];
-      text_reset (&text);
-      if (error_msg->source_info.file_name)
+      parse_file_path (file_path, input_file_name_and_directory);
+      input_directory = input_file_name_and_directory[1];
+      free (input_file_name_and_directory[0]);
+
+
+      if (strcmp (file_path, "."))
         {
-          text_append (&text, error_msg->source_info.file_name);
-          text_append_n (&text, ":", 1);
+          parser_conf_clear_INCLUDE_DIRECTORIES ();
+          parser_conf_add_include_directory (input_directory);
+          parser_conf_add_include_directory (".");
         }
-      if (error_msg->source_info.line_nr > 0)
+      free (input_directory);
+    }
+
+  parser_conf_set_LOCALE_ENCODING (locale_encoding);
+  for (i = 0; expanded_formats[i]; i++)
+    parser_conf_add_expanded_format (expanded_formats[i]);
+}
+
+/* call all the structuring/transformations typically done for a document.
+   FLAGS select the structure/transformations called.  If FORMAT_MENU is set
+   the structure functions related to menus are called.
+   No implementation in Perl, as the modules are loaded on demand, which makes
+   it impossible
+*/
+int
+txi_complete_document (DOCUMENT *document, unsigned long flags,
+                       int format_menu)
+{
+  CONST_ELEMENT_LIST *sections_list;
+  int use_sections = (flags & STTF_complete_menus_use_sections);
+
+  initialize_document_options (document);
+
+  if (flags & STTF_relate_index_entries_to_table_items)
+    relate_index_entries_to_table_items_in_tree (document->tree,
+                                           &document->indices_info);
+
+  if (flags & STTF_move_index_entries_after_items)
+    move_index_entries_after_items_in_tree (document->tree);
+
+  associate_internal_references (document);
+
+  sections_list = sectioning_structure (document);
+  if (sections_list)
+    register_document_sections_list (document, sections_list);
+
+  if (!(flags & STTF_no_warn_non_empty_parts))
+    warn_non_empty_parts (document);
+
+  if (flags & STTF_complete_tree_nodes_menus)
+    complete_tree_nodes_menus (document->tree, use_sections);
+
+  if (flags & STTF_complete_tree_nodes_missing_menu)
+    complete_tree_nodes_menus (document->tree, use_sections);
+
+  if (flags & STTF_regenerate_master_menu)
+    regenerate_master_menu (document, use_sections);
+
+  if (flags & STTF_nodes_tree)
+    {
+      CONST_ELEMENT_LIST *nodes_list = nodes_tree (document);
+      register_document_nodes_list (document, nodes_list);
+
+      if (format_menu)
         {
-          text_printf (&text, "%d:", error_msg->source_info.line_nr);
+          set_menus_node_directions (document);
+          complete_node_tree_with_menus (document);
+          check_nodes_are_referenced (document);
         }
+    }
 
-      if (text.end > 0)
-        text_append_n (&text, " ", 1);
+  if (flags & STTF_floats)
+    number_floats (document);
 
-      text_append (&text, error_msg->error_line);
-      fprintf (stderr, "%s", text.text);
-    }
-  free (text.text);
+  if (flags & STTF_setup_index_entries_sort_strings)
+    document_indices_sort_strings (document, &document->error_messages,
+                                         document->options);
 }
 
 static void
@@ -84,188 +149,47 @@ initialize_option_value (OPTION *option, OPTION 
**sorted_options,
   const OPTION *ref_option = find_option_string (sorted_options, option_name);
   if (!ref_option)
     return;
-
+  
   initialize_option (option, ref_option->type, ref_option->name);
   option->number = ref_option->number;
-
+  
   set_conf (option, int_value, char_value);
-}
+} 
 
 static void
 add_option_value (OPTIONS_LIST *options_list,  OPTION **sorted_options,
                   const char *option_name, int int_value,
                   const char *char_value)
-{
+{   
   OPTION *option = &options_list->list[options_list->number];
   initialize_option_value (option, sorted_options, option_name, int_value,
                            char_value);
   options_list->number++;
-}
+} 
 
-
-int     
-main (int argc, char *argv[])
+/* TODO add other options argument */
+CONVERTER *
+txi_converter (const char *format, const char *locale_encoding,
+               const char *program_file)
 {
-  int status;
+  size_t converter_descriptor;
+  CONVERTER *converter;
   int i;
-  char *result = 0;
-  size_t document_descriptor = 0;
-  const char *locale_encoding;
-  DOCUMENT *document;
-  const char *input_file_path;
-  char *input_file_name_and_directory[2];
-  char *input_directory;
-  char *program_file_name_and_directory[2];
-  char *program_file;
-  CONST_ELEMENT_LIST *sections_list;
-  CONST_ELEMENT_LIST *nodes_list;
+  enum converter_format converter_format = find_format_data_index (format);
   CONVERTER_INITIALIZATION_INFO *format_defaults;
   CONVERTER_INITIALIZATION_INFO *conf;
-  enum converter_format converter_format = COF_html;
-  size_t converter_descriptor;
-  CONVERTER *converter;
-  char *paths[5];
-  const char *output_file;
-  const char *destination_directory;
-  const char *output_filename;
-  const char *document_name;
-
-  /*
-  const char *texinfo_text;
-   */
-
-#ifdef ENABLE_NLS
-  setlocale (LC_ALL, "");
-
-  /* Set the text message domain.  */
-  bindtextdomain (PACKAGE_CONFIG, LOCALEDIR);
-  textdomain (PACKAGE_CONFIG);
-
-  /* set the gnulib text message domain. */
-  bindtextdomain (PACKAGE_CONFIG "_tp-gnulib", LOCALEDIR);
-#endif
-
-  configure_output_strings_translations (LOCALEDIR, 0);
-
-  locale_encoding = nl_langinfo (CODESET);
-
-  if (argc <= 1)
-    exit (1);
-
-  converter_setup (0, 0, 0, 0);
-  html_format_setup ();
-
-  parse_file_path (argv[0], program_file_name_and_directory);
-  program_file = program_file_name_and_directory[0];
-  free (program_file_name_and_directory[1]);
-
-
-  /* Texinfo file parsing */
-  input_file_path = argv[1];
-
-  parse_file_path (input_file_path, input_file_name_and_directory);
-  input_directory = input_file_name_and_directory[1];
-  free (input_file_name_and_directory[0]);
-
-  reset_parser (0);
-  
-  if (strcmp (input_file_path, "."))
-    {
-      parser_conf_clear_INCLUDE_DIRECTORIES ();
-      parser_conf_add_include_directory (input_directory);
-      parser_conf_add_include_directory (".");
-    }
-  free (input_directory);
-
-  parser_conf_set_LOCALE_ENCODING (locale_encoding);
-  parser_conf_add_expanded_format ("html");
-
-  document_descriptor = parse_file (input_file_path, &status);
-  document = retrieve_document (document_descriptor);
-
-  if (status)
-    {
-      print_errors (&document->parser_error_messages);
-      remove_document_descriptor (document_descriptor);
-      clear_error_message_list (&document->parser_error_messages);
-      exit (1);
-    }
-
-  print_errors (&document->parser_error_messages);
-  clear_error_message_list (&document->parser_error_messages);
-
-  /*
-  texinfo_text = convert_to_texinfo (document->tree);
-  fprintf (stderr, "%s", texinfo_text);
-  free (texinfo_text);
-   */
-
-
-  /* structure and transformations */
-  initialize_document_options (document);
 
-  /* TODO do a function in structuring that does that, with arguments
-     maybe flags in C.
-     relate_index_entries_to_table_items
-     move_index_entries_after_items
-     opt insert_nodes_for_sectioning_commands
-     no_warn_non_empty_parts
-
-     opt complete_tree_nodes_menus
-     opt complete_tree_nodes_missing_menu
-     opt regenerate_master_menu
-     nodes_tree
-     floats
-     setup_index_entries_sort_strings
-   */
-  /* if (relate_index_entries_to_table_items) */
-  relate_index_entries_to_table_items_in_tree (document->tree,
-                                           &document->indices_info);
-  /* if (move_index_entries_after_items) */
-  move_index_entries_after_items_in_tree (document->tree);
-  associate_internal_references (document);
-  sections_list = sectioning_structure (document);
-  if (sections_list)
-    register_document_sections_list (document, sections_list);
-  /* if (!no_warn_non_empty_parts) */
-  /* warn_non_empty_parts (document) */
-  /* complete_tree_nodes_menus */
-  /* complete_tree_nodes_missing_menu */
-  /* regenerate_master_menu */
-  /* if (nodes_tree) */
-  nodes_list = nodes_tree (document);
-  register_document_nodes_list (document, nodes_list);
-
-  /* if (format_menus) */
-  /* set_menus_node_directions */
-  /* complete_node_tree_with_menus */
-  /* check_nodes_are_referenced */
-
-  /* if (floats) */ 
-  number_floats (document);
-  /* if (setup_index_entries_sort_strings) */
-  document_indices_sort_strings (document, &document->error_messages,
-                                         document->options);
-
-  print_errors (&document->error_messages);
-  clear_error_message_list (&document->error_messages);
-
-/*
- if ($^O eq 'MSWin32') {
-  $main_program_set_options->{'DOC_ENCODING_FOR_INPUT_FILE_NAME'} = 0;
-}
-*/
-
-  /* set converter */
+  if (converter_format == COF_none)
+    return 0;
 
   /* create converter and generic converter initializations */
   converter_descriptor = new_converter ();
-  converter = retrieve_converter (converter_descriptor);
+  converter = retrieve_converter (converter_descriptor);  
 
   /* prepare specific information for the converter */
   format_defaults = new_converter_initialization_info ();
-  format_defaults->converted_format = strdup ("html");
-  format_defaults->output_format = strdup ("html");
+  format_defaults->converted_format = strdup (format);
+  format_defaults->output_format = strdup (format);
 
   conf = new_converter_initialization_info ();
   initialize_options_list (&conf->conf, 10);
@@ -283,6 +207,7 @@ main (int argc, char *argv[])
    */
   add_option_value (&conf->conf, converter->sorted_options,
                     "COMMAND_LINE_ENCODING", 0, locale_encoding);
+  /* this option is not used, it is filled to mimic texi2any */
   add_option_value (&conf->conf, converter->sorted_options,
                     "MESSAGE_ENCODING", 0, locale_encoding);
   add_option_value (&conf->conf, converter->sorted_options,
@@ -293,25 +218,42 @@ main (int argc, char *argv[])
   add_option_value (&conf->conf, converter->sorted_options,
                     "DEBUG", 1, 0);
    */
-  free (program_file);
-
 
   /* pass information to the converter and format specific initialization */
   set_converter_init_information (converter, converter_format,
                                   format_defaults, conf);
 
-  /* next 3 functions are HTML specific */
-  html_converter_init_special_unit (converter);
-  html_converter_customize (converter);
-
-  html_fill_options_directions (converter->conf, converter);
+  switch (converter_format)
+    {
+      case COF_html:
+        html_converter_init_special_unit (converter);
+        html_converter_customize (converter);
+
+        html_fill_options_directions (converter->conf, converter);
+        break;
+      default:
+        break;
+    }
 
   destroy_converter_initialization_info (format_defaults);
   destroy_converter_initialization_info (conf);
 
+  return converter;
+}
 
-  /* prepare conversion to HTML */
+char *
+txi_html_output (CONVERTER *converter, DOCUMENT *document)
+{
+  int i;
+  char *paths[5];
+  const char *output_file;
+  const char *destination_directory;
+  const char *output_filename;
+  const char *document_name;
+  char *result = 0;
+  int status;
 
+  /* prepare conversion to HTML */
   converter_set_document (converter, document);
   
   html_initialize_output_state (converter, "_output");
@@ -338,7 +280,6 @@ main (int argc, char *argv[])
   html_prepare_units_directions_files (converter,
                    output_file, destination_directory, output_filename,
                                 document_name);
-
   status = html_prepare_converted_output_info (converter, output_file,
                                                      output_filename);
 
@@ -356,8 +297,17 @@ main (int argc, char *argv[])
   if (!result)
     goto finalization;
 
-  free (result);
-    result = 0;
+  if (strlen (result) && !strlen (output_file))
+    {
+      if (converter->conf->TEST.o.integer <= 0 )
+        {
+    /* This case is unlikely to happen, as there is no output file
+       only if formatting is called as convert, which only happens in tests.
+     */
+          html_do_js_files (converter);
+        }
+      goto finalization;
+    }
 
   status = html_finish_output (converter, output_file, destination_directory);
 
@@ -370,9 +320,6 @@ main (int argc, char *argv[])
 
   html_conversion_finalization (converter);
 
-  print_errors (&converter->error_messages);
-  clear_error_message_list (&converter->error_messages);
-
-  /* destroy converter */
-  html_free_converter (converter);
+  return result;
 }
+
diff --git a/tp/Texinfo/XS/convert/txi_converter_api.h 
b/tp/Texinfo/XS/convert/txi_converter_api.h
new file mode 100644
index 0000000000..3df5516e54
--- /dev/null
+++ b/tp/Texinfo/XS/convert/txi_converter_api.h
@@ -0,0 +1,41 @@
+/* txi_html_api.h - API of conversion of Texinfo document to HTML */
+#ifndef TXI_HTML_API_H
+#define TXI_HTML_API_H
+
+#include "document_types.h"
+
+/* document structuring and transformations selection flags */
+#define STTF_relate_index_entries_to_table_items    0x0001
+#define STTF_move_index_entries_after_items         0x0002
+#define STTF_insert_nodes_for_sectioning_commands   0x0004
+#define STTF_no_warn_non_empty_parts                0x0008
+#define STTF_complete_tree_nodes_menus              0x0010
+#define STTF_complete_tree_nodes_missing_menu       0x0020
+#define STTF_regenerate_master_menu                 0x0040
+#define STTF_nodes_tree                             0x0080
+#define STTF_floats                                 0x0100
+#define STTF_setup_index_entries_sort_strings       0x0200
+/* for complete_tree_nodes_menus, complete_tree_nodes_missing_menu
+   and regenerate_master_menu */
+#define STTF_complete_menus_use_sections            0x0400
+
+/* in api.c */
+size_t parse_file (const char *input_file_path, int *status);
+
+/* locales dir for output strings translations */
+void txi_setup (const char *localesdir, int texinfo_uninstalled,
+                const char *tp_builddir,
+                const char *pkgdatadir, const char *top_srcdir);
+
+void
+txi_parser (const char *file_path, const char *locale_encoding,
+            const char **expanded_formats);
+
+int txi_complete_document (DOCUMENT *document, unsigned long flags,
+                          int format_menu);
+
+CONVERTER *txi_converter (const char *format, const char *locale_encoding,
+                          const char *program_file);
+
+char *txi_html_output (CONVERTER *converter, DOCUMENT *document);
+#endif
diff --git a/tp/Texinfo/XS/main/translations.c 
b/tp/Texinfo/XS/main/translations.c
index eb23525b2c..c7ef343656 100644
--- a/tp/Texinfo/XS/main/translations.c
+++ b/tp/Texinfo/XS/main/translations.c
@@ -52,13 +52,13 @@ my $DEFAULT_ENCODING = 'utf-8';
 static char *working_locale = 0;
 static char *locale_command = 0;
 
-static char *strings_textdomain = "texinfo_document";
+static const char *strings_textdomain = "texinfo_document";
 
 void
-configure_output_strings_translations (char *localesdir,
-                                       char *strings_textdomain_in)
+configure_output_strings_translations (const char *localesdir,
+                                       const char *strings_textdomain_in)
 {
-  char *textdomain_directory;
+  const char *textdomain_directory;
   if (strings_textdomain_in)
     strings_textdomain = strings_textdomain_in;
 
diff --git a/tp/Texinfo/XS/main/translations.h 
b/tp/Texinfo/XS/main/translations.h
index 0dc621326c..e01ed529ac 100644
--- a/tp/Texinfo/XS/main/translations.h
+++ b/tp/Texinfo/XS/main/translations.h
@@ -21,8 +21,8 @@ typedef struct NAMED_STRING_ELEMENT_LIST {
     NAMED_STRING_ELEMENT *list;
 } NAMED_STRING_ELEMENT_LIST;
 
-void configure_output_strings_translations (char *localesdir,
-                                            char *strings_textdomain_in);
+void configure_output_strings_translations (const char *localesdir,
+                                            const char *strings_textdomain_in);
 
 char *translate_string (const char * string, const char *lang,
                         const char *translation_context);
diff --git a/tp/Texinfo/XS/teximakehtml.c b/tp/Texinfo/XS/teximakehtml.c
index 6a5f97e86d..83f596ab6b 100644
--- a/tp/Texinfo/XS/teximakehtml.c
+++ b/tp/Texinfo/XS/teximakehtml.c
@@ -27,26 +27,24 @@
 #include <libintl.h>
 #endif
 
-#include "text.h"
 #include "document_types.h"
-#include "api.h"
-#include "conf.h"
+#include "converter_types.h"
 #include "errors.h"
 /* parse_file_path */
 #include "utils.h"
+/*
 #include "convert_to_texinfo.h"
+ */
+/* retrieve_document remove_document_descriptor */
 #include "document.h"
-#include "transformations.h"
-#include "structuring.h"
-#include "translations.h"
-/* enum converter_format */
+#include "txi_converter_api.h"
 #include "converter.h"
 #include "convert_html.h"
 
 #define LOCALEDIR DATADIR "/locale"
 
 static void
-print_errors (const ERROR_MESSAGE_LIST *error_messages)
+print_errors (ERROR_MESSAGE_LIST *error_messages)
 {
   int i;
 
@@ -74,61 +72,24 @@ print_errors (const ERROR_MESSAGE_LIST *error_messages)
       fprintf (stderr, "%s", text.text);
     }
   free (text.text);
-}
-
-static void
-initialize_option_value (OPTION *option, OPTION **sorted_options,
-                         const char *option_name, int int_value,
-                         const char *char_value)
-{
-  const OPTION *ref_option = find_option_string (sorted_options, option_name);
-  if (!ref_option)
-    return;
-
-  initialize_option (option, ref_option->type, ref_option->name);
-  option->number = ref_option->number;
-
-  set_conf (option, int_value, char_value);
-}
 
-static void
-add_option_value (OPTIONS_LIST *options_list,  OPTION **sorted_options,
-                  const char *option_name, int int_value,
-                  const char *char_value)
-{
-  OPTION *option = &options_list->list[options_list->number];
-  initialize_option_value (option, sorted_options, option_name, int_value,
-                           char_value);
-  options_list->number++;
+  clear_error_message_list (error_messages);
 }
 
+static const char *expanded_formats[] = {"html", 0};
 
 int     
 main (int argc, char *argv[])
 {
-  int status;
-  int i;
-  char *result = 0;
-  size_t document_descriptor = 0;
   const char *locale_encoding;
-  DOCUMENT *document;
   const char *input_file_path;
-  char *input_file_name_and_directory[2];
-  char *input_directory;
+  int status;
   char *program_file_name_and_directory[2];
   char *program_file;
-  CONST_ELEMENT_LIST *sections_list;
-  CONST_ELEMENT_LIST *nodes_list;
-  CONVERTER_INITIALIZATION_INFO *format_defaults;
-  CONVERTER_INITIALIZATION_INFO *conf;
-  enum converter_format converter_format = COF_html;
-  size_t converter_descriptor;
+  size_t document_descriptor = 0;
+  DOCUMENT *document;
   CONVERTER *converter;
-  char *paths[5];
-  const char *output_file;
-  const char *destination_directory;
-  const char *output_filename;
-  const char *document_name;
+  char *result;
 
   /*
   const char *texinfo_text;
@@ -145,41 +106,30 @@ main (int argc, char *argv[])
   bindtextdomain (PACKAGE_CONFIG "_tp-gnulib", LOCALEDIR);
 #endif
 
-  configure_output_strings_translations (LOCALEDIR, 0);
-
   locale_encoding = nl_langinfo (CODESET);
 
   if (argc <= 1)
     exit (1);
 
-  converter_setup (0, 0, 0, 0);
-  html_format_setup ();
+  txi_setup (LOCALEDIR, 0, 0, 0, 0);
 
   parse_file_path (argv[0], program_file_name_and_directory);
   program_file = program_file_name_and_directory[0];
   free (program_file_name_and_directory[1]);
 
+/*
+ if ($^O eq 'MSWin32') {
+  $main_program_set_options->{'DOC_ENCODING_FOR_INPUT_FILE_NAME'} = 0;
+}
+*/
 
   /* Texinfo file parsing */
   input_file_path = argv[1];
 
-  parse_file_path (input_file_path, input_file_name_and_directory);
-  input_directory = input_file_name_and_directory[1];
-  free (input_file_name_and_directory[0]);
-
-  reset_parser (0);
-  
-  if (strcmp (input_file_path, "."))
-    {
-      parser_conf_clear_INCLUDE_DIRECTORIES ();
-      parser_conf_add_include_directory (input_directory);
-      parser_conf_add_include_directory (".");
-    }
-  free (input_directory);
-
-  parser_conf_set_LOCALE_ENCODING (locale_encoding);
-  parser_conf_add_expanded_format ("html");
+  /* initialize parser */
+  txi_parser (input_file_path, locale_encoding, expanded_formats);
 
+  /* Texinfo document tree parsing */
   document_descriptor = parse_file (input_file_path, &status);
   document = retrieve_document (document_descriptor);
 
@@ -187,12 +137,10 @@ main (int argc, char *argv[])
     {
       print_errors (&document->parser_error_messages);
       remove_document_descriptor (document_descriptor);
-      clear_error_message_list (&document->parser_error_messages);
       exit (1);
     }
 
   print_errors (&document->parser_error_messages);
-  clear_error_message_list (&document->parser_error_messages);
 
   /*
   texinfo_text = convert_to_texinfo (document->tree);
@@ -202,177 +150,29 @@ main (int argc, char *argv[])
 
 
   /* structure and transformations */
-  initialize_document_options (document);
-
-  /* TODO do a function in structuring that does that, with arguments
-     maybe flags in C.
-     relate_index_entries_to_table_items
-     move_index_entries_after_items
-     opt insert_nodes_for_sectioning_commands
-     no_warn_non_empty_parts
-
-     opt complete_tree_nodes_menus
-     opt complete_tree_nodes_missing_menu
-     opt regenerate_master_menu
-     nodes_tree
-     floats
-     setup_index_entries_sort_strings
-   */
-  /* if (relate_index_entries_to_table_items) */
-  relate_index_entries_to_table_items_in_tree (document->tree,
-                                           &document->indices_info);
-  /* if (move_index_entries_after_items) */
-  move_index_entries_after_items_in_tree (document->tree);
-  associate_internal_references (document);
-  sections_list = sectioning_structure (document);
-  if (sections_list)
-    register_document_sections_list (document, sections_list);
-  /* if (!no_warn_non_empty_parts) */
-  /* warn_non_empty_parts (document) */
-  /* complete_tree_nodes_menus */
-  /* complete_tree_nodes_missing_menu */
-  /* regenerate_master_menu */
-  /* if (nodes_tree) */
-  nodes_list = nodes_tree (document);
-  register_document_nodes_list (document, nodes_list);
-
-  /* if (format_menus) */
-  /* set_menus_node_directions */
-  /* complete_node_tree_with_menus */
-  /* check_nodes_are_referenced */
-
-  /* if (floats) */ 
-  number_floats (document);
-  /* if (setup_index_entries_sort_strings) */
-  document_indices_sort_strings (document, &document->error_messages,
-                                         document->options);
+  txi_complete_document (document, STTF_relate_index_entries_to_table_items
+                     | STTF_move_index_entries_after_items
+                     | STTF_no_warn_non_empty_parts
+                     | STTF_nodes_tree | STTF_floats
+                     | STTF_setup_index_entries_sort_strings, 0);
 
   print_errors (&document->error_messages);
-  clear_error_message_list (&document->error_messages);
-
-/*
- if ($^O eq 'MSWin32') {
-  $main_program_set_options->{'DOC_ENCODING_FOR_INPUT_FILE_NAME'} = 0;
-}
-*/
-
-  /* set converter */
-
-  /* create converter and generic converter initializations */
-  converter_descriptor = new_converter ();
-  converter = retrieve_converter (converter_descriptor);
-
-  /* prepare specific information for the converter */
-  format_defaults = new_converter_initialization_info ();
-  format_defaults->converted_format = strdup ("html");
-  format_defaults->output_format = strdup ("html");
-
-  conf = new_converter_initialization_info ();
-  initialize_options_list (&conf->conf, 10);
-  conf->conf.number = 0;
-
-  add_option_value (&conf->conf, converter->sorted_options,
-   /*
-    */
-                    "PROGRAM", 0, program_file);
-  /* comment the line above and uncomment below to compare with
-     texi2any output
-                    "PROGRAM", 0, "texi2any");
-  add_option_value (&conf->conf, converter->sorted_options,
-                    "PACKAGE_AND_VERSION", 0, "Texinfo 7.1.90+dev");
-   */
-  add_option_value (&conf->conf, converter->sorted_options,
-                    "COMMAND_LINE_ENCODING", 0, locale_encoding);
-  add_option_value (&conf->conf, converter->sorted_options,
-                    "MESSAGE_ENCODING", 0, locale_encoding);
-  add_option_value (&conf->conf, converter->sorted_options,
-                    "LOCALE_ENCODING", 0, locale_encoding);
-  add_option_value (&conf->conf, converter->sorted_options,
-                    "XS_STRXFRM_COLLATION_LOCALE", 0, "en_US");
-  /*
-  add_option_value (&conf->conf, converter->sorted_options,
-                    "DEBUG", 1, 0);
-   */
-  free (program_file);
-
-
-  /* pass information to the converter and format specific initialization */
-  set_converter_init_information (converter, converter_format,
-                                  format_defaults, conf);
-
-  /* next 3 functions are HTML specific */
-  html_converter_init_special_unit (converter);
-  html_converter_customize (converter);
-
-  html_fill_options_directions (converter->conf, converter);
-
-  destroy_converter_initialization_info (format_defaults);
-  destroy_converter_initialization_info (conf);
-
-
-  /* prepare conversion to HTML */
-
-  converter_set_document (converter, document);
-  
-  html_initialize_output_state (converter, "_output");
-
-  status = html_setup_output (converter, paths);
 
-  if (!status)
-   {
-     memset (paths, 0, 5 * sizeof (char *));
-     goto finalization;
-   }
 
-  output_file = paths[0];
-  destination_directory = paths[1];
-  output_filename = paths[2];
-  document_name = paths[3];
+  /* setup converter */
+  converter = txi_converter ("html", locale_encoding, program_file);
 
-  html_prepare_conversion_units (converter);
-
-  html_prepare_conversion_units_targets (converter, converter->document_name);
-
-  html_translate_names (converter);
-
-  html_prepare_units_directions_files (converter,
-                   output_file, destination_directory, output_filename,
-                                document_name);
-
-  status = html_prepare_converted_output_info (converter, output_file,
-                                                     output_filename);
-
-  if (!status)
-    goto finalization;
-
-  /* conversion */
-  if (converter->document)
-    {
-      result = html_convert_output (converter, converter->document->tree,
-                  output_file, destination_directory, output_filename,
-                        document_name);
-    }
-
-  if (!result)
-    goto finalization;
+  free (program_file);
 
+  /* return value can be NULL in case of errors or an empty string, but
+     not anything else as parse_file is used with a file */
+  result = txi_html_output (converter, document);
   free (result);
-    result = 0;
-
-  status = html_finish_output (converter, output_file, destination_directory);
-
- finalization:
-
-  for (i = 0; i < 5; i++)
-    {
-      free (paths[i]);
-    }
-
-  html_conversion_finalization (converter);
 
   print_errors (&converter->error_messages);
-  clear_error_message_list (&converter->error_messages);
 
   /* destroy converter */
   html_free_converter (converter);
+  /* destroy document */
+  remove_document_descriptor (document_descriptor);
 }



reply via email to

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