Newer
Older
/*
** ast_for.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** Started on Thu Aug 3 02:41:37 2006 Seblu
node->type = T_CASE;
node->body.child_case.word = word;
node->body.child_case.items = NULL;
return node;
}
if (node->type != T_CASE)
return;
item->pattern = pattern;
item->exec = exec;
item->next = NULL;
for (this = &node->body.child_case.items; *this; *this = (*this)->next)
; //do nothing
*this = item;
void ast_case_print(s_ast_node *node, FILE *fs, unsigned *node_id)
{
unsigned cur_node;
s_case_item *item;
unsigned item_id;
if (node->type != T_CASE)
return;
fprintf(fs, "%u [label = \"CASE\\nword: %s\"];\n",
cur_node = *node_id, node->body.child_case.word);
++*node_id;
for (item = node->body.child_case.items, item_id = 0;
item;
item = item->next, ++item_id) {
fprintf(fs, "%u -> %u\n", cur_node, *node_id);
fprintf(fs, "%u [ label = \"Item %u\\n", *node_id, item_id);
++*node_id;
//print pattern
if (item->pattern)
for (int i = 0; item->pattern[i]; ++i)
fprintf(fs, "%s\\n", item->pattern[i]);
fprintf(fs, "\"];\n");
//print exec
if (item->exec)
ast_print_node(item->exec, fs, node_id);
}
}
return;
free(node->body.child_case.word);
for (this = node->body.child_case.items; this; this = buf) {
for (register int i = 0; this->pattern[i]; ++i)
free(this->pattern[i]);
free(this->pattern);
ast_destruct(this->exec);
buf = this->next;
free(this);
}
free(node);