/* * COMBINEDUMP.C * * Written by Ville Saari * * Copyright (c) 1991 Ferry Island Pixelboys * All rights reserved * * Created: 06-Jan-91 * 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;1mCOMBINEDUMP\033[0m V" VERSION " by Ville Saari.\n"\ "Copyright (c) 1991 Ferry Island Pixelboys.\n"\ "Freeware.\n" #define USAGE \ "\n" \ "Usage: combinedump [-l(R|G|B)] [-r(R|G|B)]"\ " [-c((l|r)((t|b))...)...]\n"\ " \n\n"\ "Defaults: -lR -rG -clt34b85rt0b51\n" #include #include #include #define R 0 #define G 1 #define B 2 #define BUFSIZE 16384L FILE *lfile = NULL, *rfile = NULL, *ofile = NULL; long left=R, lbot=85, ltop=34; long right=G, rbot=51, rtop=0; long readval(FILE *file) { long x; x=fgetc(file); x|=fgetc(file)<<8; return x; } void writeval(long x, FILE *file) { putc((char)x, file); putc((char)(x>>8), file); } long getrgb(char ch) { switch(ch|0x20) { case 'r': return R; case 'g': return G; case 'b': return B; default: return -1; } } void error(char *text, int code) { if(code) fputs("COMBINEDUMP: ", stderr); fputs(text, stderr); fflush(stderr); if (ofile != NULL) { fflush(ofile); fclose(ofile); } if (lfile != NULL) fclose(lfile); if (rfile != NULL) fclose(rfile); exit(code); } void main(int ac, char **arg) { char *lname=NULL, *rname=NULL, *oname=NULL; unsigned char *lbuf, *rbuf; long f, n, l, r, t, b, val; long width, height, buflines, bufsize, linesize, bufplace; long lcol, rcol; long lbc, rbc, lsc, rsc; long ofs[3]; fputs(COPYRIGHT, stderr); if(ac < 4 || arg[1][0] == '?') error(USAGE, 0); for(f=1; f255) error("Illegal '-c' switch.\n", 20); if(l && b) lbot=val; if(l && t) ltop=val; if(r && b) rbot=val; if(r && t) rtop=val; } } break; default: error("Illegal switch.\n", 20); } } } if((lfile=fopen(lname, "rb"))==NULL) error("Can't open left input file.\n", 20); if((rfile=fopen(rname, "rb"))==NULL) error("Can't open right input file.\n", 20); if((ofile=fopen(oname, "wb"))==NULL) error("Can't open output file.\n", 20); if((width=readval(lfile))!=readval(rfile) || (height=readval(lfile))!=readval(rfile)) error("Input files are incompatible.\n", 20); linesize=2+3*width; if((buflines=BUFSIZE/linesize)<0) error("Too long input lines.\n", 20); bufsize=buflines*linesize; if((lbuf = (unsigned char *)malloc((unsigned long)(buflines*linesize)))==(unsigned char *)0) error("Can't allocate memory for buffers.\n", 20); if((rbuf = (unsigned char *)malloc((unsigned long)(buflines*linesize)))==(unsigned char *)0) error("Can't allocate memory for buffers.\n", 20); writeval(width, ofile); writeval(height, ofile); #ifndef NOANSICODES fprintf(stderr, "\033[0mProcessing line: of %-5d\033[14D", (int)height); #endif for(f=0, bufplace=0; f=bufsize || f==height-1) { if(!(fwrite(lbuf, (unsigned int)bufplace, 1, ofile))) error("Error when writing output file.\n", 20); bufplace=0; } } #ifndef NOANSICODES fputs("\033[0m\n", stderr); #endif }