aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorc+12023-05-13 14:35:27 -0400
committerc+12023-05-13 14:35:27 -0400
commitc8d473a2e6bfcb463ca4fb3613cf73db8d74e479 (patch)
tree1c6ba184c1291b74759a03f71b851ba6a0866ddb /src/main.c
parentce63a4ea610bc80e9862c799633e07d3e896fe92 (diff)
real
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index a463a7e..4b4944d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;
}