Initial commit
This commit is contained in:
48
src/main.c
Normal file
48
src/main.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "types.h"
|
||||
#include "parser.h"
|
||||
#include <stdio.h>
|
||||
|
||||
char* getFileContents(const char* filename) {
|
||||
// https://stackoverflow.com/questions/3747086/reading-the-whole-text-file-into-a-char-array-in-c
|
||||
FILE* fp;
|
||||
long lSize;
|
||||
char* file;
|
||||
|
||||
fp = fopen(filename, "rb");
|
||||
if (!fp) {
|
||||
perror(filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fseek(fp, 0L, SEEK_END);
|
||||
lSize = ftell(fp);
|
||||
rewind(fp);
|
||||
|
||||
file = calloc(1, lSize + 1);
|
||||
if (!file) {
|
||||
fclose(fp);
|
||||
fputs("memory allocation fail when reading file", stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (1!=fread(file, lSize, 1, fp)) {
|
||||
fclose(fp);
|
||||
free(file);
|
||||
fputs("couldn't read entire file", stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// we done
|
||||
fclose(fp);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 2) {
|
||||
printf("Usage: ground [file]\n");
|
||||
exit(1);
|
||||
}
|
||||
char* file = getFileContents(argv[1]);
|
||||
GroundProgram program = parseFile(file);
|
||||
}
|
||||
Reference in New Issue
Block a user