2 ##############################################################################
3 # Copyright (c) 2007-2010,2011 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.14 2011/10/22 16:34:50 tom Exp $
32 OPT2=${3-tinfo/MKcaptab.awk}
33 DATA=${4-../include/Caps}
44 * comp_captab.c -- The names of the capabilities indexed via a hash
45 * table for the compiler.
49 #include <curses.priv.h>
55 ./make_hash 1 info $OPT1 <$DATA
56 ./make_hash 3 cap $OPT1 <$DATA
58 $AWK -f $OPT2 bigstrings=$OPT1 tablename=capalias <$DATA
60 $AWK -f $OPT2 bigstrings=$OPT1 tablename=infoalias <$DATA
66 next_string(const char *strings, unsigned *offset)
68 *offset += (unsigned) strlen(strings + *offset) + 1;
71 static const struct name_table_entry *
72 _nc_build_names(struct name_table_entry **actual,
73 const name_table_data *source,
77 *actual = typeCalloc(struct name_table_entry, CAPTABSIZE);
81 for (n = 0; n < CAPTABSIZE; ++n) {
82 (*actual)[n].nte_name = strings + len;
83 (*actual)[n].nte_type = source[n].nte_type;
84 (*actual)[n].nte_index = source[n].nte_index;
85 (*actual)[n].nte_link = source[n].nte_link;
86 next_string(strings, &len);
93 #define add_alias(field) \\
94 if (source[n].field >= 0) { \\
95 (*actual)[n].field = strings + source[n].field; \\
98 static const struct alias *
99 _nc_build_alias(struct alias **actual,
100 const alias_table_data *source,
105 *actual = typeCalloc(struct alias, tablesize + 1);
108 for (n = 0; n < tablesize; ++n) {
118 #define build_names(root) _nc_build_names(&_nc_##root##_table, \\
119 root##_names_data, \\
121 #define build_alias(root) _nc_build_alias(&_nc_##root##alias_table, \\
124 SIZEOF(root##alias_data))
126 #define build_names(root) _nc_ ## root ## _table
127 #define build_alias(root) _nc_ ## root ## alias_table
130 NCURSES_EXPORT(const struct name_table_entry *) _nc_get_table (bool termcap)
132 return termcap ? build_names(cap) : build_names(info) ;
135 /* entrypoint used by tack (do not alter) */
136 NCURSES_EXPORT(const HashValue *) _nc_get_hash_table (bool termcap)
138 return termcap ? _nc_cap_hash_table: _nc_info_hash_table ;
141 NCURSES_EXPORT(const struct alias *) _nc_get_alias_table (bool termcap)
143 return termcap ? build_alias(cap) : build_alias(info) ;
147 info_hash(const char *string)
151 DEBUG(9, ("hashing %s", string));
153 sum += (long) (*string + (*(string + 1) << 8));
157 DEBUG(9, ("sum is %ld", sum));
158 return (HashValue) (sum % HASHTABSIZE);
161 #define TCAP_LEN 2 /* only 1- or 2-character names are used */
164 tcap_hash(const char *string)
166 char temp[TCAP_LEN + 1];
170 temp[limit++] = *string++;
171 if (limit >= TCAP_LEN)
175 return info_hash(temp);
179 compare_tcap_names(const char *a, const char *b)
181 return !strncmp(a, b, (size_t) TCAP_LEN);
185 compare_info_names(const char *a, const char *b)
187 return !strcmp(a, b);
190 static const HashData hash_data[2] = {
191 { HASHTABSIZE, _nc_info_hash_table, info_hash, compare_info_names },
192 { HASHTABSIZE, _nc_cap_hash_table, tcap_hash, compare_tcap_names }
195 NCURSES_EXPORT(const HashData *) _nc_get_hash_info (bool termcap)
197 return &hash_data[(termcap != FALSE)];
201 NCURSES_EXPORT(void) _nc_comp_captab_leaks(void)
204 FreeIfNeeded(_nc_cap_table);
205 FreeIfNeeded(_nc_info_table);
206 FreeIfNeeded(_nc_capalias_table);
207 FreeIfNeeded(_nc_infoalias_table);
210 #endif /* NO_LEAKS */