1 /* $NetBSD: table.h,v 1.2 1997/01/12 19:12:21 tls Exp $ */
4 * generic hashed associative table for commands and variables.
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 */
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 */
21 int (*f
) ARGS((char **)); /* int function */
22 struct op
*t
; /* "function" tree */
24 int index
; /* index for an array */
26 int field
; /* field with for -L/-R/-Z */
27 int errno_
; /* CEXEC/CTALIAS */
30 struct tbl
*array
; /* array values */
31 char *fpath
; /* temporary path to undef function */
33 char name
[4]; /* name -- variable length */
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.
70 #define USERATTRIB (EXPORT|INTEGER|RDONLY|LJUST|RJUST|ZEROFIL\
71 |LCASEV|UCASEV_AL|INT_U|INT_L)
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 */
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 */
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)
97 /* Argument info. Used for $#, $* for shell, functions, includes, etc. */
102 int skip
; /* first arg is argv[0], second is argv[1 + skip] */
106 * activation record for function blocks
109 Area area
; /* area to allocate things */
110 /*struct arg_info argi;*/
113 int flags
; /* see BF_* */
114 struct table vars
; /* local variables */
115 struct table funs
; /* local functions */
116 Getopt getopts_state
;
118 char * error
; /* error handler */
119 char * exit
; /* exit handler */
123 struct block
*next
; /* enclosing block */
126 /* Values for struct block.flags */
127 #define BF_DOGETOPTS BIT(0) /* save/restore getopts state */
130 * Used by twalk() and tnext() routines.
138 EXTERN
struct table taliases
; /* tracked aliases */
139 EXTERN
struct table builtins
; /* built-in commands */
140 EXTERN
struct table aliases
; /* aliases */
141 EXTERN
struct table keywords
; /* keywords */
142 EXTERN
struct table homedirs
; /* homedir() cache */
146 int (*func
) ARGS((char **));
149 /* these really are externs! Look in table.c for them */
150 extern const struct builtin shbuiltins
[], kshbuiltins
[];
152 /* var spec values */
160 #define V_MAILCHECK 7
163 #define V_HISTFILE 10
167 #define V_POSIXLY_CORRECT 14
172 /* values for set_prompt() */
173 #define PS1 0 /* command */
174 #define PS2 1 /* command continuation */
176 EXTERN
char *path
; /* copy of either PATH or def_path */
177 EXTERN
const char *def_path
; /* path to use if PATH not set */
178 EXTERN
char *tmpdir
; /* TMPDIR value */
179 EXTERN
const char *prompt
;
180 EXTERN
int cur_prompt
; /* PS1 or PS2 */
181 EXTERN
int current_lineno
; /* LINENO value */