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