2003-08-07 15:13:06 +04:00
|
|
|
|
/* $NetBSD: termin.c,v 1.8 2003/08/07 11:16:28 agc Exp $ */
|
1997-01-09 23:18:21 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
/*-
|
|
|
|
|
* 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.
|
2003-08-07 15:13:06 +04:00
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
1998-03-04 16:16:04 +03:00
|
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#ifndef lint
|
1998-03-04 16:16:04 +03:00
|
|
|
|
#if 0
|
|
|
|
|
static char sccsid[] = "@(#)termin.c 4.2 (Berkeley) 4/26/91";
|
|
|
|
|
#else
|
2003-08-07 15:13:06 +04:00
|
|
|
|
__RCSID("$NetBSD: termin.c,v 1.8 2003/08/07 11:16:28 agc Exp $");
|
1998-03-04 16:16:04 +03:00
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
|
|
/* this takes characters from the keyboard, and produces 3270 keystroke
|
|
|
|
|
codes
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
|
|
#include "../general/general.h"
|
|
|
|
|
#include "../ctlr/function.h"
|
|
|
|
|
#include "../ctlr/declare.h"
|
1998-03-04 16:16:04 +03:00
|
|
|
|
#include "../sys_curses/telextrn.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
#include "../api/astosc.h"
|
|
|
|
|
#include "state.h"
|
1998-03-04 16:16:04 +03:00
|
|
|
|
#include "externs.h"
|
|
|
|
|
#include "map3270.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
#include "../general/globals.h"
|
|
|
|
|
|
2002-01-06 04:02:47 +03:00
|
|
|
|
extern cc_t escape; /* Escape to command mode */
|
|
|
|
|
|
1998-11-06 23:03:08 +03:00
|
|
|
|
#define IsControl(c) (!isprint((unsigned char)c) || (isspace((unsigned char)c) && ((c) != ' ')))
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
#define NextState(x) (x->next)
|
|
|
|
|
|
|
|
|
|
/* XXX temporary - hard code in the state table */
|
|
|
|
|
|
|
|
|
|
#define MATCH_ANY 0xff /* actually, match any character */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned char
|
|
|
|
|
ourBuffer[100], /* where we store stuff */
|
|
|
|
|
*ourPHead = ourBuffer, /* first character in buffer */
|
|
|
|
|
*ourPTail = ourBuffer, /* where next character goes */
|
|
|
|
|
*TransPointer = 0; /* For transparent mode data */
|
|
|
|
|
|
|
|
|
|
static int InControl;
|
|
|
|
|
static int WaitingForSynch;
|
|
|
|
|
|
|
|
|
|
static struct astosc
|
|
|
|
|
*spacePTR = 0; /* Space is hard to enter */
|
|
|
|
|
|
|
|
|
|
static state
|
|
|
|
|
*headOfControl = 0; /* where we enter code state table */
|
|
|
|
|
|
|
|
|
|
#define FullChar ((ourPTail+5) >= ourBuffer+sizeof ourBuffer)
|
|
|
|
|
#define EmptyChar (ourPTail == ourPHead)
|
|
|
|
|
|
1998-03-04 16:16:04 +03:00
|
|
|
|
|
2002-06-14 03:41:15 +04:00
|
|
|
|
static void AddChar(int);
|
|
|
|
|
static void FlushChar(void);
|
1998-03-04 16:16:04 +03:00
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* init_keyboard()
|
|
|
|
|
*
|
|
|
|
|
* Initialize the keyboard variables.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
init_keyboard()
|
|
|
|
|
{
|
|
|
|
|
ourPHead = ourPTail = ourBuffer;
|
|
|
|
|
InControl = 0;
|
|
|
|
|
WaitingForSynch = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Initialize the keyboard mapping file.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
InitMapping()
|
|
|
|
|
{
|
1998-03-04 16:16:04 +03:00
|
|
|
|
struct astosc *ptr;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
if (!headOfControl) {
|
|
|
|
|
/* need to initialize */
|
|
|
|
|
headOfControl = InitControl((char *)0, 0, ascii_to_index);
|
|
|
|
|
if (!headOfControl) { /* should not occur */
|
1998-03-04 16:16:04 +03:00
|
|
|
|
quit(0, NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
}
|
|
|
|
|
for (ptr = &astosc[0]; ptr <= &astosc[highestof(astosc)]; ptr++) {
|
|
|
|
|
if (ptr->function == FCN_SPACE) {
|
|
|
|
|
spacePTR = ptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* AddChar - put a function index in our buffer */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
AddChar(c)
|
|
|
|
|
int c;
|
|
|
|
|
{
|
|
|
|
|
if (!FullChar) {
|
|
|
|
|
*ourPTail++ = c;
|
|
|
|
|
} else {
|
|
|
|
|
RingBell("Typeahead buffer full");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* FlushChar - put everything where it belongs */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FlushChar()
|
|
|
|
|
{
|
|
|
|
|
ourPTail = ourBuffer;
|
|
|
|
|
ourPHead = ourBuffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
|
void
|
|
|
|
|
TransInput(onoff, mode)
|
|
|
|
|
int mode; /* Which KIND of transparent input */
|
|
|
|
|
int onoff; /* Going in, or coming out */
|
|
|
|
|
{
|
|
|
|
|
if (onoff) {
|
|
|
|
|
/* Flush pending input */
|
|
|
|
|
FlushChar();
|
|
|
|
|
TransPointer = ourBuffer;
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
TerminalIn()
|
|
|
|
|
{
|
|
|
|
|
/* send data from us to next link in stream */
|
|
|
|
|
int work = 0;
|
1998-03-04 16:16:04 +03:00
|
|
|
|
struct astosc *ptr;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
while (!EmptyChar) { /* send up the link */
|
|
|
|
|
if (*ourPHead == ' ') {
|
|
|
|
|
ptr = spacePTR;
|
|
|
|
|
} else {
|
|
|
|
|
ptr = &astosc[*ourPHead];
|
|
|
|
|
}
|
|
|
|
|
if (AcceptKeystroke(ptr->scancode, ptr->shiftstate) == 1) {
|
|
|
|
|
ourPHead++;
|
|
|
|
|
work = 1;
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (EmptyChar) {
|
|
|
|
|
FlushChar();
|
|
|
|
|
}
|
|
|
|
|
/* return value answers question: "did we do anything useful?" */
|
|
|
|
|
return work;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
DataFromTerminal(buffer, count)
|
1998-03-04 16:16:04 +03:00
|
|
|
|
char *buffer; /* the data read in */
|
|
|
|
|
int count; /* how many bytes in this buffer */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
{
|
1998-03-04 16:16:04 +03:00
|
|
|
|
state *regControlPointer;
|
2002-01-06 04:02:47 +03:00
|
|
|
|
int c;
|
1998-03-04 16:16:04 +03:00
|
|
|
|
int result;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
int origCount;
|
|
|
|
|
extern int bellwinup;
|
|
|
|
|
static state *controlPointer;
|
|
|
|
|
|
|
|
|
|
if (TransPointer) {
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if ((count+TransPointer) >= (ourBuffer+sizeof ourBuffer)) {
|
|
|
|
|
i = ourBuffer+sizeof ourBuffer-TransPointer;
|
|
|
|
|
} else {
|
|
|
|
|
i = count;
|
|
|
|
|
}
|
|
|
|
|
while (i--) {
|
|
|
|
|
c = (*buffer++)&0x7f;
|
|
|
|
|
*TransPointer++ = c|0x80;
|
|
|
|
|
if (c == '\r') {
|
|
|
|
|
SendTransparent((char *)ourBuffer, TransPointer-ourBuffer);
|
|
|
|
|
TransPointer = 0; /* Done */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bellwinup) {
|
|
|
|
|
BellOff();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
origCount = count;
|
|
|
|
|
|
|
|
|
|
while (count) {
|
|
|
|
|
c = *buffer++&0x7f;
|
|
|
|
|
count--;
|
|
|
|
|
|
2002-01-06 04:02:47 +03:00
|
|
|
|
if (c == escape) {
|
|
|
|
|
if (count && (*buffer&0x7f) == escape) {
|
|
|
|
|
buffer++;
|
|
|
|
|
count--;
|
|
|
|
|
} else {
|
|
|
|
|
command(0, (char *)0, 0);
|
|
|
|
|
RefreshScreen();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
|
if (!InControl && !IsControl(c)) {
|
|
|
|
|
AddChar(c); /* add ascii character */
|
|
|
|
|
} else {
|
|
|
|
|
if (!InControl) { /* first character of sequence */
|
|
|
|
|
InControl = 1;
|
|
|
|
|
controlPointer = headOfControl;
|
|
|
|
|
}
|
|
|
|
|
/* control pointer points to current position in state table */
|
|
|
|
|
for (regControlPointer = controlPointer; ;
|
|
|
|
|
regControlPointer = NextState(regControlPointer)) {
|
|
|
|
|
if (!regControlPointer) { /* ran off end */
|
|
|
|
|
RingBell("Invalid control sequence");
|
|
|
|
|
regControlPointer = headOfControl;
|
|
|
|
|
InControl = 0;
|
|
|
|
|
count = 0; /* Flush current input */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ((regControlPointer->match == c) /* hit this character */
|
|
|
|
|
|| (regControlPointer->match == MATCH_ANY)) {
|
|
|
|
|
result = regControlPointer->result;
|
|
|
|
|
if (result == STATE_GOTO) {
|
|
|
|
|
regControlPointer = regControlPointer->address;
|
|
|
|
|
break; /* go to next character */
|
|
|
|
|
}
|
|
|
|
|
if (WaitingForSynch) {
|
|
|
|
|
if (astosc[result].function == FCN_SYNCH) {
|
|
|
|
|
WaitingForSynch = 0;
|
|
|
|
|
} else {
|
|
|
|
|
RingBell("Need to type synch character");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (astosc[result].function == FCN_FLINP) {
|
|
|
|
|
FlushChar(); /* Don't add FLINP */
|
|
|
|
|
} else {
|
|
|
|
|
if (astosc[result].function == FCN_MASTER_RESET) {
|
|
|
|
|
FlushChar();
|
|
|
|
|
}
|
|
|
|
|
AddChar(result); /* add this code */
|
|
|
|
|
}
|
|
|
|
|
InControl = 0; /* out of control now */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
controlPointer = regControlPointer; /* save state */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
(void) TerminalIn(); /* try to send data */
|
|
|
|
|
return(origCount-count);
|
|
|
|
|
}
|