xref: /netbsd-src/bin/csh/csh.h (revision b544db168905aa6800a7f40a6c765601b0544ef3)
1*b544db16Snia /* $NetBSD: csh.h,v 1.30 2024/04/24 15:47:11 nia Exp $ */
249f0ad86Scgd 
361f28255Scgd /*-
4cee2bad8Smycroft  * Copyright (c) 1980, 1991, 1993
5cee2bad8Smycroft  *	The Regents of the University of California.  All rights reserved.
661f28255Scgd  *
761f28255Scgd  * Redistribution and use in source and binary forms, with or without
861f28255Scgd  * modification, are permitted provided that the following conditions
961f28255Scgd  * are met:
1061f28255Scgd  * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd  *    notice, this list of conditions and the following disclaimer.
1261f28255Scgd  * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd  *    notice, this list of conditions and the following disclaimer in the
1461f28255Scgd  *    documentation and/or other materials provided with the distribution.
15b5b29542Sagc  * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd  *    may be used to endorse or promote products derived from this software
1761f28255Scgd  *    without specific prior written permission.
1861f28255Scgd  *
1961f28255Scgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd  * SUCH DAMAGE.
3061f28255Scgd  *
3149f0ad86Scgd  *	@(#)csh.h	8.1 (Berkeley) 5/31/93
3261f28255Scgd  */
3361f28255Scgd 
34b771e65bSwiz #ifndef _CSH_H_
35b771e65bSwiz #define _CSH_H_
36b771e65bSwiz 
3761f28255Scgd /*
3861f28255Scgd  * Fundamental definitions which may vary from system to system.
3961f28255Scgd  *
400bf6fd0cSchristos  *	BUFSIZE		The i/o buffering size; also limits word size
4161f28255Scgd  *	MAILINTVL	How often to mailcheck; more often is more expensive
4261f28255Scgd  */
430bf6fd0cSchristos #ifndef BUFSIZE
440bf6fd0cSchristos #define	BUFSIZE	4096		/* default buffer size */
450bf6fd0cSchristos #endif				/* BUFSIZE */
4661f28255Scgd 
4761f28255Scgd #define FORKSLEEP 10		/* delay loop on non-interactive fork failure */
4861f28255Scgd #define	MAILINTVL 600		/* 10 minutes */
4961f28255Scgd 
5061f28255Scgd /*
5161f28255Scgd  * The shell moves std in/out/diag and the old std input away from units
5261f28255Scgd  * 0, 1, and 2 so that it is easy to set up these standards for invoked
5361f28255Scgd  * commands.
5461f28255Scgd  */
5561f28255Scgd #define	FSHTTY 15		/* /dev/tty when manip pgrps */
5661f28255Scgd #define	FSHIN 16		/* Preferred desc for shell input */
5761f28255Scgd #define	FSHOUT 17		/* ... shell output */
58cee2bad8Smycroft #define	FSHERR 18		/* ... shell diagnostics */
5961f28255Scgd #define	FOLDSTD	19		/* ... old std input */
6061f28255Scgd 
6161f28255Scgd #ifdef PROF
6261f28255Scgd #define	xexit(n) done(n)
6361f28255Scgd #endif
6461f28255Scgd 
6561f28255Scgd #ifdef SHORT_STRINGS
6661f28255Scgd typedef short Char;
6761f28255Scgd 
6861f28255Scgd #define SAVE(a) (Strsave(str2short(a)))
6961f28255Scgd #else
7061f28255Scgd typedef char Char;
7161f28255Scgd 
7261f28255Scgd #define SAVE(a) (strsave(a))
7361f28255Scgd #endif
7461f28255Scgd 
75cee2bad8Smycroft /*
76cee2bad8Smycroft  * Make sure a variable is not stored in a register by taking its address
77cee2bad8Smycroft  * This is used where variables might be clobbered by longjmp.
78cee2bad8Smycroft  */
79cee2bad8Smycroft #define UNREGISTER(a)	(void) &a
80cee2bad8Smycroft 
8161f28255Scgd typedef void *ioctl_t;		/* Third arg of ioctl */
8261f28255Scgd 
8361f28255Scgd #include "const.h"
8461f28255Scgd #include "char.h"
858ea378c6Schristos #include "errnum.h"
8661f28255Scgd 
8761f28255Scgd #define xmalloc(i) Malloc(i)
8861f28255Scgd #define xrealloc(p, i) Realloc(p, i)
89*b544db16Snia #define xreallocarray(p, n, sz) Reallocarray(p, n, sz)
9061f28255Scgd #define xcalloc(n, s) Calloc(n, s)
91cee2bad8Smycroft 
92cee2bad8Smycroft #include <stdio.h>
93e5e328a1Sjoerg extern FILE *cshin, *cshout, *csherr;
9461f28255Scgd 
95f5ad44b6Smycroft #define	isdir(d) (S_ISDIR(d.st_mode))
9661f28255Scgd 
9761f28255Scgd #define	eq(a, b) (Strcmp(a, b) == 0)
9861f28255Scgd 
9961f28255Scgd /* globone() flags */
10061f28255Scgd #define G_ERROR	0		/* default action: error if multiple words */
10161f28255Scgd #define G_IGNORE 1		/* ignore the rest of the words */
10261f28255Scgd #define G_APPEND 2		/* make a sentence by cat'ing the words */
10361f28255Scgd 
10461f28255Scgd /*
10561f28255Scgd  * Global flags
10661f28255Scgd  */
107e5e328a1Sjoerg extern int child;		/* Child shell ... errors cause exit */
108e5e328a1Sjoerg extern int chkstop;		/* Warned of stopped jobs... allow exit */
109e5e328a1Sjoerg extern int didfds;		/* Have setup i/o fd's for child */
110e5e328a1Sjoerg extern int doneinp;		/* EOF indicator after reset from readc */
111e5e328a1Sjoerg extern int exiterr;		/* Exit if error or non-zero exit status */
112e5e328a1Sjoerg extern int haderr;		/* Reset was because of an error */
113e5e328a1Sjoerg extern int havhash;		/* path hashing is available */
114e5e328a1Sjoerg extern int intact;		/* We are interactive... therefore prompt */
115e5e328a1Sjoerg extern int intty;		/* Input is a tty */
116e5e328a1Sjoerg extern int justpr;		/* Just print because of :p hist mod */
117e5e328a1Sjoerg extern int loginsh;		/* We are a loginsh -> .login/.logout */
118e5e328a1Sjoerg extern int neednote;		/* Need to pnotify() */
119e5e328a1Sjoerg extern int noexec;		/* Don't execute, just syntax check */
120e5e328a1Sjoerg extern int pjobs;		/* want to print jobs if interrupted */
121e5e328a1Sjoerg extern int setintr;		/* Set interrupts on/off -> Wait intr... */
122e5e328a1Sjoerg extern int timflg;		/* Time the next waited for command */
12361f28255Scgd 
12461f28255Scgd #ifdef FILEC
125b79c2ef2Schristos extern int filec;		/* doing filename expansion */
12661f28255Scgd #endif
12761f28255Scgd 
12861f28255Scgd /*
12961f28255Scgd  * Global i/o info
13061f28255Scgd  */
131e5e328a1Sjoerg extern Char *arginp;		/* Argument input for sh -c and internal `xx` */
132e5e328a1Sjoerg extern Char *ffile;		/* Name of shell file for $0 */
133e5e328a1Sjoerg extern int onelflg;		/* 2 -> need line for -t, 1 -> exit on read */
13461f28255Scgd 
135a1dfcb96Sscw extern char *seterr;		/* Error message from scanner/parser */
136e5e328a1Sjoerg extern Char *shtemp;		/* Temp name for << shell files in /tmp */
13761f28255Scgd 
13861f28255Scgd #include <sys/resource.h>
139b771e65bSwiz #include <sys/time.h>
140b771e65bSwiz #include <sys/types.h>
14161f28255Scgd 
142e5e328a1Sjoerg extern struct timespec time0;	/* Time at which the shell started */
143e5e328a1Sjoerg extern struct rusage ru0;
14461f28255Scgd 
14561f28255Scgd /*
14661f28255Scgd  * Miscellany
14761f28255Scgd  */
148e5e328a1Sjoerg extern time_t chktim;		/* Time mail last checked */
149e5e328a1Sjoerg extern Char *doldol;		/* Character pid for $$ */
150e5e328a1Sjoerg extern pid_t backpid;		/* Pid of the last background process */
151e5e328a1Sjoerg extern gid_t egid, gid;		/* Invokers gid */
152e5e328a1Sjoerg extern uid_t euid, uid;		/* Invokers uid */
153e5e328a1Sjoerg extern int shpgrp;		/* Pgrp of shell */
154e5e328a1Sjoerg extern int tpgrp;		/* Terminal process group */
15561f28255Scgd 
15661f28255Scgd /* If tpgrp is -1, leave tty alone! */
157e5e328a1Sjoerg extern int opgrp;		/* Initial pgrp and tty pgrp */
15861f28255Scgd 
15961f28255Scgd 
16061f28255Scgd /*
16161f28255Scgd  * To be able to redirect i/o for builtins easily, the shell moves the i/o
16261f28255Scgd  * descriptors it uses away from 0,1,2.
16361f28255Scgd  * Ideally these should be in units which are closed across exec's
16461f28255Scgd  * (this saves work) but for version 6, this is not usually possible.
165cee2bad8Smycroft  * The desired initial values for these descriptors are F{SHIN,...}.
16661f28255Scgd  */
167e5e328a1Sjoerg extern int SHIN;		/* Current shell input (script) */
168e5e328a1Sjoerg extern int SHOUT;		/* Shell output */
169e5e328a1Sjoerg extern int SHERR;		/* Diagnostic output... shell errs go here */
170e5e328a1Sjoerg extern int OLDSTD;		/* Old standard input (def for cmds) */
17161f28255Scgd 
17261f28255Scgd /*
17361f28255Scgd  * Error control
17461f28255Scgd  *
17561f28255Scgd  * Errors in scanning and parsing set up an error message to be printed
17661f28255Scgd  * at the end and complete.  Other errors always cause a reset.
17761f28255Scgd  * Because of source commands and .cshrc we need nested error catches.
17861f28255Scgd  */
17961f28255Scgd 
18061f28255Scgd #include <setjmp.h>
181e5e328a1Sjoerg extern jmp_buf reslab;
18261f28255Scgd 
18361f28255Scgd #define	setexit() (setjmp(reslab))
18461f28255Scgd #define	reset()	longjmp(reslab, 1)
18561f28255Scgd  /* Should use structure assignment here */
1865924694dSmycroft #define	getexit(a) (void)memcpy((a), reslab, sizeof reslab)
1875924694dSmycroft #define	resexit(a) (void)memcpy(reslab, (a), sizeof reslab)
18861f28255Scgd 
189e5e328a1Sjoerg extern Char *gointr;		/* Label for an onintr transfer */
19061f28255Scgd 
19161f28255Scgd #include <signal.h>
192e5e328a1Sjoerg extern sig_t parintr;		/* Parents interrupt catch */
193e5e328a1Sjoerg extern sig_t parterm;		/* Parents terminate catch */
19461f28255Scgd 
19561f28255Scgd /*
19661f28255Scgd  * Lexical definitions.
19761f28255Scgd  *
19861f28255Scgd  * All lexical space is allocated dynamically.
199cee2bad8Smycroft  * The eighth/sixteenth bit of characters is used to prevent recognition,
20061f28255Scgd  * and eventually stripped.
20161f28255Scgd  */
20237e39248Schristos #define	META 0x80
20337e39248Schristos #define	ASCII 0x7f
20461f28255Scgd #ifdef SHORT_STRINGS
20537e39248Schristos #define	CHAR ((Char)0xff)
20637e39248Schristos #define	QUOTE ((Char)0x8000)	/* 16nth char bit used for 'ing */
20737e39248Schristos #define	TRIM ((Char)0x7fff)	/* Mask to strip quote bit */
20861f28255Scgd #else
20937e39248Schristos #define	CHAR ((Char)0x7f)
21037e39248Schristos #define	QUOTE ((Char)0x80)	/* Eighth char bit used for 'ing */
21137e39248Schristos #define	TRIM ((Char)0x7f)	/* Mask to strip quote bit */
21261f28255Scgd #endif
21361f28255Scgd 
214e5e328a1Sjoerg extern int AsciiOnly;			/* If set only 7 bits is expected in characters */
21561f28255Scgd 
21661f28255Scgd /*
21761f28255Scgd  * Each level of input has a buffered input structure.
21861f28255Scgd  * There are one or more blocks of buffered input for each level,
21961f28255Scgd  * exactly one if the input is seekable and tell is available.
22061f28255Scgd  * In other cases, the shell buffers enough blocks to keep all loops
22161f28255Scgd  * in the buffer.
22261f28255Scgd  */
223e5e328a1Sjoerg extern struct Bin {
22461f28255Scgd     off_t Bfseekp;		/* Seek pointer */
22561f28255Scgd     off_t Bfbobp;		/* Seekp of beginning of buffers */
22661f28255Scgd     off_t Bfeobp;		/* Seekp of end of buffers */
227cee2bad8Smycroft     int Bfblocks;		/* Number of buffer blocks */
22861f28255Scgd     Char **Bfbuf;		/* The array of buffer blocks */
22961f28255Scgd } B;
23061f28255Scgd 
231cee2bad8Smycroft /*
232cee2bad8Smycroft  * This structure allows us to seek inside aliases
233cee2bad8Smycroft  */
234cee2bad8Smycroft struct Ain {
235cee2bad8Smycroft     int type;
236cee2bad8Smycroft #define I_SEEK -1		/* Invalid seek */
237cee2bad8Smycroft #define A_SEEK 0		/* Alias seek */
238cee2bad8Smycroft #define F_SEEK 1		/* File seek */
239cee2bad8Smycroft #define E_SEEK 2		/* Eval seek */
240cee2bad8Smycroft     union {
241cee2bad8Smycroft 	off_t _f_seek;
242cee2bad8Smycroft 	Char* _c_seek;
243cee2bad8Smycroft     } fc;
244cee2bad8Smycroft #define f_seek fc._f_seek
245cee2bad8Smycroft #define c_seek fc._c_seek
246cee2bad8Smycroft     Char **a_seek;
247cee2bad8Smycroft };
248cee2bad8Smycroft extern int aret;		/* What was the last character returned */
249cee2bad8Smycroft #define SEEKEQ(a, b) ((a)->type == (b)->type && \
250cee2bad8Smycroft 		      (a)->f_seek == (b)->f_seek && \
251cee2bad8Smycroft 		      (a)->a_seek == (b)->a_seek)
252cee2bad8Smycroft 
25361f28255Scgd #define	fseekp B.Bfseekp
25461f28255Scgd #define	fbobp B.Bfbobp
25561f28255Scgd #define	feobp B.Bfeobp
25661f28255Scgd #define	fblocks	B.Bfblocks
25761f28255Scgd #define	fbuf B.Bfbuf
25861f28255Scgd 
25961f28255Scgd /*
26061f28255Scgd  * The shell finds commands in loops by reseeking the input
26161f28255Scgd  * For whiles, in particular, it reseeks to the beginning of the
26261f28255Scgd  * line the while was on; hence the while placement restrictions.
26361f28255Scgd  */
264e5e328a1Sjoerg extern struct Ain lineloc;
26561f28255Scgd 
266e5e328a1Sjoerg extern int cantell;	/* Is current source tellable ? */
26761f28255Scgd 
26861f28255Scgd /*
26961f28255Scgd  * Input lines are parsed into doubly linked circular
27061f28255Scgd  * lists of words of the following form.
27161f28255Scgd  */
27261f28255Scgd struct wordent {
27361f28255Scgd     Char *word;
27461f28255Scgd     struct wordent *prev;
27561f28255Scgd     struct wordent *next;
27661f28255Scgd };
27761f28255Scgd 
27861f28255Scgd /*
27961f28255Scgd  * During word building, both in the initial lexical phase and
28061f28255Scgd  * when expanding $ variable substitutions, expansion by `!' and `$'
28161f28255Scgd  * must be inhibited when reading ahead in routines which are themselves
28261f28255Scgd  * processing `!' and `$' expansion or after characters such as `\' or in
28361f28255Scgd  * quotations.  The following flags are passed to the getC routines
28461f28255Scgd  * telling them which of these substitutions are appropriate for the
28561f28255Scgd  * next character to be returned.
28661f28255Scgd  */
28761f28255Scgd #define	DODOL 1
28861f28255Scgd #define	DOEXCL 2
28961f28255Scgd #define	DOALL DODOL|DOEXCL
29061f28255Scgd 
29161f28255Scgd /*
29261f28255Scgd  * Labuf implements a general buffer for lookahead during lexical operations.
29361f28255Scgd  * Text which is to be placed in the input stream can be stuck here.
29461f28255Scgd  * We stick parsed ahead $ constructs during initial input,
29561f28255Scgd  * process id's from `$$', and modified variable values (from qualifiers
29661f28255Scgd  * during expansion in sh.dol.c) here.
29761f28255Scgd  */
298e5e328a1Sjoerg extern Char *lap;
29961f28255Scgd 
30061f28255Scgd /*
30161f28255Scgd  * Parser structure
30261f28255Scgd  *
30361f28255Scgd  * Each command is parsed to a tree of command structures and
30461f28255Scgd  * flags are set bottom up during this process, to be propagated down
3058ce1f4ffSmsaitoh  * as needed during the semantics/execution pass (sh.sem.c).
30661f28255Scgd  */
30761f28255Scgd struct command {
30837e39248Schristos     int t_dtyp;			/* Type of node 		 */
30961f28255Scgd #define	NODE_COMMAND	1	/* t_dcom <t_dlef >t_drit	 */
31061f28255Scgd #define	NODE_PAREN	2	/* ( t_dspr ) <t_dlef >t_drit	 */
31161f28255Scgd #define	NODE_PIPE	3	/* t_dlef | t_drit		 */
31261f28255Scgd #define	NODE_LIST	4	/* t_dlef ; t_drit		 */
31361f28255Scgd #define	NODE_OR		5	/* t_dlef || t_drit		 */
31461f28255Scgd #define	NODE_AND	6	/* t_dlef && t_drit		 */
31537e39248Schristos     int t_dflg;			/* Flags, e.g. F_AMPERSAND|... 	 */
31661f28255Scgd #define	F_SAVE	(F_NICE|F_TIME|F_NOHUP)	/* save these when re-doing 	 */
31761f28255Scgd 
31861f28255Scgd #define	F_AMPERSAND	(1<<0)	/* executes in background	 */
31961f28255Scgd #define	F_APPEND	(1<<1)	/* output is redirected >>	 */
32061f28255Scgd #define	F_PIPEIN	(1<<2)	/* input is a pipe		 */
32161f28255Scgd #define	F_PIPEOUT	(1<<3)	/* output is a pipe		 */
32261f28255Scgd #define	F_NOFORK	(1<<4)	/* don't fork, last ()ized cmd	 */
32361f28255Scgd #define	F_NOINTERRUPT	(1<<5)	/* should be immune from intr's */
32461f28255Scgd /* spare */
32561f28255Scgd #define	F_STDERR	(1<<7)	/* redirect unit 2 with unit 1	 */
32661f28255Scgd #define	F_OVERWRITE	(1<<8)	/* output was !			 */
32761f28255Scgd #define	F_READ		(1<<9)	/* input redirection is <<	 */
32861f28255Scgd #define	F_REPEAT	(1<<10)	/* reexec aft if, repeat,...	 */
32961f28255Scgd #define	F_NICE		(1<<11)	/* t_nice is meaningful 	 */
33061f28255Scgd #define	F_NOHUP		(1<<12)	/* nohup this command 		 */
33161f28255Scgd #define	F_TIME		(1<<13)	/* time this command 		 */
33261f28255Scgd     union {
33361f28255Scgd 	Char *T_dlef;		/* Input redirect word 		 */
33461f28255Scgd 	struct command *T_dcar;	/* Left part of list/pipe 	 */
33561f28255Scgd     }       L;
33661f28255Scgd     union {
33761f28255Scgd 	Char *T_drit;		/* Output redirect word 	 */
33861f28255Scgd 	struct command *T_dcdr;	/* Right part of list/pipe 	 */
33961f28255Scgd     }       R;
34061f28255Scgd #define	t_dlef L.T_dlef
34161f28255Scgd #define	t_dcar L.T_dcar
34261f28255Scgd #define	t_drit R.T_drit
34361f28255Scgd #define	t_dcdr R.T_dcdr
34461f28255Scgd     Char **t_dcom;		/* Command/argument vector 	 */
34561f28255Scgd     struct command *t_dspr;	/* Pointer to ()'d subtree 	 */
346cee2bad8Smycroft     int t_nice;
34761f28255Scgd };
34861f28255Scgd 
34961f28255Scgd 
35061f28255Scgd /*
351cee2bad8Smycroft  * These are declared here because they want to be
352cee2bad8Smycroft  * initialized in sh.init.c (to allow them to be made readonly)
353cee2bad8Smycroft  */
354cee2bad8Smycroft 
355cee2bad8Smycroft extern struct biltins {
3566310b596Schristos     const char *bname;
357b771e65bSwiz     void (*bfunct)(Char **, struct command *);
358cee2bad8Smycroft     short minargs, maxargs;
359cee2bad8Smycroft } bfunc[];
360b771e65bSwiz 
361cee2bad8Smycroft extern int nbfunc;
362b771e65bSwiz extern int nsrchn;
363cee2bad8Smycroft 
364cee2bad8Smycroft extern struct srch {
3656310b596Schristos     const char *s_name;
366cee2bad8Smycroft     short s_value;
367cee2bad8Smycroft } srchn[];
368cee2bad8Smycroft 
369cee2bad8Smycroft /*
37061f28255Scgd  * The keywords for the parser
37161f28255Scgd  */
37261f28255Scgd #define	T_BREAK		0
37361f28255Scgd #define	T_BRKSW		1
37461f28255Scgd #define	T_CASE		2
37561f28255Scgd #define	T_DEFAULT 	3
37661f28255Scgd #define	T_ELSE		4
37761f28255Scgd #define	T_END		5
37861f28255Scgd #define	T_ENDIF		6
37961f28255Scgd #define	T_ENDSW		7
38061f28255Scgd #define	T_EXIT		8
38161f28255Scgd #define	T_FOREACH	9
38261f28255Scgd #define	T_GOTO		10
38361f28255Scgd #define	T_IF		11
38461f28255Scgd #define	T_LABEL		12
38561f28255Scgd #define	T_LET		13
38661f28255Scgd #define	T_SET		14
38761f28255Scgd #define	T_SWITCH	15
38861f28255Scgd #define	T_TEST		16
38961f28255Scgd #define	T_THEN		17
39061f28255Scgd #define	T_WHILE		18
39161f28255Scgd 
39261f28255Scgd /*
39361f28255Scgd  * Structure defining the existing while/foreach loops at this
39461f28255Scgd  * source level.  Loops are implemented by seeking back in the
39561f28255Scgd  * input.  For foreach (fe), the word list is attached here.
39661f28255Scgd  */
397e5e328a1Sjoerg extern struct whyle {
398cee2bad8Smycroft     struct Ain w_start;		/* Point to restart loop */
399cee2bad8Smycroft     struct Ain w_end;		/* End of loop (0 if unknown) */
40061f28255Scgd     Char **w_fe, **w_fe0;	/* Current/initial wordlist for fe */
40161f28255Scgd     Char *w_fename;		/* Name for fe */
40261f28255Scgd     struct whyle *w_next;	/* Next (more outer) loop */
40361f28255Scgd } *whyles;
40461f28255Scgd 
40561f28255Scgd /*
40661f28255Scgd  * Variable structure
40761f28255Scgd  *
40861f28255Scgd  * Aliases and variables are stored in AVL balanced binary trees.
40961f28255Scgd  */
410e5e328a1Sjoerg extern struct varent {
41161f28255Scgd     Char **vec;			/* Array of words which is the value */
41261f28255Scgd     Char *v_name;		/* Name of variable/alias */
41361f28255Scgd     struct varent *v_link[3];	/* The links, see below */
41461f28255Scgd     int v_bal;			/* Balance factor */
41561f28255Scgd } shvhed, aliases;
41661f28255Scgd 
41761f28255Scgd #define v_left v_link[0]
41861f28255Scgd #define v_right	v_link[1]
41961f28255Scgd #define v_parent v_link[2]
42061f28255Scgd 
42161f28255Scgd #define adrof(v) adrof1(v, &shvhed)
42261f28255Scgd #define value(v) value1(v, &shvhed)
42361f28255Scgd 
42461f28255Scgd /*
42561f28255Scgd  * The following are for interfacing redo substitution in
42661f28255Scgd  * aliases to the lexical routines.
42761f28255Scgd  */
428e5e328a1Sjoerg extern struct wordent *alhistp;	/* Argument list (first) */
429e5e328a1Sjoerg extern struct wordent *alhistt;	/* Node after last in arg list */
430a1dfcb96Sscw extern Char **alvec, *alvecp;	/* The (remnants of) alias vector */
43161f28255Scgd 
43261f28255Scgd /*
43361f28255Scgd  * Filename/command name expansion variables
43461f28255Scgd  */
435e5e328a1Sjoerg extern int gflag;		/* After tglob -> is globbing needed? */
43661f28255Scgd 
43761f28255Scgd #define MAXVARLEN 30		/* Maximum number of char in a variable name */
43861f28255Scgd 
43961f28255Scgd /*
44061f28255Scgd  * Variables for filename expansion
44161f28255Scgd  */
44261f28255Scgd extern long gargc;		/* Number args in gargv */
443b771e65bSwiz extern Char **gargv;		/* Pointer to the (stack) arglist */
44461f28255Scgd 
44561f28255Scgd /*
44661f28255Scgd  * Variables for command expansion.
44761f28255Scgd  */
44861f28255Scgd extern Char **pargv;		/* Pointer to the argv list space */
44961f28255Scgd extern long pargc;		/* Count of arguments in pargv */
450e5e328a1Sjoerg extern long pnleft;		/* Number of chars left in pargs */
451e5e328a1Sjoerg extern Char *pargs;		/* Pointer to start current word */
452e5e328a1Sjoerg extern Char *pargcp;		/* Current index into pargs */
45361f28255Scgd 
45461f28255Scgd /*
45561f28255Scgd  * History list
45661f28255Scgd  *
45761f28255Scgd  * Each history list entry contains an embedded wordlist
45861f28255Scgd  * from the scanner, a number for the event, and a reference count
45961f28255Scgd  * to aid in discarding old entries.
46061f28255Scgd  *
46161f28255Scgd  * Essentially "invisible" entries are put on the history list
46261f28255Scgd  * when history substitution includes modifiers, and thrown away
46361f28255Scgd  * at the next discarding since their event numbers are very negative.
46461f28255Scgd  */
465e5e328a1Sjoerg extern struct Hist {
46661f28255Scgd     struct wordent Hlex;
46761f28255Scgd     int Hnum;
46861f28255Scgd     int Href;
46961f28255Scgd     struct Hist *Hnext;
47061f28255Scgd } Histlist;
47161f28255Scgd 
472e5e328a1Sjoerg extern struct wordent paraml;	/* Current lexical word list */
473e5e328a1Sjoerg extern int eventno;		/* Next events number */
474e5e328a1Sjoerg extern int lastev;		/* Last event reference (default) */
47561f28255Scgd 
476e5e328a1Sjoerg extern Char HIST;		/* history invocation character */
477e5e328a1Sjoerg extern Char HISTSUB;		/* auto-substitute character */
47861f28255Scgd 
47961f28255Scgd /*
48061f28255Scgd  * strings.h:
48161f28255Scgd  */
48261f28255Scgd #ifndef SHORT_STRINGS
48361f28255Scgd #define Strchr(a, b) 		strchr(a, b)
48461f28255Scgd #define Strrchr(a, b)		strrchr(a, b)
48561f28255Scgd #define Strcat(a, b)		strcat(a, b)
48661f28255Scgd #define Strncat(a, b, c)	strncat(a, b, c)
48761f28255Scgd #define Strcpy(a, b)		strcpy(a, b)
48861f28255Scgd #define Strncpy(a, b, c)	strncpy(a, b, c)
48961f28255Scgd #define Strlen(a)		strlen(a)
49061f28255Scgd #define Strcmp(a, b)		strcmp(a, b)
49161f28255Scgd #define Strncmp(a, b, c)	strncmp(a, b, c)
49261f28255Scgd 
49361f28255Scgd #define Strspl(a, b)		strspl(a, b)
49461f28255Scgd #define Strsave(a)		strsave(a)
49561f28255Scgd #define Strend(a)		strend(a)
49661f28255Scgd #define Strstr(a, b)		strstr(a, b)
49761f28255Scgd 
49861f28255Scgd #define str2short(a)		(a)
49961f28255Scgd #define blk2short(a)		saveblk(a)
50061f28255Scgd #define short2blk(a)		saveblk(a)
501cee2bad8Smycroft #define short2str(a)		strip(a)
50261f28255Scgd #else
50361f28255Scgd #define Strchr(a, b)		s_strchr(a, b)
50461f28255Scgd #define Strrchr(a, b)		s_strrchr(a, b)
50561f28255Scgd #define Strcat(a, b)		s_strcat(a, b)
50661f28255Scgd #define Strncat(a, b, c) 	s_strncat(a, b, c)
50761f28255Scgd #define Strcpy(a, b)		s_strcpy(a, b)
50861f28255Scgd #define Strncpy(a, b, c)	s_strncpy(a, b, c)
50961f28255Scgd #define Strlen(a)		s_strlen(a)
51061f28255Scgd #define Strcmp(a, b)		s_strcmp(a, b)
51161f28255Scgd #define Strncmp(a, b, c)	s_strncmp(a, b, c)
51261f28255Scgd 
51361f28255Scgd #define Strspl(a, b)		s_strspl(a, b)
51461f28255Scgd #define Strsave(a)		s_strsave(a)
51561f28255Scgd #define Strend(a)		s_strend(a)
51661f28255Scgd #define Strstr(a, b)		s_strstr(a, b)
51761f28255Scgd #endif
51861f28255Scgd 
51961f28255Scgd /*
52061f28255Scgd  * setname is a macro to save space (see sh.err.c)
52161f28255Scgd  */
522e5e328a1Sjoerg extern const char *bname;
52361f28255Scgd 
52461f28255Scgd #define	setname(a) (bname = (a))
52561f28255Scgd 
526e5e328a1Sjoerg extern Char *Vsav;
527e5e328a1Sjoerg extern Char *Vdp;
528e5e328a1Sjoerg extern Char *Vexpath;
529e5e328a1Sjoerg extern char **Vt;
53061f28255Scgd 
531e5e328a1Sjoerg extern Char **evalvec;
532e5e328a1Sjoerg extern Char *evalp;
53361f28255Scgd 
53461f28255Scgd /* word_chars is set by default to WORD_CHARS but can be overridden by
53561f28255Scgd    the worchars variable--if unset, reverts to WORD_CHARS */
53661f28255Scgd 
537e5e328a1Sjoerg extern Char *word_chars;
53861f28255Scgd 
53961f28255Scgd #define WORD_CHARS "*?_-.[]~="	/* default chars besides alnums in words */
54061f28255Scgd 
541e5e328a1Sjoerg extern Char *STR_SHELLPATH;
54261f28255Scgd 
54361f28255Scgd #include <paths.h>
54461f28255Scgd #ifdef _PATH_BSHELL
545e5e328a1Sjoerg extern Char *STR_BSHELL;
54661f28255Scgd #endif
547e5e328a1Sjoerg extern Char *STR_WORD_CHARS;
548e5e328a1Sjoerg extern Char **STR_environ;
549b771e65bSwiz 
5505e9a2dddSchristos #ifdef EDIT
5515e9a2dddSchristos #include <histedit.h>
552e5e328a1Sjoerg extern EditLine *el;
553e5e328a1Sjoerg extern History *hi;
5545e9a2dddSchristos #endif
555e5e328a1Sjoerg extern int editing;
5565e9a2dddSchristos 
557b771e65bSwiz #endif /* !_CSH_H_ */
558