INS_ARR readInstructions(const char *fn) { int l; char *ptr = readFile(fn, &l); char *raw = realloc(ptr, l + 1); raw[l] = '\0'; ptr = raw; if(raw == NULL) { fprintf(stderr, "ERR: Couldn't open file '%s'.\nAbort.\n", fn); exit(1); } INS_ARR arr; arr.instructions = NULL; arr.c = 0; while(*raw != '\0') { char *line = strdupv(raw, '\n'); raw += strlen(line) + 1; arr.instructions = (INSTR *) realloc(arr.instructions, ++arr.c * sizeof(INSTR)); arr.instructions[arr.c - 1] = INSTR_read(line); arr.instructions[arr.c - 1].id = (WORD) ((arr.c - 1) & 0xffff); free(line); } free(ptr); return arr; }
extern char *strdup3(const char *s2, const char *s1, const char *s0) { return(strdupv(3, s2, s1, s0)); }
extern char *strdup2(const char *s1, const char *s0) { return(strdupv(2, s1, s0)); }