This repository has been archived on 2026-03-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
v2/src/main.c

59 lines
1.3 KiB
C
Raw Normal View History

2026-02-05 08:34:16 +11:00
#include "lexer/lexer.h"
2026-02-05 19:14:31 +11:00
#include <stdio.h>
2026-02-05 08:34:16 +11:00
2026-02-16 18:34:03 +11:00
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: %s [file]\n", argv[0]);
exit(1);
}
char* fileContents = getFileContents(argv[1]);
ResultType(SolsLexer, charptr) lexer = createLexer(fileContents);
2026-02-05 19:14:31 +11:00
if (lexer.error) {
printf("Error while creating lexer: %s", lexer.as.error);
2026-02-16 18:34:03 +11:00
exit(1);
2026-02-05 19:14:31 +11:00
}
ResultType(Nothing, charptr) lexed = lex(&lexer.as.success);
2026-02-12 08:46:12 +11:00
if (lexed.error) {
printf("%s", lexed.as.error);
2026-02-15 09:42:11 +11:00
exit(1);
2026-02-12 08:46:12 +11:00
}
2026-02-05 08:34:16 +11:00
return 0;
}