2 ##############################################################################
3 # Copyright (c) 2007-2011,2019 Free Software Foundation, Inc. #
5 # Permission is hereby granted, free of charge, to any person obtaining a #
6 # copy of this software and associated documentation files (the "Software"), #
7 # to deal in the Software without restriction, including without limitation #
8 # the rights to use, copy, modify, merge, publish, distribute, distribute #
9 # with modifications, sublicense, and/or sell copies of the Software, and to #
10 # permit persons to whom the Software is furnished to do so, subject to the #
11 # following conditions: #
13 # The above copyright notice and this permission notice shall be included in #
14 # all copies or substantial portions of the Software. #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
19 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
22 # DEALINGS IN THE SOFTWARE. #
24 # Except as contained in this notice, the name(s) of the above copyright #
25 # holders shall not be used in advertising or otherwise to promote the sale, #
26 # use or other dealings in this Software without prior written #
28 ##############################################################################
29 # $Id: MKcaptab.sh,v 1.15 2019/04/06 21:53:49 tom Exp $
49 OPT2="tinfo/MKcaptab.awk"
61 * comp_captab.c -- The names of the capabilities indexed via a hash
62 * table for the compiler.
66 #include <curses.priv.h>
72 cat "$@" |./make_hash 1 info $OPT1
73 cat "$@" |./make_hash 3 cap $OPT1
75 cat "$@" |$AWK -f $OPT2 bigstrings=$OPT1 tablename=capalias
77 cat "$@" |$AWK -f $OPT2 bigstrings=$OPT1 tablename=infoalias
83 next_string(const char *strings, unsigned *offset)
85 *offset += (unsigned) strlen(strings + *offset) + 1;
88 static const struct name_table_entry *
89 _nc_build_names(struct name_table_entry **actual,
90 const name_table_data *source,
94 *actual = typeCalloc(struct name_table_entry, CAPTABSIZE);
98 for (n = 0; n < CAPTABSIZE; ++n) {
99 (*actual)[n].nte_name = strings + len;
100 (*actual)[n].nte_type = source[n].nte_type;
101 (*actual)[n].nte_index = source[n].nte_index;
102 (*actual)[n].nte_link = source[n].nte_link;
103 next_string(strings, &len);
110 #define add_alias(field) \\
111 if (source[n].field >= 0) { \\
112 (*actual)[n].field = strings + source[n].field; \\
115 static const struct alias *
116 _nc_build_alias(struct alias **actual,
117 const alias_table_data *source,
122 *actual = typeCalloc(struct alias, tablesize + 1);
125 for (n = 0; n < tablesize; ++n) {
135 #define build_names(root) _nc_build_names(&_nc_##root##_table, \\
136 root##_names_data, \\
138 #define build_alias(root) _nc_build_alias(&_nc_##root##alias_table, \\
141 SIZEOF(root##alias_data))
143 #define build_names(root) _nc_ ## root ## _table
144 #define build_alias(root) _nc_ ## root ## alias_table
147 NCURSES_EXPORT(const struct name_table_entry *) _nc_get_table (bool termcap)
149 return termcap ? build_names(cap) : build_names(info) ;
152 /* entrypoint used by tack (do not alter) */
153 NCURSES_EXPORT(const HashValue *) _nc_get_hash_table (bool termcap)
155 return termcap ? _nc_cap_hash_table: _nc_info_hash_table ;
158 NCURSES_EXPORT(const struct alias *) _nc_get_alias_table (bool termcap)
160 return termcap ? build_alias(cap) : build_alias(info) ;
164 info_hash(const char *string)
168 DEBUG(9, ("hashing %s", string));
170 sum += (long) (*string + (*(string + 1) << 8));
174 DEBUG(9, ("sum is %ld", sum));
175 return (HashValue) (sum % HASHTABSIZE);
178 #define TCAP_LEN 2 /* only 1- or 2-character names are used */
181 tcap_hash(const char *string)
183 char temp[TCAP_LEN + 1];
187 temp[limit++] = *string++;
188 if (limit >= TCAP_LEN)
192 return info_hash(temp);
196 compare_tcap_names(const char *a, const char *b)
198 return !strncmp(a, b, (size_t) TCAP_LEN);
202 compare_info_names(const char *a, const char *b)
204 return !strcmp(a, b);
207 static const HashData hash_data[2] = {
208 { HASHTABSIZE, _nc_info_hash_table, info_hash, compare_info_names },
209 { HASHTABSIZE, _nc_cap_hash_table, tcap_hash, compare_tcap_names }
212 NCURSES_EXPORT(const HashData *) _nc_get_hash_info (bool termcap)
214 return &hash_data[(termcap != FALSE)];
218 NCURSES_EXPORT(void) _nc_comp_captab_leaks(void)
221 FreeIfNeeded(_nc_cap_table);
222 FreeIfNeeded(_nc_info_table);
223 FreeIfNeeded(_nc_capalias_table);
224 FreeIfNeeded(_nc_infoalias_table);
227 #endif /* NO_LEAKS */