]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/MKuserdefs.sh
ncurses 6.1 - patch 20190309
[ncurses.git] / ncurses / tinfo / MKuserdefs.sh
1 #!/bin/sh
2 ##############################################################################
3 # Copyright (c) 2019 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: MKuserdefs.sh,v 1.6 2019/03/10 01:08:14 tom Exp $
30 AWK=${1-awk}; shift 1
31 OPT1=${1-0}; shift 1
32
33 cat <<EOF
34 /*
35  * generated by $0
36  */
37
38 EOF
39
40 cat <<'EOF'
41 /*
42  *    comp_userdefs.c -- The names of widely used user-defined capabilities
43  *                       indexed via a hash table for the compiler.
44  *
45  */
46
47 #include <curses.priv.h>
48 #include <tic.h>
49 #include <hashsize.h>
50
51 #if NCURSES_XNAMES
52 EOF
53
54 cat "$@" | ./make_hash 1 user $OPT1
55
56 cat <<EOF
57
58 #if $OPT1
59 static void
60 next_string(const char *strings, unsigned *offset)
61 {
62     *offset += (unsigned) strlen(strings + *offset) + 1;
63 }
64
65 static const struct user_table_entry *
66 _nc_build_names(struct user_table_entry **actual,
67                 const user_table_data *source,
68                 const char *strings)
69 {
70     if (*actual == 0) {
71         *actual = typeCalloc(struct user_table_entry, CAPTABSIZE);
72         if (*actual != 0) {
73             unsigned n;
74             unsigned len = 0;
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_index = source[n].ute_index;
79                 (*actual)[n].ute_link = source[n].ute_link;
80                 next_string(strings, &len);
81             }
82         }
83     }
84     return *actual;
85 }
86
87 #define build_names(root) _nc_build_names(&_nc_##root##_table, \\
88                                           root##_names_data, \\
89                                           root##_names_text)
90 #else
91 #define build_names(root) _nc_ ## root ## _table
92 #endif
93
94 NCURSES_EXPORT(const struct user_table_entry *) _nc_get_userdefs_table (void)
95 {
96     return build_names(user) ;
97 }
98
99 static HashValue
100 info_hash(const char *string)
101 {
102     long sum = 0;
103
104     DEBUG(9, ("hashing %s", string));
105     while (*string) {
106         sum += (long) (*string + (*(string + 1) << 8));
107         string++;
108     }
109
110     DEBUG(9, ("sum is %ld", sum));
111     return (HashValue) (sum % HASHTABSIZE);
112 }
113
114 static int
115 compare_info_names(const char *a, const char *b)
116 {
117     return !strcmp(a, b);
118 }
119
120 static const HashData hash_data[] = {
121     { HASHTABSIZE, _nc_user_hash_table, info_hash, compare_info_names }
122 };
123
124 NCURSES_EXPORT(const HashData *) _nc_get_hash_user (void)
125 {
126     return hash_data;
127 }
128
129 #if NO_LEAKS
130 NCURSES_EXPORT(void) _nc_comp_userdefs_leaks(void)
131 {
132 #if $OPT1
133     FreeIfNeeded(_nc_user_table);
134 #endif
135 }
136 #endif /* NO_LEAKS */
137
138 #else /*! NCURSES_XNAMES */
139 NCURSES_EXPORT(void) _nc_comp_userdefs(void);
140 NCURSES_EXPORT(void) _nc_comp_userdefs(void) { }
141 #endif /* NCURSES_XNAMES */
142 EOF