aboutsummaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc22
1 files changed, 6 insertions, 16 deletions
diff --git a/src/main.cc b/src/main.cc
index d357756..ea28324 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -1,3 +1,4 @@
+#include <filehandler.h>
#include <scanner.h>
#include <stdio.h>
#include <stdlib.h>
@@ -5,34 +6,23 @@
int
main(int argc, char **argv)
{
- (void) argc;
- (void) argv;
-
if (argc != 2) {
printf("Usage: %s <script>\n", argv[0]);
return 1;
}
- FILE *f = fopen(argv[1], "r");
- if (f == NULL) {
+ Filehandler f(argv[1]);
+ bool success = f.open();
+ if (!success) {
printf("Unable to open %s\n", argv[1]);
return 1;
}
- fseek(f, 0, SEEK_END);
- unsigned long fsize = ftell(f);
- fseek(f, 0, SEEK_SET);
-
- char *buffer = (char *) calloc(fsize, sizeof(char));
- int bytesread = fread(buffer, sizeof(char), fsize, f);
- if (bytesread < 0) {
- printf("Unable to open %s\n", argv[1]);
- return 1;
- }
+ char *buffer = f.read();
Scanner s(buffer);
s.scan_tokens();
- free(buffer);
+ f.close();
return 0;
}