diff options
author | c+1 | 2023-05-13 14:35:27 -0400 |
---|---|---|
committer | c+1 | 2023-05-13 14:35:27 -0400 |
commit | c8d473a2e6bfcb463ca4fb3613cf73db8d74e479 (patch) | |
tree | 1c6ba184c1291b74759a03f71b851ba6a0866ddb /src/main.c | |
parent | ce63a4ea610bc80e9862c799633e07d3e896fe92 (diff) |
real
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -11,16 +11,20 @@ int main(int argc, char* argv[]) { char *source; fsource = fopen ("examples/hello.halk", "rb"); - if (!fsource) { fputs("Source file not found.", stderr); exit(1); }; + if (!fsource) { + fputs("Source file not found.", stderr); + exit(1); + }; fseek(fsource, 0L, SEEK_END); fsource_size = ftell(fsource); rewind(fsource); source = calloc(1, fsource_size + 1); + if (!source) { fclose(fsource); - fputs("Memory allocation faled.", stderr); + fputs("Memory allocation failed.", stderr); exit(1); } @@ -31,12 +35,9 @@ int main(int argc, char* argv[]) { exit(1); } - lexer_t* lexer = lexer_init( - source - ); - fclose(fsource); - free(source); + + lexer_t* lexer = lexer_init( source ); printf("\n=== INPUT =======\n%s\n=== END INPUT ===\n", lexer->content); @@ -46,5 +47,7 @@ int main(int argc, char* argv[]) { printf("===\ntoken type: %d\ntoken value: %s\n===\n", token->type, token->value); } + lexer_destroy(lexer); + return 0; } |