예제 #1
0
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;
}
예제 #2
0
파일: strdupv.c 프로젝트: lassik/junkcode
extern char *strdup3(const char *s2, const char *s1, const char *s0)
{
    return(strdupv(3, s2, s1, s0));
}
예제 #3
0
파일: strdupv.c 프로젝트: lassik/junkcode
extern char *strdup2(const char *s1, const char *s0)
{
    return(strdupv(2, s1, s0));
}