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