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 <stdlib.h>
#include <stdio.h>
#include "operetta.h"
#include "lexer.h"
#include "parse.h"
#include "proposition.h"
int main(int argc, char** argv) {
/* read file */
char* path = argv[1];
char* content = read_file(path);
int lineCount = count_lines(content);
lineSet_t lines = parse_lines(content, lineCount);
for (int i = 0; i < lines.count; i++) {
write_prop(lines.lines[i].proposition);
printf(" BECAUSE: ");
write_just(lines.lines[i].justification);
printf("\n");
}
free(content);
}
void write_prop(prop_t prop) {
if (prop.isSimple) {
printf("%s", prop.name);
}
else {
printf("(");
write_prop(*(prop.propA));
printf(" %s ", tttos(prop.relation));
write_prop(*(prop.propB));
printf(")");
}
}
void write_just(just_t just) {
printf("%s", jrtos(just.rule));
for (int i = 0; i < just.referencesCount; i++) {
printf(" %d", just.references[i]);
}
}
char* read_file(char* path) {
FILE* file = fopen(path, "r");
if (file == NULL) {
printf("file %s does not exist\n", path);
}
fseek(file, 0, SEEK_END);
unsigned long int length = ftell(file);
fseek(file, 0, SEEK_SET);
char* out = malloc((length + 1) * sizeof(char));
fread(out, length, 1, file);
fclose(file);
out[length] = '\0';
return out;
}
|