2 ##############################################################################
3 # Copyright (c) 2007 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.8 2007/08/12 13:13:51 tom Exp $
32 OPT2=${3-tinfo/MKcaptab.awk}
33 DATA=${4-../include/Caps}
37 * comp_captab.c -- The names of the capabilities indexed via a hash
38 * table for the compiler.
42 #include <curses.priv.h>
48 ./make_hash 1 info $OPT1 <$DATA
49 ./make_hash 3 cap $OPT1 <$DATA
51 $AWK -f $OPT2 bigstrings=$OPT1 tablename=capalias <$DATA
53 $AWK -f $OPT2 bigstrings=$OPT1 tablename=infoalias <$DATA
59 next_string(const char *strings, unsigned *offset)
61 *offset += strlen(strings + *offset) + 1;
64 static const struct name_table_entry *
65 _nc_build_names(struct name_table_entry **actual,
66 const name_table_data *source,
70 *actual = typeCalloc(struct name_table_entry, CAPTABSIZE);
74 for (n = 0; n < CAPTABSIZE; ++n) {
75 (*actual)[n].nte_name = strings + len;
76 (*actual)[n].nte_type = source[n].nte_type;
77 (*actual)[n].nte_index = source[n].nte_index;
78 (*actual)[n].nte_link = source[n].nte_link;
79 next_string(strings, &len);
86 #define add_alias(field) \\
87 if (source[n].field >= 0) { \\
88 (*actual)[n].field = strings + source[n].field; \\
91 static const struct alias *
92 _nc_build_alias(struct alias **actual,
93 const alias_table_data *source,
98 *actual = typeCalloc(struct alias, tablesize + 1);
101 for (n = 0; n < tablesize; ++n) {
111 #define build_names(root) _nc_build_names(&_nc_##root##_table, \\
112 root##_names_data, \\
114 #define build_alias(root) _nc_build_alias(&_nc_##root##alias_table, \\
117 SIZEOF(root##alias_data))
119 #define build_names(root) _nc_ ## root ## _table
120 #define build_alias(root) _nc_ ## root ## alias_table
123 NCURSES_EXPORT(const struct name_table_entry *) _nc_get_table (bool termcap)
125 return termcap ? build_names(cap) : build_names(info) ;
128 NCURSES_EXPORT(const short *) _nc_get_hash_table (bool termcap)
130 return termcap ? _nc_cap_hash_table: _nc_info_hash_table ;
133 NCURSES_EXPORT(const struct alias *) _nc_get_alias_table (bool termcap)
135 return termcap ? build_alias(cap) : build_alias(info) ;
139 NCURSES_EXPORT(void) _nc_comp_captab_leaks(void)
142 FreeIfNeeded(_nc_cap_table);
143 FreeIfNeeded(_nc_info_table);
144 FreeIfNeeded(_nc_capalias_table);
145 FreeIfNeeded(_nc_infoalias_table);
148 #endif /* NO_LEAKS */