129998Sminshall /* 229998Sminshall * This program scans a file which describes a keyboard. The output 329998Sminshall * of the program is a series of 'C' declarations which describe a 429998Sminshall * mapping between (scancode, shiftstate, altstate) and 3270 functions, 529998Sminshall * characters, and AIDs. 629998Sminshall * 729998Sminshall * The format of the input file is as follows: 829998Sminshall * 929998Sminshall * keynumber [ scancode [ unshifted [ shifted [ alted [ shiftalted ] ] ] ] ] 1029998Sminshall * 1129998Sminshall * keynumber is in decimal, and starts in column 1. 1229998Sminshall * scancode is hexadecimal. 1329998Sminshall * unshifted, etc. - these are either a single ascii character, 1429998Sminshall * or the name of a function or an AID-generating key. 1529998Sminshall * 1629998Sminshall * all fields are separated by a single space. 1729998Sminshall */ 1829998Sminshall 1929998Sminshall #include <stdio.h> 2029998Sminshall #include <string.h> 2129998Sminshall #include <ctype.h> 2229998Sminshall 2329998Sminshall #define LETS_SEE_ASCII 24*30052Sminshall #include "../keyboard/m4.out" 2529998Sminshall #undef LETS_SEE_ASCII 2629998Sminshall 27*30052Sminshall #include "../ascii/ascebc.h" 28*30052Sminshall #include "../ctlr/ebc_disp.h" 29*30052Sminshall #include "../ctlr/function.h" 3029998Sminshall 3129998Sminshall #include "dohits.h" 3229998Sminshall 3329998Sminshall 3429998Sminshall void 3529998Sminshall main() 3629998Sminshall { 3729998Sminshall int scancode; 38*30052Sminshall int asciicode; 3929998Sminshall int empty; 4029998Sminshall int i; 41*30052Sminshall int c; 4229998Sminshall int found; 4329998Sminshall struct hits *ph; 4429998Sminshall struct Hits *Ph; 4529998Sminshall TC_Ascii_t *TC; 4629998Sminshall struct thing *this; 47*30052Sminshall struct { 48*30052Sminshall char *shift; 49*30052Sminshall int scancode; 50*30052Sminshall } tbl[128], *Pt; 51*30052Sminshall static char *shiftof[] = { "normal", "shifted", "alted", "shiftalted" }; 5229998Sminshall 5329998Sminshall dohits(); /* Set up "Hits" */ 5429998Sminshall 55*30052Sminshall printf("/*\n"); 56*30052Sminshall printf(" * Ascii to scancode conversion table. First\n"); 57*30052Sminshall printf(" * 128 bytes (0-127) correspond with actual Ascii\n"); 58*30052Sminshall printf(" * characters; the rest are TC types from termcodes.m4\n"); 59*30052Sminshall printf(" * (actually, from m4.out).\n"); 60*30052Sminshall printf(" */\n"); 61*30052Sminshall printf("struct asctosc {\n"); 62*30052Sminshall printf("\tenum shiftvalue { cantdo, normal, shifted, alted,"); 6329998Sminshall printf(" shiftalted } shift;\n\tunsigned char scancode;"); 64*30052Sminshall printf("\n} asctosc[] = {\n"); 65*30052Sminshall /* Build the ascii part of the table. */ 66*30052Sminshall for (Ph = Hits, scancode = 0; Ph <= Hits+highestof(Hits); 67*30052Sminshall Ph++, scancode++) { 68*30052Sminshall ph = &Ph->hits; 69*30052Sminshall for (i = 0; i < 4; i++) { 70*30052Sminshall if (ph->hit[i].type == character) { 71*30052Sminshall c = Ph->name[i][0]; /* "name" of this one */ 72*30052Sminshall if (tbl[c].shift[0] == 0) { 73*30052Sminshall tbl[c].shift = shiftof[i]; 74*30052Sminshall tbl[c].scancode = scancode; 75*30052Sminshall } 76*30052Sminshall } 77*30052Sminshall } 78*30052Sminshall } 79*30052Sminshall /* Now, output the table */ 80*30052Sminshall for (Pt = tbl, asciicode = 0; Pt <= tbl+highestof(tbl); Pt++, asciicode++) { 81*30052Sminshall if (Pt->shift[0] == 0) { 82*30052Sminshall if (isprint(asciicode) && (asciicode != ' ')) { 83*30052Sminshall fprintf(stderr, "Unable to produce scancode sequence for"); 84*30052Sminshall fprintf(stderr, " ASCII character [%c]!\n", asciicode); 85*30052Sminshall } 86*30052Sminshall printf("\t{ cantdo, 0 },\t"); 87*30052Sminshall } else { 88*30052Sminshall printf("\t{ %s, 0x%x },", Pt->shift, Pt->scancode); 89*30052Sminshall } 90*30052Sminshall printf("\t/* 0x%x", asciicode); 91*30052Sminshall if (isprint(asciicode)) { 92*30052Sminshall printf(" [%c]", asciicode); 93*30052Sminshall } 94*30052Sminshall printf(" */\n"); 95*30052Sminshall } 96*30052Sminshall 97*30052Sminshall 98*30052Sminshall for (TC = &TC_Ascii[TC_LOWEST-TC_LOWEST]; 99*30052Sminshall TC < &TC_Ascii[TC_LOWEST_USER-TC_LOWEST]; TC++, asciicode++) { 100*30052Sminshall printf("\t{ cantdo, 0 },\t"); 101*30052Sminshall printf("\t/* 0x%x */\n", asciicode); 102*30052Sminshall } 10329998Sminshall for (TC = &TC_Ascii[TC_LOWEST_USER-TC_LOWEST]; 104*30052Sminshall TC <= &TC_Ascii[TC_HIGHEST-TC_LOWEST]; TC++, asciicode++) { 10529998Sminshall /* Hack for "PFK" names (which should be "PF") */ 10629998Sminshall if (memcmp(TC->tc_name, "PFK", 3) == 0) { 10729998Sminshall static char PFonly[100] = "PF"; 10829998Sminshall 10929998Sminshall strcpy(PFonly+2, TC->tc_name+3); 11029998Sminshall TC->tc_name = PFonly; 11129998Sminshall } 11229998Sminshall found = 0; 11329998Sminshall for (this = firstentry(TC->tc_name); (!found) && this; 11429998Sminshall this = this->next) { 11529998Sminshall if ((this->name[4] == TC->tc_name[0]) 11629998Sminshall && (strcmp(this->name+4, TC->tc_name) == 0)) { 11729998Sminshall /* this is the entry */ 11829998Sminshall /* What we have is a TC entry matching a scancode entry */ 11929998Sminshall Ph = this->hits; /* now, get hits */ 12029998Sminshall if (Ph == 0) { 12129998Sminshall continue; 12229998Sminshall } 12329998Sminshall for (i = 0; i < 4; i++) { 12429998Sminshall if ((Ph->name[i][4] == TC->tc_name[0]) 12529998Sminshall && (strcmp(Ph->name[i]+4, TC->tc_name) == 0)) { 12629998Sminshall /* This is THE hit! */ 12729998Sminshall found = 1; 12829998Sminshall printf("\t{ "); 12929998Sminshall switch (i) { 13029998Sminshall case 0: 13129998Sminshall printf("normal, "); 13229998Sminshall break; 13329998Sminshall case 1: 13429998Sminshall printf("shifted, "); 13529998Sminshall break; 13629998Sminshall case 2: 13729998Sminshall printf("alted, "); 13829998Sminshall break; 13929998Sminshall case 3: 14029998Sminshall printf("shitfalted, "); 14129998Sminshall break; 14229998Sminshall } 143*30052Sminshall printf("0x%02x },", Ph-Hits); 144*30052Sminshall break; 14529998Sminshall } 14629998Sminshall } 14729998Sminshall } 14829998Sminshall } 14929998Sminshall if (!found) { 150*30052Sminshall printf("\t{ cantdo, 0 },\t"); 15129998Sminshall fprintf(stderr, "Unable to produce TC_%s with scan codes!\n", 15229998Sminshall TC->tc_name); 15329998Sminshall } 154*30052Sminshall printf("\t/* 0x%x - %s */\n", asciicode, TC->tc_name); 15529998Sminshall } 15629998Sminshall printf("};\n"); 15729998Sminshall } 158