diff options
Diffstat (limited to 'src/orgaasm.c')
-rw-r--r-- | src/orgaasm.c | 37 |
1 files changed, 4 insertions, 33 deletions
diff --git a/src/orgaasm.c b/src/orgaasm.c index 8e1aa3f..d48ad94 100644 --- a/src/orgaasm.c +++ b/src/orgaasm.c @@ -1,3 +1,5 @@ +#include "ops.h" +#include "drain.h" #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -10,12 +12,6 @@ struct Label { Label *next; }; -static const char ops[][4] = { - "NOP", "LIT", "POP", "NIP", "SWP", "ROT", "DUP", "OVR", "EQU", "NEQ", - "GTH", "LTH", "JEZ", "JNZ", "JMP", "JRT", "RET", "LDA", "STA", "RED", - "WRT", "ADD", "SUB", "MUL", "DIV", "AND", "ORA", "XOR", "LSF", "RSF", - "SLP" -}; static const int hextable[256] = { ['0'] = 0x0, ['1'] = 0x1, ['2'] = 0x2, ['3'] = 0x3, ['4'] = 0x4, ['5'] = 0x5, ['6'] = 0x6, ['7'] = 0x7, ['8'] = 0x8, ['9'] = 0x9, @@ -194,32 +190,6 @@ second_pass(char *s) } } -static char * -drain(FILE *fp) -{ - if (fseek(fp, 0, SEEK_END) < 0) { - perror("drain:SEEK_END"); - return NULL; - } - const long size = ftell(fp); - if (fseek(fp, 0, SEEK_SET) < 0) { - perror("drain:SEEK_SET"); - return NULL; - } - char *const data = malloc(size + 1); - if (data == NULL) { - perror("drain:malloc"); - return NULL; - } - if ((long)fread(data, 1, size, fp) != size) { - perror("drain:fread"); - free(data); - return NULL; - } - data[size] = '\0'; - return data; -} - int main(int argc, char **argv) { @@ -235,7 +205,8 @@ main(int argc, char **argv) perror(argv[1]); return fail(); } - data = drain(fp); + long size; + data = drain(fp, &size); fclose(fp); if (data == NULL) return fail(); |