missing ncurses sources
[tomato.git] / release / src / router / libncurses / ncurses / tinfo / MKcaptab.sh
blob4d1b53a5bd9a12252f422fda43ff5f655dadb916
1 #!/bin/sh
2 ##############################################################################
3 # Copyright (c) 2007-2009,2010 Free Software Foundation, Inc. #
4 # #
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: #
12 # #
13 # The above copyright notice and this permission notice shall be included in #
14 # all copies or substantial portions of the Software. #
15 # #
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. #
23 # #
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 #
27 # authorization. #
28 ##############################################################################
29 # $Id: MKcaptab.sh,v 1.13 2010/12/25 23:43:58 tom Exp $
30 AWK=${1-awk}
31 OPT1=${2-0}
32 OPT2=${3-tinfo/MKcaptab.awk}
33 DATA=${4-../include/Caps}
35 cat <<EOF
37 * generated by $0
40 EOF
42 cat <<'EOF'
44 * comp_captab.c -- The names of the capabilities indexed via a hash
45 * table for the compiler.
49 #include <curses.priv.h>
50 #include <tic.h>
51 #include <hashsize.h>
53 EOF
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
62 cat <<EOF
64 #if $OPT1
65 static void
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,
74 const char *strings)
76 if (*actual == 0) {
77 *actual = typeCalloc(struct name_table_entry, CAPTABSIZE);
78 if (*actual != 0) {
79 unsigned n;
80 unsigned len = 0;
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);
90 return *actual;
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,
101 const char *strings,
102 unsigned tablesize)
104 if (*actual == 0) {
105 *actual = typeCalloc(struct alias, tablesize + 1);
106 if (*actual != 0) {
107 unsigned n;
108 for (n = 0; n < tablesize; ++n) {
109 add_alias(from);
110 add_alias(to);
111 add_alias(source);
115 return *actual;
118 #define build_names(root) _nc_build_names(&_nc_##root##_table, \\
119 root##_names_data, \\
120 root##_names_text)
121 #define build_alias(root) _nc_build_alias(&_nc_##root##alias_table, \\
122 root##alias_data, \\
123 root##alias_text, \\
124 SIZEOF(root##alias_data))
125 #else
126 #define build_names(root) _nc_ ## root ## _table
127 #define build_alias(root) _nc_ ## root ## alias_table
128 #endif
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) ;
146 static HashValue
147 info_hash(const char *string)
149 long sum = 0;
151 DEBUG(9, ("hashing %s", string));
152 while (*string) {
153 sum += (long) (*string + (*(string + 1) << 8));
154 string++;
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 */
163 static HashValue
164 tcap_hash(const char *string)
166 char temp[TCAP_LEN + 1];
167 int limit = 0;
169 while (*string) {
170 temp[limit++] = *string++;
171 if (limit >= TCAP_LEN)
172 break;
174 temp[limit] = '\0';
175 return info_hash(temp);
178 static int
179 compare_tcap_names(const char *a, const char *b)
181 return !strncmp(a, b, TCAP_LEN);
184 static int
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)];
200 #if NO_LEAKS
201 NCURSES_EXPORT(void) _nc_comp_captab_leaks(void)
203 #if $OPT1
204 FreeIfNeeded(_nc_cap_table);
205 FreeIfNeeded(_nc_info_table);
206 FreeIfNeeded(_nc_capalias_table);
207 FreeIfNeeded(_nc_infoalias_table);
208 #endif
210 #endif /* NO_LEAKS */