]>
git.saurik.com Git - apple/network_cmds.git/blob - telnet.tproj/tn3270.c
0e44ea907521120d0e91e2b10c08f66a1d356b13
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1988, 1993
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 static char sccsid
[] = "@(#)tn3270.c 8.2 (Berkeley) 5/30/95";
60 #include <sys/types.h>
61 #include <arpa/telnet.h>
72 #include "../ctlr/screen.h"
73 #include "../general/globals.h"
75 #include "../sys_curses/telextrn.h"
76 #include "../ctlr/externs.h"
78 #if defined(unix) || defined(__APPLE__)
80 HaveInput
, /* There is input available to scan */
81 cursesdata
, /* Do we dump curses data? */
82 sigiocount
; /* Number of times we got a SIGIO */
85 char *transcom
= 0; /* transparent mode command (default: none) */
86 #endif /* defined(unix) || defined(__APPLE__) */
88 char Ibuf
[8*BUFSIZ
], *Ifrontp
, *Ibackp
;
90 static char sb_terminal
[] = { IAC
, SB
,
91 TELOPT_TTYPE
, TELQUAL_IS
,
92 'I', 'B', 'M', '-', '3', '2', '7', '8', '-', '2',
94 #define SBTERMMODEL 13
97 Sent3270TerminalType
; /* Have we said we are a 3270? */
99 #endif /* defined(TN3270) */
106 #if defined(unix) || defined(__APPLE__)
109 #endif /* defined(unix) || defined(__APPLE__) */
110 Sent3270TerminalType
= 0;
111 Ifrontp
= Ibackp
= Ibuf
;
112 init_ctlr(); /* Initialize some things */
116 #endif /* defined(TN3270) */
123 * DataToNetwork - queue up some data to go to network. If "done" is set,
124 * then when last byte is queued, we add on an IAC EOR sequence (so,
125 * don't call us with "done" until you want that done...)
127 * We actually do send all the data to the network buffer, since our
128 * only client needs for us to do that.
132 DataToNetwork(buffer
, count
, done
)
133 register char *buffer
; /* where the data is */
134 register int count
; /* how much to send */
135 int done
; /* is this the last of a logical block */
137 register int loop
, c
;
143 /* If not enough room for EORs, IACs, etc., wait */
149 while (NETROOM() < 6) {
151 (void) select(net
+1, (fd_set
*) 0, &o
, (fd_set
*) 0,
152 (struct timeval
*) 0);
156 c
= ring_empty_count(&netoring
);
162 if (((unsigned char)*buffer
) == IAC
) {
169 ring_supply_data(&netoring
, buffer
-c
, c
);
181 netflush(); /* try to move along as quickly as ... */
183 return(origCount
- count
);
187 #if defined(unix) || defined(__APPLE__)
189 inputAvailable(signo
)
195 #endif /* defined(unix) || defined(__APPLE__) */
205 * The following routines are places where the various tn3270
206 * routines make calls into telnet.c.
210 * DataToTerminal - queue up some data to go to terminal.
212 * Note: there are people who call us and depend on our processing
213 * *all* the data at one time (thus the select).
217 DataToTerminal(buffer
, count
)
218 register char *buffer
; /* where the data is */
219 register int count
; /* how much to send */
227 if (TTYROOM() == 0) {
228 #if defined(unix) || defined(__APPLE__)
232 #endif /* defined(unix) || defined(__APPLE__) */
234 while (TTYROOM() == 0) {
235 #if defined(unix) || defined(__APPLE__)
237 (void) select(tout
+1, (fd_set
*) 0, &o
, (fd_set
*) 0,
238 (struct timeval
*) 0);
239 #endif /* defined(unix) || defined(__APPLE__) */
247 ring_supply_data(&ttyoring
, buffer
, c
);
256 * Push3270 - Try to send data along the 3270 output (to screen) direction.
262 int save
= ring_full_count(&netiring
);
265 if (Ifrontp
+save
> Ibuf
+sizeof Ibuf
) {
266 if (Ibackp
!= Ibuf
) {
267 memmove(Ibuf
, Ibackp
, Ifrontp
-Ibackp
);
268 Ifrontp
-= (Ibackp
-Ibuf
);
272 if (Ifrontp
+save
< Ibuf
+sizeof Ibuf
) {
276 return save
!= ring_full_count(&netiring
);
281 * Finish3270 - get the last dregs of 3270 data out to the terminal
288 while (Push3270() || !DoTerminalOutput()) {
289 #if defined(unix) || defined(__APPLE__)
291 #endif /* defined(unix) || defined(__APPLE__) */
297 /* StringToTerminal - output a null terminated string to the terminal */
307 (void) DataToTerminal(s
, count
); /* we know it always goes... */
312 #if ((!defined(NOT43)) || defined(PUTCHAR))
313 /* _putchar - output a single character to the terminal. This name is so that
314 * curses(3x) can call us to send out data.
321 #if defined(sun) /* SunOS 4.0 bug */
323 #endif /* defined(sun) */
328 (void) DataToTerminal(&c
, 1);
333 #endif /* ((!defined(NOT43)) || defined(PUTCHAR)) */
338 if (Sent3270TerminalType
&& my_want_state_is_will(TELOPT_BINARY
)
339 && my_want_state_is_do(TELOPT_BINARY
) && !donebinarytoggle
) {
342 Init3270(); /* Initialize 3270 functions */
343 /* initialize terminal key mapping */
344 InitTerminal(); /* Start terminal going */
351 Stop3270(); /* Tell 3270 we aren't here anymore */
360 * Send a response to a terminal type negotiation.
362 * Return '0' if no more responses to send; '1' if a response sent.
369 * Try to send a 3270 type terminal name. Decide which one based
370 * on the format of our screen, and (in the future) color
373 InitTerminal(); /* Sets MaxNumberColumns, MaxNumberLines */
374 if ((MaxNumberLines
>= 24) && (MaxNumberColumns
>= 80)) {
375 Sent3270TerminalType
= 1;
376 if ((MaxNumberLines
>= 27) && (MaxNumberColumns
>= 132)) {
378 MaxNumberColumns
= 132;
379 sb_terminal
[SBTERMMODEL
] = '5';
380 } else if (MaxNumberLines
>= 43) {
382 MaxNumberColumns
= 80;
383 sb_terminal
[SBTERMMODEL
] = '4';
384 } else if (MaxNumberLines
>= 32) {
386 MaxNumberColumns
= 80;
387 sb_terminal
[SBTERMMODEL
] = '3';
390 MaxNumberColumns
= 80;
391 sb_terminal
[SBTERMMODEL
] = '2';
393 NumberLines
= 24; /* before we start out... */
395 ScreenSize
= NumberLines
*NumberColumns
;
396 if ((MaxNumberLines
*MaxNumberColumns
) > MAXSCREENSIZE
) {
397 ExitString("Programming error: MAXSCREENSIZE too small.\n",
401 printsub('>', sb_terminal
+2, sizeof sb_terminal
-2);
402 ring_supply_data(&netoring
, sb_terminal
, sizeof sb_terminal
);
409 #if defined(unix) || defined(__APPLE__)
411 settranscom(argc
, argv
)
417 if (argc
== 1 && transcom
) {
424 (void) strcpy(transcom
, argv
[1]);
425 for (i
= 2; i
< argc
; ++i
) {
426 (void) strcat(transcom
, " ");
427 (void) strcat(transcom
, argv
[i
]);
431 #endif /* defined(unix) || defined(__APPLE__) */
433 #endif /* defined(TN3270) */