texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Wed, 2 Oct 2024 07:37:15 -0400 (EDT)

branch: master
commit c67be5c04323d456fdaa06de69346c7495b50bb7
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Jul 31 23:42:54 2024 +0200

    * tp/Texinfo/XS/convert/converter.c (html_get_direction_index),
    tp/Texinfo/XS/main/get_perl_info.c: move html_get_direction_index from
    get_perl_info.c to converter.c.
    
    * tp/Texinfo/XS/main/tree_types.h (enum html_text_type),
    tp/Texinfo/XS/main/converter_types.h: move enum html_text_type from
    converter_types.h to tree_types.h.
    
    * tp/Texinfo/XS/main/option_types.h (BUTTON_SPECIFICATION_INFO): use
    enum html_text_type for direction_information_type type instead of
    int.
    
    * tp/Texinfo/XS/main/get_perl_info.c
    (html_get_button_specification_list),
    tp/Texinfo/XS/main/option_types.h (enum button_specification_type)
    (enum button_information_type, BUTTON_SPECIFICATION_INFO)
    (BUTTON_SPECIFICATION), tp/Texinfo/XS/main/utils.c
    (html_free_button_specification_list, copy_option): rename BST_string
    as BST_external_string and BIT_string as BIT_external_string.  Readd
    BST_string and BIT_string associated to a regular char *string.
    
    * tp/Texinfo/XS/convert/convert_html.c (new_button_specification)
    (new_button_specification_list, new_basic_buttons, new_link_buttons)
    (new_section_buttons, new_section_footer_buttons): add button
    specification, button list and default button specification lists
    creation functions.
---
 ChangeLog                            |  29 ++++++++
 tp/Texinfo/XS/convert/convert_html.c | 129 ++++++++++++++++++++++++++++++++++-
 tp/Texinfo/XS/convert/converter.c    |  20 ++++++
 tp/Texinfo/XS/convert/converter.h    |   2 +
 tp/Texinfo/XS/main/converter_types.h |  11 ---
 tp/Texinfo/XS/main/get_perl_info.c   |  21 +-----
 tp/Texinfo/XS/main/option_types.h    |  14 ++--
 tp/Texinfo/XS/main/tree_types.h      |  12 ++++
 tp/Texinfo/XS/main/utils.c           |  19 ++++--
 9 files changed, 216 insertions(+), 41 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 43b36cac59..2530a362a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2024-07-31  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/converter.c (html_get_direction_index),
+       tp/Texinfo/XS/main/get_perl_info.c: move html_get_direction_index from
+       get_perl_info.c to converter.c.
+
+       * tp/Texinfo/XS/main/tree_types.h (enum html_text_type),
+       tp/Texinfo/XS/main/converter_types.h: move enum html_text_type from
+       converter_types.h to tree_types.h.
+
+       * tp/Texinfo/XS/main/option_types.h (BUTTON_SPECIFICATION_INFO): use
+       enum html_text_type for direction_information_type type instead of
+       int.
+
+       * tp/Texinfo/XS/main/get_perl_info.c
+       (html_get_button_specification_list),
+       tp/Texinfo/XS/main/option_types.h (enum button_specification_type)
+       (enum button_information_type, BUTTON_SPECIFICATION_INFO)
+       (BUTTON_SPECIFICATION), tp/Texinfo/XS/main/utils.c
+       (html_free_button_specification_list, copy_option): rename BST_string
+       as BST_external_string and BIT_string as BIT_external_string.  Readd
+       BST_string and BIT_string associated to a regular char *string.
+
+       * tp/Texinfo/XS/convert/convert_html.c (new_button_specification)
+       (new_button_specification_list, new_basic_buttons, new_link_buttons)
+       (new_section_buttons, new_section_footer_buttons): add button
+       specification, button list and default button specification lists
+       creation functions.
+
 2024-07-31  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/convert_html.c (html_converter_initialize):
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index daed75650f..ce0260d3bb 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -357,6 +357,7 @@ unit_is_top_output_unit (CONVERTER *self, const OUTPUT_UNIT 
*output_unit)
   return (top_output_unit && top_output_unit == output_unit);
 }
 
+/* index within the global (including special units) directions */
 int
 html_special_unit_variety_direction_index (const CONVERTER *self,
                                       const char *special_unit_variety)
@@ -4437,7 +4438,7 @@ html_command_description (CONVERTER *self, const ELEMENT 
*command,
 /* return value to be freed by caller */
 char *
 from_element_direction (CONVERTER *self, int direction,
-                        enum  html_text_type type,
+                        enum html_text_type type,
                         const OUTPUT_UNIT *source_unit,
                         const char *source_filename,
                         const ELEMENT *source_command)
@@ -8303,6 +8304,132 @@ open_element_with_class (CONVERTER *self, const char 
*element_name,
   text_append_n (result, ">", 1);
 }
 
+/* create button specification */
+void
+new_button_specification (BUTTON_SPECIFICATION *button,
+                          enum button_specification_type type,
+                          enum button_information_type info_type,
+                          int direction, const char *string,
+                          enum button_function_type function_type,
+                          enum html_text_type text_type)
+{
+  button->type = type;
+
+  if (type == BST_string)
+    {
+      if (string)
+        button->b.string = strdup (string);
+    }
+  else if (type == BST_direction)
+    button->b.direction = direction;
+  else if (type == BST_direction_info)
+    {
+      BUTTON_SPECIFICATION_INFO *button_spec
+       = (BUTTON_SPECIFICATION_INFO *)
+           malloc (sizeof (BUTTON_SPECIFICATION_INFO));
+      memset (button_spec, 0, sizeof (BUTTON_SPECIFICATION_INFO));
+
+      button->b.button_info = button_spec;
+
+      button_spec->type = info_type;
+      button_spec->direction = direction;
+
+      if (info_type == BIT_string)
+        {
+          if (string)
+            button_spec->bi.string = strdup (string);
+        }
+      else if (info_type == BIT_function)
+        button_spec->bi.button_function.type = function_type;
+      else if (info_type == BIT_selected_direction_information_type
+               || info_type == BIT_href_direction_information_type)
+        button_spec->bi.direction_information_type = text_type;
+    }
+}
+
+BUTTON_SPECIFICATION_LIST *
+new_button_specification_list (size_t buttons_nr)
+{
+  BUTTON_SPECIFICATION_LIST *result;
+
+  result = (BUTTON_SPECIFICATION_LIST *)
+              malloc (sizeof (BUTTON_SPECIFICATION_LIST));
+
+  result->BIT_user_function_number = 0;
+  result->number = buttons_nr;
+  result->av = 0;
+
+  result->list = (BUTTON_SPECIFICATION *) malloc (buttons_nr *
+                   sizeof (BUTTON_SPECIFICATION));
+  memset (result->list, 0, buttons_nr * sizeof (BUTTON_SPECIFICATION));
+
+  return result;
+}
+
+/* BFT_type_panel_directions */
+BUTTON_SPECIFICATION_LIST *
+new_basic_buttons (const CONVERTER *self,
+                   enum button_function_type function_type)
+{
+  BUTTON_SPECIFICATION_LIST *result = new_button_specification_list (7);
+  int contents_direction = html_get_direction_index (self, "Contents");
+  int about_direction = html_get_direction_index (self, "About");
+
+  new_button_specification (&result->list[0], BST_direction_info,
+                            BIT_function, D_direction_Next, 0,
+                            function_type, 0);
+  new_button_specification (&result->list[1], BST_direction_info,
+                            BIT_function, D_direction_Prev, 0,
+                            function_type, 0);
+  new_button_specification (&result->list[2], BST_direction_info,
+                            BIT_function, D_direction_Up, 0,
+                            function_type, 0);
+  new_button_specification (&result->list[3], BST_direction,
+                            0, D_direction_Space, 0, 0, 0);
+  new_button_specification (&result->list[4], BST_direction,
+                            0, contents_direction, 0, 0, 0);
+  new_button_specification (&result->list[5], BST_direction,
+                            0, D_direction_Index, 0, 0, 0);
+  new_button_specification (&result->list[6], BST_direction,
+                            0, about_direction, 0, 0, 0);
+  return result;
+}
+
+BUTTON_SPECIFICATION_LIST *
+new_link_buttons (const CONVERTER *self)
+{
+  BUTTON_SPECIFICATION_LIST *result = new_button_specification_list (7);
+  int contents_direction = html_get_direction_index (self, "Contents");
+  int about_direction = html_get_direction_index (self, "About");
+  new_button_specification (&result->list[0], BST_direction,
+                            0, D_direction_Top, 0, 0, 0);
+  new_button_specification (&result->list[1], BST_direction,
+                            0, D_direction_Index, 0, 0, 0);
+  new_button_specification (&result->list[2], BST_direction,
+                            0, contents_direction, 0, 0, 0);
+  new_button_specification (&result->list[3], BST_direction,
+                            0, about_direction, 0, 0, 0);
+  new_button_specification (&result->list[4], BST_direction,
+                            0, D_direction_NodeUp, 0, 0, 0);
+  new_button_specification (&result->list[5], BST_direction,
+                            0, D_direction_NodeNext, 0, 0, 0);
+  new_button_specification (&result->list[6], BST_direction,
+                            0, D_direction_NodePrev, 0, 0, 0);
+  return result;
+}
+
+BUTTON_SPECIFICATION_LIST *
+new_section_buttons (const CONVERTER *self)
+{
+  return new_basic_buttons (self, BFT_type_panel_directions);
+}
+
+BUTTON_SPECIFICATION_LIST *
+new_section_footer_buttons (const CONVERTER *self)
+{
+  return new_basic_buttons (self, BFT_type_panel_section_footer);
+}
+
 static char *nav_button_array[] = {"nav-button"};
 static const STRING_LIST nav_button_classes = {nav_button_array, 1, 1};
 
diff --git a/tp/Texinfo/XS/convert/converter.c 
b/tp/Texinfo/XS/convert/converter.c
index 63e3d34409..70aa82d1aa 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -1482,6 +1482,26 @@ free_generic_converter (CONVERTER *self)
 }
 
 
+/* here because it is used in main/get_perl_info.c */
+
+/* return -2 if there are info and not found. */
+int
+html_get_direction_index (const CONVERTER *converter, const char *direction)
+{
+  int i;
+  if (converter && converter->direction_unit_direction_name)
+    {
+      for (i = 0; converter->direction_unit_direction_name[i]; i++)
+        {
+          if (!strcmp (direction, converter->direction_unit_direction_name[i]))
+            return i;
+        }
+      return -2;
+    }
+  return -1;
+}
+
+
 
 /* XML conversion functions */
 
diff --git a/tp/Texinfo/XS/convert/converter.h 
b/tp/Texinfo/XS/convert/converter.h
index 1d6591c213..dda4db52c2 100644
--- a/tp/Texinfo/XS/convert/converter.h
+++ b/tp/Texinfo/XS/convert/converter.h
@@ -181,6 +181,8 @@ void free_output_unit_files (FILE_NAME_PATH_COUNTER_LIST 
*output_unit_files);
 
 void free_generic_converter (CONVERTER *self);
 
+int html_get_direction_index (const CONVERTER *converter,
+                              const char *direction);
 
 void xml_format_text_with_numeric_entities (const char *text, TEXT *result);
 char *xml_numeric_entity_accent (enum command_id cmd, const char *text);
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index 160221175a..6dd88b2452 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -168,17 +168,6 @@ enum html_special_character {
    SC_non_breaking_space,
 };
 
-enum html_text_type {
-   HTT_text,
-   HTT_text_nonumber,
-   HTT_string,
-   HTT_string_nonumber, /* not sure that it is set/used */
-   /* not only used for element text, also for direction text */
-   HTT_href,
-   HTT_node,
-   HTT_section,
-};
-
 enum htmlxref_split_type {
    htmlxref_split_type_none = -1,
 
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index 6ebe8cb374..7af5279ca9 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -738,23 +738,6 @@ force_sv_conf (CONVERTER *converter, const char *conf, SV 
*value)
 
 /* output format specific */
 
-/* return -2 if there are info and not found. */
-static int
-html_get_direction_index (const CONVERTER *converter, const char *direction)
-{
-  int i;
-  if (converter && converter->direction_unit_direction_name)
-    {
-      for (i = 0; converter->direction_unit_direction_name[i]; i++)
-        {
-          if (!strcmp (direction, converter->direction_unit_direction_name[i]))
-            return i;
-        }
-      return -2;
-    }
-  return -1;
-}
-
 /* should be consistent with enum button_function_type */
 static const char *button_function_type_string[] = {
   0,
@@ -897,7 +880,7 @@ html_get_button_specification_list (const CONVERTER 
*converter,
                     }
                   else
                     {
-                      button_spec->type = BIT_string;
+                      button_spec->type = BIT_external_string;
                       button_spec->bi.sv_string = *button_spec_info_type;
                     }
                 }
@@ -935,7 +918,7 @@ html_get_button_specification_list (const CONVERTER 
*converter,
             }
           else
             {
-              button->type = BST_string;
+              button->type = BST_external_string;
               button->b.sv_string = *button_sv;
             }
         }
diff --git a/tp/Texinfo/XS/main/option_types.h 
b/tp/Texinfo/XS/main/option_types.h
index 83a58bdf51..4cb7a312fd 100644
--- a/tp/Texinfo/XS/main/option_types.h
+++ b/tp/Texinfo/XS/main/option_types.h
@@ -64,11 +64,13 @@ enum button_specification_type {
    BST_direction,
    BST_function,
    BST_string,
+   BST_external_string,
    BST_direction_info,
 };
 
 enum button_information_type {
    BIT_string,
+   BIT_external_string,
    BIT_function,
    BIT_selected_direction_information_type,
    BIT_href_direction_information_type,
@@ -102,10 +104,11 @@ typedef struct BUTTON_SPECIFICATION_INFO {
       BUTTON_FUNCTION button_function; /* BIT_function */
   /* perl references. This should be SV *sv_*,
      but we don't want to include the Perl headers everywhere; */
-      void *sv_string; /* BIT_string */
-     /* both global and relative directions index */
-      int direction_information_type; /* BIT_direction_information_type
-            text string in perl, element direction information type */
+      void *sv_string; /* BIT_external_string */
+      char *string; /* BIT_string */
+     /* BIT_direction_information_type
+        text string in perl, element direction information type */
+      enum html_text_type direction_information_type;
     } bi;
 } BUTTON_SPECIFICATION_INFO;
 
@@ -120,7 +123,8 @@ typedef struct BUTTON_SPECIFICATION {
   /* perl references. This should be SV *sv_*,
      but we don't want to include the Perl headers everywhere; */
       void *sv_reference; /* BST_function */
-      void *sv_string; /* BST_string scalar reference */
+      void *sv_string; /* BST_external_string scalar reference */
+      char *string; /* BST_string */
       BUTTON_SPECIFICATION_INFO *button_info; /* BST_direction_info
                                               array reference of length 2 */
     } b;
diff --git a/tp/Texinfo/XS/main/tree_types.h b/tp/Texinfo/XS/main/tree_types.h
index a538e682a4..a966c5a928 100644
--- a/tp/Texinfo/XS/main/tree_types.h
+++ b/tp/Texinfo/XS/main/tree_types.h
@@ -77,6 +77,18 @@ enum output_unit_type {
    OU_special_unit,
 };
 
+/* here because it is used both in option_types.h and ConvertXS.xs */
+enum html_text_type {
+   HTT_text,
+   HTT_text_nonumber,
+   HTT_string,
+   HTT_string_nonumber, /* not sure that it is set/used */
+   /* not only used for element text, also for direction text */
+   HTT_href,
+   HTT_node,
+   HTT_section,
+};
+
 #define AI_KEYS_LIST \
   ai_key(cell_number) \
   ai_key(item_number) \
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 606026dc4a..653407ea94 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -1625,7 +1625,13 @@ html_free_button_specification_list 
(BUTTON_SPECIFICATION_LIST *buttons)
         {
           BUTTON_SPECIFICATION *button = &buttons->list[i];
           if (button->type == BST_direction_info)
-            free (button->b.button_info);
+            {
+              if (button->b.button_info->type == BIT_string)
+                free (button->b.button_info->bi.string);
+              free (button->b.button_info);
+            }
+          else if (button->type == BST_string)
+            free (button->b.string);
           unregister_perl_button (button);
         }
     }
@@ -1841,8 +1847,6 @@ copy_option (OPTION *destination, const OPTION *source)
               result->number = s_buttons->number;
               result->list = (BUTTON_SPECIFICATION *)
                      malloc (result->number * sizeof (BUTTON_SPECIFICATION));
-              /* TODO seems like we could simply memcpy the whole list
-                 as we only copy, there is no reallocation at all */
               memset (result->list, 0,
                       result->number * sizeof (BUTTON_SPECIFICATION));
               for (i = 0; i < result->number; i++)
@@ -1857,8 +1861,10 @@ copy_option (OPTION *destination, const OPTION *source)
                   button->type = s_button->type;
                   if (button->type == BST_function)
                     button->b.sv_reference = s_button->b.sv_reference;
-                  else if (button->type == BST_string)
+                  else if (button->type == BST_external_string)
                     button->b.sv_string = s_button->b.sv_string;
+                  else if (button->type == BST_string)
+                    button->b.string = strdup (s_button->b.string);
                   else if (button->type == BST_direction)
                     button->b.direction = s_button->b.direction;
                   else if (button->type == BST_direction_info)
@@ -1880,9 +1886,12 @@ copy_option (OPTION *destination, const OPTION *source)
                           button_spec->bi.button_function.sv_reference
                             = s_button_spec->bi.button_function.sv_reference;
                         }
-                      else if (button_spec->type == BIT_string)
+                      else if (button_spec->type == BIT_external_string)
                         button_spec->bi.sv_string
                           = s_button_spec->bi.sv_string;
+                      else if (button_spec->type == BIT_string)
+                        button_spec->bi.string
+                          = strdup (s_button_spec->bi.string);
                       else /* BIT_selected_direction_information_type
                             and BIT_href_direction_information_type */
                         button_spec->bi.direction_information_type



reply via email to

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