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