* This program scans a file which describes a keyboard. The output
* of the program is a series of 'C' declarations which describe a
* mapping between (scancode, shiftstate, altstate) and 3270 functions,
* The format of the input file is as follows:
* keynumber [ scancode [ unshifted [ shifted [ alted [ shiftalted ] ] ] ] ]
* keynumber is in decimal, and starts in column 1.
* scancode is hexadecimal.
* unshifted, etc. - these are either a single ascii character,
* or the name of a function or an AID-generating key.
* all fields are separated by a single space.
#include "../keyboard/m4.out"
#include "../ascii/ascebc.h"
#include "../ctlr/ebc_disp.h"
#include "../ctlr/function.h"
static char *shiftof
[] = { "normal", "shifted", "alted", "shiftalted" };
char *aidfile
= 0, *fcnfile
= 0;
dohits(aidfile
, fcnfile
); /* Set up "Hits" */
printf(" * Ascii to scancode conversion table. First\n");
printf(" * 128 bytes (0-127) correspond with actual Ascii\n");
printf(" * characters; the rest are TC types from termcodes.m4\n");
printf(" * (actually, from m4.out).\n");
printf("struct asctosc {\n");
printf("\tenum shiftvalue { cantdo, normal, shifted, alted,");
printf(" shiftalted } shift;\n\tunsigned char scancode;");
printf("\n} asctosc[] = {\n");
/* Build the ascii part of the table. */
for (Ph
= Hits
, scancode
= 0; Ph
<= Hits
+highestof(Hits
);
for (i
= 0; i
< 4; i
++) {
if (ph
->hit
[i
].ctlrfcn
== FCN_CHARACTER
) {
c
= Ph
->name
[i
][0]; /* "name" of this one */
if ((tbl
[c
].shift
== 0) || (tbl
[c
].shift
[0] == 0)) {
tbl
[c
].shift
= shiftof
[i
];
tbl
[c
].scancode
= scancode
;
/* Now, output the table */
for (Pt
= tbl
, asciicode
= 0; Pt
<= tbl
+highestof(tbl
); Pt
++, asciicode
++) {
if (isprint(asciicode
) && (asciicode
!= ' ')) {
fprintf(stderr
, "Unable to produce scancode sequence for");
fprintf(stderr
, " ASCII character [%c]!\n", asciicode
);
printf("\t{ cantdo, 0 },\t");
printf("\t{ %s, 0x%x },", Pt
->shift
, Pt
->scancode
);
printf("\t/* 0x%x", asciicode
);
if (isprint(asciicode
)) {
printf(" [%c]", asciicode
);
for (TC
= &TC_Ascii
[TC_LOWEST
-TC_LOWEST
];
TC
< &TC_Ascii
[TC_LOWEST_USER
-TC_LOWEST
]; TC
++, asciicode
++) {
printf("\t{ cantdo, 0 },\t");
printf("\t/* 0x%x */\n", asciicode
);
for (TC
= &TC_Ascii
[TC_LOWEST_USER
-TC_LOWEST
];
TC
<= &TC_Ascii
[TC_HIGHEST
-TC_LOWEST
]; TC
++, asciicode
++) {
/* Hack for "PFK" names (which should be "PF") */
if (memcmp(TC
->tc_name
, "PFK", 3) == 0) {
static char PFonly
[100] = "PF";
strcpy(PFonly
+2, TC
->tc_name
+3);
for (this = firstentry(TC
->tc_name
); (!found
) && this;
if ((this->name
[4] == TC
->tc_name
[0])
&& (strcmp(this->name
+4, TC
->tc_name
) == 0)) {
/* What we have is a TC entry matching a scancode entry */
Ph
= this->hits
; /* now, get hits */
for (i
= 0; i
< 4; i
++) {
if ((Ph
->name
[i
][4] == TC
->tc_name
[0])
&& (strcmp(Ph
->name
[i
]+4, TC
->tc_name
) == 0)) {
printf("0x%02x },", Ph
-Hits
);
printf("\t{ cantdo, 0 },\t");
fprintf(stderr
, "Unable to produce TC_%s with scan codes!\n",
printf("\t/* 0x%x - %s */\n", asciicode
, TC
->tc_name
);