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, 19 Dec 2023 17:06:36 -0500 (EST)

branch: master
commit d1c836a0d2daa55b64d66b446d2c778aeb8a6de5
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Dec 19 23:06:31 2023 +0100

    * tp/Texinfo/Convert/HTML.pm
    (_default_panel_button_dynamic_direction): rearrange conditions to
    avoid redundant code.
    
    * tp/Texinfo/XS/main/converter_types.h (enum button_function_type)
    (BUTTON_FUNCTION, BUTTON_SPECIFICATION_INFO),
    tp/Texinfo/XS/main/get_perl_info.c (button_function_type_string)
    (html_get_button_specification_list): get the function reference name
    used to format buttons with directions.  Based on the name, associate
    to an enum, one for each of the default button formatting functions.
    
    * tp/Texinfo/XS/main/converter_types.h (NODE_DIRECTIONS_OFFSET),
    tp/Texinfo/XS/main/tree_types.h (RUD_DIRECTIONS_TYPES_LIST): move
    NodeNext directions such that there is a fix offset between non
    prefixed Prev, Next, Up directions and Node prefixed corresponding
    directions.  NodeBack is now the last relative direction.
    
    * tp/Texinfo/XS/convert/convert_html.c (direction_anchor)
    (default_panel_button_dynamic_direction_internal)
    (default_panel_button_dynamic_direction)
    (default_panel_button_dynamic_direction_node_footer)
    'default_panel_button_dynamic_direction_section_footer):
    add omit_rel argument to direction_anchor, update callers.  Implement
    default_panel_button_dynamic_direction*.
    
    * tp/Texinfo/XS/convert/convert_html.c (html_format_button_function)
    (button_direction_function, html_default_format_button): add
    html_format_button_function array and button_direction_function to
    call the C functions for the buttons formatting for default button
    formatting functions.
---
 ChangeLog                            |  33 ++++++++++
 tp/Texinfo/Convert/HTML.pm           |  18 +++---
 tp/Texinfo/XS/convert/convert_html.c | 113 +++++++++++++++++++++++++++++++++--
 tp/Texinfo/XS/main/build_perl_info.c |   2 +-
 tp/Texinfo/XS/main/converter_types.h |  25 +++++++-
 tp/Texinfo/XS/main/get_perl_info.c   |  26 +++++++-
 tp/Texinfo/XS/main/output_unit.c     |   4 +-
 tp/Texinfo/XS/main/tree_types.h      |   8 +--
 8 files changed, 204 insertions(+), 25 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index eeaf9e0b30..d7b0d220b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2023-12-19  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm
+       (_default_panel_button_dynamic_direction): rearrange conditions to
+       avoid redundant code.
+
+       * tp/Texinfo/XS/main/converter_types.h (enum button_function_type)
+       (BUTTON_FUNCTION, BUTTON_SPECIFICATION_INFO),
+       tp/Texinfo/XS/main/get_perl_info.c (button_function_type_string)
+       (html_get_button_specification_list): get the function reference name
+       used to format buttons with directions.  Based on the name, associate
+       to an enum, one for each of the default button formatting functions.
+
+       * tp/Texinfo/XS/main/converter_types.h (NODE_DIRECTIONS_OFFSET),
+       tp/Texinfo/XS/main/tree_types.h (RUD_DIRECTIONS_TYPES_LIST): move
+       NodeNext directions such that there is a fix offset between non
+       prefixed Prev, Next, Up directions and Node prefixed corresponding
+       directions.  NodeBack is now the last relative direction.
+
+       * tp/Texinfo/XS/convert/convert_html.c (direction_anchor)
+       (default_panel_button_dynamic_direction_internal)
+       (default_panel_button_dynamic_direction)
+       (default_panel_button_dynamic_direction_node_footer)
+       'default_panel_button_dynamic_direction_section_footer):
+       add omit_rel argument to direction_anchor, update callers.  Implement
+       default_panel_button_dynamic_direction*.
+
+       * tp/Texinfo/XS/convert/convert_html.c (html_format_button_function)
+       (button_direction_function, html_default_format_button): add
+       html_format_button_function array and button_direction_function to
+       call the C functions for the buttons formatting for default button
+       formatting functions.
+
 2023-12-19  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/get_html_perl_info.c
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 744a919911..ef0f3ae46f 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -3909,15 +3909,15 @@ sub _default_panel_button_dynamic_direction($$;$$$)
     $node = $self->from_element_direction($direction, 'node');
   }
 
-  my $hyperlink;
-  if (defined($href) and $href ne '' and defined($node) and $node =~ /\S/) {
-    my $hyperlink_attributes = $omit_rel ? ''
-      : $self->_direction_href_attributes($direction);
-    $hyperlink = "<a href=\"$href\"${hyperlink_attributes}>$node</a>";
-  } elsif (defined($node) and $node =~ /\S/) {
-    $hyperlink = $node;
-  }
-  if (defined($hyperlink)) {
+  if (defined($node) and $node =~ /\S/) {
+    my $hyperlink;
+    if (defined($href) and $href ne '') {
+      my $hyperlink_attributes = $omit_rel ? ''
+        : $self->_direction_href_attributes($direction);
+      $hyperlink = "<a href=\"$href\"${hyperlink_attributes}>$node</a>";
+    } else {
+      $hyperlink = $node;
+    }
     # i18n
     $result = $self->direction_string($direction, 'text').": $hyperlink";
   }
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index e7ccf52c09..16acf4e016 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -5510,12 +5510,13 @@ direction_href_attributes (CONVERTER *self, int 
direction, TEXT *result)
 
 static char *
 direction_anchor (CONVERTER *self, int direction, const char *href,
-                  const char *text)
+                  const char *text, int omit_rel)
 {
   TEXT result;
   text_init (&result);
   text_printf (&result, "<a href=\"%s\"", href);
-  direction_href_attributes (self, direction, &result);
+  if (!omit_rel)
+    direction_href_attributes (self, direction, &result);
   text_append_n (&result, ">", 1);
   text_append (&result, text);
   text_append_n (&result, "</a>", 4);
@@ -6548,6 +6549,106 @@ format_button_icon_img (CONVERTER *self,
     }
 }
 
+static FORMATTED_BUTTON_INFO *
+default_panel_button_dynamic_direction_internal (CONVERTER *self,
+                               int direction, const ELEMENT *element,
+                               int omit_rel,
+                             int use_first_element_in_file_directions)
+{
+  char *href;
+  char *node = 0;
+  FORMATTED_BUTTON_INFO *formatted_button;
+
+  formatted_button = (FORMATTED_BUTTON_INFO *)
+    malloc (sizeof (FORMATTED_BUTTON_INFO));
+  memset (formatted_button, 0, sizeof (FORMATTED_BUTTON_INFO));
+
+  formatted_button->need_delimiter = 1;
+
+  if (self->conf->USE_NODE_DIRECTIONS > 0
+      || (self->conf->USE_NODE_DIRECTIONS < 0
+          && self->conf->USE_NODES > 0))
+    direction += NODE_DIRECTIONS_OFFSET;
+
+  if (use_first_element_in_file_directions)
+    direction -= FIRSTINFILE_OFFSET;
+
+  href = from_element_direction (self, direction, HTT_href, 0, 0, element);
+
+  if (!strcmp (self->conf->xrefautomaticsectiontitle, "on"))
+    node = from_element_direction (self, direction, HTT_section, 0, 0, 0);
+
+  if (!node)
+    node = from_element_direction (self, direction, HTT_node, 0, 0, 0);
+
+  if (node && node[strspn (node, whitespace_chars)] != '\0')
+    {
+      char *hyperlink;
+      char *text = direction_string (self, direction, TDS_type_text, 0);
+      if (href && strlen (href))
+        {
+          hyperlink =
+           direction_anchor (self, direction, href, node, omit_rel);
+          free (node);
+        }
+      else
+        hyperlink = node;
+
+      xasprintf (&formatted_button->active, "%s: %s", text, hyperlink);
+      free (hyperlink);
+      return formatted_button;
+    }
+
+  free (node);
+  return formatted_button;
+}
+
+static FORMATTED_BUTTON_INFO *
+default_panel_button_dynamic_direction (CONVERTER *self,
+                               int direction, const ELEMENT *element)
+{
+  return default_panel_button_dynamic_direction_internal (self,
+                                        direction, element, 0, 0);
+}
+
+static FORMATTED_BUTTON_INFO *
+default_panel_button_dynamic_direction_node_footer (CONVERTER *self,
+                               int direction, const ELEMENT *element)
+{
+  return default_panel_button_dynamic_direction_internal (self,
+                                        direction, element, 1, 0);
+}
+
+static FORMATTED_BUTTON_INFO *
+default_panel_button_dynamic_direction_section_footer (CONVERTER *self,
+                               int direction, const ELEMENT *element)
+{
+  return default_panel_button_dynamic_direction_internal (self,
+                                        direction, element, 0, 1);
+}
+
+/* the order corresponds to enum button_function_type */
+FORMATTED_BUTTON_INFO * (*html_format_button_function[]) (CONVERTER *self,
+                               int direction, const ELEMENT *element) = {
+ 0,
+ 0,
+ 0,
+ &default_panel_button_dynamic_direction,
+ 0
+};
+
+FORMATTED_BUTTON_INFO *
+button_direction_function (CONVERTER *self, BUTTON_FUNCTION *button_function,
+                           int direction, const ELEMENT *element)
+{
+  if (html_format_button_function[button_function->type])
+    return (*html_format_button_function[button_function->type])
+                                         (self, direction, element);
+  else
+    return call_button_direction_function (self, button_function->sv_reference,
+                                                      direction, element);
+}
+
 FORMATTED_BUTTON_INFO *
 html_default_format_button (CONVERTER *self,
                             const BUTTON_SPECIFICATION *button,
@@ -6560,8 +6661,8 @@ html_default_format_button (CONVERTER *self,
   else if (button->type == BST_direction_info
            && button->button_info->type == BIT_function)
     {
-      return call_button_direction_function (self,
-                      button->button_info->sv_reference,
+      return button_direction_function (self,
+                      &button->button_info->button_function,
                       button->button_info->direction, element);
     }
   else
@@ -6592,7 +6693,7 @@ html_default_format_button (CONVERTER *self,
                   if (href)
                     {
                       formatted_button->active
-                        = direction_anchor (self, direction, href, text);
+                        = direction_anchor (self, direction, href, text, 0);
                       free (href);
                     }
                   else
@@ -6627,7 +6728,7 @@ html_default_format_button (CONVERTER *self,
                     {
                       formatted_button->active
                         = direction_anchor (self, direction, href,
-                                                    text_formatted);
+                                                    text_formatted, 0);
                     }
                   else
                     formatted_button->passive = strdup (text_formatted);
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 44e9fb305f..3c147a3a0b 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1292,7 +1292,7 @@ output_unit_to_perl_hash (OUTPUT_UNIT *output_unit)
   sv = newRV_noinc ((SV *) directions_hv);
   STORE("directions");
 
-  for (i = 0; i < RUD_type_FirstInFileNodeUp+1; i++)
+  for (i = 0; i < RUD_type_FirstInFileNodeBack+1; i++)
     {
       if (output_unit->directions[i])
         {
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index 5e72c00353..350030843b 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -788,9 +788,10 @@ enum direction_unit_direction {
 };
 
 #define FIRSTINFILE_MIN_IDX D_direction_FirstInFileThis
-#define FIRSTINFILE_MAX_IDX D_direction_FirstInFileNodeUp
+#define FIRSTINFILE_MAX_IDX D_direction_FirstInFileNodeBack
 #define FIRSTINFILE_OFFSET (D_direction_This - D_direction_FirstInFileThis)
 #define FIRSTINFILE_NR (FIRSTINFILE_MAX_IDX - FIRSTINFILE_MIN_IDX +1)
+#define NODE_DIRECTIONS_OFFSET (D_direction_NodeNext - D_direction_Next)
 
 #define NON_SPECIAL_DIRECTIONS_NR (FIRSTINFILE_MAX_IDX +1)
 
@@ -808,14 +809,34 @@ enum button_information_type {
   BIT_href_direction_information_type,
 };
 
+/* enum value corresponding to a default button formatting function
+   used later on to select a C function to replace the default function */
+/* longest strings first to avoid ambiguity */
+enum button_function_type {
+  BFT_type_none,
+  /* _default_panel_button_dynamic_direction_section_footer */
+  BFT_type_panel_section_footer,
+  /* _default_panel_button_dynamic_direction_node_footer */
+  BFT_type_panel_node_footer,
+  /* _default_panel_button_dynamic_direction */
+  BFT_type_panel_directions,
+};
+
+typedef struct BUTTON_FUNCTION {
+ /* perl references. This should be SV *sv_*,
+    but we don't want to include the Perl headers everywhere; */
+    void *sv_reference;
+    enum button_function_type type;
+} BUTTON_FUNCTION;
+
 typedef struct BUTTON_SPECIFICATION_INFO {
      /* both global and relative directions index */
     int direction;
     enum button_information_type type;
     union {
+      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_reference; /* BIT_function */
       void *sv_string; /* BIT_string */
      /* both global and relative directions index */
       int direction_information_type; /* BIT_direction_information_type
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index 560f245f8e..0a4b19d93d 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -875,6 +875,15 @@ html_get_direction_index (CONVERTER *converter, const char 
*direction)
   return -1;
 }
 
+/* should be consistent with enum button_function_type */
+static const char *button_function_type_string[] = {
+  0,
+  "::_default_panel_button_dynamic_direction_section_footer",
+  "::_default_panel_button_dynamic_direction_node_footer",
+  "::_default_panel_button_dynamic_direction",
+  0,
+};
+
 /* HTML specific, but needs to be there for options_get_perl.c */
 BUTTON_SPECIFICATION_LIST *
 html_get_button_specification_list (CONVERTER *converter, SV *buttons_sv)
@@ -941,8 +950,23 @@ html_get_button_specification_list (CONVERTER *converter, 
SV *buttons_sv)
                 {
                   if (SvTYPE (SvRV(*button_spec_info_type)) == SVt_PVCV) /* 
CODE */
                     {
+                      int j;
+                      char *button_fun_name;
+                      enum button_function_type button_fun_type = 0;
                       button_spec->type = BIT_function;
-                      button_spec->sv_reference = *button_spec_info_type;
+                      button_spec->button_function.sv_reference
+                                          = *button_spec_info_type;
+                      button_fun_name
+                       = SvPV_nolen (cv_name ((CV *) SvRV 
(*button_spec_info_type),
+                                              0, 0));
+                      for (j = 1; button_function_type_string[j]; j++)
+                        if (strstr (button_fun_name,
+                                    button_function_type_string[j]))
+                          {
+                            button_fun_type = j;
+                            break;
+                          }
+                      button_spec->button_function.type = button_fun_type;
                     }
                   else
                     {
diff --git a/tp/Texinfo/XS/main/output_unit.c b/tp/Texinfo/XS/main/output_unit.c
index 6bda1d1567..f0a089c3f4 100644
--- a/tp/Texinfo/XS/main/output_unit.c
+++ b/tp/Texinfo/XS/main/output_unit.c
@@ -464,7 +464,7 @@ print_output_unit_directions (OUTPUT_UNIT *output_unit)
   text_printf (&result, "output unit: %s\n",
                output_unit_texi(output_unit));
 
-  for (i = 0; i < RUD_type_FirstInFileNodeUp+1; i++)
+  for (i = 0; i < RUD_type_FirstInFileNodeBack+1; i++)
     {
       OUTPUT_UNIT *direction = output_unit->directions[i];
       if (direction)
@@ -848,7 +848,7 @@ units_file_directions (OUTPUT_UNIT_LIST *output_units)
         {
           memcpy (&output_unit->directions[RUD_type_FirstInFileThis],
                   &first_unit_in_file->directions[RUD_type_This],
-                  (RUD_type_NodeUp - RUD_type_This +1) * sizeof (OUTPUT_UNIT 
*));
+                  (RUD_type_NodeBack - RUD_type_This +1) * sizeof (OUTPUT_UNIT 
*));
         }
     }
 }
diff --git a/tp/Texinfo/XS/main/tree_types.h b/tp/Texinfo/XS/main/tree_types.h
index 6ded15d58b..bd3e746726 100644
--- a/tp/Texinfo/XS/main/tree_types.h
+++ b/tp/Texinfo/XS/main/tree_types.h
@@ -109,10 +109,10 @@ enum global_unit_direction {
    rud_type(SectionPrev) \
    rud_type(SectionUp) \
    rud_type(NodeNext) \
-   rud_type(NodeForward) \
-   rud_type(NodeBack) \
    rud_type(NodePrev) \
-   rud_type(NodeUp)
+   rud_type(NodeUp) \
+   rud_type(NodeForward) \
+   rud_type(NodeBack)
 
 /* relative output unit file directions */
 #define RUD_FILE_DIRECTIONS_TYPES \
@@ -191,7 +191,7 @@ typedef struct OUTPUT_UNIT {
     struct OUTPUT_UNIT *tree_unit_directions[2];
 
     struct OUTPUT_UNIT *first_in_page;
-    struct OUTPUT_UNIT *directions[RUD_type_FirstInFileNodeUp+1];
+    struct OUTPUT_UNIT *directions[RUD_type_FirstInFileNodeBack+1];
 
     /* for special output units only */
     /* could be an enum as for now new special types cannot be customized



reply via email to

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