X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fcomp_hash.c;h=80755f22052cbce5abe4f809b9b8791c99396a05;hp=959c6e156431121f9ba652c84ef9f8c475212167;hb=312665d3aaaf5d8e3ba34d80fdd650abf758272a;hpb=d27c5b45ccee25dd4cfc8000d0f96b96c20ec6cf diff --git a/ncurses/tinfo/comp_hash.c b/ncurses/tinfo/comp_hash.c index 959c6e15..80755f22 100644 --- a/ncurses/tinfo/comp_hash.c +++ b/ncurses/tinfo/comp_hash.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. * + * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 1998-2008,2009 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -44,13 +45,13 @@ #include #include -MODULE_ID("$Id: comp_hash.c,v 1.48 2009/08/08 17:36:21 tom Exp $") +MODULE_ID("$Id: comp_hash.c,v 1.53 2020/02/02 23:34:34 tom Exp $") /* * Finds the entry for the given string in the hash table if present. * Returns a pointer to the entry in the table or 0 if not found. */ -/* entrypoint used by tack (do not alter) */ +/* entrypoint used by tack 1.07 */ NCURSES_EXPORT(struct name_table_entry const *) _nc_find_entry(const char *string, const HashValue * hash_table) @@ -63,7 +64,9 @@ _nc_find_entry(const char *string, hashvalue = data->hash_of(string); - if (data->table_data[hashvalue] >= 0) { + if (hashvalue >= 0 + && (unsigned) hashvalue < data->table_size + && data->table_data[hashvalue] >= 0) { real_table = _nc_get_table(termcap); ptr = real_table + data->table_data[hashvalue]; @@ -96,7 +99,9 @@ _nc_find_type_entry(const char *string, const HashData *data = _nc_get_hash_info(termcap); int hashvalue = data->hash_of(string); - if (data->table_data[hashvalue] >= 0) { + if (hashvalue >= 0 + && (unsigned) hashvalue < data->table_size + && data->table_data[hashvalue] >= 0) { const struct name_table_entry *const table = _nc_get_table(termcap); ptr = table + data->table_data[hashvalue]; @@ -112,3 +117,34 @@ _nc_find_type_entry(const char *string, return ptr; } + +#if NCURSES_XNAMES +NCURSES_EXPORT(struct user_table_entry const *) +_nc_find_user_entry(const char *string) +{ + const HashData *data = _nc_get_hash_user(); + int hashvalue; + struct user_table_entry const *ptr = 0; + struct user_table_entry const *real_table; + + hashvalue = data->hash_of(string); + + if (hashvalue >= 0 + && (unsigned) hashvalue < data->table_size + && data->table_data[hashvalue] >= 0) { + + real_table = _nc_get_userdefs_table(); + ptr = real_table + data->table_data[hashvalue]; + while (!data->compare_names(ptr->ute_name, string)) { + if (ptr->ute_link < 0) { + ptr = 0; + break; + } + ptr = real_table + (ptr->ute_link + + data->table_data[data->table_size]); + } + } + + return (ptr); +} +#endif /* NCURSES_XNAMES */