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 const char sccsid[] = "@(#)tn3270.c 8.2 (Berkeley) 5/30/95";
38 #include <sys/types.h>
39 #include <arpa/telnet.h>
50 #include "../ctlr/screen.h"
51 #include "../general/globals.h"
53 #include "../sys_curses/telextrn.h"
54 #include "../ctlr/externs.h"
58 HaveInput, /* There is input available to scan */
59 cursesdata, /* Do we dump curses data? */
60 sigiocount; /* Number of times we got a SIGIO */
63 char *transcom = 0; /* transparent mode command (default: none) */
64 #endif /* defined(unix) */
66 char Ibuf[8*BUFSIZ], *Ifrontp, *Ibackp;
68 static char sb_terminal[] = { IAC, SB,
69 TELOPT_TTYPE, TELQUAL_IS,
70 'I', 'B', 'M', '-', '3', '2', '7', '8', '-', '2',
72 #define SBTERMMODEL 13
75 Sent3270TerminalType; /* Have we said we are a 3270? */
77 #endif /* defined(TN3270) */
87 #endif /* defined(unix) */
88 Sent3270TerminalType = 0;
89 Ifrontp = Ibackp = Ibuf;
90 init_ctlr(); /* Initialize some things */
94 #endif /* defined(TN3270) */
101 * DataToNetwork - queue up some data to go to network. If "done" is set,
102 * then when last byte is queued, we add on an IAC EOR sequence (so,
103 * don't call us with "done" until you want that done...)
105 * We actually do send all the data to the network buffer, since our
106 * only client needs for us to do that.
110 DataToNetwork(buffer, count, done)
111 register char *buffer; /* where the data is */
112 register int count; /* how much to send */
113 int done; /* is this the last of a logical block */
115 register int loop, c;
121 /* If not enough room for EORs, IACs, etc., wait */
127 while (NETROOM() < 6) {
129 (void) select(net+1, (fd_set *) 0, &o, (fd_set *) 0,
130 (struct timeval *) 0);
134 c = ring_empty_count(&netoring);
140 if (((unsigned char)*buffer) == IAC) {
147 ring_supply_data(&netoring, buffer-c, c);
159 netflush(); /* try to move along as quickly as ... */
161 return(origCount - count);
167 inputAvailable(signo)
173 #endif /* defined(unix) */
183 * The following routines are places where the various tn3270
184 * routines make calls into telnet.c.
188 * DataToTerminal - queue up some data to go to terminal.
190 * Note: there are people who call us and depend on our processing
191 * *all* the data at one time (thus the select).
195 DataToTerminal(buffer, count)
196 register char *buffer; /* where the data is */
197 register int count; /* how much to send */
205 if (TTYROOM() == 0) {
210 #endif /* defined(unix) */
212 while (TTYROOM() == 0) {
215 (void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0,
216 (struct timeval *) 0);
217 #endif /* defined(unix) */
225 ring_supply_data(&ttyoring, buffer, c);
234 * Push3270 - Try to send data along the 3270 output (to screen) direction.
240 int save = ring_full_count(&netiring);
243 if (Ifrontp+save > Ibuf+sizeof Ibuf) {
244 if (Ibackp != Ibuf) {
245 memmove(Ibuf, Ibackp, Ifrontp-Ibackp);
246 Ifrontp -= (Ibackp-Ibuf);
250 if (Ifrontp+save < Ibuf+sizeof Ibuf) {
254 return save != ring_full_count(&netiring);
259 * Finish3270 - get the last dregs of 3270 data out to the terminal
266 while (Push3270() || !DoTerminalOutput()) {
269 #endif /* defined(unix) */
275 /* StringToTerminal - output a null terminated string to the terminal */
285 (void) DataToTerminal(s, count); /* we know it always goes... */
290 #if ((!defined(NOT43)) || defined(PUTCHAR))
291 /* _putchar - output a single character to the terminal. This name is so that
292 * curses(3x) can call us to send out data.
299 #if defined(sun) /* SunOS 4.0 bug */
301 #endif /* defined(sun) */
306 (void) DataToTerminal(&c, 1);
311 #endif /* ((!defined(NOT43)) || defined(PUTCHAR)) */
316 if (Sent3270TerminalType && my_want_state_is_will(TELOPT_BINARY)
317 && my_want_state_is_do(TELOPT_BINARY) && !donebinarytoggle) {
320 Init3270(); /* Initialize 3270 functions */
321 /* initialize terminal key mapping */
322 InitTerminal(); /* Start terminal going */
329 Stop3270(); /* Tell 3270 we aren't here anymore */
338 * Send a response to a terminal type negotiation.
340 * Return '0' if no more responses to send; '1' if a response sent.
347 * Try to send a 3270 type terminal name. Decide which one based
348 * on the format of our screen, and (in the future) color
351 InitTerminal(); /* Sets MaxNumberColumns, MaxNumberLines */
352 if ((MaxNumberLines >= 24) && (MaxNumberColumns >= 80)) {
353 Sent3270TerminalType = 1;
354 if ((MaxNumberLines >= 27) && (MaxNumberColumns >= 132)) {
356 MaxNumberColumns = 132;
357 sb_terminal[SBTERMMODEL] = '5';
358 } else if (MaxNumberLines >= 43) {
360 MaxNumberColumns = 80;
361 sb_terminal[SBTERMMODEL] = '4';
362 } else if (MaxNumberLines >= 32) {
364 MaxNumberColumns = 80;
365 sb_terminal[SBTERMMODEL] = '3';
368 MaxNumberColumns = 80;
369 sb_terminal[SBTERMMODEL] = '2';
371 NumberLines = 24; /* before we start out... */
373 ScreenSize = NumberLines*NumberColumns;
374 if ((MaxNumberLines*MaxNumberColumns) > MAXSCREENSIZE) {
375 ExitString("Programming error: MAXSCREENSIZE too small.\n",
379 printsub('>', sb_terminal+2, sizeof sb_terminal-2);
380 ring_supply_data(&netoring, sb_terminal, sizeof sb_terminal);
389 settranscom(argc, argv)
395 if (argc == 1 && transcom) {
402 (void) strcpy(transcom, argv[1]);
403 for (i = 2; i < argc; ++i) {
404 (void) strcat(transcom, " ");
405 (void) strcat(transcom, argv[i]);
409 #endif /* defined(unix) */
411 #endif /* defined(TN3270) */