reenabled swaptest. quake should now load data and start on big endian architectures...
[AROS-Contrib.git] / gnu / abc-shell / table.h
blob0dcde6196ed8ff3547320f81aa79ab81e7a886d5
1 /* $Id$ */
3 /*
4 * generic hashed associative table for commands and variables.
5 */
8 struct table {
9 Area *areap; /* area to allocate entries */
10 short size, nfree; /* hash size (always 2^^n), free entries */
11 struct tbl **tbls; /* hashed 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 EXPORTV) */
18 Area *areap; /* area to allocate from */
19 union {
20 char *s; /* string */
21 long i; /* integer */
22 int (*f)(char **); /* 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 EXPORTV 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 LJUST BIT(14) /* left justify */
51 #define RJUST BIT(15) /* right justify */
52 #define ZEROFIL BIT(16) /* 0 filled if RJUSTIFY, strip 0s if LJUSTIFY */
53 #define LCASEV BIT(17) /* convert to lower case */
54 #define UCASEV_AL BIT(18)/* convert to upper case / autoload function */
55 #define INT_U BIT(19) /* unsigned integer */
56 #define INT_L BIT(20) /* long integer (no-op) */
57 #define IMPORTV BIT(21) /* flag to typeset(): no arrays, must have = */
58 #define LOCAL_COPY BIT(22) /* with LOCAL - copy attrs from existing var */
59 #define EXPRINEVAL BIT(23) /* contents currently being evaluated */
60 #define EXPRLVALUE BIT(24) /* useable as lvalue (temp flag) */
61 /* flag bits used for taliases/builtins/aliases/keywords/functions */
62 #define KEEPASN BIT(8) /* keep command assignments (eg, var=x cmd) */
63 #define FINUSE BIT(9) /* function being executed */
64 #define FDELETE BIT(10) /* function deleted while it was executing */
65 #define FKSH BIT(11) /* function defined with function x (vs x()) */
66 #define SPEC_BI BIT(12) /* a POSIX special builtin */
67 #define REG_BI BIT(13) /* a POSIX regular builtin */
68 /* Attributes that can be set by the user (used to decide if an unset param
69 * should be repoted by set/typeset). Does not include ARRAY or LOCAL.
71 #define USERATTRIB (EXPORTV|INTEGER|RDONLY|LJUST|RJUST|ZEROFIL\
72 |LCASEV|UCASEV_AL|INT_U|INT_L)
74 /* command types */
75 #define CNONE 0 /* undefined */
76 #define CSHELL 1 /* built-in */
77 #define CFUNC 2 /* function */
78 #define CEXEC 4 /* executable command */
79 #define CALIAS 5 /* alias */
80 #define CKEYWD 6 /* keyword */
81 #define CTALIAS 7 /* tracked alias */
83 /* Flags for findcom()/comexec() */
84 #define FC_SPECBI BIT(0) /* special builtin */
85 #define FC_FUNC BIT(1) /* function builtin */
86 #define FC_REGBI BIT(2) /* regular builtin */
87 #define FC_UNREGBI BIT(3) /* un-regular builtin (!special,!regular) */
88 #define FC_BI (FC_SPECBI|FC_REGBI|FC_UNREGBI)
89 #define FC_PATH BIT(4) /* do path search */
90 #define FC_DEFPATH BIT(5) /* use default path in path search */
93 #define AF_ARGV_ALLOC 0x1 /* argv[] array allocated */
94 #define AF_ARGS_ALLOCED 0x2 /* argument strings allocated */
95 #define AI_ARGV(a, i) ((i) == 0 ? (a).argv[0] : (a).argv[(i) - (a).skip])
96 #define AI_ARGC(a) ((a).argc_ - (a).skip)
98 /* Argument info. Used for $#, $* for shell, functions, includes, etc. */
99 struct arg_info {
100 int flags; /* AF_* */
101 char **argv;
102 int argc_;
103 int skip; /* first arg is argv[0], second is argv[1 + skip] */
107 * activation record for function blocks
109 struct block {
110 Area area; /* area to allocate things */
111 /*struct arg_info argi;*/
112 char **argv;
113 int argc;
114 int flags; /* see BF_* */
115 struct table vars; /* local variables */
116 struct table funs; /* local functions */
117 Getopt getopts_state;
118 #if 1
119 char * error; /* error handler */
120 char * exit; /* exit handler */
121 #else
122 Trap error, exit;
123 #endif
124 struct block *next; /* enclosing block */
127 /* Values for struct block.flags */
128 #define BF_DOGETOPTS BIT(0) /* save/restore getopts state */
131 * Used by ktwalk() and ktnext() routines.
133 struct tstate {
134 int left;
135 struct tbl **next;
139 EXTERN struct table *taliases; /* tracked aliases */
140 EXTERN struct table builtins; /* built-in commands */
141 EXTERN struct table *aliases; /* aliases */
142 EXTERN struct table keywords; /* keywords */
143 EXTERN struct table *homedirs; /* homedir() cache */
145 struct builtin {
146 const char *name;
147 int (*func)(char **);
150 /* these really are externs! Look in table.c for them */
151 extern const struct builtin shbuiltins [], kshbuiltins [];
153 /* var spec values */
154 #define V_NONE 0
155 #define V_PATH 1
156 #define V_IFS 2
157 #define V_SECONDS 3
158 #define V_OPTIND 4
159 #define V_RANDOM 8
160 #define V_HISTSIZE 9
161 #define V_HISTFILE 10
162 #define V_VISUAL 11
163 #define V_EDITOR 12
164 #define V_COLUMNS 13
165 #define V_POSIXLY_CORRECT 14
166 #define V_TMOUT 15
167 #define V_TMPDIR 16
168 #define V_LINENO 17
170 /* values for set_prompt() */
171 #define PS1 0 /* command */
172 #define PS2 1 /* command continuation */
174 EXTERN char *path; /* copy of either PATH or def_path */
175 EXTERN const char *def_path; /* path to use if PATH not set */
176 EXTERN char *tmpdir; /* TMPDIR value */
177 EXTERN const char *prompt;
178 EXTERN int cur_prompt; /* PS1 or PS2 */
179 EXTERN int current_lineno; /* LINENO value */