* Copyright (c) 1988 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of California at Berkeley. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
static char sccsid
[] = "@(#)tn3270.c 1.9 (Berkeley) %G%";
#include "../ctlr/screen.h"
#include "../general/globals.h"
char *transcom
= 0; /* transparent mode command (default: none) */
#endif /* defined(unix) */
char Ibuf
[8*BUFSIZ
], *Ifrontp
, *Ibackp
;
static char sb_terminal
[] = { IAC
, SB
,
TELOPT_TTYPE
, TELQUAL_IS
,
'I', 'B', 'M', '-', '3', '2', '7', '8', '-', '2',
Sent3270TerminalType
; /* Have we said we are a 3270? */
#endif /* defined(TN3270) */
Sent3270TerminalType
= 0;
init_ctlr(); /* Initialize some things */
#endif /* defined(TN3270) */
* DataToNetwork - queue up some data to go to network. If "done" is set,
* then when last byte is queued, we add on an IAC EOR sequence (so,
* don't call us with "done" until you want that done...)
* We actually do send all the data to the network buffer, since our
* only client needs for us to do that.
DataToNetwork(buffer
, count
, done
)
register char *buffer
; /* where the data is */
register int count
; /* how much to send */
int done
; /* is this the last of a logical block */
/* If not enough room for EORs, IACs, etc., wait */
(void) select(net
+1, (fd_set
*) 0, &o
, (fd_set
*) 0,
c
= ring_empty_count(&netoring
);
ring_supply_data(&netoring
, buffer
-c
, c
);
netflush(); /* try to move along as quickly as ... */
return(origCount
- count
);
#endif /* defined(unix) */
* The following routines are places where the various tn3270
* routines make calls into telnet.c.
* DataToTerminal - queue up some data to go to terminal.
* Note: there are people who call us and depend on our processing
* *all* the data at one time (thus the select).
DataToTerminal(buffer
, count
)
register char *buffer
; /* where the data is */
register int count
; /* how much to send */
#endif /* defined(unix) */
(void) select(tout
+1, (fd_set
*) 0, &o
, (fd_set
*) 0,
#endif /* defined(unix) */
ring_supply_data(&ttyoring
, buffer
, c
);
/* EmptyTerminal - called to make sure that the terminal buffer is empty.
* Note that we consider the buffer to run all the
* way to the kernel (thus the select).
#endif /* defined(unix) */
(void) select(tout
+1, (int *) 0, &o
, (int *) 0,
(struct timeval
*) 0); /* wait for TTLOWAT */
#endif /* defined(unix) */
(void) select(tout
+1, (int *) 0, &o
, (int *) 0,
(struct timeval
*) 0); /* wait for TTLOWAT */
#endif /* defined(unix) */
* Push3270 - Try to send data along the 3270 output (to screen) direction.
int save
= ring_full_count(&netiring
);
if (Ifrontp
+save
> Ibuf
+sizeof Ibuf
) {
memcpy(Ibuf
, Ibackp
, Ifrontp
-Ibackp
);
Ifrontp
-= (Ibackp
-Ibuf
);
if (Ifrontp
+save
< Ibuf
+sizeof Ibuf
) {
return save
!= ring_full_count(&netiring
);
* Finish3270 - get the last dregs of 3270 data out to the terminal
while (Push3270() || !DoTerminalOutput()) {
#endif /* defined(unix) */
/* StringToTerminal - output a null terminated string to the terminal */
(void) DataToTerminal(s
, count
); /* we know it always goes... */
#if ((!defined(NOT43)) || defined(PUTCHAR))
/* _putchar - output a single character to the terminal. This name is so that
* curses(3x) can call us to send out data.
(void) DataToTerminal(&c
, 1);
#endif /* ((!defined(NOT43)) || defined(PUTCHAR)) */
ExitString(string
, returnCode
)
fwrite(string
, 1, strlen(string
), stderr
);
ExitPerror(string
, returnCode
)
if (Sent3270TerminalType
&& myopts
[TELOPT_BINARY
]
&& hisopts
[TELOPT_BINARY
] && !donebinarytoggle
) {
Init3270(); /* Initialize 3270 functions */
/* initialize terminal key mapping */
InitTerminal(); /* Start terminal going */
Stop3270(); /* Tell 3270 we aren't here anymore */
* Send a response to a terminal type negotiation.
* Return '0' if no more responses to send; '1' if a response sent.
* Try to send a 3270 type terminal name. Decide which one based
* on the format of our screen, and (in the future) color
InitTerminal(); /* Sets MaxNumberColumns, MaxNumberLines */
if ((MaxNumberLines
>= 24) && (MaxNumberColumns
>= 80)) {
Sent3270TerminalType
= 1;
if ((MaxNumberLines
>= 27) && (MaxNumberColumns
>= 132)) {
sb_terminal
[SBTERMMODEL
] = '5';
} else if (MaxNumberLines
>= 43) {
sb_terminal
[SBTERMMODEL
] = '4';
} else if (MaxNumberLines
>= 32) {
sb_terminal
[SBTERMMODEL
] = '3';
sb_terminal
[SBTERMMODEL
] = '2';
NumberLines
= 24; /* before we start out... */
ScreenSize
= NumberLines
*NumberColumns
;
if ((MaxNumberLines
*MaxNumberColumns
) > MAXSCREENSIZE
) {
ExitString("Programming error: MAXSCREENSIZE too small.\n",
printsub(">", sb_terminal
+2, sizeof sb_terminal
-2);
ring_supply_data(&netoring
, sb_terminal
, sizeof sb_terminal
);
if (argc
== 1 && transcom
) {
for (i
= 1; i
< argc
; ++i
) {
len
+= 1 + strlen(argv
[1]);
(void) strcpy(transcom
, argv
[1]);
for (i
= 2; i
< argc
; ++i
) {
(void) strcat(transcom
, " ");
(void) strcat(transcom
, argv
[i
]);
#endif /* defined(unix) */
#endif /* defined(TN3270) */