summaryrefslogtreecommitdiffstats
path: root/usr.bin/tn3270/api
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/tn3270/api')
-rw-r--r--usr.bin/tn3270/api/api_bsd.c281
-rw-r--r--usr.bin/tn3270/api/api_exch.c429
-rw-r--r--usr.bin/tn3270/api/api_exch.h161
-rw-r--r--usr.bin/tn3270/api/apilib.c411
-rw-r--r--usr.bin/tn3270/api/apilib.h44
-rw-r--r--usr.bin/tn3270/api/asc_ebc.c110
-rw-r--r--usr.bin/tn3270/api/asc_ebc.h51
-rw-r--r--usr.bin/tn3270/api/astosc.c98
-rw-r--r--usr.bin/tn3270/api/astosc.h58
-rw-r--r--usr.bin/tn3270/api/dctype.c245
-rw-r--r--usr.bin/tn3270/api/dctype.h54
-rw-r--r--usr.bin/tn3270/api/disp_asc.c45
-rw-r--r--usr.bin/tn3270/api/disp_asc.h43
-rw-r--r--usr.bin/tn3270/api/ebc_disp.c106
-rw-r--r--usr.bin/tn3270/api/ebc_disp.h38
15 files changed, 2174 insertions, 0 deletions
diff --git a/usr.bin/tn3270/api/api_bsd.c b/usr.bin/tn3270/api/api_bsd.c
new file mode 100644
index 0000000..46db372
--- /dev/null
+++ b/usr.bin/tn3270/api/api_bsd.c
@@ -0,0 +1,281 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)api_bsd.c 8.2 (Berkeley) 1/7/94";
+#endif /* not lint */
+
+#if defined(unix)
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <stdio.h>
+
+#include "../ctlr/api.h"
+#include "api_exch.h"
+
+
+int
+api_close_api()
+{
+ if (api_exch_outcommand(EXCH_CMD_DISASSOCIATE) == -1) {
+ return -1;
+ } else if (api_exch_flush() == -1) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+
+int
+api_open_api(string)
+char *string; /* if non-zero, where to connect to */
+{
+ struct sockaddr_in server;
+ struct hostent *hp;
+ struct storage_descriptor sd;
+ extern char *getenv();
+ char thehostname[100];
+ char keyname[100];
+ char inkey[100];
+ FILE *keyfile;
+ int sock;
+ unsigned int port;
+ int i;
+
+ if (string == 0) {
+ string = getenv("API3270"); /* Get API */
+ if (string == 0) {
+ fprintf(stderr,
+ "API3270 environmental variable not set - no API.\n");
+ return -1; /* Nothing */
+ }
+ }
+
+ if (sscanf(string, "%[^:]:%d:%s", thehostname,
+ (int *)&port, keyname) != 3) {
+ fprintf(stderr, "API3270 environmental variable has bad format.\n");
+ return -1;
+ }
+ /* Now, try to connect */
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+ if (sock < 0) {
+ perror("opening API socket");
+ return -1;
+ }
+ server.sin_family = AF_INET;
+ hp = gethostbyname(thehostname);
+ if (hp == 0) {
+ fprintf(stderr, "%s specifies bad host name.\n", string);
+ return -1;
+ }
+ bcopy(hp->h_addr, (char *)&server.sin_addr, hp->h_length);
+ server.sin_port = htons(port);
+
+ if (connect(sock, (struct sockaddr *)&server, sizeof server) < 0) {
+ perror("connecting to API server");
+ return -1;
+ }
+ /* Now, try application level connection */
+ if (api_exch_init(sock, "client") == -1) {
+ return -1;
+ }
+ if (api_exch_outcommand(EXCH_CMD_ASSOCIATE) == -1) {
+ return -1;
+ }
+ keyfile = fopen(keyname, "r");
+ if (keyfile == 0) {
+ perror("fopen");
+ return -1;
+ }
+ if (fscanf(keyfile, "%s\n", inkey) != 1) {
+ perror("fscanf");
+ return -1;
+ }
+ sd.length = strlen(inkey)+1;
+ if (api_exch_outtype(EXCH_TYPE_STORE_DESC, sizeof sd, (char *)&sd) == -1) {
+ return -1;
+ }
+ if (api_exch_outtype(EXCH_TYPE_BYTES, sd.length, inkey) == -1) {
+ return -1;
+ }
+ while ((i = api_exch_nextcommand()) != EXCH_CMD_ASSOCIATED) {
+ int passwd_length;
+ char *passwd, *getpass();
+ char buffer[200];
+
+ switch (i) {
+ case EXCH_CMD_REJECTED:
+ if (api_exch_intype(EXCH_TYPE_STORE_DESC,
+ sizeof sd, (char *)&sd) == -1) {
+ return -1;
+ }
+ if (api_exch_intype(EXCH_TYPE_BYTES, sd.length, buffer) == -1) {
+ return -1;
+ }
+ buffer[sd.length] = 0;
+ fprintf(stderr, "%s\n", buffer);
+ if (api_exch_outcommand(EXCH_CMD_ASSOCIATE) == -1) {
+ return -1;
+ }
+ break;
+ case EXCH_CMD_SEND_AUTH:
+ if (api_exch_intype(EXCH_TYPE_STORE_DESC, sizeof sd, (char *)&sd) == -1) {
+ return -1;
+ }
+ if (api_exch_intype(EXCH_TYPE_BYTES, sd.length, buffer) == -1) {
+ return -1;
+ }
+ buffer[sd.length] = 0;
+ passwd = getpass(buffer); /* Go to terminal */
+ passwd_length = strlen(passwd);
+ if (api_exch_intype(EXCH_TYPE_STORE_DESC, sizeof sd, (char *)&sd) == -1) {
+ return -1;
+ }
+ if (api_exch_intype(EXCH_TYPE_BYTES, sd.length, buffer) == -1) {
+ return -1;
+ }
+ buffer[sd.length] = 0;
+ if (sd.length) {
+ char *ptr;
+
+ ptr = passwd;
+ i = 0;
+ while (*ptr) {
+ *ptr++ ^= buffer[i++];
+ if (i >= sd.length) {
+ i = 0;
+ }
+ }
+ }
+ sd.length = passwd_length;
+ if (api_exch_outcommand(EXCH_CMD_AUTH) == -1) {
+ return -1;
+ }
+ if (api_exch_outtype(EXCH_TYPE_STORE_DESC, sizeof sd, (char *)&sd) == -1) {
+ return -1;
+ }
+ if (api_exch_outtype(EXCH_TYPE_BYTES, passwd_length, passwd) == -1) {
+ return -1;
+ }
+ break;
+ case -1:
+ return -1;
+ default:
+ fprintf(stderr,
+ "Waiting for connection indicator, received 0x%x.\n", i);
+ break;
+ }
+ }
+ /* YEAH */
+ return 0; /* Happiness! */
+}
+
+
+api_exch_api(regs, sregs, parms, length)
+union REGS *regs;
+struct SREGS *sregs;
+char *parms;
+int length;
+{
+ struct storage_descriptor sd;
+ int i;
+
+ if (api_exch_outcommand(EXCH_CMD_REQUEST) == -1) {
+ return -1;
+ }
+ if (api_exch_outtype(EXCH_TYPE_REGS, sizeof *regs, (char *)regs) == -1) {
+ return -1;
+ }
+ if (api_exch_outtype(EXCH_TYPE_SREGS, sizeof *sregs, (char *)sregs) == -1) {
+ return -1;
+ }
+ sd.length = length;
+ sd.location = (long) parms;
+ if (api_exch_outtype(EXCH_TYPE_STORE_DESC, sizeof sd, (char *)&sd) == -1) {
+ return -1;
+ }
+ if (api_exch_outtype(EXCH_TYPE_BYTES, length, parms) == -1) {
+ return -1;
+ }
+ while ((i = api_exch_nextcommand()) != EXCH_CMD_REPLY) {
+ switch (i) {
+ case EXCH_CMD_GIMME:
+ if (api_exch_intype(EXCH_TYPE_STORE_DESC, sizeof sd, (char *)&sd)
+ == -1) {
+ return -1;
+ }
+ /*XXX validity check GIMME? */
+ if (api_exch_outcommand(EXCH_CMD_HEREIS) == -1) {
+ return -1;
+ }
+ if (api_exch_outtype(EXCH_TYPE_STORE_DESC, sizeof sd, (char *)&sd)
+ == -1) {
+ return -1;
+ }
+ if (api_exch_outtype(EXCH_TYPE_BYTES, sd.length,
+ (char *)sd.location) == -1) {
+ return -1;
+ }
+ break;
+ case EXCH_CMD_HEREIS:
+ if (api_exch_intype(EXCH_TYPE_STORE_DESC, sizeof sd, (char *)&sd)
+ == -1) {
+ return -1;
+ }
+ /* XXX Validty check HEREIS? */
+ if (api_exch_intype(EXCH_TYPE_BYTES, sd.length,
+ (char *)sd.location) == -1) {
+ return -1;
+ }
+ break;
+ default:
+ fprintf(stderr, "Waiting for reply command, we got command %d.\n",
+ i);
+ return -1;
+ }
+ }
+ if (api_exch_intype(EXCH_TYPE_REGS, sizeof *regs, (char *)regs) == -1) {
+ return -1;
+ }
+ if (api_exch_intype(EXCH_TYPE_SREGS, sizeof *sregs, (char *)sregs) == -1) {
+ return -1;
+ }
+ /* YEAH */
+ return 0; /* Happiness! */
+}
+
+#endif /* unix */
diff --git a/usr.bin/tn3270/api/api_exch.c b/usr.bin/tn3270/api/api_exch.c
new file mode 100644
index 0000000..a4626b9
--- /dev/null
+++ b/usr.bin/tn3270/api/api_exch.c
@@ -0,0 +1,429 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)api_exch.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
+
+#include <stdio.h>
+
+#include "../general/general.h"
+
+#include "api_exch.h"
+
+static int sock; /* Socket number */
+
+static char whoarewe[40] = "";
+#define WHO_ARE_WE() fprintf(stderr, "(API %s) ", whoarewe);
+
+static enum {CONTENTION, SEND, RECEIVE } conversation;
+
+static struct exch_exch exch_state;
+
+static unsigned int
+ my_sequence,
+ your_sequence;
+
+static char ibuffer[4000], *ibuf_next, *ibuf_last;
+#define IBUFADDED(i) ibuf_last += (i)
+#define IBUFAVAILABLE() (ibuf_last-ibuf_next)
+#define IBUFFER() ibuffer
+#define IBUFFREE() (ibuffer+sizeof ibuffer-ibuf_last-1)
+#define IBUFGETBYTES(w,l) { memcpy(w, ibuf_next, l); ibuf_next += l; }
+#define IBUFRESET() (ibuf_next = ibuf_last = ibuffer)
+
+char obuffer[4000], *obuf_next;
+#define OBUFADDBYTES(w,l) { memcpy(obuf_next, w, l); obuf_next += l; }
+#define OBUFAVAILABLE() (obuf_next - obuffer)
+#define OBUFFER() obuffer
+#define OBUFRESET() obuf_next = obuffer
+#define OBUFROOM() (obuffer+sizeof obuffer-obuf_next)
+
+
+static int
+outflush()
+{
+ int length = OBUFAVAILABLE();
+
+ if (length != 0) {
+ if (write(sock, OBUFFER(), length) != length) {
+ WHO_ARE_WE();
+ perror("write");
+ return -1;
+ }
+ OBUFRESET();
+ }
+ return 0; /* All OK */
+}
+
+
+static int
+iget(location, length)
+char *location;
+int length;
+{
+ int count;
+
+ if (OBUFAVAILABLE()) {
+ if (outflush() == -1) {
+ return -1;
+ }
+ }
+ if ((count = IBUFAVAILABLE()) != 0) {
+ if (count > length) {
+ count = length;
+ }
+ IBUFGETBYTES(location, count);
+ length -= count;
+ location += count;
+ }
+ while (length) {
+ if (ibuf_next == ibuf_last) {
+ IBUFRESET();
+ }
+ if ((count = read(sock, IBUFFER(), IBUFFREE())) < 0) {
+ WHO_ARE_WE();
+ perror("read");
+ return -1;
+ }
+ if (count == 0) {
+ /* Reading past end-of-file */
+ WHO_ARE_WE();
+ fprintf(stderr, "End of file read\r\n");
+ return -1;
+ }
+ IBUFADDED(count);
+ if (count > length) {
+ count = length;
+ }
+ IBUFGETBYTES(location, count);
+ length -= count;
+ location += count;
+ }
+ return 0;
+}
+
+static char *
+exch_to_ascii(exch)
+int exch; /* opcode to decode */
+{
+ switch (exch) {
+ case EXCH_EXCH_COMMAND:
+ return "Command";
+ case EXCH_EXCH_TYPE:
+ return "Type";
+ case EXCH_EXCH_TURNAROUND:
+ return "Turnaround";
+ case EXCH_EXCH_RTS:
+ return "Request to Send";
+ default:
+ {
+ static char unknown[40];
+
+ sprintf(unknown, "(Unknown exchange 0x%02x)", exch&0xff);
+ return unknown;
+ }
+ }
+}
+
+/*
+ * Send the exch structure, updating the sequnce number field.
+ */
+
+static int
+send_state()
+{
+ if (OBUFROOM() < sizeof exch_state) {
+ if (outflush() == -1) {
+ return -1;
+ }
+ }
+ my_sequence = (my_sequence+1)&0xff;
+ exch_state.my_sequence = my_sequence;
+ exch_state.your_sequence = your_sequence;
+ OBUFADDBYTES((char *)&exch_state, sizeof exch_state);
+ return 0;
+}
+
+/*
+ * Receive the exch structure from the other side, checking
+ * sequence numbering.
+ */
+
+static int
+receive_state()
+{
+ if (iget((char *)&exch_state, sizeof exch_state) == -1) {
+ return -1;
+ }
+ if (conversation != CONTENTION) {
+ if (exch_state.your_sequence != my_sequence) {
+ WHO_ARE_WE();
+ fprintf(stderr, "Send sequence number mismatch.\n");
+ return -1;
+ }
+ if (exch_state.my_sequence != ((++your_sequence)&0xff)) {
+ WHO_ARE_WE();
+ fprintf(stderr, "Receive sequence number mismatch.\n");
+ return -1;
+ }
+ }
+ your_sequence = exch_state.my_sequence;
+ return 0;
+}
+
+static int
+enter_receive()
+{
+ switch (conversation) {
+ case CONTENTION:
+ exch_state.opcode = EXCH_EXCH_TURNAROUND;
+ if (send_state() == -1) {
+ return -1;
+ }
+ if (receive_state() == -1) {
+ return -1;
+ }
+ if (exch_state.opcode != EXCH_EXCH_RTS) {
+ WHO_ARE_WE();
+ fprintf(stderr, "In CONTENTION state: ");
+ if (exch_state.opcode == EXCH_EXCH_TURNAROUND) {
+ fprintf(stderr,
+ "Both sides tried to enter RECEIVE state.\n");
+ } else {
+ fprintf(stderr,
+ "Protocol error trying to enter RECEIVE state.\n");
+ }
+ return -1;
+ }
+ break;
+ case SEND:
+ exch_state.opcode = EXCH_EXCH_TURNAROUND;
+ if (send_state() == -1) {
+ return -1;
+ }
+ break;
+ }
+ conversation = RECEIVE;
+ return 0;
+}
+
+static int
+enter_send()
+{
+ switch (conversation) {
+ case CONTENTION:
+ exch_state.opcode = EXCH_EXCH_RTS;
+ if (send_state() == -1) {
+ return -1;
+ }
+ /* fall through */
+ case RECEIVE:
+ if (receive_state() == -1) {
+ return -1;
+ }
+ if (exch_state.opcode != EXCH_EXCH_TURNAROUND) {
+ WHO_ARE_WE();
+ fprintf(stderr, "Conversation error - both sides in SEND state.\n");
+ return -1;
+ }
+ }
+ conversation = SEND;
+ return 0;
+}
+
+int
+api_exch_nextcommand()
+{
+ if (conversation != RECEIVE) {
+ if (enter_receive() == -1) {
+ return -1;
+ }
+ }
+ if (receive_state() == -1) {
+ return -1;
+ }
+ if (exch_state.opcode != EXCH_EXCH_COMMAND) {
+ WHO_ARE_WE();
+ fprintf(stderr, "Expected a %s exchange, received a %s exchange.\n",
+ exch_to_ascii(EXCH_EXCH_COMMAND), exch_to_ascii(exch_state.opcode));
+ return -1;
+ }
+ return exch_state.command_or_type;
+}
+
+
+int
+api_exch_incommand(command)
+int command;
+{
+ int i;
+
+ if ((i = api_exch_nextcommand()) == -1) {
+ return -1;
+ }
+ if (i != command) {
+ WHO_ARE_WE();
+ fprintf(stderr, "Expected API command 0x%x, got API command 0x%x.\n",
+ command, i);
+ return -1;
+ }
+ return 0;
+}
+
+
+int
+api_exch_outcommand(command)
+int command;
+{
+ if (conversation != SEND) {
+ if (enter_send() == -1) {
+ return -1;
+ }
+ }
+ exch_state.command_or_type = command;
+ exch_state.opcode = EXCH_EXCH_COMMAND;
+ if (send_state() == -1) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+
+int
+api_exch_outtype(type, length, location)
+int
+ type,
+ length;
+char
+ *location;
+{
+ int netleng = length;
+
+ if (conversation != SEND) {
+ if (enter_send() == -1) {
+ return -1;
+ }
+ }
+ exch_state.opcode = EXCH_EXCH_TYPE;
+ exch_state.command_or_type = type;
+ exch_state.length = netleng;
+ if (send_state() == -1) {
+ return -1;
+ }
+ if (length) {
+ if (OBUFROOM() > length) {
+ OBUFADDBYTES(location, length);
+ } else {
+ if (outflush() == -1) {
+ return -1;
+ }
+ if (write(sock, location, length) != length) {
+ WHO_ARE_WE();
+ perror("write");
+ return -1;
+ }
+ }
+ }
+ return 0;
+}
+
+
+int
+api_exch_intype(type, length, location)
+int
+ type,
+ length;
+char
+ *location;
+{
+ int netleng = length;
+
+ if (conversation != RECEIVE) {
+ if (enter_receive() == -1) {
+ return -1;
+ }
+ }
+ if (receive_state() == -1) {
+ return -1;
+ }
+ if (exch_state.opcode != EXCH_EXCH_TYPE) {
+ WHO_ARE_WE();
+ fprintf(stderr,
+ "Expected to receive a %s exchange, received a %s exchange.\n",
+ exch_to_ascii(EXCH_EXCH_TYPE), exch_to_ascii(exch_state.opcode));
+ return -1;
+ }
+ if (exch_state.command_or_type != type) {
+ WHO_ARE_WE();
+ fprintf(stderr, "Expected type 0x%x, got type 0x%x.\n",
+ type, exch_state.command_or_type);
+ return -1;
+ }
+ if (exch_state.length != netleng) {
+ fprintf(stderr, "Type 0x%x - expected length %d, received length %u.\n",
+ type, length, exch_state.length);
+ return -1;
+ }
+ if (iget(location, length) == -1) {
+ return -1;
+ }
+ return 0;
+}
+
+int
+api_exch_flush()
+{
+ return outflush();
+}
+
+int
+api_exch_init(sock_number, ourname)
+int sock_number;
+char *ourname;
+{
+ extern char *strcpy();
+
+ sock = sock_number;
+ (void) strcpy(whoarewe, ourname); /* For error messages */
+
+ my_sequence = your_sequence = 0;
+
+ conversation = CONTENTION; /* We don't know which direction */
+
+ IBUFRESET();
+ OBUFRESET();
+
+ return 0;
+}
diff --git a/usr.bin/tn3270/api/api_exch.h b/usr.bin/tn3270/api/api_exch.h
new file mode 100644
index 0000000..24e6691
--- /dev/null
+++ b/usr.bin/tn3270/api/api_exch.h
@@ -0,0 +1,161 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ *
+ * @(#)api_exch.h 8.1 (Berkeley) 6/6/93
+ */
+
+/*
+ * This file describes the structures passed back and forth
+ * between the API client and API server on a Unix-based
+ * tn3270 implementation.
+ */
+
+/*
+ * The following are the low-level opcodes exchanged between the
+ * two sides. These are designed to allow for type, sequence number,
+ * and direction checking.
+ *
+ * We enforce conversation flow. There are three states: CONTENTION,
+ * SEND, and RECEIVE. Both sides start in CONTENTION.
+ * We never leave RECEIVE state without first reading a TURNAROUND
+ * opcode. We never leave SEND state without first writing a TURNAROUND
+ * opcode. This scheme ensures that we always have conversation flowing
+ * in a synchronized direction (or detect an application error), and that
+ * we never hang with both sides trying to read from the "wire".
+ *
+ * State event action
+ *
+ * CONTENTION read request send TURNAROUND
+ * read RTS
+ * enter RECEIVE
+ * CONTENTION write request send RTS
+ * read TURNAROUND
+ * enter SEND
+ *
+ * RECEIVE read request read whatever
+ * RECEIVE write request read TURNAROUND
+ *
+ * SEND read request send TURNAROUND
+ * SEND write write whatever
+ */
+
+#define EXCH_EXCH_COMMAND 0 /* The following is a command */
+#define EXCH_EXCH_TURNAROUND 1 /* Your turn to send */
+#define EXCH_EXCH_RTS 2 /* Request to send */
+#define EXCH_EXCH_TYPE 3 /* The following is a type */
+
+struct exch_exch {
+ char
+ opcode; /* COMMAND, TURNAROUND, or TYPE */
+ unsigned char
+ my_sequence, /* 0-ff, initially zero */
+ your_sequence, /* 0-ff, initially zero */
+ command_or_type; /* Application level command or type */
+ unsigned short
+ length; /* The length of any following data */
+};
+
+/*
+ * The following are the command codes which the higher level protocols
+ * send and receive.
+ */
+
+#define EXCH_CMD_ASSOCIATE 0 /* Connect [client->server] */
+ /*
+ * struct storage_desc
+ * char key[]
+ */
+#define EXCH_CMD_DISASSOCIATE 1 /* Disconnect [client->server] */
+#define EXCH_CMD_SEND_AUTH 2 /* Send password [server->client] */
+ /*
+ * struct storage_desc
+ * char prompt[]
+ * struct storage_desc
+ * char seed[]
+ */
+#define EXCH_CMD_AUTH 3 /* Authorization [client->server] */
+ /*
+ * struct storage_desc
+ * char authenticator[]
+ */
+#define EXCH_CMD_ASSOCIATED 4 /* Connected [server->client] */
+#define EXCH_CMD_REJECTED 5 /* Too bad [server->client] */
+ /*
+ * struct storage_desc
+ * char message[]
+ */
+
+#define EXCH_CMD_REQUEST 6 /* A request [client->server] */
+ /* struct regs,
+ * struct sregs,
+ * struct storage_desc
+ * char bytes[]
+ */
+#define EXCH_CMD_GIMME 7 /* Send storage [server->client] */
+ /*
+ * struct storage_desc
+ */
+#define EXCH_CMD_HEREIS 8 /* Here is storage [BOTH WAYS] */
+ /*
+ * struct storage_desc
+ * char bytes[]
+ */
+#define EXCH_CMD_REPLY 9 /* End of discussion */
+ /*
+ * struct regs,
+ * struct sregs,
+ */
+
+/*
+ * The following are typed parameters sent across the wire.
+ *
+ * This should be done much more generally, with some form of
+ * XDR or mapped conversation ability.
+ */
+
+#define EXCH_TYPE_REGS 0
+#define EXCH_TYPE_SREGS 1
+#define EXCH_TYPE_STORE_DESC 2
+#define EXCH_TYPE_BYTES 3
+
+/*
+ * each parameter that comes over looks like:
+ *
+ * char type of following
+ * short (2 bytes) length of following (network byte order)
+ * following
+ */
+
+struct storage_descriptor {
+ long location; /* In network byte order */
+ short length; /* In network byte order */
+};
diff --git a/usr.bin/tn3270/api/apilib.c b/usr.bin/tn3270/api/apilib.c
new file mode 100644
index 0000000..3146170
--- /dev/null
+++ b/usr.bin/tn3270/api/apilib.c
@@ -0,0 +1,411 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)apilib.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
+
+#include "../ctlr/api.h"
+
+#include "apilib.h"
+
+int
+ api_sup_errno = 0, /* Supervisor error number */
+ api_sup_fcn_id = 0, /* Supervisor function id (0x12) */
+ api_fcn_errno = 0, /* Function error number */
+ api_fcn_fcn_id = 0; /* Function ID (0x6b, etc.) */
+
+static int
+ gate_sessmgr = 0,
+ gate_keyboard = 0,
+ gate_copy = 0,
+ gate_oiam = 0;
+
+/*
+ * Issue an API request, with reg structures supplied by the caller.
+ *
+ * Only certain routines need this (supervisor services come to mind).
+ */
+
+static int
+api_issue_regs(ah, al, bh, bl, cx, dx, parms, length, regs, sregs)
+int ah, al, bh, bl, cx, dx;
+char *parms;
+int length;
+union REGS *regs;
+struct SREGS *sregs;
+{
+ char far *ourseg = parms;
+
+ regs->h.ah = ah;
+ regs->h.al = al;
+ regs->h.bh = bh;
+ regs->h.bl = bl;
+ regs->x.cx = cx;
+ regs->x.dx = dx;
+ sregs->es = FP_SEG(ourseg);
+ regs->x.di = FP_OFF(ourseg);
+
+#if defined(MSDOS)
+ int86x(API_INTERRUPT_NUMBER, regs, regs, sregs);
+#endif /* defined(MSDOS) */
+#if defined(unix)
+ api_exch_api(regs, sregs, parms, length);
+#endif /* defined(unix) */
+
+ if (regs->h.cl != 0) {
+ api_sup_errno = regs->h.cl;
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+
+/*
+ * Issue an API request without requiring caller to supply
+ * registers. Most routines use this.
+ */
+
+static int
+api_issue(ah, al, bh, bl, cx, dx, parms, length)
+int
+ ah,
+ al,
+ bh,
+ bl,
+ cx,
+ dx;
+char *parms;
+int length; /* Length of parms */
+{
+ union REGS regs;
+ struct SREGS sregs;
+
+ return api_issue_regs(ah, al, bh, bl, cx, dx, parms, length, &regs, &sregs);
+}
+
+/*
+ * Supervisor Services
+ */
+
+int
+api_name_resolve(name)
+char *name;
+{
+ NameResolveParms parms;
+ int i;
+ union REGS regs;
+ struct SREGS sregs;
+
+ for (i = 0; i < sizeof parms.gate_name; i++) {
+ if (*name) {
+ parms.gate_name[i] = *name++;
+ } else {
+ parms.gate_name[i] = ' ';
+ }
+ }
+
+ if (api_issue_regs(NAME_RESOLUTION, 0, 0, 0, 0, 0, (char *) &parms,
+ sizeof parms, &regs, &sregs) == -1) {
+ return -1;
+ } else {
+ return regs.x.dx;
+ }
+}
+
+#if defined(unix)
+/*
+ * Block until the oia or ps is modified.
+ */
+
+int
+api_ps_or_oia_modified()
+{
+ union REGS regs;
+ struct SREGS sregs;
+
+ if (api_issue_regs(PS_OR_OIA_MODIFIED, 0, 0, 0, 0, 0, (char *) 0,
+ 0, &regs, &sregs) == -1) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+#endif /* defined(unix) */
+
+/*
+ * Session Information Services
+ */
+
+api_query_session_id(parms)
+QuerySessionIdParms *parms;
+{
+ if (api_issue(0x09, QUERY_SESSION_ID, 0x80, 0x20, 0,
+ gate_sessmgr, (char *)parms, sizeof *parms) == -1) {
+ api_fcn_errno = 0;
+ api_fcn_fcn_id = 0;
+ return -1;
+ } else if (parms->rc == 0) {
+ return 0;
+ } else {
+ api_fcn_errno = parms->rc;
+ api_fcn_fcn_id = parms->function_id;
+ return -1;
+ }
+}
+
+
+api_query_session_parameters(parms)
+QuerySessionParametersParms *parms;
+{
+ if (api_issue(0x09, QUERY_SESSION_PARAMETERS, 0x80, 0x20, 0,
+ gate_sessmgr, (char *)parms, sizeof *parms) == -1) {
+ api_fcn_errno = 0;
+ api_fcn_fcn_id = 0;
+ return -1;
+ } else if (parms->rc == 0) {
+ return 0;
+ } else {
+ api_fcn_errno = parms->rc;
+ api_fcn_fcn_id = parms->function_id;
+ return -1;
+ }
+}
+
+api_query_session_cursor(parms)
+QuerySessionCursorParms *parms;
+{
+ if (api_issue(0x09, QUERY_SESSION_CURSOR, 0x80, 0x20, 0xff,
+ gate_sessmgr, (char *)parms, sizeof *parms) == -1) {
+ api_fcn_errno = 0;
+ api_fcn_fcn_id = 0;
+ return -1;
+ } else if (parms->rc == 0) {
+ return 0;
+ } else {
+ api_fcn_errno = parms->rc;
+ api_fcn_fcn_id = parms->function_id;
+ return -1;
+ }
+}
+
+/*
+ * Keyboard Services
+ */
+
+api_connect_to_keyboard(parms)
+ConnectToKeyboardParms *parms;
+{
+ if (api_issue(0x09, CONNECT_TO_KEYBOARD, 0x80, 0x20, 0,
+ gate_keyboard, (char *)parms, sizeof *parms) == -1) {
+ api_fcn_errno = 0;
+ api_fcn_fcn_id = 0;
+ return -1;
+ } else if (parms->rc == 0) {
+ return 0;
+ } else {
+ api_fcn_errno = parms->rc;
+ api_fcn_fcn_id = parms->function_id;
+ return -1;
+ }
+}
+
+
+api_disconnect_from_keyboard(parms)
+DisconnectFromKeyboardParms *parms;
+{
+ if (api_issue(0x09, DISCONNECT_FROM_KEYBOARD, 0x80, 0x20, 0,
+ gate_keyboard, (char *)parms, sizeof *parms) == -1) {
+ api_fcn_errno = 0;
+ api_fcn_fcn_id = 0;
+ return -1;
+ } else if (parms->rc == 0) {
+ return 0;
+ } else {
+ api_fcn_errno = parms->rc;
+ api_fcn_fcn_id = parms->function_id;
+ return -1;
+ }
+}
+
+
+api_write_keystroke(parms)
+WriteKeystrokeParms *parms;
+{
+ if (api_issue(0x09, WRITE_KEYSTROKE, 0x80, 0x20, 0,
+ gate_keyboard, (char *)parms, sizeof *parms) == -1) {
+ api_fcn_errno = 0;
+ api_fcn_fcn_id = 0;
+ return -1;
+ } else if (parms->rc == 0) {
+ return 0;
+ } else {
+ api_fcn_errno = parms->rc;
+ api_fcn_fcn_id = parms->function_id;
+ return -1;
+ }
+}
+
+
+api_disable_input(parms)
+DisableInputParms *parms;
+{
+ if (api_issue(0x09, DISABLE_INPUT, 0x80, 0x20, 0,
+ gate_keyboard, (char *)parms, sizeof *parms) == -1) {
+ api_fcn_errno = 0;
+ api_fcn_fcn_id = 0;
+ return -1;
+ } else if (parms->rc == 0) {
+ return 0;
+ } else {
+ api_fcn_errno = parms->rc;
+ api_fcn_fcn_id = parms->function_id;
+ return -1;
+ }
+}
+
+api_enable_input(parms)
+EnableInputParms *parms;
+{
+ if (api_issue(0x09, ENABLE_INPUT, 0x80, 0x20, 0,
+ gate_keyboard, (char *)parms, sizeof *parms) == -1) {
+ api_fcn_errno = 0;
+ api_fcn_fcn_id = 0;
+ return -1;
+ } else if (parms->rc == 0) {
+ return 0;
+ } else {
+ api_fcn_errno = parms->rc;
+ api_fcn_fcn_id = parms->function_id;
+ return -1;
+ }
+}
+
+/*
+ * Copy Services
+ */
+
+api_copy_string(parms)
+CopyStringParms *parms;
+{
+ if (api_issue(0x09, COPY_STRING, 0x80, 0x20, 0xff,
+ gate_copy, (char *)parms, sizeof *parms) == -1) {
+ api_fcn_errno = 0;
+ api_fcn_fcn_id = 0;
+ return -1;
+ } else if (parms->rc == 0) {
+ return 0;
+ } else {
+ api_fcn_errno = parms->rc;
+ api_fcn_fcn_id = parms->function_id;
+ return -1;
+ }
+}
+
+/*
+ * Operator Information Area Services
+ */
+
+api_read_oia_group(parms)
+ReadOiaGroupParms *parms;
+{
+ if (api_issue(0x09, READ_OIA_GROUP, 0x80, 0x20, 0xff,
+ gate_oiam, (char *)parms, sizeof *parms) == -1) {
+ api_fcn_errno = 0;
+ api_fcn_fcn_id = 0;
+ return -1;
+ } else if (parms->rc == 0) {
+ return 0;
+ } else {
+ api_fcn_errno = parms->rc;
+ api_fcn_fcn_id = parms->function_id;
+ return -1;
+ }
+}
+
+/*
+ * The "we are done" routine. This gets called last.
+ */
+
+api_finish()
+{
+#if defined(unix)
+ if (api_close_api() == -1) {
+ return -1;
+ } else {
+ return 0;
+ }
+#endif /* defined(unix) */
+}
+
+
+/*
+ * The initialization routine. Be sure to call this first.
+ */
+
+api_init()
+{
+#if defined(MSDOS)
+ union REGS regs;
+ struct SREGS sregs;
+
+ regs.h.ah = 0x35;
+ regs.h.al = API_INTERRUPT_NUMBER;
+ intdosx(&regs, &regs, &sregs);
+
+ if ((regs.x.bx == 0) && (sregs.es == 0)) {
+ return 0; /* Interrupt not being handled */
+ }
+#endif /* defined(MSDOS) */
+#if defined(unix)
+ if (api_open_api((char *)0) == -1) {
+ return 0;
+ }
+#endif /* defined(unix) */
+
+ gate_sessmgr = api_name_resolve("SESSMGR");
+ gate_keyboard = api_name_resolve("KEYBOARD");
+ gate_copy = api_name_resolve("COPY");
+ gate_oiam = api_name_resolve("OIAM");
+
+ if ((gate_sessmgr == gate_keyboard) ||
+ (gate_sessmgr == gate_copy) ||
+ (gate_sessmgr == gate_oiam) ||
+ (gate_keyboard == gate_copy) ||
+ (gate_keyboard == gate_oiam) ||
+ (gate_copy == gate_oiam)) {
+ return 0; /* Interrupt doesn't seem correct */
+ }
+ return 1;
+}
diff --git a/usr.bin/tn3270/api/apilib.h b/usr.bin/tn3270/api/apilib.h
new file mode 100644
index 0000000..3253e39
--- /dev/null
+++ b/usr.bin/tn3270/api/apilib.h
@@ -0,0 +1,44 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ *
+ * @(#)apilib.h 8.1 (Berkeley) 6/6/93
+ */
+
+/*
+ * What one needs to specify
+ */
+
+extern int
+ api_sup_errno, /* Supervisor error number */
+ api_sup_fcn_id, /* Supervisor function id (0x12) */
+ api_fcn_errno, /* Function error number */
+ api_fcn_fcn_id; /* Function ID (0x6b, etc.) */
diff --git a/usr.bin/tn3270/api/asc_ebc.c b/usr.bin/tn3270/api/asc_ebc.c
new file mode 100644
index 0000000..14061f0
--- /dev/null
+++ b/usr.bin/tn3270/api/asc_ebc.c
@@ -0,0 +1,110 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)asc_ebc.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
+
+/*
+ * Ascii<->Ebcdic translation tables.
+ */
+
+#include "asc_ebc.h"
+
+unsigned char asc_ebc[NASCII] = {
+
+/* 00 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* 08 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* 10 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* 18 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* 20 */ 0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D,
+/* 28 */ 0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61,
+/* 30 */ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
+/* 38 */ 0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F,
+/* 40 */ 0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
+/* 48 */ 0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
+/* 50 */ 0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,
+/* 58 */ 0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D,
+/* 60 */ 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+/* 68 */ 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
+/* 70 */ 0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
+/* 78 */ 0xA7, 0xA8, 0xA9, 0xC0, 0x4F, 0xD0, 0xA1, 0x00,
+
+};
+
+/*
+ * ebcdic to ascii translation tables
+ */
+
+unsigned char ebc_asc[NEBC] = {
+/* 00 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+/* 08 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+/* 10 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+/* 18 */ ' ', ' ', ' ', ' ', '*', ' ', ';', ' ',
+/* 20 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+/* 28 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+/* 30 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+/* 38 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+/* 40 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+
+/* 48 */ ' ', ' ',
+#if !defined(MSDOS)
+ /* 4A */ '\\',
+#else /* !defined(MSDOS) */
+ /* 4A */ '\233', /* PC cent sign */
+#endif /* !defined(MSDOS) */
+ /* 4B */ '.', '<', '(', '+', '|',
+
+/* 50 */ '&', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+/* 58 */ ' ', ' ', '!', '$', '*', ')', ';', '^',
+/* 60 */ '-', '/', ' ', ' ', ' ', ' ', ' ', ' ',
+/* 68 */ ' ', ' ', '|', ',', '%', '_', '>', '?',
+/* 70 */ ' ', '^', ' ', ' ', ' ', ' ', ' ', ' ',
+/* 78 */ ' ', '`', ':', '#', '@', '\'', '=', '"',
+/* 80 */ ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
+/* 88 */ 'h', 'i', ' ', ' ', ' ', ' ', ' ', ' ',
+/* 90 */ ' ', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
+/* 98 */ 'q', 'r', ' ', ' ', ' ', ' ', ' ', ' ',
+/* A0 */ ' ', '~', 's', 't', 'u', 'v', 'w', 'x',
+/* A8 */ 'y', 'z', ' ', ' ', ' ', '[', ' ', ' ',
+/* B0 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+/* B8 */ ' ', ' ', ' ', ' ', ' ', ']', ' ', ' ',
+/* C0 */ '{', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
+/* C8 */ 'H', 'I', ' ', ' ', ' ', ' ', ' ', ' ',
+/* D0 */ '}', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+/* D8 */ 'Q', 'R', ' ', ' ', ' ', ' ', ' ', ' ',
+/* E0 */ '\\', ' ', 'S', 'T', 'U', 'V', 'W', 'X',
+/* E8 */ 'Y', 'Z', ' ', ' ', ' ', ' ', ' ', ' ',
+/* F0 */ '0', '1', '2', '3', '4', '5', '6', '7',
+/* F8 */ '8', '9', ' ', ' ', ' ', ' ', ' ', ' ',
+};
diff --git a/usr.bin/tn3270/api/asc_ebc.h b/usr.bin/tn3270/api/asc_ebc.h
new file mode 100644
index 0000000..17c0488
--- /dev/null
+++ b/usr.bin/tn3270/api/asc_ebc.h
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ *
+ * @(#)asc_ebc.h 8.1 (Berkeley) 6/6/93
+ */
+
+/*
+ * Definitions of translate tables used for ascii<->ebcdic translation.
+ */
+
+#define INCLUDED_ASCEBC
+
+/*
+ * ascii/ebcdic translation information
+ */
+
+#define NASCII 128 /* number of ascii characters */
+
+#define NEBC 256 /* number of ebcdic characters */
+
+extern unsigned char
+ asc_ebc[NASCII], ebc_asc[NEBC];
diff --git a/usr.bin/tn3270/api/astosc.c b/usr.bin/tn3270/api/astosc.c
new file mode 100644
index 0000000..ff641d6
--- /dev/null
+++ b/usr.bin/tn3270/api/astosc.c
@@ -0,0 +1,98 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)astosc.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
+
+#include <ctype.h>
+
+#include "../general/general.h"
+
+#include "../ctlr/function.h"
+
+#include "astosc.h"
+
+struct astosc astosc[256] = {
+#include "astosc.out"
+};
+
+/* compare two strings, ignoring case */
+
+static
+ustrcmp(string1, string2)
+register char *string1;
+register char *string2;
+{
+ register int c1, c2;
+
+ while ((c1 = (unsigned char) *string1++) != 0) {
+ if (isupper(c1)) {
+ c1 = tolower(c1);
+ }
+ if (isupper(c2 = (unsigned char) *string2++)) {
+ c2 = tolower(c2);
+ }
+ if (c1 < c2) {
+ return(-1);
+ } else if (c1 > c2) {
+ return(1);
+ }
+ }
+ if (*string2) {
+ return(-1);
+ } else {
+ return(0);
+ }
+}
+
+
+/*
+ * This routine takes a string and returns an integer. It may return
+ * -1 if there is no other integer which corresponds to the
+ * string. -1 implies an error.
+ */
+
+int
+ascii_to_index(string)
+register char *string;
+{
+ register struct astosc *this;
+
+ for (this = astosc; this <= &astosc[highestof(astosc)]; this++) {
+ if ((this->name != 0) && (ustrcmp(this->name, string) == 0)) {
+ return this-astosc;
+ }
+ }
+ return -1;
+}
diff --git a/usr.bin/tn3270/api/astosc.h b/usr.bin/tn3270/api/astosc.h
new file mode 100644
index 0000000..bbafd5f
--- /dev/null
+++ b/usr.bin/tn3270/api/astosc.h
@@ -0,0 +1,58 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ *
+ * @(#)astosc.h 8.1 (Berkeley) 6/6/93
+ */
+
+/*
+ * This defines the structure used to translate:
+ *
+ * ascii name ==> (scancode, shiftstate)
+ *
+ * (Actually, map3270 does "ascii name ==> index", and
+ * termin does "index ==> (scancode, shiftstate)". Both
+ * mappings use this structure.)
+ */
+
+#define INCLUDED_ASTOSC
+
+struct astosc {
+ unsigned char
+ scancode, /* Scan code for this function */
+ shiftstate; /* Shift state for this function */
+ enum ctlrfcn function; /* Internal function identifier */
+ char *name; /* Name of this function */
+};
+
+int ascii_to_index(); /* Function to feed InitControl() */
+
+extern struct astosc astosc[256];
diff --git a/usr.bin/tn3270/api/dctype.c b/usr.bin/tn3270/api/dctype.c
new file mode 100644
index 0000000..1fd8a90
--- /dev/null
+++ b/usr.bin/tn3270/api/dctype.c
@@ -0,0 +1,245 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)dctype.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
+
+#include "dctype.h"
+
+unsigned char dctype[192] = {
+/*00*/
+ D_SPACE,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+/*10*/
+ D_SPACE,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ 0,
+ 0,
+ 0,
+ 0,
+/*20*/
+ D_DIGIT|D_PRINT,
+ D_DIGIT|D_PRINT,
+ D_DIGIT|D_PRINT,
+ D_DIGIT|D_PRINT,
+ D_DIGIT|D_PRINT,
+ D_DIGIT|D_PRINT,
+ D_DIGIT|D_PRINT,
+ D_DIGIT|D_PRINT,
+ D_DIGIT|D_PRINT,
+ D_DIGIT|D_PRINT,
+ 0,
+ 0,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+/*30*/
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+ 0,
+ 0,
+ 0,
+ 0,
+ D_PUNCT|D_PRINT,
+ 0,
+ D_PUNCT|D_PRINT,
+ 0,
+ 0,
+/*40*/
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+/*50*/
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+/*60*/
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+/*70*/
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+/*80*/
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+/*90*/
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ D_LOWER|D_PRINT,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+/*A0*/
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+/*B0*/
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ D_UPPER|D_PRINT,
+ 0,
+ 0,
+ 0,
+ 0,
+ D_PUNCT|D_PRINT,
+ D_PUNCT|D_PRINT,
+};
diff --git a/usr.bin/tn3270/api/dctype.h b/usr.bin/tn3270/api/dctype.h
new file mode 100644
index 0000000..2b0c068
--- /dev/null
+++ b/usr.bin/tn3270/api/dctype.h
@@ -0,0 +1,54 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ *
+ * @(#)dctype.h 8.1 (Berkeley) 6/6/93
+ */
+
+#define INCLUDED_ECTYPE
+
+#define D_UPPER 0x01
+#define D_LOWER 0x02
+#define D_DIGIT 0x04
+#define D_SPACE 0x08
+#define D_PUNCT 0x10
+#define D_PRINT 0x20
+
+#define Disalpha(c) (dctype[(c)]&(D_UPPER|D_LOWER))
+#define Disupper(c) (dctype[(c)]&D_UPPER)
+#define Dislower(c) (dctype[(c)]&D_LOWER)
+#define Disdigit(c) (dctype[(c)]&D_DIGIT)
+#define Disalnum(c) (dctype[(c)]&(D_UPPER|D_LOWER|D_DIGIT))
+#define Disspace(c) (dctype[(c)]&D_SPACE) /* blank or null */
+#define Dispunct(c) (dctype[(c)]&D_PUNCT)
+#define Disprint(c) (dctype[(c)]&D_PRINT)
+
+extern unsigned char dctype[192];
diff --git a/usr.bin/tn3270/api/disp_asc.c b/usr.bin/tn3270/api/disp_asc.c
new file mode 100644
index 0000000..85ba106
--- /dev/null
+++ b/usr.bin/tn3270/api/disp_asc.c
@@ -0,0 +1,45 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)disp_asc.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
+
+/*
+ * There isn't much excuse for this file, but here it is.
+ */
+
+#include "disp_asc.h"
+
+#include "asc_disp.out"
+#include "disp_asc.out"
diff --git a/usr.bin/tn3270/api/disp_asc.h b/usr.bin/tn3270/api/disp_asc.h
new file mode 100644
index 0000000..5abe92b
--- /dev/null
+++ b/usr.bin/tn3270/api/disp_asc.h
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ *
+ * @(#)disp_asc.h 8.1 (Berkeley) 6/6/93
+ */
+
+/*
+ * Define the translate tables used to go between 3270 display code
+ * and ascii
+ */
+
+extern unsigned char
+ disp_asc[256], /* Goes between display code and ascii */
+ asc_disp[256]; /* Goes between ascii and display code */
diff --git a/usr.bin/tn3270/api/ebc_disp.c b/usr.bin/tn3270/api/ebc_disp.c
new file mode 100644
index 0000000..a601099
--- /dev/null
+++ b/usr.bin/tn3270/api/ebc_disp.c
@@ -0,0 +1,106 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)ebc_disp.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
+
+/*
+ * Translate table to map EBCDIC into 3270 display codes.
+ */
+
+unsigned char ebc_disp[256] = {
+/*00*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/*08*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/*10*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/*18*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/*20*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/*28*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/*30*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/*38*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/*40*/ 0x10, 0x0a, 0x0b, 0x1c, 0x1d, 0x1e, 0x1f, 0x2a,
+/*48*/ 0x2b, 0x37, 0x1b, 0x32, 0x09, 0x0d, 0x35, 0x16,
+/*50*/ 0x30, 0x38, 0x39, 0x3a, 0x3c, 0x3e, 0x3f, 0x40,
+/*58*/ 0x41, 0x42, 0x19, 0x1a, 0xbf, 0x0c, 0xbe, 0x36,
+/*60*/ 0x31, 0x14, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
+/*68*/ 0x49, 0x4a, 0x17, 0x33, 0x2e, 0x2f, 0x08, 0x18,
+/*70*/ 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52,
+/*78*/ 0x53, 0x3d, 0x34, 0x2c, 0x2d, 0x12, 0x11, 0x13,
+/*80*/ 0x54, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86,
+/*88*/ 0x87, 0x88, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
+/*90*/ 0x5b, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+/*98*/ 0x90, 0x91, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61,
+/*A0*/ 0x62, 0x3b, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+/*A8*/ 0x98, 0x99, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
+/*B0*/ 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
+/*B8*/ 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
+/*C0*/ 0x0f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6,
+/*C8*/ 0xa7, 0xa8, 0x79, 0x7a, 0x7b, 0x7c, 0x01, 0x02,
+/*D0*/ 0x0e, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+/*D8*/ 0xb0, 0xb1, 0x7d, 0x7e, 0x7f, 0x03, 0x04, 0x05,
+/*E0*/ 0x15, 0x9a, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+/*E8*/ 0xb8, 0xb9, 0x9b, 0x9c, 0x9d, 0x06, 0x07, 0x9e,
+/*F0*/ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+/*F8*/ 0x28, 0x29, 0xba, 0xbb, 0xbc, 0xbd, 0x9f, 0x00,
+};
+
+/*
+ * Translate table to map 3270 display codes to EBCDIC.
+ */
+
+unsigned char disp_ebc[192] = {
+/*00*/ 0x00, 0xce, 0xcf, 0xdd, 0xde, 0xdf, 0xed, 0xee,
+/*08*/ 0x6e, 0x4c, 0x41, 0x42, 0x5d, 0x4d, 0xd0, 0xc0,
+/*10*/ 0x40, 0x7e, 0x7d, 0x7f, 0x61, 0xe0, 0x4f, 0x6a,
+/*18*/ 0x6f, 0x5a, 0x5b, 0x4a, 0x43, 0x44, 0x45, 0x46,
+/*20*/ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+/*28*/ 0xf8, 0xf9, 0x47, 0x48, 0x7b, 0x7c, 0x6c, 0x6d,
+/*30*/ 0x50, 0x60, 0x4b, 0x6b, 0x7a, 0x4e, 0x5f, 0x49,
+/*38*/ 0x51, 0x52, 0x53, 0xa1, 0x54, 0x79, 0x55, 0x56,
+/*40*/ 0x57, 0x58, 0x59, 0x62, 0x63, 0x64, 0x65, 0x66,
+/*48*/ 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74,
+/*50*/ 0x75, 0x76, 0x77, 0x78, 0x80, 0x8a, 0x8b, 0x8c,
+/*58*/ 0x8d, 0x8e, 0x8f, 0x90, 0x9a, 0x9b, 0x9c, 0x9d,
+/*60*/ 0x9e, 0x9f, 0xa0, 0xaa, 0xab, 0xac, 0xad, 0xae,
+/*68*/ 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
+/*70*/ 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe,
+/*78*/ 0xbf, 0xca, 0xcb, 0xcc, 0xcd, 0xda, 0xdb, 0xdc,
+/*80*/ 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
+/*88*/ 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+/*90*/ 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+/*98*/ 0xa8, 0xa9, 0xe1, 0xea, 0xeb, 0xec, 0xef, 0xfe,
+/*A0*/ 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8,
+/*A8*/ 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+/*B0*/ 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+/*B8*/ 0xe8, 0xe9, 0xfa, 0xfb, 0xfc, 0xfd, 0x5e, 0x5c,
+};
diff --git a/usr.bin/tn3270/api/ebc_disp.h b/usr.bin/tn3270/api/ebc_disp.h
new file mode 100644
index 0000000..201c39d
--- /dev/null
+++ b/usr.bin/tn3270/api/ebc_disp.h
@@ -0,0 +1,38 @@
+/*-
+ * Copyright (c) 1988, 1993
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ *
+ * @(#)ebc_disp.h 8.1 (Berkeley) 6/6/93
+ */
+
+extern unsigned char
+ ebc_disp[256],
+ disp_ebc[192];
OpenPOWER on IntegriCloud