1 /****************************************************************************
2 * Copyright 2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2011,2015 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 *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER 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 *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Thomas E. Dickey 1997-on *
32 ****************************************************************************/
35 * This replaces an awk script which translated keys.list into keys.tries by
36 * making the output show the indices into the TERMTYPE Strings array. Doing
37 * it that way lets us cut down on the size of the init_keytry() function.
41 #include <build.priv.h>
43 MODULE_ID("$Id: make_keys.c,v 1.23 2021/08/18 20:55:25 tom Exp $")
50 static unsigned result = 0;
54 for (n = 0; strnames[n] != 0; n++) {
57 for (n = 0; strfnames[n] != 0; n++) {
65 lookup(const char *name)
69 for (n = 0; strnames[n] != 0; n++) {
70 if (!strcmp(name, strnames[n])) {
76 for (n = 0; strfnames[n] != 0; n++) {
77 if (!strcmp(name, strfnames[n])) {
83 return found ? n : unknown();
87 make_keys(FILE *ifp, FILE *ofp)
92 unsigned ignore = unknown();
96 while (fgets(buffer, (int) sizeof(buffer), ifp) != 0) {
100 to[sizeof(to) - 1] = '\0';
101 from[sizeof(from) - 1] = '\0';
103 scanned = sscanf(buffer, "%255s %255s", to, from);
105 unsigned code = lookup(from);
108 if (strlen(from) > maxlen)
109 maxlen = (unsigned) strlen(from);
110 fprintf(ofp, "\t{ %4u, %-*.*s },\t/* %s */\n",
112 (int) maxlen, (int) maxlen,
120 write_list(FILE *ofp, const char **list)
123 fprintf(ofp, "%s\n", *list++);
127 main(int argc, char *argv[])
129 static const char *prefix[] =
131 "#ifndef _INIT_KEYTRY_H",
132 "#define _INIT_KEYTRY_H 1",
134 "/* This file was generated by MAKE_KEYS */",
141 "const struct tinfo_fkeys _nc_tinfo_fkeys[] = {",
144 static const char *suffix[] =
148 "#endif /* _INIT_KEYTRY_H */",
152 write_list(stdout, prefix);
155 for (n = 1; n < argc; n++) {
156 FILE *fp = fopen(argv[n], "r");
158 make_keys(fp, stdout);
163 make_keys(stdin, stdout);
165 write_list(stdout, suffix);