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