Reduce warnings (#2)
* Begin reducing the number of compiler warnings.
* Checkpoint reducing the compiler warnings.
* Eliminate yet more compiler warnings. Still so many to go.
* The continuing quest for no compiler warnings
* More prototypes in kernel.h, for the macros.
* More warnings, more worrisome signature mismatches
* Checkpoint
* No warnings in param.c or parse.c anymore.
* Checkpoint
* Eliminate compiler warnings in rule.c and scope.c.
* Address some warnings in sys.c.
* Continue cleaning up sys.c.
* Address compiler warnings in zlex.c.
* Elminate compiler warnings in table.c.
* Reduce warnings in zsys.c.
* Reduce warnings further in sys.c.
* Eliminate warnings in zsys.c.
Chris Pressey authored 1 year, 10 months ago
GitHub committed 1 year, 10 months ago
27 | 27 | #include "param.h" |
28 | 28 | #include "trace.h" |
29 | 29 | |
30 | /*PROTOTYPES*/ | |
31 | int parse(struct s_nt *); | |
32 | void pop_source(void); | |
33 | int source_list(struct s_content *, void *); | |
34 | ||
30 | 35 | struct s_content zz_ret_value = {0,0}; |
31 | 36 | |
32 | 37 | /*--------------------------------------------------------------------------*/ |
40 | 45 | |
41 | 46 | #define MAX_ARGV 100 |
42 | 47 | |
43 | action(rule,stack,ret) | |
44 | struct s_rule *rule; | |
45 | struct s_content stack[],*ret; | |
48 | void action(struct s_rule *rule, struct s_content stack[], struct s_content *ret) | |
46 | 49 | { |
47 | 50 | struct s_content cnt,old_zz_ret_value; |
48 | 51 | struct s_content argv [MAX_ARGV]; /* allocation issue */ |
197 | 200 | push_param_scope(); |
198 | 201 | for(i=0;i<argc;i++) |
199 | 202 | set_param(namev[i],&argv[i]); |
200 | source_list(&rule->action); | |
203 | source_list(&rule->action, NULL); | |
201 | 204 | if(!root_nt) root_nt=find_nt("root"); |
202 | 205 | if(zz_trace_mask()&TRACE_ZZACTION) |
203 | 206 | { |
288 | 291 | |
289 | 292 | } |
290 | 293 | |
291 | fprint_action(action) | |
294 | void fprint_action(action) | |
292 | 295 | struct content *action; |
293 | 296 | { |
294 | 297 |
18 | 18 | |
19 | 19 | |
20 | 20 | #include <stdint.h> |
21 | #include <string.h> | |
22 | ||
21 | 23 | #include "zlex.h" |
22 | 24 | #include "rule.h" |
23 | 25 | #include "avl.h" |
24 | 26 | #include "err.h" |
27 | #include "printz.h" | |
28 | ||
29 | /*PROTOTYPES*/ | |
30 | int do_dumpnet(struct s_nt *); | |
25 | 31 | |
26 | 32 | static struct s_dot *hd_dot=0; |
27 | 33 | |
35 | 41 | |
36 | 42 | /*----------------------------------------------------------------------------*/ |
37 | 43 | |
38 | static dump_tran(string) | |
39 | char *string; | |
44 | static void dump_tran(char *string) | |
40 | 45 | { |
41 | 46 | int i,tab; |
42 | 47 | char buffer[256]; |
150 | 155 | |
151 | 156 | /*----------------------------------------------------------------------------*/ |
152 | 157 | |
153 | static dump_rule(rule) | |
154 | struct s_rule *rule; | |
158 | static void dump_rule(struct s_rule *rule) | |
155 | 159 | { |
156 | 160 | char buffer[256]; |
157 | 161 | printz(buffer,"reduce: %r", rule); |
160 | 164 | |
161 | 165 | /*----------------------------------------------------------------------------*/ |
162 | 166 | |
163 | dumpnet(ntname) | |
164 | char *ntname; | |
167 | void dumpnet(char *ntname) | |
165 | 168 | { |
166 | 169 | int i; |
167 | 170 | struct s_nt *nt; |
177 | 180 | |
178 | 181 | /*----------------------------------------------------------------------------*/ |
179 | 182 | |
180 | do_dumpnet(nt) | |
181 | struct s_nt *nt; | |
183 | int do_dumpnet(struct s_nt *nt) | |
182 | 184 | { |
183 | 185 | int i; |
184 | 186 | struct s_dot *dot; |
29 | 29 | |
30 | 30 | #include <stdio.h> |
31 | 31 | #include <stdint.h> |
32 | #include <stdlib.h> | |
32 | 33 | #include "err.h" |
33 | 34 | #include "zlex.h" |
34 | 35 | #include "printz.h" |
40 | 41 | #else |
41 | 42 | #include <varargs.h> |
42 | 43 | #endif |
44 | ||
45 | /*PROTOTYPES*/ | |
46 | void get_source_file(char *); | |
47 | void error_head(int); | |
48 | void error_tail(void); | |
49 | void error_tail_1(void); | |
50 | void change_filetype(char *fullfilename,char *filetype); | |
51 | void fprint_source_position(FILE *,int); | |
52 | void fprint_param(FILE *); | |
53 | int do_printz(FILE *chanout, FILE *chanout_1, | |
54 | char *stringout, char *fmt, va_list *ap); | |
55 | void check_error_max_number(void); | |
43 | 56 | |
44 | 57 | char err_file[256] = "LOG.ERR"; |
45 | 58 | |
59 | 72 | |
60 | 73 | /*---------------------------------------------------------------------------*/ |
61 | 74 | |
62 | open_err_file() | |
75 | void open_err_file(void) | |
63 | 76 | { |
64 | 77 | char filename[132]; |
65 | 78 | static int err_file_flag=0; |
180 | 193 | |
181 | 194 | /*---------------------------------------------------------------------------*/ |
182 | 195 | |
183 | error_head(type) | |
196 | void error_head(type) | |
184 | 197 | int type; |
185 | 198 | { |
186 | 199 | open_err_file(); |
234 | 247 | |
235 | 248 | /*---------------------------------------------------------------------------*/ |
236 | 249 | |
237 | error_tail() | |
250 | void error_tail(void) | |
238 | 251 | { |
239 | 252 | fprintz(stderr," ****\n"); |
240 | 253 | if(err_chan) fprintz(err_chan," ****\n"); |
251 | 264 | |
252 | 265 | /*---------------------------------------------------------------------------*/ |
253 | 266 | |
254 | error_tail_1() | |
267 | void error_tail_1(void) | |
255 | 268 | { |
256 | 269 | fprintz(stderr," ****\n"); |
257 | 270 | if(err_chan) fprintz(err_chan," ****\n"); |
268 | 281 | |
269 | 282 | /*---------------------------------------------------------------------------*/ |
270 | 283 | |
271 | error_token(cnt) | |
272 | struct s_content *cnt; | |
284 | void error_token(struct s_content *cnt) | |
273 | 285 | { |
274 | 286 | fprintz(stderr,"%z ",cnt); |
275 | 287 | if(err_chan) fprintz(err_chan,"%z ",cnt); |
279 | 291 | /*---------------------------------------------------------------------------*/ |
280 | 292 | |
281 | 293 | |
282 | print_error_count() | |
294 | void print_error_count(void) | |
283 | 295 | { |
284 | 296 | if(total_error_n) |
285 | 297 | { |
298 | 310 | /*---------------------------------------------------------------------------*/ |
299 | 311 | |
300 | 312 | |
301 | get_error_number() | |
313 | int get_error_number(void) | |
302 | 314 | { |
303 | 315 | return lexical_error_n+error_n+fatal_error_n+unknown_error_n+internal_error_n; |
304 | 316 | } |
305 | 317 | |
306 | 318 | /*---------------------------------------------------------------------------*/ |
307 | 319 | |
308 | syntax_error(info_routine) | |
309 | int (*info_routine)(); | |
320 | void syntax_error(int (*info_routine)()) | |
310 | 321 | { |
311 | 322 | open_err_file(); |
312 | 323 | fprintz(stderr,"+ **** SYNTAX ERROR ****\n"); |
327 | 338 | |
328 | 339 | /*---------------------------------------------------------------------------*/ |
329 | 340 | |
330 | check_error_max_number() | |
341 | void check_error_max_number(void) | |
331 | 342 | { |
332 | 343 | static int count=0; |
333 | 344 | char *s; |
343 | 354 | } |
344 | 355 | } |
345 | 356 | |
346 | set_max_error_n(argc,argv,ret) | |
347 | int argc; | |
348 | struct s_content argv[],*ret; | |
357 | int set_max_error_n(int argc, struct s_content argv[], struct s_content *ret) | |
349 | 358 | { |
350 | 359 | int n; |
351 | if(argc!=1) return; | |
360 | if(argc!=1) return -1; | |
352 | 361 | n=(int)s_content_value(argv[0]); |
353 | 362 | max_error_n=n; |
363 | return 0; | |
354 | 364 | } |
355 | 365 | |
356 | 366 | int zz_get_error_number() |
24 | 24 | |
25 | 25 | #include <stdint.h> |
26 | 26 | #include "zlex.h" |
27 | #include "rule.h" | |
28 | ||
29 | /*PROTOTYPES*/ | |
30 | void open_rule(char *); | |
31 | void setaction_exeproc(int (*proc)(), struct s_tag *tag); | |
32 | void setaction_exesproc(int (*sproc)(), struct s_tag *tag); | |
33 | void setaction_pass(void); | |
34 | void insert_rule(char *, struct s_rule *); | |
35 | void init_zlex(void); | |
36 | void append_t_bead(struct s_content *cnt); | |
37 | void append_nt_bead(char *ntname, char *beadname); | |
27 | 38 | |
28 | 39 | /*-------------------------------------------------------------------------*/ |
29 | 40 | |
30 | zz_bind_open(s) | |
31 | const char *s; | |
41 | int zz_bind_open(const char *s) | |
32 | 42 | { |
33 | 43 | if(!init_zlex_done) |
34 | 44 | init_zlex(); |
38 | 48 | |
39 | 49 | /*-------------------------------------------------------------------------*/ |
40 | 50 | |
41 | zz_bind_match(s) | |
42 | const char *s; | |
51 | int zz_bind_match(const char *s) | |
43 | 52 | { |
44 | 53 | append_nt_bead(zlex_strsave(s),0); |
45 | 54 | return 1; |
47 | 56 | |
48 | 57 | /*-------------------------------------------------------------------------*/ |
49 | 58 | |
50 | zz_bind_keyword(s) | |
51 | const char *s; | |
59 | int zz_bind_keyword(const char *s) | |
52 | 60 | { |
53 | 61 | struct s_content cnt; |
54 | 62 | cnt.tag=tag_qstring; |
59 | 67 | |
60 | 68 | /*-------------------------------------------------------------------------*/ |
61 | 69 | |
62 | zz_bind_close() | |
70 | int zz_bind_close(void) | |
63 | 71 | { |
64 | 72 | insert_rule(0,close_rule()); |
65 | 73 | return 1; |
67 | 75 | |
68 | 76 | /*-------------------------------------------------------------------------*/ |
69 | 77 | |
70 | zz_bind_call(proc) | |
71 | int (*proc)(); | |
78 | int zz_bind_call(int (*proc)()) | |
72 | 79 | { |
73 | 80 | setaction_exesproc(proc,tag_none); |
74 | 81 | return 1; |
76 | 83 | |
77 | 84 | /*-------------------------------------------------------------------------*/ |
78 | 85 | |
79 | zz_bind_call_fun(proc,tag) | |
80 | int (*proc)(); | |
81 | const char *tag; | |
86 | int zz_bind_call_fun(int (*proc)(), const char *tag) | |
82 | 87 | { |
83 | 88 | setaction_exesproc(proc,find_tag(tag)); |
84 | 89 | return 1; |
86 | 91 | |
87 | 92 | /*-------------------------------------------------------------------------*/ |
88 | 93 | |
89 | zz_bind_call_fun_tag(proc,tag) | |
90 | int (*proc)(); | |
91 | struct s_tag *tag; | |
94 | int zz_bind_call_fun_tag(int (*proc)(), struct s_tag *tag) | |
92 | 95 | { |
93 | 96 | setaction_exesproc(proc,tag); |
94 | 97 | return 1; |
96 | 99 | |
97 | 100 | /*-------------------------------------------------------------------------*/ |
98 | 101 | |
99 | zz_bind_call_exe_proc(proc,tag) | |
100 | int (*proc)(); | |
101 | const char *tag; | |
102 | int zz_bind_call_exe_proc(int (*proc)(), const char *tag) | |
102 | 103 | { |
103 | 104 | setaction_exeproc(proc,find_tag(tag)); |
104 | 105 | return 1; |
106 | 107 | |
107 | 108 | /*-------------------------------------------------------------------------*/ |
108 | 109 | |
109 | zz_bind_call_exe_no_tag(proc) | |
110 | int (*proc)(); | |
110 | int zz_bind_call_exe_no_tag(int (*proc)()) | |
111 | 111 | { |
112 | 112 | setaction_exeproc(proc,0); |
113 | 113 | return 1; |
115 | 115 | |
116 | 116 | /*-------------------------------------------------------------------------*/ |
117 | 117 | |
118 | zz_bind_pass() | |
118 | int zz_bind_pass(void) | |
119 | 119 | { |
120 | 120 | setaction_pass(); |
121 | 121 | return 1; |
23 | 23 | #include "sys.h" |
24 | 24 | |
25 | 25 | |
26 | kernel() | |
26 | void kernel(void) | |
27 | 27 | { |
28 | 28 | struct s_tag *tag; |
29 | 29 | extern int max_error_n; |
18 | 18 | |
19 | 19 | #ifndef __KERNEL_H__ |
20 | 20 | #define __KERNEL_H__ |
21 | ||
22 | /*PROTOTYPES*/ | |
23 | void init_zlex(void); | |
24 | void setaction_exesproc(int (*sproc)(), struct s_tag *tag); | |
25 | void setaction_exeproc(int (*proc)(), struct s_tag *tag); | |
26 | void setaction_pass(void); | |
27 | void setaction_merge(); | |
28 | void setaction_merge_all(); | |
29 | void setaction_list(); | |
30 | void setaction_append(); | |
31 | void setaction_return(struct s_content *, char *); | |
32 | void insert_rule(); /* actual signature is: void insert_rule(char *, struct s_rule *); */ | |
33 | void append_t_bead(struct s_content *); | |
34 | void append_nt_bead(char *, char *); | |
35 | void set_recovery(char *, char *); | |
36 | void set_nt_prompt(char *, const char *); | |
37 | void open_rule(char *); | |
38 | struct s_rule *close_rule(void); | |
21 | 39 | |
22 | 40 | #define OPEN(S) {INIT_ZLEX open_rule(zlex_strsave( #S ));} |
23 | 41 | #define GSB(S) append_nt_bead(zlex_strsave( #S),0); |
17 | 17 | */ |
18 | 18 | |
19 | 19 | #include <stdint.h> |
20 | #include <stdlib.h> | |
21 | #include <string.h> | |
22 | ||
20 | 23 | #include "rule.h" |
21 | 24 | |
22 | 25 | |
77 | 80 | /*----------------------------------------------------------------*/ |
78 | 81 | |
79 | 82 | |
80 | lazy_rec(dots,len) | |
83 | void lazy_rec(dots,len) | |
81 | 84 | struct s_dot *dots[]; |
82 | 85 | int len; |
83 | 86 | { |
94 | 97 | /*----------------------------------------------------------------*/ |
95 | 98 | |
96 | 99 | |
97 | print_lazy_report() | |
100 | int print_lazy_report() | |
98 | 101 | { |
99 | 102 | struct s_l_node *node; |
100 | 103 | int k,i,count,flag; |
124 | 127 | node=node->next; |
125 | 128 | } |
126 | 129 | } |
130 | return 0; | |
127 | 131 | } |
128 | 132 | static char sccsid[]="@(#)lazy.c 6.1\t9/7/94"; |
129 | 133 | static char rcsid[] = "$Id: lazy.c,v 1.3 2002/01/11 11:52:02 brooks Exp $ "; |
29 | 29 | |
30 | 30 | #include <stdio.h> |
31 | 31 | #include <stdint.h> |
32 | #include <stdlib.h> | |
33 | #include <string.h> | |
34 | ||
32 | 35 | #include "zlex.h" |
33 | 36 | #include "list.h" |
34 | 37 | #include "mem.h" |
17 | 17 | */ |
18 | 18 | |
19 | 19 | #include <stdint.h> |
20 | #include <stdlib.h> | |
21 | #include <string.h> | |
22 | ||
20 | 23 | #include "zlex.h" |
21 | 24 | #include "rule.h" |
22 | 25 | #include "err.h" |
63 | 66 | |
64 | 67 | /*------------------------------------------------------------------------*/ |
65 | 68 | |
66 | static free_param_pair(pair) | |
67 | struct s_param_pair *pair; | |
69 | static void free_param_pair(struct s_param_pair *pair) | |
68 | 70 | { |
69 | 71 | pair->next=param_first_free; |
70 | 72 | pair->name=0; |
74 | 76 | |
75 | 77 | /*------------------------------------------------------------------------*/ |
76 | 78 | |
77 | push_param_scope() | |
79 | int push_param_scope(void) | |
78 | 80 | { |
79 | 81 | if(param_level>=PARAM_SCOPE_STACK_SIZE-1) |
80 | 82 | zz_error(ERROR,"too many Zz variable scopes"); |
82 | 84 | { |
83 | 85 | param_scope_stack[param_level++] = 0; |
84 | 86 | } |
85 | } | |
86 | ||
87 | /*------------------------------------------------------------------------*/ | |
88 | ||
89 | pop_param_scope() | |
87 | return 0; | |
88 | } | |
89 | ||
90 | /*------------------------------------------------------------------------*/ | |
91 | ||
92 | int pop_param_scope(void) | |
90 | 93 | { |
91 | 94 | struct s_param_pair *pair,*tmp; |
92 | 95 | if(param_level>0) |
102 | 105 | free_param_pair(tmp); |
103 | 106 | } |
104 | 107 | } |
108 | return 0; | |
105 | 109 | } |
106 | 110 | |
107 | 111 | /*------------------------------------------------------------------------*/ |
151 | 155 | |
152 | 156 | /*------------------------------------------------------------------------*/ |
153 | 157 | |
154 | gset_param(char *name, struct s_content *cnt) | |
158 | int gset_param(char *name, struct s_content *cnt) | |
155 | 159 | { |
156 | 160 | struct s_param_pair *pair; |
157 | 161 | struct s_content *old; |
183 | 187 | |
184 | 188 | /*------------------------------------------------------------------------*/ |
185 | 189 | |
186 | gnset_param(name,cnt,delta) | |
190 | int gnset_param(name,cnt,delta) | |
187 | 191 | char *name; |
188 | 192 | struct s_content *cnt; |
189 | 193 | int delta; |
222 | 226 | |
223 | 227 | /*------------------------------------------------------------------------*/ |
224 | 228 | |
225 | unset_param(name) | |
226 | char *name; | |
229 | int unset_param(char *name) | |
227 | 230 | { |
228 | 231 | struct s_param_pair *pair,**ptr; |
229 | 232 | struct s_content *old; |
230 | 233 | int i; |
231 | 234 | if(strcmp(name,"$")==0) return 1; |
232 | 235 | i=param_level-1; |
233 | if(i<0) return; | |
236 | if(i<0) return 0; | |
234 | 237 | ptr= &(param_scope_stack[i]); |
235 | 238 | while(*ptr && (*ptr)->name!=name) ptr= &((*ptr)->next); |
236 | 239 | if(*ptr) |
241 | 244 | (*pair->cnt.tag->param_off)(&(pair->cnt),pair->name); |
242 | 245 | free_param_pair(pair); |
243 | 246 | } |
247 | return 0; | |
244 | 248 | } |
245 | 249 | |
246 | 250 | |
254 | 258 | returns 1 if local param found |
255 | 259 | returns 2 if global param found |
256 | 260 | */ |
257 | param_substitute(token,paramname) | |
258 | struct s_content *token; | |
259 | char **paramname; | |
261 | int param_substitute(struct s_content *token, char **paramname) | |
260 | 262 | { |
261 | 263 | struct s_param_pair *pair; |
262 | 264 | struct s_content *cnt; |
284 | 286 | |
285 | 287 | /*------------------------------------------------------------------------*/ |
286 | 288 | |
287 | local_param_substitute(token,paramname) | |
288 | struct s_content *token; | |
289 | struct s_content *paramname; | |
289 | int local_param_substitute(struct s_content *token, struct s_content *paramname) | |
290 | 290 | { |
291 | 291 | struct s_param_pair *pair; |
292 | 292 | struct s_content *cnt; |
293 | 293 | char *name; |
294 | 294 | int i; |
295 | 295 | paramname->tag = tag_none; |
296 | if(token->tag!=tag_ident) return; | |
296 | if(token->tag!=tag_ident) return 0; | |
297 | 297 | name = (char*)s_content_value(*token); |
298 | 298 | if(param_level>0) |
299 | 299 | { |
306 | 306 | s_content_value(*paramname) = (long)name; /*ep*/ |
307 | 307 | cnt = &(pair->cnt); |
308 | 308 | *token = *cnt; |
309 | return; | |
310 | 309 | } |
311 | 310 | } |
312 | } | |
313 | ||
314 | /*------------------------------------------------------------------------*/ | |
315 | ||
316 | s_param_filter(argc,argv,ret) | |
317 | int argc; | |
318 | struct s_content argv[],*ret; | |
311 | return 0; | |
312 | } | |
313 | ||
314 | /*------------------------------------------------------------------------*/ | |
315 | ||
316 | int s_param_filter(int argc, struct s_content argv[], struct s_content *ret) | |
319 | 317 | { |
320 | 318 | struct s_param_pair *pair; |
321 | 319 | int i,lev; |
339 | 337 | /*------------------------------------------------------------------------*/ |
340 | 338 | |
341 | 339 | |
342 | list_params() | |
340 | int list_params(void) | |
343 | 341 | { |
344 | 342 | struct s_param_pair *pair; |
345 | 343 | int i,lev; |
371 | 369 | |
372 | 370 | /*---------------------------------------------------------------------------*/ |
373 | 371 | |
374 | show_param_memory() | |
372 | int show_param_memory(void) | |
375 | 373 | { |
376 | 374 | PRINTMEM("param",param_mem) |
375 | return 0; | |
377 | 376 | } |
378 | 377 | |
379 | 378 |
18 | 18 | |
19 | 19 | #include <stdio.h> |
20 | 20 | #include <stdint.h> |
21 | #include <stdlib.h> | |
22 | #include <string.h> | |
23 | ||
21 | 24 | #include "zz.h" |
22 | 25 | #include "zlex.h" |
23 | 26 | #include "rule.h" |
25 | 28 | #include "avl.h" |
26 | 29 | #include "trace.h" |
27 | 30 | |
31 | /*PROTOTYPES*/ | |
32 | int next_token(struct s_content *); | |
33 | void syntax_error(int (*info_routine)()); | |
34 | void action(struct s_rule *rule, struct s_content stack[], struct s_content *ret); | |
35 | int get_error_number(void); | |
36 | int errprintf(char *fmt,...); | |
37 | int param_substitute(struct s_content *token,char **paramname); | |
38 | /*FORWARD*/ | |
39 | int check_reduce(int, struct s_rule *); | |
40 | void lr_reduce(struct s_rule *, int, struct s_content *); | |
41 | void dump_stack(void); | |
28 | 42 | |
29 | 43 | /*---------------------------------------------------------------------------*/ |
30 | 44 | |
31 | 45 | extern struct s_nt *nt_any,*nt_param,*nt_gparam; |
32 | static char *first_prompt=""; | |
33 | static max_dot=0,tot_dot=0,ndot=0,max_sp=0; | |
46 | static const char *first_prompt=""; | |
47 | static int max_dot=0,tot_dot=0,ndot=0,max_sp=0; | |
34 | 48 | static int reduction_count=0; |
35 | 49 | #define EXPECTED_SIZE 30 |
36 | 50 | static struct s_content expected[EXPECTED_SIZE]; |
178 | 192 | static long int setid=0; |
179 | 193 | |
180 | 194 | /* calcola la chiusura del work set */ |
181 | make_closure() | |
195 | void make_closure(void) | |
182 | 196 | { |
183 | 197 | void lr_add_nt(); |
184 | 198 | int i,a=cur_lrenv.a,b=cur_lrenv.b; |
221 | 235 | |
222 | 236 | */ |
223 | 237 | |
224 | try_shift(set_index) | |
225 | int set_index; | |
238 | void try_shift(int set_index) | |
226 | 239 | { |
227 | 240 | struct s_term_tran *ttran; |
228 | 241 | struct s_nt_tran *nttran; |
288 | 301 | /*----------------------------------------------------------------------*/ |
289 | 302 | |
290 | 303 | /* ritorna 1 se lo shift e' ammissibile */ |
291 | check_shift(set_index) | |
292 | int set_index; | |
304 | int check_shift(int set_index) | |
293 | 305 | { |
294 | 306 | struct s_term_tran *ttran; |
295 | 307 | struct s_nt_tran *nttran; |
319 | 331 | |
320 | 332 | */ |
321 | 333 | |
322 | try_reduce(set_index,rule) | |
323 | int set_index; | |
324 | struct s_rule *rule; | |
334 | int try_reduce(int set_index, struct s_rule *rule) | |
325 | 335 | { |
326 | 336 | LRENV oldenv; |
327 | 337 | int oldset,i,j,k,a,b,curset,ret,length,base; |
383 | 393 | |
384 | 394 | /*----------------------------------------------------------------------*/ |
385 | 395 | |
386 | check_reduce(set_index,rule) | |
387 | int set_index; | |
388 | struct s_rule *rule; | |
396 | int check_reduce(int set_index, struct s_rule *rule) | |
389 | 397 | { |
390 | 398 | int oldset,i,j,k,a,b,curset,ret,length,base; |
391 | 399 | struct s_nt *nt; |
434 | 442 | /*----------------------------------------------------------------------*/ |
435 | 443 | |
436 | 444 | |
437 | lr_loop(main_nt) | |
438 | struct s_nt *main_nt; | |
445 | int lr_loop(struct s_nt *main_nt) | |
439 | 446 | { |
440 | 447 | struct s_content ret_token,shift_token; |
441 | 448 | int i,j,dst,a,b,newa,newb,olda,oldb,is_param; |
552 | 559 | |
553 | 560 | /*----------------------------------------------------------------------*/ |
554 | 561 | |
555 | lr_reduce(rule,set_index,ret_token) | |
556 | struct s_rule *rule; | |
557 | int set_index; | |
558 | struct s_content *ret_token; | |
562 | void lr_reduce(struct s_rule *rule, int set_index, struct s_content *ret_token) | |
559 | 563 | { |
560 | 564 | int i,length; |
561 | 565 | reduction_count++; |
577 | 581 | |
578 | 582 | /*----------------------------------------------------------------------*/ |
579 | 583 | |
580 | static add_expected(tag,value) | |
584 | static int add_expected(tag,value) | |
581 | 585 | struct s_tag *tag; |
582 | 586 | long value; |
583 | 587 | { |
607 | 611 | |
608 | 612 | /*----------------------------------------------------------------------*/ |
609 | 613 | |
610 | static compute_expected_from_reduction(set_index,rule) | |
614 | static int compute_expected_from_reduction(set_index,rule) | |
611 | 615 | int set_index; |
612 | 616 | struct s_rule *rule; |
613 | 617 | { |
674 | 678 | |
675 | 679 | /*----------------------------------------------------------------------*/ |
676 | 680 | |
677 | static void print_expected() | |
681 | static int print_expected() | |
678 | 682 | { |
679 | 683 | char buffer[256]; |
680 | 684 | int i,j,k; |
707 | 711 | |
708 | 712 | if(j>0) errprintf("| %s\n",buffer); |
709 | 713 | } |
710 | } | |
711 | ||
712 | /*----------------------------------------------------------------------*/ | |
713 | ||
714 | recovery() | |
714 | return 0; | |
715 | } | |
716 | ||
717 | /*----------------------------------------------------------------------*/ | |
718 | ||
719 | int recovery(void) | |
715 | 720 | { |
716 | 721 | struct {struct s_content cnt; struct s_nt *nt;int lrset;} |
717 | 722 | tmpterm,termlist[1000]; |
820 | 825 | Associa una lista di termini di recovery ad un non-terminale |
821 | 826 | |
822 | 827 | */ |
823 | set_recovery(ntname,termlist) | |
824 | char *ntname,*termlist; | |
828 | void set_recovery(char *ntname, char *termlist) | |
825 | 829 | { |
826 | 830 | struct s_nt *nt; |
827 | 831 | int i; |
888 | 892 | |
889 | 893 | */ |
890 | 894 | |
891 | set_nt_prompt(ntname,prompt) | |
892 | char *ntname,*prompt; | |
895 | void set_nt_prompt(char *ntname, const char *prompt) | |
893 | 896 | { |
894 | 897 | struct s_nt *nt; |
895 | 898 | if(ntname) |
905 | 908 | /*----------------------------------------------------------------------*/ |
906 | 909 | |
907 | 910 | |
908 | dump_dot(dot,off) | |
909 | struct s_dot *dot; | |
910 | int off; | |
911 | void dump_dot(struct s_dot *dot, int off) | |
911 | 912 | { |
912 | 913 | int length; |
913 | 914 | struct s_term_tran *ttran; |
929 | 930 | |
930 | 931 | /*----------------------------------------------------------------------*/ |
931 | 932 | |
932 | dump_stack() | |
933 | void dump_stack(void) | |
933 | 934 | { |
934 | 935 | #define IMAGE_SIZE 10 |
935 | 936 | int image[IMAGE_SIZE],image_n; |
957 | 958 | |
958 | 959 | /*----------------------------------------------------------------------*/ |
959 | 960 | |
960 | dump_set(set_index) | |
961 | int set_index; | |
961 | void dump_set(int set_index) | |
962 | 962 | { |
963 | 963 | int i,a,b; |
964 | 964 | a=lrstack[set_index].a; |
974 | 974 | |
975 | 975 | /*----------------------------------------------------------------------*/ |
976 | 976 | |
977 | write_dot_stat() | |
977 | void write_dot_stat(void) | |
978 | 978 | { |
979 | 979 | printf("dot n.: max=%d, mean=%d\n",max_dot,ndot==0?0:tot_dot/ndot); |
980 | 980 | printf("lr sp: max=%d\n",max_sp); |
982 | 982 | |
983 | 983 | /*------------------------------------------------------------------*/ |
984 | 984 | |
985 | print_report() | |
985 | void print_report(void) | |
986 | 986 | { |
987 | 987 | static int old_reduction_count=0; |
988 | 988 | printf("%d reductions done (%+d)\n", |
993 | 993 | |
994 | 994 | /*------------------------------------------------------------------*/ |
995 | 995 | |
996 | fprint_param(chan) | |
996 | void fprint_param(chan) | |
997 | 997 | FILE *chan; |
998 | 998 | { |
999 | 999 | if(cur_token.is_param) |
1007 | 1007 | |
1008 | 1008 | /*------------------------------------------------------------------*/ |
1009 | 1009 | |
1010 | parse(start_nt) | |
1011 | struct s_nt *start_nt; | |
1010 | int parse(struct s_nt *start_nt) | |
1012 | 1011 | { |
1013 | 1012 | int ret; |
1014 | 1013 | struct s_cur_token old_token; |
1035 | 1034 | if(ret>0) break; |
1036 | 1035 | if(ret==0) syntax_error(print_expected); |
1037 | 1036 | if(!recovery()) |
1038 | { | |
1039 | zz_error(FATAL_ERROR,"unrecoverable error"); | |
1040 | break; | |
1041 | } | |
1037 | { | |
1038 | zz_error(FATAL_ERROR,"unrecoverable error"); | |
1039 | break; | |
1040 | } | |
1042 | 1041 | } |
1043 | 1042 | |
1044 | 1043 | cur_lrenv = old_lrenv; |
56 | 56 | |
57 | 57 | #include <stdio.h> |
58 | 58 | #include <stdint.h> |
59 | #include <stdlib.h> | |
60 | #include <string.h> | |
61 | ||
59 | 62 | #include "avl.h" |
60 | 63 | #include "rule.h" |
61 | 64 | #include "list.h" |
65 | 68 | #include "table.h" |
66 | 69 | #include "printz.h" |
67 | 70 | |
71 | /*PROTOTYPES*/ | |
72 | int param_substitute(); /* signature int param_substitute(struct s_content *token,char **paramname) in param.h is incompatible */ | |
73 | int parse(struct s_nt *); | |
74 | int source_list(); /* signature int source_list(struct s_content *, void *); is incompatible */ | |
75 | void pop_source(void); | |
76 | ||
68 | 77 | static int nt_mem=0; |
69 | 78 | static int rule_mem=0; |
70 | 79 | struct s_nt *nt_any=0,*nt_param=0,*nt_gparam; |
174 | 183 | ntname = (char*)s_content_value(tmp1); |
175 | 184 | if(!init_rule_done) init_rule(); |
176 | 185 | if(cur_rule) |
177 | free_rule(cur_rule); | |
186 | free_rule(cur_rule, NULL); | |
178 | 187 | cur_rule = (struct s_rule *)calloc(1,sizeof(struct s_rule)); |
179 | 188 | rule_mem += sizeof(struct s_rule); |
180 | 189 | cur_rule->bead_n=1; |
520 | 529 | } |
521 | 530 | } |
522 | 531 | |
523 | void free_rule(void *_rule /*, void *dummy_param*/) | |
532 | void free_rule(void *_rule, void *dummy_param) | |
524 | 533 | { |
525 | 534 | struct s_rule *rule = (struct s_rule *)_rule; |
526 | 535 | do_delete_scope_action(rule); |
47 | 47 | |
48 | 48 | struct s_nt { |
49 | 49 | char *name; |
50 | char *prompt; | |
50 | const char *prompt; | |
51 | 51 | struct s_dot *first_dot; |
52 | 52 | }; |
53 | 53 | |
81 | 81 | struct s_nt |
82 | 82 | *find_nt(); |
83 | 83 | |
84 | void free_rule(void * rule_param/*, void* dummy_param*/); | |
84 | void open_rule(char *); | |
85 | void free_rule(void *, void *); | |
85 | 86 | void init_rule(); |
86 | 87 | struct s_rule *close_rule(); |
87 | 88 | struct s_dot *find_nt_tran(),*find_term_tran(); |
20 | 20 | |
21 | 21 | #include <stdio.h> |
22 | 22 | #include <stdint.h> |
23 | #include <stdlib.h> | |
24 | #include <string.h> | |
25 | ||
23 | 26 | #include "zz.h" |
24 | 27 | #include "avl.h" |
25 | 28 | #include "rule.h" |
27 | 30 | #include "err.h" |
28 | 31 | #include "trace.h" |
29 | 32 | |
33 | /*PROTOTYPES*/ | |
34 | int parse(struct s_nt *); | |
35 | void pop_source(void); | |
36 | int source_list(struct s_content *, void *); | |
37 | /*FORWARD*/ | |
38 | void delete_scope(char *name); | |
39 | void do_list_rules(char *sintname, int kflag); | |
40 | ||
30 | 41 | struct s_scope { |
31 | 42 | char enabled; |
32 | char *name; | |
33 | TREE *rules; | |
43 | char *name; | |
44 | TREE *rules; | |
34 | 45 | struct s_scope *previous,*next; |
35 | }; | |
36 | ||
37 | ||
46 | }; | |
47 | ||
38 | 48 | static struct s_scope *top_scope=0,*cur_scope=0; |
39 | 49 | static TREE *scope_tree=0; |
40 | 50 | static int link_flag=0; |
77 | 87 | |
78 | 88 | /*---------------------------------------------------------------------------*/ |
79 | 89 | |
80 | zz_push_scope(scope_name) | |
81 | char *scope_name; | |
90 | void zz_push_scope(char *scope_name) | |
82 | 91 | { |
83 | 92 | struct s_scope *scope,*new_scope; |
84 | 93 | new_scope = find_scope(scope_name); |
95 | 104 | } |
96 | 105 | |
97 | 106 | /*---------------------------------------------------------------------------*/ |
98 | delete_and_push_scope(scope_name) | |
99 | char *scope_name; | |
107 | int delete_and_push_scope(char *scope_name) | |
100 | 108 | { |
101 | 109 | delete_scope(scope_name); |
102 | zz_push_scope(scope_name); | |
103 | } | |
104 | ||
105 | /*---------------------------------------------------------------------------*/ | |
106 | ||
107 | zz_pop_scope() | |
110 | zz_push_scope(scope_name); | |
111 | return 0; | |
112 | } | |
113 | ||
114 | /*---------------------------------------------------------------------------*/ | |
115 | ||
116 | void zz_pop_scope(void) | |
108 | 117 | { |
109 | 118 | struct s_scope *scope; |
110 | 119 | if(!top_scope || !top_scope->previous) |
212 | 221 | |
213 | 222 | /*---------------------------------------------------------------------------*/ |
214 | 223 | |
215 | insert_rule(scope_name,rule) | |
216 | char *scope_name; | |
217 | struct s_rule *rule; | |
224 | void insert_rule(char *scope_name, struct s_rule *rule) | |
218 | 225 | { |
219 | 226 | struct s_scope *scope,*dst_scope; |
220 | 227 | struct s_rule *oldrule,*r; |
237 | 244 | |
238 | 245 | if(oldrule->when_change_action.tag==tag_list) |
239 | 246 | { |
240 | source_list(&oldrule->when_change_action); | |
247 | source_list(&oldrule->when_change_action, NULL); | |
241 | 248 | parse(find_nt("root")); |
242 | 249 | pop_source(); |
243 | 250 | } |
284 | 291 | flag=1; |
285 | 292 | while(scope) |
286 | 293 | { |
287 | oldrule = avl_locate(scope->rules,rule); | |
288 | if(oldrule) break; | |
289 | scope=scope->previous; | |
294 | oldrule = avl_locate(scope->rules,rule); | |
295 | if(oldrule) break; | |
296 | scope=scope->previous; | |
290 | 297 | } |
291 | 298 | if(oldrule) |
292 | 299 | { |
293 | /* rule oscura oldrule */ | |
294 | rule->table_backptr=oldrule->table_backptr; | |
295 | *(rule->table_backptr) = rule; | |
296 | oldrule->table_backptr = 0; | |
297 | oldrule->next_rule = rule; | |
298 | rule->next_rule = 0; | |
299 | rule->prev_rule = oldrule; | |
300 | } | |
300 | /* rule oscura oldrule */ | |
301 | rule->table_backptr=oldrule->table_backptr; | |
302 | *(rule->table_backptr) = rule; | |
303 | oldrule->table_backptr = 0; | |
304 | oldrule->next_rule = rule; | |
305 | rule->next_rule = 0; | |
306 | rule->prev_rule = oldrule; | |
307 | } | |
301 | 308 | else |
302 | { | |
303 | /* rule e' nuova */ | |
304 | if(dst_scope->enabled) | |
305 | link_rule(rule); | |
306 | } | |
309 | { | |
310 | /* rule e' nuova */ | |
311 | if(dst_scope->enabled) | |
312 | link_rule(rule); | |
313 | } | |
307 | 314 | } |
308 | 315 | } |
309 | 316 | } |
310 | 317 | |
311 | 318 | /*---------------------------------------------------------------------------*/ |
312 | 319 | |
313 | delete_scope(name) | |
314 | char *name; | |
320 | void delete_scope(char *name) | |
315 | 321 | { |
316 | 322 | int i,j; |
317 | 323 | /*void free_rule();*/ |
377 | 383 | /*---------------------------------------------------------------------------*/ |
378 | 384 | |
379 | 385 | |
380 | list_all_rules() {do_list_rules(0,0);} | |
381 | list_all_krules() {do_list_rules(0,1);} | |
382 | list_rules(s)char*s; {do_list_rules(s,0);} | |
383 | list_krules(s)char*s; {do_list_rules(s,1);} | |
384 | ||
385 | /*---------------------------------------------------------------------------*/ | |
386 | ||
387 | do_list_rules(sintname,kflag) | |
388 | char *sintname; | |
389 | int kflag; | |
386 | int list_all_rules(void) {do_list_rules(0,0); return 0;} | |
387 | int list_all_krules(void) {do_list_rules(0,1); return 0;} | |
388 | int list_rules(char *s) {do_list_rules(s,0); return 0;} | |
389 | int list_krules(char *s) {do_list_rules(s,1); return 0;} | |
390 | ||
391 | /*---------------------------------------------------------------------------*/ | |
392 | ||
393 | void do_list_rules(char *sintname, int kflag) | |
390 | 394 | { |
391 | 395 | struct s_scope *scope; |
392 | 396 | int i; |
429 | 433 | /*---------------------------------------------------------------------------*/ |
430 | 434 | |
431 | 435 | |
432 | write_rules(filename) | |
433 | char *filename; | |
436 | int write_rules(char *filename) | |
434 | 437 | { |
435 | 438 | struct s_scope *scope; |
436 | 439 | int i; |
437 | 440 | Uchan = fopen(filename,"a"); |
438 | if(!Uchan) {zz_error(ERROR,"Unable to write %s\n",filename);return;} | |
441 | if(!Uchan) {zz_error(ERROR,"Unable to write %s\n",filename);return 1;} | |
439 | 442 | printf("RULES segment %d -> (%s)\n",cur_segment_id,filename); |
440 | 443 | scope = top_scope; |
441 | 444 | while(scope) |
450 | 453 | fclose(Uchan); |
451 | 454 | Uchan=0; |
452 | 455 | cur_segment_id++; |
456 | return 0; | |
453 | 457 | } |
454 | 458 | |
455 | 459 | /*---------------------------------------------------------------------------*/ |
26 | 26 | |
27 | 27 | #include <stdio.h> |
28 | 28 | #include <stdint.h> |
29 | #include <stdlib.h> | |
30 | #include <string.h> | |
29 | 31 | #include <errno.h> |
30 | 32 | |
31 | 33 | #include "avl.h" |
33 | 35 | #include "list.h" |
34 | 36 | #include "trace.h" |
35 | 37 | #include "source.h" |
38 | #include "rule.h" | |
39 | ||
40 | /*PROTOTYPES*/ | |
41 | int parse(struct s_nt *); | |
42 | void get_extension(char *, char *); | |
43 | int change_extension(char *, const char *); | |
36 | 44 | |
37 | 45 | int (*find_prompt_proc)()=0; |
38 | 46 | int (*source_line_routine)()=0; |
141 | 149 | |
142 | 150 | /*--------------------------------------------------------------------*/ |
143 | 151 | |
144 | pop_source() | |
152 | void pop_source(void) | |
145 | 153 | { |
146 | 154 | struct s_source *next; |
147 | 155 | if(!cur_source) return; |
166 | 174 | /*--------------------------------------------------------------------*/ |
167 | 175 | |
168 | 176 | // Initialization function for file source: |
169 | source_file(filename) | |
170 | char *filename; | |
177 | int source_file(char *filename) | |
171 | 178 | { |
172 | 179 | FILE *chan; |
173 | 180 | chan = fopen(filename,"r"); |
189 | 196 | /*--------------------------------------------------------------------*/ |
190 | 197 | |
191 | 198 | |
192 | source_pipe() | |
199 | int source_pipe(void) | |
193 | 200 | { |
194 | 201 | new_source(next_token_file); |
195 | 202 | |
204 | 211 | |
205 | 212 | /*--------------------------------------------------------------------*/ |
206 | 213 | |
207 | source_list(list,id) | |
208 | struct s_content *list; | |
209 | void *id; | |
214 | int source_list(struct s_content *list, void *id) | |
210 | 215 | { |
211 | 216 | if(list->tag!=tag_list) |
212 | 217 | { |
229 | 234 | /* |
230 | 235 | blocca lo stream di input. un successivo next_token ritornera' EOF |
231 | 236 | */ |
232 | stop_source() | |
237 | void stop_source(void) | |
233 | 238 | { |
234 | 239 | if(cur_source) |
235 | 240 | cur_source->eof = 1; |
241 | 246 | /** |
242 | 247 | * Read the next token |
243 | 248 | */ |
244 | next_token(token) | |
245 | struct s_content *token; | |
249 | int next_token(struct s_content *token) | |
246 | 250 | { |
247 | 251 | int status; |
248 | 252 | |
486 | 490 | /*--------------------------------------------------------------------*/ |
487 | 491 | |
488 | 492 | |
489 | source_line(source) | |
493 | int source_line(source) | |
490 | 494 | struct s_source *source; |
491 | 495 | { |
492 | 496 | return source->line_n; |
496 | 500 | /*--------------------------------------------------------------------*/ |
497 | 501 | |
498 | 502 | |
499 | get_current_line() | |
503 | int get_current_line(void) | |
500 | 504 | { |
501 | 505 | struct s_source *source; |
502 | 506 | int sp; |
516 | 520 | |
517 | 521 | /*--------------------------------------------------------------------*/ |
518 | 522 | |
519 | char *get_source_name() | |
523 | char *get_source_name(void) | |
520 | 524 | { |
521 | 525 | if(!cur_source) |
522 | 526 | return "NOSOURCE"; |
528 | 532 | /*--------------------------------------------------------------------*/ |
529 | 533 | |
530 | 534 | |
531 | get_source_line() | |
535 | int get_source_line(void) | |
532 | 536 | { |
533 | 537 | if(!cur_source) |
534 | 538 | return 0; |
538 | 542 | |
539 | 543 | /*--------------------------------------------------------------------*/ |
540 | 544 | |
541 | get_source_file(buffer) | |
542 | char *buffer; | |
545 | void get_source_file(char *buffer) | |
543 | 546 | { |
544 | 547 | int i; |
545 | 548 | struct s_source *source; |
595 | 598 | /*--------------------------------------------------------------------*/ |
596 | 599 | |
597 | 600 | |
598 | fprint_source_position(chan,print_action_flag) | |
601 | void fprint_source_position(chan,print_action_flag) | |
599 | 602 | FILE *chan; |
600 | 603 | int print_action_flag; |
601 | 604 | { |
687 | 690 | /*--------------------------------------------------------------------*/ |
688 | 691 | |
689 | 692 | |
690 | pretend_eof() | |
693 | int pretend_eof(void) | |
691 | 694 | { |
692 | 695 | if(cur_source) cur_source->eof=1; |
693 | } | |
694 | ||
695 | ||
696 | /*--------------------------------------------------------------------*/ | |
697 | ||
698 | read_once_only(id) | |
699 | char *id; | |
696 | return 0; | |
697 | } | |
698 | ||
699 | ||
700 | /*--------------------------------------------------------------------*/ | |
701 | ||
702 | int read_once_only(char *id) | |
700 | 703 | { |
701 | 704 | struct node {char *id;} *p; |
702 | 705 | static TREE *tree=0; |
713 | 716 | { |
714 | 717 | if(cur_source) cur_source->eof=1; |
715 | 718 | } |
719 | return 0; | |
716 | 720 | } |
717 | 721 | |
718 | 722 | /*---------------------------------------------------------------------*/ |
21 | 21 | #include <stdlib.h> |
22 | 22 | #include <string.h> |
23 | 23 | #include <dlfcn.h> |
24 | #include <ctype.h> | |
25 | ||
24 | 26 | #include "zlex.h" |
25 | 27 | #include "list.h" |
26 | 28 | #include "rule.h" |
34 | 36 | extern FILE *zz_chanout; |
35 | 37 | extern struct s_content zz_ret_value; |
36 | 38 | |
39 | /*PROTOTYPES*/ | |
40 | char *get_source_name(void); | |
41 | int get_source_line(void); | |
42 | void error_token(struct s_content *); | |
43 | void error_head(int); | |
44 | void error_tail_1(void); | |
45 | int parse(struct s_nt *); | |
46 | void show_zlex_memory(void); | |
47 | void show_rule_memory(void); | |
48 | int source_file(char *); | |
49 | void pop_source(void); | |
50 | void dumpnet(char *); | |
51 | int change_extension(char *, const char *); | |
52 | int source_list(struct s_content *list, void *id); | |
37 | 53 | |
38 | 54 | const char* zz_includes = ""; |
39 | 55 | |
136 | 152 | |
137 | 153 | /*----------------------------------------------------------------------------*/ |
138 | 154 | |
139 | s_print(list) | |
140 | struct s_list *list; | |
155 | int s_print(struct s_list *list) | |
141 | 156 | { |
142 | 157 | int i; |
143 | 158 | |
152 | 167 | |
153 | 168 | /*---------------------------------------------------------------------------*/ |
154 | 169 | |
155 | s_error(list) | |
156 | struct s_list *list; | |
170 | int s_error(struct s_list *list) | |
157 | 171 | { |
158 | 172 | int i; |
159 | 173 | error_head(2); |
167 | 181 | |
168 | 182 | /*---------------------------------------------------------------------------*/ |
169 | 183 | |
170 | s_dump(argc,argv,ret) | |
171 | int argc; | |
172 | struct s_content argv[],*ret; | |
184 | int s_dump(int argc, struct s_content argv[], struct s_content* ret) | |
173 | 185 | { |
174 | 186 | int i; |
175 | 187 | fprintz(zz_chanout,"argc=%d\n",argc); |
181 | 193 | |
182 | 194 | /*---------------------------------------------------------------------------*/ |
183 | 195 | |
184 | int s_param_assign(argc,argv,ret) | |
185 | int argc; | |
186 | struct s_content argv[],*ret; | |
196 | int s_param_assign(int argc, struct s_content argv[], struct s_content* ret) | |
187 | 197 | { |
188 | 198 | struct s_content value; |
189 | 199 | value=argv[1]; |
196 | 206 | |
197 | 207 | /*---------------------------------------------------------------------------*/ |
198 | 208 | |
199 | s_param_g_assign(int argc, struct s_content *argv , struct s_content*ret) | |
209 | int s_param_g_assign(int argc, struct s_content argv[], struct s_content* ret) | |
200 | 210 | { |
201 | 211 | struct s_content value; |
202 | 212 | value=argv[1]; |
209 | 219 | |
210 | 220 | /*---------------------------------------------------------------------------*/ |
211 | 221 | |
212 | s_param_gn_assign(int argc, struct s_content argv[], struct s_content *ret) | |
222 | int s_param_gn_assign(int argc, struct s_content argv[], struct s_content* ret) | |
213 | 223 | { |
214 | 224 | int delta; |
215 | 225 | struct s_content value; |
225 | 235 | /*----------------------------------------------------------------------------*/ |
226 | 236 | |
227 | 237 | |
228 | s_dumpnet(argc,argv,ret) | |
229 | int argc; | |
230 | struct s_content argv[],*ret; | |
238 | int s_dumpnet(int argc, struct s_content argv[], struct s_content* ret) | |
231 | 239 | { |
232 | 240 | if(argc<=0 || argv[0].tag!=tag_ident) |
233 | 241 | { |
234 | 242 | zz_error(ERROR,"dumpnet: bad argument");return 0; |
235 | 243 | } |
236 | dumpnet(s_content_value(argv[0])); | |
244 | dumpnet(s_content_svalue(argv[0])); | |
237 | 245 | return 1; |
238 | 246 | } |
239 | 247 | |
241 | 249 | /*--------------------------------------------------------------------------*/ |
242 | 250 | |
243 | 251 | |
244 | s_trace(trace) | |
252 | int s_trace(trace) | |
245 | 253 | int trace; |
246 | 254 | { |
247 | 255 | zztrace = trace; |
251 | 259 | /*---------------------------------------------------------------------------*/ |
252 | 260 | |
253 | 261 | |
254 | s_eq(int argc, struct s_content argv[], struct s_content* ret) | |
262 | int s_eq(int argc, struct s_content argv[], struct s_content* ret) | |
255 | 263 | { |
256 | 264 | ret->tag=tag_int; |
257 | 265 | |
279 | 287 | |
280 | 288 | /*---------------------------------------------------------------------------*/ |
281 | 289 | |
282 | s_ne(argc,argv,ret) | |
283 | int argc; | |
284 | struct s_content argv[],*ret; | |
290 | int s_ne(int argc, struct s_content argv[], struct s_content* ret) | |
285 | 291 | { |
286 | 292 | if(s_eq(argc,argv,ret)) { |
287 | 293 | s_content_value(*ret) = ! (int)s_content_value(*ret); |
293 | 299 | |
294 | 300 | /*---------------------------------------------------------------------------*/ |
295 | 301 | |
296 | s_ge(argc,argv,ret) | |
297 | int argc; | |
298 | struct s_content argv[],*ret; | |
302 | int s_ge(int argc, struct s_content argv[], struct s_content* ret) | |
299 | 303 | { |
300 | 304 | ret->tag=tag_int; |
301 | 305 | |
315 | 319 | |
316 | 320 | /*---------------------------------------------------------------------------*/ |
317 | 321 | |
318 | s_gt(argc,argv,ret) | |
319 | int argc; | |
320 | struct s_content argv[],*ret; | |
322 | int s_gt(int argc, struct s_content argv[], struct s_content* ret) | |
321 | 323 | { |
322 | 324 | ret->tag=tag_int; |
323 | 325 | |
337 | 339 | |
338 | 340 | /*---------------------------------------------------------------------------*/ |
339 | 341 | |
340 | s_le(argc,argv,ret) | |
341 | int argc; | |
342 | struct s_content argv[],*ret; | |
342 | int s_le(int argc, struct s_content argv[], struct s_content* ret) | |
343 | 343 | { |
344 | 344 | if(s_gt(argc,argv,ret)) { |
345 | 345 | s_content_value(*ret) = ! (int)s_content_value(*ret); |
351 | 351 | |
352 | 352 | /*---------------------------------------------------------------------------*/ |
353 | 353 | |
354 | s_lt(argc,argv,ret) | |
355 | int argc; | |
356 | struct s_content argv[],*ret; | |
354 | int s_lt(int argc, struct s_content argv[], struct s_content* ret) | |
357 | 355 | { |
358 | 356 | if(s_ge(argc,argv,ret)) { |
359 | 357 | s_content_value(*ret) = !s_content_value(*ret); |
365 | 363 | |
366 | 364 | /*---------------------------------------------------------------------------*/ |
367 | 365 | |
368 | s_add(argc,argv,ret) | |
369 | int argc; | |
370 | struct s_content argv[],*ret; | |
366 | int s_add(int argc, struct s_content argv[], struct s_content* ret) | |
371 | 367 | { |
372 | 368 | struct s_tag *targetType = s_target_type(argc, argv); |
373 | 369 | |
400 | 396 | /*----------------------------------------------------------------------------*/ |
401 | 397 | |
402 | 398 | |
403 | s_boolean_and(argc, argv, ret) | |
404 | int argc; | |
405 | struct s_content argv[], *ret; | |
399 | int s_boolean_and(int argc, struct s_content argv[], struct s_content* ret) | |
406 | 400 | { |
407 | 401 | if (argc != 2) { |
408 | 402 | zz_error(ERROR, "Error in s_boolean_and: wrong number of arguments(%i)", argc); |
433 | 427 | /*----------------------------------------------------------------------------*/ |
434 | 428 | |
435 | 429 | |
436 | s_boolean_or(argc, argv, ret) | |
437 | int argc; | |
438 | struct s_content argv[], *ret; | |
430 | int s_boolean_or(int argc, struct s_content argv[], struct s_content* ret) | |
439 | 431 | { |
440 | 432 | if (argc != 2) { |
441 | 433 | zz_error(ERROR, "Error in s_boolean_or: wrong number of arguments(%i)", argc); |
466 | 458 | /*----------------------------------------------------------------------------*/ |
467 | 459 | |
468 | 460 | |
469 | s_sub(argc,argv,ret) | |
470 | int argc; | |
471 | struct s_content argv[],*ret; | |
461 | int s_sub(int argc, struct s_content argv[], struct s_content* ret) | |
472 | 462 | { |
473 | 463 | struct s_tag *targetType = s_target_type(argc, argv); |
474 | 464 | |
494 | 484 | |
495 | 485 | /*---------------------------------------------------------------------------*/ |
496 | 486 | |
497 | s_mult(argc,argv,ret) | |
498 | int argc; | |
499 | struct s_content argv[],*ret; | |
487 | int s_mult(int argc, struct s_content argv[], struct s_content* ret) | |
500 | 488 | { |
501 | 489 | struct s_tag *targetType = s_target_type(argc, argv); |
502 | 490 | |
521 | 509 | |
522 | 510 | /*----------------------------------------------------------------------------*/ |
523 | 511 | |
524 | s_div(argc,argv,ret) | |
525 | int argc; | |
526 | struct s_content argv[],*ret; | |
512 | int s_div(int argc, struct s_content argv[], struct s_content* ret) | |
527 | 513 | { |
528 | 514 | struct s_tag *targetType = s_target_type(argc, argv); |
529 | 515 | |
554 | 540 | |
555 | 541 | /*----------------------------------------------------------------------------*/ |
556 | 542 | |
557 | s_chs(argc,argv,ret) /* s_chs - change of sign */ | |
558 | int argc; | |
559 | struct s_content argv[],*ret; | |
543 | /* s_chs - change of sign */ | |
544 | int s_chs(int argc, struct s_content argv[], struct s_content* ret) | |
560 | 545 | { |
561 | 546 | if(argc!=1) { |
562 | 547 | zz_error(ERROR,"chs: bad argument number"); |
596 | 581 | |
597 | 582 | /*--------------------------------------------------------------------------*/ |
598 | 583 | |
599 | s_strcat(argc,argv,ret) | |
600 | int argc; | |
601 | struct s_content argv[],*ret; | |
584 | int s_strcat(int argc, struct s_content argv[], struct s_content* ret) | |
602 | 585 | { |
603 | 586 | char buffer[256]; |
604 | 587 | char *w,*s; |
654 | 637 | |
655 | 638 | /*----------------------------------------------------------------------------*/ |
656 | 639 | |
657 | s_return(argc,argv,ret) | |
658 | int argc; | |
659 | struct s_content argv[],*ret; | |
640 | int s_return(int argc, struct s_content argv[], struct s_content* ret) | |
660 | 641 | { |
661 | 642 | zz_ret_value=argv[0]; |
662 | 643 | |
670 | 651 | |
671 | 652 | /*----------------------------------------------------------------------------*/ |
672 | 653 | |
673 | s_exec(argc,argv,ret) | |
674 | int argc; | |
675 | struct s_content argv[],*ret; | |
676 | { | |
677 | source_list(&argv[0]); | |
654 | int s_exec(int argc, struct s_content argv[], struct s_content* ret) | |
655 | { | |
656 | source_list(&argv[0], NULL); | |
678 | 657 | parse(find_nt("root")); |
679 | 658 | pop_source(); |
680 | 659 | return 1; |
682 | 661 | |
683 | 662 | /*----------------------------------------------------------------------------*/ |
684 | 663 | |
685 | s_dumplist(argc,argv,ret) | |
686 | int argc; | |
687 | struct s_content argv[]; | |
688 | int ret; | |
664 | int s_dumplist(int argc, struct s_content argv[], struct s_content* ret) | |
689 | 665 | { |
690 | 666 | int i; |
691 | 667 | struct s_list *lst; |
699 | 675 | |
700 | 676 | /*--------------------------------------------------------------------------*/ |
701 | 677 | |
702 | s_foreach(argc,argv,ret) | |
703 | int argc; | |
704 | struct s_content argv[],*ret; | |
678 | int s_foreach(int argc, struct s_content argv[], struct s_content* ret) | |
705 | 679 | { |
706 | 680 | int i,created,rr; |
707 | 681 | char *paramname; |
718 | 692 | { |
719 | 693 | rr=set_param(paramname,lst->array+i); |
720 | 694 | if(i==0) created=rr; |
721 | source_list(&blk); | |
695 | source_list(&blk, NULL); | |
722 | 696 | parse(find_nt("root")); |
723 | 697 | pop_source(); |
724 | 698 | } |
728 | 702 | |
729 | 703 | /*--------------------------------------------------------------------------*/ |
730 | 704 | |
731 | s_for(argc,argv,ret) | |
732 | int argc; | |
733 | struct s_content argv[],*ret; | |
705 | int s_for(int argc, struct s_content argv[], struct s_content* ret) | |
734 | 706 | { |
735 | 707 | int from,to,step,i,created,rr; |
736 | 708 | char *paramname; |
758 | 730 | s_content_value(paramval)=i; |
759 | 731 | rr=set_param(paramname,¶mval); |
760 | 732 | if(i==from) created=rr; |
761 | source_list(&blk); | |
733 | source_list(&blk, NULL); | |
762 | 734 | parse(find_nt("root")); |
763 | 735 | pop_source(); |
764 | 736 | } |
778 | 750 | */ |
779 | 751 | |
780 | 752 | /* Echo back an argument surrounded by parens as a list (with parens) */ |
781 | s_condecho_passparens(argc,argv, ret) | |
782 | int argc; | |
783 | struct s_content argv[], *ret; | |
753 | int s_condecho_passparens(int argc, struct s_content argv[], struct s_content* ret) | |
784 | 754 | { |
785 | 755 | struct s_content tmp; |
786 | 756 | |
801 | 771 | } |
802 | 772 | |
803 | 773 | |
804 | s_condecho_chs(argc,argv,ret) | |
805 | int argc; | |
806 | struct s_content argv[], *ret; | |
774 | int s_condecho_chs(int argc, struct s_content argv[], struct s_content* ret) | |
807 | 775 | { |
808 | 776 | struct s_content tmp; |
809 | 777 | |
824 | 792 | Called by unary and binary loop operations |
825 | 793 | to relect arguments while retaining operators. |
826 | 794 | */ |
827 | s_condecho(argc,argv, action, ret) | |
795 | int s_condecho(argc,argv, action, ret) | |
828 | 796 | int argc; |
829 | 797 | char *action; |
830 | 798 | struct s_content argv[], *ret; |
854 | 822 | return 1; |
855 | 823 | } |
856 | 824 | |
857 | s_condecho_and(argc,argv,ret) | |
858 | int argc; | |
859 | struct s_content argv[], *ret; | |
825 | int s_condecho_and(int argc, struct s_content argv[], struct s_content* ret) | |
860 | 826 | { |
861 | 827 | return s_condecho(argc, argv, "&&", ret); |
862 | 828 | } |
863 | 829 | |
864 | s_condecho_or(argc,argv,ret) | |
865 | int argc; | |
866 | struct s_content argv[], *ret; | |
830 | int s_condecho_or(int argc, struct s_content argv[], struct s_content* ret) | |
867 | 831 | { |
868 | 832 | return s_condecho(argc, argv, "||", ret); |
869 | 833 | } |
870 | 834 | |
871 | s_condecho_add(argc,argv,ret) | |
872 | int argc; | |
873 | struct s_content argv[], *ret; | |
835 | int s_condecho_add(int argc, struct s_content argv[], struct s_content* ret) | |
874 | 836 | { |
875 | 837 | return s_condecho(argc, argv, "+", ret); |
876 | 838 | } |
877 | 839 | |
878 | s_condecho_sub(argc,argv,ret) | |
879 | int argc; | |
880 | struct s_content argv[], *ret; | |
840 | int s_condecho_sub(int argc, struct s_content argv[], struct s_content* ret) | |
881 | 841 | { |
882 | 842 | return s_condecho(argc, argv, "-", ret); |
883 | 843 | } |
884 | 844 | |
885 | s_condecho_mult(argc,argv,ret) | |
886 | int argc; | |
887 | struct s_content argv[], *ret; | |
845 | int s_condecho_mult(int argc, struct s_content argv[], struct s_content* ret) | |
888 | 846 | { |
889 | 847 | return s_condecho(argc, argv, "*", ret); |
890 | 848 | } |
891 | 849 | |
892 | s_condecho_div(argc,argv,ret) | |
893 | int argc; | |
894 | struct s_content argv[], *ret; | |
850 | int s_condecho_div(int argc, struct s_content argv[], struct s_content* ret) | |
895 | 851 | { |
896 | 852 | return s_condecho(argc, argv, "/", ret); |
897 | 853 | } |
898 | 854 | |
899 | s_condecho_eq(argc,argv,ret) | |
900 | int argc; | |
901 | struct s_content argv[], *ret; | |
855 | int s_condecho_eq(int argc, struct s_content argv[], struct s_content* ret) | |
902 | 856 | { |
903 | 857 | return s_condecho(argc, argv, "==", ret); |
904 | 858 | } |
905 | 859 | |
906 | s_condecho_ne(argc,argv,ret) | |
907 | int argc; | |
908 | struct s_content argv[], *ret; | |
860 | int s_condecho_ne(int argc, struct s_content argv[], struct s_content* ret) | |
909 | 861 | { |
910 | 862 | return s_condecho(argc, argv, "!=", ret); |
911 | 863 | } |
912 | 864 | |
913 | s_condecho_ge(argc,argv,ret) | |
914 | int argc; | |
915 | struct s_content argv[], *ret; | |
865 | int s_condecho_ge(int argc, struct s_content argv[], struct s_content* ret) | |
916 | 866 | { |
917 | 867 | return s_condecho(argc, argv, ">=", ret); |
918 | 868 | } |
919 | 869 | |
920 | s_condecho_gt(argc,argv,ret) | |
921 | int argc; | |
922 | struct s_content argv[], *ret; | |
870 | int s_condecho_gt(int argc, struct s_content argv[], struct s_content* ret) | |
923 | 871 | { |
924 | 872 | return s_condecho(argc, argv, ">", ret); |
925 | 873 | } |
926 | 874 | |
927 | s_condecho_le(argc,argv,ret) | |
928 | int argc; | |
929 | struct s_content argv[], *ret; | |
875 | int s_condecho_le(int argc, struct s_content argv[], struct s_content* ret) | |
930 | 876 | { |
931 | 877 | return s_condecho(argc, argv, "<=", ret); |
932 | 878 | } |
933 | 879 | |
934 | s_condecho_lt(argc,argv,ret) | |
935 | int argc; | |
936 | struct s_content argv[], *ret; | |
880 | int s_condecho_lt(int argc, struct s_content argv[], struct s_content* ret) | |
937 | 881 | { |
938 | 882 | return s_condecho(argc, argv, "<", ret); |
939 | 883 | } |
941 | 885 | /*--------------------------------------------------------------------------*/ |
942 | 886 | |
943 | 887 | |
944 | s_do(argc,argv,ret) | |
945 | int argc; | |
946 | struct s_content argv[], *ret; | |
888 | int s_do(int argc, struct s_content argv[], struct s_content* ret) | |
947 | 889 | { |
948 | 890 | s_do_while_loops(argc,argv,&ret,0); |
949 | 891 | } |
950 | 892 | |
951 | s_while(argc,argv,ret) | |
952 | int argc; | |
953 | struct s_content argv[], *ret; | |
893 | int s_while(int argc, struct s_content argv[], struct s_content* ret) | |
954 | 894 | { |
955 | 895 | s_do_while_loops(argc,argv,&ret,1); |
956 | 896 | } |
962 | 902 | * while loop for each pass of the loop (different from 'for' loop |
963 | 903 | * where interpretation is only done at parse of loop). |
964 | 904 | */ |
965 | s_do_while_loops(argc,argv,ret,while_loop) | |
905 | int s_do_while_loops(argc,argv,ret,while_loop) | |
966 | 906 | int argc; |
967 | 907 | struct s_content argv[], *ret; |
968 | 908 | int while_loop; |
1052 | 992 | while ( loop_control_flag ) |
1053 | 993 | { |
1054 | 994 | // Execute the code block of the loop |
1055 | source_list(&blk); | |
995 | source_list(&blk, NULL); | |
1056 | 996 | |
1057 | 997 | // If there is a parse error in the loop body break out of loop |
1058 | 998 | if (!parse(find_nt("root"))) { |
1087 | 1027 | /*--------------------------------------------------------------------------*/ |
1088 | 1028 | |
1089 | 1029 | |
1090 | s_if(argc,argv,ret) | |
1091 | int argc; | |
1092 | struct s_content argv[],*ret; | |
1030 | int s_if(int argc, struct s_content argv[], struct s_content* ret) | |
1093 | 1031 | { |
1094 | 1032 | int i,flag; |
1095 | 1033 | char *paramname; |
1099 | 1037 | |
1100 | 1038 | if(s_content_value(argv[0])) |
1101 | 1039 | { |
1102 | source_list(&blk); | |
1040 | source_list(&blk, NULL); | |
1103 | 1041 | parse(find_nt("root")); |
1104 | 1042 | pop_source(); |
1105 | 1043 | } |
1108 | 1046 | |
1109 | 1047 | /*--------------------------------------------------------------------------*/ |
1110 | 1048 | |
1111 | s_ifelse(argc,argv,ret) | |
1112 | int argc; | |
1113 | struct s_content argv[],*ret; | |
1049 | int s_ifelse(int argc, struct s_content argv[], struct s_content* ret) | |
1114 | 1050 | { |
1115 | 1051 | int i,flag; |
1116 | 1052 | char *paramname; |
1124 | 1060 | { |
1125 | 1061 | blk = argv[2]; |
1126 | 1062 | } |
1127 | source_list(&blk); | |
1063 | source_list(&blk, NULL); | |
1128 | 1064 | parse(find_nt("root")); |
1129 | 1065 | pop_source(); |
1130 | 1066 | } |
1145 | 1081 | |
1146 | 1082 | /*--------------------------------------------------------------------------*/ |
1147 | 1083 | |
1148 | s_include(argc,argv,ret) | |
1149 | int argc; | |
1150 | struct s_content argv[],*ret; | |
1084 | int s_include(int argc, struct s_content argv[], struct s_content* ret) | |
1151 | 1085 | { |
1152 | 1086 | char filename[FILENAME_MAX],type[40]; |
1153 | 1087 | |
1192 | 1126 | |
1193 | 1127 | /*--------------------------------------------------------------------------*/ |
1194 | 1128 | |
1195 | s_add_includedir(argc,argv,ret) | |
1196 | int argc; | |
1197 | struct s_content argv[],*ret; | |
1129 | int s_add_includedir(int argc, struct s_content argv[], struct s_content* ret) | |
1198 | 1130 | { |
1199 | 1131 | zz_assert(argc==1); |
1200 | 1132 | if (zz_num_includedirs == MAX_INCLUDEDIRS-1) { |
1208 | 1140 | |
1209 | 1141 | /*--------------------------------------------------------------------------*/ |
1210 | 1142 | |
1211 | s_print_includedirs(argc,argv,ret) | |
1212 | int argc; | |
1213 | struct s_content argv[],*ret; | |
1143 | int s_print_includedirs(int argc, struct s_content argv[], struct s_content* ret) | |
1214 | 1144 | { |
1215 | 1145 | int i; |
1216 | 1146 | fprintf(zz_chanout, "Default Include Directories:\n"); |
1221 | 1151 | |
1222 | 1152 | /*--------------------------------------------------------------------------*/ |
1223 | 1153 | |
1224 | s_include_default(argc,argv,ret) | |
1225 | int argc; | |
1226 | struct s_content argv[],*ret; | |
1154 | int s_include_default(int argc, struct s_content argv[], struct s_content* ret) | |
1227 | 1155 | { |
1228 | 1156 | char filename[512],type[40]; |
1229 | 1157 | int i; |
1327 | 1255 | |
1328 | 1256 | /*----------------------------------------------------------------------------*/ |
1329 | 1257 | |
1330 | dump_memory_usage() | |
1258 | int dump_memory_usage(void) | |
1331 | 1259 | { |
1332 | 1260 | char cmd[256]; |
1333 | 1261 | strcpy(cmd,"ps -u"); |
1341 | 1269 | /*---------------------------------------------------------------------------*/ |
1342 | 1270 | |
1343 | 1271 | |
1344 | s_extract(argc,argv,ret) | |
1345 | int argc; | |
1346 | struct s_content argv[],*ret; | |
1272 | int s_extract(int argc, struct s_content argv[], struct s_content* ret) | |
1347 | 1273 | { |
1348 | 1274 | struct s_content *cnt; |
1349 | 1275 | struct s_content *list_extract(); |
1361 | 1287 | |
1362 | 1288 | /*---------------------------------------------------------------------------*/ |
1363 | 1289 | |
1364 | s_list_length(argc,argv,ret) | |
1365 | int argc; | |
1366 | struct s_content argv[],*ret; | |
1290 | int s_list_length(int argc, struct s_content argv[], struct s_content* ret) | |
1367 | 1291 | { |
1368 | 1292 | struct s_content *cnt; |
1369 | 1293 | struct s_content *list_extract(); |
1373 | 1297 | } |
1374 | 1298 | |
1375 | 1299 | /*----------------------------------------------------------------------------*/ |
1376 | s_string_length(int argc, struct s_content argv[], struct s_content* ret) | |
1300 | ||
1301 | int s_string_length(int argc, struct s_content argv[], struct s_content* ret) | |
1377 | 1302 | { |
1378 | 1303 | struct s_content *cnt; |
1379 | 1304 | ret->tag = tag_int; |
1385 | 1310 | /*----------------------------------------------------------------------------*/ |
1386 | 1311 | |
1387 | 1312 | // Implement split function for zz simillar to strtok() c function. |
1388 | s_split(argc,argv,ret) | |
1389 | int argc; | |
1390 | struct s_content argv[], *ret; | |
1313 | int s_split(int argc, struct s_content argv[], struct s_content* ret) | |
1391 | 1314 | { |
1392 | 1315 | char *pch; |
1393 | 1316 | char *srcstr; |
1438 | 1361 | /*----------------------------------------------------------------------------*/ |
1439 | 1362 | |
1440 | 1363 | |
1441 | show_sys_memory() | |
1364 | void show_sys_memory(void) | |
1442 | 1365 | { |
1443 | 1366 | PRINTMEM("sys.qstring",sys_qstring_mem) |
1444 | 1367 | } |
1445 | 1368 | |
1446 | 1369 | /*---------------------------------------------------------------------------*/ |
1447 | 1370 | |
1448 | subtag(tagson_name,tagparent_name) | |
1449 | char *tagson_name,*tagparent_name; | |
1371 | int subtag(char *tagson_name, char *tagparent_name) | |
1450 | 1372 | { |
1451 | 1373 | struct s_tag *tagson,*tagparent; |
1452 | 1374 | tagson = find_tag(tagson_name); |
1454 | 1376 | tagson->delete = tagparent->delete; |
1455 | 1377 | tagson->param_on = tagparent->param_on; |
1456 | 1378 | tagson->param_off = tagparent->param_off; |
1457 | } | |
1458 | ||
1459 | /*---------------------------------------------------------------------------*/ | |
1460 | ||
1461 | show_memory() | |
1379 | return 0; | |
1380 | } | |
1381 | ||
1382 | /*---------------------------------------------------------------------------*/ | |
1383 | ||
1384 | void show_memory(void) | |
1462 | 1385 | { |
1463 | 1386 | printf("Memory usage\n"); |
1464 | 1387 | show_zlex_memory(); |
1481 | 1404 | |
1482 | 1405 | |
1483 | 1406 | |
1484 | init_time() | |
1407 | void init_time(void) | |
1485 | 1408 | { |
1486 | 1409 | times (&Time); |
1487 | 1410 | Start_Time = Time.proc_user_time; |
1488 | 1411 | } |
1489 | 1412 | |
1490 | 1413 | |
1491 | get_time() | |
1414 | int get_time(void) | |
1492 | 1415 | { |
1493 | 1416 | int t; |
1494 | 1417 | times (&Time); |
1499 | 1422 | |
1500 | 1423 | |
1501 | 1424 | |
1502 | proc_beep(argc,argv,ret) | |
1503 | int argc; | |
1504 | struct s_content argv[],*ret; | |
1425 | int proc_beep(int argc, struct s_content argv[], struct s_content *ret) | |
1505 | 1426 | { |
1506 | 1427 | char *s; |
1507 | 1428 | int line_n; |
1508 | 1429 | int time; |
1509 | 1430 | float sec; |
1510 | static count=0; | |
1431 | static int count=0; | |
1511 | 1432 | time = get_time(); |
1512 | 1433 | sec = (float)time*0.01; |
1513 | 1434 | if(argc==1) |
1514 | 1435 | printz("** %z ** ",&argv[0]); |
1515 | 1436 | else |
1516 | 1437 | printf("** %d ** ",count++); |
1517 | s=(char*)get_source_name(); | |
1438 | s=get_source_name(); | |
1518 | 1439 | line_n=get_source_line(); |
1519 | 1440 | printf("TIME %4.2fs FILE %s LINE %d\n",sec,s,line_n); |
1520 | 1441 | return 1; |
1526 | 1447 | static struct s_content bra,ket; |
1527 | 1448 | |
1528 | 1449 | |
1529 | s_append_bra(argc,argv,ret) | |
1530 | int argc; | |
1531 | struct s_content argv[],*ret; | |
1450 | int s_append_bra(int argc, struct s_content argv[], struct s_content *ret) | |
1532 | 1451 | { |
1533 | 1452 | if(argc!=1 || argv[0].tag!=tag_list) |
1534 | 1453 | {printf("error - s_append_bra; bad parameters\n");exit(1);} |
1547 | 1466 | |
1548 | 1467 | /*---------------------------------------------------------------------------*/ |
1549 | 1468 | |
1550 | s_append_ket(argc,argv,ret) | |
1551 | int argc; | |
1552 | struct s_content argv[],*ret; | |
1469 | int s_append_ket(int argc, struct s_content argv[], struct s_content *ret) | |
1553 | 1470 | { |
1554 | 1471 | if(argc!=1 || argv[0].tag!=tag_list) |
1555 | 1472 | {printf("error - s_append_ket; bad parameters\n");exit(1);} |
1610 | 1527 | int zz_inttohex(int i) |
1611 | 1528 | { |
1612 | 1529 | char* q=calloc(20,sizeof(char)); |
1613 | sprintf(q,"0x%x\0",i); | |
1530 | sprintf(q,"0x%x",i); | |
1614 | 1531 | return (int)q; |
1615 | 1532 | } |
1616 | 1533 | |
1752 | 1669 | */ |
1753 | 1670 | /*---------------------------------------------------------------------------*/ |
1754 | 1671 | |
1755 | int change_extension(char *fullfilename,char *filetype) { | |
1672 | int change_extension(char *fullfilename, const char *filetype) { | |
1756 | 1673 | char tmp[256],*r,*s,*t; |
1757 | 1674 | int i; |
1758 | 1675 | if(*filetype=='.') filetype++; |
38 | 38 | #include "mem.h" |
39 | 39 | #include "table.h" |
40 | 40 | |
41 | /*FORWARDS*/ | |
42 | void remove_dot(struct s_dot *); | |
43 | void print_rule(struct s_rule *); | |
44 | ||
41 | 45 | static int table_mem=0; |
42 | 46 | extern struct s_nt *nt_any,*nt_param,*nt_gparam; |
43 | 47 | |
46 | 50 | |
47 | 51 | /* CONFRONTO DI T-TRAN */ |
48 | 52 | |
49 | ttrancmp(p1,p2) | |
50 | struct s_term_tran *p1,*p2; | |
53 | int ttrancmp(void *vp1, void *vp2) | |
51 | 54 | { |
52 | 55 | struct s_content *t1,*t2; |
56 | struct s_term_tran *p1 = vp1; | |
57 | struct s_term_tran *p2 = vp2; | |
53 | 58 | t1 = &(p1->term); |
54 | 59 | t2 = &(p2->term); |
55 | 60 | if(t1->tag<t2->tag) return -1; |
67 | 72 | |
68 | 73 | /*----------------------------------------------------------------------------*/ |
69 | 74 | |
70 | struct s_dot *create_dot(nt) | |
71 | struct s_nt *nt; | |
75 | struct s_dot *create_dot(struct s_nt *nt) | |
72 | 76 | { |
73 | 77 | static int dot_count=0; |
74 | 78 | struct s_dot *dot; |
110 | 114 | |
111 | 115 | /*----------------------------------------------------------------------------*/ |
112 | 116 | |
113 | remove_dot(dot) | |
114 | struct s_dot *dot; | |
117 | void remove_dot(struct s_dot *dot) | |
115 | 118 | { |
116 | 119 | if(!dot)return; |
117 | 120 | avl_release(dot->termtree,remove_term_tran); |
283 | 286 | |
284 | 287 | /*---------------------------------------------------------------------------*/ |
285 | 288 | |
286 | link_rule(rule) | |
287 | struct s_rule *rule; | |
289 | int link_rule(struct s_rule *rule) | |
288 | 290 | { |
289 | 291 | int bead_n; |
290 | 292 | struct s_bead *bead; |
313 | 315 | dot->rule = rule; |
314 | 316 | dot->rule_count++; |
315 | 317 | rule->table_backptr = &(dot->rule); |
316 | } | |
317 | ||
318 | ||
319 | /*----------------------------------------------------------------------------*/ | |
320 | ||
321 | unlink_rule(rule) | |
322 | struct s_rule *rule; | |
318 | return 0; | |
319 | } | |
320 | ||
321 | ||
322 | /*----------------------------------------------------------------------------*/ | |
323 | ||
324 | int unlink_rule(struct s_rule *rule) | |
323 | 325 | { |
324 | 326 | int bead_n; |
325 | 327 | struct s_bead *bead; |
353 | 355 | else if(dot->rule != 0) /* work around for popvoidrule bug */ |
354 | 356 | { /* why can dot->rule be null ??? */ |
355 | 357 | zz_error(INTERNAL_ERROR,"unlink_rule: rule mismatch"); |
356 | printf("| old rule is (0x%x)",dot->rule);print_rule(dot->rule);//printf(" (%p)\n", dot->rule); | |
358 | printf("| old rule is (0x%x)",(int)dot->rule);print_rule(dot->rule);//printf(" (%p)\n", dot->rule); | |
357 | 359 | printf("| unlinking rule is ");print_rule(rule);printf("\n"); |
358 | 360 | abort(); |
359 | 361 | } |
360 | 362 | } |
361 | } | |
362 | ||
363 | ||
364 | /*----------------------------------------------------------------------------*/ | |
365 | ||
366 | show_table_mem() | |
363 | return 0; | |
364 | } | |
365 | ||
366 | ||
367 | /*----------------------------------------------------------------------------*/ | |
368 | ||
369 | void show_table_mem(void) | |
367 | 370 | { |
368 | 371 | PRINTMEM("table",table_mem) |
369 | 372 | } |
33 | 33 | #include "param.h" |
34 | 34 | #include "trace.h" |
35 | 35 | #include "sys.h" |
36 | ||
37 | /*PROTOTYPES*/ | |
38 | void pop_source(void); | |
39 | int source_list(struct s_content *list, void *id); | |
40 | void kernel(void); | |
41 | void zkernel(void); | |
42 | int parse(struct s_nt *start_nt); | |
36 | 43 | |
37 | 44 | static const char *std_prompt = "ozz> "; // Default prompt |
38 | 45 |
20 | 20 | #include "zlex.h" |
21 | 21 | #include "kernel.h" |
22 | 22 | |
23 | zkernel() | |
23 | void zkernel(void) | |
24 | 24 | { |
25 | 25 | /* redefinition of the syntax */ |
26 | 26 |
117 | 117 | struct s_content *cnt; |
118 | 118 | { |
119 | 119 | //zz_assert(cnt && s_content_tag(*cnt)==tag_qstring); |
120 | strcpy(buffer,(char*)s_content_value(*cnt)); | |
120 | strcpy(buffer, s_content_svalue(*cnt)); | |
121 | 121 | } |
122 | 122 | |
123 | 123 | int fprint_string(chan,cnt) |
125 | 125 | struct s_content *cnt; |
126 | 126 | { |
127 | 127 | //zz_assert(cnt && s_content_tag(*cnt)==tag_qstring); |
128 | fprintf(chan,"%s",s_content_value(*cnt)); | |
128 | fprintf(chan,"%s", s_content_svalue(*cnt)); | |
129 | 129 | } |
130 | 130 | |
131 | 131 | /*----------------------------------------------------------------------------*/ |
449 | 449 | } |
450 | 450 | #endif |
451 | 451 | |
452 | init_zlex() | |
452 | void init_zlex(void) | |
453 | 453 | { |
454 | 454 | if(init_zlex_done) return; |
455 | 455 | init_zlex_done=1; |
609 | 609 | /*----------------------------------------------------------------------------*/ |
610 | 610 | |
611 | 611 | |
612 | zlex_set_precedence(cnt,prec,left_assoc) | |
612 | void zlex_set_precedence(cnt,prec,left_assoc) | |
613 | 613 | struct s_content *cnt; |
614 | 614 | int prec,left_assoc; |
615 | 615 | { |
693 | 693 | |
694 | 694 | /*----------------------------------------------------------------------------*/ |
695 | 695 | |
696 | std_len(cnt) | |
697 | struct s_content *cnt; | |
696 | int std_len(struct s_content *cnt) | |
698 | 697 | { |
699 | 698 | //return strlen(cnt->tag->name)+9; |
700 | 699 | zz_assert(!"any use????"); |
1156 | 1155 | |
1157 | 1156 | /*----------------------------------------------------------------------------*/ |
1158 | 1157 | |
1159 | show_zlex_memory() | |
1158 | void show_zlex_memory(void) | |
1160 | 1159 | { |
1161 | 1160 | PRINTMEM("zlex.qstring.mex",zlex_qstring_mem) |
1162 | 1161 | PRINTMEM("zlex.strsaved.mem",zlex_strsaved_mem) |
1199 | 1198 | /*------------------------------------------------------------------------*/ |
1200 | 1199 | |
1201 | 1200 | |
1202 | ignore_block() | |
1201 | void ignore_block(void) | |
1203 | 1202 | { |
1204 | 1203 | ignore_block_flag = 1; |
1205 | 1204 | braket_level = 0; |
44 | 44 | extern int init_zlex_done; |
45 | 45 | #endif |
46 | 46 | |
47 | void init_zlex(void); | |
47 | 48 | #define INIT_ZLEX {if(!init_zlex_done)init_zlex();} |
48 | 49 | |
49 | 50 |
19 | 19 | //#define DEBUG 1 |
20 | 20 | |
21 | 21 | #include <stdint.h> |
22 | #include <string.h> | |
23 | ||
22 | 24 | #include "zlex.h" |
23 | 25 | #include "rule.h" |
24 | 26 | #include "err.h" |
25 | 27 | #include "trace.h" |
26 | 28 | |
29 | /*PROTOTYPES*/ | |
30 | void setaction_return(struct s_content *value, char *tag_name); | |
31 | void setaction_rreturn(void); | |
32 | void setaction_pass(void); | |
33 | void setaction_exelist(struct s_content *list); | |
34 | void setaction_assign(void); | |
35 | void append_nt_bead(char *ntname, char *beadname); | |
36 | void append_t_bead(struct s_content *cnt); | |
37 | void insert_rule(char *, struct s_rule *); | |
38 | ||
27 | 39 | static struct {struct s_content bead;char *name;} beads[MAX_RULE_LENGTH]; |
28 | 40 | static int bead_n=0; |
29 | 41 | static struct {struct s_content cnt;char *tag_name,is_return;} |
33 | 45 | |
34 | 46 | /* aggiungi una bead alla regola corrente */ |
35 | 47 | |
36 | z_bead(argc,argv,ret) | |
37 | int argc; | |
38 | struct s_content argv[],*ret; | |
48 | int z_bead(int argc, struct s_content argv[], struct s_content *ret) | |
39 | 49 | { |
40 | 50 | if(bead_n>=MAX_RULE_LENGTH) |
41 | 51 | { |
42 | 52 | zz_error(ERROR,"rule too long"); |
43 | return; | |
53 | return 0; | |
44 | 54 | } |
45 | 55 | beads[bead_n].bead=argv[1]; |
46 | 56 | beads[bead_n].name=(argc==3)?(char*)s_content_value(argv[2]):0; |
52 | 62 | |
53 | 63 | /* l'azione della regola corrente (zz-action o special) */ |
54 | 64 | |
55 | z_set_action(argc,argv,ret) | |
56 | int argc; | |
57 | struct s_content argv[],*ret; | |
65 | int z_set_action(int argc, struct s_content argv[], struct s_content *ret) | |
58 | 66 | { |
59 | 67 | cur_action.cnt=argv[0]; |
60 | 68 | cur_action.is_return=0; |
65 | 73 | |
66 | 74 | /* l'azione della regola corrente (return [as]) */ |
67 | 75 | |
68 | z_set_return_action(argc,argv,ret) | |
69 | int argc; | |
70 | struct s_content argv[],*ret; | |
76 | int z_set_return_action(int argc, struct s_content argv[], struct s_content *ret) | |
71 | 77 | { |
72 | 78 | cur_action.cnt=argv[0]; |
73 | 79 | cur_action.is_return=1; |
80 | 86 | |
81 | 87 | /*---------------------------------------------------------------------------*/ |
82 | 88 | |
89 | void do_z_link_rule(char *, char *); | |
90 | ||
83 | 91 | /* inserisce una regola nello scope di default */ |
84 | 92 | |
85 | z_link_rule_default(argc,argv,ret) | |
86 | int argc; | |
87 | struct s_content argv[],*ret; | |
88 | { | |
89 | do_z_link_rule(s_content_value(argv[0]),0); | |
93 | int z_link_rule_default(int argc, struct s_content argv[], struct s_content *ret) | |
94 | { | |
95 | do_z_link_rule(s_content_svalue(argv[0]), NULL); | |
90 | 96 | return 1; |
91 | 97 | } |
92 | 98 | |
94 | 100 | |
95 | 101 | /* inserisce una regola in uno scope */ |
96 | 102 | |
97 | z_link_rule(argc,argv,ret) | |
98 | int argc; | |
99 | struct s_content argv[],*ret; | |
100 | { | |
101 | do_z_link_rule(s_content_value(argv[1]),s_content_value(argv[0])); | |
102 | return 1; | |
103 | } | |
104 | ||
105 | /*---------------------------------------------------------------------------*/ | |
106 | ||
107 | do_z_link_rule(sint_name,scope_name) | |
108 | char *sint_name,*scope_name; | |
103 | int z_link_rule(int argc, struct s_content argv[], struct s_content *ret) | |
104 | { | |
105 | do_z_link_rule(s_content_svalue(argv[1]), s_content_svalue(argv[0])); | |
106 | return 1; | |
107 | } | |
108 | ||
109 | /*---------------------------------------------------------------------------*/ | |
110 | ||
111 | void do_z_link_rule(char *sint_name, char *scope_name) | |
109 | 112 | { |
110 | 113 | int i; |
111 | 114 | struct s_rule *rule; |
112 | 115 | open_rule(zlex_strsave(sint_name)); |
113 | 116 | for(i=0;i<bead_n;i++) |
114 | 117 | if(beads[i].name) |
115 | append_nt_bead(s_content_value(beads[i].bead),beads[i].name); | |
118 | append_nt_bead(s_content_svalue(beads[i].bead),beads[i].name); | |
116 | 119 | else |
117 | 120 | append_t_bead(&beads[i].bead); |
118 | 121 | bead_n=0; |
142 | 145 | cur_action.cnt.tag=tag_none; |
143 | 146 | s_content_value(cur_action.cnt)=0; |
144 | 147 | cur_action.is_return=0; |
145 | return 1; | |
146 | 148 | } |
147 | 149 | |
148 | 150 | /*---------------------------------------------------------------------------*/ |
196 | 198 | } |
197 | 199 | |
198 | 200 | |
199 | z_append_term(argc,argv,ret) | |
200 | int argc; | |
201 | struct s_content argv[],*ret; | |
201 | int z_append_term(int argc, struct s_content argv[], struct s_content *ret) | |
202 | 202 | { |
203 | 203 | append_t_bead(&argv[0]); |
204 | 204 | return 1; |
205 | 205 | } |
206 | 206 | |
207 | z_append_nt(argc,argv,ret) | |
208 | int argc; | |
209 | struct s_content argv[],*ret; | |
207 | int z_append_nt(int argc, struct s_content argv[], struct s_content *ret) | |
210 | 208 | { |
211 | 209 | append_nt_bead(s_content_value(argv[0]),s_content_value(argv[1])); |
212 | 210 | return 1; |
216 | 214 | |
217 | 215 | /*---------------------------------------------------------------------------*/ |
218 | 216 | |
219 | z_set_when_change_action(argc,argv,ret) | |
220 | int argc; | |
221 | struct s_content argv[],*ret; | |
217 | int z_set_when_change_action(int argc, struct s_content argv[], struct s_content *ret) | |
222 | 218 | { |
223 | 219 | struct s_rule *rule,*get_last_rule(); |
224 | 220 | rule = get_last_rule(); |
232 | 228 | |
233 | 229 | /*---------------------------------------------------------------------------*/ |
234 | 230 | |
235 | z_set_when_exit_scope(argc,argv,ret) | |
236 | int argc; | |
237 | struct s_content argv[],*ret; | |
231 | int z_set_when_exit_scope(int argc, struct s_content argv[], struct s_content *ret) | |
238 | 232 | { |
239 | 233 | struct s_rule *rule,*get_last_rule(); |
240 | 234 | rule = get_last_rule(); |
28 | 28 | #include <stdlib.h> |
29 | 29 | |
30 | 30 | #include "zz.h" |
31 | ||
32 | /*PROTOYPES*/ | |
33 | void print_error_count(void); | |
34 | void print_usage(void); | |
31 | 35 | |
32 | 36 | int main(argc,argv,env) |
33 | 37 | int argc; |
164 | 168 | /*---------------------------------------------------------------------*/ |
165 | 169 | |
166 | 170 | |
167 | print_usage() { | |
171 | void print_usage(void) { | |
168 | 172 | fprintf(stderr, |
169 | 173 | "usage: ozz [params] [filein [fileout]]\n" |
170 | 174 | " -q quiet\n" |
36 | 36 | #include "zlex.h" |
37 | 37 | #include "trace.h" |
38 | 38 | #include "source.h" |
39 | #include "rule.h" | |
39 | 40 | |
41 | /*PROTOTYPES*/ | |
42 | int parse(struct s_nt *); | |
40 | 43 | void next_token_tt(struct s_source *src); |
41 | 44 | |
42 | 45 | /*--------------------------------------------------------------------*/ |
44 | 47 | /** |
45 | 48 | * Initialization function for using zz with interactive tty interface: |
46 | 49 | */ |
47 | source_tt() | |
50 | void source_tt(void) | |
48 | 51 | { |
49 | 52 | struct s_source *src = new_source(next_token_tt); |
50 | 53 | |
52 | 55 | src->src.tt.prompt = zz_get_prompt(); |
53 | 56 | src->src.tt.old = src->src.tt.s = 0; |
54 | 57 | src->src.tt.row[0]='\0'; |
55 | ||
56 | return 1; | |
57 | 58 | } |
58 | 59 | |
59 | 60 | |
61 | 62 | |
62 | 63 | |
63 | 64 | |
64 | zz_parse_tt() | |
65 | int zz_parse_tt(void) | |
65 | 66 | { |
66 | 67 | /* really necessary... hope it doesn't come first in the calling sequence.. |
67 | 68 | if(!zz_chanout) |