Home | History | Annotate | Line # | Download | only in sh
shell.h revision 1.26
      1  1.26       kre /*	$NetBSD: shell.h,v 1.26 2018/07/22 20:38:06 kre Exp $	*/
      2   1.7       cgd 
      3   1.1       cgd /*-
      4   1.5       jtc  * Copyright (c) 1991, 1993
      5   1.5       jtc  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * This code is derived from software contributed to Berkeley by
      8   1.1       cgd  * Kenneth Almquist.
      9   1.1       cgd  *
     10   1.1       cgd  * Redistribution and use in source and binary forms, with or without
     11   1.1       cgd  * modification, are permitted provided that the following conditions
     12   1.1       cgd  * are met:
     13   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     14   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     15   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     17   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     18  1.17       agc  * 3. Neither the name of the University nor the names of its contributors
     19   1.1       cgd  *    may be used to endorse or promote products derived from this software
     20   1.1       cgd  *    without specific prior written permission.
     21   1.1       cgd  *
     22   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32   1.1       cgd  * SUCH DAMAGE.
     33   1.1       cgd  *
     34   1.8  christos  *	@(#)shell.h	8.2 (Berkeley) 5/4/95
     35   1.1       cgd  */
     36   1.1       cgd 
     37   1.1       cgd /*
     38   1.1       cgd  * The follow should be set to reflect the type of system you have:
     39   1.1       cgd  *	JOBS -> 1 if you have Berkeley job control, 0 otherwise.
     40   1.1       cgd  *	define BSD if you are running 4.2 BSD or later.
     41   1.1       cgd  *	define SYSV if you are running under System V.
     42  1.16       dsl  *	define DEBUG=1 to compile in debugging ('set -o debug' to turn on)
     43  1.23       kre  *	define DEBUG=2 to compile in and enable debugging.
     44  1.23       kre  *	define DEBUG=3 for DEBUG==2 + enable most standard debug output
     45  1.23       kre  *	define DEBUG=4 for DEBUG==2 + enable absolutely everything
     46  1.15  christos  *	define DO_SHAREDVFORK to indicate that vfork(2) shares its address
     47  1.15  christos  *	       with its parent.
     48  1.22       kre  *	define BOGUS_NOT_COMMAND to allow ! reserved words in weird places
     49  1.22       kre  *		(traditional ash behaviour.)
     50   1.1       cgd  *
     51  1.16       dsl  * When debugging is on, debugging info will be written to ./trace and
     52   1.1       cgd  * a quit signal will generate a core dump.
     53   1.1       cgd  */
     54   1.1       cgd 
     55  1.20     joerg #ifndef SHELL_H
     56  1.20     joerg #define SHELL_H
     57  1.15  christos #include <sys/param.h>
     58   1.1       cgd 
     59   1.1       cgd #define JOBS 1
     60   1.5       jtc #ifndef BSD
     61   1.5       jtc #define BSD 1
     62  1.15  christos #endif
     63  1.15  christos 
     64  1.15  christos #ifndef DO_SHAREDVFORK
     65  1.21       kre #if defined(__NetBSD_Version__) &&  __NetBSD_Version__ >= 104000000
     66  1.15  christos #define DO_SHAREDVFORK
     67  1.15  christos #endif
     68   1.5       jtc #endif
     69   1.1       cgd 
     70   1.1       cgd typedef void *pointer;
     71   1.1       cgd #ifndef NULL
     72   1.1       cgd #define NULL (void *)0
     73   1.1       cgd #endif
     74  1.19       kre #ifndef STATIC
     75   1.1       cgd #define STATIC	/* empty */
     76  1.19       kre #endif
     77   1.1       cgd #define MKINIT	/* empty */
     78   1.1       cgd 
     79   1.1       cgd #include <sys/cdefs.h>
     80   1.1       cgd 
     81  1.18  dholland extern const char nullstr[1];		/* null string */
     82   1.1       cgd 
     83  1.21       kre #ifdef	SMALL
     84  1.21       kre #undef	DEBUG
     85  1.21       kre #endif
     86   1.1       cgd 
     87   1.1       cgd #ifdef DEBUG
     88  1.21       kre 
     89  1.21       kre extern	uint64_t	DFlags;
     90  1.21       kre extern	int		ShNest;
     91  1.21       kre 
     92  1.21       kre /*
     93  1.21       kre  * This is selected as there are 26 letters in ascii - not that that
     94  1.21       kre  * matters for anything, just makes it easier to assign a different
     95  1.21       kre  * command letter to each debug option.  We currently use only 18
     96  1.21       kre  * so this could be reduced, but that is of no real benefit.  It can also
     97  1.21       kre  * be increased, but that both limits the maximum value tha can be
     98  1.21       kre  * used with DBG_EXTRAS(), and causes problems with verbose option naming.
     99  1.21       kre  */
    100  1.21       kre #define	DBG_VBOSE_SHIFT		26
    101  1.21       kre #define	DBG_EXTRAS(n)	((DBG_VBOSE_SHIFT * 2) + (n))
    102  1.21       kre 
    103  1.21       kre /*
    104  1.21       kre  * Unconditional tracing for compatibility with old tracing setup.
    105  1.21       kre  */
    106  1.21       kre #define TRACE(param)		do {					\
    107  1.21       kre 					trace param;			\
    108  1.21       kre 				} while (/*CONSTCOND*/ 0)
    109  1.21       kre #define TRACEV(param)		do {					\
    110  1.21       kre 					tracev param;			\
    111  1.21       kre 				} while (/*CONSTCOND*/ 0)
    112  1.21       kre 
    113  1.21       kre /*
    114  1.21       kre  * and the newer conditional tracing, so the mainainer can control
    115  1.21       kre  * just how much debug output is dumped to the trace file
    116  1.21       kre  * (once the rest of the shell is converted to use it).
    117  1.21       kre  *
    118  1.21       kre  * in the X forms, "xtra" can be any legal C statement(s) without (bare) commas
    119  1.21       kre  * executed if the relevant debug flag is enabled, after any tracing output.
    120  1.21       kre  */
    121  1.21       kre #define CTRACE(when, param)	do {					\
    122  1.21       kre 				    if ((DFlags & (when)) != 0)		\
    123  1.21       kre 					trace param;			\
    124  1.21       kre 				} while (/*CONSTCOND*/ 0)
    125  1.21       kre 
    126  1.25       kre #define CCTRACE(when,cond,param) do {					\
    127  1.25       kre 				    if ((cond) && (DFlags & (when)) != 0) \
    128  1.25       kre 					trace param;			\
    129  1.25       kre 				} while (/*CONSTCOND*/ 0)
    130  1.25       kre 
    131  1.21       kre #define CTRACEV(when, param)	do {					\
    132  1.21       kre 				    if ((DFlags & (when)) != 0)		\
    133  1.21       kre 					tracev param;			\
    134  1.21       kre 				} while (/*CONSTCOND*/ 0)
    135  1.21       kre 
    136  1.21       kre #define XTRACE(when, param, xtra) do {					\
    137  1.21       kre 				    if ((DFlags & (when)) != 0) {	\
    138  1.21       kre 					trace param;			\
    139  1.21       kre 					xtra;				\
    140  1.21       kre 				    }					\
    141  1.21       kre 				} while (/*CONSTCOND*/ 0)
    142  1.21       kre 
    143  1.21       kre #define VTRACE(when, param)	do {					\
    144  1.21       kre 				    if ((DFlags &			\
    145  1.21       kre 					(when)<<DBG_VBOSE_SHIFT) != 0)	\
    146  1.21       kre 					    trace param;		\
    147  1.21       kre 				} while (/*CONSTCOND*/ 0)
    148  1.21       kre 
    149  1.25       kre #define CVTRACE(when,cond,param) do {					\
    150  1.25       kre 				    if ((cond) && (DFlags &		\
    151  1.25       kre 					(when)<<DBG_VBOSE_SHIFT) != 0)	\
    152  1.25       kre 					    trace param;		\
    153  1.25       kre 				} while (/*CONSTCOND*/ 0)
    154  1.25       kre 
    155  1.21       kre #define VTRACEV(when, param)	do {					\
    156  1.21       kre 				    if ((DFlags &			\
    157  1.21       kre 					(when)<<DBG_VBOSE_SHIFT) != 0)	\
    158  1.21       kre 					    tracev param;		\
    159  1.21       kre 				} while (/*CONSTCOND*/ 0)
    160  1.21       kre 
    161  1.21       kre #define VXTRACE(when, param, xtra) do {					\
    162  1.21       kre 				    if ((DFlags &			\
    163  1.21       kre 					(when)<<DBG_VBOSE_SHIFT) != 0) {\
    164  1.21       kre 					    trace param;		\
    165  1.21       kre 					    xtra;			\
    166  1.21       kre 				    }					\
    167  1.21       kre 				} while (/*CONSTCOND*/ 0)
    168  1.21       kre 
    169  1.21       kre #define SHELL_FORKED()	ShNest++
    170  1.21       kre #define VFORK_BLOCK	{ const int _ShNest = ShNest;
    171  1.21       kre #define VFORK_END	}
    172  1.21       kre #define VFORK_UNDO()	ShNest = _ShNest
    173  1.21       kre 
    174  1.21       kre #define	DBG_ALWAYS	(1LL << 0)
    175  1.21       kre #define	DBG_PARSE	(1LL << 1)		/* r (read commands) */
    176  1.21       kre #define	DBG_EVAL	(1LL << 2)		/* e */
    177  1.21       kre #define	DBG_EXPAND	(1LL << 3)		/* x */
    178  1.21       kre #define	DBG_JOBS	(1LL << 4)		/* j */
    179  1.21       kre #define	DBG_PROCS	(1LL << 5)		/* p */
    180  1.21       kre #define	DBG_REDIR	(1LL << 6)		/* f (fds) */
    181  1.21       kre #define	DBG_CMDS	(1LL << 7)		/* c */
    182  1.21       kre #define	DBG_ERRS	(1LL << 8)		/* z (?) */
    183  1.21       kre #define	DBG_WAIT	(1LL << 9)		/* w */
    184  1.21       kre #define	DBG_TRAP	(1LL << 10)		/* t */
    185  1.21       kre #define	DBG_VARS	(1LL << 11)		/* v */
    186  1.21       kre #define	DBG_INPUT	(1LL << 12)		/* i */
    187  1.21       kre #define	DBG_OUTPUT	(1LL << 13)		/* o */
    188  1.21       kre #define	DBG_MEM		(1LL << 14)		/* m */
    189  1.21       kre #define	DBG_ARITH	(1LL << 15)		/* a */
    190  1.21       kre #define	DBG_HISTORY	(1LL << 16)		/* h */
    191  1.21       kre #define	DBG_SIG		(1LL << 17)		/* s */
    192  1.26       kre #define	DBG_MATCH	(1LL << 18)		/* g (glob) */
    193  1.21       kre 
    194  1.21       kre /*
    195  1.21       kre  * reserved extras: b=builtins l=alias
    196  1.26       kre  * still free:  d k n q u y
    197  1.21       kre  */
    198  1.21       kre 
    199  1.21       kre 	/* use VTRACE(DBG_ALWAYS, (...)) to test this one */
    200  1.21       kre #define	DBG_VERBOSE	(1LL << DBG_VBOSE_SHIFT)
    201  1.21       kre 
    202  1.21       kre 	/* DBG_EXTRAS 0 .. 11 (max) only  - non-alpha options (no VTRACE !!) */
    203  1.21       kre #define	DBG_U0		(1LL << DBG_EXTRAS(0))	/* 0 - ad-hoc extra flags */
    204  1.21       kre #define	DBG_U1		(1LL << DBG_EXTRAS(1))	/* 1 - for short term */
    205  1.21       kre #define	DBG_U2		(1LL << DBG_EXTRAS(2))	/* 2 - extra tracing*/
    206  1.21       kre 
    207  1.23       kre #define	DBG_LINE	(1LL << DBG_EXTRAS(9))	/* @ ($LINENO) */
    208  1.21       kre #define	DBG_PID		(1LL << DBG_EXTRAS(10))	/* $ ($$) */
    209  1.21       kre #define	DBG_NEST	(1LL << DBG_EXTRAS(11))	/* ^ */
    210  1.21       kre 
    211  1.21       kre extern void set_debug(const char *, int);
    212  1.21       kre 
    213  1.21       kre #else	/* DEBUG */
    214  1.21       kre 
    215  1.21       kre #define TRACE(param)			/* historic normal trace */
    216  1.21       kre #define TRACEV(param)			/* historic varargs trace */
    217  1.21       kre 
    218  1.21       kre #define CTRACE(when, param)		/* conditional normal trace */
    219  1.25       kre #define CCTRACE(when, cond, param)	/* more conditional normal trace */
    220  1.21       kre #define CTRACEV(when, param)		/* conditional varargs trace */
    221  1.21       kre #define XTRACE(when, param, extra)	/* conditional trace, plus more */
    222  1.21       kre #define VTRACE(when, param)		/* conditional verbose trace */
    223  1.25       kre #define CVTRACE(when, cond, param)	/* more conditional verbose trace */
    224  1.21       kre #define VTRACEV(when, param)		/* conditional verbose varargs trace */
    225  1.21       kre #define VXTRACE(when, param, extra)	/* cond verbose trace, plus more */
    226  1.21       kre 
    227  1.21       kre #define SHELL_FORKED()
    228  1.21       kre #define VFORK_BLOCK
    229  1.21       kre #define VFORK_END
    230  1.21       kre #define VFORK_UNDO()
    231  1.21       kre 
    232  1.21       kre #endif	/* DEBUG */
    233  1.20     joerg 
    234  1.20     joerg #endif /* SHELL_H */
    235