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