--- ray/src/px/pcompos.c 1989/09/12 13:04:24 1.4 +++ ray/src/px/pcompos.c 1991/05/30 09:44:36 1.7 @@ -1,4 +1,4 @@ -/* Copyright (c) 1987 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -15,8 +15,12 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" -#define MAXFILE 16 +#define MAXFILE 32 +#define SIGNHT 24 +#define setpscom(b,n) sprintf(b, "psign -h %d '%.30s'|pfilt -1 -x /2 -y /2",\ + 2*SIGNHT, n) + /* output picture size */ int xsiz = 0; int ysiz = 0; @@ -33,7 +37,7 @@ int checkthresh = 0; /* check threshold value */ char *progname; struct { - char *name; /* file name */ + char *name; /* file or command name */ FILE *fp; /* stream pointer */ int xres, yres; /* picture size */ int xloc, yloc; /* anchor point */ @@ -43,12 +47,25 @@ struct { int nfile; /* number of files */ +int wrongformat = 0; +char tmpbuf[128]; + +FILE *popen(); + + tabputs(s) /* print line preceded by a tab */ char *s; { - putc('\t', stdout); - fputs(s, stdout); + char fmt[32]; + + if (isformat(s)) { + formatval(fmt, s); + wrongformat = strcmp(fmt, COLRFMT); + } else { + putc('\t', stdout); + fputs(s, stdout); + } } @@ -57,6 +74,9 @@ int argc; char *argv[]; { double atof(); + int ncolumns = 0; + int dolabels = 0; + int curcol = 0, curx = 0, cury = 0; int an; progname = argv[0]; @@ -75,6 +95,12 @@ char *argv[]; atof(argv[an+3])); an += 3; break; + case 'a': + ncolumns = atoi(argv[++an]); + break; + case 'l': + dolabels++; + break; case '\0': case 't': goto dofiles; @@ -83,7 +109,20 @@ char *argv[]; } dofiles: for (nfile = 0; an < argc; nfile++) { - if (nfile >= MAXFILE) { + if (dolabels) { + if (nfile >= MAXFILE-1) { + fprintf(stderr, + "%s: only %d files allowed with labels\n", + progname, MAXFILE/2); + } + } else { + if (nfile >= MAXFILE) { + fprintf(stderr, "%s: only %d files allowed\n", + progname, MAXFILE); + quit(1); + } + } + if (nfile >= (dolabels ? MAXFILE-1 : MAXFILE)) { fprintf(stderr, "%s: too many files\n", progname); quit(1); } @@ -115,22 +154,29 @@ dofiles: goto userr; } getfile: - if (argc-an < 3) + if (argc-an < (ncolumns ? 1 : 3)) goto userr; if (!strcmp(argv[an], "-")) { input[nfile].name = ""; input[nfile].fp = stdin; } else { input[nfile].name = argv[an]; - if ((input[nfile].fp = fopen(argv[an], "r")) == NULL) { - fprintf(stderr, "%s: cannot open\n", argv[an]); + if ((input[nfile].fp = argv[an][0] == '!' ? + popen(argv[an]+1, "r") : + fopen(argv[an], "r")) == NULL) { + perror(argv[an]); quit(1); } } an++; /* get header */ printf("%s:\n", input[nfile].name); - getheader(input[nfile].fp, tabputs); + getheader(input[nfile].fp, tabputs, NULL); + if (wrongformat) { + fprintf(stderr, "%s: not a Radiance picture\n", + input[nfile].name); + quit(1); + } /* get picture size */ if (fgetresolu(&input[nfile].xres, &input[nfile].yres, input[nfile].fp) != (YMAJOR|YDECR)) { @@ -138,8 +184,20 @@ getfile: input[nfile].name); quit(1); } - input[nfile].xloc = atoi(argv[an++]); - input[nfile].yloc = atoi(argv[an++]); + if (ncolumns > 0) { + if (curcol >= ncolumns) { + cury = ymax; + curx = 0; + curcol = 0; + } + input[nfile].xloc = curx; + input[nfile].yloc = cury; + curx += input[nfile].xres; + curcol++; + } else { + input[nfile].xloc = atoi(argv[an++]); + input[nfile].yloc = atoi(argv[an++]); + } if (input[nfile].xloc < xmin) xmin = input[nfile].xloc; if (input[nfile].yloc < ymin) @@ -148,6 +206,21 @@ getfile: xmax = input[nfile].xloc+input[nfile].xres; if (input[nfile].yloc+input[nfile].yres > ymax) ymax = input[nfile].yloc+input[nfile].yres; + if (dolabels) { + input[++nfile].name = "