* 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 "../ascii/ascebc.h"
#include "../ctlr/ebc_disp.h"
#include "../ctlr/function.h"
struct Hits Hits
[256]; /* one for each of 0x00-0xff */
struct thing
*table
[100];
register unsigned int i
= seed
;
register unsigned char c
;
i
= (i
>>26) + (i
<<6) + (c
&0x3f);
add(first
, second
, value
)
struct thing
**item
, *this;
item
= &firstentry(second
);
this = (struct thing
*) malloc(sizeof *this);
strcpy(this->name
, first
);
strcpy(this->name
+strlen(this->name
), second
);
char *file
, /* Name of file to scan for whitespace prefix */
*prefix
; /* prefix of what should be picked up */
char what
[100], value
[100];
sprintf(compare
, " %s%%[^,\t \n]", prefix
);
if ((ourfile
= fopen(file
, "r")) == NULL
) {
if (fscanf(ourfile
, compare
, what
) == 1) {
if (fgets(line
, sizeof line
, ourfile
) == NULL
) {
} while (line
[strlen(line
)-1] != '\n');
char *file
, /* Name of file to scan for #define prefix */
*prefix
; /* prefix of what should be picked up */
char what
[100], value
[100];
sprintf(compare
, "#define %s%%s %%s", prefix
);
if ((ourfile
= fopen(file
, "r")) == NULL
) {
if (fscanf(ourfile
, compare
, what
, value
) == 2) {
if ((value
[1] == 'x') || (value
[1] == 'X')) {
sscanf(value
, "0x%x", &whatitis
);
sscanf(value
, "0%o", &whatitis
);
sscanf(value
, "%d", &whatitis
);
add(prefix
, what
, whatitis
);
if (fgets(line
, sizeof line
, ourfile
) == NULL
) {
} while (line
[strlen(line
)-1] != '\n');
fprintf(stderr
, "No room for ascii characters!\n");
if (type
[1] == 0) { /* character */
hit
->ctlrfcn
= FCN_CHARACTER
;
hit
->code
= ebc_disp
[ascebc
[AE_IN
][type
[0]]];
return savechr(*type
); /* The character is the name */
for (this = firstentry(type
); this; this = this->next
) {
if ((type
[0] == this->name
[4])
&& (strcmp(type
, this->name
+4) == 0)) {
if (this->name
[0] == 'F') {
hit
->ctlrfcn
= FCN_NULL
; /* XXX */
fprintf(stderr
, "Error: Unknown type %s.\n", type
);
unsigned char plain
[100], shifted
[100], alted
[100], shiftalted
[100];
memset((char *)Hits
, 0, sizeof Hits
);
* First, we read "host3270.h" to find the names/values of
* various AID; then we read kbd3270.h to find the names/values
aidfile
= "../ctlr/hostctlr.h";
scandefine(aidfile
, "AID_");
fcnfile
= "../ctlr/function.h";
scanwhite(fcnfile
, "FCN_");
while (gets(line
) != NULL
) {
plain
[0] = shifted
[0] = alted
[0] = shiftalted
[0] = 0;
(void) sscanf(line
, "%d %x %s %s %s %s", &keynumber
,
&scancode
, plain
, shifted
, alted
, shiftalted
);
if ((keynumber
== -1) || (scancode
== -1)
&& (shiftalted
[0] == 0))) {
"Error: scancode 0x%02x for keynumber %d\n", scancode
,
if (Hits
[scancode
].hits
.hit
[0].ctlrfcn
!= undefined
) {
"Error: duplicate scancode 0x%02x for keynumber %d\n",
hit
= Hits
[scancode
].hits
.hit
;
Hits
[scancode
].hits
.keynumber
= keynumber
;
Hits
[scancode
].name
[0] = doit(hit
, plain
, &Hits
[scancode
]);
Hits
[scancode
].name
[1] = doit(hit
+1, shifted
, &Hits
[scancode
]);
Hits
[scancode
].name
[2] = doit(hit
+2, alted
, &Hits
[scancode
]);
Hits
[scancode
].name
[3] = doit(hit
+3, shiftalted
, &Hits
[scancode
]);