-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
44 lines (33 loc) · 761 Bytes
/
main.c
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
38
39
40
41
42
43
44
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
#include "file.h"
#include "parser.h"
int main(int argc, char** argv) {
char* filepath = "";
char* output_filename = "output.asm";
if(argc < 2) {
puts("Please put a file as the second argument.");
return 1;
}
if(argc > 2) {
output_filename = argv[2];
puts(output_filename);
}
filepath = argv[1];
FILE* file;
file = fopen(filepath, "r");
if(file == NULL) {
puts("Bad file.");
return 1;
}
char* buffer = (char*) malloc(4096);
if(!read_file(file, &buffer, 4096)) {
puts("Bad read file.");
return 1;
}
parse_vm(&buffer);
fclose(file);
free(buffer);
return 0;
}