xref: /titanic_51/usr/src/cmd/sh/defs.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 
32 #ifndef	_DEFS_H
33 #define	_DEFS_H
34 
35 #pragma ident	"%Z%%M%	%I%	%E% SMI"
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  *	UNIX shell
43  */
44 
45 /* execute flags */
46 #define		XEC_EXECED	01
47 #define			XEC_LINKED	02
48 #define		XEC_NOSTOP	04
49 
50 /* endjobs flags */
51 #define			JOB_STOPPED	01
52 #define			JOB_RUNNING	02
53 
54 /* error exits from various parts of shell */
55 #define		ERROR		1
56 #define		SYNBAD		2
57 #define		SIGFAIL 	2000
58 #define		SIGFLG		0200
59 
60 /* command tree */
61 #define		FPIN		0x0100
62 #define		FPOU		0x0200
63 #define		FAMP		0x0400
64 #define		COMMSK		0x00F0
65 #define			CNTMSK		0x000F
66 
67 #define		TCOM		0x0000
68 #define		TPAR		0x0010
69 #define		TFIL		0x0020
70 #define		TLST		0x0030
71 #define		TIF			0x0040
72 #define		TWH			0x0050
73 #define		TUN			0x0060
74 #define		TSW			0x0070
75 #define		TAND		0x0080
76 #define		TORF		0x0090
77 #define		TFORK		0x00A0
78 #define		TFOR		0x00B0
79 #define			TFND		0x00C0
80 
81 /* execute table */
82 #define		SYSSET		1
83 #define		SYSCD		2
84 #define		SYSEXEC		3
85 
86 #ifdef RES	/*	include login code	*/
87 #define		SYSLOGIN	4
88 #else
89 #define		SYSNEWGRP 	4
90 #endif
91 
92 #define		SYSTRAP		5
93 #define		SYSEXIT		6
94 #define		SYSSHFT 	7
95 #define		SYSWAIT		8
96 #define		SYSCONT 	9
97 #define		SYSBREAK	10
98 #define		SYSEVAL 	11
99 #define		SYSDOT		12
100 #define		SYSRDONLY 	13
101 #define		SYSTIMES 	14
102 #define		SYSXPORT	15
103 #define		SYSNULL 	16
104 #define		SYSREAD 	17
105 #define			SYSTST		18
106 
107 #ifndef RES	/*	exclude umask code	*/
108 #define		SYSUMASK 	20
109 #define		SYSULIMIT 	21
110 #endif
111 
112 #define		SYSECHO		22
113 #define			SYSHASH		23
114 #define			SYSPWD		24
115 #define		SYSRETURN	25
116 #define			SYSUNS		26
117 #define			SYSMEM		27
118 #define			SYSTYPE  	28
119 #define			SYSGETOPT	29
120 #define		SYSJOBS		30
121 #define		SYSFGBG		31
122 #define		SYSKILL		32
123 #define		SYSSUSP		33
124 #define		SYSSTOP		34
125 
126 /* used for input and output of shell */
127 #define		INIO 		19
128 
129 /* io nodes */
130 #define		USERIO		10
131 #define		IOUFD		15
132 #define		IODOC		16
133 #define		IOPUT		32
134 #define		IOAPP		64
135 #define		IOMOV		128
136 #define		IORDW		256
137 #define			IOSTRIP		512
138 #define		INPIPE		0
139 #define		OTPIPE		1
140 
141 /* arg list terminator */
142 #define		ENDARGS		0
143 
144 #include	<unistd.h>
145 #include	"mac.h"
146 #include	"mode.h"
147 #include	"name.h"
148 #include	<signal.h>
149 #include	<sys/types.h>
150 
151 /* id's */
152 extern pid_t	mypid;
153 extern pid_t	mypgid;
154 extern pid_t	mysid;
155 
156 /* getopt */
157 
158 extern int		optind;
159 extern int		opterr;
160 extern int 		_sp;
161 extern char 		*optarg;
162 
163 
164 /* use sh-private versions of memory allocation routines */
165 
166 #define		alloc 		malloc
167 
168 /* result type declarations */
169 
170 extern int handle();
171 extern void chktrap();
172 extern void done();
173 extern void sh_free();
174 extern unsigned char *make();
175 extern unsigned char *movstr();
176 extern unsigned char *movstrn();
177 extern unsigned char *cwdget();
178 extern struct trenod *cmd();
179 extern struct trenod *makefork();
180 extern struct namnod *lookup();
181 extern struct namnod *findnam();
182 extern struct dolnod *useargs();
183 extern float expr();
184 extern unsigned char *catpath();
185 extern unsigned char *getpath();
186 extern unsigned char *nextpath();
187 extern unsigned char **scan();
188 extern unsigned char *mactrim();
189 extern unsigned char *macro();
190 extern int exname();
191 extern int printnam();
192 extern int printro();
193 extern int printexp();
194 extern unsigned int readwc();
195 extern unsigned int nextwc();
196 extern unsigned char skipc();
197 extern unsigned char **local_setenv();
198 extern time_t time();
199 
200 #define		attrib(n, f)		(n->namflg |= f)
201 #define		round(a, b)		(((int)(((char *)(a)+b)-1))&~((b)-1))
202 #define		closepipe(x)	(close(x[INPIPE]), close(x[OTPIPE]))
203 #define		eq(a, b)		(cf(a, b) == 0)
204 #define		max(a, b)		((a) > (b)?(a):(b))
205 #define		assert(x)
206 
207 /* temp files and io */
208 extern int				output;
209 extern int				ioset;
210 extern struct ionod	*iotemp; /* files to be deleted sometime */
211 extern struct ionod	*fiotemp; /* function files to be deleted sometime */
212 extern struct ionod	*iopend; /* documents waiting to be read at NL */
213 extern struct fdsave	fdmap[];
214 extern int savpipe;
215 
216 /* substitution */
217 extern int				dolc;
218 extern unsigned char				**dolv;
219 extern struct dolnod	*argfor;
220 extern struct argnod	*gchain;
221 
222 /* stak stuff */
223 #include		"stak.h"
224 
225 /*
226  * If non-ANSI C, make const go away.  We bring it back
227  * at the end of the file to avoid side-effects.
228  */
229 #ifndef __STDC__
230 #define	const
231 #endif
232 
233 /* string constants */
234 extern const char				atline[];
235 extern const char				readmsg[];
236 extern const char				colon[];
237 extern const char				minus[];
238 extern const char				nullstr[];
239 extern const char				sptbnl[];
240 extern const char				unexpected[];
241 extern const char				endoffile[];
242 extern const char				synmsg[];
243 
244 /* name tree and words */
245 extern const struct sysnod	reserved[];
246 extern const int				no_reserved;
247 extern const struct sysnod	commands[];
248 extern const int				no_commands;
249 
250 extern int				wdval;
251 extern int				wdnum;
252 extern int				fndef;
253 extern int				nohash;
254 extern struct argnod	*wdarg;
255 extern int				wdset;
256 extern BOOL				reserv;
257 
258 /* prompting */
259 extern const char				stdprompt[];
260 extern const char				supprompt[];
261 extern const char				profile[];
262 extern const char				sysprofile[];
263 
264 /* locale testing */
265 extern const char			localedir[];
266 extern int				localedir_exists;
267 
268 /* built in names */
269 extern struct namnod	fngnod;
270 extern struct namnod	cdpnod;
271 extern struct namnod	ifsnod;
272 extern struct namnod	homenod;
273 extern struct namnod	mailnod;
274 extern struct namnod	pathnod;
275 extern struct namnod	ps1nod;
276 extern struct namnod	ps2nod;
277 extern struct namnod	mchknod;
278 extern struct namnod	acctnod;
279 extern struct namnod	mailpnod;
280 
281 /* special names */
282 extern unsigned char				flagadr[];
283 extern unsigned char				*pcsadr;
284 extern unsigned char				*pidadr;
285 extern unsigned char				*cmdadr;
286 
287 /* names always present */
288 extern const char				defpath[];
289 extern const char				mailname[];
290 extern const char				homename[];
291 extern const char				pathname[];
292 extern const char				cdpname[];
293 extern const char				ifsname[];
294 extern const char				ps1name[];
295 extern const char				ps2name[];
296 extern const char				mchkname[];
297 extern const char				acctname[];
298 extern const char				mailpname[];
299 
300 /* transput */
301 extern unsigned char				tmpout[];
302 extern unsigned char				*tmpname;
303 extern int				serial;
304 
305 #define			TMPNAM 		7
306 
307 extern struct fileblk	*standin;
308 
309 #define		input		(standin->fdes)
310 #define		eof			(standin->feof)
311 
312 extern int				peekc;
313 extern int				peekn;
314 extern unsigned char				*comdiv;
315 extern
316 #ifdef __STDC__
317 const
318 #endif
319 char				devnull[];
320 
321 /* flags */
322 #define			noexec		01
323 #define			sysflg		01
324 #define			intflg		02
325 #define			prompt		04
326 #define			setflg		010
327 #define			errflg		020
328 #define			ttyflg		040
329 #define			forked		0100
330 #define			oneflg		0200
331 #define			rshflg		0400
332 #define			subsh		01000
333 #define			stdflg		02000
334 #define			STDFLG		's'
335 #define			execpr		04000
336 #define			readpr		010000
337 #define			keyflg		020000
338 #define			hashflg		040000
339 #define			nofngflg	0200000
340 #define			exportflg	0400000
341 #define			monitorflg	01000000
342 #define			jcflg		02000000
343 #define			privflg		04000000
344 #define			forcexit	010000000
345 #define			jcoff		020000000
346 #define			pfshflg		040000000
347 
348 extern long				flags;
349 extern int				rwait;	/* flags read waiting */
350 
351 /* error exits from various parts of shell */
352 #include	<setjmp.h>
353 extern jmp_buf			subshell;
354 extern jmp_buf			errshell;
355 
356 /* fault handling */
357 #include	"brkincr.h"
358 
359 extern unsigned			brkincr;
360 #define		MINTRAP		0
361 #define		MAXTRAP		NSIG
362 
363 #define		TRAPSET		2
364 #define		SIGSET		4
365 #define			SIGMOD		8
366 #define			SIGIGN		16
367 
368 extern BOOL				trapnote;
369 
370 /* name tree and words */
371 extern unsigned char				**environ;
372 extern unsigned char				numbuf[];
373 extern const char				export[];
374 extern const char				duperr[];
375 extern const char				readonly[];
376 
377 /* execflgs */
378 extern int				exitval;
379 extern int				retval;
380 extern BOOL				execbrk;
381 extern int				loopcnt;
382 extern int				breakcnt;
383 extern int				funcnt;
384 extern int				tried_to_exit;
385 
386 /* messages */
387 extern const char				mailmsg[];
388 extern const char				coredump[];
389 extern const char				badopt[];
390 extern const char				badparam[];
391 extern const char				unset[];
392 extern const char				badsub[];
393 extern const char				nospace[];
394 extern const char				nostack[];
395 extern const char				notfound[];
396 extern const char				badtrap[];
397 extern const char				baddir[];
398 extern const char				badshift[];
399 extern const char				restricted[];
400 extern const char				execpmsg[];
401 extern const char				notid[];
402 extern const char 				badulimit[];
403 extern const char 				badresource[];
404 extern const char 				badscale[];
405 extern const char 				ulimit[];
406 extern const char				wtfailed[];
407 extern const char				badcreate[];
408 extern const char				nofork[];
409 extern const char				noswap[];
410 extern const char				piperr[];
411 extern const char				badopen[];
412 extern const char				badnum[];
413 extern const char				badsig[];
414 extern const char				badid[];
415 extern const char				arglist[];
416 extern const char				txtbsy[];
417 extern const char				toobig[];
418 extern const char				badexec[];
419 extern const char				badfile[];
420 extern const char				badreturn[];
421 extern const char				badexport[];
422 extern const char				badunset[];
423 extern const char				nohome[];
424 extern const char				badperm[];
425 extern const char				mssgargn[];
426 extern const char				libacc[];
427 extern const char				libbad[];
428 extern const char				libscn[];
429 extern const char				libmax[];
430 extern const char				emultihop[];
431 extern const char				nulldir[];
432 extern const char				enotdir[];
433 extern const char				enoent[];
434 extern const char				eacces[];
435 extern const char				enolink[];
436 extern const char				exited[];
437 extern const char				running[];
438 extern const char				ambiguous[];
439 extern const char				nosuchjob[];
440 extern const char				nosuchpid[];
441 extern const char				nosuchpgid[];
442 extern const char				usage[];
443 extern const char				nojc[];
444 extern const char				killuse[];
445 extern const char				jobsuse[];
446 extern const char				stopuse[];
447 extern const char				ulimuse[];
448 extern const char				nocurjob[];
449 extern const char				loginsh[];
450 extern const char				jobsstopped[];
451 extern const char				jobsrunning[];
452 
453 /*	'builtin' error messages	*/
454 
455 extern const char				btest[];
456 extern const char				badop[];
457 
458 #ifndef __STDC__
459 #undef const 					/* bring back const */
460 #endif
461 
462 /*	fork constant	*/
463 
464 #define		FORKLIM 	32
465 
466 extern address			end[];
467 
468 #include	"ctype.h"
469 #include	<ctype.h>
470 #include	<locale.h>
471 
472 extern int				eflag;
473 extern int				ucb_builtins;
474 
475 /*
476  * Find out if it is time to go away.
477  * `trapnote' is set to SIGSET when fault is seen and
478  * no trap has been set.
479  */
480 
481 #define		sigchk()	if (trapnote & SIGSET)	\
482 					exitsh(exitval ? exitval : SIGFAIL)
483 
484 #define		exitset()	retval = exitval
485 
486 /* Multibyte characters */
487 void setwidth();
488 unsigned char *readw();
489 #include <stdlib.h>
490 #include <limits.h>
491 #define	MULTI_BYTE_MAX MB_LEN_MAX
492 
493 
494 #ifdef	__cplusplus
495 }
496 #endif
497 
498 #endif	/* _DEFS_H */
499