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
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "precedent.h"
#include "hashtable.h"
#include "parse.h"
#include "eval.h"
int main(int argc, char** argv) {
if (argc > 1) {
if (strcmp("--version", argv[1]) == 0) {
printf("precedent, version 0.1\n");
printf("Copyright 2023 Kai Stevenson\n");
printf("This software was licensed under the MIT license;\n");
printf("for more information, see the license file.\n");
return 0;
}
else if (strcmp("--help", argv[1]) == 0) {
printf("usage: precedent [--version] [--help] <file>\n");
return 0;
}
}
sym_t* finalSymbol = parse_symbol_final(read_file(argv[1]));
printf("drawing program:\n");
write_symbol_visual(finalSymbol, 0);
printf("\nexecuting program:\n");
init_eval();
eval(finalSymbol);
return 0;
}
char* read_file(char* path) {
FILE* file = fopen(path, "r");
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;
}
|