summaryrefslogtreecommitdiff
path: root/src/whatis.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2019-02-03 10:20:57 +0000
committerColin Watson <cjwatson@debian.org>2019-02-03 10:20:57 +0000
commit6e28f527ce5f349af4f172313300e68ca98d75e8 (patch)
treeb703908d0214eb874d415a2d660b740e560d91ad /src/whatis.c
parent816c0f8bfc8e8a82cdf3993ac4d0593cbd3a4eb9 (diff)
Replace hashtable with Gnulib containers
Since we're using Gnulib's container types anyway, we might as well reduce the maintenance burden of local code, especially since the result tends to be more concise. * bootstrap.conf (gnulib_modules): Add hash-map, hash-set, xmap, and xset. * lib/glcontainers.h (GL_MAP_FOREACH_START, GL_MAP_FOREACH_END): New macros. * lib/orderfiles.c (compare_physical_offsets, order_files): Convert physical_offsets from a hashtable to a gl_map. * libdb/db_btree.c (loop_check_hash): Rename to ... (loop_check): ... this. (btree_findkey): Convert loop_check from a hashtable to a gl_set. * libdb/db_gdbm.c (parent_sortkey_hash): Rename to ... (parent_keys: ... this. (struct sortkey, parent_sortkey_hashtable_free): Remove. (sortkey_hashtable_free): Rename to ... (datum_free): ... this. Adjust for gl_list's expected interface. (sortkey_compare): Rename to ... (datum_compare): ... this. Adjust for gl_list's expected interface. (datum_equals, datum_hash): New functions. (man_gdbm_firstkey, man_gdbm_nextkey, man_gdbm_close): Convert parent_keys from a hashtable to a gl_map, and convert its values from hashtables with manual linking to gl_lists using a hash for fast lookup by key. * src/check_mandirs.c (whatis_hash): Rename to ... (whatis_map): ... this. (struct whatis_hashent): Rename to ... (struct whatis): ... this. (whatis_hashtable_free): Rename to ... (whatis_free): ... this. Adjust for gl_map's expected interface. (test_manfile): Convert whatis_map from a hashtable to a gl_map. * src/globbing.c (struct dirent_hashent): Rename to ... (struct dirent_names): ... this. (dirent_hashtable_free): Rename to ... (dirent_names_free): ... this. Adjust for gl_map's expected interface. (dirent_hash): Rename to ... (dirent_map): ... this. (update_directory_cache): Convert dirent_map from a hashtable to a gl_map. * src/man.c (db_hash): Rename to ... (db_map): ... this. (db_hashtable_free): Remove. (try_db, main): Convert db_map from a hashtable to a gl_map. * src/mandb.c (process_manpath, tried_catdirs_free, purge_catdir, purge_catdirs, main): Convert tried_catdirs from a hashtable to a gl_map. * src/whatis.c (display, main): Convert display_seen from a hashtable to a gl_set. * lib/Makefile.am (libman_la_SOURCES): Remove hashtable.c and hashtable.h. * lib/README: Remove hashtable.*. * lib/hashtable.c, lib/hashtable.h: Remove.
Diffstat (limited to 'src/whatis.c')
-rw-r--r--src/whatis.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/whatis.c b/src/whatis.c
index 7c3bfb61..5d45ae46 100644
--- a/src/whatis.c
+++ b/src/whatis.c
@@ -57,7 +57,9 @@
#include "argp.h"
#include "dirname.h"
+#include "gl_hash_set.h"
#include "gl_list.h"
+#include "gl_xset.h"
#include "fnmatch.h"
#include "progname.h"
#include "xvasprintf.h"
@@ -70,7 +72,6 @@
#include "pipeline.h"
#include "pathsearch.h"
#include "linelength.h"
-#include "hashtable.h"
#include "lower.h"
#include "wordfnmatch.h"
#include "xregcomp.h"
@@ -114,7 +115,7 @@ static const char *alt_systems = "";
static const char *locale = NULL;
static char *multiple_locale = NULL, *internal_locale;
-static struct hashtable *display_seen = NULL;
+static gl_set_t display_seen = NULL;
const char *argp_program_version; /* initialised in main */
const char *argp_program_bug_address = PACKAGE_BUGREPORT;
@@ -454,9 +455,9 @@ static void display (MYDBM_FILE dbf, struct mandata *info, const char *page)
page_name = page;
key = xasprintf ("%s (%s)", page_name, newinfo->ext);
- if (hashtable_lookup_structure (display_seen, key, strlen (key)))
+ if (gl_set_search (display_seen, key))
goto out;
- hashtable_install (display_seen, key, strlen (key), NULL);
+ gl_set_add (display_seen, xstrdup (key));
line_len = get_line_length ();
@@ -968,7 +969,8 @@ int main (int argc, char *argv[])
manpathlist = create_pathlist (manp);
- display_seen = hashtable_create (&null_hashtable_free);
+ display_seen = gl_set_create_empty (GL_HASH_SET, string_equals,
+ string_hash, plain_free);
#ifdef HAVE_ICONV
locale_charset = xasprintf ("%s//IGNORE", get_locale_charset ());
@@ -998,7 +1000,7 @@ int main (int argc, char *argv[])
if (conv_to_locale != (iconv_t) -1)
iconv_close (conv_to_locale);
#endif /* HAVE_ICONV */
- hashtable_free (display_seen);
+ gl_set_free (display_seen);
free_pathlist (manpathlist);
free (manp);
free (internal_locale);