#include "../../parser.h" #include #include #define EMBED_FILE(name) \ void emit_##name(const char *filename) \ { \ FILE *f = fopen(filename, "wb"); \ if(f) { \ fwrite(name, 1, name##_len, f); \ fclose(f); \ } \ } static char* readFile(const char* path) { FILE* file = fopen(path, "rb"); if (file == NULL) { fprintf(stderr, "Could not open file \"%s\".\n", path); exit(74); } fseek(file, 0L, SEEK_END); size_t fileSize = ftell(file); rewind(file); char* buffer = (char*)malloc(fileSize + 1); if (buffer == NULL) { fprintf(stderr, "Not enough memory to read \"%s\".\n", path); exit(74); } size_t bytesRead = fread(buffer, sizeof(char), fileSize, file); if (bytesRead < fileSize) { fprintf(stderr, "Could not read file \"%s\".\n", path); exit(74); } buffer[bytesRead] = '\0'; fclose(file); return buffer; } int main(int argc, char **argv) { if(argc != 2) return EXIT_FAILURE; char* source = readFile(argv[1]); compile(source); free(source); return EXIT_SUCCESS; }