]>
git.cameronkatri.com Git - apple_cmds.git/blob - remote_cmds/telnet.tproj/tn3270.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1988, 1993
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 #include <sys/cdefs.h>
59 __unused
static char sccsid
[] = "@(#)tn3270.c 8.2 (Berkeley) 5/30/95";
62 #include <sys/types.h>
63 #include <arpa/telnet.h>
74 #include "../ctlr/screen.h"
75 #include "../general/globals.h"
77 #include "../sys_curses/telextrn.h"
78 #include "../ctlr/externs.h"
80 #if defined(unix) || defined(__APPLE__)
82 HaveInput
, /* There is input available to scan */
83 cursesdata
, /* Do we dump curses data? */
84 sigiocount
; /* Number of times we got a SIGIO */
87 char *transcom
= 0; /* transparent mode command (default: none) */
88 #endif /* defined(unix) || defined(__APPLE__) */
90 char Ibuf
[8*BUFSIZ
], *Ifrontp
, *Ibackp
;
92 static char sb_terminal
[] = { IAC
, SB
,
93 TELOPT_TTYPE
, TELQUAL_IS
,
94 'I', 'B', 'M', '-', '3', '2', '7', '8', '-', '2',
96 #define SBTERMMODEL 13
99 Sent3270TerminalType
; /* Have we said we are a 3270? */
101 #endif /* defined(TN3270) */
108 #if defined(unix) || defined(__APPLE__)
111 #endif /* defined(unix) || defined(__APPLE__) */
112 Sent3270TerminalType
= 0;
113 Ifrontp
= Ibackp
= Ibuf
;
114 init_ctlr(); /* Initialize some things */
118 #endif /* defined(TN3270) */
125 * DataToNetwork - queue up some data to go to network. If "done" is set,
126 * then when last byte is queued, we add on an IAC EOR sequence (so,
127 * don't call us with "done" until you want that done...)
129 * We actually do send all the data to the network buffer, since our
130 * only client needs for us to do that.
134 DataToNetwork(buffer
, count
, done
)
135 register char *buffer
; /* where the data is */
136 register int count
; /* how much to send */
137 int done
; /* is this the last of a logical block */
139 register int loop
, c
;
145 /* If not enough room for EORs, IACs, etc., wait */
151 while (NETROOM() < 6) {
153 (void) select(net
+1, (fd_set
*) 0, &o
, (fd_set
*) 0,
154 (struct timeval
*) 0);
158 c
= ring_empty_count(&netoring
);
164 if (((unsigned char)*buffer
) == IAC
) {
171 ring_supply_data(&netoring
, buffer
-c
, c
);
183 netflush(); /* try to move along as quickly as ... */
185 return(origCount
- count
);
189 #if defined(unix) || defined(__APPLE__)
191 inputAvailable(signo
)
197 #endif /* defined(unix) || defined(__APPLE__) */
207 * The following routines are places where the various tn3270
208 * routines make calls into telnet.c.
212 * DataToTerminal - queue up some data to go to terminal.
214 * Note: there are people who call us and depend on our processing
215 * *all* the data at one time (thus the select).
219 DataToTerminal(buffer
, count
)
220 register char *buffer
; /* where the data is */
221 register int count
; /* how much to send */
229 if (TTYROOM() == 0) {
230 #if defined(unix) || defined(__APPLE__)
234 #endif /* defined(unix) || defined(__APPLE__) */
236 while (TTYROOM() == 0) {
237 #if defined(unix) || defined(__APPLE__)
239 (void) select(tout
+1, (fd_set
*) 0, &o
, (fd_set
*) 0,
240 (struct timeval
*) 0);
241 #endif /* defined(unix) || defined(__APPLE__) */
249 ring_supply_data(&ttyoring
, buffer
, c
);
258 * Push3270 - Try to send data along the 3270 output (to screen) direction.
264 int save
= ring_full_count(&netiring
);
267 if (Ifrontp
+save
> Ibuf
+sizeof Ibuf
) {
268 if (Ibackp
!= Ibuf
) {
269 memmove(Ibuf
, Ibackp
, Ifrontp
-Ibackp
);
270 Ifrontp
-= (Ibackp
-Ibuf
);
274 if (Ifrontp
+save
< Ibuf
+sizeof Ibuf
) {
278 return save
!= ring_full_count(&netiring
);
283 * Finish3270 - get the last dregs of 3270 data out to the terminal
290 while (Push3270() || !DoTerminalOutput()) {
291 #if defined(unix) || defined(__APPLE__)
293 #endif /* defined(unix) || defined(__APPLE__) */
299 /* StringToTerminal - output a null terminated string to the terminal */
309 (void) DataToTerminal(s
, count
); /* we know it always goes... */
314 #if ((!defined(NOT43)) || defined(PUTCHAR))
315 /* _putchar - output a single character to the terminal. This name is so that
316 * curses(3x) can call us to send out data.
323 #if defined(sun) /* SunOS 4.0 bug */
325 #endif /* defined(sun) */
330 (void) DataToTerminal(&c
, 1);
335 #endif /* ((!defined(NOT43)) || defined(PUTCHAR)) */
340 if (Sent3270TerminalType
&& my_want_state_is_will(TELOPT_BINARY
)
341 && my_want_state_is_do(TELOPT_BINARY
) && !donebinarytoggle
) {
344 Init3270(); /* Initialize 3270 functions */
345 /* initialize terminal key mapping */
346 InitTerminal(); /* Start terminal going */
353 Stop3270(); /* Tell 3270 we aren't here anymore */
362 * Send a response to a terminal type negotiation.
364 * Return '0' if no more responses to send; '1' if a response sent.
371 * Try to send a 3270 type terminal name. Decide which one based
372 * on the format of our screen, and (in the future) color
375 InitTerminal(); /* Sets MaxNumberColumns, MaxNumberLines */
376 if ((MaxNumberLines
>= 24) && (MaxNumberColumns
>= 80)) {
377 Sent3270TerminalType
= 1;
378 if ((MaxNumberLines
>= 27) && (MaxNumberColumns
>= 132)) {
380 MaxNumberColumns
= 132;
381 sb_terminal
[SBTERMMODEL
] = '5';
382 } else if (MaxNumberLines
>= 43) {
384 MaxNumberColumns
= 80;
385 sb_terminal
[SBTERMMODEL
] = '4';
386 } else if (MaxNumberLines
>= 32) {
388 MaxNumberColumns
= 80;
389 sb_terminal
[SBTERMMODEL
] = '3';
392 MaxNumberColumns
= 80;
393 sb_terminal
[SBTERMMODEL
] = '2';
395 NumberLines
= 24; /* before we start out... */
397 ScreenSize
= NumberLines
*NumberColumns
;
398 if ((MaxNumberLines
*MaxNumberColumns
) > MAXSCREENSIZE
) {
399 ExitString("Programming error: MAXSCREENSIZE too small.\n",
403 printsub('>', sb_terminal
+2, sizeof sb_terminal
-2);
404 ring_supply_data(&netoring
, sb_terminal
, sizeof sb_terminal
);
411 #if defined(unix) || defined(__APPLE__)
413 settranscom(argc
, argv
)
419 if (argc
== 1 && transcom
) {
426 (void) strcpy(transcom
, argv
[1]);
427 for (i
= 2; i
< argc
; ++i
) {
428 (void) strcat(transcom
, " ");
429 (void) strcat(transcom
, argv
[i
]);
433 #endif /* defined(unix) || defined(__APPLE__) */
435 #endif /* defined(TN3270) */