texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Sun, 10 Dec 2023 05:33:08 -0500 (EST)

branch: master
commit 9464a3b0564cc25dcb483b773e6af3cdd9aebb7e
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Dec 9 23:56:44 2023 +0100

    * tp/Texinfo/Convert/HTML.pm (_default_format_end_file): avoid using
    intermediary variables.
    
    * doc/texi2any_api.texi (Associating Information to an Output File),
    tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides),
    tp/Texinfo/XS/convert/ConvertXS.xs (html_register_file_information)
    (html_get_file_information), tp/Texinfo/XS/convert/convert_html.c
    (html_register_file_information, html_get_file_information)
    (html_set_pages_files, setup_output_simple_page)
    (html_finalize_output_state), tp/Texinfo/XS/main/converter_types.h
    (ASSOCIATED_INFO_LIST, CONVERTER): implement get_file_information and
    register_file_information and add an XS interface.
---
 ChangeLog                            |  15 ++++
 doc/texi2any_api.texi                |   6 +-
 tp/Texinfo/Convert/HTML.pm           |  34 +++++----
 tp/Texinfo/XS/convert/ConvertXS.xs   |  49 ++++++++++++
 tp/Texinfo/XS/convert/convert_html.c | 142 +++++++++++++++++++++++++++++------
 tp/Texinfo/XS/convert/convert_html.h |   5 ++
 tp/Texinfo/XS/main/converter_types.h |  18 +++--
 7 files changed, 220 insertions(+), 49 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7782b7ded6..de7c29e151 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2023-12-09  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm (_default_format_end_file): avoid using
+       intermediary variables.
+
+       * doc/texi2any_api.texi (Associating Information to an Output File),
+       tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides),
+       tp/Texinfo/XS/convert/ConvertXS.xs (html_register_file_information)
+       (html_get_file_information), tp/Texinfo/XS/convert/convert_html.c
+       (html_register_file_information, html_get_file_information)
+       (html_set_pages_files, setup_output_simple_page)
+       (html_finalize_output_state), tp/Texinfo/XS/main/converter_types.h
+       (ASSOCIATED_INFO_LIST, CONVERTER): implement get_file_information and
+       register_file_information and add an XS interface.
+
 2023-12-09  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/convert_html.c (format_simpletitle)
diff --git a/doc/texi2any_api.texi b/doc/texi2any_api.texi
index 45825bb4fc..2c504c3900 100644
--- a/doc/texi2any_api.texi
+++ b/doc/texi2any_api.texi
@@ -3078,12 +3078,12 @@ Get @var{$content} associated to the Texinfo tree 
element @var{\%element}.
 
 To be able to retrieve information associated to the current file, in general
 for the file begin or end formatting, @code{register_file_information} can  be
-used to associate information, and @code{get_file_information} to retrieve that
-information.
+used to associate integer information, and @code{get_file_information} to
+retrieve that information.
 
 @defun @var{$converter}->register_file_information ($key, $value)
 Associate the current output file name file to the key @var{$key}, itself
-associated to the value @var{$value}.
+associated to the integer value @var{$value}.
 @end defun
 
 @deftypefun {@var{$value} =} @var{$converter}->get_file_information 
(@var{$key}, @var{$file_name})
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index b75f43eb21..b03c278f5c 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -185,6 +185,10 @@ my %XS_conversion_overrides = (
   "Texinfo::Convert::HTML::in_align"
    => "Texinfo::Convert::ConvertXS::html_in_align",
 
+  "Texinfo::Convert::HTML::register_file_information"
+   => "Texinfo::Convert::ConvertXS::html_register_file_information",
+  "Texinfo::Convert::HTML::get_file_information",
+   => "Texinfo::Convert::ConvertXS::html_get_file_information",
   "Texinfo::Convert::HTML::register_opened_section_level"
    => "Texinfo::Convert::ConvertXS::html_register_opened_section_level",
   "Texinfo::Convert::HTML::close_registered_sections_level"
@@ -1988,9 +1992,9 @@ sub get_associated_formatted_inline_content($$) {
 }
 
 # API to register an information to a file and get it.  To be able to
-# set an information during conversion and get it back during headers
+# set an integer information during conversion and get it back during headers
 # and footers conversion
-sub register_file_information($$;$)
+sub register_file_information($$$)
 {
   my $self = shift;
   my $key = shift;
@@ -10555,21 +10559,23 @@ sub _default_format_end_file($$$)
   my $filename = shift;
   my $output_unit = shift;
 
-  my $program_text = '';
+  my $result = '';
   if ($self->get_conf('PROGRAM_NAME_IN_FOOTER')) {
+    $result .= "<p>\n  ";
+    my $open = $self->html_attribute_class('span', ['program-in-footer']);
+    $result .= $open.'>' if ($open ne '');
+
     my $program_string
       = &{$self->formatting_function('format_program_string')}($self);
-    my $open = $self->html_attribute_class('span', ['program-in-footer']);
-    if ($open ne '') {
-      $program_string = $open.'>'.$program_string.'</span>';
-    }
-    $program_text .= "<p>
-  $program_string
-</p>";
+    $result .= $program_string;
+
+    $result .= '</span>' if ($open ne '');
+    $result .= "\n</p>";
   }
+  $result .= "\n\n";
 
   my $pre_body_close = $self->get_conf('PRE_BODY_CLOSE');
-  $pre_body_close = '' if (!defined($pre_body_close));
+  $result .= $pre_body_close if (defined($pre_body_close));
 
   my $jslicenses = $self->get_info('jslicenses');
   if ($jslicenses
@@ -10583,16 +10589,14 @@ sub _default_format_end_file($$$)
     my $js_path = $self->get_conf('JS_WEBLABELS_FILE');
     if (defined($js_setting) and defined($js_path)
         and ($js_setting eq 'generate' or $js_setting eq 'reference')) {
-      $pre_body_close .=
+      $result .=
         '<a href="'.$self->url_protect_url_text($js_path).'" 
rel="jslicense"><small>'
         .$self->convert_tree($self->gdt('JavaScript license information'))
         .'</small></a>';
     }
   }
 
-  return "${program_text}
-
-$pre_body_close
+  return "$result
 </body>
 </html>
 ";
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 2a0aa6ceb6..eeffa48275 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -621,6 +621,55 @@ html_in_align (SV *converter_in)
     OUTPUT:
          RETVAL
 
+void
+html_register_file_information (SV *converter_in, key, int value)
+         char *key = (char *)SvPVutf8_nolen($arg);
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_register_file_information");
+         if (self)
+           {
+             html_register_file_information (self, key, value);
+           }
+
+void
+html_get_file_information (SV *converter_in, key, ...)
+         char *key = (char *)SvPVutf8_nolen($arg);
+    PROTOTYPE: $$;$
+     PREINIT:
+         CONVERTER *self;
+         SV *filename_sv = 0;
+         int found = 0;
+         int result = 0;
+         SV *found_sv;
+         SV *result_sv;
+     PPCODE:
+         self = get_sv_converter (converter_in,
+                                  "html_get_file_information");
+         if (items > 2 && SvOK(ST(2)))
+           filename_sv = ST(2);
+         if (self)
+           {
+             char *filename = 0;
+             int status;
+             if (filename_sv)
+               filename = SvPVutf8_nolen (filename_sv);
+             result = html_get_file_information (self, key, filename, &status);
+             if (status >= 0)
+               found = 1;
+           }
+         found_sv = newSViv ((IV)found);
+         if (found)
+           result_sv = newSViv ((IV)result);
+         else
+           result_sv = newSV(0);
+
+         EXTEND(SP, 2);
+         PUSHs(sv_2mortal(found_sv));
+         PUSHs(sv_2mortal(result_sv));
+
 void
 html_register_opened_section_level (SV *converter_in, int level, close_string)
          char *close_string = (char *)SvPVutf8_nolen($arg);
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 81eb659759..99788497b9 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -1081,6 +1081,75 @@ html_get_associated_formatted_inline_content (CONVERTER 
*self,
   return strdup ("");
 }
 
+static int
+compare_page_name_number (const void *a, const void *b)
+{
+  const PAGE_NAME_NUMBER *pnn_a = (const PAGE_NAME_NUMBER *) a;
+  const PAGE_NAME_NUMBER *pnn_b = (const PAGE_NAME_NUMBER *) b;
+
+  return strcmp (pnn_a->page_name, pnn_b->page_name);
+}
+
+size_t
+find_page_name_number
+     (const PAGE_NAME_NUMBER_LIST *page_name_number,
+                                          const char *page_name)
+{
+  PAGE_NAME_NUMBER *result = 0;
+  static PAGE_NAME_NUMBER searched_page_name;
+  searched_page_name.page_name = page_name;
+
+  result = (PAGE_NAME_NUMBER *) bsearch (&searched_page_name,
+                page_name_number->list,
+                page_name_number->number, sizeof(PAGE_NAME_NUMBER),
+                compare_page_name_number);
+  return result->number;
+}
+
+/* API to register an information to a file and get it.  To be able to
+   set an information during conversion and get it back during headers
+   and footers conversion */
+void
+html_register_file_information (CONVERTER *self, const char *key,
+                                int value)
+{
+  ASSOCIATED_INFO *associated_info
+    = &self->html_files_information.list[self->current_filename.file_number];
+  add_associated_info_integer (associated_info, key, value);
+}
+
+int
+html_get_file_information (CONVERTER *self, const char *key,
+                           const char *filename, int *status)
+{
+  size_t page_number;
+  ASSOCIATED_INFO *associated_info;
+  const KEY_PAIR *k;
+
+  *status = 0;
+  if (filename)
+    {
+      page_number = find_page_name_number (&self->page_name_number,
+                                           filename);
+      if (!page_number)
+        {
+          *status = -1;
+          return 0;
+        }
+    }
+  else
+    page_number = self->current_filename.file_number;
+
+  associated_info = &self->html_files_information.list[page_number];
+  k = lookup_associated_info (associated_info, key);
+  if (!k)
+    {
+      *status = -2;
+      return 0;
+    }
+  return k->integer;
+}
+
 void
 html_register_opened_section_level (CONVERTER *self, int level,
                                     const char *close_string)
@@ -3599,31 +3668,6 @@ html_command_text (CONVERTER *self, const ELEMENT 
*command,
   return 0;
 }
 
-static int
-compare_page_name_number (const void *a, const void *b)
-{
-  const PAGE_NAME_NUMBER *pnn_a = (const PAGE_NAME_NUMBER *) a;
-  const PAGE_NAME_NUMBER *pnn_b = (const PAGE_NAME_NUMBER *) b;
-
-  return strcmp (pnn_a->page_name, pnn_b->page_name);
-}
-
-size_t
-find_page_name_number
-     (const PAGE_NAME_NUMBER_LIST *page_name_number,
-                                          const char *page_name)
-{
-  PAGE_NAME_NUMBER *result = 0;
-  static PAGE_NAME_NUMBER searched_page_name;
-  searched_page_name.page_name = page_name;
-
-  result = (PAGE_NAME_NUMBER *) bsearch (&searched_page_name,
-                page_name_number->list,
-                page_name_number->number, sizeof(PAGE_NAME_NUMBER),
-                compare_page_name_number);
-  return result->number;
-}
-
 static int
 compare_selector_style (const void *a, const void *b)
 {
@@ -4822,6 +4866,12 @@ html_set_pages_files (CONVERTER *self, OUTPUT_UNIT_LIST 
*output_units,
   memset (self->page_css.list, 0,
           self->page_css.number * sizeof (CSS_LIST));
 
+  self->html_files_information.number = self->output_unit_files.number +1;
+  self->html_files_information.list = (ASSOCIATED_INFO *)
+    malloc (self->html_files_information.number * sizeof (ASSOCIATED_INFO));
+  memset (self->html_files_information.list, 0,
+          self->html_files_information.number * sizeof (ASSOCIATED_INFO));
+
   return files_source_info;
 }
 
@@ -4837,6 +4887,12 @@ setup_output_simple_page (CONVERTER *self, const char 
*output_filename)
   memset (self->page_css.list, 0,
           self->page_css.number * sizeof (CSS_LIST));
 
+  self->html_files_information.number = 1+1;
+  self->html_files_information.list = (ASSOCIATED_INFO *)
+       malloc (self->html_files_information.number * sizeof (ASSOCIATED_INFO));
+  memset (self->html_files_information.list, 0,
+          self->html_files_information.number * sizeof (ASSOCIATED_INFO));
+
   self->page_name_number.number = 1;
   self->page_name_number.list = (PAGE_NAME_NUMBER *)
       malloc (self->page_name_number.number * sizeof (PAGE_NAME_NUMBER));
@@ -5407,6 +5463,14 @@ format_element_footer (CONVERTER *self,
   FORMATTING_REFERENCE *formatting_reference
    = &self->current_formatting_references[FR_format_element_footer];
 
+/*
+  if (formatting_reference->status == FRS_status_default_set)
+    {
+      html_default_format_element_footer (self, unit_type, output_unit,
+                                          content, element, result)
+    }
+  else
+*/
    {
      char *formatted_footer
        = call_formatting_function_format_element_footer (self,
@@ -5418,12 +5482,27 @@ format_element_footer (CONVERTER *self,
    }
 }
 
+/*
+char *
+html_default_format_end_file (CONVERTER *self, const char *filename,
+                              const OUTPUT_UNIT *output_unit)
+{
+}
+*/
+
 char *
 format_end_file (CONVERTER *self, const char *filename,
                  const OUTPUT_UNIT *output_unit)
 {
   FORMATTING_REFERENCE *formatting_reference
    = &self->current_formatting_references[FR_format_end_file];
+/*
+  if (formatting_reference->status == FRS_status_default_set)
+    {
+      return html_default_format_end_file (self, filename, output_unit);
+    }
+  else
+*/
     {
       return call_formatting_function_format_end_file (self,
                                                      formatting_reference,
@@ -5437,6 +5516,13 @@ format_begin_file (CONVERTER *self, const char *filename,
 {
   FORMATTING_REFERENCE *formatting_reference
    = &self->current_formatting_references[FR_format_begin_file];
+/*
+  if (formatting_reference->status == FRS_status_default_set)
+    {
+      return html_default_format_begin_file (self, filename, output_unit);
+    }
+  else
+*/
     {
       return call_formatting_function_format_begin_file (self,
                                                      formatting_reference,
@@ -8454,6 +8540,12 @@ html_finalize_output_state (CONVERTER *self)
     }
   free (self->page_css.list);
 
+  for (i = 0; i < self->html_files_information.number; i++)
+    {
+      destroy_associated_info (&self->html_files_information.list[i]);
+    }
+  free (self->html_files_information.list);
+
   /* should not be possible with default code, as
      close_registered_sections_level(0)
      is called at the end of processing or at the end of each file.
diff --git a/tp/Texinfo/XS/convert/convert_html.h 
b/tp/Texinfo/XS/convert/convert_html.h
index 796a77024a..70ca82a7fb 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -62,6 +62,11 @@ enum command_id html_in_align (CONVERTER *self);
 
 char *debug_print_html_contexts (CONVERTER *self);
 
+void html_register_file_information (CONVERTER *self, const char *key,
+                                     int value);
+int html_get_file_information (CONVERTER *self, const char *key,
+                               const char *filename, int *status);
+
 void html_register_opened_section_level (CONVERTER *self, int level,
                                          const char *close_string);
 STRING_LIST *html_close_registered_sections_level (CONVERTER *self,
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index 7661a59f5f..38e356f368 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -260,8 +260,8 @@ typedef struct HTML_SHARED_CONVERSION_STATE {
     int element_explanation_content; /* element_explanation_content->{ELEMENT 
$command}
                                 = ELEMENT */
     int footnote_id_numbers; /* footnote_id_numbers->{char $footid} = int */
-    /* probably not useful, directly use expanded formats in the converter 
-       needed in perl as expanded formats are accessed per format in the API
+    /* Not useful, directly use expanded formats in the converter.
+       Needed in perl as expanded formats are accessed per format in the API
     int expanded_format_raw;
      */
     int formatted_index_entries; /* formatted_index_entries->{INDEX_ENTRY 
$index_entry_ref} = 1, ++ */
@@ -599,6 +599,11 @@ typedef struct HTMLXREF_MANUAL_ELEMENT_WARNED_LIST {
     HTMLXREF_MANUAL_ELEMENT_WARNED *list;
 } HTMLXREF_MANUAL_ELEMENT_WARNED_LIST;
 
+typedef struct ASSOCIATED_INFO_LIST {
+    size_t number;
+    ASSOCIATED_INFO *list;
+} ASSOCIATED_INFO_LIST;
+
 typedef struct CONVERTER {
     int converter_descriptor;
   /* perl converter. This should be HV *hv,
@@ -680,8 +685,6 @@ typedef struct CONVERTER {
     size_t *output_unit_file_indices;   /* array of indices in 
output_unit_files
               each position corresponding to an output unit. */
     size_t *special_unit_file_indices;  /* same for special output units */
-    PAGES_CSS_LIST page_css;
-    HTMLXREF_MANUAL_ELEMENT_WARNED_LIST check_htmlxref_already_warned;
     ELEMENT *simpletitle_tree;
     enum command_id simpletitle_cmd;
 
@@ -720,6 +723,9 @@ typedef struct CONVERTER {
     HTML_INLINE_CONTENT_STACK pending_inline_content;
     HTML_PENDING_FOOTNOTE_STACK pending_footnotes;
     HTML_ASSOCIATED_INLINE_CONTENT_LIST associated_inline_content;
+    PAGES_CSS_LIST page_css;
+    HTMLXREF_MANUAL_ELEMENT_WARNED_LIST check_htmlxref_already_warned;
+    ASSOCIATED_INFO_LIST html_files_information;
     /* state common with perl converter, not transmitted to perl */
     int use_unicode_text;
 } CONVERTER;
@@ -789,13 +795,13 @@ typedef struct BUTTON_SPECIFICATION {
      but we don't want to include the Perl headers everywhere; */
       void *sv_reference; /* BST_function */
       void *sv_string; /* BST_string scalar reference */
-      BUTTON_SPECIFICATION_INFO *button_info; /* BST_direction_info 
+      BUTTON_SPECIFICATION_INFO *button_info; /* BST_direction_info
                                               array reference of length 2 */
     };
 } BUTTON_SPECIFICATION;
 
 typedef struct BUTTON_SPECIFICATION_LIST {
-    void *av; /* reference to perl data that can be used instead of 
+    void *av; /* reference to perl data that can be used instead of
                  the list */
     size_t number;
     BUTTON_SPECIFICATION *list;



reply via email to

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