Back to index

tetex-bin  3.0
Defines | Functions
make_keys.c File Reference
#include <curses.priv.h>
#include <names.c>

Go to the source code of this file.

Defines

#define UNKNOWN   (SIZEOF(strnames) + SIZEOF(strfnames))

Functions

static size_t lookup (const char *name)
static void make_keys (FILE *ifp, FILE *ofp)
static void write_list (FILE *ofp, const char **list)
int main (int argc, char *argv[])

Define Documentation

#define UNKNOWN   (SIZEOF(strnames) + SIZEOF(strfnames))

Definition at line 44 of file make_keys.c.


Function Documentation

static size_t lookup ( const char *  name) [static]

Definition at line 47 of file make_keys.c.

{
    size_t n;
    bool found = FALSE;
    for (n = 0; strnames[n] != 0; n++) {
       if (!strcmp(name, strnames[n])) {
           found = TRUE;
           break;
       }
    }
    if (!found) {
       for (n = 0; strfnames[n] != 0; n++) {
           if (!strcmp(name, strfnames[n])) {
              found = TRUE;
              break;
           }
       }
    }
    return found ? n : UNKNOWN;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 102 of file make_keys.c.

{
    static const char *prefix[] =
    {
       "#ifndef NCU_KEYS_H",
       "#define NCU_KEYS_H 1",
       "",
       "/* This file was generated by MAKE_KEYS */",
       "",
       "#if BROKEN_LINKER",
       "static",
       "#endif",
       "struct tinfo_fkeys _nc_tinfo_fkeys[] = {",
       0
    };
    static const char *suffix[] =
    {
       "\t{ 0, 0} };",
       "",
       "#endif /* NCU_KEYS_H */",
       0
    };

    write_list(stdout, prefix);
    if (argc > 1) {
       int n;
       for (n = 1; n < argc; n++) {
           FILE *fp = fopen(argv[n], "r");
           if (fp != 0) {
              make_keys(fp, stdout);
              fclose(fp);
           }
       }
    } else {
       make_keys(stdin, stdout);
    }
    write_list(stdout, suffix);
    return EXIT_SUCCESS;
}

Here is the call graph for this function:

static void make_keys ( FILE ifp,
FILE ofp 
) [static]

Definition at line 69 of file make_keys.c.

{
    char buffer[BUFSIZ];
    char from[BUFSIZ];
    char to[BUFSIZ];
    int maxlen = 16;

    while (fgets(buffer, sizeof(buffer), ifp) != 0) {
       if (*buffer == '#')
           continue;
       if (sscanf(buffer, "%s %s", to, from) == 2) {
           int code = lookup(from);
           if (code == UNKNOWN)
              continue;
           if ((int) strlen(from) > maxlen)
              maxlen = strlen(from);
           fprintf(ofp, "\t{ %4d, %-*.*s },\t/* %s */\n",
                  code,
                  maxlen, maxlen,
                  to,
                  from);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void write_list ( FILE ofp,
const char **  list 
) [static]

Definition at line 95 of file make_keys.c.

{
    while (*list != 0)
       fprintf(ofp, "%s\n", *list++);
}

Here is the call graph for this function:

Here is the caller graph for this function: