2 ##############################################################################
3 # Copyright 2019,2020 Thomas E. Dickey #
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: MKuserdefs.sh,v 1.10 2020/02/02 23:34:34 tom Exp $
42 * comp_userdefs.c -- The names of widely used user-defined capabilities
43 * indexed via a hash table for the compiler.
47 #include <curses.priv.h>
54 cat "$@" | ./make_hash 1 user $OPT1
58 #define USERTABSIZE SIZEOF(user_names_data)
62 next_string(const char *strings, unsigned *offset)
64 *offset += (unsigned) strlen(strings + *offset) + 1;
67 static const struct user_table_entry *
68 _nc_build_names(struct user_table_entry **actual,
69 const user_table_data *source,
73 *actual = typeCalloc(struct user_table_entry, USERTABSIZE);
77 for (n = 0; n < USERTABSIZE; ++n) {
78 (*actual)[n].ute_name = strings + len;
79 (*actual)[n].ute_type = (int) source[n].ute_type;
80 (*actual)[n].ute_argc = source[n].ute_argc;
81 (*actual)[n].ute_args = source[n].ute_args;
82 (*actual)[n].ute_index = source[n].ute_index;
83 (*actual)[n].ute_link = source[n].ute_link;
84 next_string(strings, &len);
91 #define build_names(root) _nc_build_names(&_nc_##root##_table, \\
95 #define build_names(root) _nc_ ## root ## _table
98 NCURSES_EXPORT(const struct user_table_entry *) _nc_get_userdefs_table (void)
100 return build_names(user) ;
104 info_hash(const char *string)
108 DEBUG(9, ("hashing %s", string));
110 sum += (long) (*string + (*(string + 1) << 8));
114 DEBUG(9, ("sum is %ld", sum));
115 return (HashValue) (sum % HASHTABSIZE);
119 compare_info_names(const char *a, const char *b)
121 return !strcmp(a, b);
124 static const HashData hash_data[] = {
125 { HASHTABSIZE, _nc_user_hash_table, info_hash, compare_info_names }
128 NCURSES_EXPORT(const HashData *) _nc_get_hash_user (void)
134 NCURSES_EXPORT(void) _nc_comp_userdefs_leaks(void)
137 FreeIfNeeded(_nc_user_table);
140 #endif /* NO_LEAKS */
142 #else /*! NCURSES_XNAMES */
143 NCURSES_EXPORT(void) _nc_comp_userdefs(void);
144 NCURSES_EXPORT(void) _nc_comp_userdefs(void) { }
145 #endif /* NCURSES_XNAMES */