externs.h revision 1.7 1 /*
2 * Copyright (c) 1988, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
20 *
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
31 * SUCH DAMAGE.
32 *
33 * from: @(#)externs.h 8.3 (Berkeley) 5/30/95
34 * $NetBSD: externs.h,v 1.7 1996/02/24 07:32:00 jtk Exp $
35 */
36
37 #ifndef BSD
38 # define BSD 43
39 #endif
40
41 /*
42 * ucb stdio.h defines BSD as something wierd
43 */
44 #if defined(sun) && defined(__svr4__)
45 #define BSD 43
46 #endif
47
48 #ifndef USE_TERMIO
49 # if BSD > 43 || defined(SYSV_TERMIO)
50 # define USE_TERMIO
51 # endif
52 #endif
53
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <setjmp.h>
57 #if defined(CRAY) && !defined(NO_BSD_SETJMP)
58 #include <bsdsetjmp.h>
59 #endif
60 #ifndef FILIO_H
61 #include <sys/ioctl.h>
62 #else
63 #include <sys/filio.h>
64 #endif
65 #ifdef CRAY
66 # include <errno.h>
67 #endif /* CRAY */
68 #ifdef USE_TERMIO
69 # ifndef VINTR
70 # ifdef SYSV_TERMIO
71 # include <sys/termio.h>
72 # else
73 # include <sys/termios.h>
74 # define termio termios
75 # endif
76 # endif
77 #endif
78 #if defined(NO_CC_T) || !defined(USE_TERMIO)
79 # if !defined(USE_TERMIO)
80 typedef char cc_t;
81 # else
82 typedef unsigned char cc_t;
83 # endif
84 #endif
85
86 #ifndef NO_STRING_H
87 #include <string.h>
88 #else
89 #include <strings.h>
90 #endif
91
92 #ifndef _POSIX_VDISABLE
93 # ifdef sun
94 # include <sys/param.h> /* pick up VDISABLE definition, mayby */
95 # endif
96 # ifdef VDISABLE
97 # define _POSIX_VDISABLE VDISABLE
98 # else
99 # define _POSIX_VDISABLE ((cc_t)'\377')
100 # endif
101 #endif
102
103 #define SUBBUFSIZE 256
104
105 #ifndef CRAY
106 extern int errno; /* outside this world */
107 #endif /* !CRAY */
108
109 #include <sys/cdefs.h>
110 #define P __P
111
112 extern int
113 autologin, /* Autologin enabled */
114 skiprc, /* Don't process the ~/.telnetrc file */
115 eight, /* use eight bit mode (binary in and/or out */
116 flushout, /* flush output */
117 connected, /* Are we connected to the other side? */
118 globalmode, /* Mode tty should be in */
119 In3270, /* Are we in 3270 mode? */
120 telnetport, /* Are we connected to the telnet port? */
121 localflow, /* Flow control handled locally */
122 restartany, /* If flow control, restart output on any character */
123 localchars, /* we recognize interrupt/quit */
124 donelclchars, /* the user has set "localchars" */
125 showoptions,
126 net, /* Network file descriptor */
127 tin, /* Terminal input file descriptor */
128 tout, /* Terminal output file descriptor */
129 crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
130 autoflush, /* flush output when interrupting? */
131 autosynch, /* send interrupt characters with SYNCH? */
132 SYNCHing, /* Is the stream in telnet SYNCH mode? */
133 donebinarytoggle, /* the user has put us in binary */
134 dontlecho, /* do we suppress local echoing right now? */
135 crmod,
136 netdata, /* Print out network data flow */
137 prettydump, /* Print "netdata" output in user readable format */
138 #if defined(unix)
139 #if defined(TN3270)
140 cursesdata, /* Print out curses data flow */
141 apitrace, /* Trace API transactions */
142 #endif /* defined(TN3270) */
143 termdata, /* Print out terminal data flow */
144 #endif /* defined(unix) */
145 debug, /* Debug level */
146 clienteof; /* Client received EOF */
147
148 extern cc_t escape; /* Escape to command mode */
149 extern cc_t rlogin; /* Rlogin mode escape character */
150 #ifdef KLUDGELINEMODE
151 extern cc_t echoc; /* Toggle local echoing */
152 #endif
153
154 extern char
155 *prompt; /* Prompt for command. */
156
157 extern char
158 doopt[],
159 dont[],
160 will[],
161 wont[],
162 options[], /* All the little options */
163 *hostname; /* Who are we connected to? */
164
165 /*
166 * We keep track of each side of the option negotiation.
167 */
168
169 #define MY_STATE_WILL 0x01
170 #define MY_WANT_STATE_WILL 0x02
171 #define MY_STATE_DO 0x04
172 #define MY_WANT_STATE_DO 0x08
173
174 /*
175 * Macros to check the current state of things
176 */
177
178 #define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
179 #define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
180 #define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
181 #define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
182
183 #define my_state_is_dont(opt) (!my_state_is_do(opt))
184 #define my_state_is_wont(opt) (!my_state_is_will(opt))
185 #define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
186 #define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
187
188 #define set_my_state_do(opt) {options[opt] |= MY_STATE_DO;}
189 #define set_my_state_will(opt) {options[opt] |= MY_STATE_WILL;}
190 #define set_my_want_state_do(opt) {options[opt] |= MY_WANT_STATE_DO;}
191 #define set_my_want_state_will(opt) {options[opt] |= MY_WANT_STATE_WILL;}
192
193 #define set_my_state_dont(opt) {options[opt] &= ~MY_STATE_DO;}
194 #define set_my_state_wont(opt) {options[opt] &= ~MY_STATE_WILL;}
195 #define set_my_want_state_dont(opt) {options[opt] &= ~MY_WANT_STATE_DO;}
196 #define set_my_want_state_wont(opt) {options[opt] &= ~MY_WANT_STATE_WILL;}
197
198 /*
199 * Make everything symetrical
200 */
201
202 #define HIS_STATE_WILL MY_STATE_DO
203 #define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
204 #define HIS_STATE_DO MY_STATE_WILL
205 #define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
206
207 #define his_state_is_do my_state_is_will
208 #define his_state_is_will my_state_is_do
209 #define his_want_state_is_do my_want_state_is_will
210 #define his_want_state_is_will my_want_state_is_do
211
212 #define his_state_is_dont my_state_is_wont
213 #define his_state_is_wont my_state_is_dont
214 #define his_want_state_is_dont my_want_state_is_wont
215 #define his_want_state_is_wont my_want_state_is_dont
216
217 #define set_his_state_do set_my_state_will
218 #define set_his_state_will set_my_state_do
219 #define set_his_want_state_do set_my_want_state_will
220 #define set_his_want_state_will set_my_want_state_do
221
222 #define set_his_state_dont set_my_state_wont
223 #define set_his_state_wont set_my_state_dont
224 #define set_his_want_state_dont set_my_want_state_wont
225 #define set_his_want_state_wont set_my_want_state_dont
226
227
228 extern FILE
229 *NetTrace; /* Where debugging output goes */
230 extern unsigned char
231 NetTraceFile[]; /* Name of file where debugging output goes */
232 extern void
233 SetNetTrace P((char *)); /* Function to change where debugging goes */
234
235 extern jmp_buf
236 peerdied,
237 toplevel; /* For error conditions. */
238
239 extern void
240 command P((int, char *, int)),
241 Dump P((int, unsigned char *, int)),
242 init_3270 P((void)),
243 printoption P((char *, int, int)),
244 printsub P((int, unsigned char *, int)),
245 sendnaws P((void)),
246 setconnmode P((int)),
247 setcommandmode P((void)),
248 setneturg P((void)),
249 sys_telnet_init P((void)),
250 telnet P((char *)),
251 tel_enter_binary P((int)),
252 TerminalFlushOutput P((void)),
253 TerminalNewMode P((int)),
254 TerminalRestoreState P((void)),
255 TerminalSaveState P((void)),
256 tninit P((void)),
257 upcase P((char *)),
258 willoption P((int)),
259 wontoption P((int));
260
261 extern void
262 send_do P((int, int)),
263 send_dont P((int, int)),
264 send_will P((int, int)),
265 send_wont P((int, int));
266
267 extern void
268 lm_will P((unsigned char *, int)),
269 lm_wont P((unsigned char *, int)),
270 lm_do P((unsigned char *, int)),
271 lm_dont P((unsigned char *, int)),
272 lm_mode P((unsigned char *, int, int));
273
274 extern void
275 slc_init P((void)),
276 slcstate P((void)),
277 slc_mode_export P((void)),
278 slc_mode_import P((int)),
279 slc_import P((int)),
280 slc_export P((void)),
281 slc P((unsigned char *, int)),
282 slc_check P((void)),
283 slc_start_reply P((void)),
284 slc_add_reply P((int, int, int)),
285 slc_end_reply P((void));
286 extern int
287 slc_update P((void));
288
289 extern void
290 env_opt P((unsigned char *, int)),
291 env_opt_start P((void)),
292 env_opt_start_info P((void)),
293 env_opt_add P((unsigned char *)),
294 env_opt_end P((int));
295
296 extern unsigned char
297 *env_default P((int, int)),
298 *env_getvalue P((unsigned char *));
299
300 extern int
301 get_status P((void)),
302 dosynch P((void));
303
304 extern cc_t
305 *tcval P((int));
306
307 #ifndef USE_TERMIO
308
309 extern struct tchars ntc;
310 extern struct ltchars nltc;
311 extern struct sgttyb nttyb;
312
313 # define termEofChar ntc.t_eofc
314 # define termEraseChar nttyb.sg_erase
315 # define termFlushChar nltc.t_flushc
316 # define termIntChar ntc.t_intrc
317 # define termKillChar nttyb.sg_kill
318 # define termLiteralNextChar nltc.t_lnextc
319 # define termQuitChar ntc.t_quitc
320 # define termSuspChar nltc.t_suspc
321 # define termRprntChar nltc.t_rprntc
322 # define termWerasChar nltc.t_werasc
323 # define termStartChar ntc.t_startc
324 # define termStopChar ntc.t_stopc
325 # define termForw1Char ntc.t_brkc
326 extern cc_t termForw2Char;
327 extern cc_t termAytChar;
328
329 # define termEofCharp (cc_t *)&ntc.t_eofc
330 # define termEraseCharp (cc_t *)&nttyb.sg_erase
331 # define termFlushCharp (cc_t *)&nltc.t_flushc
332 # define termIntCharp (cc_t *)&ntc.t_intrc
333 # define termKillCharp (cc_t *)&nttyb.sg_kill
334 # define termLiteralNextCharp (cc_t *)&nltc.t_lnextc
335 # define termQuitCharp (cc_t *)&ntc.t_quitc
336 # define termSuspCharp (cc_t *)&nltc.t_suspc
337 # define termRprntCharp (cc_t *)&nltc.t_rprntc
338 # define termWerasCharp (cc_t *)&nltc.t_werasc
339 # define termStartCharp (cc_t *)&ntc.t_startc
340 # define termStopCharp (cc_t *)&ntc.t_stopc
341 # define termForw1Charp (cc_t *)&ntc.t_brkc
342 # define termForw2Charp (cc_t *)&termForw2Char
343 # define termAytCharp (cc_t *)&termAytChar
344
345 # else
346
347 extern struct termio new_tc;
348
349 # define termEofChar new_tc.c_cc[VEOF]
350 # define termEraseChar new_tc.c_cc[VERASE]
351 # define termIntChar new_tc.c_cc[VINTR]
352 # define termKillChar new_tc.c_cc[VKILL]
353 # define termQuitChar new_tc.c_cc[VQUIT]
354
355 # ifndef VSUSP
356 extern cc_t termSuspChar;
357 # else
358 # define termSuspChar new_tc.c_cc[VSUSP]
359 # endif
360 # if defined(VFLUSHO) && !defined(VDISCARD)
361 # define VDISCARD VFLUSHO
362 # endif
363 # ifndef VDISCARD
364 extern cc_t termFlushChar;
365 # else
366 # define termFlushChar new_tc.c_cc[VDISCARD]
367 # endif
368 # ifndef VWERASE
369 extern cc_t termWerasChar;
370 # else
371 # define termWerasChar new_tc.c_cc[VWERASE]
372 # endif
373 # ifndef VREPRINT
374 extern cc_t termRprntChar;
375 # else
376 # define termRprntChar new_tc.c_cc[VREPRINT]
377 # endif
378 # ifndef VLNEXT
379 extern cc_t termLiteralNextChar;
380 # else
381 # define termLiteralNextChar new_tc.c_cc[VLNEXT]
382 # endif
383 # ifndef VSTART
384 extern cc_t termStartChar;
385 # else
386 # define termStartChar new_tc.c_cc[VSTART]
387 # endif
388 # ifndef VSTOP
389 extern cc_t termStopChar;
390 # else
391 # define termStopChar new_tc.c_cc[VSTOP]
392 # endif
393 # ifndef VEOL
394 extern cc_t termForw1Char;
395 # else
396 # define termForw1Char new_tc.c_cc[VEOL]
397 # endif
398 # ifndef VEOL2
399 extern cc_t termForw2Char;
400 # else
401 # define termForw2Char new_tc.c_cc[VEOL]
402 # endif
403 # ifndef VSTATUS
404 extern cc_t termAytChar;
405 #else
406 # define termAytChar new_tc.c_cc[VSTATUS]
407 #endif
408
409 # if !defined(CRAY) || defined(__STDC__)
410 # define termEofCharp &termEofChar
411 # define termEraseCharp &termEraseChar
412 # define termIntCharp &termIntChar
413 # define termKillCharp &termKillChar
414 # define termQuitCharp &termQuitChar
415 # define termSuspCharp &termSuspChar
416 # define termFlushCharp &termFlushChar
417 # define termWerasCharp &termWerasChar
418 # define termRprntCharp &termRprntChar
419 # define termLiteralNextCharp &termLiteralNextChar
420 # define termStartCharp &termStartChar
421 # define termStopCharp &termStopChar
422 # define termForw1Charp &termForw1Char
423 # define termForw2Charp &termForw2Char
424 # define termAytCharp &termAytChar
425 # else
426 /* Work around a compiler bug */
427 # define termEofCharp 0
428 # define termEraseCharp 0
429 # define termIntCharp 0
430 # define termKillCharp 0
431 # define termQuitCharp 0
432 # define termSuspCharp 0
433 # define termFlushCharp 0
434 # define termWerasCharp 0
435 # define termRprntCharp 0
436 # define termLiteralNextCharp 0
437 # define termStartCharp 0
438 # define termStopCharp 0
439 # define termForw1Charp 0
440 # define termForw2Charp 0
441 # define termAytCharp 0
442 # endif
443 #endif
444
445
446 /* Ring buffer structures which are shared */
447
448 extern Ring
449 netoring,
450 netiring,
451 ttyoring,
452 ttyiring;
453
454 /* Tn3270 section */
455 #if defined(TN3270)
456
457 extern int
458 HaveInput, /* Whether an asynchronous I/O indication came in */
459 noasynchtty, /* Don't do signals on I/O (SIGURG, SIGIO) */
460 noasynchnet, /* Don't do signals on I/O (SIGURG, SIGIO) */
461 sigiocount, /* Count of SIGIO receptions */
462 shell_active; /* Subshell is active */
463
464 extern char
465 *Ibackp, /* Oldest byte of 3270 data */
466 Ibuf[], /* 3270 buffer */
467 *Ifrontp, /* Where next 3270 byte goes */
468 tline[],
469 *transcom; /* Transparent command */
470
471 extern int
472 settranscom P((int, char**));
473
474 extern void
475 inputAvailable P((int));
476 #endif /* defined(TN3270) */
477