1 /* $NetBSD: shell.h,v 1.29 2019/01/22 13:48:28 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 enable debugging. 44 * define DEBUG=3 for DEBUG==2 + enable most standard debug output 45 * define DEBUG=4 for DEBUG==2 + enable absolutely everything 46 * define DO_SHAREDVFORK to indicate that vfork(2) shares its address 47 * with its parent. 48 * define BOGUS_NOT_COMMAND to allow ! reserved words in weird places 49 * (traditional ash behaviour.) 50 * 51 * When debugging is on, debugging info will be written to ./trace and 52 * a quit signal will generate a core dump. 53 */ 54 55 #ifndef SHELL_H 56 #define SHELL_H 57 #include <sys/param.h> 58 59 #define JOBS 1 60 #ifndef BSD 61 #define BSD 1 62 #endif 63 64 #ifndef DO_SHAREDVFORK 65 #if defined(__NetBSD_Version__) && __NetBSD_Version__ >= 104000000 66 #define DO_SHAREDVFORK 67 #endif 68 #endif 69 70 typedef void *pointer; 71 #ifndef NULL 72 #define NULL (void *)0 73 #endif 74 #ifndef STATIC 75 #define STATIC /* empty */ 76 #endif 77 #define MKINIT /* empty */ 78 79 #include <sys/cdefs.h> 80 81 extern const char nullstr[1]; /* null string */ 82 83 #ifdef SMALL 84 #undef DEBUG 85 #endif 86 87 #ifdef DEBUG 88 89 extern uint64_t DFlags; 90 extern int ShNest; 91 92 /* 93 * This is selected as there are 26 letters in ascii - not that that 94 * matters for anything, just makes it easier to assign a different 95 * command letter to each debug option. We currently use only 18 96 * so this could be reduced, but that is of no real benefit. It can also 97 * be increased, but that both limits the maximum value tha can be 98 * used with DBG_EXTRAS(), and causes problems with verbose option naming. 99 */ 100 #define DBG_VBOSE_SHIFT 27 101 #define DBG_EXTRAS(n) ((DBG_VBOSE_SHIFT * 2) + (n)) 102 103 /* 104 * Macros to enable tracing, so the mainainer can control 105 * just how much debug output is dumped to the trace file 106 * 107 * In the X forms, "xtra" can be any legal C statement(s) without (bare) commas 108 * executed if the relevant debug flag is enabled, after any tracing output. 109 */ 110 #define CTRACE(when, param) do { \ 111 if ((DFlags & (when)) != 0) \ 112 trace param; \ 113 } while (/*CONSTCOND*/ 0) 114 115 #define CCTRACE(when,cond,param) do { \ 116 if ((cond) && (DFlags & (when)) != 0) \ 117 trace param; \ 118 } while (/*CONSTCOND*/ 0) 119 120 #define CTRACEV(when, param) do { \ 121 if ((DFlags & (when)) != 0) \ 122 tracev param; \ 123 } while (/*CONSTCOND*/ 0) 124 125 #define XTRACE(when, param, xtra) do { \ 126 if ((DFlags & (when)) != 0) { \ 127 trace param; \ 128 xtra; \ 129 } \ 130 } while (/*CONSTCOND*/ 0) 131 132 #define VTRACE(when, param) do { \ 133 if ((DFlags & \ 134 (when)<<DBG_VBOSE_SHIFT) != 0) \ 135 trace param; \ 136 } while (/*CONSTCOND*/ 0) 137 138 #define CVTRACE(when,cond,param) do { \ 139 if ((cond) && (DFlags & \ 140 (when)<<DBG_VBOSE_SHIFT) != 0) \ 141 trace param; \ 142 } while (/*CONSTCOND*/ 0) 143 144 #define VTRACEV(when, param) do { \ 145 if ((DFlags & \ 146 (when)<<DBG_VBOSE_SHIFT) != 0) \ 147 tracev param; \ 148 } while (/*CONSTCOND*/ 0) 149 150 #define VXTRACE(when, param, xtra) do { \ 151 if ((DFlags & \ 152 (when)<<DBG_VBOSE_SHIFT) != 0) {\ 153 trace param; \ 154 xtra; \ 155 } \ 156 } while (/*CONSTCOND*/ 0) 157 158 #define SHELL_FORKED() ShNest++ 159 #define VFORK_BLOCK { const int _ShNest = ShNest; 160 #define VFORK_END } 161 #define VFORK_UNDO() ShNest = _ShNest 162 163 #define DBG_ALWAYS (1LL << 0) 164 #define DBG_PARSE (1LL << 1) /* r (read commands) */ 165 #define DBG_EVAL (1LL << 2) /* e */ 166 #define DBG_EXPAND (1LL << 3) /* x */ 167 #define DBG_JOBS (1LL << 4) /* j */ 168 #define DBG_PROCS (1LL << 5) /* p */ 169 #define DBG_REDIR (1LL << 6) /* f (fds) */ 170 #define DBG_CMDS (1LL << 7) /* c */ 171 #define DBG_ERRS (1LL << 8) /* z (?) */ 172 #define DBG_WAIT (1LL << 9) /* w */ 173 #define DBG_TRAP (1LL << 10) /* t */ 174 #define DBG_VARS (1LL << 11) /* v */ 175 #define DBG_INPUT (1LL << 12) /* i */ 176 #define DBG_OUTPUT (1LL << 13) /* o */ 177 #define DBG_MEM (1LL << 14) /* m */ 178 #define DBG_ARITH (1LL << 15) /* a */ 179 #define DBG_HISTORY (1LL << 16) /* h */ 180 #define DBG_SIG (1LL << 17) /* s */ 181 #define DBG_MATCH (1LL << 18) /* g (glob) */ 182 #define DBG_LEXER (1LL << 19) /* l */ 183 184 /* 185 * reserved extras: b=builtins y=alias 186 * still free: d k n q u 187 */ 188 189 /* use VTRACE(DBG_ALWAYS, (...)) to test this one */ 190 #define DBG_VERBOSE (1LL << DBG_VBOSE_SHIFT) 191 192 /* DBG_EXTRAS 0 .. 9 (max) only - non-alpha options (no VTRACE !!) */ 193 #define DBG_U0 (1LL << DBG_EXTRAS(0)) /* 0 - ad-hoc extra flags */ 194 #define DBG_U1 (1LL << DBG_EXTRAS(1)) /* 1 - for short term */ 195 #define DBG_U2 (1LL << DBG_EXTRAS(2)) /* 2 - extra tracing */ 196 #define DBG_U3 (1LL << DBG_EXTRAS(3)) /* 3 - when needed */ 197 /* 4, 5, & 6 currently free */ 198 #define DBG_LINE (1LL << DBG_EXTRAS(7)) /* @ ($LINENO) */ 199 #define DBG_PID (1LL << DBG_EXTRAS(8)) /* $ ($$) */ 200 #define DBG_NEST (1LL << DBG_EXTRAS(9)) /* ^ */ 201 202 /* 26 lower case, 26 upper case, always, verbose, and 10 extras: 64 bits */ 203 204 extern void set_debug(const char *, int); 205 206 #else /* DEBUG */ 207 208 #define CTRACE(when, param) /* conditional normal trace */ 209 #define CCTRACE(when, cond, param) /* more conditional normal trace */ 210 #define CTRACEV(when, param) /* conditional varargs trace */ 211 #define XTRACE(when, param, extra) /* conditional trace, plus more */ 212 #define VTRACE(when, param) /* conditional verbose trace */ 213 #define CVTRACE(when, cond, param) /* more conditional verbose trace */ 214 #define VTRACEV(when, param) /* conditional verbose varargs trace */ 215 #define VXTRACE(when, param, extra) /* cond verbose trace, plus more */ 216 217 #define SHELL_FORKED() 218 #define VFORK_BLOCK 219 #define VFORK_END 220 #define VFORK_UNDO() 221 222 #endif /* DEBUG */ 223 224 #endif /* SHELL_H */ 225