1 /* $NetBSD: prt3270.c,v 1.10 2006/11/09 20:59:23 christos Exp $ */
4 * Copyright (c) 1988 The Regents of the University of California.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 #if defined(__COPYRIGHT) && !defined(lint)
35 __COPYRIGHT("@(#) Copyright (c) 1988\
36 The Regents of the University of California. All rights reserved.");
40 #if defined(__RCSID) && !defined(lint)
42 static char sccsid
[] = "@(#)prt3270.c 4.2 (Berkeley) 4/26/91";
44 __RCSID("$NetBSD: prt3270.c,v 1.10 2006/11/09 20:59:23 christos Exp $");
52 #define DEFINING_INSTANCES
53 #include "../general/general.h"
55 #include "../api/asc_ebc.h"
56 #include "../ctlr/hostctlr.h"
57 #include "../ctlr/screen.h"
58 #include "../ctlr/function.h"
59 #include "../api/astosc.h"
60 #include "../general/globals.h"
65 int NumberColumns
= 80;
73 unsigned char printBuffer
[200], *print
= printBuffer
;
75 #define ColsLeft() (79-column) /* A little room for error */
91 int DataFromNetwork(unsigned char *, int, int);
92 int DataToNetwork(unsigned char *, int, int);
94 void termblock(int, int , int);
95 int main(int, char *[]);
100 unsigned char *ourPrint
= print
;
102 print
= printBuffer
; /* For mutual calls */
104 if (ColsLeft() < 0) {
107 if (column
!= (indenting
*8+1)) {
114 for (i
= 0; i
< indenting
; i
++) {
118 printf("%s", printBuffer
);
119 column
+= strlen(printBuffer
);
125 if (print
!= printBuffer
) {
128 if (column
!= (indenting
*8+1)) {
130 column
= indenting
*8+1;
137 if ((column
!= (indenting
*8+1)) || (print
!= printBuffer
)) {
141 column
= indenting
*8+1;
147 if ((column
!= (indenting
*8+1)) || (print
!= printBuffer
)) {
153 fprintf(stderr
, "INTERNAL ERROR: indenting < 0.\n");
156 column
= indenting
*8+1;
164 *print
++ = character
;
183 sprintf(place
, "%02x", i
);
194 sprintf(place
, "%d", i
);
204 sprintf(place
, "%x", i
);
212 putChar(ebc_asc
[character
]);
213 if (ColsLeft() < 10) {
224 for (this = &astosc
[0]; this <= &astosc
[highestof(astosc
)]; this++) {
225 if (this->function
== FCN_AID
) {
228 switch (this->shiftstate
) {
238 case (SHIFT_UPSHIFT
|SHIFT_ALT
):
242 fprintf(stderr
, "Bad shiftstate 0x%x.\n", this->shiftstate
);
245 if (hits
[this->scancode
].hit
[j
].code
== i
) {
252 putstr("Unknown AID 0x");
260 if (ColsLeft() < 9) {
264 putdecimal(ScreenLine(i
));
266 putdecimal(ScreenLineOffset(i
));
271 /* returns the number of characters consumed */
273 DataFromNetwork(buffer
, count
, control
)
274 unsigned char *buffer
; /* what the data is */
275 int count
; /* and how much there is */
276 int control
; /* this buffer ended block? */
283 static int LastWasTerminated
= 1; /* was "control" = 1 last time? */
292 if (LastWasTerminated
) {
297 fprintf(stderr
, "Short count received from host!\n");
302 switch (Command
) { /* This had better be a read command */
303 case CMD_READ_MODIFIED
:
304 putstr("read_modified command\n");
306 case CMD_SNA_READ_MODIFIED
:
307 putstr("sna_read_modified command\n");
309 case CMD_SNA_READ_MODIFIED_ALL
:
310 putstr("sna_read_modified_all command\n");
312 case CMD_READ_BUFFER
:
313 putstr("read_buffer command\n");
315 case CMD_SNA_READ_BUFFER
:
316 putstr("sna_read_buffer command\n");
321 return(1); /* We consumed everything */
326 case CMD_ERASE_WRITE
:
327 putstr("erase write command ");
329 case CMD_ERASE_WRITE_ALTERNATE
:
330 putstr("erase write alternate command ");
332 case CMD_SNA_ERASE_WRITE
:
333 putstr("sna erase write command ");
335 case CMD_SNA_ERASE_WRITE_ALTERNATE
:
336 putstr("erase write alternate command ");
338 case CMD_ERASE_ALL_UNPROTECTED
:
339 putstr("erase all unprotected command ");
341 case CMD_SNA_ERASE_ALL_UNPROTECTED
:
342 putstr("sna erase write command ");
345 putstr("write command ");
348 putstr("sna write command ");
351 putstr("Unexpected command code 0x");
353 putstr(" received.");
361 count
-= 2; /* strip off command and wcc */
365 LastWasTerminated
= 0; /* then, reset at end... */
371 /* handle an order */
373 # define Ensure(x) if (count < x) { \
375 return(origCount-(count+1)); \
377 /* XXX - should not occur */ \
397 PrintAddr(Addr3270(i
,c
));
410 i
= Addr3270(buffer
[0], buffer
[1]);
420 case ORDER_EUA
: /* (from [here,there), ie: half open interval] */
423 PrintAddr(Addr3270(buffer
[0], buffer
[1]));
428 case ORDER_YALE
: /* special YALE defined order */
429 Ensure(2); /* need at least two characters */
430 putstr("YALE order");
434 putstr("UNKNOWN ORDER: 0x");
443 /* Data comes in large clumps - take it all */
448 while (count
&& !IsOrder(c
)) {
457 LastWasTerminated
= control
;
458 return origCount
- count
;
462 DataToNetwork(buffer
, count
, control
)
463 unsigned char *buffer
;
468 #define JUST_GOT_AID 1
470 #define DATA_CONTINUE 3
471 static int state
= NEED_AID
;
473 int origCount
= count
;
490 if (aid
== AID_TREQ
) {
493 state
= JUST_GOT_AID
;
495 return origCount
- count
+ DataToNetwork(buffer
, count
, control
);
498 PrintAddr(Addr3270(buffer
[0], buffer
[1]));
503 return origCount
- count
+ DataToNetwork(buffer
, count
, control
);
507 if (*buffer
== ORDER_SBA
) {
508 if (state
== DATA_CONTINUE
) {
513 PrintAddr(Addr3270(buffer
[1], buffer
[2]));
521 state
= DATA_CONTINUE
;
529 if (state
== DATA_CONTINUE
) {
534 return origCount
-count
;
545 fprintf(stderr
, "Non-hex digit 0x%x.\n", c
);
551 } else if (isupper(c
)) {
559 unsigned char outbound
[8192], inbound
[8192],
560 *outnext
= outbound
, *innext
= inbound
, *p
= 0;
563 termblock(old
, new, control
)
565 new; /* old and new directions */
572 count
= DataFromNetwork(outbound
, outnext
-outbound
, control
);
573 if (outbound
+count
== outnext
) {
576 memcpy(outbound
, outbound
+count
, outnext
-(outbound
+count
));
577 outnext
= outbound
+count
;
581 count
= DataToNetwork(inbound
, innext
-inbound
, control
);
582 if (inbound
+count
== innext
) {
585 memcpy(inbound
, inbound
+count
, innext
-(inbound
+count
));
586 innext
= inbound
+count
;
592 } else if (new == '>') {
595 fprintf(stderr
, "Bad direction character '%c'.\n", new);
609 memset(Orders
, 0, sizeof Orders
);
610 Orders
[ORDER_SF
] = Orders
[ORDER_SBA
] = Orders
[ORDER_IC
]
611 = Orders
[ORDER_PT
] = Orders
[ORDER_RA
] = Orders
[ORDER_EUA
]
612 = Orders
[ORDER_YALE
] = 1;
614 while (scanf("%c 0x%x\t", &new, &location
) != EOF
) {
615 if (new != direction
) {
616 termblock(direction
, new, 0);
619 while (((c
= getchar()) != EOF
) && (c
!= '\n') && (isxdigit(c
))) {
622 static int state
= NORMAL
;
625 c
= (GetXValue(c
) << 4) + GetXValue(c1
);
636 termblock(direction
, direction
, 1);