1 /*- 2 * Copyright (c) 1988 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 char copyright[] = 10 "@(#) Copyright (c) 1988 The Regents of the University of California.\n\ 11 All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)mkastosc.c 4.2 (Berkeley) 04/26/91"; 16 #endif /* not lint */ 17 18 #include <stdio.h> 19 #if defined(unix) 20 #include <strings.h> 21 #else /* defined(unix) */ 22 #include <string.h> 23 #endif /* defined(unix) */ 24 #include <ctype.h> 25 26 #include "../general/general.h" 27 #include "../ctlr/function.h" 28 29 #include "dohits.h" 30 31 static struct tbl { 32 unsigned char 33 scancode, 34 used; 35 char 36 *shiftstate; 37 } tbl[128]; 38 39 int 40 main(argc, argv) 41 int argc; 42 char *argv[]; 43 { 44 int scancode; 45 int asciicode; 46 int empty; 47 int i; 48 int c; 49 int found; 50 struct hits *ph; 51 struct Hits *Ph; 52 struct thing *this; 53 struct thing **attable; 54 struct tbl *Pt; 55 static char *shiftof[] = 56 { "0", "SHIFT_UPSHIFT", "SHIFT_ALT", "SHIFT_ALT|SHIFT_UPSHIFT" }; 57 char *aidfile = 0, *fcnfile = 0; 58 59 if (argc > 1) { 60 if (argv[1][0] != '-') { 61 aidfile = argv[1]; 62 } 63 } 64 if (argc > 2) { 65 if (argv[2][0] != '-') { 66 fcnfile = argv[2]; 67 } 68 } 69 70 dohits(aidfile, fcnfile); /* Set up "Hits" */ 71 72 printf("/*\n"); 73 printf(" * Ascii to scancode conversion table. First\n"); 74 printf(" * 128 bytes (0-127) correspond with actual Ascii\n"); 75 printf(" * characters; the rest are functions from ctrl/function.h\n"); 76 printf(" */\n"); 77 /* Build the ascii part of the table. */ 78 for (Ph = Hits, scancode = 0; Ph <= Hits+highestof(Hits); 79 Ph++, scancode++) { 80 ph = &Ph->hits; 81 for (i = 0; i < 4; i++) { 82 if (ph->hit[i].ctlrfcn == FCN_CHARACTER) { 83 c = Ph->name[i][0]; /* "name" of this one */ 84 if (tbl[c].used == 0) { 85 tbl[c].used = 1; 86 tbl[c].shiftstate = shiftof[i]; 87 tbl[c].scancode = scancode; 88 } 89 } 90 } 91 } 92 /* Now, output the table */ 93 for (Pt = tbl, asciicode = 0; Pt <= tbl+highestof(tbl); Pt++, asciicode++) { 94 if (Pt->used == 0) { 95 if (isprint(asciicode) && (asciicode != ' ')) { 96 fprintf(stderr, "Unable to produce scancode sequence for"); 97 fprintf(stderr, " ASCII character [%c]!\n", asciicode); 98 } 99 printf("\t{ 0, 0, undefined, 0 },\t"); 100 } else { 101 printf("\t{ 0x%02x, %s, FCN_CHARACTER, 0 },", 102 Pt->scancode, Pt->shiftstate); 103 } 104 printf("\t/* 0x%x", asciicode); 105 if (isprint(asciicode)) { 106 printf(" [%c]", asciicode); 107 } 108 printf(" */\n"); 109 } 110 111 112 for (attable = &table[0]; attable <= &table[highestof(table)]; attable++) { 113 for (this = *attable; this; this = this->next) { 114 Ph = this->hits; 115 if (Ph == 0) { 116 continue; 117 } 118 for (i = 0; i < 4; i++) { 119 if ((Ph->name[i] != 0) && 120 (Ph->name[i][0] == this->name[0]) && 121 (strcmp(Ph->name[i], this->name) == 0)) { 122 printf("\t{ 0x%02x, %s, ", 123 Ph-Hits, shiftof[i]); 124 if (memcmp("AID_", this->name, 4) == 0) { /* AID key */ 125 printf("FCN_AID, "); 126 } else { 127 printf("%s, ", Ph->name[i]); 128 } 129 if (memcmp("PF", this->name+4, 2) == 0) { 130 printf("\"PFK%s\" },\n", Ph->name[i]+4+2); 131 } else { 132 printf("\"%s\" },\n", Ph->name[i]+4); 133 } 134 } 135 } 136 } 137 } 138 139 return 0; 140 } 141