blob: 5d71c0bf80c162aeac01f177629ed7a0ebf13ef0 (
plain)
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
|
#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);
linkList_t* ll = lex_line(content);
linkList_t* l1 = ll;
while (1) {
token_t* t = (token_t*)l1->value;
printf("%d \n", t->type);
if (l1->next == NULL) {
break;
}
l1 = l1->next;
}
free(content);
}
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;
}
|