129996Sminshall /* 2*31896Sminshall * Copyright (c) 1984-1987 by the Regents of the 3*31896Sminshall * University of California and by Gregory Glenn Minshall. 4*31896Sminshall * 5*31896Sminshall * Permission to use, copy, modify, and distribute these 6*31896Sminshall * programs and their documentation for any purpose and 7*31896Sminshall * without fee is hereby granted, provided that this 8*31896Sminshall * copyright and permission appear on all copies and 9*31896Sminshall * supporting documentation, the name of the Regents of 10*31896Sminshall * the University of California not be used in advertising 11*31896Sminshall * or publicity pertaining to distribution of the programs 12*31896Sminshall * without specific prior permission, and notice be given in 13*31896Sminshall * supporting documentation that copying and distribution is 14*31896Sminshall * by permission of the Regents of the University of California 15*31896Sminshall * and by Gregory Glenn Minshall. Neither the Regents of the 16*31896Sminshall * University of California nor Gregory Glenn Minshall make 17*31896Sminshall * representations about the suitability of this software 18*31896Sminshall * for any purpose. It is provided "as is" without 19*31896Sminshall * express or implied warranty. 20*31896Sminshall */ 21*31896Sminshall 22*31896Sminshall #ifndef lint 23*31896Sminshall static char sccsid[] = "@(#)mkhits.c 1.7 (Berkeley) 07/17/87"; 24*31896Sminshall #endif /* not lint */ 25*31896Sminshall 26*31896Sminshall /* 2729996Sminshall * This program scans a file which describes a keyboard. The output 2829996Sminshall * of the program is a series of 'C' declarations which describe a 2929996Sminshall * mapping between (scancode, shiftstate, altstate) and 3270 functions, 3029996Sminshall * characters, and AIDs. 3129996Sminshall * 3229996Sminshall * The format of the input file is as follows: 3329996Sminshall * 3429996Sminshall * keynumber [ scancode [ unshifted [ shifted [ alted [ shiftalted ] ] ] ] ] 3529996Sminshall * 3629996Sminshall * keynumber is in decimal, and starts in column 1. 3729996Sminshall * scancode is hexadecimal. 3829996Sminshall * unshifted, etc. - these are either a single ascii character, 3929996Sminshall * or the name of a function or an AID-generating key. 4029996Sminshall * 4129996Sminshall * all fields are separated by a single space. 4229996Sminshall */ 4329996Sminshall 4429996Sminshall #include <stdio.h> 4531102Sminshall #if defined(unix) 4631065Sminshall #include <strings.h> 4731102Sminshall #else /* defined(unix) */ 4831102Sminshall #include <string.h> 4931102Sminshall #endif /* defined(unix) */ 5029996Sminshall #include <ctype.h> 5130052Sminshall #include "../ctlr/function.h" 5229996Sminshall 5329996Sminshall #include "dohits.h" 5429996Sminshall 5529996Sminshall 5631102Sminshall int 5730077Sminshall main(argc, argv) 5830077Sminshall int argc; 5930077Sminshall char *argv[]; 6029996Sminshall { 6129996Sminshall int scancode; 6229996Sminshall int empty; 6329996Sminshall int i; 6429996Sminshall struct hits *ph; 6529996Sminshall struct Hits *Ph; 6630077Sminshall char *aidfile = 0, *fcnfile = 0; 6729996Sminshall 6830077Sminshall if (argc > 1) { 6930077Sminshall if (argv[1][0] != '-') { 7030077Sminshall aidfile = argv[1]; 7130077Sminshall } 7230077Sminshall } 7330077Sminshall if (argc > 2) { 7430077Sminshall if (argv[2][0] != '-') { 7530077Sminshall fcnfile = argv[2]; 7630077Sminshall } 7730077Sminshall } 7829996Sminshall 7930077Sminshall dohits(aidfile, fcnfile); /* Set up "Hits" */ 8030077Sminshall 8129996Sminshall printf("struct hits hits[] = {\n"); 8229996Sminshall empty = 0; 8329996Sminshall scancode = -1; 8429996Sminshall for (Ph = Hits; Ph < Hits+(sizeof Hits/sizeof Hits[0]); Ph++) { 8529996Sminshall ph = &Ph->hits; 8629996Sminshall scancode++; 8730077Sminshall if ((ph->hit[0].ctlrfcn == undefined) 8830077Sminshall && (ph->hit[1].ctlrfcn == undefined) 8930077Sminshall && (ph->hit[2].ctlrfcn == undefined) 9030077Sminshall && (ph->hit[3].ctlrfcn == undefined)) { 9129996Sminshall empty++; 9229996Sminshall continue; 9329996Sminshall } else { 9429996Sminshall while (empty) { 9530077Sminshall printf("\t{ 0, { {undefined}, {undefined}"); 9630077Sminshall printf(", {undefined}, {undefined} } },\n"); 9729996Sminshall empty--; 9829996Sminshall } 9929996Sminshall } 10029996Sminshall printf("\t{ %d, {\t/* 0x%02x */\n\t", ph->keynumber, scancode); 10129996Sminshall for (i = 0; i < 4; i++) { 10229996Sminshall printf("\t{ "); 10330077Sminshall switch (ph->hit[i].ctlrfcn) { 10429996Sminshall case undefined: 10530077Sminshall printf("undefined"); 10629996Sminshall break; 10730077Sminshall case FCN_CHARACTER: 10830077Sminshall printf("FCN_CHARACTER, 0x%02x", ph->hit[i].code); 10929996Sminshall break; 11030077Sminshall case FCN_AID: 11130077Sminshall printf("FCN_AID, %s", Ph->name[i]); 11229996Sminshall break; 11330077Sminshall case FCN_NULL: 11430077Sminshall default: 11530077Sminshall if ((Ph->name[i] != 0) 11630077Sminshall && (strcmp(Ph->name[i], "FCN_NULL") != 0)) { 11730077Sminshall printf("%s", Ph->name[i]); 11830077Sminshall } else { 11930077Sminshall printf("undefined"); 12030077Sminshall } 12129996Sminshall break; 12229996Sminshall } 12329996Sminshall printf(" },\n\t"); 12429996Sminshall } 12529996Sminshall printf("} },\n"); 12629996Sminshall } 12729996Sminshall printf("};\n"); 12831102Sminshall return 0; 12929996Sminshall } 130