15 struct variable** res;
17 res = xmalloc (HASHSIZE * sizeof(struct variable*));
18 memset(res, 0, sizeof(struct variable*)*HASHSIZE);
24 get_bucket_number(char* name)
27 unsigned char* p = name;
37 /* value NULL for finding without modyfiing */
38 static struct variable*
39 find_var(char* name, char* value, struct variable** hash)
44 n = get_bucket_number(name);
47 while(p && strcmp(p->name,name))
54 p = xmalloc(sizeof(struct variable));
57 p->name = xstrdup(name);
58 p->value = (value? value:xstrdup(""));
65 regex_cmp(char* s, char* r)
70 int ovector[OVECCOUNT];
72 brum = pcre_compile(r,0,&error,&erroroffset,NULL);
76 int res = pcre_exec(brum,NULL,s,strlen(s),0,0,ovector,OVECCOUNT);
83 print_tree(struct tree* t, int ind)
90 printf("%*s if\n", ind, "");
91 print_tree(t->pt.tif.c,ind+1);
92 printf("%*s then\n", ind, "");
93 print_tree(t->pt.tif.i,ind+1);
94 printf("%*s else\n", ind, "");
95 print_tree(t->pt.tif.e,ind+1);
98 #define UPPER(a) ((a) >> 8)
99 #define LOWER(a) ((a) & 0xFF)
100 print_tree(t->pt.cond.left, ind+1);
101 printf("%*s", ind, "");
102 if (UPPER(t->pt.cond.op) > 0)
103 putchar(UPPER(t->pt.cond.op));
104 putchar(LOWER(t->pt.cond.op));
106 print_tree(t->pt.cond.right, ind+1);
109 print_tree(t->pt.block.head,ind);
110 print_tree(t->pt.block.tail,ind);
113 print_tree(t->pt.ass.left, ind+1);
114 printf("%*s =\n", ind, "");
115 print_tree(t->pt.ass.right, ind+1);
118 printf("%*s", ind, "");
119 switch (t->pt.leaf.type){
123 puts(t->pt.leaf.value);
128 if (t->pt.arrow.kw_left)
129 printf("%*s%s\n", ind+1, "", t->pt.arrow.kw_left);
130 printf("%*s ->\n", ind, "");
131 if (t->pt.arrow.kw_right)
132 printf("%*s%s\n", ind+1, "", t->pt.arrow.kw_right);
133 print_tree(t->pt.arrow.s,ind+1);
136 print_tree(t->pt.op.left, ind+1);
137 printf("%*s%c\n", ind, "", t->pt.op.op);
138 print_tree(t->pt.op.right, ind+1);
148 xcat(char* left, char* right)
150 char* res = xmalloc(strlen(left) + strlen(right) + 1);
162 interp_ass_right(struct tree* t, struct variable** hash)
166 if (t->pt.leaf.type == L_VAR)
167 return xstrdup(find_var(t->pt.leaf.value,NULL,hash)->value);
169 return xstrdup(t->pt.leaf.value);
171 switch (t->pt.op.op){
173 return xcat(interp_ass_right(t->pt.op.left, hash),interp_ass_right(t->pt.op.right, hash));
178 die("interp_ass_right: got to default");
183 interp(struct tree* t, struct variable** hash)
190 interp(t->pt.block.head, hash);
191 interp(t->pt.block.tail, hash);
194 find_var(t->pt.ass.left->pt.leaf.value, interp_ass_right(t->pt.ass.right, hash), hash);
197 die("interp: got to default");