-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.c
65 lines (57 loc) · 1.24 KB
/
action.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "action.h"
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include "option.h"
#include "setter.h"
#include "when.h"
#include "strtable.h"
#include "symtable.h"
#include "text.h"
#include "y_tab.h"
int run_flag = 1;
struct action* create_action(int type) {
struct action* action = malloc(sizeof(struct action));
if (!action) {
perror("create_action: malloc");
exit(errno);
}
action->type = type;
return action;
}
void free_action(struct action* action) {
if (!action)
return;
free_action(action->next);
switch (action->type) {
case SET:
free_setter(action->arg.setter);
break;
case OPTIONS:
free_option(action->arg.options);
break;
}
free(action);
}
void exec_actions(struct action* action) {
if (!action)
return;
switch (action->type) {
case EXIT:
run_flag = 0;
break;
case TEXT:
print_text(get_string(action->arg.text_str));
break;
case SET:
set(action->arg.setter);
break;
case GOTO:
set_temp(action->arg.goto_sym);
break;
case OPTIONS:
add_options(action->arg.options);
break;
}
exec_actions(action->next);
}