xref: /original-bsd/usr.bin/tip/tip.h (revision c3e32dec)
1 /*
2  * Copyright (c) 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  *
6  * %sccs.include.redist.c%
7  *
8  *      @(#)tip.h	8.1 (Berkeley) 06/06/93
9  */
10 
11 /*
12  * tip - terminal interface program
13  */
14 
15 #include <sys/types.h>
16 #include <machine/endian.h>
17 #include <sys/file.h>
18 #include <sys/time.h>
19 
20 #include <sgtty.h>
21 #include <signal.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <pwd.h>
26 #include <ctype.h>
27 #include <setjmp.h>
28 #include <unistd.h>
29 #include <errno.h>
30 
31 /*
32  * Remote host attributes
33  */
34 char	*DV;			/* UNIX device(s) to open */
35 char	*EL;			/* chars marking an EOL */
36 char	*CM;			/* initial connection message */
37 char	*IE;			/* EOT to expect on input */
38 char	*OE;			/* EOT to send to complete FT */
39 char	*CU;			/* call unit if making a phone call */
40 char	*AT;			/* acu type */
41 char	*PN;			/* phone number(s) */
42 char	*DI;			/* disconnect string */
43 char	*PA;			/* parity to be generated */
44 
45 char	*PH;			/* phone number file */
46 char	*RM;			/* remote file name */
47 char	*HO;			/* host name */
48 
49 long	BR;			/* line speed for conversation */
50 long	FS;			/* frame size for transfers */
51 
52 char	DU;			/* this host is dialed up */
53 char	HW;			/* this device is hardwired, see hunt.c */
54 char	*ES;			/* escape character */
55 char	*EX;			/* exceptions */
56 char	*FO;			/* force (literal next) char*/
57 char	*RC;			/* raise character */
58 char	*RE;			/* script record file */
59 char	*PR;			/* remote prompt */
60 long	DL;			/* line delay for file transfers to remote */
61 long	CL;			/* char delay for file transfers to remote */
62 long	ET;			/* echocheck timeout */
63 char	HD;			/* this host is half duplex - do local echo */
64 
65 /*
66  * String value table
67  */
68 typedef
69 	struct {
70 		char	*v_name;	/* whose name is it */
71 		char	v_type;		/* for interpreting set's */
72 		char	v_access;	/* protection of touchy ones */
73 		char	*v_abrev;	/* possible abreviation */
74 		char	*v_value;	/* casted to a union later */
75 	}
76 	value_t;
77 
78 #define STRING	01		/* string valued */
79 #define BOOL	02		/* true-false value */
80 #define NUMBER	04		/* numeric value */
81 #define CHAR	010		/* character value */
82 
83 #define WRITE	01		/* write access to variable */
84 #define	READ	02		/* read access */
85 
86 #define CHANGED	01		/* low bit is used to show modification */
87 #define PUBLIC	1		/* public access rights */
88 #define PRIVATE	03		/* private to definer */
89 #define ROOT	05		/* root defined */
90 
91 #define	TRUE	1
92 #define FALSE	0
93 
94 #define ENVIRON	020		/* initialize out of the environment */
95 #define IREMOTE	040		/* initialize out of remote structure */
96 #define INIT	0100		/* static data space used for initialization */
97 #define TMASK	017
98 
99 /*
100  * Definition of ACU line description
101  */
102 typedef
103 	struct {
104 		char	*acu_name;
105 		int	(*acu_dialer)();
106 		int	(*acu_disconnect)();
107 		int	(*acu_abort)();
108 	}
109 	acu_t;
110 
111 #define	equal(a, b)	(strcmp(a,b)==0)/* A nice function to string compare */
112 
113 /*
114  * variable manipulation stuff --
115  *   if we defined the value entry in value_t, then we couldn't
116  *   initialize it in vars.c, so we cast it as needed to keep lint
117  *   happy.
118  */
119 typedef
120 	union {
121 		int	zz_number;
122 		short	zz_boolean[2];
123 		char	zz_character[4];
124 		int	*zz_address;
125 	}
126 	zzhack;
127 
128 #define value(v)	vtable[v].v_value
129 
130 #define number(v)	((((zzhack *)(&(v))))->zz_number)
131 
132 #if BYTE_ORDER == LITTLE_ENDIAN
133 #define boolean(v)	((((zzhack *)(&(v))))->zz_boolean[0])
134 #define character(v)	((((zzhack *)(&(v))))->zz_character[0])
135 #endif
136 
137 #if BYTE_ORDER == BIG_ENDIAN
138 #define boolean(v)	((((zzhack *)(&(v))))->zz_boolean[1])
139 #define character(v)	((((zzhack *)(&(v))))->zz_character[3])
140 #endif
141 
142 #define address(v)	((((zzhack *)(&(v))))->zz_address)
143 
144 /*
145  * Escape command table definitions --
146  *   lookup in this table is performed when ``escapec'' is recognized
147  *   at the begining of a line (as defined by the eolmarks variable).
148 */
149 
150 typedef
151 	struct {
152 		char	e_char;		/* char to match on */
153 		char	e_flags;	/* experimental, priviledged */
154 		char	*e_help;	/* help string */
155 		int 	(*e_func)();	/* command */
156 	}
157 	esctable_t;
158 
159 #define NORM	00		/* normal protection, execute anyone */
160 #define EXP	01		/* experimental, mark it with a `*' on help */
161 #define PRIV	02		/* priviledged, root execute only */
162 
163 extern int	vflag;		/* verbose during reading of .tiprc file */
164 extern value_t	vtable[];	/* variable table */
165 
166 #ifndef ACULOG
167 #define logent(a, b, c, d)
168 #define loginit()
169 #endif
170 
171 /*
172  * Definition of indices into variable table so
173  *  value(DEFINE) turns into a static address.
174  */
175 
176 #define BEAUTIFY	0
177 #define BAUDRATE	1
178 #define DIALTIMEOUT	2
179 #define EOFREAD		3
180 #define EOFWRITE	4
181 #define EOL		5
182 #define ESCAPE		6
183 #define EXCEPTIONS	7
184 #define FORCE		8
185 #define FRAMESIZE	9
186 #define HOST		10
187 #define LOG		11
188 #define PHONES		12
189 #define PROMPT		13
190 #define RAISE		14
191 #define RAISECHAR	15
192 #define RECORD		16
193 #define REMOTE		17
194 #define SCRIPT		18
195 #define TABEXPAND	19
196 #define VERBOSE		20
197 #define SHELL		21
198 #define HOME		22
199 #define ECHOCHECK	23
200 #define DISCONNECT	24
201 #define TAND		25
202 #define LDELAY		26
203 #define CDELAY		27
204 #define ETIMEOUT	28
205 #define RAWFTP		29
206 #define HALFDUPLEX	30
207 #define	LECHO		31
208 #define	PARITY		32
209 
210 #define NOVAL	((value_t *)NULL)
211 #define NOACU	((acu_t *)NULL)
212 #define NOSTR	((char *)NULL)
213 #define NOFILE	((FILE *)NULL)
214 #define NOPWD	((struct passwd *)0)
215 
216 struct sgttyb	arg;		/* current mode of local terminal */
217 struct sgttyb	defarg;		/* initial mode of local terminal */
218 struct tchars	tchars;		/* current state of terminal */
219 struct tchars	defchars;	/* initial state of terminal */
220 struct ltchars	ltchars;	/* current local characters of terminal */
221 struct ltchars	deflchars;	/* initial local characters of terminal */
222 
223 FILE	*fscript;		/* FILE for scripting */
224 
225 int	fildes[2];		/* file transfer synchronization channel */
226 int	repdes[2];		/* read process sychronization channel */
227 int	FD;			/* open file descriptor to remote host */
228 int	AC;			/* open file descriptor to dialer (v831 only) */
229 int	vflag;			/* print .tiprc initialization sequence */
230 int	sfd;			/* for ~< operation */
231 int	pid;			/* pid of tipout */
232 uid_t	uid, euid;		/* real and effective user id's */
233 gid_t	gid, egid;		/* real and effective group id's */
234 int	stop;			/* stop transfer session flag */
235 int	quit;			/* same; but on other end */
236 int	intflag;		/* recognized interrupt */
237 int	stoprompt;		/* for interrupting a prompt session */
238 int	timedout;		/* ~> transfer timedout */
239 int	cumode;			/* simulating the "cu" program */
240 
241 char	fname[80];		/* file name buffer for ~< */
242 char	copyname[80];		/* file name buffer for ~> */
243 char	ccc;			/* synchronization character */
244 char	ch;			/* for tipout */
245 char	*uucplock;		/* name of lock file for uucp's */
246 
247 int	odisc;				/* initial tty line discipline */
248 extern	int disc;			/* current tty discpline */
249 
250 extern	char *ctrl();
251 extern	char *vinterp();
252 extern	char *connect();
253