helloJSON/src/main.c

49 lines
782 B
C

#include "aliases.h"
#include "lexer.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("NO FILE PROVIDED\n");
return EXIT_FAILURE;
}
const char *filename = argv[1];
FILE *fp = fopen(filename, "r");
fseek(fp, 0, SEEK_END);
u64 length = ftell(fp);
fseek(fp, 0, SEEK_SET);
char json[length + 1];
memset(json, 0, length + 1);
fread(json, sizeof(char), length, fp);
fclose(fp);
lexer_t *lexer = NULL;
lexer_init(&lexer);
if (!lexer) {
return EXIT_FAILURE;
}
token_t token = get_next_token(lexer, json);
while (token.type != TK_NO_TOKEN) {
print_token(token);
token = get_next_token(lexer, NULL);
}
lexer_free(&lexer);
return EXIT_SUCCESS;
}