blob: 959c6e156431121f9ba652c84ef9f8c475212167 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
Steve Kondikae271bc2015-11-15 02:50:53 +01002 * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05303 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
11 * *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
14 * *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
22 * *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
26 * authorization. *
27 ****************************************************************************/
28
29/****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 * and: Thomas E. Dickey 1996-on *
33 ****************************************************************************/
34
35/*
36 * comp_hash.c --- Routines to deal with the hashtable of capability
37 * names.
38 *
39 */
40
41#define USE_TERMLIB 1
42#include <curses.priv.h>
43
44#include <tic.h>
45#include <hashsize.h>
46
Steve Kondikae271bc2015-11-15 02:50:53 +010047MODULE_ID("$Id: comp_hash.c,v 1.48 2009/08/08 17:36:21 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053048
49/*
Steve Kondikae271bc2015-11-15 02:50:53 +010050 * Finds the entry for the given string in the hash table if present.
51 * Returns a pointer to the entry in the table or 0 if not found.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053052 */
Steve Kondikae271bc2015-11-15 02:50:53 +010053/* entrypoint used by tack (do not alter) */
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053054NCURSES_EXPORT(struct name_table_entry const *)
55_nc_find_entry(const char *string,
Steve Kondikae271bc2015-11-15 02:50:53 +010056 const HashValue * hash_table)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053057{
Steve Kondikae271bc2015-11-15 02:50:53 +010058 bool termcap = (hash_table != _nc_get_hash_table(FALSE));
59 const HashData *data = _nc_get_hash_info(termcap);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053060 int hashvalue;
61 struct name_table_entry const *ptr = 0;
62 struct name_table_entry const *real_table;
63
Steve Kondikae271bc2015-11-15 02:50:53 +010064 hashvalue = data->hash_of(string);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053065
Steve Kondikae271bc2015-11-15 02:50:53 +010066 if (data->table_data[hashvalue] >= 0) {
67
68 real_table = _nc_get_table(termcap);
69 ptr = real_table + data->table_data[hashvalue];
70 while (!data->compare_names(ptr->nte_name, string)) {
71 if (ptr->nte_link < 0) {
72 ptr = 0;
73 break;
74 }
75 ptr = real_table + (ptr->nte_link
76 + data->table_data[data->table_size]);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053077 }
78 }
79
80 return (ptr);
81}
82
83/*
Steve Kondikae271bc2015-11-15 02:50:53 +010084 * Finds the entry for the given name with the given type in the given table if
85 * present (as distinct from _nc_find_entry, which finds the last entry
86 * regardless of type).
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053087 *
Steve Kondikae271bc2015-11-15 02:50:53 +010088 * Returns a pointer to the entry in the table or 0 if not found.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053089 */
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053090NCURSES_EXPORT(struct name_table_entry const *)
91_nc_find_type_entry(const char *string,
92 int type,
Steve Kondikae271bc2015-11-15 02:50:53 +010093 bool termcap)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053094{
Steve Kondikae271bc2015-11-15 02:50:53 +010095 struct name_table_entry const *ptr = NULL;
96 const HashData *data = _nc_get_hash_info(termcap);
97 int hashvalue = data->hash_of(string);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053098
Steve Kondikae271bc2015-11-15 02:50:53 +010099 if (data->table_data[hashvalue] >= 0) {
100 const struct name_table_entry *const table = _nc_get_table(termcap);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530101
Steve Kondikae271bc2015-11-15 02:50:53 +0100102 ptr = table + data->table_data[hashvalue];
103 while (ptr->nte_type != type
104 || !data->compare_names(ptr->nte_name, string)) {
105 if (ptr->nte_link < 0) {
106 ptr = 0;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530107 break;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530108 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100109 ptr = table + (ptr->nte_link + data->table_data[data->table_size]);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530110 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530111 }
112
Steve Kondikae271bc2015-11-15 02:50:53 +0100113 return ptr;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530114}