Commit | Line | Data |
---|---|---|
4c6bedc5 GM |
1 | /* |
2 | * This program scans a file which describes a keyboard. The output | |
3 | * of the program is a series of 'C' declarations which describe a | |
4 | * mapping between (scancode, shiftstate, altstate) and 3270 functions, | |
5 | * characters, and AIDs. | |
6 | * | |
7 | * The format of the input file is as follows: | |
8 | * | |
9 | * keynumber [ scancode [ unshifted [ shifted [ alted [ shiftalted ] ] ] ] ] | |
10 | * | |
11 | * keynumber is in decimal, and starts in column 1. | |
12 | * scancode is hexadecimal. | |
13 | * unshifted, etc. - these are either a single ascii character, | |
14 | * or the name of a function or an AID-generating key. | |
15 | * | |
16 | * all fields are separated by a single space. | |
17 | */ | |
18 | ||
19 | #include <stdio.h> | |
e56fc5cb | 20 | #if defined(unix) |
577b1ba9 | 21 | #include <strings.h> |
e56fc5cb GM |
22 | #else /* defined(unix) */ |
23 | #include <string.h> | |
24 | #endif /* defined(unix) */ | |
4c6bedc5 GM |
25 | #include <ctype.h> |
26 | ||
03bae598 | 27 | #include "../general/general.h" |
4c6bedc5 | 28 | #define LETS_SEE_ASCII |
03bae598 | 29 | #include "../ascii/m4.out" |
4c6bedc5 GM |
30 | #undef LETS_SEE_ASCII |
31 | ||
bfbc528f GM |
32 | #include "../ascii/ascebc.h" |
33 | #include "../ctlr/ebc_disp.h" | |
34 | #include "../ctlr/function.h" | |
4c6bedc5 GM |
35 | |
36 | #include "dohits.h" | |
37 | ||
e56fc5cb GM |
38 | static struct tbl { |
39 | char *shift; | |
40 | int scancode; | |
41 | } tbl[128]; | |
4c6bedc5 | 42 | |
e56fc5cb | 43 | int |
d5c90a59 GM |
44 | main(argc, argv) |
45 | int argc; | |
46 | char *argv[]; | |
4c6bedc5 GM |
47 | { |
48 | int scancode; | |
bfbc528f | 49 | int asciicode; |
4c6bedc5 GM |
50 | int empty; |
51 | int i; | |
bfbc528f | 52 | int c; |
4c6bedc5 GM |
53 | int found; |
54 | struct hits *ph; | |
55 | struct Hits *Ph; | |
56 | TC_Ascii_t *TC; | |
57 | struct thing *this; | |
e56fc5cb | 58 | struct tbl *Pt; |
bfbc528f | 59 | static char *shiftof[] = { "normal", "shifted", "alted", "shiftalted" }; |
d5c90a59 | 60 | char *aidfile = 0, *fcnfile = 0; |
4c6bedc5 | 61 | |
d5c90a59 GM |
62 | if (argc > 1) { |
63 | if (argv[1][0] != '-') { | |
64 | aidfile = argv[1]; | |
65 | } | |
66 | } | |
67 | if (argc > 2) { | |
68 | if (argv[2][0] != '-') { | |
69 | fcnfile = argv[2]; | |
70 | } | |
71 | } | |
72 | ||
73 | dohits(aidfile, fcnfile); /* Set up "Hits" */ | |
4c6bedc5 | 74 | |
bfbc528f GM |
75 | printf("/*\n"); |
76 | printf(" * Ascii to scancode conversion table. First\n"); | |
77 | printf(" * 128 bytes (0-127) correspond with actual Ascii\n"); | |
78 | printf(" * characters; the rest are TC types from termcodes.m4\n"); | |
79 | printf(" * (actually, from m4.out).\n"); | |
80 | printf(" */\n"); | |
81 | printf("struct asctosc {\n"); | |
82 | printf("\tenum shiftvalue { cantdo, normal, shifted, alted,"); | |
4c6bedc5 | 83 | printf(" shiftalted } shift;\n\tunsigned char scancode;"); |
bfbc528f GM |
84 | printf("\n} asctosc[] = {\n"); |
85 | /* Build the ascii part of the table. */ | |
86 | for (Ph = Hits, scancode = 0; Ph <= Hits+highestof(Hits); | |
87 | Ph++, scancode++) { | |
88 | ph = &Ph->hits; | |
89 | for (i = 0; i < 4; i++) { | |
d5c90a59 | 90 | if (ph->hit[i].ctlrfcn == FCN_CHARACTER) { |
bfbc528f | 91 | c = Ph->name[i][0]; /* "name" of this one */ |
577b1ba9 | 92 | if ((tbl[c].shift == 0) || (tbl[c].shift[0] == 0)) { |
bfbc528f GM |
93 | tbl[c].shift = shiftof[i]; |
94 | tbl[c].scancode = scancode; | |
95 | } | |
96 | } | |
97 | } | |
98 | } | |
99 | /* Now, output the table */ | |
100 | for (Pt = tbl, asciicode = 0; Pt <= tbl+highestof(tbl); Pt++, asciicode++) { | |
77a3dae5 | 101 | if ((Pt->shift == 0) || (Pt->shift[0] == 0)) { |
bfbc528f GM |
102 | if (isprint(asciicode) && (asciicode != ' ')) { |
103 | fprintf(stderr, "Unable to produce scancode sequence for"); | |
104 | fprintf(stderr, " ASCII character [%c]!\n", asciicode); | |
105 | } | |
106 | printf("\t{ cantdo, 0 },\t"); | |
107 | } else { | |
108 | printf("\t{ %s, 0x%x },", Pt->shift, Pt->scancode); | |
109 | } | |
110 | printf("\t/* 0x%x", asciicode); | |
111 | if (isprint(asciicode)) { | |
112 | printf(" [%c]", asciicode); | |
113 | } | |
114 | printf(" */\n"); | |
115 | } | |
116 | ||
117 | ||
118 | for (TC = &TC_Ascii[TC_LOWEST-TC_LOWEST]; | |
119 | TC < &TC_Ascii[TC_LOWEST_USER-TC_LOWEST]; TC++, asciicode++) { | |
120 | printf("\t{ cantdo, 0 },\t"); | |
121 | printf("\t/* 0x%x */\n", asciicode); | |
122 | } | |
4c6bedc5 | 123 | for (TC = &TC_Ascii[TC_LOWEST_USER-TC_LOWEST]; |
bfbc528f | 124 | TC <= &TC_Ascii[TC_HIGHEST-TC_LOWEST]; TC++, asciicode++) { |
4c6bedc5 GM |
125 | /* Hack for "PFK" names (which should be "PF") */ |
126 | if (memcmp(TC->tc_name, "PFK", 3) == 0) { | |
127 | static char PFonly[100] = "PF"; | |
128 | ||
129 | strcpy(PFonly+2, TC->tc_name+3); | |
130 | TC->tc_name = PFonly; | |
131 | } | |
132 | found = 0; | |
133 | for (this = firstentry(TC->tc_name); (!found) && this; | |
134 | this = this->next) { | |
135 | if ((this->name[4] == TC->tc_name[0]) | |
136 | && (strcmp(this->name+4, TC->tc_name) == 0)) { | |
137 | /* this is the entry */ | |
138 | /* What we have is a TC entry matching a scancode entry */ | |
139 | Ph = this->hits; /* now, get hits */ | |
140 | if (Ph == 0) { | |
141 | continue; | |
142 | } | |
143 | for (i = 0; i < 4; i++) { | |
144 | if ((Ph->name[i][4] == TC->tc_name[0]) | |
145 | && (strcmp(Ph->name[i]+4, TC->tc_name) == 0)) { | |
146 | /* This is THE hit! */ | |
147 | found = 1; | |
148 | printf("\t{ "); | |
149 | switch (i) { | |
150 | case 0: | |
151 | printf("normal, "); | |
152 | break; | |
153 | case 1: | |
154 | printf("shifted, "); | |
155 | break; | |
156 | case 2: | |
157 | printf("alted, "); | |
158 | break; | |
159 | case 3: | |
160 | printf("shitfalted, "); | |
161 | break; | |
162 | } | |
bfbc528f GM |
163 | printf("0x%02x },", Ph-Hits); |
164 | break; | |
4c6bedc5 GM |
165 | } |
166 | } | |
167 | } | |
168 | } | |
169 | if (!found) { | |
bfbc528f | 170 | printf("\t{ cantdo, 0 },\t"); |
4c6bedc5 GM |
171 | fprintf(stderr, "Unable to produce TC_%s with scan codes!\n", |
172 | TC->tc_name); | |
173 | } | |
bfbc528f | 174 | printf("\t/* 0x%x - %s */\n", asciicode, TC->tc_name); |
4c6bedc5 GM |
175 | } |
176 | printf("};\n"); | |
e56fc5cb GM |
177 | |
178 | return 0; | |
4c6bedc5 | 179 | } |