[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Tue, 13 Feb 2024 17:51:47 -0500 (EST) |
branch: master
commit 219e37f90c003c938ad9a38d476a97a0466520aa
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Feb 13 23:51:39 2024 +0100
* tp/Texinfo/XS/main/document.c
(new_collation_sorted_indices_by_index)
(find_collation_sorted_indices_by_index, sorted_indices_by_index)
(destroy_document_information_except_tree),
tp/Texinfo/XS/main/document_types.h (INDEX_SORTED_BY_INDEX)
(COLLATION_INDICES_SORTED_BY_INDEX, COLLATIONS_INDICES_SORTED_BY_INDEX)
(DOCUMENT), tp/Texinfo/XS/main/manipulate_indices.c
(destroy_indices_sorted_by_index, compare_sortable_index_entry)
(sort_indices_by_index): implement index sorting by index. Separate
compare_sortable_index_entry and functions called from qsort,
compare_sortable_index_entry_refs and
compare_sortable_index_entry_wrapper.
* tp/Texinfo/XS/main/document.c
(new_collation_sorted_indices_by_letter)
(find_collation_sorted_indices_by_letter):
Rename new_collation_sorted_indices and find_collation_sorted_indices
to avoid ambiguity.
* tp/Texinfo/Convert/Converter.pm (%XS_overrides),
tp/Texinfo/XS/convert/ConvertXS.xs
(get_converter_indices_sorted_by_index),
tp/Texinfo/XS/convert/converter.c
(get_converter_indices_sorted_by_index),
tp/Texinfo/XS/main/build_perl_info.c (build_sorted_indices_by_index):
XS interface for sorted_indices_by_index through
get_converter_indices_sorted_by_index.
---
ChangeLog | 30 +++++++
tp/Texinfo/Convert/Converter.pm | 6 +-
tp/Texinfo/XS/convert/ConvertXS.xs | 41 +++++++++
tp/Texinfo/XS/convert/converter.c | 21 +++++
tp/Texinfo/XS/convert/converter.h | 1 +
tp/Texinfo/XS/main/build_perl_info.c | 48 +++++++++++
tp/Texinfo/XS/main/build_perl_info.h | 3 +
tp/Texinfo/XS/main/document.c | 146 ++++++++++++++++++++++++++++++--
tp/Texinfo/XS/main/document.h | 7 ++
tp/Texinfo/XS/main/document_types.h | 19 +++++
tp/Texinfo/XS/main/manipulate_indices.c | 118 ++++++++++++++++++++++++--
tp/Texinfo/XS/main/manipulate_indices.h | 10 +++
12 files changed, 434 insertions(+), 16 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fe4c8e13a9..f438217d98 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2024-02-13 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/main/document.c
+ (new_collation_sorted_indices_by_index)
+ (find_collation_sorted_indices_by_index, sorted_indices_by_index)
+ (destroy_document_information_except_tree),
+ tp/Texinfo/XS/main/document_types.h (INDEX_SORTED_BY_INDEX)
+ (COLLATION_INDICES_SORTED_BY_INDEX, COLLATIONS_INDICES_SORTED_BY_INDEX)
+ (DOCUMENT), tp/Texinfo/XS/main/manipulate_indices.c
+ (destroy_indices_sorted_by_index, compare_sortable_index_entry)
+ (sort_indices_by_index): implement index sorting by index. Separate
+ compare_sortable_index_entry and functions called from qsort,
+ compare_sortable_index_entry_refs and
+ compare_sortable_index_entry_wrapper.
+
+ * tp/Texinfo/XS/main/document.c
+ (new_collation_sorted_indices_by_letter)
+ (find_collation_sorted_indices_by_letter):
+ Rename new_collation_sorted_indices and find_collation_sorted_indices
+ to avoid ambiguity.
+
+ * tp/Texinfo/Convert/Converter.pm (%XS_overrides),
+ tp/Texinfo/XS/convert/ConvertXS.xs
+ (get_converter_indices_sorted_by_index),
+ tp/Texinfo/XS/convert/converter.c
+ (get_converter_indices_sorted_by_index),
+ tp/Texinfo/XS/main/build_perl_info.c (build_sorted_indices_by_index):
+ XS interface for sorted_indices_by_index through
+ get_converter_indices_sorted_by_index.
+
2024-02-13 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/convert/convert_html.c (html_reset_converter),
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 15267fa16e..4303d90cec 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -96,8 +96,6 @@ my %XS_overrides = (
=> "Texinfo::Convert::ConvertXS::get_conf",
"Texinfo::Convert::Converter::_XS_set_document"
=> "Texinfo::Convert::ConvertXS::converter_set_document",
- "Texinfo::Convert::Converter::get_converter_indices_sorted_by_letter"
- => "Texinfo::Convert::ConvertXS::get_converter_indices_sorted_by_letter",
# fully overriden for all the converters
"Texinfo::Convert::Converter::get_converter_errors"
@@ -110,6 +108,10 @@ my %XS_overrides = (
=> "Texinfo::Convert::ConvertXS::converter_document_error",
"Texinfo::Convert::Converter::converter_document_warn"
=> "Texinfo::Convert::ConvertXS::converter_document_warn",
+ "Texinfo::Convert::Converter::get_converter_indices_sorted_by_letter"
+ => "Texinfo::Convert::ConvertXS::get_converter_indices_sorted_by_letter",
+ "Texinfo::Convert::Converter::get_converter_indices_sorted_by_index"
+ => "Texinfo::Convert::ConvertXS::get_converter_indices_sorted_by_index",
# XS only
"Texinfo::Convert::Converter::reset_converter"
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index e0e6073040..03992db51c 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -180,6 +180,47 @@ converter_document_warn (SV *converter_in, text, ...)
self->conf, MSG_document_warning, continuation, strdup
(text));
}
+SV *
+get_converter_indices_sorted_by_index (SV *converter_sv)
+ PREINIT:
+ CONVERTER *self;
+ INDEX_SORTED_BY_INDEX *index_entries_by_index = 0;
+ HV *converter_hv;
+ SV **document_sv;
+ CODE:
+ self = get_sv_converter (converter_sv,
+ "get_converter_indices_sorted_by_index");
+ if (self)
+ index_entries_by_index
+ = get_converter_indices_sorted_by_index (self);
+
+ converter_hv = (HV *) SvRV (converter_sv);
+ document_sv = hv_fetch (converter_hv, "document",
+ strlen ("document"), 0);
+ RETVAL = 0;
+ if (document_sv)
+ {
+ SV **indices_information_sv;
+ HV *document_hv = (HV *) SvRV (*document_sv);
+ indices_information_sv
+ = hv_fetch (document_hv, "indices", strlen ("indices"), 0);
+
+ if (index_entries_by_index && indices_information_sv)
+ {
+ HV *indices_information_hv
+ = (HV *) SvRV (*indices_information_sv);
+ HV *index_entries_by_index_hv
+ = build_sorted_indices_by_index (index_entries_by_index,
+ indices_information_hv);
+ RETVAL
+ = newRV_inc ((SV *) index_entries_by_index_hv);
+ }
+ }
+ if (!RETVAL)
+ RETVAL = newSV (0);
+ OUTPUT:
+ RETVAL
+
SV *
get_converter_indices_sorted_by_letter (SV *converter_sv)
PREINIT:
diff --git a/tp/Texinfo/XS/convert/converter.c
b/tp/Texinfo/XS/convert/converter.c
index 45dcfd3686..ded7317d85 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -637,6 +637,27 @@ free_comma_index_subentries_tree (ELEMENT_LIST
*element_list)
destroy_list (element_list);
}
+INDEX_SORTED_BY_INDEX *
+get_converter_indices_sorted_by_index (CONVERTER *self)
+{
+ if (self->document)
+ {
+ char *collation_language = 0;
+ if (self->conf->COLLATION_LANGUAGE.string)
+ collation_language = self->conf->COLLATION_LANGUAGE.string;
+ else if (self->conf->DOCUMENTLANGUAGE_COLLATION.integer > 0
+ && self->conf->documentlanguage.string)
+ collation_language = self->conf->documentlanguage.string;
+
+ return sorted_indices_by_index (&self->error_messages, self->conf,
+ self->document,
+ self->conf->USE_UNICODE_COLLATION.integer,
+ collation_language,
+ self->conf->XS_STRXFRM_COLLATION_LOCALE.string);
+ }
+ return 0;
+}
+
INDEX_SORTED_BY_LETTER *
get_converter_indices_sorted_by_letter (CONVERTER *self)
{
diff --git a/tp/Texinfo/XS/convert/converter.h
b/tp/Texinfo/XS/convert/converter.h
index 66915297e8..d8552474f1 100644
--- a/tp/Texinfo/XS/convert/converter.h
+++ b/tp/Texinfo/XS/convert/converter.h
@@ -114,6 +114,7 @@ ELEMENT_LIST *comma_index_subentries_tree (const ELEMENT
*current_entry,
char *separator);
void free_comma_index_subentries_tree (ELEMENT_LIST *element);
+INDEX_SORTED_BY_INDEX *get_converter_indices_sorted_by_index (CONVERTER *self);
INDEX_SORTED_BY_LETTER *get_converter_indices_sorted_by_letter
(CONVERTER *self);
diff --git a/tp/Texinfo/XS/main/build_perl_info.c
b/tp/Texinfo/XS/main/build_perl_info.c
index 9a2acf0120..4853940a58 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -2079,6 +2079,54 @@ build_indices_sort_strings (const INDICES_SORT_STRINGS
*indices_sort_strings,
return indices_sort_strings_hv;
}
+HV *
+build_sorted_indices_by_index (
+ const INDEX_SORTED_BY_INDEX *index_entries_by_index,
+ HV *indices_information_hv)
+{
+ HV *indices_hv;
+ const INDEX_SORTED_BY_INDEX *idx;
+
+ dTHX;
+
+ if (!index_entries_by_index)
+ return 0;
+
+ indices_hv = newHV ();
+
+ for (idx = index_entries_by_index; idx->name; idx++)
+ {
+ AV *entries_av = newAV ();
+ size_t j;
+
+ hv_store (indices_hv, idx->name, strlen (idx->name),
+ newRV_noinc ((SV *)entries_av), 0);
+
+ for (j = 0; j < idx->entries_number; j++)
+ {
+ INDEX_ENTRY *entry = idx->entries[j];
+ char *index_name = entry->index_name;
+ int entry_number = entry->number;
+ char *message;
+ SV *index_entry_sv;
+ xasprintf (&message, "BUG: build_sorted_indices_by_index:"
+ " %s: entry %zu", idx->name, j);
+ index_entry_sv
+ = find_idx_name_entry_number_sv (indices_information_hv,
+ index_name, entry_number,
+ message);
+ free (message);
+
+ if (index_entry_sv)
+ {
+ SvREFCNT_inc (index_entry_sv);
+ av_push (entries_av, index_entry_sv);
+ }
+ }
+ }
+ return indices_hv;
+}
+
HV *
build_sorted_indices_by_letter (
const INDEX_SORTED_BY_LETTER *index_entries_by_letter,
diff --git a/tp/Texinfo/XS/main/build_perl_info.h
b/tp/Texinfo/XS/main/build_perl_info.h
index e9416e8f79..5410668a5e 100644
--- a/tp/Texinfo/XS/main/build_perl_info.h
+++ b/tp/Texinfo/XS/main/build_perl_info.h
@@ -59,6 +59,9 @@ HV *build_indices_sort_strings (
HV *build_sorted_indices_by_letter (
const INDEX_SORTED_BY_LETTER *index_entries_by_letter,
HV *indices_information_hv);
+HV *build_sorted_indices_by_index (
+ const INDEX_SORTED_BY_INDEX *index_entries_by_index,
+ HV *indices_information_hv);
SV *html_build_direction_icons (CONVERTER *converter,
DIRECTION_ICON_LIST *direction_icons);
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index c03b35ba19..6947f2dd00 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -176,8 +176,121 @@ document_indices_sort_strings (DOCUMENT *document,
return document->indices_sort_strings;
}
+static COLLATION_INDICES_SORTED_BY_INDEX *
+new_collation_sorted_indices_by_index (
+ COLLATIONS_INDICES_SORTED_BY_INDEX *collations,
+ enum collation_type_name type,
+ const char *language)
+{
+ COLLATION_INDICES_SORTED_BY_INDEX *result = 0;
+ if (collations->number <= collations->space)
+ {
+ collations->collation_sorted_indices
+ = (COLLATION_INDICES_SORTED_BY_INDEX *) realloc
+ (collations->collation_sorted_indices,
+ (collations->space += 3)
+ * sizeof (COLLATION_INDICES_SORTED_BY_INDEX));
+ if (!collations->collation_sorted_indices)
+ fatal ("realloc failed");
+ }
+
+ result = &collations->collation_sorted_indices[collations->number];
+ memset (result, 0, sizeof (COLLATION_INDICES_SORTED_BY_INDEX));
+ result->type = type;
+ result->language = strdup (language);
+
+ collations->number++;
+
+ return result;
+}
+
+COLLATION_INDICES_SORTED_BY_INDEX *
+find_collation_sorted_indices_by_index (
+ COLLATIONS_INDICES_SORTED_BY_INDEX *collations,
+ enum collation_type_name type,
+ const char *language)
+{
+ size_t i;
+ for (i = 2; i < collations->number; i++)
+ {
+ COLLATION_INDICES_SORTED_BY_INDEX *collation_sorted_indices
+ = &collations->collation_sorted_indices[i];
+ if (collation_sorted_indices->type == type
+ && !strcmp (collation_sorted_indices->language, language))
+ return collation_sorted_indices;
+ }
+ return 0;
+}
+
+INDEX_SORTED_BY_INDEX *
+sorted_indices_by_index (ERROR_MESSAGE_LIST *error_messages,
+ OPTIONS *options, DOCUMENT *document,
+ int use_unicode_collation,
+ const char *collation_language,
+ const char *collation_locale)
+{
+ COLLATIONS_INDICES_SORTED_BY_INDEX *collations;
+ COLLATION_INDICES_SORTED_BY_INDEX *collation_sorted_indices = 0;
+ if (!document->sorted_indices_by_index)
+ {
+ collations
+ = (COLLATIONS_INDICES_SORTED_BY_INDEX *)
+ malloc (sizeof (COLLATIONS_INDICES_SORTED_BY_INDEX));
+ memset (collations, 0,
+ sizeof (COLLATIONS_INDICES_SORTED_BY_INDEX));
+
+ /* order is important, to match enum */
+ new_collation_sorted_indices_by_index (collations, ctn_unicode, "-");
+ new_collation_sorted_indices_by_index (collations, ctn_no_unicode, "");
+
+ document->sorted_indices_by_index = collations;
+ }
+
+ collations = document->sorted_indices_by_index;
+
+ if (use_unicode_collation == 0)
+ collation_sorted_indices
+ = &collations->collation_sorted_indices[ctn_no_unicode];
+ else if (!collation_language && !collation_locale)
+ collation_sorted_indices
+ = &collations->collation_sorted_indices[ctn_unicode];
+ else
+ {
+ enum collation_type_name type;
+ const char *language;
+ if (collation_language)
+ {
+ type = ctn_language_collation;
+ language = collation_language;
+ }
+ else
+ {
+ type = ctn_locale_collation;
+ language = collation_locale;
+ }
+ collation_sorted_indices
+ = find_collation_sorted_indices_by_index (collations, type, language);
+ if (!collation_sorted_indices)
+ collation_sorted_indices
+ = new_collation_sorted_indices_by_index (collations,
+ type, language);
+ }
+
+ if (!collation_sorted_indices->sorted_indices)
+ {
+ const MERGED_INDICES *merged_indices
+ = document_merged_indices (document);
+ collation_sorted_indices->sorted_indices
+ = sort_indices_by_index (error_messages, options,
+ use_unicode_collation, collation_language,
+ collation_locale, merged_indices,
+ document->index_names, document);
+ }
+ return collation_sorted_indices->sorted_indices;
+}
+
static COLLATION_INDICES_SORTED_BY_LETTER *
-new_collation_sorted_indices (
+new_collation_sorted_indices_by_letter (
COLLATIONS_INDICES_SORTED_BY_LETTER *collations,
enum collation_type_name type,
const char *language)
@@ -205,7 +318,7 @@ new_collation_sorted_indices (
}
COLLATION_INDICES_SORTED_BY_LETTER *
-find_collation_sorted_indices (
+find_collation_sorted_indices_by_letter (
COLLATIONS_INDICES_SORTED_BY_LETTER *collations,
enum collation_type_name type,
const char *language)
@@ -240,8 +353,8 @@ sorted_indices_by_letter (ERROR_MESSAGE_LIST
*error_messages,
sizeof (COLLATIONS_INDICES_SORTED_BY_LETTER));
/* order is important, to match enum */
- new_collation_sorted_indices (collations, ctn_unicode, "-");
- new_collation_sorted_indices (collations, ctn_no_unicode, "");
+ new_collation_sorted_indices_by_letter (collations, ctn_unicode, "-");
+ new_collation_sorted_indices_by_letter (collations, ctn_no_unicode, "");
document->sorted_indices_by_letter = collations;
}
@@ -269,10 +382,11 @@ sorted_indices_by_letter (ERROR_MESSAGE_LIST
*error_messages,
language = collation_locale;
}
collation_sorted_indices
- = find_collation_sorted_indices (collations, type, language);
+ = find_collation_sorted_indices_by_letter (collations, type, language);
if (!collation_sorted_indices)
- collation_sorted_indices = new_collation_sorted_indices (collations,
- type, language);
+ collation_sorted_indices
+ = new_collation_sorted_indices_by_letter (collations,
+ type, language);
}
if (!collation_sorted_indices->sorted_indices)
@@ -324,6 +438,24 @@ destroy_document_information_except_tree (DOCUMENT
*document)
destroy_merged_indices (document->merged_indices);
if (document->indices_sort_strings)
destroy_index_entries_sort_strings (document->indices_sort_strings);
+ if (document->sorted_indices_by_index)
+ {
+ if (document->sorted_indices_by_index->number > 0)
+ {
+ size_t i;
+ for (i = 0; i < document->sorted_indices_by_index->number; i++)
+ {
+ COLLATION_INDICES_SORTED_BY_INDEX *collation_sorted_indices
+ = &document->sorted_indices_by_index->collation_sorted_indices[i];
+ free (collation_sorted_indices->language);
+ if (collation_sorted_indices->sorted_indices)
+ destroy_indices_sorted_by_index (
+ collation_sorted_indices->sorted_indices);
+ }
+ }
+ free (document->sorted_indices_by_index->collation_sorted_indices);
+ free (document->sorted_indices_by_index);
+ }
if (document->sorted_indices_by_letter)
{
if (document->sorted_indices_by_letter->number > 0)
diff --git a/tp/Texinfo/XS/main/document.h b/tp/Texinfo/XS/main/document.h
index 709d92c0be..38f57c913b 100644
--- a/tp/Texinfo/XS/main/document.h
+++ b/tp/Texinfo/XS/main/document.h
@@ -35,6 +35,13 @@ const INDICES_SORT_STRINGS *document_indices_sort_strings (
DOCUMENT *document,
ERROR_MESSAGE_LIST *error_messages,
OPTIONS *options, int prefer_reference_element);
+
+INDEX_SORTED_BY_INDEX *sorted_indices_by_index (
+ ERROR_MESSAGE_LIST *error_messages,
+ OPTIONS *options, DOCUMENT *document,
+ int use_unicode_collation,
+ const char *collation_language,
+ const char *collation_locale);
INDEX_SORTED_BY_LETTER *sorted_indices_by_letter (
ERROR_MESSAGE_LIST *error_messages,
OPTIONS *options, DOCUMENT *document,
diff --git a/tp/Texinfo/XS/main/document_types.h
b/tp/Texinfo/XS/main/document_types.h
index 7cd1c2ff4b..96d95208ea 100644
--- a/tp/Texinfo/XS/main/document_types.h
+++ b/tp/Texinfo/XS/main/document_types.h
@@ -108,6 +108,12 @@ typedef struct INDICES_SORT_STRINGS {
INDEX_SORT_STRINGS *indices;
} INDICES_SORT_STRINGS;
+typedef struct INDEX_SORTED_BY_INDEX {
+ char *name;
+ INDEX_ENTRY **entries;
+ size_t entries_number;
+} INDEX_SORTED_BY_INDEX;
+
typedef struct LETTER_INDEX_ENTRIES {
char *letter;
INDEX_ENTRY **entries;
@@ -127,6 +133,18 @@ enum collation_type_name {
ctn_locale_collation, /* experimental, to test strxfrm */
};
+typedef struct COLLATION_INDICES_SORTED_BY_INDEX {
+ enum collation_type_name type;
+ char *language;
+ INDEX_SORTED_BY_INDEX *sorted_indices;
+} COLLATION_INDICES_SORTED_BY_INDEX;
+
+typedef struct COLLATIONS_INDICES_SORTED_BY_INDEX {
+ size_t number;
+ size_t space;
+ COLLATION_INDICES_SORTED_BY_INDEX *collation_sorted_indices;
+} COLLATIONS_INDICES_SORTED_BY_INDEX;
+
typedef struct COLLATION_INDICES_SORTED_BY_LETTER {
enum collation_type_name type;
char *language;
@@ -159,6 +177,7 @@ typedef struct DOCUMENT {
struct TEXT_OPTIONS *convert_index_text_options; /* for index
sorting without converter */
INDICES_SORT_STRINGS *indices_sort_strings;
+ COLLATIONS_INDICES_SORTED_BY_INDEX *sorted_indices_by_index;
COLLATIONS_INDICES_SORTED_BY_LETTER *sorted_indices_by_letter;
} DOCUMENT;
diff --git a/tp/Texinfo/XS/main/manipulate_indices.c
b/tp/Texinfo/XS/main/manipulate_indices.c
index e719b9f18f..c487067553 100644
--- a/tp/Texinfo/XS/main/manipulate_indices.c
+++ b/tp/Texinfo/XS/main/manipulate_indices.c
@@ -138,6 +138,20 @@ destroy_merged_indices (MERGED_INDICES *merged_indices)
+void
+destroy_indices_sorted_by_index (
+ INDEX_SORTED_BY_INDEX *indices_entries_by_index)
+{
+ INDEX_SORTED_BY_INDEX *index;
+
+ for (index = indices_entries_by_index; index->name; index++)
+ {
+ free (index->name);
+ free (index->entries);
+ }
+ free (indices_entries_by_index);
+}
+
void
destroy_indices_sorted_by_letter (
INDEX_SORTED_BY_LETTER *indices_entries_by_letter)
@@ -757,13 +771,9 @@ compare_sortable_subentry_keys (const void *a, const void
*b)
}
static int
-compare_sortable_index_entry (const void *a, const void *b)
+compare_sortable_index_entry (const SORTABLE_INDEX_ENTRY *sie_a,
+ const SORTABLE_INDEX_ENTRY *sie_b)
{
- const SORTABLE_INDEX_ENTRY **psie_a = (const SORTABLE_INDEX_ENTRY **) a;
- const SORTABLE_INDEX_ENTRY **psie_b = (const SORTABLE_INDEX_ENTRY **) b;
- const SORTABLE_INDEX_ENTRY *sie_a = *psie_a;
- const SORTABLE_INDEX_ENTRY *sie_b = *psie_b;
-
size_t i;
int res;
@@ -799,6 +809,24 @@ compare_sortable_index_entry (const void *a, const void *b)
return strcmp (sie_a->entry->index_name, sie_b->entry->index_name);
}
+static int
+compare_sortable_index_entry_refs (const void *a, const void *b)
+{
+ const SORTABLE_INDEX_ENTRY **psie_a = (const SORTABLE_INDEX_ENTRY **) a;
+ const SORTABLE_INDEX_ENTRY **psie_b = (const SORTABLE_INDEX_ENTRY **) b;
+
+ return compare_sortable_index_entry (*psie_a, *psie_b);
+}
+
+static int
+compare_sortable_index_entry_wrapper (const void *a, const void *b)
+{
+ const SORTABLE_INDEX_ENTRY *sie_a = (const SORTABLE_INDEX_ENTRY *) a;
+ const SORTABLE_INDEX_ENTRY *sie_b = (const SORTABLE_INDEX_ENTRY *) b;
+
+ return compare_sortable_index_entry (sie_a, sie_b);
+}
+
void
destroy_indices_sortable_entries (
INDICES_SORTABLE_ENTRIES *indices_sortable_entries)
@@ -847,6 +875,82 @@ destroy_collator (INDEX_COLLATOR *collator)
free (collator);
}
+INDEX_SORTED_BY_INDEX *
+sort_indices_by_index (ERROR_MESSAGE_LIST *error_messages,
+ OPTIONS *options, int use_unicode_collation,
+ const char *collation_language,
+ const char *collation_locale,
+ const MERGED_INDICES *merged_indices,
+ INDEX **indices_information, DOCUMENT *document)
+{
+ size_t i;
+ int index_nr = 0;
+ INDEX_COLLATOR *collator;
+
+ INDICES_SORTABLE_ENTRIES *indices_sortable_entries
+ = setup_sort_sortable_strings_collator (error_messages, options,
+ use_unicode_collation, collation_language,
+ collation_locale,
+ merged_indices, indices_information,
+ document, &collator);
+
+ if (!indices_sortable_entries || indices_sortable_entries->number <= 0)
+ {
+ destroy_indices_sortable_entries (indices_sortable_entries);
+ destroy_collator (collator);
+ return 0;
+ }
+
+ INDEX_SORTED_BY_INDEX *sorted_index_entries
+ = (INDEX_SORTED_BY_INDEX *) malloc
+ ((indices_sortable_entries->number +1) * sizeof (INDEX_SORTED_BY_INDEX));
+
+ for (i = 0; i < indices_sortable_entries->number; i++)
+ {
+ size_t k;
+ INDEX_SORTABLE_ENTRIES *sortable_index_entries
+ = &indices_sortable_entries->indices[i];
+ INDEX_SORTED_BY_INDEX *index_sorted;
+
+ if (sortable_index_entries->number <= 0)
+ continue;
+
+ index_sorted = &sorted_index_entries[index_nr];
+ index_sorted->name = strdup (sortable_index_entries->index->name);
+ index_sorted->entries_number = sortable_index_entries->number;
+
+ /* directly sort the sortable entries */
+ qsort (sortable_index_entries->sortable_entries,
+ index_sorted->entries_number,
+ sizeof (SORTABLE_INDEX_ENTRY),
+ compare_sortable_index_entry_wrapper);
+
+ index_sorted->entries = (INDEX_ENTRY **) malloc
+ (sizeof (INDEX_ENTRY *) * index_sorted->entries_number);
+
+ /* set index entries in the sorted order */
+ for (k = 0; k < index_sorted->entries_number; k++)
+ {
+ index_sorted->entries[k]
+ = sortable_index_entries->sortable_entries[k].entry;
+ }
+
+ index_nr++;
+ }
+
+ memset (&sorted_index_entries[index_nr], 0, sizeof (INDEX_SORTED_BY_INDEX));
+ if (index_nr < indices_sortable_entries->number)
+ sorted_index_entries = realloc (sorted_index_entries,
+ (index_nr+1) * sizeof (INDEX_SORTED_BY_INDEX));
+
+ destroy_collator (collator);
+ destroy_indices_sortable_entries (indices_sortable_entries);
+
+ return sorted_index_entries;
+}
+
+
+
INDEX_SORTED_BY_LETTER *
sort_indices_by_letter (ERROR_MESSAGE_LIST *error_messages,
OPTIONS *options, int use_unicode_collation,
@@ -1069,7 +1173,7 @@ sort_indices_by_letter (ERROR_MESSAGE_LIST
*error_messages,
qsort (letter_sortable_entries->sortable_entries,
letter_sortable_entries->number,
sizeof (SORTABLE_INDEX_ENTRY *),
- compare_sortable_index_entry);
+ compare_sortable_index_entry_refs);
letter_index_entries->letter = letter_sortable_entries->letter;
letter_index_entries->entries = (INDEX_ENTRY **) malloc
diff --git a/tp/Texinfo/XS/main/manipulate_indices.h
b/tp/Texinfo/XS/main/manipulate_indices.h
index 80d748c7f7..4f9934d5a7 100644
--- a/tp/Texinfo/XS/main/manipulate_indices.h
+++ b/tp/Texinfo/XS/main/manipulate_indices.h
@@ -40,6 +40,8 @@ typedef struct INDEX_ENTRY_TEXT_OR_COMMAND {
MERGED_INDICES *merge_indices (INDEX **index_names);
void destroy_merged_indices (MERGED_INDICES *merged_indices);
+void destroy_indices_sorted_by_index (
+ INDEX_SORTED_BY_INDEX *indices_entries_by_index);
void destroy_indices_sorted_by_letter (
INDEX_SORTED_BY_LETTER *indices_entries_by_letter);
@@ -57,6 +59,14 @@ INDICES_SORT_STRINGS *setup_index_entries_sort_strings (
OPTIONS *options, const MERGED_INDICES *merged_indices,
INDEX **indices_information, int prefer_reference_element);
+INDEX_SORTED_BY_INDEX *sort_indices_by_index (
+ ERROR_MESSAGE_LIST *error_messages,
+ OPTIONS *options, int use_unicode_collation,
+ const char *collation_language,
+ const char *collation_locale,
+ const MERGED_INDICES *merged_indices,
+ INDEX **indices_information, DOCUMENT *document);
+
INDEX_SORTED_BY_LETTER *sort_indices_by_letter (
ERROR_MESSAGE_LIST *error_messages,
OPTIONS *options, int use_unicode_collation,