changelog for 0.9.1
[posh.git] / table.h
blob5b8f820a3213f3d5cd8c7e08762109adf64b4414
1 /* $Id: table.h,v 1.3 1994/05/31 13:34:34 michael Exp $ */
3 /*
4 * generic hashed associative table for commands and variables.
5 */
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 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 */
19 union {
20 char *s; /* string */
21 long i; /* integer */
22 int (*f) ARGS((int, char **, int)); /* int function */
23 struct op *t; /* "function" tree */
24 } val; /* value */
25 int index; /* index for an array */
26 union {
27 int field; /* field with for -L/-R/-Z */
28 int errno_; /* CEXEC/CTALIAS */
29 } u2;
30 union {
31 struct tbl *array; /* array values */
32 char *fpath; /* temporary path to undef function */
33 } u;
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)
79 /* command types */
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. */
104 struct arg_info {
105 int flags; /* AF_* */
106 char **argv;
107 int argc_;
108 int skip; /* first arg is argv[0], second is argv[1 + skip] */
112 * activation record for function blocks
114 struct block {
115 Area area; /* area to allocate things */
116 /*struct arg_info argi;*/
117 char **argv;
118 int argc;
119 int flags; /* see BF_* */
120 struct table vars; /* local variables */
121 struct table funs; /* local functions */
122 LameGetopt getopts_state;
123 #if 1
124 char * error; /* error handler */
125 char * exit; /* exit handler */
126 #else
127 Trap error, exit;
128 #endif
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.
138 struct tstate {
139 int left;
140 struct tbl **next;
144 EXTERN struct table builtins; /* built-in commands */
145 EXTERN struct table aliases; /* aliases */
146 EXTERN struct table keywords; /* keywords */
148 struct builtin {
149 const char *name;
150 int (*func) ARGS((int, char **, int));
151 int flags;
154 /* these really are externs! Look in table.c for them */
155 extern const struct builtin shbuiltins [];
157 /* var spec values */
158 #define V_NONE 0
159 #define V_PATH 1
160 #define V_IFS 2
161 #define V_SECONDS 3
162 #define V_OPTIND 4
163 #define V_MAIL 5
164 #define V_MAILPATH 6
165 #define V_MAILCHECK 7
166 #define V_RANDOM 8
167 #define V_HISTSIZE 9
168 #define V_HISTFILE 10
169 #define V_VISUAL 11
170 #define V_EDITOR 12
171 #define V_COLUMNS 13
172 #define V_POSIXLY_CORRECT 14
173 #define V_TMOUT 15
174 #define V_TMPDIR 16
175 #define V_LINENO 17
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 */