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, 10 Jan 2024 17:21:19 -0500 (EST)

branch: master
commit 43e3278325f3c250b9c75332a98d376aeb236549
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Jan 10 10:57:21 2024 +0100

    * tp/Texinfo/Structuring.pm (setup_sortable_index_entries): remove the
    $silent argument, not used.
    
    * tp/Texinfo/XS/main/utils.c (set_expanded_formats_from_options): add
    to be able to set expanded formats based on EXPANDED_FORMATS
    customization option, without a converter information.
    
    * tp/Texinfo/XS/convert/indices_in_conversion.c
    (index_entry_element_sort_string), tp/Texinfo/XS/main/get_perl_info.c
    (find_index_entry_sv, get_sv_index_entries_sorted_by_letter),
    tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
    (index_entry_element_sort_string): return as reference the INDEX in
    find_index_entry_sv.  Pass in_code argument to
    index_entry_element_sort_string and use it to modify the text options
    directly in the function.
    
    * tp/Texinfo/XS/main/convert_to_text.c (copy_options_for_convert_text)
    (copy_converter_options_for_convert_text, destroy_text_options),
    tp/Texinfo/XS/main/convert_to_text.h (TEXT_OPTIONS),
    tp/Texinfo/XS/main/get_perl_info.c (converter_initialize): use OPTIONS in
    copy_options_for_convert_text argument, and add another variant with a
    converter in argument, copy_converter_options_for_convert_text.
    
    * tp/Texinfo/XS/main/document.c
    (register_document_convert_index_text_options)
    (destroy_document_information_except_tree),
    tp/Texinfo/XS/convert/converter.c (free_generic_converter),
    tp/Texinfo/XS/main/document_types.h (DOCUMENT),
    tp/Texinfo/XS/main/converter_types.h (CONVERTER): add
    convert_index_text_options to register text options used for index
    sorting keys conversion.
    
    * tp/Texinfo/Structuring.pm (%XS_overrides),
    tp/Texinfo/XS/main/convert_to_text.c
    (set_additional_index_entry_keys_options)
    (setup_index_entry_keys_formatting)
    (setup_converter_index_entry_keys_formatting),
    tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
    (setup_index_entry_keys_formatting, index_entry_element_sort_string):
    add an override for setup_index_entry_keys_formatting that triggers
    initializing TEXT_OPTIONS for a converter or a document to be used for
    index sorting in index_entry_element_sort_string.
    
    * tp/t/test_sort.t: call register_XS_document_main_configuration to
    have the customization available in document for the
    setup_index_entry_keys_formatting override.
---
 ChangeLog                                          | 49 +++++++++++++
 tp/TODO                                            |  4 +
 tp/Texinfo/Convert/Text.pm                         |  5 +-
 tp/Texinfo/Structuring.pm                          | 21 +++---
 tp/Texinfo/XS/convert/converter.c                  |  3 +
 tp/Texinfo/XS/convert/indices_in_conversion.c      |  6 +-
 tp/Texinfo/XS/convert/indices_in_conversion.h      |  2 +-
 tp/Texinfo/XS/main/convert_to_text.c               | 72 ++++++++++++++----
 tp/Texinfo/XS/main/convert_to_text.h               | 12 ++-
 tp/Texinfo/XS/main/converter_types.h               |  1 +
 tp/Texinfo/XS/main/document.c                      | 12 +++
 tp/Texinfo/XS/main/document.h                      |  5 ++
 tp/Texinfo/XS/main/document_types.h                |  5 ++
 tp/Texinfo/XS/main/get_perl_info.c                 | 27 +++----
 tp/Texinfo/XS/main/get_perl_info.h                 |  4 +-
 tp/Texinfo/XS/main/utils.c                         | 23 +++++-
 tp/Texinfo/XS/main/utils.h                         |  7 +-
 tp/Texinfo/XS/parsetexi/end_line.c                 |  7 +-
 tp/Texinfo/XS/parsetexi/indices.c                  |  2 +-
 tp/Texinfo/XS/parsetexi/indices.h                  |  2 +-
 .../XS/structuring_transfo/StructuringTransfoXS.xs | 85 +++++++++++++++++++---
 tp/t/test_sort.t                                   |  5 +-
 22 files changed, 288 insertions(+), 71 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d4300b4055..f9fb5a33b4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,52 @@
+2024-01-10  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Structuring.pm (setup_sortable_index_entries): remove the
+       $silent argument, not used.
+
+       * tp/Texinfo/XS/main/utils.c (set_expanded_formats_from_options): add
+       to be able to set expanded formats based on EXPANDED_FORMATS
+       customization option, without a converter information.
+
+       * tp/Texinfo/XS/convert/indices_in_conversion.c
+       (index_entry_element_sort_string), tp/Texinfo/XS/main/get_perl_info.c
+       (find_index_entry_sv, get_sv_index_entries_sorted_by_letter),
+       tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+       (index_entry_element_sort_string): return as reference the INDEX in
+       find_index_entry_sv.  Pass in_code argument to
+       index_entry_element_sort_string and use it to modify the text options
+       directly in the function.
+
+       * tp/Texinfo/XS/main/convert_to_text.c (copy_options_for_convert_text)
+       (copy_converter_options_for_convert_text, destroy_text_options), 
+       tp/Texinfo/XS/main/convert_to_text.h (TEXT_OPTIONS),
+       tp/Texinfo/XS/main/get_perl_info.c (converter_initialize): use OPTIONS 
in
+       copy_options_for_convert_text argument, and add another variant with a
+       converter in argument, copy_converter_options_for_convert_text.
+
+       * tp/Texinfo/XS/main/document.c
+       (register_document_convert_index_text_options)
+       (destroy_document_information_except_tree),
+       tp/Texinfo/XS/convert/converter.c (free_generic_converter),
+       tp/Texinfo/XS/main/document_types.h (DOCUMENT),
+       tp/Texinfo/XS/main/converter_types.h (CONVERTER): add
+       convert_index_text_options to register text options used for index
+       sorting keys conversion.
+
+       * tp/Texinfo/Structuring.pm (%XS_overrides),
+       tp/Texinfo/XS/main/convert_to_text.c
+       (set_additional_index_entry_keys_options)
+       (setup_index_entry_keys_formatting)
+       (setup_converter_index_entry_keys_formatting),
+       tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+       (setup_index_entry_keys_formatting, index_entry_element_sort_string):
+       add an override for setup_index_entry_keys_formatting that triggers
+       initializing TEXT_OPTIONS for a converter or a document to be used for
+       index sorting in index_entry_element_sort_string.
+
+       * tp/t/test_sort.t: call register_XS_document_main_configuration to
+       have the customization available in document for the
+       setup_index_entry_keys_formatting override.
+
 2024-01-09  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/utils.c (copy_strings, set_conf_string)
diff --git a/tp/TODO b/tp/TODO
index 8d18307060..7a3454bdbc 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -19,6 +19,10 @@ Any directory part in the file name argument of the source 
cross reference comma
 Document that Texinfo::Document::rebuild_document or
 Texinfo::Document::rebuild_tree should be called after tree modifications
 if the parser is XS but converters are perl.
+Also if conversion with XS, and there is a MainConfig, the configuration
+should be registered in the document if it is needed in structuring and
+indices sorting.
+$main_configuration->register_XS_document_main_configuration($document);
 
 
 Bugs
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index 317e08f555..d2cc173c34 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -386,7 +386,7 @@ my @text_indicator_converter_options = ('NUMBER_SECTIONS', 
'ASCII_GLYPH', 'TEST'
     # for error registering,
     'DEBUG');
 
-# TODO not documented, used in many converters
+# TODO not documented
 # $SELF is typically a converter object.
 # Setup options as used by Texinfo::Convert::Text::convert_to_text
 # based on the converter information.
@@ -442,8 +442,7 @@ sub set_options_encoding_if_not_ascii($$)
   my $self = shift;
   my $options = shift;
   my $output_encoding_name = $self->get_conf('OUTPUT_ENCODING_NAME');
-  if (defined($output_encoding_name)
-      and $output_encoding_name ne 'us-ascii') {
+  if (defined($output_encoding_name) and $output_encoding_name ne 'us-ascii') {
     if (defined($options->{'_saved_enabled_encoding'})) {
        print STDERR "BUG: if_not_ascii _saved_enabled_encoding set: "
                             .$options->{'_saved_enabled_encoding'}." / ".
diff --git a/tp/Texinfo/Structuring.pm b/tp/Texinfo/Structuring.pm
index 5ffb9e17e2..8d1bbac0da 100644
--- a/tp/Texinfo/Structuring.pm
+++ b/tp/Texinfo/Structuring.pm
@@ -114,10 +114,10 @@ our %XS_overrides = (
   "Texinfo::Structuring::_XS_unsplit"
     => "Texinfo::StructTransfXS::unsplit",
 
-  # TODO the text options are read
-  # from perl for each entry instead of once for each index.
   "Texinfo::Structuring::index_entry_element_sort_string"
     => "Texinfo::StructTransfXS::index_entry_element_sort_string",
+  "Texinfo::Structuring::setup_index_entry_keys_formatting",
+    => "Texinfo::StructTransfXS::setup_index_entry_keys_formatting",
 
   # Not useful for HTML as functions, as the calling functions are
   # already overriden
@@ -2410,14 +2410,19 @@ sub _converter_or_registrar_line_warn($$$$)
 # information.  It should already be set if it is a converter based
 # on Texinfo::Convert::Converter, but otherwise it should be set by
 # the caller, setting 'document_descriptor' to document->document_descriptor().
-sub setup_sortable_index_entries($$$$$;$)
+# If $PRESET_KEYS is set, the entries sort keys are set with a collator help
+# and the default sort function can be directly used.  If unset, no collator
+# is passed to the functions setting the sort key, but a collator is used for
+# sorting.  In practice $PRESET_KEYS is always set, as the default
+# $default_preset_keys, which set to 1 is always used in calling functions
+# to determine the value of $PRESET_KEYS.
+sub setup_sortable_index_entries($$$$$)
 {
   my $registrar = shift;
   my $customization_information = shift;
   my $index_entries = shift;
   my $indices_information = shift;
   my $preset_keys = shift;
-  my $silent = shift;
 
   # The 'Non-Ignorable' for variable collation elements means that they are
   # treated as normal characters.   This allows to have spaces and punctuation
@@ -2495,13 +2500,11 @@ sub setup_sortable_index_entries($$$$$;$)
         $entry_cmdname
           = $main_entry_element->{'extra'}->{'original_def_cmdname'}
            if (!defined($entry_cmdname));
-        if (!$silent) {
-          _converter_or_registrar_line_warn($registrar,
+        _converter_or_registrar_line_warn($registrar,
                                    $customization_information,
                        sprintf(__("empty index key in \@%s"),
                                   $entry_cmdname),
                                $main_entry_element->{'source_info'});
-        }
         push @entry_keys, '';
         push @sort_entry_keys, '';
       } else {
@@ -2522,13 +2525,11 @@ sub setup_sortable_index_entries($$$$$;$)
           $entry_cmdname
             = $main_entry_element->{'extra'}->{'original_def_cmdname'}
               if (!defined($entry_cmdname));
-          if (!$silent) {
-            _converter_or_registrar_line_warn($registrar,
+          _converter_or_registrar_line_warn($registrar,
                                 $customization_information,
                          sprintf(__("empty index sub entry %d key in \@%s"),
                                     $subentry_nr, $entry_cmdname),
                                   $main_entry_element->{'source_info'});
-          }
           push @entry_keys, '';
           push @sort_entry_keys, '';
         } else {
diff --git a/tp/Texinfo/XS/convert/converter.c 
b/tp/Texinfo/XS/convert/converter.c
index 55cee45dc2..37308d0250 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -866,6 +866,9 @@ free_generic_converter (CONVERTER *self)
     free_options (self->conf);
   free (self->conf);
 
+  if (self->convert_index_text_options)
+    destroy_text_options (self->convert_index_text_options);
+
   free_output_files_information (&self->output_files_information);
   free_output_unit_files (&self->output_unit_files);
 
diff --git a/tp/Texinfo/XS/convert/indices_in_conversion.c 
b/tp/Texinfo/XS/convert/indices_in_conversion.c
index cd8b43097c..8f05f58e61 100644
--- a/tp/Texinfo/XS/convert/indices_in_conversion.c
+++ b/tp/Texinfo/XS/convert/indices_in_conversion.c
@@ -164,7 +164,7 @@ index_content_element (const ELEMENT *element, int 
prefer_reference_element)
 char *
 index_entry_element_sort_string (INDEX_ENTRY *main_entry,
                                  ELEMENT *index_entry_element,
-                                 TEXT_OPTIONS *options,
+                                 TEXT_OPTIONS *options, int in_code,
                                  int prefer_reference_element)
 {
   char *sort_string;
@@ -183,7 +183,11 @@ index_entry_element_sort_string (INDEX_ENTRY *main_entry,
   entry_tree_element = index_content_element (index_entry_element,
                                           prefer_reference_element);
 
+  if (in_code)
+    options->code_state++;
   sort_string = convert_to_text (entry_tree_element, options);
+  if (in_code)
+    options->code_state--;
 
   index_ignore_chars = lookup_extra_string (main_entry->entry_element,
                                             "index_ignore_chars");
diff --git a/tp/Texinfo/XS/convert/indices_in_conversion.h 
b/tp/Texinfo/XS/convert/indices_in_conversion.h
index 7d9c7f7ab0..71787d165d 100644
--- a/tp/Texinfo/XS/convert/indices_in_conversion.h
+++ b/tp/Texinfo/XS/convert/indices_in_conversion.h
@@ -16,6 +16,6 @@ ELEMENT *index_content_element (const ELEMENT *element,
 
 char *index_entry_element_sort_string (INDEX_ENTRY *main_entry,
                                  ELEMENT *index_entry_element,
-                                 TEXT_OPTIONS *options,
+                                 TEXT_OPTIONS *options, int in_code,
                                  int prefer_reference_element);
 #endif
diff --git a/tp/Texinfo/XS/main/convert_to_text.c 
b/tp/Texinfo/XS/main/convert_to_text.c
index 4a009dc1bc..1178fac039 100644
--- a/tp/Texinfo/XS/main/convert_to_text.c
+++ b/tp/Texinfo/XS/main/convert_to_text.c
@@ -127,7 +127,8 @@ destroy_text_options (TEXT_OPTIONS *text_options)
   free (text_options->expanded_formats);
   free_strings_list (&text_options->include_directories);
   if (text_options->other_converter_options
-      && !text_options->converter)
+      && !text_options->converter
+      && !text_options->other_options)
     {
       free_options (text_options->other_converter_options);
       free (text_options->other_converter_options);
@@ -148,34 +149,73 @@ destroy_text_options (TEXT_OPTIONS *text_options)
 /* the string and strlist options need to be copied, in case they are
    deallocated if options are reset */
 TEXT_OPTIONS *
-copy_options_for_convert_text (CONVERTER *self)
+copy_options_for_convert_text (OPTIONS *options)
 {
-  TEXT_OPTIONS *options = new_text_options ();
+  TEXT_OPTIONS *text_options = new_text_options ();
   int text_indicator_option;
 
-  if (self->conf->ENABLE_ENCODING.integer > 0
-       && self->conf->OUTPUT_ENCODING_NAME.string)
+  if (options->ENABLE_ENCODING.integer > 0
+       && options->OUTPUT_ENCODING_NAME.string)
     {
-      options->encoding = strdup (self->conf->OUTPUT_ENCODING_NAME.string);
+      text_options->encoding = strdup (options->OUTPUT_ENCODING_NAME.string);
     }
 
   #define tico_option_name(name) \
-  text_indicator_option = self->conf->name.integer; \
-  if (text_indicator_option > 0) { options->name = 1; } \
-  else if (text_indicator_option >= 0) { options->name = 0; }
+  text_indicator_option = options->name.integer; \
+  if (text_indicator_option > 0) { text_options->name = 1; } \
+  else if (text_indicator_option >= 0) { text_options->name = 0; }
    TEXT_INDICATOR_CONVERTER_OPTIONS
   #undef tico_option_name
 
-  memcpy (options->expanded_formats, self->expanded_formats,
-          expanded_formats_number () * sizeof (EXPANDED_FORMAT));
+  set_expanded_formats_from_options (text_options->expanded_formats, options);
 
-  copy_strings (&options->include_directories,
-                self->conf->INCLUDE_DIRECTORIES.strlist);
+  copy_strings (&text_options->include_directories,
+                options->INCLUDE_DIRECTORIES.strlist);
 
-  options->other_converter_options = self->conf;
-  options->converter = self;
+  text_options->other_converter_options = options;
 
-  return options;
+  return text_options;
+}
+
+TEXT_OPTIONS *
+copy_converter_options_for_convert_text (CONVERTER *self)
+{
+  TEXT_OPTIONS *text_options = copy_options_for_convert_text (self->conf);
+  text_options->converter = self;
+  return text_options;
+}
+
+/* In Structuring.pm */
+static void
+set_additional_index_entry_keys_options (OPTIONS *options,
+                                         TEXT_OPTIONS *text_options)
+{
+  if (options->ENABLE_ENCODING.integer <= 0
+      || !(options->OUTPUT_ENCODING_NAME.string
+           && !strcasecmp (options->OUTPUT_ENCODING_NAME.string, "utf-8")))
+    {
+      text_options->sort_string = 1;
+    }
+}
+
+/* there are two variants, to setup the text options used for index
+   index entries formatting as text in case this is done with a
+   converter or without. */
+TEXT_OPTIONS *
+setup_index_entry_keys_formatting (OPTIONS *options)
+{
+  TEXT_OPTIONS *text_options = copy_options_for_convert_text (options);
+  text_options->other_options = 1;
+  set_additional_index_entry_keys_options (options, text_options);
+  return text_options;
+}
+
+TEXT_OPTIONS *
+setup_converter_index_entry_keys_formatting (CONVERTER *self)
+{
+  TEXT_OPTIONS *text_options = copy_converter_options_for_convert_text (self);
+  set_additional_index_entry_keys_options (self->conf, text_options);
+  return text_options;
 }
 
 void
diff --git a/tp/Texinfo/XS/main/convert_to_text.h 
b/tp/Texinfo/XS/main/convert_to_text.h
index 82b44bbfe0..92d1d01d13 100644
--- a/tp/Texinfo/XS/main/convert_to_text.h
+++ b/tp/Texinfo/XS/main/convert_to_text.h
@@ -17,14 +17,15 @@ typedef struct TEXT_OPTIONS {
     int ASCII_GLYPH;
     int TEST;
     int NUMBER_SECTIONS;
+    int other_options;
     EXPANDED_FORMAT *expanded_formats;
     STRING_LIST include_directories;
     CONVERTER *converter;
     /* other_converter_options is used if set.  If not set and in some cases
        self_converter_options, if set, is used. */
-    OPTIONS *other_converter_options; /* corresponds to converter passed
-                                         to convert_to_text text options.
-      same than converter if set, but can be set directly from perl */
+    OPTIONS *other_converter_options; /* same than converter if converter
+      is set, but can be set directly from perl or from another source,
+      in which case other_options is set */
     OPTIONS *self_converter_options; /* text converter options available
                                         as the OPTIONS structure */
     int document_descriptor;
@@ -33,7 +34,10 @@ typedef struct TEXT_OPTIONS {
 char *convert_to_text (const ELEMENT *root, TEXT_OPTIONS *text_options);
 TEXT_OPTIONS *new_text_options (void);
 void destroy_text_options (TEXT_OPTIONS *text_options);
-TEXT_OPTIONS *copy_options_for_convert_text (CONVERTER *self);
+TEXT_OPTIONS *copy_options_for_convert_text (OPTIONS *options);
+TEXT_OPTIONS *copy_converter_options_for_convert_text (CONVERTER *self);
+TEXT_OPTIONS *setup_index_entry_keys_formatting (OPTIONS *options);
+TEXT_OPTIONS *setup_converter_index_entry_keys_formatting (CONVERTER *self);
 
 void text_set_options_encoding_if_not_ascii (CONVERTER *self,
                                         TEXT_OPTIONS *text_options);
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index c6c9e3c119..7903997e3c 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -712,6 +712,7 @@ typedef struct CONVERTER {
     int document_units_descriptor;
 
     struct TEXT_OPTIONS *convert_text_options;
+    struct TEXT_OPTIONS *convert_index_text_options;
 
   /* output unit files API */
     FILE_NAME_PATH_COUNTER_LIST output_unit_files;
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index b85b536f54..2568fd1eed 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -30,6 +30,7 @@
 #include "debug.h"
 /* for delete_global_info and wipe_index */
 #include "utils.h"
+#include "convert_to_text.h"
 #include "document.h"
 
 /* note that each time the document list is reallocated, pointers
@@ -132,6 +133,13 @@ register_document_options (DOCUMENT *document, OPTIONS 
*options)
   document->options = options;
 }
 
+void
+register_document_convert_index_text_options (DOCUMENT *document,
+                                              TEXT_OPTIONS *text_options)
+{
+  document->convert_index_text_options = text_options;
+}
+
 void
 destroy_document_information_except_tree (DOCUMENT *document)
 {
@@ -162,6 +170,10 @@ destroy_document_information_except_tree (DOCUMENT 
*document)
           free_options (document->options);
           free (document->options);
         }
+      if (document->convert_index_text_options)
+        {
+          destroy_text_options (document->convert_index_text_options);
+        }
     }
 }
 
diff --git a/tp/Texinfo/XS/main/document.h b/tp/Texinfo/XS/main/document.h
index d883d34319..f9dbd64e06 100644
--- a/tp/Texinfo/XS/main/document.h
+++ b/tp/Texinfo/XS/main/document.h
@@ -14,6 +14,8 @@ typedef struct TREE_AND_STRINGS {
     STRING_LIST *small_strings;
 } TREE_AND_STRINGS;
 
+struct TEXT_OPTIONS;
+
 
 DOCUMENT *retrieve_document (int document_descriptor);
 size_t register_document (ELEMENT *root, INDEX **index_names,
@@ -30,6 +32,9 @@ void register_document_nodes_list (DOCUMENT *document,
 void register_document_sections_list (DOCUMENT *document,
                                       ELEMENT_LIST *sections_list);
 void register_document_options (DOCUMENT *document, OPTIONS *options);
+void register_document_convert_index_text_options (DOCUMENT *document,
+                                         struct TEXT_OPTIONS *text_options);
+
 void remove_document_descriptor (int document_descriptor);
 TREE_AND_STRINGS *unregister_document_descriptor_tree (int 
document_descriptor);
 void clear_document_errors (int document_descriptor);
diff --git a/tp/Texinfo/XS/main/document_types.h 
b/tp/Texinfo/XS/main/document_types.h
index 92c1884f9f..7ce19de6ae 100644
--- a/tp/Texinfo/XS/main/document_types.h
+++ b/tp/Texinfo/XS/main/document_types.h
@@ -22,12 +22,15 @@
 #include "tree_types.h"
 /*
 #include "options_types.h"
+#include "convert_to_text.h"
  */
 #include "global_commands_types.h"
 
 /* to avoid interdependency with options_types.h, including for
    other include files */
 struct OPTIONS;
+/* same with convert_to_text.h */
+struct TEXT_OPTIONS;
 
 enum error_type { MSG_error, MSG_warning,
                   MSG_document_error, MSG_document_warning };
@@ -75,6 +78,8 @@ typedef struct DOCUMENT {
     ELEMENT_LIST *sections_list;
     ERROR_MESSAGE_LIST *error_messages;
     struct OPTIONS *options; /* for options used in structuring */
+    struct TEXT_OPTIONS *convert_index_text_options; /* for index
+                                       sorting without converter */
 } DOCUMENT;
 
 /* not in document, but used in parser */
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index bf12fda410..d137193fec 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -607,7 +607,7 @@ converter_initialize (SV *converter_sv)
   set_output_encoding (converter->conf, converter->document);
 
   converter->convert_text_options
-    = copy_options_for_convert_text (converter);
+    = copy_converter_options_for_convert_text (converter);
 
   converter->hv = hv_in;
 
@@ -639,15 +639,16 @@ reset_output_init_conf (SV *sv_in)
 }
 
 INDEX_ENTRY *
-find_index_entry_sv (SV *index_entry_sv, INDEX **index_names,
-                     const char *warn_string, char **entry_index_name,
+find_index_entry_sv (const SV *index_entry_sv, INDEX **index_names,
+                     const char *warn_string, const INDEX **entry_idx,
                      int *entry_number)
 {
   HV *index_entry_hv;
   SV **index_name_sv;
   SV **entry_number_sv;
   int entry_idx_in_index;
-  INDEX *idx;
+  char *entry_index_name = 0;
+  const INDEX *idx;
 
   dTHX;
 
@@ -657,9 +658,6 @@ find_index_entry_sv (SV *index_entry_sv, INDEX 
**index_names,
   entry_number_sv = hv_fetch (index_entry_hv, "entry_number",
                               strlen ("entry_number"), 0);
 
-  *entry_index_name = 0;
-  *entry_number = 0;
-
   if (!index_name_sv || !entry_number_sv)
     {
       char *msg;
@@ -669,13 +667,13 @@ find_index_entry_sv (SV *index_entry_sv, INDEX 
**index_names,
       xasprintf (&msg, "%s: no entry info\n", warn_str);
       fatal (msg);
     }
-  *entry_index_name = (char *) SvPVutf8_nolen (*index_name_sv);
+  entry_index_name = (char *) SvPVutf8_nolen (*index_name_sv);
   *entry_number = SvIV (*entry_number_sv);
   entry_idx_in_index = *entry_number - 1;
 
   idx = indices_info_index_by_name (index_names,
-                                    *entry_index_name);
-
+                                    entry_index_name);
+  *entry_idx = idx;
   if (idx)
     {
       if (entry_idx_in_index < idx->entries_number)
@@ -849,7 +847,7 @@ get_sv_index_entries_sorted_by_letter (INDEX **index_names,
               for (k = 0; k < entries_nr; k++)
                 {
                   SV** index_entry_sv = av_fetch (entries_av, k, 0);
-                  char *entry_index_name;
+                  const INDEX *entry_idx = 0;
                   int entry_number;
                   char *warn_string;
                   INDEX_ENTRY *index_entry = 0;
@@ -866,7 +864,7 @@ get_sv_index_entries_sorted_by_letter (INDEX **index_names,
                          "get_sv_index_entries_sorted_by_letter: %s: %d: %s: 
%d",
                          idx_name, i, letter_entries->letter, k);
                   index_entry = find_index_entry_sv (*index_entry_sv, 
index_names,
-                                                     warn_string, 
&entry_index_name,
+                                                     warn_string, &entry_idx,
                                                      &entry_number);
                   free (warn_string);
 
@@ -875,6 +873,9 @@ get_sv_index_entries_sorted_by_letter (INDEX **index_names,
                   if (!letter_entries->entries[k])
                     {
                       char *msg;
+                      char *entry_index_name = 0;
+                      if (entry_idx)
+                        entry_index_name = entry_idx->name;
                       xasprintf (&msg,
           "BUG: index %s letter %s position %d: %s entry %d not found\n",
                                  idx_name, letter_string, k,
@@ -1254,7 +1255,7 @@ find_document_index_entry_extra_index_entry_sv (DOCUMENT 
*document,
   AV *extra_index_entry_av;
   SV **index_name_sv;
   char *index_name = 0;
-  INDEX *idx = 0;
+  const INDEX *idx = 0;
 
   dTHX;
 
diff --git a/tp/Texinfo/XS/main/get_perl_info.h 
b/tp/Texinfo/XS/main/get_perl_info.h
index 5be575eff5..5e61413dd8 100644
--- a/tp/Texinfo/XS/main/get_perl_info.h
+++ b/tp/Texinfo/XS/main/get_perl_info.h
@@ -42,8 +42,8 @@ CONVERTER *get_sv_converter (SV *sv_in, const char 
*warn_string);
 int converter_initialize (SV *converter_sv);
 void reset_output_init_conf (SV *sv_in);
 
-INDEX_ENTRY *find_index_entry_sv (SV *index_entry_sv, INDEX **index_names,
-                     const char *warn_string, char **entry_index_name,
+INDEX_ENTRY *find_index_entry_sv (const SV *index_entry_sv, INDEX 
**index_names,
+                     const char *warn_string, const INDEX **entry_idx,
                      int *entry_number);
 
 INDEX_SORTED_BY_LETTER *get_sv_index_entries_sorted_by_letter
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index f3e9de84d6..dc0cdf9dd9 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -518,7 +518,7 @@ clear_expanded_formats (EXPANDED_FORMAT *formats)
 }
 
 void
-add_expanded_format (EXPANDED_FORMAT *formats, char *format)
+add_expanded_format (EXPANDED_FORMAT *formats, const char *format)
 {
   int i;
   for (i = 0; i < sizeof (expanded_formats)/sizeof (*expanded_formats);
@@ -563,6 +563,22 @@ expanded_formats_number (void)
   return sizeof (expanded_formats)/sizeof (*expanded_formats);
 }
 
+void
+set_expanded_formats_from_options (EXPANDED_FORMAT *formats,
+                                   const OPTIONS *options)
+{
+  if (options->EXPANDED_FORMATS.strlist
+      && (options->EXPANDED_FORMATS.strlist->number))
+    {
+      size_t i;
+      for (i = 0; i < options->EXPANDED_FORMATS.strlist->number; i++)
+        {
+          add_expanded_format (formats,
+                               options->EXPANDED_FORMATS.strlist->list[i]);
+        }
+    }
+}
+
 
 /* Return the parent if in an item_line command, @*table */
 ELEMENT *
@@ -594,9 +610,10 @@ get_label_element (const ELEMENT *e)
 /* index related code used both in parsing and conversion */
 /* NAME is the name of an index, e.g. "cp" */
 INDEX *
-indices_info_index_by_name (INDEX **indices_information, char *name)
+indices_info_index_by_name (INDEX **indices_information, const char *name)
 {
-  INDEX **i, *idx;
+  INDEX **i;
+  INDEX *idx;
 
   for (i = indices_information; (idx = *i); i++)
     if (!strcmp (idx->name, name))
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index 4e987e3685..a3657badf8 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -166,7 +166,8 @@ void delete_global_commands (GLOBAL_COMMANDS 
*global_commands_ref);
 char *normalize_encoding_name (const char *text, int *possible_encoding);
 ELEMENT *item_line_parent (ELEMENT *current);
 ELEMENT *get_label_element (const ELEMENT *e);
-INDEX *indices_info_index_by_name (INDEX **indices_information, char *name);
+INDEX *indices_info_index_by_name (INDEX **indices_information,
+                                   const char *name);
 INDEX *ultimate_index (INDEX *index);
 size_t index_number_index_by_name (const SORTED_INDEX_NAMES *sorted_indices,
                                    const char *name);
@@ -215,9 +216,11 @@ char *encode_string (char *input_string, char *encoding, 
int *status,
 
 EXPANDED_FORMAT *new_expanded_formats (void);
 void clear_expanded_formats (EXPANDED_FORMAT *formats);
-void add_expanded_format (EXPANDED_FORMAT *formats, char *format);
+void add_expanded_format (EXPANDED_FORMAT *formats, const char *format);
 int format_expanded_p (EXPANDED_FORMAT *formats, const char *format);
 int expanded_formats_number (void);
+void set_expanded_formats_from_options (EXPANDED_FORMAT *formats,
+                                        const OPTIONS *options);
 
 char *enumerate_item_representation (char *specification, int number);
 
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c 
b/tp/Texinfo/XS/parsetexi/end_line.c
index ef4371aa93..ed61982df7 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -367,7 +367,8 @@ parse_line_command_args (ELEMENT *line_command)
       {
         /* synindex FROM TO */
         char *index_name_from = 0, *index_name_to = 0;
-        INDEX *from_index, *to_index;
+        INDEX *from_index;
+        INDEX *to_index;
         char *p = line;
 
         if (!isascii_alnum (*p))
@@ -386,8 +387,8 @@ parse_line_command_args (ELEMENT *line_command)
         if (*p)
           goto synindex_invalid; /* More at end of line. */
 
-        from_index = indices_info_index_by_name (index_names,index_name_from);
-        to_index = indices_info_index_by_name (index_names,index_name_to);
+        from_index = indices_info_index_by_name (index_names, index_name_from);
+        to_index = indices_info_index_by_name (index_names, index_name_to);
         if (!from_index)
           line_error ("unknown source index in @%s: %s",
                       command_name(cmd), index_name_from);
diff --git a/tp/Texinfo/XS/parsetexi/indices.c 
b/tp/Texinfo/XS/parsetexi/indices.c
index b31653f97c..25319fcf06 100644
--- a/tp/Texinfo/XS/parsetexi/indices.c
+++ b/tp/Texinfo/XS/parsetexi/indices.c
@@ -124,7 +124,7 @@ add_index_internal (char *name, int in_code)
 
 /* Add a user defined index with the name NAME */
 void
-add_index (char *name, int in_code)
+add_index (const char *name, int in_code)
 {
   INDEX *idx = indices_info_index_by_name (index_names, name);
   char *cmdname;
diff --git a/tp/Texinfo/XS/parsetexi/indices.h 
b/tp/Texinfo/XS/parsetexi/indices.h
index 623cee4320..926acd8da3 100644
--- a/tp/Texinfo/XS/parsetexi/indices.h
+++ b/tp/Texinfo/XS/parsetexi/indices.h
@@ -8,7 +8,7 @@ extern INDEX **index_names;
 
 void init_index_commands (void);
 
-void add_index (char *name, int in_code);
+void add_index (const char *name, int in_code);
 INDEX *index_of_command (enum command_id cmd);
 void enter_index_entry (enum command_id index_type_cmd,
                         ELEMENT *current);
diff --git a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs 
b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
index 80d48356e6..899fd77531 100644
--- a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+++ b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
@@ -438,31 +438,98 @@ split_pages (SV *output_units_in, char *split)
         if (output_units)
           split_pages (output_units, split);
 
+# This function triggers setting the information needed for calls
+# to index_entry_element_sort_string in C, either in a document
+# or in a converter, depending whether index sorting is done with a converter
+# or without.
+# A returned hash reference is needed as some information is set in the
+# hash in perl afterwards, but this information is not used as the hash
+# is not used by any function not overriden, so there is no need to
+# return information corresponding to the text options for perl.  An empty
+# hash reference is therefore returned.
 SV *
-index_entry_element_sort_string (SV *document_in, SV *main_entry_sv, SV 
*element_sv, SV *options_sv, SV *prefer_reference_element_sv=0)
+setup_index_entry_keys_formatting (SV *customization_info_sv)
     PREINIT:
+        CONVERTER *self;
+        HV *hv;
+     CODE:
+        self = get_sv_converter (customization_info_sv, 0);
+        if (self)
+          {
+            TEXT_OPTIONS *text_options
+              = setup_converter_index_entry_keys_formatting (self);
+            self->convert_index_text_options = text_options;
+          }
+        else
+          {
+            DOCUMENT *document;
+            document = get_sv_document_document (customization_info_sv,
+                         "setup_index_entry_keys_formatting");
+            if (document && document->options)
+              {
+                TEXT_OPTIONS *text_options
+                 = setup_index_entry_keys_formatting (document->options);
+                register_document_convert_index_text_options (document,
+                                                           text_options);
+              }
+          }
+        hv = newHV ();
+        RETVAL = newRV_noinc ((SV *) hv);
+    OUTPUT:
+         RETVAL
+
+SV *
+index_entry_element_sort_string (SV *customization_info_sv, SV *main_entry_sv, 
SV *element_sv, SV *options_sv, SV *prefer_reference_element_sv=0)
+    PREINIT:
+        CONVERTER *self;
         DOCUMENT *document;
         char *sort_string = 0;
+        TEXT_OPTIONS *convert_index_text_options = 0;
      CODE:
-        document = get_sv_document_document (document_in,
-                   "index_entry_element_sort_string");
+        self = get_sv_converter (customization_info_sv, 0);
+        if (self)
+          {
+            document = self->document;
+            convert_index_text_options = self->convert_index_text_options;
+          }
+        else
+          {
+            document = get_sv_document_document (customization_info_sv,
+                     "index_entry_element_sort_string");
+            if (document)
+              convert_index_text_options
+                = document->convert_index_text_options;
+          }
         if (document)
           {
-            char *entry_index_name;
+            const INDEX *entry_idx = 0;
             int entry_number;
             int prefer_reference_element = 0;
+            int in_code;
+            int allocated_text_options = 0;
             ELEMENT *element = find_element_from_sv (0, document,
                                                     element_sv, 0);
             INDEX_ENTRY *main_entry = find_index_entry_sv (main_entry_sv,
                                           document->index_names, 0,
-                                          &entry_index_name, &entry_number);
-            TEXT_OPTIONS *options
-              = copy_sv_options_for_convert_text (options_sv);
+                                          &entry_idx, &entry_number);
+            in_code = entry_idx->in_code;
+
+            /* should not be possible */
+            if (!convert_index_text_options)
+              {
+                allocated_text_options = 1;
+                convert_index_text_options
+                  = copy_sv_options_for_convert_text (options_sv);
+              }
+
             if (prefer_reference_element_sv && SvOK 
(prefer_reference_element_sv))
               prefer_reference_element = SvIV (prefer_reference_element_sv);
+
             sort_string = index_entry_element_sort_string (main_entry,
-                                 element, options, prefer_reference_element);
-            destroy_text_options (options);
+                          element, convert_index_text_options, in_code,
+                          prefer_reference_element);
+            if (allocated_text_options)
+              destroy_text_options (convert_index_text_options);
           }
 
        if (!sort_string)
diff --git a/tp/t/test_sort.t b/tp/t/test_sort.t
index eef08d15c0..872120b0b0 100644
--- a/tp/t/test_sort.t
+++ b/tp/t/test_sort.t
@@ -51,6 +51,7 @@ my $main_configuration = 
Texinfo::MainConfig::new({'ENABLE_ENCODING' => 1});
 Texinfo::Common::set_output_encodings($main_configuration, 
$document_information);
 $main_configuration->{'document_descriptor'}
   = $document->document_descriptor();
+$main_configuration->register_XS_document_main_configuration($document);
 my ($sorted_index_entries, $index_entries_sort_strings)
   = Texinfo::Structuring::sort_indices_by_index($registrar, 
$main_configuration,
                                           $index_entries, 
$indices_information);
@@ -62,7 +63,7 @@ foreach my $entry (@{$sorted_index_entries->{'cp'}}) {
 
 use utf8;
 
-# e is before E because they are equal and e appears before E in the document 
+# e is before E because they are equal and e appears before E in the document
 my @entries_ref = ('!', '"', 'aaaaaaaaaaaa', 'e', 'E', 'ẽ', 'ł');
 
 cmp_deeply (\@entries, \@entries_ref, 'sorted index entries');
@@ -81,7 +82,7 @@ my @letter_entries_ref = (
    {'E' => [ 'e', 'E', 'ẽ' ]},
    {'Ł' => [ 'ł' ]},
 );
- 
+
 my @letter_entries;
 foreach my $letter (@{$sorted_index_entries_by_letter->{'cp'}}) {
   my $letter_entry = {};



reply via email to

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