/* * CATDUMP.C * * Written by Ville Saari * * Copyright (c) 1991 Ferry Island Pixelboys * All rights reserved * * Created: 26-Dec-90 * Updated: 31-Jan-91 * * Updated: 07-May-91 - Aaron A. Collins - Made somewhat more portable, and * made the program write out to a file instead of stdout. */ #define VERSION "1.10" #define COPYRIGHT \ "\033[33;1mCATDUMP\033[0m V" VERSION " by Ville Saari.\n"\ "Copyright (c) 1991 Ferry Island pixelboys.\n"\ "Freeware.\n" #define USAGE \ "\n" \ "Usage: catdump [...] \n" /* #define NOANSICODES 1 */ /* uncomment if you don't want ANSI */ #include #include #include #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) #define BUFSIZE 32768L FILE *outfile = NULL; struct { char *fn; FILE *fp; long width, height; long startline, endline; } infile[30]; long width, height, startline=0x7fffffffL, endline=0L; char buf[81]; char *buffer; void error(char *text, int code) { if(code) fputs("CATDUMP: ", stderr); fputs(text, stderr); if (outfile != NULL) { fflush(outfile); fclose(outfile); } exit(code); } void main(int ac, char **arg) { #ifndef NOANSICODES long prev; #endif long f, ct=0, first, ok, line, linesize, bufp, buflines; fputs(COPYRIGHT, stderr); if(ac < 4 || arg[1][0] == '?' || arg[1][0] == '-') error(USAGE, 0); for(f=1; f>8), (char)height, (char)(height>>8)); buflines=BUFSIZE/linesize; if((buffer=malloc((unsigned int)(linesize*buflines)))==NULL) error("Couldn't allocate memory for buffer.\n", 20); bufp=0; #ifndef NOANSICODES prev=-2; #endif for(line=startline; line=0 && (infile[f].startline > line || infile[f].endline <= line); f--); #ifndef NOANSICODES if(f!=prev) { if(prev!=-2) fputs("\n", stderr); if(f==-1) fprintf(stderr, "Lines%5d to zeroed.\033[13D", (int)line); else fprintf(stderr, "Lines%5d to copied from file '%s'.\r\033[13C", (int)line, infile[f].fn); prev=f; } #endif if(f>=0) { fseek(infile[f].fp, 4L+linesize*(line-infile[f].startline), 0); if(!fread(buffer+bufp, (unsigned int)linesize, 1, infile[f].fp) || (long)((unsigned char)buffer[bufp]|((unsigned char)buffer[bufp+1]<<8))!=line) { free(buffer); fputs("\n", stderr); sprintf(buf, "Error while reading input file '%s'.\n", infile[f].fn); error(buf, 20); } } else { memset(buffer+bufp, 0, (unsigned int)linesize); buffer[bufp]=(char)line, buffer[bufp+1]=(char)(line>>8); } if((bufp+=linesize)>=linesize*buflines || line>=endline-1) { if(!fwrite(buffer, (unsigned int)bufp, 1, outfile)) { free(buffer); fputs("\n", stderr); error("Error while writing output file.\n", 20); } bufp=0; } #ifndef NOANSICODES fprintf(stderr, "%5d\033[5D", (int)line); fflush(stderr); #endif } fputs("\n", stderr); for(f=0; f