/* Last edited on 2007-08-15 22:35:05 by stolfi */ /* See the authorship and copyright notice at the end of this file. */ /* Changes: */ #include #include #include #include #include #include #include void* Alloc(long size) { void *p = malloc(size); if (p == NULL) { Error("out of memory"); } return(p); } char *CopyString(char *p) { char *q = (char*)(Alloc((strlen(p)+1)*sizeof(char))); char *t = q; while(((*t) = (*p)) != 0) { p++; t++; } return q; } byte* CopyBytes(byte *L, long W) { byte *S = (char*)(Alloc(W*sizeof(byte))); long i; for (i=0; i= curA) { if (curW >= MAX_LINE_LENGTH) { LineError("line too long", name, R); } else { long newA = (curA == 0 ? 256 : 2*curA); byte *newL = (byte *)Alloc(newA*sizeof(byte)); long i; for (i=0; i 0) free(curB); curA = newA; curB = newL; } } curB[curW] = c; curW++; c = fgetc(f); if (c == EOF) { FileError("missing NL at end of file", name); } } (*B) = curB; (*A) = curA; (*L) = CopyBytes(curB, curW); (*W) = curW; return(FALSE); } void WriteLine(FILE *f, byte *L, long W) { long i; for (i=0; i