* Copyright 1984, 1985 by the Regents of the University of
* California and by Gregory Glenn Minshall.
* Permission to use, copy, modify, and distribute these
* programs and their documentation for any purpose and
* without fee is hereby granted, provided that this
* copyright and permission appear on all copies and
* supporting documentation, the name of the Regents of
* the University of California not be used in advertising
* or publicity pertaining to distribution of the programs
* without specific prior permission, and notice be given in
* supporting documentation that copying and distribution is
* by permission of the Regents of the University of California
* and by Gregory Glenn Minshall. Neither the Regents of the
* University of California nor Gregory Glenn Minshall make
* representations about the suitability of this software
* for any purpose. It is provided "as is" without
* express or implied warranty.
/* test stub for DataFrom3270, etc. */
#include "m4.out" /* output of termcodes.m4 */
static char sccsid
[] = "@(#)keyboard.c 2.6 4/4/86";
#define EmptyChar (ourPTail == ourBuffer)
#define FullChar (ourPTail == ourBuffer+sizeof ourBuffer)
extern char ascebc
[NASCEBC
][NASCII
];
static char ourBuffer
[4000];
static char *ourPHead
= ourBuffer
,
static int trTbl
= AE_IN
; /* which ascii->ebcdic tr table */
static int HadAid
= 0; /* Had an AID haven't sent */
/* the following are global variables */
extern int UnLocked
; /* keyboard is UnLocked? */
/* Tab() - sets cursor to the start of the next unprotected field */
j
= WhereAttrByte(CursorAddress
);
if (IsStartField(i
) && IsUnProtected(ScreenInc(i
))) {
if (IsStartField(i
) && IsUnProtected(ScreenInc(i
))) {
CursorAddress
= ScreenInc(i
);
CursorAddress
= SetBufferAddress(0,0);
/* BackTab() - sets cursor to the start of the most recent field */
i
= ScreenDec(CursorAddress
);
if (IsStartField(ScreenDec(i
)) && IsUnProtected(i
)) {
if (i
== CursorAddress
) {
CursorAddress
= SetBufferAddress(0,0);
/* EraseEndOfField - erase all characters to the end of a field */
if (IsProtected(CursorAddress
)) {
TurnOnMdt(CursorAddress
);
} while ((i
!= CursorAddress
) && IsUnProtected(i
));
/* Delete() - deletes a character from the screen
* What we want to do is delete the section
* [where, from-1] from the screen,
* filling in with what comes at from.
* The deleting continues to the end of the field (or
* until the cursor wraps).
* From can be a start of a field. We
* check for that. However, there can't be any
* fields that start between where and from.
* We don't check for that.
* Also, we assume that the protection status of
* everything has been checked by the caller.
register int where
, /* Where to start deleting from */
from
; /* Where to pull back from */
TurnOnMdt(where
); /* Only do this once in this field */
if (IsStartField(from
)) {
AddHost(i
, 0); /* Stick the edge at the start field */
AddHost(i
, GetHost(from
));
from
= ScreenInc(from
); /* Move the edge */
} while ((!IsStartField(i
)) && (i
!= where
));
i
= ScreenLineOffset(CursorAddress
);
for (i
= i
-1; i
>= 0; i
--) {
CursorAddress
= SetBufferAddress(ScreenLine(CursorAddress
), i
);
i
= ScreenLineOffset(CursorAddress
);
for (i
= i
+1; i
< LINESIZE
; i
++) {
CursorAddress
= SetBufferAddress(ScreenLine(CursorAddress
), i
);
i
= SetBufferAddress(OptHome
, 0);
/* the following could be a problem if we got here with an
* unformatted screen. However, this is "impossible", since
* with an unformatted screen, the IsUnProtected(i) above
i
= ScreenInc(FieldInc(i
));
CursorAddress
= LowestScreen();
register int i
; /* position to start from */
while (IsProtected(i
) || Eisspace(GetHost(i
))) {
/* We are now IN a word IN an unprotected field (or wrapped) */
while (!IsProtected(i
)) {
if (!Eisspace(GetHost(i
))) {
ourPTail
= ourPHead
= ourBuffer
;
/* look for start of field */
AddChar(0x40); /* put in blanks */
register int i
; /* where we saw MDT bit */
/* look for start of field */
AddChar(ORDER_SBA
); /* set start field */
AddChar(BufferTo3270_0(j
)); /* set address of this field */
AddChar(BufferTo3270_1(j
));
k
= ScreenInc(WhereHighByte(j
));
AddChar(0x40); /* put in blanks */
} while ((j
!= k
) && (j
!= i
));
/* Various types of reads... */
if ((AidByte
!= AID_PA1
) && (AidByte
!= AID_PA2
) && (AidByte
!= AID_PA3
)
&& (AidByte
!= AID_CLEAR
)) {
AddChar(BufferTo3270_0(CursorAddress
));
AddChar(BufferTo3270_1(CursorAddress
));
i
= j
= WhereAttrByte(LowestScreen());
/* Is this an unformatted screen? */
if (!IsStartField(i
)) { /* yes, handle separate */
ourPTail
+= DataToNetwork(ourPTail
, ourPHead
-ourPTail
);
if (ourPTail
== ourPHead
) {
HadAid
= 0; /* killed that buffer */
/* A read buffer operation... */
AddChar(BufferTo3270_0(CursorAddress
));
AddChar(BufferTo3270_1(CursorAddress
));
AddChar(BufferTo3270_1(FieldAttributes(i
)));
ourPTail
+= DataToNetwork(ourPTail
, ourPHead
-ourPTail
);
if (ourPTail
== ourPHead
) {
HadAid
= 0; /* killed that buffer */
/* Try to send some data to host */
extern int TransparentClock
, OutputClock
;
if (TransparentClock
== OutputClock
) {
ourPTail
+= DataToNetwork(ourPTail
, ourPHead
-ourPTail
);
} while (ourPTail
!= ourPHead
);
/* This takes in one character from the keyboard and places it on the
int c
; /* character (Ebcdic) to be shoved in */
int insert
; /* are we in insert mode? */
if (IsProtected(CursorAddress
)) {
/* is the last character in the field a blank or null? */
i
= ScreenDec(FieldInc(CursorAddress
));
for (j
= ScreenDec(i
); i
!= CursorAddress
;
j
= ScreenDec(j
), i
= ScreenDec(i
)) {
AddHost(CursorAddress
, c
);
TurnOnMdt(CursorAddress
);
CursorAddress
= ScreenInc(CursorAddress
);
if (IsStartField(CursorAddress
) &&
((FieldAttributes(CursorAddress
)&ATTR_AUTO_SKIP_MASK
) ==
/* go through data until an AID character is hit, then generate an interrupt */
DataFrom3270(buffer
, count
)
char *buffer
; /* where the data is */
int count
; /* how much data there is */
static int InsertMode
= 0; /* is the terminal in insert mode? */
extern int OutputClock
, TransparentClock
;
if (!UnLocked
|| HadAid
) {
return(0); /* nothing to do */
if (!HadAid
&& (((*buffer
&0xff) == TC_RESET
) ||
((*buffer
&0xff) == TC_MASTER_RESET
)) && EmptyChar
) {
/* now, either empty, or haven't seen aid yet */
if (TransparentClock
== OutputClock
) {
return(origCount
-(count
+1));
/* Add the character to the buffer */
OneCharacter(ascebc
[trTbl
][c
], InsertMode
);
} else if (IsAid(c
)) { /* got Aid */
InsertMode
= 0; /* just like a 3278 */
/* non-AID TC character */
if (IsProtected(ScreenDec(CursorAddress
))) {
CursorAddress
= ScreenDec(CursorAddress
);
Delete(CursorAddress
, ScreenInc(CursorAddress
));
while ((!IsProtected(i
) && Eisspace(GetHost(i
)))
/* we are pointing at a character in a word, or
* at a protected position
while ((!IsProtected(i
) && !Eisspace(GetHost(i
)))
/* we are pointing at a space, or at a protected
CursorAddress
= ScreenInc(i
);
Delete(CursorAddress
, j
);
if (IsProtected(CursorAddress
)) {
CursorAddress
= ScreenInc(CursorAddress
); /* for btab */
CursorAddress
= ScreenUp(CursorAddress
);
CursorAddress
= ScreenDec(CursorAddress
);
CursorAddress
= ScreenInc(CursorAddress
);
CursorAddress
= ScreenDown(CursorAddress
);
if (IsProtected(CursorAddress
)) {
Delete(CursorAddress
, ScreenInc(CursorAddress
));
InsertMode
= !InsertMode
;
/* The algorithm is to look for the first unprotected
* column after column 0 of the following line. Having
* found that unprotected column, we check whether the
* cursor-address-at-entry is at or to the right of the
* LeftMargin AND the LeftMargin column of the found line
* is unprotected. If this conjunction is true, then
* we set the found pointer to the address of the LeftMargin
* column in the found line.
* Then, we set the cursor address to the found address.
i
= SetBufferAddress(ScreenLine(ScreenDown(CursorAddress
)), 0);
j
= ScreenInc(WhereAttrByte(CursorAddress
));
/* Again (see comment in Home()), this COULD be a problem
* with an unformatted screen.
/* If there was a field with only an attribute byte,
* we may be pointing to the attribute byte of the NEXT
* field, so just look at the next byte.
i
= ScreenInc(FieldInc(i
));
if (!IsUnProtected(i
)) { /* couldn't find unprotected */
i
= SetBufferAddress(0,0);
if (OptLeftMargin
<= ScreenLineOffset(CursorAddress
)) {
if (IsUnProtected(SetBufferAddress(ScreenLine(i
),
i
= SetBufferAddress(ScreenLine(i
), OptLeftMargin
);
i
= j
= ScreenInc(WhereAttrByte(LowestScreen()));
/* FieldInc() puts us at the start of the next
* We don't want to skip to the start of the
* next field if we are on the attribute byte,
* since we may be skipping over an otherwise
* Also, j points at the first byte of the first
* field on the screen, unprotected or not. If
* we never point there, we might loop here for
Home(); /* get to home position */
if (IsProtected(CursorAddress
)) {
OneCharacter(EBCDIC_FM
, InsertMode
); /* Add field mark */
if (IsProtected(CursorAddress
)) {
OneCharacter(EBCDIC_DUP
, InsertMode
); /* Add dup character */
#ifdef NOTUSED /* Actually, this is superseded by unix flow
Flow
= 0; /* stop output */
Flow
= 1; /* turn it back on */
/* FlushChar(); do we want to flush characters from before? */
OptColTabs
[ScreenLineOffset(CursorAddress
)] = 1;
OptColTabs
[ScreenLineOffset(CursorAddress
)] = 0;
for (i
= 0; i
< sizeof OptColTabs
; i
++) {
OptLeftMargin
= ScreenLineOffset(CursorAddress
);
OptLeftMargin
= ScreenLineOffset(CursorAddress
);
OptLeftMargin
= ScreenLineOffset(CursorAddress
);
OptHome
= ScreenLine(CursorAddress
);
* Point to first character of next unprotected word on
while (!IsProtected(i
) && !Eisspace(GetHost(i
))) {
if (i
== CursorAddress
) {
/* i is either protected, a space (blank or null),
while (IsProtected(i
) || Eisspace(GetHost(i
))) {
if (i
== CursorAddress
) {
i
= ScreenDec(CursorAddress
);
while (IsProtected(i
) || Eisspace(GetHost(i
))) {
if (i
== CursorAddress
) {
/* i is pointing to a character IN an unprotected word
while (!Eisspace(GetHost(i
))) {
if (i
== CursorAddress
) {
CursorAddress
= ScreenInc(i
);
/* Point to last non-blank character of this/next
i
= ScreenInc(CursorAddress
);
while (IsProtected(i
) || Eisspace(GetHost(i
))) {
if (i
== CursorAddress
) {
/* we are pointing at a character IN an
* unprotected word (or we wrapped)
while (!Eisspace(GetHost(i
))) {
if (i
== CursorAddress
) {
CursorAddress
= ScreenDec(i
);
/* Get to last non-blank of this/next unprotected
i
= LastOfField(CursorAddress
);
if (i
!= CursorAddress
) {
CursorAddress
= i
; /* We moved; take this */
j
= FieldInc(CursorAddress
); /* Move to next field */
CursorAddress
= i
; /* We moved; take this */
/* else - nowhere else on screen to be; stay here */
RingBell(); /* We don't handle this yet */