Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / usr.bin / tn3270 / tools / mkastosc / mkastosc.c
blob0c41a07247fea473f8c7185b1c78848ab5b5422c
1 /* $NetBSD: mkastosc.c,v 1.11 2003/08/07 11:16:40 agc Exp $ */
3 /*-
4 * Copyright (c) 1988 The Regents of the University of California.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
32 #include <stdio.h>
33 #include <string.h>
34 #include <ctype.h>
36 #if defined(__COPYRIGHT) && !defined(lint)
37 __COPYRIGHT("@(#) Copyright (c) 1988\
38 The Regents of the University of California. All rights reserved.");
39 #endif /* not lint */
41 #if defined(__RCSID) && !defined(lint)
42 #if 0
43 static char sccsid[] = "@(#)mkastosc.c 4.2 (Berkeley) 4/26/91";
44 #else
45 __RCSID("$NetBSD: mkastosc.c,v 1.11 2003/08/07 11:16:40 agc Exp $");
46 #endif
47 #endif /* not lint */
49 #include "../general/general.h"
50 #include "../ctlr/function.h"
52 #include "dohits.h"
54 static struct tbl {
55 unsigned char
56 scancode,
57 used;
58 const char
59 *shiftstate;
60 } tbl[128];
63 int main(int, char *[]);
65 int
66 main(argc, argv)
67 int argc;
68 char *argv[];
70 int scancode;
71 int asciicode;
72 int i;
73 int c;
74 struct hits *ph;
75 struct Hits *Ph;
76 struct thing *this;
77 struct thing **attable;
78 struct tbl *Pt;
79 static const char *shiftof[] =
80 { "0", "SHIFT_UPSHIFT", "SHIFT_ALT", "SHIFT_ALT|SHIFT_UPSHIFT" };
81 char *aidfile = 0, *fcnfile = 0;
83 if (argc > 1) {
84 if (argv[1][0] != '-') {
85 aidfile = argv[1];
88 if (argc > 2) {
89 if (argv[2][0] != '-') {
90 fcnfile = argv[2];
94 dohits(aidfile, fcnfile); /* Set up "Hits" */
96 printf("/*\n");
97 printf(" * Ascii to scancode conversion table. First\n");
98 printf(" * 128 bytes (0-127) correspond with actual Ascii\n");
99 printf(" * characters; the rest are functions from ctrl/function.h\n");
100 printf(" */\n");
101 /* Build the ascii part of the table. */
102 for (Ph = Hits, scancode = 0; Ph <= Hits+highestof(Hits);
103 Ph++, scancode++) {
104 ph = &Ph->hits;
105 for (i = 0; i < 4; i++) {
106 if (ph->hit[i].ctlrfcn == FCN_CHARACTER) {
107 c = Ph->name[i][0]; /* "name" of this one */
108 if (tbl[c].used == 0) {
109 tbl[c].used = 1;
110 tbl[c].shiftstate = shiftof[i];
111 tbl[c].scancode = scancode;
116 /* Now, output the table */
117 for (Pt = tbl, asciicode = 0; Pt <= tbl+highestof(tbl); Pt++, asciicode++) {
118 if (Pt->used == 0) {
119 if (isprint(asciicode) && (asciicode != ' ')) {
120 fprintf(stderr, "mkastosc: Unable to produce scancode sequence"
121 " for ASCII character [%c]!", asciicode);
123 printf("\t{ 0, 0, undefined, 0 },\t");
124 } else {
125 printf("\t{ 0x%02x, %s, FCN_CHARACTER, 0 },",
126 Pt->scancode, Pt->shiftstate);
128 printf("\t/* 0x%x", asciicode);
129 if (isprint(asciicode)) {
130 printf(" [%c]", asciicode);
132 printf(" */\n");
136 for (attable = &table[0]; attable <= &table[highestof(table)]; attable++) {
137 for (this = *attable; this; this = this->next) {
138 Ph = this->hits;
139 if (Ph == 0) {
140 continue;
142 for (i = 0; i < 4; i++) {
143 if ((Ph->name[i] != 0) &&
144 (Ph->name[i][0] == this->name[0]) &&
145 (strcmp(Ph->name[i], this->name) == 0)) {
146 printf("\t{ 0x%02lx, %s, ",
147 (u_long)(Ph-Hits), shiftof[i]);
148 if (memcmp("AID_", this->name, 4) == 0) { /* AID key */
149 printf("FCN_AID, ");
150 } else {
151 printf("%s, ", Ph->name[i]);
153 if (memcmp("PF", this->name+4, 2) == 0) {
154 printf("\"PFK%s\" },\n", Ph->name[i]+4+2);
155 } else {
156 printf("\"%s\" },\n", Ph->name[i]+4);
163 return 0;