xref: /illumos-gate/usr/src/cmd/sh/defs.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2001 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate /*
32*7c478bd9Sstevel@tonic-gate  *	UNIX shell
33*7c478bd9Sstevel@tonic-gate  */
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #include 		<setjmp.h>
36*7c478bd9Sstevel@tonic-gate #include		"mode.h"
37*7c478bd9Sstevel@tonic-gate #include		"name.h"
38*7c478bd9Sstevel@tonic-gate #include		<sys/param.h>
39*7c478bd9Sstevel@tonic-gate #ifndef NOFILE
40*7c478bd9Sstevel@tonic-gate #define	NOFILE 20
41*7c478bd9Sstevel@tonic-gate #endif
42*7c478bd9Sstevel@tonic-gate /* temp files and io */
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate int				output = 2;
45*7c478bd9Sstevel@tonic-gate int				ioset;
46*7c478bd9Sstevel@tonic-gate struct ionod	*iotemp;	/* files to be deleted sometime */
47*7c478bd9Sstevel@tonic-gate struct ionod	*fiotemp;	/* function files to be deleted sometime */
48*7c478bd9Sstevel@tonic-gate struct ionod	*iopend;	/* documents waiting to be read at NL */
49*7c478bd9Sstevel@tonic-gate struct fdsave	fdmap[NOFILE];
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate /* substitution */
52*7c478bd9Sstevel@tonic-gate int				dolc;
53*7c478bd9Sstevel@tonic-gate unsigned char			**dolv;
54*7c478bd9Sstevel@tonic-gate struct dolnod	*argfor;
55*7c478bd9Sstevel@tonic-gate struct argnod	*gchain;
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate /* name tree and words */
59*7c478bd9Sstevel@tonic-gate int				wdval;
60*7c478bd9Sstevel@tonic-gate int				wdnum;
61*7c478bd9Sstevel@tonic-gate int				fndef;
62*7c478bd9Sstevel@tonic-gate int				nohash;
63*7c478bd9Sstevel@tonic-gate struct argnod	*wdarg;
64*7c478bd9Sstevel@tonic-gate int				wdset;
65*7c478bd9Sstevel@tonic-gate BOOL			reserv;
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate /* special names */
68*7c478bd9Sstevel@tonic-gate unsigned char			*pcsadr;
69*7c478bd9Sstevel@tonic-gate unsigned char			*pidadr;
70*7c478bd9Sstevel@tonic-gate unsigned char			*cmdadr;
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate /* transput */
73*7c478bd9Sstevel@tonic-gate unsigned char 			*tmpname;
74*7c478bd9Sstevel@tonic-gate int 			serial;
75*7c478bd9Sstevel@tonic-gate unsigned 		peekc;
76*7c478bd9Sstevel@tonic-gate unsigned		peekn;
77*7c478bd9Sstevel@tonic-gate unsigned char 			*comdiv;
78*7c478bd9Sstevel@tonic-gate long			flags;
79*7c478bd9Sstevel@tonic-gate int				rwait;	/* flags read waiting */
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate /* error exits from various parts of shell */
82*7c478bd9Sstevel@tonic-gate jmp_buf			subshell;
83*7c478bd9Sstevel@tonic-gate jmp_buf			errshell;
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate /* fault handling */
86*7c478bd9Sstevel@tonic-gate BOOL			trapnote;
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate /* execflgs */
89*7c478bd9Sstevel@tonic-gate int				exitval;
90*7c478bd9Sstevel@tonic-gate int				retval;
91*7c478bd9Sstevel@tonic-gate BOOL			execbrk;
92*7c478bd9Sstevel@tonic-gate int				loopcnt;
93*7c478bd9Sstevel@tonic-gate int				breakcnt;
94*7c478bd9Sstevel@tonic-gate int 			funcnt;
95*7c478bd9Sstevel@tonic-gate int				eflag;
96*7c478bd9Sstevel@tonic-gate /*
97*7c478bd9Sstevel@tonic-gate  * The following flag is set if you try to exit with stopped jobs.
98*7c478bd9Sstevel@tonic-gate  * On the second try the exit will succeed.
99*7c478bd9Sstevel@tonic-gate  */
100*7c478bd9Sstevel@tonic-gate int			tried_to_exit;
101*7c478bd9Sstevel@tonic-gate /*
102*7c478bd9Sstevel@tonic-gate  * The following flag is set to true if /usr/ucb is found in the path
103*7c478bd9Sstevel@tonic-gate  * before /usr/bin. This value is checked when executing the echo and test
104*7c478bd9Sstevel@tonic-gate  * built-in commands. If true, the command behaves as in BSD systems.
105*7c478bd9Sstevel@tonic-gate  */
106*7c478bd9Sstevel@tonic-gate int				ucb_builtins;
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate /* The following stuff is from stak.h	*/
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate unsigned char 			*stakbas;
111*7c478bd9Sstevel@tonic-gate unsigned char			*staktop;
112*7c478bd9Sstevel@tonic-gate unsigned char			*stakbot = 0;
113*7c478bd9Sstevel@tonic-gate struct blk			*stakbsy;
114*7c478bd9Sstevel@tonic-gate unsigned char 			*brkend;
115