Fetch Flex from Sourceforge.
[AROS-Contrib.git] / regina / types.h
blobdaba8f013d9ee26e7ba13738dd0b99e651b78dac
1 /*
2 * The Regina Rexx Interpreter
3 * Copyright (C) 1992-1994 Anders Christensen <anders@pvv.unit.no>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * $Id$
25 typedef struct varbox *variableptr ;
26 typedef const struct varbox *cvariableptr ;
27 typedef struct varbox {
28 variableptr next, prev, realbox, *index ;
29 struct strengtype *name, *value ;
30 int guard ;
31 num_descr *num ;
32 int flag ;
33 long hwired, valid ; /* FGC: at least valid may be too small for many
34 recursions with short instead of long.
35 27.09.98 (09/27/98). */
36 variableptr stem ;
37 } variable ;
39 /* typedef int bool ; */
41 typedef struct {
42 unsigned int lnum:1 ;
43 unsigned int rnum:1 ;
44 unsigned int lsvar:1 ;
45 unsigned int rsvar:1 ;
46 unsigned int lcvar:1 ;
47 unsigned int rcvar:1 ;
48 } compflags ;
50 typedef enum {
51 isUNKNOWN = 0,
52 isSTREAM = 1,
53 isSTEM = 2,
54 isLIFO = 3,
55 isFIFO = 4
56 } AddressWithType;
57 typedef struct {
58 unsigned int append:1 ;
59 unsigned int isinput:1 ;
60 unsigned int awt:3 ; /* overlay with AddressWithType */
61 } outputflags ; /* used by ADDRESS WITH resourceo */
63 typedef struct pparambox *paramboxptr ;
64 typedef const struct pparambox *cparamboxptr ;
65 typedef struct tnode *nodeptr ;
66 typedef const struct tnode *cnodeptr ;
68 typedef struct {
69 long sec ;
70 long usec ;
71 } rexx_time;
73 struct _tsd_t; /* If this won't work change "struct _tsd_t *" to "void *"
74 * below. This will require more changes. Let your compiler
75 * choose the places.
77 typedef struct tnode {
78 unsigned int type ;
79 int charnr, lineno ;
80 int called;
81 struct strengtype *name ;
82 rexx_time *now ;
83 struct tnode *p[4] ;
84 union {
85 streng *(*func)(struct _tsd_t *,cparamboxptr) ;
86 streng *strng ;
87 struct tnode *node ;
88 num_descr *number ;
89 compflags flags ;
90 variable *varbx ;
91 outputflags of ;
92 int nonansi ;
93 } u ;
94 struct tnode *next ;
95 unsigned long nodeindex ; /* for an effectiv relocation, never change! */
96 } treenode ;
98 typedef struct pparambox {
99 paramboxptr next ;
100 int dealloc ;
101 struct strengtype *value ;
102 } parambox ;
104 typedef struct lineboxx *lineboxptr ;
105 typedef const struct lineboxx *clineboxptr ;
106 typedef struct lineboxx {
107 lineboxptr next, prev ;
108 struct strengtype *line ;
109 int lineno ;
110 } linebox ;
112 typedef struct labelboxx *labelboxptr ;
113 typedef const struct labelboxx *clabelboxptr ;
114 typedef struct labelboxx {
115 labelboxptr next ;
116 unsigned long hash ;
117 nodeptr entry ;
118 } labelbox ;
120 typedef struct trap_type /* index is type of signal */
122 unsigned int on_off:1 ; /* true if trap is active/on */
123 /* unsigned int trapped:1 ; */ /* true if condition has been raised */
124 unsigned int def_act:1 ; /* true if default action is to ignore */
125 unsigned int delayed:1 ; /* true if trap is in delay mode */
126 unsigned int ignored:1 ; /* true if ignored when in delayed mode */
127 unsigned int invoked:1 ; /* true if invoked by SIGNAL */
128 streng *name ; /* label to transfer control to */
129 } trap ;
131 typedef struct sig_type
133 int type ;
134 streng *info ;
135 streng *descr ;
136 int invoke ; /* is true if invoked with SIGNAL */
137 int rc, subrc, lineno ;
138 } sigtype ;
140 typedef void (*signal_handler)(int);
142 typedef struct __regina_option
144 char *name ;
145 int offset ;
146 char *contains ;
147 } option_type ;
149 typedef struct { /* one for each redirection in environment */
150 streng *name; /* stemname or streamname if any */
151 outputflags flags;
152 streng *base; /* "number" if name is a stem */
153 streng *currname; /* name + ".number" if name is a stem */
154 int currnum; /* current number for a stem position */
155 /* or -1 if unknown */
156 int maxnum; /* maximum number for a stem position */
157 /* or -1 if unknown */
158 void *file; /* fileboxptr of the file with the */
159 /* above name or NULL. */
160 unsigned int SameAsOutput:1; /* locally used in shell.c */
161 unsigned int FileRedirected:1; /* locally used in shell.c */
162 char *tempname; /* locally used filename in shell.c */
163 int type; /* locally used source in shell.c */
164 int hdls[2]; /* locally used connection in shell.c */
165 } environpart;
167 typedef struct {
168 struct strengtype *name; /* stemname or streamname if any */
169 int subtype; /* SUBENVIR_... */
170 environpart input;
171 environpart output;
172 environpart error;
173 } environment;
175 typedef struct proclevelbox *proclevel ;
176 typedef const struct proclevelbox *cproclevel ;
177 typedef struct proclevelbox {
178 int numfuzz, currnumsize, numform ;
179 int mathtype ;
180 rexx_time time ;
181 proclevel prev, next ;
182 variableptr *vars ;
183 paramboxptr args ;
184 struct strengtype *environment, *prev_env ;
185 char tracestat, traceint, varflag ; /* MDW 30012002 */
186 sigtype *sig ;
187 trap *traps ;
188 jmp_buf *buf ; /* for use by longjmp */
189 union {
190 unsigned char flags[4] ;
191 } u ;
192 } proclevbox ;
194 typedef struct _ttree { /* bucket list of treenodes which allows ultra fast
195 * loading of instore macros.
197 struct _ttree *next;
198 unsigned long max; /* maximum number of elements in the bucket */
199 unsigned long num; /* current number of elements in the bucket */
200 unsigned long sum; /* sum of indices until element 0 */
201 treenode * elems;
202 } ttree; /* treenode type */
204 typedef struct { /* offsrcline: offset based source lines */
205 unsigned long length;
206 unsigned long offset;
207 /* That's all. You need the source string of the incore macro to create
208 * a real sourceline using this information.
210 } offsrcline;
212 typedef struct _otree { /* bucket list of offscrlines which allows ultra fast
213 * loading of instore macros.
215 struct _otree *next;
216 unsigned long max; /* maximum number of elements in the bucket */
217 unsigned long num; /* current number of elements in the bucket */
218 unsigned long sum; /* sum of indices until element 0 */
219 offsrcline * elems;
220 } otree; /* offsrcline type */
222 typedef struct { /* internal_parser_type is a structure containing data from a
223 * parsing operation.
225 lineboxptr first_source_line; /* Either this two values */
226 lineboxptr last_source_line ; /* exist or srclines below */
227 int tline; /* line number where error occured */
228 int tstart; /* column number where error occured */
229 int if_linenr; /* line number of last IF keyword */
230 int when_linenr; /* line number of last WHEN keyword */
231 labelboxptr first_label;
232 labelboxptr last_label;
233 unsigned long numlabels;
234 labelboxptr sort_labels ;
235 int result;
236 nodeptr root;
237 ttree * nodes;
238 otree * srclines; /* Either this two values exist */
239 const char * incore_source; /* or the two values above */
240 streng * kill; /* Probably the true source of incore_source in case
241 * of an "INTERPRET" instruction or other not user
242 * generated but interpreted strings; else NULL.
244 struct _tsd_t *TSD; /* needed during the parsing step */
245 } internal_parser_type;
247 typedef struct { /* extstring: external (instore) string */
248 unsigned long length;
249 /* and directly following the string's content */
250 } extstring;
252 typedef struct { /* external_parser_type: the instore macro in user space */
253 /* Never change from here until source including since it allows the
254 * reconstruction of the source if the machine type or Regina version
255 * doesn't match.
257 char Magic[32]; /* "Regina's Internal Format\r\n" filled with 0 */
258 #define MAGIC "Regina's Internal Format\r\n"
259 char ReginaVersion[64]; /* PARSE_VERSION_STRING */
261 /* The following structure allows the detection of different
262 * architectures. We don't want to try to decode something from
263 * a 64 bit big endian encoded parsing tree on an i586 for
264 * example.
266 union {
267 char ignore[4 * 256/8]; /* Allow 256 bit machines */
268 struct {
269 unsigned long one; /* value one */
270 unsigned long two; /* value two */
271 void * ptr3; /* value (void*)3, size may be different to unsigned */
272 void * ptr4; /* value (void*)4 */
273 } s;
274 } arch_detector;
276 unsigned long OverallSize; /* in byte of this structure and all dependencies */
278 unsigned long version; /* INSTORE_VERSION */
280 /* We describe the sourcelines first */
281 unsigned long NumberOfSourceLines;
282 unsigned long source;
283 /* Offset to table of source lines. Imagine a value of 1000 and
284 * 5 source lines (previous value). This structure has an address
285 * of 500 in the memory (what you get from malloc or something else).
286 * Then: The table has 5 entries at position 1500 in memory.
287 * Each table entry is an offsrcline structure. The source string is the
288 * instore[0] string of RexxStart or another source string.
291 unsigned long NumberOfTreeElements;
292 unsigned long TreeStart; /* Within 0 .. (NumberOfTreeElements-1) */
293 unsigned long tree;
294 /* Offset to table of nodes. Imagine a value of 2000 and
295 * 6 elements (NumberIfTreeElements). This structure has an address
296 * of 500 in the memory (what you get from malloc or something else).
297 * Then: The table has 6 treenodes at position 2500 in memory.
298 * Each table entry (treenode) must be relocated. Every nodeptr within a
299 * element is just an index within this table. If node->p[2] of one picked
300 * table entry is ((nodeptr) 4) then the address is calculated as follows:
301 * 500 + tree + (4*sizeof(treenode))
302 * This value should be assigned to node->p[2] to use the value in its
303 * normal manner.
304 * A NULL value is represented by (nodeptr) (unsigned) -1.
305 * Every string within a treenode is relocated by adding 500. Imagine a
306 * value of 3000 for node->name. Then an extstring structure is located
307 * at 3500 in memory which represents the string's content.
309 } external_parser_type;
311 typedef struct systeminfobox *sysinfo ;
312 typedef const struct systeminfobox *csysinfo ;
313 typedef struct systeminfobox {
314 struct strengtype *called_as;
315 struct strengtype *input_file ; /* must be 0-terminated without counting of the '\0' */
316 streng *environment ;
317 FILE *input_fp;
318 int tracing ;
319 int interactive ;
320 jmp_buf *panic ;
321 streng *result ;
322 proclevbox *currlevel0 ;
323 struct systeminfobox *previous ;
324 nodeptr *callstack ;
325 int cstackcnt, cstackmax ;
326 int hooks ;
327 int invoked ;
328 int trace_override;
329 internal_parser_type tree;
330 } sysinfobox ;
332 struct entrypt {
333 char *name ;
334 streng *(*addr)() ;
338 struct library {
339 streng *name ;
340 void *handle ;
341 short number ;
342 struct library_func *first ;
343 struct entrypt *funcs ;
344 struct library *next, *prev ;
347 #if !defined(DONT_TYPEDEF_PFN) && !defined(PFN_DEFINED)
348 typedef unsigned long (*PFN)() ;
349 #define PFN_DEFINED
350 #endif
352 struct library_func {
353 streng *name ;
354 PFN addr ;
355 unsigned long hash ;
356 struct library *lib ;
357 struct library_func *next, *prev ;
358 struct library_func *forw, *backw ;