129996Sminshall /* 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 */ 1231896Sminshall 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[] = "@(#)mkhits.c 3.2 (Berkeley) 03/28/88"; 21*33811Sbostic #endif /* not lint */ 22*33811Sbostic 2331896Sminshall /* 2429996Sminshall * This program scans a file which describes a keyboard. The output 2529996Sminshall * of the program is a series of 'C' declarations which describe a 2629996Sminshall * mapping between (scancode, shiftstate, altstate) and 3270 functions, 2729996Sminshall * characters, and AIDs. 2829996Sminshall * 2929996Sminshall * The format of the input file is as follows: 3029996Sminshall * 3129996Sminshall * keynumber [ scancode [ unshifted [ shifted [ alted [ shiftalted ] ] ] ] ] 3229996Sminshall * 3329996Sminshall * keynumber is in decimal, and starts in column 1. 3429996Sminshall * scancode is hexadecimal. 3529996Sminshall * unshifted, etc. - these are either a single ascii character, 3629996Sminshall * or the name of a function or an AID-generating key. 3729996Sminshall * 3829996Sminshall * all fields are separated by a single space. 3929996Sminshall */ 4029996Sminshall 4129996Sminshall #include <stdio.h> 4231102Sminshall #if defined(unix) 4331065Sminshall #include <strings.h> 4431102Sminshall #else /* defined(unix) */ 4531102Sminshall #include <string.h> 4631102Sminshall #endif /* defined(unix) */ 4729996Sminshall #include <ctype.h> 4830052Sminshall #include "../ctlr/function.h" 4929996Sminshall 5029996Sminshall #include "dohits.h" 5129996Sminshall 5229996Sminshall 5331102Sminshall int 5430077Sminshall main(argc, argv) 5530077Sminshall int argc; 5630077Sminshall char *argv[]; 5729996Sminshall { 5829996Sminshall int scancode; 5929996Sminshall int empty; 6029996Sminshall int i; 6129996Sminshall struct hits *ph; 6229996Sminshall struct Hits *Ph; 6330077Sminshall char *aidfile = 0, *fcnfile = 0; 6429996Sminshall 6530077Sminshall if (argc > 1) { 6630077Sminshall if (argv[1][0] != '-') { 6730077Sminshall aidfile = argv[1]; 6830077Sminshall } 6930077Sminshall } 7030077Sminshall if (argc > 2) { 7130077Sminshall if (argv[2][0] != '-') { 7230077Sminshall fcnfile = argv[2]; 7330077Sminshall } 7430077Sminshall } 7529996Sminshall 7630077Sminshall dohits(aidfile, fcnfile); /* Set up "Hits" */ 7730077Sminshall 7829996Sminshall printf("struct hits hits[] = {\n"); 7929996Sminshall empty = 0; 8029996Sminshall scancode = -1; 8129996Sminshall for (Ph = Hits; Ph < Hits+(sizeof Hits/sizeof Hits[0]); Ph++) { 8229996Sminshall ph = &Ph->hits; 8329996Sminshall scancode++; 8430077Sminshall if ((ph->hit[0].ctlrfcn == undefined) 8530077Sminshall && (ph->hit[1].ctlrfcn == undefined) 8630077Sminshall && (ph->hit[2].ctlrfcn == undefined) 8730077Sminshall && (ph->hit[3].ctlrfcn == undefined)) { 8829996Sminshall empty++; 8929996Sminshall continue; 9029996Sminshall } else { 9129996Sminshall while (empty) { 9230077Sminshall printf("\t{ 0, { {undefined}, {undefined}"); 9330077Sminshall printf(", {undefined}, {undefined} } },\n"); 9429996Sminshall empty--; 9529996Sminshall } 9629996Sminshall } 9729996Sminshall printf("\t{ %d, {\t/* 0x%02x */\n\t", ph->keynumber, scancode); 9829996Sminshall for (i = 0; i < 4; i++) { 9929996Sminshall printf("\t{ "); 10030077Sminshall switch (ph->hit[i].ctlrfcn) { 10129996Sminshall case undefined: 10230077Sminshall printf("undefined"); 10329996Sminshall break; 10430077Sminshall case FCN_CHARACTER: 10530077Sminshall printf("FCN_CHARACTER, 0x%02x", ph->hit[i].code); 10629996Sminshall break; 10730077Sminshall case FCN_AID: 10830077Sminshall printf("FCN_AID, %s", Ph->name[i]); 10929996Sminshall break; 11030077Sminshall case FCN_NULL: 11130077Sminshall default: 11230077Sminshall if ((Ph->name[i] != 0) 11330077Sminshall && (strcmp(Ph->name[i], "FCN_NULL") != 0)) { 11430077Sminshall printf("%s", Ph->name[i]); 11530077Sminshall } else { 11630077Sminshall printf("undefined"); 11730077Sminshall } 11829996Sminshall break; 11929996Sminshall } 12029996Sminshall printf(" },\n\t"); 12129996Sminshall } 12229996Sminshall printf("} },\n"); 12329996Sminshall } 12429996Sminshall printf("};\n"); 12531102Sminshall return 0; 12629996Sminshall } 127