1 /* $Id: table.h,v 1.3 1994/05/31 13:34:34 michael 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 */
11 void *root
; /* b-treed table items */
14 struct tbl
{ /* table item */
15 Tflag flag
; /* flags */
16 int type
; /* command type (see below), base (if INTEGER),
17 * or offset from val.s of value (if EXPORT) */
18 Area
*areap
; /* area to allocate from */
22 int (*f
) ARGS((int, char **, int)); /* int function */
23 struct op
*t
; /* "function" tree */
25 int index
; /* index for an array */
27 int field
; /* field with for -L/-R/-Z */
28 int errno_
; /* CEXEC/CTALIAS */
31 struct tbl
*array
; /* array values */
32 char *fpath
; /* temporary path to undef function */
34 char name
[4]; /* name -- variable length */
37 /* common flag bits */
38 #define ALLOC BIT(0) /* val.s has been allocated */
39 #define DEFINED BIT(1) /* is defined in block */
40 #define ISSET BIT(2) /* has value, vp->val.[si] */
41 #define EXPORT BIT(3) /* exported variable/function */
42 #define TRACE BIT(4) /* var: user flagged, func: execution tracing */
43 /* (start non-common flags at 8) */
44 /* flag bits used for variables */
45 #define SPECIAL BIT(8) /* PATH, IFS, SECONDS, etc */
46 #define INTEGER BIT(9) /* val.i contains integer value */
47 #define RDONLY BIT(10) /* read-only variable */
48 #define LOCAL BIT(11) /* for local typeset() */
49 #define ARRAY BIT(13) /* array */
50 #define IMPORT BIT(21) /* flag to typeset(): no arrays, must have = */
51 #define LOCAL_COPY BIT(22) /* with LOCAL - copy attrs from existing var */
52 #define EXPRINEVAL BIT(23) /* contents currently being evaluated */
53 #define EXPRLVALUE BIT(24) /* useable as lvalue (temp flag) */
54 /* flag bits used for builtins/aliases/keywords/functions */
55 #define KEEPASN BIT(8) /* keep command assignments (eg, var=x cmd) */
56 #define FINUSE BIT(9) /* function being executed */
57 #define FDELETE BIT(10) /* function deleted while it was executing */
58 #define SPEC_BI BIT(12) /* a POSIX special builtin */
59 #define REG_BI BIT(13) /* a POSIX regular builtin */
61 #define POSH_BUILTIN_KEEPASN BIT(8)
62 #define POSH_BUILTIN_POSIX_SPECIAL BIT(12)
63 #define POSH_BUILTIN_POSIX_REGULAR BIT(13)
65 #define POSH_BUILTIN_FALSE BIT(14)
66 #define POSH_BUILTIN_EXPORT BIT(15)
67 #define POSH_BUILTIN_READONLY BIT(16)
68 #define POSH_BUILTIN_SET BIT(17)
69 #define POSH_BUILTIN_EXIT BIT(18)
70 #define POSH_BUILTIN_RETURN BIT(19)
71 #define POSH_BUILTIN_BREAK BIT(20)
72 #define POSH_BUILTIN_CONTINUE BIT(21)
74 /* Attributes that can be set by the user (used to decide if an unset param
75 * should be repoted by set/typeset). Does not include ARRAY or LOCAL.
77 #define USERATTRIB (EXPORT|INTEGER|RDONLY)
80 #define CNONE 0 /* undefined */
81 #define CSHELL 1 /* built-in */
82 #define CFUNC 2 /* function */
83 #define CEXEC 4 /* executable command */
84 #define CALIAS 5 /* alias */
85 #define CKEYWD 6 /* keyword */
86 #define CTALIAS 7 /* tracked alias */
88 /* Flags for findcom()/comexec() */
89 #define FC_SPECBI BIT(0) /* special builtin */
90 #define FC_FUNC BIT(1) /* function builtin */
91 #define FC_REGBI BIT(2) /* regular builtin */
92 #define FC_UNREGBI BIT(3) /* un-regular builtin (!special,!regular) */
93 #define FC_BI (FC_SPECBI|FC_REGBI|FC_UNREGBI)
94 #define FC_PATH BIT(4) /* do path search */
95 #define FC_DEFPATH BIT(5) /* use default path in path search */
98 #define AF_ARGV_ALLOC 0x1 /* argv[] array allocated */
99 #define AF_ARGS_ALLOCED 0x2 /* argument strings allocated */
100 #define AI_ARGV(a, i) ((i) == 0 ? (a).argv[0] : (a).argv[(i) - (a).skip])
101 #define AI_ARGC(a) ((a).argc_ - (a).skip)
103 /* Argument info. Used for $#, $* for shell, functions, includes, etc. */
105 int flags
; /* AF_* */
108 int skip
; /* first arg is argv[0], second is argv[1 + skip] */
112 * activation record for function blocks
115 Area area
; /* area to allocate things */
116 /*struct arg_info argi;*/
119 int flags
; /* see BF_* */
120 struct table vars
; /* local variables */
121 struct table funs
; /* local functions */
122 LameGetopt getopts_state
;
124 char * error
; /* error handler */
125 char * exit
; /* exit handler */
129 struct block
*next
; /* enclosing block */
132 /* Values for struct block.flags */
133 #define BF_DOGETOPTS BIT(0) /* save/restore getopts state */
136 * Used by twalk() and tnext() routines.
144 EXTERN
struct table builtins
; /* built-in commands */
145 EXTERN
struct table aliases
; /* aliases */
146 EXTERN
struct table keywords
; /* keywords */
150 int (*func
) ARGS((int, char **, int));
154 /* these really are externs! Look in table.c for them */
155 extern const struct builtin shbuiltins
[];
157 /* var spec values */
165 #define V_MAILCHECK 7
168 #define V_HISTFILE 10
172 #define V_POSIXLY_CORRECT 14
177 /* values for set_prompt() */
178 #define PS1 0 /* command */
179 #define PS2 1 /* command continuation */
181 EXTERN
char *path
; /* copy of either PATH or def_path */
182 EXTERN
const char *def_path
; /* path to use if PATH not set */
183 EXTERN
char *tmpdir
; /* TMPDIR value */
184 EXTERN
const char *prompt
;
185 EXTERN
int cur_prompt
; /* PS1 or PS2 */
186 EXTERN
int current_lineno
; /* LINENO value */