texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Mon, 20 Nov 2023 18:30:19 -0500 (EST)

branch: master
commit 4d0292815f475d65fea8694e58c460915a38ee0a
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Nov 20 21:39:46 2023 +0100

    * tp/Texinfo/XS/convert/build_html_perl_state.c (build_html_target)
    (build_html_element_targets, add_html_element_target)
    (pass_html_element_targets, build_html_special_targets): split
    build_html_element_targets in three functions to be able to build one
    html target, and add one.
    
    * tp/Texinfo/XS/convert/convert_html.c
    (convert_output_output_unit_internal): add a flag for
    file_changed_counter, to be sure that the state is rebuilt.
    
    * tp/Texinfo/XS/convert/build_html_perl_state.c
    (build_html_formatting_state), tp/Texinfo/XS/convert/convert_html.c
    (register_added_target, get_target, html_command_id),
    tp/Texinfo/XS/main/converter_types.h (HTML_ADDED_TARGET_LIST)
    (CONVERTER): add get_target and html_command_id and rebuild perl
    state with a new target.
---
 ChangeLog                                     |  19 ++++
 tp/Texinfo/XS/convert/build_html_perl_state.c | 132 +++++++++++++++++---------
 tp/Texinfo/XS/convert/convert_html.c          |  41 ++++++++
 tp/Texinfo/XS/main/converter_types.h          |   7 ++
 tp/Texinfo/XS/main/utils.h                    |   2 +
 5 files changed, 154 insertions(+), 47 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 47dddb393f..770f01322c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2023-11-20  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/build_html_perl_state.c (build_html_target)
+       (build_html_element_targets, add_html_element_target)
+       (pass_html_element_targets, build_html_special_targets): split
+       build_html_element_targets in three functions to be able to build one
+       html target, and add one.
+
+       * tp/Texinfo/XS/convert/convert_html.c
+       (convert_output_output_unit_internal): add a flag for
+       file_changed_counter, to be sure that the state is rebuilt.
+
+       * tp/Texinfo/XS/convert/build_html_perl_state.c
+       (build_html_formatting_state), tp/Texinfo/XS/convert/convert_html.c
+       (register_added_target, get_target, html_command_id),
+       tp/Texinfo/XS/main/converter_types.h (HTML_ADDED_TARGET_LIST)
+       (CONVERTER): add get_target and html_command_id and rebuild perl
+       state with a new target.
+
 2023-11-20  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XSLoader.pm (init): avoid undefined value in warning
diff --git a/tp/Texinfo/XS/convert/build_html_perl_state.c 
b/tp/Texinfo/XS/convert/build_html_perl_state.c
index 1182359544..8ebbd4a438 100644
--- a/tp/Texinfo/XS/convert/build_html_perl_state.c
+++ b/tp/Texinfo/XS/convert/build_html_perl_state.c
@@ -63,62 +63,79 @@
      free below is redirected to Perl's implementation.  This could
      cause crashes if the two malloc/free implementations were different.  */
 
+#define STORE(key, sv) hv_store (html_target_hv, key, strlen (key), sv, 0)
+HV *
+build_html_target (HTML_TARGET *html_target)
+{
+  HV *html_target_hv;
+  SV *target_sv;
+
+  dTHX;
+
+  target_sv = newSVpv_utf8 (html_target->target, 0);
+
+  html_target_hv = newHV ();
+
+  STORE("target", target_sv);
+  if (html_target->special_unit_filename)
+    STORE("special_unit_filename",
+          newSVpv_utf8 (html_target->special_unit_filename, 0));
+  if (html_target->node_filename)
+    STORE("node_filename",
+          newSVpv_utf8 (html_target->node_filename, 0));
+  if (html_target->section_filename)
+    STORE("section_filename",
+          newSVpv_utf8 (html_target->section_filename, 0));
+  if (html_target->contents_target)
+    STORE("contents_target",
+          newSVpv_utf8 (html_target->contents_target, 0));
+  if (html_target->shortcontents_target)
+    STORE("shortcontents_target",
+          newSVpv_utf8 (html_target->shortcontents_target, 0));
+#undef STORE
+  return html_target_hv;
+}
+
+static void
+add_html_element_target (HV *hv, HTML_TARGET *html_target)
+{
+  SV *html_target_sv;
+  HV *html_target_hv;
+  SV *element_sv;
+
+  dTHX;
+
+  html_target_hv = build_html_target (html_target);
+
+  if (!html_target->element->hv)
+    {
+      fprintf (stderr, "BUG: No hv for target '%s'\n", html_target->target);
+      fatal ("No hv for target");
+    }
+
+  element_sv = newRV_inc ((SV *) html_target->element->hv);
+  html_target_sv = newRV_noinc ((SV *) html_target_hv);
+  hv_store_ent (hv, element_sv, html_target_sv, 0);
+}
+
 /* this function is used to set the initial targets information. */
 /* Dynamical changes are done in other functions, build_html_translated_names
    .... */
-HV *
-build_html_element_targets (HTML_TARGET_LIST *html_targets)
+void
+build_html_element_targets (HV *hv, HTML_TARGET_LIST *html_targets)
 {
-  HV *hv;
   int i;
 
   dTHX;
 
-  hv = newHV ();
-
   if (!html_targets || html_targets->number <= 0)
-    return hv;
+    return;
 
-#define STORE(key, sv) hv_store (html_target_hv, key, strlen (key), sv, 0)
   for (i = 0; i < html_targets->number; i++)
     {
-      HV *html_target_hv;
       HTML_TARGET *html_target = &html_targets->list[i];
-      SV *target_sv = newSVpv_utf8 (html_target->target, 0);
-      SV *element_sv;
-      SV *html_target_sv;
-
-      if (!html_target->element->hv)
-        {
-          fprintf (stderr, "BUG: No hv for target '%s'\n", 
html_target->target);
-          fatal ("No hv for target");
-        }
-
-      element_sv = newRV_inc ((SV *) html_target->element->hv);
-
-      html_target_hv = newHV ();
-      html_target_sv = newRV_noinc ((SV *) html_target_hv);
-      hv_store_ent (hv, element_sv, html_target_sv, 0);
-
-      STORE("target", target_sv);
-      if (html_target->special_unit_filename)
-        STORE("special_unit_filename",
-              newSVpv_utf8 (html_target->special_unit_filename, 0));
-      if (html_target->node_filename)
-        STORE("node_filename",
-              newSVpv_utf8 (html_target->node_filename, 0));
-      if (html_target->section_filename)
-        STORE("section_filename",
-              newSVpv_utf8 (html_target->section_filename, 0));
-      if (html_target->contents_target)
-        STORE("contents_target",
-              newSVpv_utf8 (html_target->contents_target, 0));
-      if (html_target->shortcontents_target)
-        STORE("shortcontents_target",
-              newSVpv_utf8 (html_target->shortcontents_target, 0));
+      add_html_element_target (hv, html_target);
     }
-#undef STORE
-  return hv;
 }
 
 void
@@ -131,7 +148,8 @@ pass_html_element_targets (SV *converter_sv, 
HTML_TARGET_LIST *html_targets)
 
   hv = (HV *) SvRV (converter_sv);
 
-  targets_hv = build_html_element_targets (html_targets);
+  targets_hv = newHV ();
+  build_html_element_targets (targets_hv, html_targets);
 
   hv_store (hv, "targets", strlen ("targets"),
             newRV_noinc ((SV *) targets_hv), 0);
@@ -149,8 +167,10 @@ build_html_special_targets (HTML_TARGET_LIST 
*html_special_targets)
 
   /* could be generalized if needed */
 
-  HTML_TARGET_LIST *html_special_target = 
&html_special_targets[ST_footnote_location];
-  html_special_target_hv = build_html_element_targets (html_special_target);
+  HTML_TARGET_LIST *html_special_target
+    = &html_special_targets[ST_footnote_location];
+  html_special_target_hv = newHV ();
+  build_html_element_targets (html_special_target_hv, html_special_target);
 
   hv_store (hv, "footnote_location", strlen ("footnote_location"),
             newRV_noinc ((SV *) html_special_target_hv), 0);
@@ -713,8 +733,6 @@ build_html_formatting_state (CONVERTER *converter, unsigned 
long flags)
   HV *hv;
   SV **document_context_sv;
   AV *document_context_av;
-  SV **file_counters_sv;
-  HV *file_counters_hv;
   /*
   SV **files_information_sv;
   HV *files_information_hv;
@@ -962,6 +980,9 @@ build_html_formatting_state (CONVERTER *converter, unsigned 
long flags)
 
   if (converter->file_changed_counter.number)
     {
+      SV **file_counters_sv;
+      HV *file_counters_hv;
+
       FETCH(file_counters);
       file_counters_hv = (HV *) SvRV (*file_counters_sv);
 
@@ -985,6 +1006,23 @@ build_html_formatting_state (CONVERTER *converter, 
unsigned long flags)
       converter->file_changed_counter.number = 0;
     }
 
+  if (converter->added_targets.number)
+    {
+      SV **targets_sv;
+      HV *targets_hv;
+
+      FETCH(targets);
+      targets_hv = (HV *) SvRV (*targets_sv);
+
+      int j;
+      for (j = 0; j < converter->added_targets.number; j++)
+        {
+          HTML_TARGET *html_target = converter->added_targets.list[j];
+          add_html_element_target (targets_hv, html_target);
+        }
+      converter->added_targets.number = 0;
+    }
+
   /*
   files_information_sv = hv_fetch (hv, "files_information",
                                   strlen ("files_information"), 0);
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 33101eb875..828d1ce3d8 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -1398,6 +1398,46 @@ set_root_commands_targets_node_files (CONVERTER *self)
     }
 }
 
+static void
+register_added_target (HTML_ADDED_TARGET_LIST *added_targets,
+                       HTML_TARGET *target)
+{
+  if (added_targets->number == added_targets->space)
+    {
+      added_targets->list = realloc (added_targets->list,
+                   sizeof (HTML_TARGET *) * (added_targets->space += 5));
+    }
+  added_targets->list[added_targets->number] = target;
+  added_targets->number++;
+}
+
+static HTML_TARGET *
+get_target (CONVERTER *self, const ELEMENT *element)
+{
+  HTML_TARGET *result
+   = find_element_target (&self->html_targets, element);
+  if (!result && element->cmd
+      && builtin_command_flags(element) & CF_sectioning_heading
+      && !(builtin_command_flags(element) & CF_root)) {
+    new_sectioning_command_target (self, element);
+
+    result = find_element_target (&self->html_targets, element);
+
+    register_added_target (&self->added_targets, result);
+    self->modified_state |= HMSF_added_target;
+  }
+  return result;
+}
+
+char *html_command_id (CONVERTER *self, ELEMENT *command)
+{
+  HTML_TARGET *target = get_target (self, command);
+  if (target)
+    return target->target;
+  else
+    return 0;
+}
+
 void
 html_merge_index_entries (CONVERTER *self)
 {
@@ -4707,6 +4747,7 @@ convert_output_output_unit_internal (CONVERTER *self,
         = file_index;
       self->file_changed_counter.number++;
       unit_file->counter_changed = 1;
+      self->modified_state |= HMSF_file_counter;
     }
 
       /* register the output but do not print anything. Printing
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index 20315fa82a..e138fcb696 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -361,6 +361,12 @@ typedef struct STRING_WITH_LEN {
     size_t len;
 } STRING_WITH_LEN;
 
+typedef struct HTML_ADDED_TARGET_LIST {
+    size_t space;
+    size_t number;
+    HTML_TARGET **list;
+} HTML_ADDED_TARGET_LIST;
+
 /* we have a circular reference with TYPE_CONVERSION_FUNCTION
    and CONVERTER and with COMMAND_CONVERSION_FUNCTION and CONVERTER */
 struct CONVERTER;
@@ -486,6 +492,7 @@ typedef struct CONVERTER {
                                     to be brought to perl */
     int document_contexts_to_pop;  /* number of contexts to pop in perl before
                                       readding the new contexts */
+    HTML_ADDED_TARGET_LIST added_targets; /* targets added */
     /* next three allow to switch from normal HTML formatting to css strings
        formatting */
     FORMATTING_REFERENCE *current_formatting_references;
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index cfca2f7170..2b3815138a 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -146,6 +146,8 @@ enum command_location {
 #define HMSF_converter_state         0x1000
 #define HMSF_multiple_pass           0x2000
 #define HMSF_translations            0x4000
+#define HMSF_file_counter            0x8000
+#define HMSF_added_target            0x00010000
 
 typedef struct TARGET_FILENAME {
     char *target;



reply via email to

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