From d5c90a592ecf72d18a76692b095a073a9f55f5d4 Mon Sep 17 00:00:00 2001 From: Gregory Minshall Date: Sun, 16 Nov 1986 23:22:23 -0800 Subject: [PATCH 1/1] Change FCN_... from #define's into enum's. SCCS-vsn: usr.bin/tn3270/tools/mkhits/dohits.c 1.3 SCCS-vsn: usr.bin/tn3270/tools/mkhits/mkhits.c 1.3 SCCS-vsn: usr.bin/tn3270/tools/mkastosc/mkastosc.c 1.3 --- .../usr.bin/tn3270/tools/mkastosc/mkastosc.c | 20 ++++++- usr/src/usr.bin/tn3270/tools/mkhits/dohits.c | 59 +++++++++++++++---- usr/src/usr.bin/tn3270/tools/mkhits/mkhits.c | 53 +++++++++++------ 3 files changed, 102 insertions(+), 30 deletions(-) diff --git a/usr/src/usr.bin/tn3270/tools/mkastosc/mkastosc.c b/usr/src/usr.bin/tn3270/tools/mkastosc/mkastosc.c index 8eb79c88fb..8973ef6c7b 100644 --- a/usr/src/usr.bin/tn3270/tools/mkastosc/mkastosc.c +++ b/usr/src/usr.bin/tn3270/tools/mkastosc/mkastosc.c @@ -32,7 +32,9 @@ void -main() +main(argc, argv) +int argc; +char *argv[]; { int scancode; int asciicode; @@ -49,8 +51,20 @@ main() int scancode; } tbl[128], *Pt; static char *shiftof[] = { "normal", "shifted", "alted", "shiftalted" }; + char *aidfile = 0, *fcnfile = 0; - dohits(); /* Set up "Hits" */ + if (argc > 1) { + if (argv[1][0] != '-') { + aidfile = argv[1]; + } + } + if (argc > 2) { + if (argv[2][0] != '-') { + fcnfile = argv[2]; + } + } + + dohits(aidfile, fcnfile); /* Set up "Hits" */ printf("/*\n"); printf(" * Ascii to scancode conversion table. First\n"); @@ -67,7 +81,7 @@ main() Ph++, scancode++) { ph = &Ph->hits; for (i = 0; i < 4; i++) { - if (ph->hit[i].type == character) { + if (ph->hit[i].ctlrfcn == FCN_CHARACTER) { c = Ph->name[i][0]; /* "name" of this one */ if (tbl[c].shift[0] == 0) { tbl[c].shift = shiftof[i]; diff --git a/usr/src/usr.bin/tn3270/tools/mkhits/dohits.c b/usr/src/usr.bin/tn3270/tools/mkhits/dohits.c index a092f6c72a..7bc87b8c3a 100644 --- a/usr/src/usr.bin/tn3270/tools/mkhits/dohits.c +++ b/usr/src/usr.bin/tn3270/tools/mkhits/dohits.c @@ -52,6 +52,8 @@ char *string; void add(first, second, value) +char *first, *second; +int value; { struct thing **item, *this; @@ -65,8 +67,38 @@ add(first, second, value) } void -scan(file, prefix) -char *file, /* Name of file to scan */ +scanwhite(file, prefix) +char *file, /* Name of file to scan for whitespace prefix */ + *prefix; /* prefix of what should be picked up */ +{ + FILE *ourfile; + char compare[100]; + char what[100], value[100]; + char line[200]; + + sprintf(compare, " %s%%[^,\t \n]", prefix); + if ((ourfile = fopen(file, "r")) == NULL) { + perror("fopen"); + exit(1); + } + while (!feof(ourfile)) { + if (fscanf(ourfile, compare, what) == 1) { + add(prefix, what, 0); + } + do { + if (fgets(line, sizeof line, ourfile) == NULL) { + if (!feof(ourfile)) { + perror("fgets"); + } + break; + } + } while (line[strlen(line)-1] != '\n'); + } +} + +void +scandefine(file, prefix) +char *file, /* Name of file to scan for #define prefix */ *prefix; /* prefix of what should be picked up */ { FILE *ourfile; @@ -126,12 +158,12 @@ struct Hits *hits; { struct thing *this; - hit->type = illegal; + hit->ctlrfcn = FCN_NULL; if (type[0] == 0) { return 0; } if (type[1] == 0) { /* character */ - hit->type = character; + hit->ctlrfcn = FCN_CHARACTER; hit->code = ebc_disp[ascebc[AE_IN][type[0]]]; return savechr(*type); /* The character is the name */ } else { @@ -140,9 +172,9 @@ struct Hits *hits; && (strcmp(type, this->name+4) == 0)) { this->hits = hits; if (this->name[0] == 'F') { - hit->type = function; + hit->ctlrfcn = FCN_NULL; /* XXX */ } else { - hit->type = aid; + hit->ctlrfcn = FCN_AID; } return this->name; } @@ -154,7 +186,8 @@ struct Hits *hits; void -dohits() +dohits(aidfile, fcnfile) +char *aidfile, *fcnfile; { unsigned char plain[100], shifted[100], alted[100], shiftalted[100]; unsigned char line[200]; @@ -173,8 +206,14 @@ dohits() * of various FCNs. */ - scan("../ctlr/hostctlr.h", "AID_"); - scan("../ctlr/function.h", "FCN_"); + if (aidfile == 0) { + aidfile = "../ctlr/hostctlr.h"; + } + scandefine(aidfile, "AID_"); + if (fcnfile == 0) { + fcnfile = "../ctlr/function.h"; + } + scanwhite(fcnfile, "FCN_"); while (gets(line) != NULL) { if (!isdigit(line[0])) { @@ -198,7 +237,7 @@ dohits() keynumber); break; } - if (Hits[scancode].hits.hit[0].type != undefined) { + if (Hits[scancode].hits.hit[0].ctlrfcn != undefined) { fprintf(stderr, "Error: duplicate scancode 0x%02x for keynumber %d\n", scancode, keynumber); diff --git a/usr/src/usr.bin/tn3270/tools/mkhits/mkhits.c b/usr/src/usr.bin/tn3270/tools/mkhits/mkhits.c index dee6aaa616..4ca070ea75 100644 --- a/usr/src/usr.bin/tn3270/tools/mkhits/mkhits.c +++ b/usr/src/usr.bin/tn3270/tools/mkhits/mkhits.c @@ -27,15 +27,29 @@ void -main() +main(argc, argv) +int argc; +char *argv[]; { int scancode; int empty; int i; struct hits *ph; struct Hits *Ph; + char *aidfile = 0, *fcnfile = 0; - dohits(); /* Set up "Hits" */ + if (argc > 1) { + if (argv[1][0] != '-') { + aidfile = argv[1]; + } + } + if (argc > 2) { + if (argv[2][0] != '-') { + fcnfile = argv[2]; + } + } + + dohits(aidfile, fcnfile); /* Set up "Hits" */ printf("struct hits hits[] = {\n"); empty = 0; @@ -43,35 +57,40 @@ main() for (Ph = Hits; Ph < Hits+(sizeof Hits/sizeof Hits[0]); Ph++) { ph = &Ph->hits; scancode++; - if ((ph->hit[0].type == undefined) - && (ph->hit[1].type == undefined) - && (ph->hit[2].type == undefined) - && (ph->hit[3].type == undefined)) { + if ((ph->hit[0].ctlrfcn == undefined) + && (ph->hit[1].ctlrfcn == undefined) + && (ph->hit[2].ctlrfcn == undefined) + && (ph->hit[3].ctlrfcn == undefined)) { empty++; continue; } else { while (empty) { - printf("\t{ 0, {\t{ illegal },\t{ illegal }"); - printf(",\t{ illegal },\t{ illegal } } },\n"); + printf("\t{ 0, { {undefined}, {undefined}"); + printf(", {undefined}, {undefined} } },\n"); empty--; } } printf("\t{ %d, {\t/* 0x%02x */\n\t", ph->keynumber, scancode); for (i = 0; i < 4; i++) { printf("\t{ "); - switch (ph->hit[i].type) { + switch (ph->hit[i].ctlrfcn) { case undefined: - case illegal: - printf("illegal"); + printf("undefined"); break; - case character: - printf("character, 0x%02x", ph->hit[i].code); + case FCN_CHARACTER: + printf("FCN_CHARACTER, 0x%02x", ph->hit[i].code); break; - case function: - printf("function, %s", Ph->name[i]); + case FCN_AID: + printf("FCN_AID, %s", Ph->name[i]); break; - case aid: - printf("aid, %s", Ph->name[i]); + case FCN_NULL: + default: + if ((Ph->name[i] != 0) + && (strcmp(Ph->name[i], "FCN_NULL") != 0)) { + printf("%s", Ph->name[i]); + } else { + printf("undefined"); + } break; } printf(" },\n\t"); -- 2.20.1