2 ##############################################################################
3 # Copyright 2019,2020 Thomas E. Dickey #
4 # Copyright 2007-2010,2011 Free Software Foundation, Inc. #
6 # Permission is hereby granted, free of charge, to any person obtaining a #
7 # copy of this software and associated documentation files (the "Software"), #
8 # to deal in the Software without restriction, including without limitation #
9 # the rights to use, copy, modify, merge, publish, distribute, distribute #
10 # with modifications, sublicense, and/or sell copies of the Software, and to #
11 # permit persons to whom the Software is furnished to do so, subject to the #
12 # following conditions: #
14 # The above copyright notice and this permission notice shall be included in #
15 # all copies or substantial portions of the Software. #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
20 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
23 # DEALINGS IN THE SOFTWARE. #
25 # Except as contained in this notice, the name(s) of the above copyright #
26 # holders shall not be used in advertising or otherwise to promote the sale, #
27 # use or other dealings in this Software without prior written #
29 ##############################################################################
30 # $Id: MKcaptab.sh,v 1.19 2020/02/02 23:34:34 tom Exp $
50 OPT2="tinfo/MKcaptab.awk"
62 * comp_captab.c -- The names of the capabilities indexed via a hash
63 * table for the compiler.
67 #include <curses.priv.h>
74 cat "$@" |./make_hash 1 info $OPT1
75 cat "$@" |./make_hash 3 cap $OPT1
77 cat "$@" |$AWK -f $OPT2 bigstrings=$OPT1 tablename=capalias
79 cat "$@" |$AWK -f $OPT2 bigstrings=$OPT1 tablename=infoalias
86 next_string(const char *strings, unsigned *offset)
88 *offset += (unsigned) strlen(strings + *offset) + 1;
91 static const struct name_table_entry *
92 _nc_build_names(struct name_table_entry **actual,
93 const name_table_data * source,
97 *actual = typeCalloc(struct name_table_entry, CAPTABSIZE);
101 for (n = 0; n < CAPTABSIZE; ++n) {
102 (*actual)[n].nte_name = strings + len;
103 (*actual)[n].nte_type = source[n].nte_type;
104 (*actual)[n].nte_index = source[n].nte_index;
105 (*actual)[n].nte_link = source[n].nte_link;
106 next_string(strings, &len);
113 #define add_alias(field) \\
114 if (source[n].field >= 0) { \\
115 (*actual)[n].field = strings + source[n].field; \\
118 static const struct alias *
119 _nc_build_alias(struct alias **actual,
120 const alias_table_data * source,
125 *actual = typeCalloc(struct alias, tablesize + 1);
128 for (n = 0; n < tablesize; ++n) {
138 #define build_names(root) _nc_build_names(&_nc_##root##_table, \\
139 root##_names_data, \\
141 #define build_alias(root) _nc_build_alias(&_nc_##root##alias_table, \\
144 SIZEOF(root##alias_data))
146 #define build_names(root) _nc_ ## root ## _table
147 #define build_alias(root) _nc_ ## root ## alias_table
150 NCURSES_EXPORT(const struct name_table_entry *)
151 _nc_get_table(bool termcap)
153 return termcap ? build_names(cap) : build_names(info);
156 /* entrypoint used by tack 1.07 */
157 NCURSES_EXPORT(const HashValue *)
158 _nc_get_hash_table(bool termcap)
160 return termcap ? _nc_cap_hash_table : _nc_info_hash_table;
163 NCURSES_EXPORT(const struct alias *)
164 _nc_get_alias_table(bool termcap)
166 return termcap ? build_alias(cap) : build_alias(info);
170 info_hash(const char *string)
174 DEBUG(9, ("hashing %s", string));
176 sum += (long) (UChar(*string) + (UChar(*(string + 1)) << 8));
180 DEBUG(9, ("sum is %ld", sum));
181 return (HashValue) (sum % HASHTABSIZE);
184 #define TCAP_LEN 2 /* only 1- or 2-character names are used */
187 tcap_hash(const char *string)
189 char temp[TCAP_LEN + 1];
193 temp[limit++] = *string++;
194 if (limit >= TCAP_LEN)
198 return info_hash(temp);
202 compare_tcap_names(const char *a, const char *b)
204 return !strncmp(a, b, (size_t) TCAP_LEN);
208 compare_info_names(const char *a, const char *b)
210 return !strcmp(a, b);
213 static const HashData hash_data[2] =
215 {HASHTABSIZE, _nc_info_hash_table, info_hash, compare_info_names},
216 {HASHTABSIZE, _nc_cap_hash_table, tcap_hash, compare_tcap_names}
219 NCURSES_EXPORT(const HashData *)
220 _nc_get_hash_info(bool termcap)
222 return &hash_data[(termcap != FALSE)];
227 _nc_comp_captab_leaks(void)
230 FreeIfNeeded(_nc_cap_table);
231 FreeIfNeeded(_nc_info_table);
232 FreeIfNeeded(_nc_capalias_table);
233 FreeIfNeeded(_nc_infoalias_table);
236 #endif /* NO_LEAKS */