add Berkeley specific headers
[unix-history] / usr / src / usr.bin / tn3270 / tools / mkastosc / mkastosc.c
CommitLineData
992de934 1/*
0de390c0
KB
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
992de934 4 *
0de390c0
KB
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of California at Berkeley. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
992de934
GM
11 */
12
13#ifndef lint
0de390c0
KB
14char copyright[] =
15"@(#) Copyright (c) 1988 Regents of the University of California.\n\
16 All rights reserved.\n";
17#endif /* not lint */
992de934 18
0de390c0
KB
19#ifndef lint
20static char sccsid[] = "@(#)mkastosc.c 3.2 (Berkeley) %G%";
21#endif /* not lint */
4c6bedc5
GM
22
23#include <stdio.h>
e56fc5cb 24#if defined(unix)
577b1ba9 25#include <strings.h>
e56fc5cb
GM
26#else /* defined(unix) */
27#include <string.h>
28#endif /* defined(unix) */
4c6bedc5
GM
29#include <ctype.h>
30
03bae598 31#include "../general/general.h"
bfbc528f 32#include "../ctlr/function.h"
4c6bedc5
GM
33
34#include "dohits.h"
35
e56fc5cb 36static struct tbl {
addfa672
GM
37 unsigned char
38 scancode,
39 used;
40 char
41 *shiftstate;
e56fc5cb 42} tbl[128];
4c6bedc5 43
e56fc5cb 44int
d5c90a59
GM
45main(argc, argv)
46int argc;
47char *argv[];
4c6bedc5
GM
48{
49 int scancode;
bfbc528f 50 int asciicode;
4c6bedc5
GM
51 int empty;
52 int i;
bfbc528f 53 int c;
4c6bedc5
GM
54 int found;
55 struct hits *ph;
56 struct Hits *Ph;
4c6bedc5 57 struct thing *this;
addfa672 58 struct thing **attable;
e56fc5cb 59 struct tbl *Pt;
addfa672
GM
60 static char *shiftof[] =
61 { "0", "SHIFT_UPSHIFT", "SHIFT_ALT", "SHIFT_ALT|SHIFT_UPSHIFT" };
d5c90a59 62 char *aidfile = 0, *fcnfile = 0;
4c6bedc5 63
d5c90a59
GM
64 if (argc > 1) {
65 if (argv[1][0] != '-') {
66 aidfile = argv[1];
67 }
68 }
69 if (argc > 2) {
70 if (argv[2][0] != '-') {
71 fcnfile = argv[2];
72 }
73 }
74
75 dohits(aidfile, fcnfile); /* Set up "Hits" */
4c6bedc5 76
bfbc528f
GM
77 printf("/*\n");
78 printf(" * Ascii to scancode conversion table. First\n");
79 printf(" * 128 bytes (0-127) correspond with actual Ascii\n");
addfa672 80 printf(" * characters; the rest are functions from ctrl/function.h\n");
bfbc528f 81 printf(" */\n");
bfbc528f
GM
82 /* Build the ascii part of the table. */
83 for (Ph = Hits, scancode = 0; Ph <= Hits+highestof(Hits);
84 Ph++, scancode++) {
85 ph = &Ph->hits;
86 for (i = 0; i < 4; i++) {
d5c90a59 87 if (ph->hit[i].ctlrfcn == FCN_CHARACTER) {
bfbc528f 88 c = Ph->name[i][0]; /* "name" of this one */
addfa672
GM
89 if (tbl[c].used == 0) {
90 tbl[c].used = 1;
91 tbl[c].shiftstate = shiftof[i];
bfbc528f
GM
92 tbl[c].scancode = scancode;
93 }
94 }
95 }
96 }
97 /* Now, output the table */
98 for (Pt = tbl, asciicode = 0; Pt <= tbl+highestof(tbl); Pt++, asciicode++) {
addfa672 99 if (Pt->used == 0) {
bfbc528f
GM
100 if (isprint(asciicode) && (asciicode != ' ')) {
101 fprintf(stderr, "Unable to produce scancode sequence for");
102 fprintf(stderr, " ASCII character [%c]!\n", asciicode);
103 }
addfa672 104 printf("\t{ 0, 0, undefined, 0 },\t");
bfbc528f 105 } else {
addfa672
GM
106 printf("\t{ 0x%02x, %s, FCN_CHARACTER, 0 },",
107 Pt->scancode, Pt->shiftstate);
bfbc528f
GM
108 }
109 printf("\t/* 0x%x", asciicode);
110 if (isprint(asciicode)) {
111 printf(" [%c]", asciicode);
112 }
113 printf(" */\n");
114 }
115
116
addfa672
GM
117 for (attable = &table[0]; attable <= &table[highestof(table)]; attable++) {
118 for (this = *attable; this; this = this->next) {
119 Ph = this->hits;
120 if (Ph == 0) {
121 continue;
122 }
123 for (i = 0; i < 4; i++) {
124 if ((Ph->name[i] != 0) &&
125 (Ph->name[i][0] == this->name[0]) &&
126 (strcmp(Ph->name[i], this->name) == 0)) {
127 printf("\t{ 0x%02x, %s, ",
128 Ph-Hits, shiftof[i]);
f396c0da 129 if (memcmp("AID_", this->name, 4) == 0) { /* AID key */
addfa672
GM
130 printf("FCN_AID, ");
131 } else {
132 printf("%s, ", Ph->name[i]);
133 }
f396c0da 134 if (memcmp("PF", this->name+4, 2) == 0) {
addfa672
GM
135 printf("\"PFK%s\" },\n", Ph->name[i]+4+2);
136 } else {
137 printf("\"%s\" },\n", Ph->name[i]+4);
4c6bedc5
GM
138 }
139 }
140 }
141 }
4c6bedc5 142 }
e56fc5cb
GM
143
144 return 0;
4c6bedc5 145}