-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
53 lines (40 loc) · 959 Bytes
/
main.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "structs.h"
#include "parser.h"
#include "exec.h"
void operation_clean(struct operation *op) {
if (op == NULL)
return;
if (op->var != NULL)
g_free(op->var);
g_free(op);
}
void operations_cleanup(GSList *op_list) {
if (op_list == NULL)
return;
g_slist_free_full(op_list, (GDestroyNotify)operation_clean);
op_list = NULL;
}
int main(int argc, char **argv) {
GSList *op_list;
op_list = NULL;
if (argc < 2) {
printf("ERROR!\n");
return 0;
}
printf("Parsing \"%s\"\n", argv[1]);
op_list = parse_operations(argv[1]);
if (op_list == NULL) {
printf("Error parsing file.\n");
return 0;
}
printf("%d operations found\n", g_slist_length(op_list));
g_slist_foreach(op_list, (GFunc)dump_operation, NULL);
printf("Executing \"%s\"\n", argv[1]);
exec_operations(op_list);
printf("Cleaning \"%s\"\n", argv[1]);
operations_cleanup(op_list);
}