📄 inbound.c
字号:
/*- * 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 lintstatic char sccsid[] = "@(#)inbound.c 8.1 (Berkeley) 6/6/93";#endif /* not lint */#include <stdio.h>#include "../general/general.h"#include "function.h"#include "hostctlr.h"#include "oia.h"#include "scrnctlr.h"#include "screen.h"#include "options.h"#include "../api/dctype.h"#include "../api/ebc_disp.h"#include "../general/globals.h"#include "externs.h"#include "declare.h"#define EmptyChar() (ourPTail == ourPHead)#define FullChar() (ourPHead == ourBuffer+sizeof ourBuffer)/* * We define something to allow us to to IsProtected() quickly * on unformatted screens (with the current algorithm for fields, * unprotected takes exponential time...). * * The idea is to call SetXIsProtected() BEFORE the * loop, then use XIsProtected(). */#define SetXIsProtected() (XWasSF = 1)#define XIsProtected(p) (IsStartField(p)? \ XWasSF = 1 : \ (XWasSF? \ (XWasSF = 0, XProtected = IsProtected(p)) : \ XProtected))static char ourBuffer[400];static char *ourPHead = ourBuffer, *ourPTail = ourBuffer;static int HadAid; /* Had an AID haven't sent */static int InsertMode; /* is the terminal in insert mode? */static unsigned int rememberedshiftstate; /* Shift (alt) state of terminal */# define HITNUM(s) ((((s)&(SHIFT_CAPS|SHIFT_UPSHIFT))? 1:0) \ + ((((s)&SHIFT_ALT)? 1:0)<<1))static int XWasSF, XProtected; /* For optimizations */#if !defined(PURE3274)extern int TransparentClock, OutputClock;#endif /* !defined(PURE3274) */#include "kbd.out" /* Get keyboard mapping function *//* the following are global variables */extern int UnLocked; /* keyboard is UnLocked? *//* * init_inbound : * * Reset variables to initial state. */voidinit_inbound(){ ourPHead = ourPTail = ourBuffer; HadAid = 0; rememberedshiftstate = 0; InsertMode = 0;}/* Tab() - sets cursor to the start of the next unprotected field */static voidTab(){ register int i, j; i = CursorAddress; j = WhereAttrByte(CursorAddress); do { if (IsStartField(i) && IsUnProtected(ScreenInc(i))) { break; } i = FieldInc(i); } while (i != j); if (IsStartField(i) && IsUnProtected(ScreenInc(i))) { CursorAddress = ScreenInc(i); } else { CursorAddress = SetBufferAddress(0,0); }}/* BackTab() - sets cursor to the start of the most recent field */static voidBackTab(){ register int i; i = ScreenDec(CursorAddress); for (;;) { if (IsStartField(ScreenDec(i)) && IsUnProtected(i)) { CursorAddress = i; break; } if (i == CursorAddress) { CursorAddress = SetBufferAddress(0,0); break; } i = ScreenDec(i); }}/* * ModifyMdt() - Turn a modified data tag bit on or off (watch * out for unformatted screens). */ModifyMdt(x,on)int x;int on;{ int i = x; if (IsStartField(i)) { /* If we are at a start field position... */ if (on) { ModifyHost(i, |= ATTR_MDT); /* Turn it on */ } else { ModifyHost(i, &= ~ATTR_MDT); /* Turn it off */ } } else { i = WhereAttrByte(i); /* Find beginning of field */ if (IsStartField(i)) { /* Is there one? */ if (on) { ModifyHost(i, |= ATTR_MDT); /* Turn it on */ } else { ModifyHost(i, &= ~ATTR_MDT); /* Turn it off */ } } /* else, don't modify - this is an unformatted screen */ }}/* EraseEndOfField - erase all characters to the end of a field */static voidEraseEndOfField(){ register int i; if (IsProtected(CursorAddress)) { RingBell("Protected Field"); } else { TurnOnMdt(CursorAddress); if (FormattedScreen()) { i = CursorAddress; do { AddHost(i, 0); i = ScreenInc(i); } while ((i != CursorAddress) && !IsStartField(i)); } else { /* Screen is Unformatted */ i = CursorAddress; do { AddHost(i, 0); i = ScreenInc(i); } while (i != HighestScreen()); } }}/* 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. * */static voidDelete(where, from)register int where, /* Where to start deleting from */ from; /* Where to pull back from */{ register int i; TurnOnMdt(where); /* Only do this once in this field */ i = where; do { if (IsStartField(from)) { AddHost(i, 0); /* Stick the edge at the start field */ } else { AddHost(i, (char)GetHost(from)); from = ScreenInc(from); /* Move the edge */ } i = ScreenInc(i); } while ((!IsStartField(i)) && (i != where));}static voidColBak(){ register int i; i = ScreenLineOffset(CursorAddress); for (i = i-1; i >= 0; i--) { if (OptColTabs[i]) { break; } } if (i < 0) { i = 0; } CursorAddress = SetBufferAddress(ScreenLine(CursorAddress), i);}static voidColTab(){ register int i; i = ScreenLineOffset(CursorAddress); for (i = i+1; i < NumberColumns; i++) { if (OptColTabs[i]) { break; } } if (i >= NumberColumns) { i = NumberColumns-1; } CursorAddress = SetBufferAddress(ScreenLine(CursorAddress), i);}static voidHome(){ register int i; register int j; i = SetBufferAddress(OptHome, 0); j = WhereLowByte(i); /* * If the initial value of i points to the field attribute of * an unprotected field, we need to return the address of the * first data byte in the field (assuming there are any!). */ if (IsStartField(i) && IsUnProtected(j)) { CursorAddress = j; return; } do { if (IsUnProtected(i)) { CursorAddress = i; return; } /* 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 * should be true. */ i = ScreenInc(FieldInc(i)); } while (i != j); CursorAddress = LowestScreen();}staticLastOfField(i)register int i; /* position to start from */{ register int j; register int k; k = j = i; SetXIsProtected(); while (XIsProtected(i) || Disspace(GetHost(i))) { i = ScreenInc(i); if (i == j) { break; } } /* We are now IN a word IN an unprotected field (or wrapped) */ while (!XIsProtected(i)) { if (!Disspace(GetHost(i))) { k = i; } i = ScreenInc(i); if (i == j) { break; } } return(k);}static voidFlushChar(){ ourPTail = ourPHead = ourBuffer;}/* * Add one EBCDIC (NOT display code) character to the buffer. */static voidAddChar(character)char character;{ if (FullChar()) { ourPTail += DataToNetwork(ourPTail, ourPHead-ourPTail, 0); if (EmptyChar()) { FlushChar(); } else { char buffer[100]; sprintf(buffer, "File %s, line %d: No room in network buffer!\n", __FILE__, __LINE__); ExitString(buffer, 1); /*NOTREACHED*/ } } *ourPHead++ = character;}static voidSendUnformatted(){ register int i, j; register int Nulls; register int c; /* look for start of field */ Nulls = 0; i = j = LowestScreen(); do { c = GetHost(i); if (c == 0) { Nulls++; } else { while (Nulls) { Nulls--; AddChar(EBCDIC_BLANK); /* put in blanks */ } AddChar((char)disp_ebc[c]); } i = ScreenInc(i); } while (i != j);}staticSendField(i, cmd)register int i; /* where we saw MDT bit */int cmd; /* The command code (type of read) */{ register int j; register int k; register int Nulls; register int c; /* look for start of field */ i = j = WhereLowByte(i); /* On a test_request_read, don't send sba and address */ if ((AidByte != AID_TREQ) || (cmd == CMD_SNA_READ_MODIFIED_ALL)) { AddChar(ORDER_SBA); /* set start field */ AddChar(BufferTo3270_0(j)); /* set address of this field */ AddChar(BufferTo3270_1(j)); } /* * Only on read_modified_all do we return the contents * of the field when the attention was caused by a * selector pen. */ if ((AidByte != AID_SELPEN) || (cmd == CMD_SNA_READ_MODIFIED_ALL)) { if (!IsStartField(j)) { Nulls = 0; k = ScreenInc(WhereHighByte(j)); do { c = GetHost(j); if (c == 0) { Nulls++; } else { while (Nulls) { Nulls--; AddChar(EBCDIC_BLANK); /* put in blanks */ } AddChar((char)disp_ebc[c]); } j = ScreenInc(j); } while ((j != k) && (j != i)); } } else { j = FieldInc(j); } return(j);}/* Various types of reads... */voidDoReadModified(cmd)int cmd; /* The command sent */{ register int i, j; if (AidByte) { if (AidByte != AID_TREQ) { AddChar(AidByte); } else { /* Test Request Read header */ AddChar(EBCDIC_SOH); AddChar(EBCDIC_PERCENT); AddChar(EBCDIC_SLASH); AddChar(EBCDIC_STX); } } else { AddChar(AID_NONE); } if (((AidByte != AID_PA1) && (AidByte != AID_PA2) && (AidByte != AID_PA3) && (AidByte != AID_CLEAR)) || (cmd == CMD_SNA_READ_MODIFIED_ALL)) { if ((AidByte != AID_TREQ) || (cmd == CMD_SNA_READ_MODIFIED_ALL)) { /* Test request read_modified doesn't give cursor address */ AddChar(BufferTo3270_0(CursorAddress)); AddChar(BufferTo3270_1(CursorAddress)); } i = j = WhereAttrByte(LowestScreen()); /* Is this an unformatted screen? */ if (!IsStartField(i)) { /* yes, handle separate */ SendUnformatted(); } else { do { if (HasMdt(i)) { i = SendField(i, cmd); } else { i = FieldInc(i); } } while (i != j); } } ourPTail += DataToNetwork(ourPTail, ourPHead-ourPTail, 1); if (EmptyChar()) { FlushChar(); HadAid = 0; /* killed that buffer */ }}/* A read buffer operation... */voidDoReadBuffer(){ register int i, j; if (AidByte) { AddChar(AidByte); } else { AddChar(AID_NONE); } AddChar(BufferTo3270_0(CursorAddress)); AddChar(BufferTo3270_1(CursorAddress)); i = j = LowestScreen(); do { if (IsStartField(i)) { AddChar(ORDER_SF); AddChar(BufferTo3270_1(FieldAttributes(i))); } else { AddChar((char)disp_ebc[GetHost(i)]); } i = ScreenInc(i); } while (i != j); ourPTail += DataToNetwork(ourPTail, ourPHead-ourPTail, 1); if (EmptyChar()) { FlushChar(); HadAid = 0; /* killed that buffer */ }}/* Send some transparent data to the host */voidSendTransparent(buffer, count)char *buffer;int count;{ char stuff[3]; stuff[0] = AID_NONE_PRINTER; stuff[1] = BufferTo3270_0(count); stuff[2] = BufferTo3270_1(count); DataToNetwork(stuff, sizeof stuff, 0); DataToNetwork(buffer, count, 1);}/* Try to send some data to host */voidSendToIBM(){#if !defined(PURE3274) if (TransparentClock >= OutputClock) { if (HadAid) { AddChar(AidByte); HadAid = 0; } else { AddChar(AID_NONE_PRINTER); } do { ourPTail += DataToNetwork(ourPTail, ourPHead-ourPTail, 1); } while (!EmptyChar()); FlushChar(); } else if (HadAid) { DoReadModified(CMD_READ_MODIFIED); }#else /* !defined(PURE3274) */ if (HadAid) { DoReadModified(CMD_READ_MODIFIED); }#endif /* !defined(PURE3274) */}/* This takes in one character from the keyboard and places it on the * screen. */static voidOneCharacter(c, insert)int c; /* character (Ebcdic) to be shoved in */int insert; /* are we in insert mode? */{ register int i, j; if (IsProtected(CursorAddress)) { RingBell("Protected Field"); return; } if (insert) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -