summaryrefslogtreecommitdiff
path: root/libdb/db_lookup.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2022-09-19 18:32:03 +0100
committerColin Watson <cjwatson@debian.org>2022-09-19 18:32:03 +0100
commitbb0f7086ba4ce4503761737bf612088c03b6c495 (patch)
tree7b83df0f8d10f67d22c426dd97e487d94e76d350 /libdb/db_lookup.c
parent9ee5a17dea3b1c7e8d8f65d53a4f9b86f8156d99 (diff)
Maintain multi key references in sorted order
This is a step towards being able to reproduce the same database given the same manual page tree. * bootstrap.conf (gnulib_modules): Add stpcpy. * libdb/db_lookup.c (name_ext_equals): Remove static; add pure attribute. (name_ext_compare): New function. (list_extensions): Add entries in sorted order. * libdb/db_storage.h (name_ext_equals, name_ext_compare): Add prototypes. * libdb/db_store.c (make_extensions_reference): New function. (dbstore): When building or updating multi key references, maintain them in sorted order. * NEWS.md: Document this.
Diffstat (limited to 'libdb/db_lookup.c')
-rw-r--r--libdb/db_lookup.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/libdb/db_lookup.c b/libdb/db_lookup.c
index db062597..66541d83 100644
--- a/libdb/db_lookup.c
+++ b/libdb/db_lookup.c
@@ -230,12 +230,21 @@ void split_content (MYDBM_FILE dbf, char *cont_ptr, struct mandata *pinfo)
pinfo->addr = cont_ptr;
}
-static bool name_ext_equals (const void *elt1, const void *elt2)
+bool ATTRIBUTE_PURE name_ext_equals (const void *elt1, const void *elt2)
{
const struct name_ext *ref1 = elt1, *ref2 = elt2;
return STREQ (ref1->name, ref2->name) && STREQ (ref1->ext, ref2->ext);
}
+int ATTRIBUTE_PURE name_ext_compare (const void *elt1, const void *elt2)
+{
+ const struct name_ext *ref1 = elt1, *ref2 = elt2;
+ int name_cmp = strcmp (ref1->name, ref2->name);
+ if (name_cmp)
+ return name_cmp;
+ return strcmp (ref1->ext, ref2->ext);
+}
+
/* Extract all of the names/extensions associated with this key. Each case
* variant of a name will be returned separately.
*
@@ -260,7 +269,7 @@ gl_list_t list_extensions (char *data)
/* Don't copy these; they will point into the given string. */
name_ext->name = name;
name_ext->ext = ext;
- gl_list_add_last (list, name_ext);
+ gl_sortedlist_add (list, name_ext_compare, name_ext);
}
debug ("found %zu names/extensions\n", gl_list_size (list));