xref: /titanic_50/usr/src/cmd/sh/defs.h (revision c77a61a72b5ecdc507d6cf104142edd371a16c84)
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 2006 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		16
131 #define		IOPUT		32
132 #define		IOAPP		64
133 #define		IOMOV		128
134 #define		IORDW		256
135 #define			IOSTRIP		512
136 #define		INPIPE		0
137 #define		OTPIPE		1
138 
139 /* arg list terminator */
140 #define		ENDARGS		0
141 
142 #include	<unistd.h>
143 #include 	"mac.h"
144 #include	"mode.h"
145 #include	"name.h"
146 #include	<signal.h>
147 #include	<sys/types.h>
148 
149 /* id's */
150 extern pid_t	mypid;
151 extern pid_t	mypgid;
152 extern pid_t	mysid;
153 
154 /* getopt */
155 
156 extern int		optind;
157 extern int		opterr;
158 extern int 		_sp;
159 extern char 		*optarg;
160 
161 
162 /* use sh-private versions of memory allocation routines */
163 
164 #define		alloc 		malloc
165 
166 /* result type declarations */
167 
168 extern int handle();
169 extern void chktrap();
170 extern void done(int)
171 	__NORETURN;
172 extern void sh_free();
173 extern unsigned char *make();
174 extern unsigned char *movstr();
175 extern unsigned char *movstrn();
176 extern unsigned char *cwdget();
177 extern struct trenod *cmd();
178 extern struct trenod *makefork();
179 extern struct namnod *lookup();
180 extern struct namnod *findnam();
181 extern struct dolnod *useargs();
182 extern float expr();
183 extern unsigned char *catpath();
184 extern unsigned char *getpath();
185 extern unsigned char *nextpath();
186 extern unsigned char **scan();
187 extern unsigned char *mactrim();
188 extern unsigned char *macro();
189 extern void exname(struct namnod *);
190 extern void printnam(struct namnod *);
191 extern void printro(struct namnod *);
192 extern void printexp(struct namnod *);
193 extern unsigned int readwc();
194 extern unsigned int nextwc();
195 extern unsigned char skipc();
196 extern unsigned char **local_setenv();
197 extern time_t time();
198 extern void exitsh(int)
199 	__NORETURN;
200 extern void failed_real(unsigned char *, const char *, unsigned char *)
201     __NORETURN;
202 extern void error(const char *) __NORETURN;
203 extern void prf();
204 extern void assign(struct namnod *, unsigned char *);
205 extern void setmode(int);
206 extern void trim(unsigned char *);
207 extern void preacct(unsigned char *);
208 
209 
210 
211 #define		attrib(n, f)		(n->namflg |= f)
212 #define		round(a, b)		(((int)(((char *)(a)+b)-1))&~((b)-1))
213 #define		closepipe(x)		(close(x[INPIPE]), close(x[OTPIPE]))
214 #define		eq(a, b)		(cf(a, b) == 0)
215 #define		max(a, b)		((a) > (b)?(a):(b))
216 #define		assert(x)
217 #define		_gettext(s)		(unsigned char *)gettext(s)
218 
219 /*
220  * macros using failed_real(). Only s2 is gettext'd with both functions.
221  */
222 #define		failed(s1, s2)		failed_real(s1, s2, NULL)
223 #define		bfailed(s1, s2, s3)	failed_real(s1, s2, s3)
224 
225 /*
226  * macros using failure_real(). s1 and s2 is gettext'd with gfailure(), but
227  * only s2 is gettext'd with failure().
228  */
229 #define		failure(s1, s2)		failure_real(s1, s2, 0)
230 #define		gfailure(s1, s2)	failure_real(s1, s2, 1)
231 
232 /* temp files and io */
233 extern int				output;
234 extern int				ioset;
235 extern struct ionod	*iotemp; /* files to be deleted sometime */
236 extern struct ionod	*fiotemp; /* function files to be deleted sometime */
237 extern struct ionod	*iopend; /* documents waiting to be read at NL */
238 extern struct fdsave	fdmap[];
239 extern int savpipe;
240 
241 /* substitution */
242 extern int				dolc;
243 extern unsigned char				**dolv;
244 extern struct dolnod	*argfor;
245 extern struct argnod	*gchain;
246 
247 /* stak stuff */
248 #include		"stak.h"
249 
250 /*
251  * If non-ANSI C, make const go away.  We bring it back
252  * at the end of the file to avoid side-effects.
253  */
254 #ifndef __STDC__
255 #define	const
256 #endif
257 
258 /* string constants */
259 extern const char				atline[];
260 extern const char				readmsg[];
261 extern const char				colon[];
262 extern const char				minus[];
263 extern const char				nullstr[];
264 extern const char				sptbnl[];
265 extern const char				unexpected[];
266 extern const char				endoffile[];
267 extern const char				synmsg[];
268 
269 /* name tree and words */
270 extern const struct sysnod	reserved[];
271 extern const int				no_reserved;
272 extern const struct sysnod	commands[];
273 extern const int				no_commands;
274 
275 extern int				wdval;
276 extern int				wdnum;
277 extern int				fndef;
278 extern int				nohash;
279 extern struct argnod	*wdarg;
280 extern int				wdset;
281 extern BOOL				reserv;
282 
283 /* prompting */
284 extern const char				stdprompt[];
285 extern const char				supprompt[];
286 extern const char				profile[];
287 extern const char				sysprofile[];
288 
289 /* locale testing */
290 extern const char			localedir[];
291 extern int				localedir_exists;
292 
293 /* built in names */
294 extern struct namnod	fngnod;
295 extern struct namnod	cdpnod;
296 extern struct namnod	ifsnod;
297 extern struct namnod	homenod;
298 extern struct namnod	mailnod;
299 extern struct namnod	pathnod;
300 extern struct namnod	ps1nod;
301 extern struct namnod	ps2nod;
302 extern struct namnod	mchknod;
303 extern struct namnod	acctnod;
304 extern struct namnod	mailpnod;
305 
306 /* special names */
307 extern unsigned char				flagadr[];
308 extern unsigned char				*pcsadr;
309 extern unsigned char				*pidadr;
310 extern unsigned char				*cmdadr;
311 
312 /* names always present */
313 extern const char				defpath[];
314 extern const char				mailname[];
315 extern const char				homename[];
316 extern const char				pathname[];
317 extern const char				cdpname[];
318 extern const char				ifsname[];
319 extern const char				ps1name[];
320 extern const char				ps2name[];
321 extern const char				mchkname[];
322 extern const char				acctname[];
323 extern const char				mailpname[];
324 
325 /* transput */
326 extern unsigned char				tmpout[];
327 extern int 					tmpout_offset;
328 extern unsigned int				serial;
329 
330 /*
331  * allow plenty of room for size for temp file name:
332  * "/tmp/sh"(7) + <pid> (<=6) + <unsigned int #> (<=10) + \0 (1)
333  */
334 #define			TMPOUTSZ 		32
335 
336 extern struct fileblk	*standin;
337 
338 #define		input		(standin->fdes)
339 #define		eof			(standin->feof)
340 
341 extern int				peekc;
342 extern int				peekn;
343 extern unsigned char				*comdiv;
344 extern
345 #ifdef __STDC__
346 const
347 #endif
348 char				devnull[];
349 
350 /* flags */
351 #define			noexec		01
352 #define			sysflg		01
353 #define			intflg		02
354 #define			prompt		04
355 #define			setflg		010
356 #define			errflg		020
357 #define			ttyflg		040
358 #define			forked		0100
359 #define			oneflg		0200
360 #define			rshflg		0400
361 #define			subsh		01000
362 #define			stdflg		02000
363 #define			STDFLG		's'
364 #define			execpr		04000
365 #define			readpr		010000
366 #define			keyflg		020000
367 #define			hashflg		040000
368 #define			nofngflg	0200000
369 #define			exportflg	0400000
370 #define			monitorflg	01000000
371 #define			jcflg		02000000
372 #define			privflg		04000000
373 #define			forcexit	010000000
374 #define			jcoff		020000000
375 #define			pfshflg		040000000
376 
377 extern long				flags;
378 extern int				rwait;	/* flags read waiting */
379 
380 /* error exits from various parts of shell */
381 #include	<setjmp.h>
382 extern jmp_buf			subshell;
383 extern jmp_buf			errshell;
384 
385 /* fault handling */
386 #include	"brkincr.h"
387 
388 extern unsigned			brkincr;
389 #define		MINTRAP		0
390 #define		MAXTRAP		NSIG
391 
392 #define		TRAPSET		2
393 #define		SIGSET		4
394 #define			SIGMOD		8
395 #define			SIGIGN		16
396 
397 extern BOOL				trapnote;
398 
399 /* name tree and words */
400 extern unsigned char				**environ;
401 extern unsigned char				numbuf[];
402 extern const char				export[];
403 extern const char				duperr[];
404 extern const char				readonly[];
405 
406 /* execflgs */
407 extern int				exitval;
408 extern int				retval;
409 extern BOOL				execbrk;
410 extern int				loopcnt;
411 extern int				breakcnt;
412 extern int				funcnt;
413 extern int				tried_to_exit;
414 
415 /* messages */
416 extern const char				mailmsg[];
417 extern const char				coredump[];
418 extern const char				badopt[];
419 extern const char				badparam[];
420 extern const char				unset[];
421 extern const char				badsub[];
422 extern const char				nospace[];
423 extern const char				nostack[];
424 extern const char				notfound[];
425 extern const char				badtrap[];
426 extern const char				baddir[];
427 extern const char				badshift[];
428 extern const char				restricted[];
429 extern const char				execpmsg[];
430 extern const char				notid[];
431 extern const char 				badulimit[];
432 extern const char 				ulimit[];
433 extern const char				wtfailed[];
434 extern const char				badcreate[];
435 extern const char				nofork[];
436 extern const char				noswap[];
437 extern const char				piperr[];
438 extern const char				badopen[];
439 extern const char				badnum[];
440 extern const char				badsig[];
441 extern const char				badid[];
442 extern const char				arglist[];
443 extern const char				txtbsy[];
444 extern const char				toobig[];
445 extern const char				badexec[];
446 extern const char				badfile[];
447 extern const char				badreturn[];
448 extern const char				badexport[];
449 extern const char				badunset[];
450 extern const char				nohome[];
451 extern const char				badperm[];
452 extern const char				mssgargn[];
453 extern const char				libacc[];
454 extern const char				libbad[];
455 extern const char				libscn[];
456 extern const char				libmax[];
457 extern const char				emultihop[];
458 extern const char				nulldir[];
459 extern const char				enotdir[];
460 extern const char				enoent[];
461 extern const char				eacces[];
462 extern const char				enolink[];
463 extern const char				exited[];
464 extern const char				running[];
465 extern const char				ambiguous[];
466 extern const char				nosuchjob[];
467 extern const char				nosuchpid[];
468 extern const char				nosuchpgid[];
469 extern const char				usage[];
470 extern const char				nojc[];
471 extern const char				killuse[];
472 extern const char				jobsuse[];
473 extern const char				stopuse[];
474 extern const char				ulimuse[];
475 extern const char				nocurjob[];
476 extern const char				loginsh[];
477 extern const char				jobsstopped[];
478 extern const char				jobsrunning[];
479 extern const char				nlorsemi[];
480 extern const char				signalnum[];
481 extern const char				badpwd[];
482 extern const char				badlocale[];
483 extern const char				nobracket[];
484 extern const char				noparen[];
485 extern const char				noarg[];
486 
487 /*	'builtin' error messages	*/
488 
489 extern const char				btest[];
490 extern const char				badop[];
491 
492 #ifndef __STDC__
493 #undef const 					/* bring back const */
494 #endif
495 
496 /*	fork constant	*/
497 
498 #define		FORKLIM 	32
499 
500 extern address			end[];
501 
502 #include	"ctype.h"
503 #include	<ctype.h>
504 #include	<locale.h>
505 
506 extern int				eflag;
507 extern int				ucb_builtins;
508 
509 /*
510  * Find out if it is time to go away.
511  * `trapnote' is set to SIGSET when fault is seen and
512  * no trap has been set.
513  */
514 
515 #define		sigchk()	if (trapnote & SIGSET)	\
516 					exitsh(exitval ? exitval : SIGFAIL)
517 
518 #define		exitset()	retval = exitval
519 
520 /* Multibyte characters */
521 unsigned char *readw();
522 #include <stdlib.h>
523 #include <limits.h>
524 #define	MULTI_BYTE_MAX MB_LEN_MAX
525 
526 
527 #ifdef	__cplusplus
528 }
529 #endif
530 
531 #endif	/* _DEFS_H */
532