|
|
1.1 root 1: /*
2: * Copyright (c) 1988 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that this notice is preserved and that due credit is given
7: * to the University of California at Berkeley. The name of the University
8: * may not be used to endorse or promote products derived from this
9: * software without specific prior written permission. This software
10: * is provided ``as is'' without express or implied warranty.
11: */
12:
13: #ifndef lint
14: static char sccsid[] = "@(#)dohits.c 3.2 (Berkeley) 3/28/88";
15: #endif /* not lint */
16:
17: /*
18: * This program scans a file which describes a keyboard. The output
19: * of the program is a series of 'C' declarations which describe a
20: * mapping between (scancode, shiftstate, altstate) and 3270 functions,
21: * characters, and AIDs.
22: *
23: * The format of the input file is as follows:
24: *
25: * keynumber [ scancode [ unshifted [ shifted [ alted [ shiftalted ] ] ] ] ]
26: *
27: * keynumber is in decimal, and starts in column 1.
28: * scancode is hexadecimal.
29: * unshifted, etc. - these are either a single ascii character,
30: * or the name of a function or an AID-generating key.
31: *
32: * all fields are separated by a single space.
33: */
34:
35: #include <stdio.h>
36: #if defined(unix)
37: #include <strings.h>
38: #else /* defined(unix) */
39: #include <string.h>
40: #endif /* defined(unix) */
41: #include <ctype.h>
42: #include "../general/general.h"
43: #include "../api/asc_ebc.h"
44: #include "../api/ebc_disp.h"
45: #include "../ctlr/function.h"
46:
47: #include "dohits.h"
48:
49: struct Hits Hits[256]; /* one for each of 0x00-0xff */
50:
51: struct thing *table[100];
52:
53: extern char *malloc();
54:
55: unsigned int
56: dohash(seed, string)
57: unsigned int seed;
58: char *string;
59: {
60: register unsigned int i = seed;
61: register unsigned char c;
62:
63: while (c = *string++) {
64: if (c >= 0x60) {
65: c -= (0x60+0x20);
66: } else {
67: c -= 0x20;
68: }
69: i = (i>>26) + (i<<6) + (c&0x3f);
70: }
71: return i;
72: }
73:
74: void
75: add(first, second, value)
76: char *first, *second;
77: int value;
78: {
79: struct thing **item, *this;
80:
81: item = &firstentry(second);
82: this = (struct thing *) malloc(sizeof *this);
83: this->next = *item;
84: *item = this;
85: this->value = value;
86: strcpy(this->name, first);
87: strcpy(this->name+strlen(this->name), second);
88: }
89:
90: void
91: scanwhite(file, prefix)
92: char *file, /* Name of file to scan for whitespace prefix */
93: *prefix; /* prefix of what should be picked up */
94: {
95: FILE *ourfile;
96: char compare[100];
97: char what[100], value[100];
98: char line[200];
99:
100: sprintf(compare, " %s%%[^,\t \n]", prefix);
101: if ((ourfile = fopen(file, "r")) == NULL) {
102: perror("fopen");
103: exit(1);
104: }
105: while (!feof(ourfile)) {
106: if (fscanf(ourfile, compare, what) == 1) {
107: add(prefix, what, 0);
108: }
109: do {
110: if (fgets(line, sizeof line, ourfile) == NULL) {
111: if (!feof(ourfile)) {
112: perror("fgets");
113: }
114: break;
115: }
116: } while (line[strlen(line)-1] != '\n');
117: }
118: }
119:
120: void
121: scandefine(file, prefix)
122: char *file, /* Name of file to scan for #define prefix */
123: *prefix; /* prefix of what should be picked up */
124: {
125: FILE *ourfile;
126: char compare[100];
127: char what[100], value[100];
128: char line[200];
129: int whatitis;
130:
131: sprintf(compare, "#define %s%%s %%s", prefix);
132: if ((ourfile = fopen(file, "r")) == NULL) {
133: perror("fopen");
134: exit(1);
135: }
136: while (!feof(ourfile)) {
137: if (fscanf(ourfile, compare, what, value) == 2) {
138: if (value[0] == '0') {
139: if ((value[1] == 'x') || (value[1] == 'X')) {
140: sscanf(value, "0x%x", &whatitis);
141: } else {
142: sscanf(value, "0%o", &whatitis);
143: }
144: } else {
145: sscanf(value, "%d", &whatitis);
146: }
147: add(prefix, what, whatitis);
148: }
149: do {
150: if (fgets(line, sizeof line, ourfile) == NULL) {
151: if (!feof(ourfile)) {
152: perror("fgets");
153: }
154: break;
155: }
156: } while (line[strlen(line)-1] != '\n');
157: }
158: }
159:
160: char *savechr(c)
161: unsigned char c;
162: {
163: char *foo;
164:
165: foo = malloc(sizeof c);
166: if (foo == 0) {
167: fprintf(stderr, "No room for ascii characters!\n");
168: exit(1);
169: }
170: *foo = c;
171: return foo;
172: }
173:
174: char *
175: doit(hit, type, hits)
176: struct hit *hit;
177: unsigned char *type;
178: struct Hits *hits;
179: {
180: struct thing *this;
181:
182: hit->ctlrfcn = FCN_NULL;
183: if (type[0] == 0) {
184: return 0;
185: }
186: if (type[1] == 0) { /* character */
187: hit->ctlrfcn = FCN_CHARACTER;
188: hit->code = ebc_disp[asc_ebc[type[0]]];
189: return savechr(*type); /* The character is the name */
190: } else {
191: for (this = firstentry(type); this; this = this->next) {
192: if ((type[0] == this->name[4])
193: && (strcmp(type, this->name+4) == 0)) {
194: this->hits = hits;
195: if (this->name[0] == 'F') {
196: hit->ctlrfcn = FCN_NULL; /* XXX */
197: } else {
198: hit->ctlrfcn = FCN_AID;
199: }
200: return this->name;
201: }
202: }
203: fprintf(stderr, "Error: Unknown type %s.\n", type);
204: return 0;
205: }
206: }
207:
208:
209: void
210: dohits(aidfile, fcnfile)
211: char *aidfile, *fcnfile;
212: {
213: unsigned char plain[100], shifted[100], alted[100], shiftalted[100];
214: unsigned char line[200];
215: int keynumber, scancode;
216: int empty;
217: int i;
218: struct hit *hit;
219: struct hits *ph;
220: struct Hits *Ph;
221:
222: memset((char *)Hits, 0, sizeof Hits);
223:
224: /*
225: * First, we read "host3270.h" to find the names/values of
226: * various AID; then we read kbd3270.h to find the names/values
227: * of various FCNs.
228: */
229:
230: if (aidfile == 0) {
231: aidfile = "../ctlr/hostctlr.h";
232: }
233: scandefine(aidfile, "AID_");
234: if (fcnfile == 0) {
235: fcnfile = "../ctlr/function.h";
236: }
237: scanwhite(fcnfile, "FCN_");
238:
239: while (gets(line) != NULL) {
240: if (!isdigit(line[0])) {
241: continue;
242: }
243: plain[0] = shifted[0] = alted[0] = shiftalted[0] = 0;
244: keynumber = -1;
245: scancode = -1;
246: (void) sscanf(line, "%d %x %s %s %s %s", &keynumber,
247: &scancode, plain, shifted, alted, shiftalted);
248: if ((keynumber == -1) || (scancode == -1)
249: || ((plain[0] == 0)
250: && (shifted[0] == 0)
251: && (alted[0] == 0)
252: && (shiftalted[0] == 0))) {
253: continue;
254: }
255: if (scancode >= 256) {
256: fprintf(stderr,
257: "Error: scancode 0x%02x for keynumber %d\n", scancode,
258: keynumber);
259: break;
260: }
261: if (Hits[scancode].hits.hit[0].ctlrfcn != undefined) {
262: fprintf(stderr,
263: "Error: duplicate scancode 0x%02x for keynumber %d\n",
264: scancode, keynumber);
265: break;
266: }
267: hit = Hits[scancode].hits.hit;
268: Hits[scancode].hits.keynumber = keynumber;
269: Hits[scancode].name[0] = doit(hit, plain, &Hits[scancode]);
270: Hits[scancode].name[1] = doit(hit+1, shifted, &Hits[scancode]);
271: Hits[scancode].name[2] = doit(hit+2, alted, &Hits[scancode]);
272: Hits[scancode].name[3] = doit(hit+3, shiftalted, &Hits[scancode]);
273: }
274: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.