2 ##############################################################################
3 # Copyright (c) 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: MKuserdefs.sh,v 1.8 2019/03/17 00:46:17 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
60 next_string(const char *strings, unsigned *offset)
62 *offset += (unsigned) strlen(strings + *offset) + 1;
65 static const struct user_table_entry *
66 _nc_build_names(struct user_table_entry **actual,
67 const user_table_data *source,
71 *actual = typeCalloc(struct user_table_entry, CAPTABSIZE);
75 for (n = 0; n < CAPTABSIZE; ++n) {
76 (*actual)[n].ute_name = strings + len;
77 (*actual)[n].ute_type = (int) source[n].ute_type;
78 (*actual)[n].ute_argc = source[n].ute_argc;
79 (*actual)[n].ute_args = source[n].ute_args;
80 (*actual)[n].ute_index = source[n].ute_index;
81 (*actual)[n].ute_link = source[n].ute_link;
82 next_string(strings, &len);
89 #define build_names(root) _nc_build_names(&_nc_##root##_table, \\
93 #define build_names(root) _nc_ ## root ## _table
96 NCURSES_EXPORT(const struct user_table_entry *) _nc_get_userdefs_table (void)
98 return build_names(user) ;
102 info_hash(const char *string)
106 DEBUG(9, ("hashing %s", string));
108 sum += (long) (*string + (*(string + 1) << 8));
112 DEBUG(9, ("sum is %ld", sum));
113 return (HashValue) (sum % HASHTABSIZE);
117 compare_info_names(const char *a, const char *b)
119 return !strcmp(a, b);
122 static const HashData hash_data[] = {
123 { HASHTABSIZE, _nc_user_hash_table, info_hash, compare_info_names }
126 NCURSES_EXPORT(const HashData *) _nc_get_hash_user (void)
132 NCURSES_EXPORT(void) _nc_comp_userdefs_leaks(void)
135 FreeIfNeeded(_nc_user_table);
138 #endif /* NO_LEAKS */
140 #else /*! NCURSES_XNAMES */
141 NCURSES_EXPORT(void) _nc_comp_userdefs(void);
142 NCURSES_EXPORT(void) _nc_comp_userdefs(void) { }
143 #endif /* NCURSES_XNAMES */