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/convert_html.c (html_comm


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/convert/convert_html.c (html_command_href) (from_element_direction, mini_toc_internal): return 0 instead of an empty string.
Date: Tue, 19 Dec 2023 03:32:39 -0500

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 2261bffec7 * tp/Texinfo/XS/convert/convert_html.c (html_command_href) 
(from_element_direction, mini_toc_internal): return 0 instead of an empty 
string.
2261bffec7 is described below

commit 2261bffec7ed7cbfca2ff64ba7c134226fdc5fdb
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Dec 19 09:31:03 2023 +0100

    * tp/Texinfo/XS/convert/convert_html.c (html_command_href)
    (from_element_direction, mini_toc_internal): return 0 instead of an
    empty string.
    
    * tp/Texinfo/XS/convert/convert_html.c, tp/Texinfo/XS/main/utils.c
    (html_command_text_type_name): move html_command_text_type_name to
    utils.c and complete.
    
    * tp/Texinfo/XS/convert/convert_html.c (html_converter_initialize)
    (html_free_converter), tp/Texinfo/XS/convert/convert_html.c
    (direction_string), tp/Texinfo/XS/main/api_to_perl.h (CONVERTER),
    tp/Texinfo/XS/main/get_perl_info.c (html_get_direction_index):
    setup self->direction_unit_direction_name with all the direction
    names.  In direction_string, distinguish index in the full direction
    units array, to use self->direction_unit_direction_name and index in
    direction_string data.  Use in html_get_direction_index.
    
    * tp/Texinfo/XS/main/converter_types.h (DIRECTION_ICON_LIST),
    tp/Texinfo/XS/main/get_perl_info.c (html_get_direction_icons_sv),
    tp/Texinfo/XS/main/utils.c (html_free_direction_icons),
    tp/Texinfo/options_data.txt, tp/maintain/regenerate_C_options_info.pl:
    use a specific type for icon direction associated file list, get them
    from perl.
    
    * tp/Texinfo/XS/main/api_to_perl.h (enum button_specification_type),
    tp/Texinfo/XS/main/get_perl_info.c
    (html_get_button_specification_list): use two different types of
    button_information_type, with selected and href
    direction_information_type, and determine the type index in
    html_get_button_specification_list.
    
    * tp/Texinfo/XS/convert/call_html_perl_function.c
    (call_formatting_function_format_button_icon_img)
    (call_button_simple_function, call_button_direction_function),
    tp/Texinfo/XS/convert/convert_html.c (format_button_icon_img): add
    call_formatting_function_format_button_icon_img and functions called
    for button formatting.
    
    * tp/Texinfo/XS/main/api_to_perl.c (get_perl_scalar_reference_value):
    add a function to get a perl text reference value, used in buttons
    formatting.
    
    * tp/Texinfo/XS/convert/convert_html.c (direction_href_attributes)
    (direction_anchor, html_default_format_button, format_button):
    implement format_button in C.
---
 ChangeLog                                       |  48 ++++
 tp/Texinfo/XS/convert/call_html_perl_function.c | 222 +++++++++++++++-
 tp/Texinfo/XS/convert/call_html_perl_function.h |   9 +
 tp/Texinfo/XS/convert/convert_html.c            | 336 ++++++++++++++++++++++--
 tp/Texinfo/XS/convert/get_html_perl_info.c      |   2 +
 tp/Texinfo/XS/main/api_to_perl.c                |   9 +
 tp/Texinfo/XS/main/api_to_perl.h                |   2 +
 tp/Texinfo/XS/main/converter_types.h            |   9 +-
 tp/Texinfo/XS/main/get_perl_info.c              |  96 +++++--
 tp/Texinfo/XS/main/get_perl_info.h              |   3 +
 tp/Texinfo/XS/main/utils.c                      |  24 ++
 tp/Texinfo/XS/main/utils.h                      |   2 +
 tp/Texinfo/options_data.txt                     |   4 +-
 tp/maintain/regenerate_C_options_info.pl        |  16 +-
 14 files changed, 736 insertions(+), 46 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bf8009953b..715052084e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,51 @@
+2023-12-19  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/convert_html.c (html_command_href)
+       (from_element_direction, mini_toc_internal): return 0 instead of an
+       empty string.
+
+       * tp/Texinfo/XS/convert/convert_html.c, tp/Texinfo/XS/main/utils.c
+       (html_command_text_type_name): move html_command_text_type_name to
+       utils.c and complete.
+
+       * tp/Texinfo/XS/convert/convert_html.c (html_converter_initialize)
+       (html_free_converter), tp/Texinfo/XS/convert/convert_html.c
+       (direction_string), tp/Texinfo/XS/main/api_to_perl.h (CONVERTER),
+       tp/Texinfo/XS/main/get_perl_info.c (html_get_direction_index):
+       setup self->direction_unit_direction_name with all the direction
+       names.  In direction_string, distinguish index in the full direction
+       units array, to use self->direction_unit_direction_name and index in
+       direction_string data.  Use in html_get_direction_index.
+
+       * tp/Texinfo/XS/main/converter_types.h (DIRECTION_ICON_LIST),
+       tp/Texinfo/XS/main/get_perl_info.c (html_get_direction_icons_sv),
+       tp/Texinfo/XS/main/utils.c (html_free_direction_icons),
+       tp/Texinfo/options_data.txt, tp/maintain/regenerate_C_options_info.pl:
+       use a specific type for icon direction associated file list, get them
+       from perl.
+
+       * tp/Texinfo/XS/main/api_to_perl.h (enum button_specification_type),
+       tp/Texinfo/XS/main/get_perl_info.c
+       (html_get_button_specification_list): use two different types of
+       button_information_type, with selected and href
+       direction_information_type, and determine the type index in
+       html_get_button_specification_list.
+
+       * tp/Texinfo/XS/convert/call_html_perl_function.c
+       (call_formatting_function_format_button_icon_img)
+       (call_button_simple_function, call_button_direction_function),
+       tp/Texinfo/XS/convert/convert_html.c (format_button_icon_img): add
+       call_formatting_function_format_button_icon_img and functions called
+       for button formatting.
+
+       * tp/Texinfo/XS/main/api_to_perl.c (get_perl_scalar_reference_value):
+       add a function to get a perl text reference value, used in buttons
+       formatting.
+
+       * tp/Texinfo/XS/convert/convert_html.c (direction_href_attributes)
+       (direction_anchor, html_default_format_button, format_button):
+       implement format_button in C.
+
 2023-12-17  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/call_html_perl_function.c
diff --git a/tp/Texinfo/XS/convert/call_html_perl_function.c 
b/tp/Texinfo/XS/convert/call_html_perl_function.c
index f3a5c183d9..249a574b4b 100644
--- a/tp/Texinfo/XS/convert/call_html_perl_function.c
+++ b/tp/Texinfo/XS/convert/call_html_perl_function.c
@@ -1361,6 +1361,78 @@ call_formatting_function_format_translate_message 
(CONVERTER *self,
   return result;
 }
 
+char *
+call_formatting_function_format_button_icon_img (CONVERTER *self,
+                         const FORMATTING_REFERENCE *formatting_reference,
+                         const char *button_name,
+                         const char *icon, const char *name)
+
+{
+  int count;
+  SV *name_sv;
+  char *result = 0;
+  char *result_ret;
+  STRLEN len;
+  SV *result_sv;
+  SV *formatting_reference_sv;
+
+  dTHX;
+
+  if (!self->hv)
+    return 0;
+
+  formatting_reference_sv = formatting_reference->sv_reference;
+
+  if (self->modified_state)
+    {
+      build_html_formatting_state (self, self->modified_state);
+      self->modified_state = 0;
+    }
+
+  build_tree_to_build (&self->tree_to_build);
+
+  if (name)
+    name_sv = newSVpv_utf8 (name, 0);
+  else
+    name_sv = newSV (0);
+
+  dSP;
+
+  ENTER;
+  SAVETMPS;
+
+  PUSHMARK(SP);
+  EXTEND(SP, 4);
+
+  PUSHs(sv_2mortal (newRV_inc (self->hv)));
+  PUSHs(sv_2mortal (newSVpv_utf8 (button_name, 0)));
+  /* FIXME could also be a byte string */
+  PUSHs(sv_2mortal (newSVpv_utf8 (icon, 0)));
+  PUSHs(sv_2mortal (name_sv));
+  PUTBACK;
+
+  count = call_sv (formatting_reference_sv,
+                   G_SCALAR);
+
+  SPAGAIN;
+
+  if (count != 1)
+    croak("format_button_icon_img should return 1 item\n");
+
+  result_sv = POPs;
+  result_ret = SvPVutf8 (result_sv, len);
+  result = strdup (result_ret);
+
+  PUTBACK;
+
+  FREETMPS;
+  LEAVE;
+
+  get_shared_conversion_state (self);
+
+  return result;
+}
+
 FORMATTED_BUTTON_INFO *
 call_formatting_function_format_button (CONVERTER *self,
                          const FORMATTING_REFERENCE *formatting_reference,
@@ -1425,7 +1497,7 @@ call_formatting_function_format_button (CONVERTER *self,
   if (SvOK (passive_sv))
     {
       STRLEN len;
-      char *passive_ret = SvPV (passive_sv, len);
+      char *passive_ret = SvPVutf8 (passive_sv, len);
       result->passive = strdup (passive_ret);
     }
 
@@ -1433,7 +1505,7 @@ call_formatting_function_format_button (CONVERTER *self,
   if (SvOK (active_sv))
     {
       STRLEN len;
-      char *active_ret = SvPV (active_sv, len);
+      char *active_ret = SvPVutf8 (active_sv, len);
       result->active = strdup (active_ret);
     }
 
@@ -2349,3 +2421,149 @@ call_special_unit_body_formatting (CONVERTER *self,
 }
 
 
+
+FORMATTED_BUTTON_INFO *
+call_button_simple_function (CONVERTER *self,
+                             void *formatting_reference_sv)
+{
+  int count;
+  FORMATTED_BUTTON_INFO *result;
+  SV *need_delimiter_sv;
+  SV *active_sv;
+
+  dTHX;
+
+  if (!self->hv)
+    return 0;
+
+  build_tree_to_build (&self->tree_to_build);
+
+  if (self->modified_state)
+    {
+      build_html_formatting_state (self, self->modified_state);
+      self->modified_state = 0;
+    }
+
+  result
+   = (FORMATTED_BUTTON_INFO *) malloc (sizeof (FORMATTED_BUTTON_INFO));
+  memset (result, 0, sizeof (FORMATTED_BUTTON_INFO));
+
+  dSP;
+
+  ENTER;
+  SAVETMPS;
+
+  PUSHMARK(SP);
+  EXTEND(SP, 1);
+
+  PUSHs(sv_2mortal (newRV_inc (self->hv)));
+  PUTBACK;
+
+  count = call_sv ((SV *) formatting_reference_sv,
+                   G_ARRAY);
+
+  SPAGAIN;
+
+  if (count != 2)
+    croak("button_simple_function should return 2 items\n");
+
+  need_delimiter_sv = POPs;
+  if (SvOK (need_delimiter_sv))
+    {
+      result->need_delimiter = SvIV (need_delimiter_sv);
+    }
+
+  active_sv = POPs;
+  if (SvOK (active_sv))
+    {
+      STRLEN len;
+      char *active_ret = SvPVutf8 (active_sv, len);
+      result->active = strdup (active_ret);
+    }
+
+  PUTBACK;
+
+  FREETMPS;
+  LEAVE;
+
+  get_shared_conversion_state (self);
+
+  return result;
+}
+
+FORMATTED_BUTTON_INFO *
+call_button_direction_function (CONVERTER *self,
+                             void *formatting_reference_sv,
+                             int direction, const ELEMENT *element)
+{
+  int count;
+  FORMATTED_BUTTON_INFO *result;
+  SV *need_delimiter_sv;
+  SV *active_sv;
+
+  dTHX;
+
+  if (!self->hv)
+    return 0;
+
+  build_tree_to_build (&self->tree_to_build);
+
+  if (self->modified_state)
+    {
+      build_html_formatting_state (self, self->modified_state);
+      self->modified_state = 0;
+    }
+
+  result
+   = (FORMATTED_BUTTON_INFO *) malloc (sizeof (FORMATTED_BUTTON_INFO));
+  memset (result, 0, sizeof (FORMATTED_BUTTON_INFO));
+
+  dSP;
+
+  ENTER;
+  SAVETMPS;
+
+  PUSHMARK(SP);
+  EXTEND(SP, 3);
+
+  PUSHs(sv_2mortal (newRV_inc (self->hv)));
+  PUSHs(sv_2mortal (newSVpv (self->direction_unit_direction_name[direction],
+                             0)));
+  PUSHs(sv_2mortal (newRV_inc (element->hv)));
+
+  PUTBACK;
+
+  count = call_sv ((SV *) formatting_reference_sv,
+                   G_ARRAY);
+
+  SPAGAIN;
+
+  if (count != 2)
+    croak("button_direction_function should return 2 items\n");
+
+  need_delimiter_sv = POPs;
+  if (SvOK (need_delimiter_sv))
+    {
+      result->need_delimiter = SvIV (need_delimiter_sv);
+    }
+
+  active_sv = POPs;
+  if (SvOK (active_sv))
+    {
+      STRLEN len;
+      char *active_ret = SvPVutf8 (active_sv, len);
+      result->active = strdup (active_ret);
+    }
+
+  PUTBACK;
+
+  FREETMPS;
+  LEAVE;
+
+  get_shared_conversion_state (self);
+
+  return result;
+}
+
+
+
diff --git a/tp/Texinfo/XS/convert/call_html_perl_function.h 
b/tp/Texinfo/XS/convert/call_html_perl_function.h
index 007335d79c..f38f3224d7 100644
--- a/tp/Texinfo/XS/convert/call_html_perl_function.h
+++ b/tp/Texinfo/XS/convert/call_html_perl_function.h
@@ -84,6 +84,10 @@ char *call_formatting_function_format_translate_message 
(CONVERTER *self,
                          const FORMATTING_REFERENCE *formatting_reference,
                                   const char *message, const char *lang,
                                   const char *message_context);
+char * call_formatting_function_format_button_icon_img (CONVERTER *self,
+                         const FORMATTING_REFERENCE *formatting_reference,
+                         const char *button_name,
+                         const char *icon, const char *name);
 FORMATTED_BUTTON_INFO *call_formatting_function_format_button (CONVERTER *self,
                          const FORMATTING_REFERENCE *formatting_reference,
                                   const BUTTON_SPECIFICATION *button,
@@ -146,4 +150,9 @@ void call_special_unit_body_formatting (CONVERTER *self,
                               TEXT *result);
 
 
+FORMATTED_BUTTON_INFO *call_button_simple_function (CONVERTER *self,
+                                         void *formatting_reference_sv);
+FORMATTED_BUTTON_INFO *call_button_direction_function (CONVERTER *self,
+                             void *formatting_reference_sv,
+                             int direction, const ELEMENT *element);
 #endif
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 2074f1e05a..e7ccf52c09 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -51,6 +51,7 @@
 #include "manipulate_tree.h"
 /* for new_complete_menu_master_menu */
 #include "structuring.h"
+#include "api_to_perl.h"
 #include "convert_html.h"
 
 char *count_elements_in_filename_type_names[] = {
@@ -2749,8 +2750,12 @@ direction_string (CONVERTER *self, int direction,
                   enum direction_string_type string_type,
                   enum direction_string_context context)
 {
+  int direction_unit_direction_idx = direction;
   if (direction >= FIRSTINFILE_MIN_IDX && direction <= FIRSTINFILE_MAX_IDX)
-    direction += FIRSTINFILE_OFFSET;
+    {
+      direction += FIRSTINFILE_OFFSET;
+      direction_unit_direction_idx = direction;
+    }
   else if (direction > NON_SPECIAL_DIRECTIONS_NR - 1)
     direction -= FIRSTINFILE_NR;
 
@@ -2768,12 +2773,8 @@ direction_string (CONVERTER *self, int direction,
           const char *direction_name;
           TREE_ADDED_ELEMENTS *string_tree = 0;
           text_init (&translation_context);
-          if (direction < FIRSTINFILE_MIN_IDX)
-            direction_name = html_button_direction_names[direction];
-          else
-            direction_name =
-               self->special_unit_info[SUI_type_direction]
-                                  [direction - FIRSTINFILE_MIN_IDX];
+          direction_name
+           = self->direction_unit_direction_name[direction_unit_direction_idx];
           text_append (&translation_context, direction_name);
 
           if (direction == RUD_type_This)
@@ -3375,7 +3376,7 @@ char *html_command_href (CONVERTER *self, const ELEMENT 
*command,
         target = target_info->target;
     }
   if (!target)
-    return strdup ("");
+    return 0;
 
   text_init (&href);
   text_append (&href, "");
@@ -3779,11 +3780,6 @@ html_command_tree (CONVERTER *self, const ELEMENT 
*command, int no_number)
   return 0;
 }
 
-/* keep in sync with enum html_text_type */
-static char *html_command_text_type_name[] = {
-  "text", "text_nonumber", "string", "string_nonumber"
-};
-
 /* return value to be freed by caller */
 char *
 html_command_text (CONVERTER *self, const ELEMENT *command,
@@ -4041,7 +4037,7 @@ from_element_direction (CONVERTER *self, int direction,
                 return html_command_href (self, command,
                                           filename_from, 0, 0);
               else
-                return strdup ("");
+                return 0;
             }
 
           if (command)
@@ -5490,6 +5486,42 @@ format_separate_anchor (CONVERTER *self, const char *id,
     }
 }
 
+static void
+direction_href_attributes (CONVERTER *self, int direction, TEXT *result)
+{
+  if (self->conf->USE_ACCESSKEY > 0)
+    {
+      char *accesskey
+        = direction_string (self, direction, TDS_type_accesskey,
+                                    TDS_context_string);
+      if (accesskey && strlen (accesskey))
+        text_printf (result, " accesskey=\"%s\"", accesskey);
+    }
+
+  if (self->conf->USE_REL_REV)
+    {
+      char *button_rel
+        = direction_string (self, direction, TDS_type_rel,
+                                    TDS_context_string);
+      if (button_rel && strlen (button_rel))
+        text_printf (result, " rel=\"%s\"", button_rel);
+    }
+}
+
+static char *
+direction_anchor (CONVERTER *self, int direction, const char *href,
+                  const char *text)
+{
+  TEXT result;
+  text_init (&result);
+  text_printf (&result, "<a href=\"%s\"", href);
+  direction_href_attributes (self, direction, &result);
+  text_append_n (&result, ">", 1);
+  text_append (&result, text);
+  text_append_n (&result, "</a>", 4);
+  return result.text;
+}
+
 void
 html_default_format_heading_text (CONVERTER *self, const enum command_id cmd,
                      const STRING_LIST *classes, const char *text,
@@ -6493,6 +6525,259 @@ format_begin_file (CONVERTER *self, const char 
*filename,
     }
 }
 
+char *
+format_button_icon_img (CONVERTER *self,
+                        const char *button_name,
+                        const char *icon, const char *name)
+{
+  FORMATTING_REFERENCE *formatting_reference
+   = &self->current_formatting_references[FR_format_button_icon_img];
+/*
+  if (formatting_reference->status == FRS_status_default_set)
+    {
+      return html_default_format_button_icon_img (self, button_name,
+                                                        icon, name);
+    }
+  else
+*/
+    {
+      return call_formatting_function_format_button_icon_img (self,
+                                                     formatting_reference,
+                                                     button_name,
+                                                     icon, name);
+    }
+}
+
+FORMATTED_BUTTON_INFO *
+html_default_format_button (CONVERTER *self,
+                            const BUTTON_SPECIFICATION *button,
+                            const ELEMENT *element)
+{
+  if (button->type == BST_function)
+    {
+      return call_button_simple_function (self, button->sv_reference);
+    }
+  else if (button->type == BST_direction_info
+           && button->button_info->type == BIT_function)
+    {
+      return call_button_direction_function (self,
+                      button->button_info->sv_reference,
+                      button->button_info->direction, element);
+    }
+  else
+    {
+      FORMATTED_BUTTON_INFO *formatted_button;
+      formatted_button = (FORMATTED_BUTTON_INFO *)
+        malloc (sizeof (FORMATTED_BUTTON_INFO));
+      memset (formatted_button, 0, sizeof (FORMATTED_BUTTON_INFO));
+
+      if (button->type == BST_string)
+        {
+          formatted_button->active
+            = get_perl_scalar_reference_value (button->sv_string);
+          formatted_button->need_delimiter = 1;
+        }
+      else if (button->type == BST_direction_info)
+        {
+          int direction = button->button_info->direction;
+          if (button->button_info->type == BIT_string)
+            {
+              /* use given text */
+              char *text = get_perl_scalar_reference_value
+                                      (button->button_info->sv_string);
+              if (text)
+                {
+                  char *href = from_element_direction (self, direction,
+                                                HTT_href, 0, 0, element);
+                  if (href)
+                    {
+                      formatted_button->active
+                        = direction_anchor (self, direction, href, text);
+                      free (href);
+                    }
+                  else
+                    {
+                      formatted_button->passive = text;
+                    }
+                }
+            }
+          else if (button->button_info->type
+                   == BIT_selected_direction_information_type)
+            {
+         /* this case is mostly for tests, to test the direction type
+            in direction_information_type with the direction direction */
+              if (button->button_info->direction_information_type >= 0)
+                formatted_button->active
+                  = from_element_direction (self, direction,
+                         button->button_info->direction_information_type,
+                                                           0, 0, element);
+            }
+          else if (button->button_info->type
+                   == BIT_href_direction_information_type)
+            {
+              char *href = from_element_direction (self, direction,
+                                                   HTT_href, 0, 0, element);
+              if (button->button_info->direction_information_type >= 0)
+                {
+                  char *text_formatted = from_element_direction (self,
+                                                                 direction,
+                            button->button_info->direction_information_type,
+                                                                 0, 0, 0);
+                  if (href)
+                    {
+                      formatted_button->active
+                        = direction_anchor (self, direction, href,
+                                                    text_formatted);
+                    }
+                  else
+                    formatted_button->passive = strdup (text_formatted);
+                  free (text_formatted);
+                }
+              free (href);
+            }
+          formatted_button->need_delimiter = 1;
+        }
+      /* for the next cases, button->type == BST_direction */
+      else if (button->direction == D_direction_Space)
+        {
+          /* handle space button */
+          if (self->conf->ICONS > 0 && self->conf->ACTIVE_ICONS.number > 0
+              && self->conf->ACTIVE_ICONS.list[button->direction]
+              && strlen (self->conf->ACTIVE_ICONS.list[button->direction]))
+            {
+              char *button_name_string = direction_string (self,
+                                     button->direction, TDS_type_button,
+                                                      TDS_context_string);
+              formatted_button->active
+                = format_button_icon_img (self, button_name_string,
+                       self->conf->ACTIVE_ICONS.list[button->direction], 0);
+            }
+          else
+            {
+              formatted_button->active = strdup (direction_string (self,
+                                    button->direction, TDS_type_text, 0));
+            }
+          formatted_button->need_delimiter = 0;
+        }
+      else
+        {
+          char *href = from_element_direction (self, button->direction,
+                                               HTT_href, 0, 0, element);
+          /*
+          fprintf (stderr, "HHH '%s' %s\n", href, print_element_debug 
(element, 0));
+           */
+          if (href)
+            {
+              /* button is active */
+              TEXT active_text;
+              char *active_icon = 0;
+              char *description = direction_string (self, button->direction,
+                                   TDS_type_description, TDS_context_string);
+
+              if (self->conf->ICONS > 0 && self->conf->ACTIVE_ICONS.number > 0
+                  && self->conf->ACTIVE_ICONS.list[button->direction]
+                  && strlen (self->conf->ACTIVE_ICONS.list[button->direction]))
+                active_icon = self->conf->ACTIVE_ICONS.list[button->direction];
+
+              text_init (&active_text);
+              if (!active_icon)
+                text_append_n (&active_text, "[", 1);
+              text_printf (&active_text, "<a href=\"%s\"", href);
+              if (description)
+                text_printf (&active_text, " title=\"%s\"", description);
+              if (self->conf->USE_ACCESSKEY > 0)
+                {
+                  char *accesskey = direction_string (self, button->direction,
+                                      TDS_type_accesskey, TDS_context_string);
+                  if (accesskey && strlen (accesskey))
+                    text_printf (&active_text, " accesskey=\"%s\"", accesskey);
+                }
+              if (self->conf->USE_REL_REV > 0)
+                {
+                  char *button_rel = direction_string (self, button->direction,
+                                     TDS_type_rel, TDS_context_string);
+                  if (button_rel && strlen (button_rel))
+                    text_printf (&active_text, " rel=\"%s\"", button_rel);
+                }
+              text_append_n (&active_text, ">", 1);
+              if (active_icon)
+                {
+                  char *button_name_string = direction_string (self,
+                                     button->direction, TDS_type_button,
+                                                      TDS_context_string);
+                  char *icon_name = from_element_direction (self,
+                                                        button->direction,
+                                                               HTT_string,
+                                                                 0, 0, 0);
+                  char *icon_img
+                    = format_button_icon_img (self, button_name_string,
+                                              active_icon, icon_name);
+                  free (icon_name);
+
+                  text_append (&active_text, icon_img);
+                  free (icon_img);
+                }
+              else
+                text_append (&active_text,
+                             direction_string (self, button->direction,
+                                               TDS_type_text, 0));
+
+              text_append_n (&active_text, "</a>", 4);
+
+              if (!active_icon)
+                text_append_n (&active_text, "]", 1);
+
+              formatted_button->active = active_text.text;
+              free (href);
+            }
+          else
+            {
+              TEXT passive_text;
+              char *passive_icon = 0;
+
+              text_init (&passive_text);
+
+              if (self->conf->ICONS > 0 && self->conf->PASSIVE_ICONS.number > 0
+                  && self->conf->PASSIVE_ICONS.list[button->direction]
+                  && strlen 
(self->conf->PASSIVE_ICONS.list[button->direction]))
+                {
+                  passive_icon
+                    = self->conf->PASSIVE_ICONS.list[button->direction];
+                }
+              if (passive_icon)
+                {
+                  char *button_name_string = direction_string (self,
+                                     button->direction, TDS_type_button,
+                                                      TDS_context_string);
+                  char *icon_name = from_element_direction (self,
+                                                        button->direction,
+                                                               HTT_string,
+                                                                 0, 0, 0);
+                  char *icon_img
+                    = format_button_icon_img (self, button_name_string,
+                                              passive_icon, icon_name);
+                  free (icon_name);
+
+                  text_append (&passive_text, icon_img);
+                  free (icon_img);
+                }
+              else
+                {
+                  text_append_n (&passive_text, "[", 1);
+                  text_append (&passive_text,
+                             direction_string (self, button->direction,
+                                               TDS_type_text, 0));
+                  text_append_n (&passive_text, "]", 1);
+                }
+              formatted_button->passive = passive_text.text;
+            }
+          formatted_button->need_delimiter = 0;
+        }
+      return formatted_button;
+    }
+  return 0;
+}
+
 FORMATTED_BUTTON_INFO *
 format_button (CONVERTER *self,
                const BUTTON_SPECIFICATION *button,
@@ -6500,13 +6785,11 @@ format_button (CONVERTER *self,
 {
   FORMATTING_REFERENCE *formatting_reference
    = &self->current_formatting_references[FR_format_button];
-/*
   if (formatting_reference->status == FRS_status_default_set)
     {
-      html_default_format_button (self, button, element, result);
+      return html_default_format_button (self, button, element);
     }
   else
-*/
     {
       return call_formatting_function_format_button (self,
                                                      formatting_reference,
@@ -8119,7 +8402,7 @@ mini_toc_internal (CONVERTER *self, const ELEMENT 
*element, TEXT *result)
 
           if (strlen (text))
             {
-              if (strlen (href))
+              if (href)
                 {
                   text_printf (result, "<li><a href=\"%s\"%s>%s</a>",
                                href, accesskey, text);
@@ -9354,6 +9637,21 @@ html_converter_initialize (CONVERTER *self)
 
   nr_special_units = self->special_unit_varieties.number;
 
+  self->direction_unit_direction_name = (const char **) malloc
+     ((nr_special_units + NON_SPECIAL_DIRECTIONS_NR +1) * sizeof (char *));
+  memcpy (self->direction_unit_direction_name, html_button_direction_names,
+          NON_SPECIAL_DIRECTIONS_NR * sizeof (char *));
+  memcpy (self->direction_unit_direction_name + NON_SPECIAL_DIRECTIONS_NR,
+          self->special_unit_info[SUI_type_direction],
+          nr_special_units * sizeof (char *));
+  self->direction_unit_direction_name[
+               nr_special_units + NON_SPECIAL_DIRECTIONS_NR] = 0;
+  /*
+  for (i = 0; self->direction_unit_direction_name[i]; i++)
+    fprintf (stderr, "DEBUG: direction unit names: %d '%s'\n", i,
+             self->direction_unit_direction_name[i]);
+   */
+
   /* allocate space for translated tree types, they will be created
      on-demand during the conversion */
   for (i = 0; i < SUIT_type_heading+1; i++)
@@ -9868,6 +10166,8 @@ html_free_converter (CONVERTER *self)
 
   free_generic_converter (self);
 
+  free (self->direction_unit_direction_name);
+
   free (self->special_unit_body);
   free (self->special_unit_body_formatting);
 
diff --git a/tp/Texinfo/XS/convert/get_html_perl_info.c 
b/tp/Texinfo/XS/convert/get_html_perl_info.c
index 281204b494..6d14517cdf 100644
--- a/tp/Texinfo/XS/convert/get_html_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_html_perl_info.c
@@ -825,6 +825,8 @@ html_converter_initialize_sv (SV *converter_sv,
         }
     }
 
+  /* The corresponding direction without FirstInFile are used instead
+     of FirstInFile*, so the directions_strings are not set */
   nr_string_directions = NON_SPECIAL_DIRECTIONS_NR - FIRSTINFILE_NR
                      + converter->special_unit_varieties.number;
 
diff --git a/tp/Texinfo/XS/main/api_to_perl.c b/tp/Texinfo/XS/main/api_to_perl.c
index 2f1e2c0298..0dabf7f9c2 100644
--- a/tp/Texinfo/XS/main/api_to_perl.c
+++ b/tp/Texinfo/XS/main/api_to_perl.c
@@ -55,6 +55,15 @@ unregister_perl_button (BUTTON_SPECIFICATION *button)
   SvREFCNT_dec (button->sv);
 }
 
+char *
+get_perl_scalar_reference_value (const void *sv_string)
+{
+  dTHX;
+
+  char *value = strdup ((char *) SvPVutf8_nolen (SvRV ((SV *) sv_string)));
+  return value;
+}
+
 void
 call_switch_to_global_locale (void)
 {
diff --git a/tp/Texinfo/XS/main/api_to_perl.h b/tp/Texinfo/XS/main/api_to_perl.h
index 7b701e7076..de489a1222 100644
--- a/tp/Texinfo/XS/main/api_to_perl.h
+++ b/tp/Texinfo/XS/main/api_to_perl.h
@@ -11,4 +11,6 @@ void unregister_perl_button (BUTTON_SPECIFICATION *button);
 void call_switch_to_global_locale (void);
 void call_sync_locale (void);
 void croak_message (char *message);
+
+char *get_perl_scalar_reference_value (const void *sv_string);
 #endif
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index 55557ae946..5e72c00353 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -695,6 +695,7 @@ typedef struct CONVERTER {
     /* set for a converter, modified in a document */
     HTML_COMMAND_CONVERSION 
html_command_conversion[BUILTIN_CMD_NUMBER][HCC_type_css_string+1];
     char ***directions_strings[TDS_TYPE_MAX_NR];
+    const char **direction_unit_direction_name;
 
     /* set for a document */
     enum htmlxref_split_type document_htmlxref_split_type;
@@ -803,7 +804,8 @@ enum button_specification_type {
 enum button_information_type {
   BIT_string,
   BIT_function,
-  BIT_direction_information_type,
+  BIT_selected_direction_information_type,
+  BIT_href_direction_information_type,
 };
 
 typedef struct BUTTON_SPECIFICATION_INFO {
@@ -851,4 +853,9 @@ typedef struct FORMATTED_BUTTON_INFO {
     int need_delimiter;
 } FORMATTED_BUTTON_INFO;
 
+typedef struct DIRECTION_ICON_LIST {
+    size_t number;
+    char **list;
+} DIRECTION_ICON_LIST;
+
 #endif
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index 833ac33058..560f245f8e 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -852,23 +852,26 @@ int
 html_get_direction_index (CONVERTER *converter, const char *direction)
 {
   int i;
-  int idx;
-  for (i = 0; i < FIRSTINFILE_MAX_IDX +1; i++)
+  if (converter && converter->direction_unit_direction_name)
     {
-      if (!strcmp (direction, html_button_direction_names[i]))
-        return i;
+      for (i = 0; converter->direction_unit_direction_name[i]; i++)
+        {
+          if (!strcmp (direction, converter->direction_unit_direction_name[i]))
+            return i;
+        }
     }
-  idx = FIRSTINFILE_MAX_IDX +1;
-  if (converter)
+   /* we could do the following, but there is no point in getting the
+      buttons if not all can be determined */
+   /*
+  else
     {
-      for (i = 0; i < converter->special_unit_varieties.number; i++)
+      for (i = 0; i < NON_SPECIAL_DIRECTIONS_NR; i++)
         {
-          if (!strcmp(direction,
-                  converter->special_unit_info[SUI_type_direction][i]))
-            return idx;
-          idx++;
+          if (!strcmp (direction, html_button_direction_names[i]))
+            return i;
         }
     }
+    */
   return -1;
 }
 
@@ -949,10 +952,34 @@ html_get_button_specification_list (CONVERTER *converter, 
SV *buttons_sv)
                 }
               else
                 {
-                  button_spec->type = BIT_direction_information_type;
-                  button_spec->direction_information_type
-                   = html_get_direction_index (converter,
-                                 SvPVutf8_nolen (*button_spec_info_type));
+                  int j;
+                  char *text_type_string
+                     = SvPVutf8_nolen (*button_spec_info_type);
+                  char *text_type_p;
+                  if (strlen (text_type_string) > 2
+                      && !(memcmp (text_type_string, "->", 2)))
+                    {
+                      button_spec->type
+                        = BIT_selected_direction_information_type;
+                      text_type_p = text_type_string +2;
+                      text_type_p += strspn (text_type_p, whitespace_chars);
+                    }
+                  else
+                    {
+                      text_type_p = text_type_string;
+                      button_spec->type
+                        = BIT_href_direction_information_type;
+                    }
+                  button_spec->direction_information_type = -1;
+                  for (j = 0; j < HTT_section +1; j++)
+                    {
+                      if (!strcmp (html_command_text_type_name[j],
+                                   text_type_p))
+                        {
+                          button_spec->direction_information_type = j;
+                          break;
+                        }
+                    }
                 }
             }
           else
@@ -972,3 +999,42 @@ html_get_button_specification_list (CONVERTER *converter, 
SV *buttons_sv)
   return result;
 }
 
+/* HTML specific, but needs to be there for options_get_perl.c */
+void
+html_get_direction_icons_sv (CONVERTER *converter,
+                             DIRECTION_ICON_LIST *direction_icons,
+                             SV *icons_sv)
+{
+  HV *icons_hv;
+  int i;
+
+  dTHX;
+
+  if (!SvOK (icons_sv))
+    return;
+
+  if (!converter || !converter->direction_unit_direction_name)
+    return;
+
+  direction_icons->number = converter->special_unit_varieties.number
+                        + NON_SPECIAL_DIRECTIONS_NR;
+  direction_icons->list = (char **) malloc
+           (direction_icons->number * sizeof (char *));
+  memset (direction_icons->list, 0, direction_icons->number * sizeof (char *));
+
+  icons_hv = (HV *)SvRV (icons_sv);
+
+  for (i = 0; converter->direction_unit_direction_name[i] ; i++)
+    {
+      const char *direction_name
+        = converter->direction_unit_direction_name[i];
+      SV **direction_icon_sv = hv_fetch (icons_hv, direction_name,
+                                         strlen (direction_name), 0);
+      if (direction_icon_sv && SvOK (*direction_icon_sv))
+        {
+          direction_icons->list[i]
+            = strdup (SvPVutf8_nolen (*direction_icon_sv));
+        }
+    }
+}
+
diff --git a/tp/Texinfo/XS/main/get_perl_info.h 
b/tp/Texinfo/XS/main/get_perl_info.h
index 8ae558269d..5750a25798 100644
--- a/tp/Texinfo/XS/main/get_perl_info.h
+++ b/tp/Texinfo/XS/main/get_perl_info.h
@@ -50,5 +50,8 @@ TEXT_OPTIONS *copy_sv_options_for_convert_text (SV *sv_in);
 
 BUTTON_SPECIFICATION_LIST *html_get_button_specification_list
                                 (CONVERTER *converter, SV *buttons_sv);
+void html_get_direction_icons_sv (CONVERTER *converter,
+                             DIRECTION_ICON_LIST *direction_icons,
+                             SV *icons_sv);
 
 #endif
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 7e430443af..dd3d053a24 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -128,6 +128,12 @@ const char *html_button_direction_names[] = {
   #undef rud_type
 };
 
+/* keep in sync with enum html_text_type */
+char *html_command_text_type_name[] = {
+  "text", "text_nonumber", "string", "string_nonumber",
+  "href", "target", "node", "section",
+};
+
 /* wrapper for asprintf */
 int
 xasprintf (char **ptr, const char *template, ...)
@@ -1338,3 +1344,21 @@ html_free_button_specification_list 
(BUTTON_SPECIFICATION_LIST *buttons)
   free (buttons);
 }
 
+void
+html_free_direction_icons (DIRECTION_ICON_LIST *direction_icons)
+{
+  if (!direction_icons)
+    return;
+
+  if (direction_icons->number > 0)
+    {
+      size_t i;
+      for (i = 0; i < direction_icons->number; i++)
+        {
+          free (direction_icons->list[i]);
+        }
+    }
+  free (direction_icons->list);
+}
+
+
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index df9e95704d..d66707167e 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -41,6 +41,7 @@ extern const char *output_unit_type_names[];
 extern const char *command_location_names[];
 
 extern const char *html_button_direction_names[];
+extern char *html_command_text_type_name[];
 
 typedef struct {
     char *encoding_name;
@@ -248,5 +249,6 @@ ELEMENT *get_cmd_global_uniq_command (GLOBAL_COMMANDS 
*global_commands_ref,
                                       enum command_id cmd);
 
 void html_free_button_specification_list (BUTTON_SPECIFICATION_LIST *buttons);
+void html_free_direction_icons (DIRECTION_ICON_LIST *direction_icons);
 
 #endif
diff --git a/tp/Texinfo/options_data.txt b/tp/Texinfo/options_data.txt
index bfe7bbd628..f238b1f5a0 100644
--- a/tp/Texinfo/options_data.txt
+++ b/tp/Texinfo/options_data.txt
@@ -329,8 +329,8 @@ SECTION_FOOTER_BUTTONS             converter_other undef   
BUTTON_SPECIFICATION_
 NODE_FOOTER_BUTTONS                converter_other undef   
BUTTON_SPECIFICATION_LIST *
 MISC_BUTTONS                       converter_other undef   
BUTTON_SPECIFICATION_LIST *
 CHAPTER_BUTTONS                    converter_other undef   
BUTTON_SPECIFICATION_LIST *
-ACTIVE_ICONS                       converter_other undef   ICONS *
-PASSIVE_ICONS                      converter_other undef   ICONS *
+ACTIVE_ICONS                       converter_other undef   DIRECTION_ICON_LIST
+PASSIVE_ICONS                      converter_other undef   DIRECTION_ICON_LIST
 
 
 # set from command line.
diff --git a/tp/maintain/regenerate_C_options_info.pl 
b/tp/maintain/regenerate_C_options_info.pl
index 54e8d9c011..cb4000a870 100755
--- a/tp/maintain/regenerate_C_options_info.pl
+++ b/tp/maintain/regenerate_C_options_info.pl
@@ -104,13 +104,6 @@ print HEADER "#ifndef OPTIONS_TYPE_H\n#define 
OPTIONS_TYPE_H\n\n";
 print HEADER "#include \"tree_types.h\"\n";
 print HEADER "#include \"converter_types.h\"\n\n";
 
-print HEADER '
-/* temporary */
-typedef struct {
-} ICONS;
-
-';
-
 print HEADER "typedef struct OPTIONS {\n";
 
 foreach my $category (sort(keys(%option_categories))) {
@@ -145,7 +138,7 @@ foreach my $category (sort(keys(%option_categories))) {
   print CODE "\n/* ${category} */\n\n";
   foreach my $option_info (@{$option_categories{$category}}) {
     my ($option, $value, $type) = @$option_info;
-    if ($type eq 'STRING_LIST') {
+    if ($type eq 'STRING_LIST' or $type eq 'DIRECTION_ICON_LIST') {
       print CODE "  memset (&options->$option, 0, sizeof ($type));\n";
     } else {
       my $init_value = 0;
@@ -169,6 +162,8 @@ foreach my $category (sort(keys(%option_categories))) {
       print CODE " free (options->$option);\n";
     } elsif ($type eq 'BUTTON_SPECIFICATION_LIST *') {
       print CODE "  html_free_button_specification_list (options->$option);\n";
+    } elsif ($type eq 'DIRECTION_ICON_LIST') {
+      print CODE "  html_free_direction_icons (&options->$option);\n";
     }
   }
 }
@@ -344,6 +339,11 @@ foreach my $category (sort(keys(%option_categories))) {
       print GET "      options->$option = "
                         ."html_get_button_specification_list (converter, 
value);\n";
       print GET "    }\n";
+    } elsif ($type eq 'DIRECTION_ICON_LIST') {
+      print GET "    {\n";
+      print GET "      html_free_direction_icons (&options->$option);\n";
+      print GET "      html_get_direction_icons_sv (converter, 
&options->$option, value);\n";
+      print GET "    }\n";
     } else {
       print GET "    {}\n";
     }



reply via email to

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