-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
60 lines (48 loc) · 1.11 KB
/
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
54
55
56
57
58
59
60
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "when.h"
#include "option.h"
#include "setter.h"
#include "strtable.h"
#include "symtable.h"
#include "y_tab.h"
extern FILE* yyin;
extern int yy_flex_debug;
int main(int argc, char** argv) {
if (argc < 2) {
printf("Usage: %s [game.dlg]\n", argv[0]);
return 1;
}
yyin = fopen(argv[1], "rb");
if (!yyin) {
perror("Game file");
return errno;
}
#if YYDEBUG
yydebug = YYDEBUG;
yy_flex_debug = YYDEBUG;
#endif
yyparse();
exec_when(get_when(0)); /* bootstrap */
eval_whens();
while (run_flag && option_count() > 0) {
char buf[64];
do {
int len;
printf("> ");
fgets(buf, sizeof(buf), stdin);
len = strlen(buf);
if (len > 0 && buf[len - 1] == '\n')
buf[len - 1] = '\0';
} while(eval_options(buf) == 0);
clear_options();
eval_whens();
clear_temp();
}
clear_whens();
clear_strings();
fclose(yyin);
return 0;
}