Back to index

tetex-bin  3.0
make_keys.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /****************************************************************************
00030  *  Author: Thomas E. Dickey <dickey@clark.net> 1997                        *
00031  ****************************************************************************/
00032 
00033 /*
00034  * This replaces an awk script which translated keys.list into keys.tries by
00035  * making the output show the indices into the TERMTYPE Strings array.  Doing
00036  * it that way lets us cut down on the size of the init_keytry() function.
00037  */
00038 #include <curses.priv.h>
00039 
00040 MODULE_ID("$Id: make_keys.c,v 1.10 2000/12/10 02:55:08 tom Exp $")
00041 
00042 #include <names.c>
00043 
00044 #define UNKNOWN (SIZEOF(strnames) + SIZEOF(strfnames))
00045 
00046 static size_t
00047 lookup(const char *name)
00048 {
00049     size_t n;
00050     bool found = FALSE;
00051     for (n = 0; strnames[n] != 0; n++) {
00052        if (!strcmp(name, strnames[n])) {
00053            found = TRUE;
00054            break;
00055        }
00056     }
00057     if (!found) {
00058        for (n = 0; strfnames[n] != 0; n++) {
00059            if (!strcmp(name, strfnames[n])) {
00060               found = TRUE;
00061               break;
00062            }
00063        }
00064     }
00065     return found ? n : UNKNOWN;
00066 }
00067 
00068 static void
00069 make_keys(FILE * ifp, FILE * ofp)
00070 {
00071     char buffer[BUFSIZ];
00072     char from[BUFSIZ];
00073     char to[BUFSIZ];
00074     int maxlen = 16;
00075 
00076     while (fgets(buffer, sizeof(buffer), ifp) != 0) {
00077        if (*buffer == '#')
00078            continue;
00079        if (sscanf(buffer, "%s %s", to, from) == 2) {
00080            int code = lookup(from);
00081            if (code == UNKNOWN)
00082               continue;
00083            if ((int) strlen(from) > maxlen)
00084               maxlen = strlen(from);
00085            fprintf(ofp, "\t{ %4d, %-*.*s },\t/* %s */\n",
00086                   code,
00087                   maxlen, maxlen,
00088                   to,
00089                   from);
00090        }
00091     }
00092 }
00093 
00094 static void
00095 write_list(FILE * ofp, const char **list)
00096 {
00097     while (*list != 0)
00098        fprintf(ofp, "%s\n", *list++);
00099 }
00100 
00101 int
00102 main(int argc, char *argv[])
00103 {
00104     static const char *prefix[] =
00105     {
00106        "#ifndef NCU_KEYS_H",
00107        "#define NCU_KEYS_H 1",
00108        "",
00109        "/* This file was generated by MAKE_KEYS */",
00110        "",
00111        "#if BROKEN_LINKER",
00112        "static",
00113        "#endif",
00114        "struct tinfo_fkeys _nc_tinfo_fkeys[] = {",
00115        0
00116     };
00117     static const char *suffix[] =
00118     {
00119        "\t{ 0, 0} };",
00120        "",
00121        "#endif /* NCU_KEYS_H */",
00122        0
00123     };
00124 
00125     write_list(stdout, prefix);
00126     if (argc > 1) {
00127        int n;
00128        for (n = 1; n < argc; n++) {
00129            FILE *fp = fopen(argv[n], "r");
00130            if (fp != 0) {
00131               make_keys(fp, stdout);
00132               fclose(fp);
00133            }
00134        }
00135     } else {
00136        make_keys(stdin, stdout);
00137     }
00138     write_list(stdout, suffix);
00139     return EXIT_SUCCESS;
00140 }