1 /* $NetBSD: table.h,v 1.2 1997/01/12 19:12:21 tls Exp $ */ 2 3 /* 4 * generic hashed associative table for commands and variables. 5 */ 6 7 struct table { 8 Area *areap; /* area to allocate entries */ 9 short size, nfree; /* hash size (always 2^^n), free entries */ 10 struct tbl **tbls; /* hashed table items */ 11 }; 12 13 struct tbl { /* table item */ 14 Tflag flag; /* flags */ 15 int type; /* command type (see below), base (if INTEGER), 16 * or offset from val.s of value (if EXPORT) */ 17 Area *areap; /* area to allocate from */ 18 union { 19 char *s; /* string */ 20 long i; /* integer */ 21 int (*f) ARGS((char **)); /* int function */ 22 struct op *t; /* "function" tree */ 23 } val; /* value */ 24 int index; /* index for an array */ 25 union { 26 int field; /* field with for -L/-R/-Z */ 27 int errno_; /* CEXEC/CTALIAS */ 28 } u2; 29 union { 30 struct tbl *array; /* array values */ 31 char *fpath; /* temporary path to undef function */ 32 } u; 33 char name[4]; /* name -- variable length */ 34 }; 35 36 /* common flag bits */ 37 #define ALLOC BIT(0) /* val.s has been allocated */ 38 #define DEFINED BIT(1) /* is defined in block */ 39 #define ISSET BIT(2) /* has value, vp->val.[si] */ 40 #define EXPORT BIT(3) /* exported variable/function */ 41 #define TRACE BIT(4) /* var: user flagged, func: execution tracing */ 42 /* (start non-common flags at 8) */ 43 /* flag bits used for variables */ 44 #define SPECIAL BIT(8) /* PATH, IFS, SECONDS, etc */ 45 #define INTEGER BIT(9) /* val.i contains integer value */ 46 #define RDONLY BIT(10) /* read-only variable */ 47 #define LOCAL BIT(11) /* for local typeset() */ 48 #define ARRAY BIT(13) /* array */ 49 #define LJUST BIT(14) /* left justify */ 50 #define RJUST BIT(15) /* right justify */ 51 #define ZEROFIL BIT(16) /* 0 filled if RJUSTIFY, strip 0s if LJUSTIFY */ 52 #define LCASEV BIT(17) /* convert to lower case */ 53 #define UCASEV_AL BIT(18)/* convert to upper case / autoload function */ 54 #define INT_U BIT(19) /* unsigned integer */ 55 #define INT_L BIT(20) /* long integer (no-op) */ 56 #define IMPORT BIT(21) /* flag to typeset(): no arrays, must have = */ 57 #define LOCAL_COPY BIT(22) /* with LOCAL - copy attrs from existing var */ 58 #define EXPRINEVAL BIT(23) /* contents currently being evaluated */ 59 #define EXPRLVALUE BIT(24) /* useable as lvalue (temp flag) */ 60 /* flag bits used for taliases/builtins/aliases/keywords/functions */ 61 #define KEEPASN BIT(8) /* keep command assignments (eg, var=x cmd) */ 62 #define FINUSE BIT(9) /* function being executed */ 63 #define FDELETE BIT(10) /* function deleted while it was executing */ 64 #define FKSH BIT(11) /* function defined with function x (vs x()) */ 65 #define SPEC_BI BIT(12) /* a POSIX special builtin */ 66 #define REG_BI BIT(13) /* a POSIX regular builtin */ 67 /* Attributes that can be set by the user (used to decide if an unset param 68 * should be repoted by set/typeset). Does not include ARRAY or LOCAL. 69 */ 70 #define USERATTRIB (EXPORT|INTEGER|RDONLY|LJUST|RJUST|ZEROFIL\ 71 |LCASEV|UCASEV_AL|INT_U|INT_L) 72 73 /* command types */ 74 #define CNONE 0 /* undefined */ 75 #define CSHELL 1 /* built-in */ 76 #define CFUNC 2 /* function */ 77 #define CEXEC 4 /* executable command */ 78 #define CALIAS 5 /* alias */ 79 #define CKEYWD 6 /* keyword */ 80 #define CTALIAS 7 /* tracked alias */ 81 82 /* Flags for findcom()/comexec() */ 83 #define FC_SPECBI BIT(0) /* special builtin */ 84 #define FC_FUNC BIT(1) /* function builtin */ 85 #define FC_REGBI BIT(2) /* regular builtin */ 86 #define FC_UNREGBI BIT(3) /* un-regular builtin (!special,!regular) */ 87 #define FC_BI (FC_SPECBI|FC_REGBI|FC_UNREGBI) 88 #define FC_PATH BIT(4) /* do path search */ 89 #define FC_DEFPATH BIT(5) /* use default path in path search */ 90 91 92 #define AF_ARGV_ALLOC 0x1 /* argv[] array allocated */ 93 #define AF_ARGS_ALLOCED 0x2 /* argument strings allocated */ 94 #define AI_ARGV(a, i) ((i) == 0 ? (a).argv[0] : (a).argv[(i) - (a).skip]) 95 #define AI_ARGC(a) ((a).argc_ - (a).skip) 96 97 /* Argument info. Used for $#, $* for shell, functions, includes, etc. */ 98 struct arg_info { 99 int flags; /* AF_* */ 100 char **argv; 101 int argc_; 102 int skip; /* first arg is argv[0], second is argv[1 + skip] */ 103 }; 104 105 /* 106 * activation record for function blocks 107 */ 108 struct block { 109 Area area; /* area to allocate things */ 110 /*struct arg_info argi;*/ 111 char **argv; 112 int argc; 113 struct table vars; /* local variables */ 114 struct table funs; /* local functions */ 115 #if 1 116 char * error; /* error handler */ 117 char * exit; /* exit handler */ 118 #else 119 Trap error, exit; 120 #endif 121 struct block *next; /* enclosing block */ 122 }; 123 124 /* 125 * Used by twalk() and tnext() routines. 126 */ 127 struct tstate { 128 int left; 129 struct tbl **next; 130 }; 131 132 133 EXTERN struct table taliases; /* tracked aliases */ 134 EXTERN struct table builtins; /* built-in commands */ 135 EXTERN struct table aliases; /* aliases */ 136 EXTERN struct table keywords; /* keywords */ 137 EXTERN struct table homedirs; /* homedir() cache */ 138 139 struct builtin { 140 const char *name; 141 int (*func) ARGS((char **)); 142 }; 143 144 /* these really are externs! Look in table.c for them */ 145 extern const struct builtin shbuiltins [], kshbuiltins []; 146 147 /* var spec values */ 148 #define V_NONE 0 149 #define V_PATH 1 150 #define V_IFS 2 151 #define V_SECONDS 3 152 #define V_OPTIND 4 153 #define V_MAIL 5 154 #define V_MAILPATH 6 155 #define V_MAILCHECK 7 156 #define V_RANDOM 8 157 #define V_HISTSIZE 9 158 #define V_HISTFILE 10 159 #define V_VISUAL 11 160 #define V_EDITOR 12 161 #define V_COLUMNS 13 162 #define V_POSIXLY_CORRECT 14 163 #define V_TMOUT 15 164 #define V_TMPDIR 16 165 166 /* values for set_prompt() */ 167 #define PS1 0 /* command */ 168 #define PS2 1 /* command continuation */ 169 170 EXTERN const char *path; /* PATH value */ 171 EXTERN const char *def_path; /* path to use if PATH not set */ 172 EXTERN char *tmpdir; /* TMPDIR value */ 173 EXTERN const char *prompt; 174 EXTERN int cur_prompt; /* PS1 or PS2 */ 175