2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static char copyright[] =
36 "@(#) Copyright (c) 1988, 1993\n\
37 The Regents of the University of California. All rights reserved.\n";
41 static char sccsid[] = "@(#)prt3270.c 8.1 (Berkeley) 6/6/93";
49 #include "../general/general.h"
51 #include "../api/asc_ebc.h"
52 #include "../ctlr/hostctlr.h"
53 #include "../ctlr/screen.h"
54 #include "../ctlr/function.h"
55 #include "../api/astosc.h"
56 #include "../general/globals.h"
58 #include "../ctlr/kbd.out"
61 int NumberColumns = 80;
69 unsigned char printBuffer[200], *print = printBuffer;
71 #define ColsLeft() (79-column) /* A little room for error */
77 extern void Column1();
78 unsigned char *ourPrint = print;
80 print = printBuffer; /* For mutual calls */
85 if (column != (indenting*8+1)) {
92 for (i = 0; i < indenting; i++) {
96 printf("%s", printBuffer);
97 column += strlen(printBuffer);
103 if (print != printBuffer) {
106 if (column != (indenting*8+1)) {
108 column = indenting*8+1;
115 if ((column != (indenting*8+1)) || (print != printBuffer)) {
119 column = indenting*8+1;
125 if ((column != (indenting*8+1)) || (print != printBuffer)) {
131 fprintf(stderr, "INTERNAL ERROR: indenting < 0.\n");
134 column = indenting*8+1;
142 *print++ = character;
161 sprintf(place, "%02x", i);
172 sprintf(place, "%d", i);
182 sprintf(place, "%x", i);
190 putChar(ebc_asc[character]);
191 if (ColsLeft() < 10) {
202 for (this = &astosc[0]; this <= &astosc[highestof(astosc)]; this++) {
203 if (this->function == FCN_AID) {
206 switch (this->shiftstate) {
216 case (SHIFT_UPSHIFT|SHIFT_ALT):
220 fprintf(stderr, "Bad shiftstate 0x%x.\n", this->shiftstate);
223 if (hits[this->scancode].hit[j].code == i) {
230 putstr("Unknown AID 0x");
238 if (ColsLeft() < 9) {
242 putdecimal(ScreenLine(i));
244 putdecimal(ScreenLineOffset(i));
249 /* returns the number of characters consumed */
251 DataFromNetwork(buffer, count, control)
252 register unsigned char *buffer; /* what the data is */
253 register int count; /* and how much there is */
254 int control; /* this buffer ended block? */
261 static int LastWasTerminated = 1; /* was "control" = 1 last time? */
270 if (LastWasTerminated) {
275 fprintf(stderr, "Short count received from host!\n");
280 switch (Command) { /* This had better be a read command */
281 case CMD_READ_MODIFIED:
282 putstr("read_modified command\n");
284 case CMD_SNA_READ_MODIFIED:
285 putstr("sna_read_modified command\n");
287 case CMD_SNA_READ_MODIFIED_ALL:
288 putstr("sna_read_modified_all command\n");
290 case CMD_READ_BUFFER:
291 putstr("read_buffer command\n");
293 case CMD_SNA_READ_BUFFER:
294 putstr("sna_read_buffer command\n");
299 return(1); /* We consumed everything */
304 case CMD_ERASE_WRITE:
305 putstr("erase write command ");
307 case CMD_ERASE_WRITE_ALTERNATE:
308 putstr("erase write alternate command ");
310 case CMD_SNA_ERASE_WRITE:
311 putstr("sna erase write command ");
313 case CMD_SNA_ERASE_WRITE_ALTERNATE:
314 putstr("erase write alternate command ");
316 case CMD_ERASE_ALL_UNPROTECTED:
317 putstr("erase all unprotected command ");
319 case CMD_SNA_ERASE_ALL_UNPROTECTED:
320 putstr("sna erase write command ");
323 putstr("write command ");
326 putstr("sna write command ");
329 putstr("Unexpected command code 0x");
331 putstr(" received.");
339 count -= 2; /* strip off command and wcc */
343 LastWasTerminated = 0; /* then, reset at end... */
349 /* handle an order */
351 # define Ensure(x) if (count < x) { \
353 return(origCount-(count+1)); \
355 /* XXX - should not occur */ \
375 PrintAddr(Addr3270(i,c));
388 i = Addr3270(buffer[0], buffer[1]);
398 case ORDER_EUA: /* (from [here,there), ie: half open interval] */
401 PrintAddr(Addr3270(buffer[0], buffer[1]));
406 case ORDER_YALE: /* special YALE defined order */
407 Ensure(2); /* need at least two characters */
408 putstr("YALE order");
412 putstr("UNKNOWN ORDER: 0x");
421 /* Data comes in large clumps - take it all */
426 while (count && !IsOrder(c)) {
435 LastWasTerminated = control;
436 return origCount - count;
440 DataToNetwork(buffer, count, control)
441 unsigned char *buffer;
446 #define JUST_GOT_AID 1
448 #define DATA_CONTINUE 3
449 static int state = NEED_AID;
451 int origCount = count;
468 if (aid == AID_TREQ) {
471 state = JUST_GOT_AID;
473 return origCount - count + DataToNetwork(buffer, count, control);
476 PrintAddr(Addr3270(buffer[0], buffer[1]));
481 return origCount - count + DataToNetwork(buffer, count, control);
485 if (*buffer == ORDER_SBA) {
486 if (state == DATA_CONTINUE) {
491 PrintAddr(Addr3270(buffer[1], buffer[2]));
499 state = DATA_CONTINUE;
507 if (state == DATA_CONTINUE) {
512 return origCount-count;
522 fprintf(stderr, "Non-hex digit 0x%x.\n");
528 } else if (isupper(c)) {
536 unsigned char outbound[8192], inbound[8192],
537 *outnext = outbound, *innext = inbound, *p = 0;
540 termblock(old, new, control)
542 new; /* old and new directions */
549 count = DataFromNetwork(outbound, outnext-outbound, control);
550 if (outbound+count == outnext) {
553 memcpy(outbound, outbound+count, outnext-(outbound+count));
554 outnext = outbound+count;
558 count = DataToNetwork(inbound, innext-inbound, control);
559 if (inbound+count == innext) {
562 memcpy(inbound, inbound+count, innext-(inbound+count));
563 innext = inbound+count;
569 } else if (new == '>') {
572 fprintf(stderr, "Bad direction character '%c'.\n", new);
583 memset(Orders, 0, sizeof Orders);
584 Orders[ORDER_SF] = Orders[ORDER_SBA] = Orders[ORDER_IC]
585 = Orders[ORDER_PT] = Orders[ORDER_RA] = Orders[ORDER_EUA]
586 = Orders[ORDER_YALE] = 1;
588 while (scanf("%c 0x%x\t", &new, &location) != EOF) {
589 if (new != direction) {
590 termblock(direction, new, 0);
593 while (((c = getchar()) != EOF) && (c != '\n') && (isxdigit(c))) {
596 static int state = NORMAL;
599 c = (GetXValue(c) << 4) + GetXValue(c1);
610 termblock(direction, direction, 1);