summaryrefslogtreecommitdiff
path: root/comms/tn3270/files/tools/mkhits
diff options
context:
space:
mode:
authordholland <dholland@pkgsrc.org>2010-01-17 01:33:16 +0000
committerdholland <dholland@pkgsrc.org>2010-01-17 01:33:16 +0000
commit996a15a26aacec2c22f5147ddd1fe2c4b230bc90 (patch)
tree059459d9cd3a55813e0f4c7af61277165ab8755f /comms/tn3270/files/tools/mkhits
parent9f9f3b9474c359d804dffed896865b40b537c17e (diff)
downloadpkgsrc-996a15a26aacec2c22f5147ddd1fe2c4b230bc90.tar.gz
Import tn3270 from base as of 20100114, just before its removal. This
is just the sources, and they're unchanged from base except that the rcsids have been preserved. The package will be along shortly.
Diffstat (limited to 'comms/tn3270/files/tools/mkhits')
-rw-r--r--comms/tn3270/files/tools/mkhits/Makefile8
-rw-r--r--comms/tn3270/files/tools/mkhits/dohits.c300
-rw-r--r--comms/tn3270/files/tools/mkhits/dohits.h56
-rw-r--r--comms/tn3270/files/tools/mkhits/mkhits.c144
4 files changed, 508 insertions, 0 deletions
diff --git a/comms/tn3270/files/tools/mkhits/Makefile b/comms/tn3270/files/tools/mkhits/Makefile
new file mode 100644
index 00000000000..6dbfcc791eb
--- /dev/null
+++ b/comms/tn3270/files/tools/mkhits/Makefile
@@ -0,0 +1,8 @@
+# $NetBSD: Makefile,v 1.1.1.1 2010/01/17 01:33:26 dholland Exp $
+# From NetBSD: Makefile,v 1.10 2002/09/15 01:27:47 thorpej Exp
+
+HOSTPROG= mkhits
+HOST_CPPFLAGS+= -DHOST_TOOL
+SRCS= mkhits.c dohits.c asc_ebc.c ebc_disp.c
+
+.include <bsd.hostprog.mk>
diff --git a/comms/tn3270/files/tools/mkhits/dohits.c b/comms/tn3270/files/tools/mkhits/dohits.c
new file mode 100644
index 00000000000..df7eeba146d
--- /dev/null
+++ b/comms/tn3270/files/tools/mkhits/dohits.c
@@ -0,0 +1,300 @@
+/* $NetBSD: dohits.c,v 1.1.1.1 2010/01/17 01:33:26 dholland Exp $ */
+/* From NetBSD: dohits.c,v 1.14 2006/04/22 18:02:26 christos Exp */
+
+/*-
+ * Copyright (c) 1988 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(__RCSID) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)dohits.c 4.2 (Berkeley) 4/26/91";
+#else
+__RCSID("$NetBSD: dohits.c,v 1.1.1.1 2010/01/17 01:33:26 dholland Exp $");
+#endif
+#endif /* not lint */
+
+/*
+ * This program scans a file which describes a keyboard. The output
+ * of the program is a series of 'C' declarations which describe a
+ * mapping between (scancode, shiftstate, altstate) and 3270 functions,
+ * characters, and AIDs.
+ *
+ * The format of the input file is as follows:
+ *
+ * keynumber [ scancode [ unshifted [ shifted [ alted [ shiftalted ] ] ] ] ]
+ *
+ * keynumber is in decimal, and starts in column 1.
+ * scancode is hexadecimal.
+ * unshifted, etc. - these are either a single ascii character,
+ * or the name of a function or an AID-generating key.
+ *
+ * all fields are separated by a single space.
+ */
+
+#include "../general/general.h"
+#include "../api/asc_ebc.h"
+#include "../api/ebc_disp.h"
+#include "../ctlr/function.h"
+
+#include "dohits.h"
+
+struct Hits Hits[256]; /* one for each of 0x00-0xff */
+
+struct thing *table[100];
+
+static void add(const char *, const char *, int);
+static void scanwhite(const char *, const char *);
+static void scandefine(const char *, const char *);
+static char *savechr(unsigned int);
+static char *doit(struct hit *, unsigned char *, struct Hits *);
+
+unsigned int
+dohash(seed, string)
+unsigned int seed;
+const char *string;
+{
+ unsigned int i = seed;
+ unsigned char c;
+
+ while ((c = *string++) != '\0') {
+ if (c >= 0x60) {
+ c -= (0x60+0x20);
+ } else {
+ c -= 0x20;
+ }
+ i = (i>>26) + (i<<6) + (c&0x3f);
+ }
+ return i;
+}
+
+static void
+add(first, second, value)
+const char *first, *second;
+int value;
+{
+ struct thing **item, *this;
+
+ item = &firstentry(second);
+ this = (struct thing *) malloc(sizeof *this);
+ this->hits = 0;
+ this->next = *item;
+ *item = this;
+ this->value = value;
+ strcpy(this->name, first);
+ strcpy(this->name+strlen(this->name), second);
+}
+
+static void
+scanwhite(file, prefix)
+const char *file, /* Name of file to scan for whitespace prefix */
+ *prefix; /* prefix of what should be picked up */
+{
+ FILE *ourfile;
+ char compare[100];
+ char what[100];
+ char line[200];
+
+ (void) snprintf(compare, sizeof(compare), " %s%%[^,\t \n]", prefix);
+ if ((ourfile = fopen(file, "r")) == NULL) {
+ fprintf(stderr, "Cannot open `%s': %s\n", file, strerror(errno));
+ exit(1);
+ }
+ while (!feof(ourfile)) {
+ if (fscanf(ourfile, compare, what) == 1) {
+ add(prefix, what, 0);
+ }
+ do {
+ if (fgets(line, sizeof line, ourfile) == NULL) {
+ if (!feof(ourfile)) {
+ fprintf(stderr, "fgets failed: %s\n", strerror(errno));
+ }
+ break;
+ }
+ } while (line[strlen(line)-1] != '\n');
+ }
+ (void)fclose(ourfile);
+}
+
+static void
+scandefine(file, prefix)
+const char *file, /* Name of file to scan for #define prefix */
+ *prefix; /* prefix of what should be picked up */
+{
+ FILE *ourfile;
+ char compare[100];
+ char what[100], value[100];
+ char line[200];
+ int whatitis;
+
+ snprintf(compare, sizeof(compare), "#define %s%%s %%s", prefix);
+ if ((ourfile = fopen(file, "r")) == NULL) {
+ fprintf(stderr, "Cannot open `%s': %s\n", file, strerror(errno));
+ exit(1);
+ }
+
+ while (!feof(ourfile)) {
+ if (fscanf(ourfile, compare, what, value) == 2) {
+ if (value[0] == '0') {
+ if ((value[1] == 'x') || (value[1] == 'X')) {
+ sscanf(value, "0x%x", &whatitis);
+ } else {
+ sscanf(value, "0%o", &whatitis);
+ }
+ } else {
+ sscanf(value, "%d", &whatitis);
+ }
+ add(prefix, what, whatitis);
+ }
+ do {
+ if (fgets(line, sizeof line, ourfile) == NULL) {
+ if (!feof(ourfile)) {
+ fprintf(stderr, "End of file with error: %s\n",
+ strerror(errno));
+ }
+ break;
+ }
+ } while (line[strlen(line)-1] != '\n');
+ }
+ (void)fclose(ourfile);
+}
+
+static char *savechr(c)
+unsigned int c;
+{
+ char *foo = malloc(sizeof(unsigned char));
+ if (foo == NULL) {
+ fprintf(stderr, "No room for ascii characters\n");
+ exit(1);
+ }
+ *foo = c;
+ return foo;
+}
+
+static char *
+doit(hit, type, hits)
+struct hit *hit;
+unsigned char *type;
+struct Hits *hits;
+{
+ struct thing *this;
+
+ hit->ctlrfcn = FCN_NULL;
+ if (type[0] == 0) {
+ return 0;
+ }
+ if (type[1] == 0) { /* character */
+ hit->ctlrfcn = FCN_CHARACTER;
+ hit->code = ebc_disp[asc_ebc[type[0]]];
+ return savechr(*type); /* The character is the name */
+ } else {
+ for (this = firstentry(type); this; this = this->next) {
+ if ((type[0] == this->name[4])
+ && (strcmp(type, this->name+4) == 0)) {
+ this->hits = hits;
+ if (this->name[0] == 'F') {
+ hit->ctlrfcn = FCN_NULL; /* XXX */
+ } else {
+ hit->ctlrfcn = FCN_AID;
+ }
+ return this->name;
+ }
+ }
+ fprintf(stderr, "Unknown type %s.\n", type);
+ return 0;
+ }
+}
+
+
+void
+dohits(aidfile, fcnfile)
+const char *aidfile, *fcnfile;
+{
+ unsigned char plain[100], shifted[100], alted[100], shiftalted[100];
+ unsigned char line[200];
+ int keynumber, scancode;
+ struct hit *hit;
+
+ memset((char *)Hits, 0, sizeof Hits);
+
+ /*
+ * First, we read "host3270.h" to find the names/values of
+ * various AID; then we read kbd3270.h to find the names/values
+ * of various FCNs.
+ */
+
+ if (aidfile == 0) {
+ aidfile = "../ctlr/hostctlr.h";
+ }
+ scandefine(aidfile, "AID_");
+ if (fcnfile == 0) {
+ fcnfile = "../ctlr/function.h";
+ }
+ scanwhite(fcnfile, "FCN_");
+
+ while (fgets(line, sizeof(line), stdin) != NULL) {
+ if (line[strlen(line)-1] == '\n')
+ line[strlen(line)-1] = '\0';
+ if (!isdigit(line[0])) {
+ continue;
+ }
+ plain[0] = shifted[0] = alted[0] = shiftalted[0] = 0;
+ keynumber = -1;
+ scancode = -1;
+ (void) sscanf(line, "%d %x %s %s %s %s", &keynumber,
+ &scancode, plain, shifted, alted, shiftalted);
+ if ((keynumber == -1) || (scancode == -1)
+ || ((plain[0] == 0)
+ && (shifted[0] == 0)
+ && (alted[0] == 0)
+ && (shiftalted[0] == 0))) {
+ continue;
+ }
+ if (scancode >= 256) {
+ fprintf(stderr, "Scancode 0x%02x for keynumber %d\n", scancode,
+ keynumber);
+ break;
+ }
+ if (Hits[scancode].hits.hit[0].ctlrfcn != undefined) {
+ fprintf(stderr, "Duplicate scancode 0x%02x for keynumber %d\n",
+ scancode, keynumber);
+ break;
+ }
+ hit = Hits[scancode].hits.hit;
+ Hits[scancode].hits.keynumber = keynumber;
+ Hits[scancode].name[0] = doit(hit, plain, &Hits[scancode]);
+ Hits[scancode].name[1] = doit(hit+1, shifted, &Hits[scancode]);
+ Hits[scancode].name[2] = doit(hit+2, alted, &Hits[scancode]);
+ Hits[scancode].name[3] = doit(hit+3, shiftalted, &Hits[scancode]);
+ }
+}
diff --git a/comms/tn3270/files/tools/mkhits/dohits.h b/comms/tn3270/files/tools/mkhits/dohits.h
new file mode 100644
index 00000000000..df6fa43daad
--- /dev/null
+++ b/comms/tn3270/files/tools/mkhits/dohits.h
@@ -0,0 +1,56 @@
+/* $NetBSD: dohits.h,v 1.1.1.1 2010/01/17 01:33:26 dholland Exp $ */
+/* From NetBSD: dohits.h,v 1.7 2003/08/07 11:16:42 agc Exp */
+
+/*-
+ * Copyright (c) 1988 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)dohits.h 4.2 (Berkeley) 4/26/91
+ */
+
+#define numberof(x) (sizeof x/sizeof x[0])
+#define highestof(x) (numberof(x)-1)
+
+#define firstentry(x) (table[dohash(0, (x))%highestof(table)])
+
+struct Hits {
+ struct hits hits;
+ char *name[4];
+};
+
+struct thing {
+ struct thing *next;
+ struct Hits *hits;
+ unsigned char value;
+ char name[100];
+};
+
+extern struct Hits Hits[256]; /* one for each of 0x00-0xff */
+extern struct thing *table[100];
+
+void dohits(const char *, const char *);
+unsigned int dohash(unsigned int, const char *);
diff --git a/comms/tn3270/files/tools/mkhits/mkhits.c b/comms/tn3270/files/tools/mkhits/mkhits.c
new file mode 100644
index 00000000000..2b6e9e578e1
--- /dev/null
+++ b/comms/tn3270/files/tools/mkhits/mkhits.c
@@ -0,0 +1,144 @@
+/* $NetBSD: mkhits.c,v 1.1.1.1 2010/01/17 01:33:26 dholland Exp $ */
+/* From NetBSD: mkhits.c,v 1.11 2008/07/21 14:19:27 lukem Exp */
+
+/*-
+ * Copyright (c) 1988 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#if defined(__COPYRIGHT) && !defined(lint)
+__COPYRIGHT("@(#) Copyright (c) 1988\
+ The Regents of the University of California. All rights reserved.");
+#endif /* not lint */
+
+#if defined(__RCSID) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)mkhits.c 4.2 (Berkeley) 4/26/91";
+#else
+__RCSID("$NetBSD: mkhits.c,v 1.1.1.1 2010/01/17 01:33:26 dholland Exp $");
+#endif
+#endif /* not lint */
+
+/*
+ * This program scans a file which describes a keyboard. The output
+ * of the program is a series of 'C' declarations which describe a
+ * mapping between (scancode, shiftstate, altstate) and 3270 functions,
+ * characters, and AIDs.
+ *
+ * The format of the input file is as follows:
+ *
+ * keynumber [ scancode [ unshifted [ shifted [ alted [ shiftalted ] ] ] ] ]
+ *
+ * keynumber is in decimal, and starts in column 1.
+ * scancode is hexadecimal.
+ * unshifted, etc. - these are either a single ascii character,
+ * or the name of a function or an AID-generating key.
+ *
+ * all fields are separated by a single space.
+ */
+
+#include "../ctlr/function.h"
+
+#include "dohits.h"
+
+int main(int, char *[]);
+
+int
+main(int argc, char *argv[])
+{
+ int scancode;
+ int empty;
+ int i;
+ struct hits *ph;
+ struct Hits *Ph;
+ char *aidfile = 0, *fcnfile = 0;
+
+ if (argc > 1) {
+ if (argv[1][0] != '-') {
+ aidfile = argv[1];
+ }
+ }
+ if (argc > 2) {
+ if (argv[2][0] != '-') {
+ fcnfile = argv[2];
+ }
+ }
+
+ dohits(aidfile, fcnfile); /* Set up "Hits" */
+
+ printf("struct hits hits[] = {\n");
+ empty = 0;
+ scancode = -1;
+ for (Ph = Hits; Ph < Hits+(sizeof Hits/sizeof Hits[0]); Ph++) {
+ ph = &Ph->hits;
+ scancode++;
+ if ((ph->hit[0].ctlrfcn == undefined)
+ && (ph->hit[1].ctlrfcn == undefined)
+ && (ph->hit[2].ctlrfcn == undefined)
+ && (ph->hit[3].ctlrfcn == undefined)) {
+ empty++;
+ continue;
+ } else {
+ while (empty) {
+ printf("\t{ 0, { {undefined}, {undefined}");
+ printf(", {undefined}, {undefined} } },\n");
+ empty--;
+ }
+ }
+ printf("\t{ %d, {\t/* 0x%02x */\n\t", ph->keynumber, scancode);
+ for (i = 0; i < 4; i++) {
+ printf("\t{ ");
+ switch (ph->hit[i].ctlrfcn) {
+ case undefined:
+ printf("undefined");
+ break;
+ case FCN_CHARACTER:
+ printf("FCN_CHARACTER, 0x%02x", ph->hit[i].code);
+ break;
+ case FCN_AID:
+ printf("FCN_AID, %s", Ph->name[i]);
+ break;
+ case FCN_NULL:
+ default:
+ if ((Ph->name[i] != 0)
+ && (strcmp(Ph->name[i], "FCN_NULL") != 0)) {
+ printf("%s", Ph->name[i]);
+ } else {
+ printf("undefined");
+ }
+ break;
+ }
+ printf(" },\n\t");
+ }
+ printf("} },\n");
+ }
+ printf("};\n");
+ return 0;
+}