131896Sminshall /*
2*33811Sbostic  * Copyright (c) 1988 Regents of the University of California.
3*33811Sbostic  * All rights reserved.
431896Sminshall  *
5*33811Sbostic  * Redistribution and use in source and binary forms are permitted
6*33811Sbostic  * provided that this notice is preserved and that due credit is given
7*33811Sbostic  * to the University of California at Berkeley. The name of the University
8*33811Sbostic  * may not be used to endorse or promote products derived from this
9*33811Sbostic  * software without specific prior written permission. This software
10*33811Sbostic  * is provided ``as is'' without express or implied warranty.
1131896Sminshall  */
1229998Sminshall 
1331896Sminshall #ifndef lint
14*33811Sbostic char copyright[] =
15*33811Sbostic "@(#) Copyright (c) 1988 Regents of the University of California.\n\
16*33811Sbostic  All rights reserved.\n";
17*33811Sbostic #endif /* not lint */
1831896Sminshall 
19*33811Sbostic #ifndef lint
20*33811Sbostic static char sccsid[] = "@(#)mkastosc.c	3.2 (Berkeley) 03/28/88";
21*33811Sbostic #endif /* not lint */
2231896Sminshall 
2329998Sminshall #include <stdio.h>
2431102Sminshall #if	defined(unix)
2531065Sminshall #include <strings.h>
2631102Sminshall #else	/* defined(unix) */
2731102Sminshall #include <string.h>
2831102Sminshall #endif	/* defined(unix) */
2929998Sminshall #include <ctype.h>
3029998Sminshall 
3131175Sminshall #include "../general/general.h"
3230052Sminshall #include "../ctlr/function.h"
3329998Sminshall 
3429998Sminshall #include "dohits.h"
3529998Sminshall 
3631102Sminshall static struct tbl {
3731246Sminshall     unsigned char
3831246Sminshall 	scancode,
3931246Sminshall 	used;
4031246Sminshall     char
4131246Sminshall 	*shiftstate;
4231102Sminshall } tbl[128];
4329998Sminshall 
4431102Sminshall int
4530077Sminshall main(argc, argv)
4630077Sminshall int	argc;
4730077Sminshall char	*argv[];
4829998Sminshall {
4929998Sminshall     int scancode;
5030052Sminshall     int asciicode;
5129998Sminshall     int empty;
5229998Sminshall     int i;
5330052Sminshall     int c;
5429998Sminshall     int found;
5529998Sminshall     struct hits *ph;
5629998Sminshall     struct Hits *Ph;
5729998Sminshall     struct thing *this;
5831246Sminshall     struct thing **attable;
5931102Sminshall     struct tbl *Pt;
6031246Sminshall     static char *shiftof[] =
6131246Sminshall 	    { "0", "SHIFT_UPSHIFT", "SHIFT_ALT", "SHIFT_ALT|SHIFT_UPSHIFT" };
6230077Sminshall     char *aidfile = 0, *fcnfile = 0;
6329998Sminshall 
6430077Sminshall     if (argc > 1) {
6530077Sminshall 	if (argv[1][0] != '-') {
6630077Sminshall 	    aidfile = argv[1];
6730077Sminshall 	}
6830077Sminshall     }
6930077Sminshall     if (argc > 2) {
7030077Sminshall 	if (argv[2][0] != '-') {
7130077Sminshall 	    fcnfile = argv[2];
7230077Sminshall 	}
7330077Sminshall     }
7429998Sminshall 
7530077Sminshall     dohits(aidfile, fcnfile);		/* Set up "Hits" */
7630077Sminshall 
7730052Sminshall     printf("/*\n");
7830052Sminshall     printf(" * Ascii to scancode conversion table.  First\n");
7930052Sminshall     printf(" * 128 bytes (0-127) correspond with actual Ascii\n");
8031246Sminshall     printf(" * characters; the rest are functions from ctrl/function.h\n");
8130052Sminshall     printf(" */\n");
8230052Sminshall     /* Build the ascii part of the table. */
8330052Sminshall     for (Ph = Hits, scancode = 0; Ph <= Hits+highestof(Hits);
8430052Sminshall 							Ph++, scancode++) {
8530052Sminshall 	ph = &Ph->hits;
8630052Sminshall 	for (i = 0; i < 4; i++) {
8730077Sminshall 	    if (ph->hit[i].ctlrfcn == FCN_CHARACTER) {
8830052Sminshall 		c = Ph->name[i][0];	/* "name" of this one */
8931246Sminshall 		if (tbl[c].used == 0) {
9031246Sminshall 		    tbl[c].used = 1;
9131246Sminshall 		    tbl[c].shiftstate = shiftof[i];
9230052Sminshall 		    tbl[c].scancode = scancode;
9330052Sminshall 		}
9430052Sminshall 	    }
9530052Sminshall 	}
9630052Sminshall     }
9730052Sminshall     /* Now, output the table */
9830052Sminshall     for (Pt = tbl, asciicode = 0; Pt <= tbl+highestof(tbl); Pt++, asciicode++) {
9931246Sminshall 	if (Pt->used == 0) {
10030052Sminshall 	    if (isprint(asciicode) && (asciicode != ' ')) {
10130052Sminshall 		fprintf(stderr, "Unable to produce scancode sequence for");
10230052Sminshall 		fprintf(stderr, " ASCII character [%c]!\n", asciicode);
10330052Sminshall 	    }
10431246Sminshall 	    printf("\t{ 0, 0, undefined, 0 },\t");
10530052Sminshall 	} else {
10631246Sminshall 	    printf("\t{ 0x%02x, %s, FCN_CHARACTER, 0 },",
10731246Sminshall 					Pt->scancode, Pt->shiftstate);
10830052Sminshall 	}
10930052Sminshall 	printf("\t/* 0x%x", asciicode);
11030052Sminshall 	if (isprint(asciicode)) {
11130052Sminshall 	    printf(" [%c]", asciicode);
11230052Sminshall 	}
11330052Sminshall 	printf(" */\n");
11430052Sminshall     }
11530052Sminshall 
11630052Sminshall 
11731246Sminshall     for (attable = &table[0]; attable <= &table[highestof(table)]; attable++) {
11831246Sminshall 	for (this = *attable; this; this = this->next) {
11931246Sminshall 	    Ph = this->hits;
12031246Sminshall 	    if (Ph == 0) {
12131246Sminshall 		continue;
12231246Sminshall 	    }
12331246Sminshall 	    for (i = 0; i < 4; i++) {
12431246Sminshall 		if ((Ph->name[i] != 0) &&
12531246Sminshall 			(Ph->name[i][0] == this->name[0]) &&
12631246Sminshall 			(strcmp(Ph->name[i], this->name) == 0)) {
12731246Sminshall 		    printf("\t{ 0x%02x, %s, ",
12831246Sminshall 				Ph-Hits, shiftof[i]);
12931247Sminshall 		    if (memcmp("AID_", this->name, 4) == 0) {	/* AID key */
13031246Sminshall 			printf("FCN_AID, ");
13131246Sminshall 		    } else {
13231246Sminshall 			printf("%s, ", Ph->name[i]);
13329998Sminshall 		    }
13431247Sminshall 		    if (memcmp("PF", this->name+4, 2) == 0) {
13531246Sminshall 			printf("\"PFK%s\" },\n", Ph->name[i]+4+2);
13631246Sminshall 		    } else {
13731246Sminshall 			printf("\"%s\" },\n", Ph->name[i]+4);
13831246Sminshall 		    }
13929998Sminshall 		}
14029998Sminshall 	    }
14129998Sminshall 	}
14229998Sminshall     }
14331102Sminshall 
14431102Sminshall     return 0;
14529998Sminshall }
146