1 /* 2 * Copyright (c) 1984-1987 by the Regents of the 3 * University of California and by Gregory Glenn Minshall. 4 * 5 * Permission to use, copy, modify, and distribute these 6 * programs and their documentation for any purpose and 7 * without fee is hereby granted, provided that this 8 * copyright and permission appear on all copies and 9 * supporting documentation, the name of the Regents of 10 * the University of California not be used in advertising 11 * or publicity pertaining to distribution of the programs 12 * without specific prior permission, and notice be given in 13 * supporting documentation that copying and distribution is 14 * by permission of the Regents of the University of California 15 * and by Gregory Glenn Minshall. Neither the Regents of the 16 * University of California nor Gregory Glenn Minshall make 17 * representations about the suitability of this software 18 * for any purpose. It is provided "as is" without 19 * express or implied warranty. 20 */ 21 22 #ifndef lint 23 static char sccsid[] = "@(#)mkastosc.c 3.1 (Berkeley) 08/11/87"; 24 #endif /* not lint */ 25 26 27 #include <stdio.h> 28 #if defined(unix) 29 #include <strings.h> 30 #else /* defined(unix) */ 31 #include <string.h> 32 #endif /* defined(unix) */ 33 #include <ctype.h> 34 35 #include "../general/general.h" 36 #include "../ctlr/function.h" 37 38 #include "dohits.h" 39 40 static struct tbl { 41 unsigned char 42 scancode, 43 used; 44 char 45 *shiftstate; 46 } tbl[128]; 47 48 int 49 main(argc, argv) 50 int argc; 51 char *argv[]; 52 { 53 int scancode; 54 int asciicode; 55 int empty; 56 int i; 57 int c; 58 int found; 59 struct hits *ph; 60 struct Hits *Ph; 61 struct thing *this; 62 struct thing **attable; 63 struct tbl *Pt; 64 static char *shiftof[] = 65 { "0", "SHIFT_UPSHIFT", "SHIFT_ALT", "SHIFT_ALT|SHIFT_UPSHIFT" }; 66 char *aidfile = 0, *fcnfile = 0; 67 68 if (argc > 1) { 69 if (argv[1][0] != '-') { 70 aidfile = argv[1]; 71 } 72 } 73 if (argc > 2) { 74 if (argv[2][0] != '-') { 75 fcnfile = argv[2]; 76 } 77 } 78 79 dohits(aidfile, fcnfile); /* Set up "Hits" */ 80 81 printf("/*\n"); 82 printf(" * Ascii to scancode conversion table. First\n"); 83 printf(" * 128 bytes (0-127) correspond with actual Ascii\n"); 84 printf(" * characters; the rest are functions from ctrl/function.h\n"); 85 printf(" */\n"); 86 /* Build the ascii part of the table. */ 87 for (Ph = Hits, scancode = 0; Ph <= Hits+highestof(Hits); 88 Ph++, scancode++) { 89 ph = &Ph->hits; 90 for (i = 0; i < 4; i++) { 91 if (ph->hit[i].ctlrfcn == FCN_CHARACTER) { 92 c = Ph->name[i][0]; /* "name" of this one */ 93 if (tbl[c].used == 0) { 94 tbl[c].used = 1; 95 tbl[c].shiftstate = shiftof[i]; 96 tbl[c].scancode = scancode; 97 } 98 } 99 } 100 } 101 /* Now, output the table */ 102 for (Pt = tbl, asciicode = 0; Pt <= tbl+highestof(tbl); Pt++, asciicode++) { 103 if (Pt->used == 0) { 104 if (isprint(asciicode) && (asciicode != ' ')) { 105 fprintf(stderr, "Unable to produce scancode sequence for"); 106 fprintf(stderr, " ASCII character [%c]!\n", asciicode); 107 } 108 printf("\t{ 0, 0, undefined, 0 },\t"); 109 } else { 110 printf("\t{ 0x%02x, %s, FCN_CHARACTER, 0 },", 111 Pt->scancode, Pt->shiftstate); 112 } 113 printf("\t/* 0x%x", asciicode); 114 if (isprint(asciicode)) { 115 printf(" [%c]", asciicode); 116 } 117 printf(" */\n"); 118 } 119 120 121 for (attable = &table[0]; attable <= &table[highestof(table)]; attable++) { 122 for (this = *attable; this; this = this->next) { 123 Ph = this->hits; 124 if (Ph == 0) { 125 continue; 126 } 127 for (i = 0; i < 4; i++) { 128 if ((Ph->name[i] != 0) && 129 (Ph->name[i][0] == this->name[0]) && 130 (strcmp(Ph->name[i], this->name) == 0)) { 131 printf("\t{ 0x%02x, %s, ", 132 Ph-Hits, shiftof[i]); 133 if (memcmp("AID_", this->name, 4) == 0) { /* AID key */ 134 printf("FCN_AID, "); 135 } else { 136 printf("%s, ", Ph->name[i]); 137 } 138 if (memcmp("PF", this->name+4, 2) == 0) { 139 printf("\"PFK%s\" },\n", Ph->name[i]+4+2); 140 } else { 141 printf("\"%s\" },\n", Ph->name[i]+4); 142 } 143 } 144 } 145 } 146 } 147 148 return 0; 149 } 150