xref: /original-bsd/local/toolchest/ksh/sh/defs.h (revision f30a25d9)
1 /*
2 
3  *      Copyright (c) 1984, 1985, 1986 AT&T
4  *      All Rights Reserved
5 
6  *      THIS IS UNPUBLISHED PROPRIETARY SOURCE
7  *      CODE OF AT&T.
8  *      The copyright notice above does not
9  *      evidence any actual or intended
10  *      publication of such source code.
11 
12  */
13 /* @(#)defs.h	1.1 */
14 
15 /*
16  *	UNIX shell
17  *	S. R. Bourne
18  *	Rewritten by David Korn
19  *
20  */
21 
22 #include	<stdio.h>
23 #include	<setjmp.h>
24 #include	<signal.h>
25 
26 #define const
27 
28 /* error exits from various parts of shell */
29 #define ERROR	1
30 #define SYNBAD	2
31 
32 #define BYTESPERWORD	(sizeof(char *))
33 #define ENDARGS	0	/* arg list terminator */
34 #define	NIL	((char*)0)
35 #ifndef NULL
36 #define NULL 0
37 #endif
38 
39 
40 /* typedefs used in the shell */
41 typedef char	BOOL;
42 typedef char	*ADDRESS;
43 typedef char	MSG[];
44 typedef char	*STKPTR;
45 
46 typedef struct stat	STATBUF;	/* defined in /usr/include/sys/stat.h */
47 typedef struct blk	*BLKPTR;
48 typedef struct fileblk	FILEBLK;
49 typedef struct fileblk	*SHFILE;
50 typedef struct trenod	*TREPTR;
51 typedef struct forknod	*FORKPTR;
52 typedef struct comnod	*COMPTR;
53 typedef struct swnod	*SWPTR;
54 typedef struct regnod	*REGPTR;
55 typedef struct parnod	*PARPTR;
56 typedef struct ifnod	*IFPTR;
57 typedef struct whnod	*WHPTR;
58 typedef struct fornod	*FORPTR;
59 typedef struct lstnod	*LSTPTR;
60 typedef struct chnnod	*CHNPTR;
61 typedef struct dolnod	*DOLPTR;
62 typedef struct ionod	*IOPTR;
63 typedef struct Namnod	NAMNOD;
64 typedef struct Namnod	*NAMPTR;
65 typedef struct sysnod	*SYSPTR;
66 typedef struct procnod	*PROCPTR;
67 
68 #define Rcheat(a)	((unsigned)(a))
69 
70 #define blank()		putc(SP,output)
71 #define newline()	putc(NL,output)
72 #define round(a,b)	(((int)((ADR(a)+b)-1))&~((b)-1))
73 #define eq(a,b)		(strcmp(a,b)==0)
74 #define max(a,b)	((a)>(b)?(a):(b))
75 #define assert(x)	;
76 #define exitset()	(savexit=exitval)
77 #define error(s)	failed(s,NIL)
78 #define		BLK(x)	((BLKPTR)(x))
79 #define		BYT(x)	((BYTPTR)(x))
80 #define		STK(x)	((STKPTR)(x))
81 #define		ADR(x)	((char*)(x))
82 #ifdef BSD
83 #define	strchr		index
84 #define	strrchr		rindex
85 #endif	/* BSD */
86 #ifdef  VENIX
87 #define	strchr		index
88 #define	strrchr		rindex
89 #endif	/* VENIX */
90 
91 /* flags */
92 
93 typedef long optflag;
94 #ifdef INT16
95 # ifndef pdp11
96 # define _OPTIM_	1
97 # endif /* pdp11 */
98 #endif /* INT16 */
99 
100 #ifdef _OPTIM_
101 #define _HIGH_	1
102 #define _LOW_	_HIGH_-1
103 #define is_option(flag)		((flag)&0xffffL?\
104 					st.Flags.i[_LOW_]&(unsigned int)(flag):\
105 					st.Flags.i[_HIGH_]&(unsigned int)((flag)>>16))
106 #define on_option(flag)		((flag)&0xffffL?\
107 					(st.Flags.i[_LOW_] |= (unsigned int)(flag)):\
108 					(st.Flags.i[_HIGH_] |= (unsigned int)((flag)>>16)))
109 #define off_option(flag)	((flag)&0xffffL?\
110 					(st.Flags.i[_LOW_] &= ~(unsigned int)(flag)):\
111 					(st.Flags.i[_HIGH_] &= ~(unsigned int)((flag)>>16)))
112 #else
113 #define is_option(flag)		(st.Flags.l & (flag))
114 #define on_option(flag)		(st.Flags.l |= (flag))
115 #define off_option(flag)	(st.Flags.l &= ~(flag))
116 #endif /* _OPTIM_ */
117 
118 #define Fixflg	1
119 #define Errflg	2
120 #define Readpr	3
121 #define Monitor	4
122 #define	Intflg	5
123 #define Rshflg	6
124 #define Execpr	7
125 #define Keyflg	8
126 #define Noset	9
127 #define Noglob	10
128 #define Allexp	11
129 #define Noeof	13
130 #define Nomatch	14
131 #define Markdir	15
132 #define Bgnice	16
133 #define Editvi	17
134 #define Viraw	18
135 #define Oneflg	19
136 #define Hashall	20
137 #define Stdflg	21
138 #define Noexec	22
139 #define Notify	23
140 #define Gmacs	24
141 #define Emacs	25
142 #define	Privmod 26
143 #define	Inproc	27
144 
145 #define FIXFLG	(1<<Fixflg) /* used also as a state */
146 #define	ERRFLG	(1<<Errflg) /* used also as a state */
147 #define	READPR	(1<<Readpr) /* used also as a state */
148 #define MONITOR	(1<<Monitor)/* used also as a state */
149 #define	INTFLG	(1<<Intflg) /* used also as a state */
150 #define	RSHFLG	(1L<<Rshflg)
151 #define	EXECPR	(1L<<Execpr)
152 #define	KEYFLG	(1L<<Keyflg)
153 #define NOSET	(1L<<Noset)
154 #define NOGLOB	(1L<<Noglob)
155 #define ALLEXP	(1L<<Allexp)
156 #define NOEOF	(1L<<Noeof)
157 #define NOMATCH	(1L<<Nomatch)
158 #define EMACS	(1L<<Emacs)
159 #define BGNICE	(1L<<Bgnice)
160 #define EDITVI	(1L<<Editvi)
161 #define VIRAW	(1L<<Viraw)
162 #define	ONEFLG	(1L<<Oneflg)
163 #define HASHALL	(1L<<Hashall)
164 #define	STDFLG	(1L<<Stdflg)
165 #define	NOEXEC	(1L<<Noexec)
166 #define	NOTIFY	(1L<<Notify)
167 #define GMACS	(1L<<Gmacs)
168 #define MARKDIR	(1L<<Markdir)
169 #define PRIVM	(1L<<Privmod)
170 #define INPROC	(1L<<Inproc)
171 #define CFLAG	(1L<<30)
172 
173 
174 /* states */
175 /* low numbered states are same as flags */
176 #define	PROMPT		INTFLG
177 #define	WAITING		0x40
178 #define	FORKED		0x80
179 #define	TTYFLG		0x100
180 #define IS_TMP		0x200	/* set when TMPFD is available */
181 #define	NO_TMP		0x400	/* set when invalid /tmp/filename */
182 #define RM_TMP		0x800	/* temp files to remove on exit */
183 #define FUNCTION 	0x1000	/* set when entering a function */
184 #define RWAIT		0x2000	/* set when waiting for a read */
185 #define BUILTIN		0x4000	/* set when processing built-in command */
186 #define NONSTOP		0x8000	/* set when job cannot be stopped */
187 #define READC		0x10000	/* only for BSD */
188 #define VFORKED		0x20000	/* only used with VFORK mode */
189 
190 
191 
192 /*	fork constant	*/
193 #define FORKLIM 32
194 /*	comment delimiter 	*/
195 
196 #define	COMCHAR	'#'
197 
198 
199 #define NL	'\n'
200 #define LITERAL	'\''
201 #define ENDOF	0
202 #define STRIP	0377
203 #define SP	' '
204 #define NOEXP	1
205 #define HAT	'^'
206 #define ESCAPE	'\\'
207 #define HIGHBIT	0200
208 #define TO_PRINT 0100	/* bit to set for printing control char */
209 
210 extern MSG	argcount;
211 extern MSG	argexp;
212 extern MSG	arglist;
213 extern MSG	atline;
214 extern MSG	baddir;
215 extern MSG	badexec;
216 extern MSG	badnum;
217 extern MSG	badop;
218 extern MSG	badopt;
219 extern MSG	badparam;
220 extern MSG	badsub;
221 extern MSG	badtrap;
222 extern MSG	blet;
223 extern MSG	bltfn;
224 extern MSG	bset;
225 extern MSG	bread;
226 extern MSG	colon;
227 extern MSG	coredump;
228 extern MSG	defedit;
229 extern MSG	defpath;
230 extern MSG	dot;
231 extern MSG	endmatch;
232 extern MSG	fn_hdr;
233 extern MSG	execpmsg;
234 extern MSG	intbase;
235 extern MSG	is_;
236 extern MSG	is_alias;
237 extern MSG	is_builtin;
238 extern MSG	is_function;
239 extern MSG	is_reserved;
240 extern MSG	is_talias;
241 extern MSG	is_xalias;
242 extern MSG	is_xfunction;
243 extern MSG	logout;
244 extern MSG	mailmsg;
245 extern MSG	minus;
246 extern MSG	noalias;
247 extern MSG	nofork;
248 extern MSG	noquery;
249 extern MSG	nosign;
250 extern MSG	nospace;
251 extern MSG	noswap;
252 extern MSG	notfound;
253 extern MSG	nullstr;
254 extern MSG	off_;
255 extern MSG	on_;
256 extern MSG	opt_heading;
257 extern MSG	parexp;
258 extern MSG	pexists;
259 extern MSG	ptrace;
260 extern MSG	recursive;
261 extern MSG	restricted;
262 extern MSG	setpwd;
263 extern MSG	sptbnl;
264 extern MSG	stdprompt;
265 extern MSG	suid_profile;
266 extern MSG	supprompt;
267 extern MSG	t_real;
268 extern MSG	t_sys;
269 extern MSG	t_user;
270 extern MSG	toobig;
271 extern MSG	txtbsy;
272 extern MSG	unlimited;
273 extern MSG	unset;
274 extern MSG	version;
275 extern MSG	pcsadr;
276 extern MSG	pidadr;
277 extern MSG	pwderr;
278 
279 
280 extern struct Amemory	*alias;	/* for alias names */
281 extern struct Namnod	*bltin_nodes;
282 
283 /*
284  * Saves the state of the shell
285  */
286 
287 struct State
288 {
289 	jmp_buf		jmpbuf;
290 	union
291 	{
292 		long	l;
293 #ifdef _OPTIM_
294 		int	i[2];
295 #endif /* _OPTIM_ */
296 	}		Flags;
297 	unsigned	States;
298 	int		Breakcnt;
299 	int		Execbrk;
300 	int		Loopcnt;
301 	int		Fn_depth;
302 	int		Peekc;
303 	int		Peekn;
304 	int		Aliflg;
305 	int		Reserv;
306 	char		*Cmdadr;
307 	int		Cmdline;
308 	int		Firstline;
309 	int		Exec_flag;
310 	int		Dolc;
311 	char		**Dolv;
312 	IOPTR		Iopend;
313 	int		Ioset;
314 	IOPTR		Iotemp;
315 	int		Linked;
316 	SHFILE		Standin;
317 	FILE		*Standout;
318 	FILE		*Cpipe[2];
319 	int		Cpid;
320 	int		Wdset;
321 };
322 
323 extern struct State st;
324 
325 #define flags		st.Flags.l
326 
327 #define states		st.States
328 #define breakcnt	st.Breakcnt
329 #define loopcnt		st.Loopcnt
330 #define execbrk		st.Execbrk
331 #define fn_depth	st.Fn_depth
332 #define peekc		st.Peekc
333 #define peekn		st.Peekn
334 #define aliflg		st.Aliflg
335 #define reserv		st.Reserv
336 #define cmdadr		st.Cmdadr
337 #define cmdline		st.Cmdline
338 #define firstline	st.Firstline
339 #define exec_flag	st.Exec_flag
340 #define dolc		st.Dolc
341 #define dolv		st.Dolv
342 #define linked		st.Linked
343 #define iotemp		st.Iotemp
344 #define ioset		st.Ioset
345 #define iopend		st.Iopend
346 #define	standout	st.Standout
347 #define	standin		st.Standin
348 #define	cpipe		st.Cpipe
349 #define	cpid		st.Cpid
350 #define wdset		st.Wdset
351 
352 extern char	*comdiv;
353 extern int	errno;
354 extern int	exitval;
355 extern char	*lastarg;
356 extern long	mailchk;
357 extern int	oldexit;
358 extern FILE	*output;
359 extern long	ppid;
360 extern struct Amemory *prnames;	/* for function names */
361 extern int	savexit;
362 extern int	topfd;
363 extern char	*trapcom[];
364 extern BOOL	trapnote;
365 extern BOOL	login_sh;
366 extern int 	userid;
367 #ifdef pdp11
368 # ifndef INT16
369 # define INT16
370 # endif /* INT16 */
371 #endif	/* pdp11 */
372 
373 #ifdef INT16
374 /* save space */
375 #undef putc
376 #define putc fputc
377 #endif	/* INT16 */
378