ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pcompos.c
(Generate patch)

Comparing ray/src/px/pcompos.c (file contents):
Revision 1.7 by greg, Thu May 30 09:44:36 1991 UTC vs.
Revision 2.15 by greg, Mon Sep 21 12:13:57 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include  <stdio.h>
14  
15 + #ifdef MSDOS
16 + #include  <fcntl.h>
17 + #endif
18 +
19   #include  "color.h"
20  
21 + #include  "resolu.h"
22  
23 < #define  MAXFILE        32
23 > #define  MAXFILE        64
24  
20 #define  SIGNHT         24
21 #define  setpscom(b,n)  sprintf(b, "psign -h %d '%.30s'|pfilt -1 -x /2 -y /2",\
22                                2*SIGNHT, n)
23
25                                          /* output picture size */
26   int  xsiz = 0;
27   int  ysiz = 0;
# Line 32 | Line 33 | int  ymax = 0;
33  
34   COLR  bgcolr = BLKCOLR;                 /* background color */
35  
36 + int  labelht = 24;                      /* label height */
37 +
38   int  checkthresh = 0;                   /* check threshold value */
39  
40 + char  Command[] = "<Command>";
41 + char  Label[] = "<Label>";
42 +
43   char  *progname;
44  
45   struct {
# Line 49 | Line 55 | int  nfile;                    /* number of files */
55  
56   int  wrongformat = 0;
57  
58 < char  tmpbuf[128];
58 > FILE  *popen(), *lblopen();
59  
60 < FILE  *popen();
60 > extern char  *malloc();
61  
62  
63   tabputs(s)                      /* print line preceded by a tab */
# Line 73 | Line 79 | main(argc, argv)
79   int  argc;
80   char  *argv[];
81   {
76        double  atof();
82          int  ncolumns = 0;
83 <        int  dolabels = 0;
84 <        int  curcol = 0, curx = 0, cury = 0;
83 >        int  autolabel = 0;
84 >        int  curcol = 0, x0 = 0, curx = 0, cury = 0, spacing = 0;
85 >        char  *thislabel;
86          int  an;
87 <
87 > #ifdef MSDOS
88 >        extern int  _fmode;
89 >        _fmode = O_BINARY;
90 >        setmode(fileno(stdin), O_BINARY);
91 >        setmode(fileno(stdout), O_BINARY);
92 > #endif
93          progname = argv[0];
94  
95          for (an = 1; an < argc && argv[an][0] == '-'; an++)
96                  switch (argv[an][1]) {
97                  case 'x':
98 <                        xmax = xsiz = atoi(argv[++an]);
98 >                        xsiz = atoi(argv[++an]);
99                          break;
100                  case 'y':
101 <                        ymax = ysiz = atoi(argv[++an]);
101 >                        ysiz = atoi(argv[++an]);
102                          break;
103                  case 'b':
104                          setcolr(bgcolr, atof(argv[an+1]),
# Line 98 | Line 109 | char  *argv[];
109                  case 'a':
110                          ncolumns = atoi(argv[++an]);
111                          break;
112 +                case 's':
113 +                        spacing = atoi(argv[++an]);
114 +                        break;
115 +                case 'o':
116 +                        curx = x0 = atoi(argv[++an]);
117 +                        cury = atoi(argv[++an]);
118 +                        break;
119                  case 'l':
120 <                        dolabels++;
120 >                        switch (argv[an][2]) {
121 >                        case 'a':
122 >                                autolabel++;
123 >                                break;
124 >                        case 'h':
125 >                                labelht = atoi(argv[++an]);
126 >                                break;
127 >                        case '\0':
128 >                                goto dofiles;
129 >                        default:
130 >                                goto userr;
131 >                        }
132                          break;
133                  case '\0':
134                  case 't':
# Line 109 | Line 138 | char  *argv[];
138                  }
139   dofiles:
140          for (nfile = 0; an < argc; nfile++) {
141 <                if (dolabels) {
142 <                        if (nfile >= MAXFILE-1) {
143 <                                fprintf(stderr,
115 <                                "%s: only %d files allowed with labels\n",
116 <                                        progname, MAXFILE/2);
117 <                        }
118 <                } else {
119 <                        if (nfile >= MAXFILE) {
120 <                                fprintf(stderr, "%s: only %d files allowed\n",
121 <                                                progname, MAXFILE);
122 <                                quit(1);
123 <                        }
124 <                }
125 <                if (nfile >= (dolabels ? MAXFILE-1 : MAXFILE)) {
126 <                        fprintf(stderr, "%s: too many files\n", progname);
127 <                        quit(1);
128 <                }
141 >                if (nfile >= MAXFILE)
142 >                        goto toomany;
143 >                thislabel = NULL;
144                  input[nfile].hasmin = input[nfile].hasmax = 0;
145                  while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+'))
146                          switch (argv[an][1]) {
# Line 146 | Line 161 | dofiles:
161                                  }
162                                  an += 2;
163                                  break;
164 +                        case 'l':
165 +                                if (strcmp(argv[an], "-l"))
166 +                                        goto userr;
167 +                                thislabel = argv[an+1];
168 +                                an += 2;
169 +                                break;
170                          case '\0':
171                                  if (argv[an][0] == '-')
172                                          goto getfile;
173 <                        /* fall through */
173 >                                goto userr;
174                          default:
175                                  goto userr;
176                          }
177   getfile:
178                  if (argc-an < (ncolumns ? 1 : 3))
179                          goto userr;
180 +                if (autolabel && thislabel == NULL)
181 +                        thislabel = argv[an];
182                  if (!strcmp(argv[an], "-")) {
183                          input[nfile].name = "<stdin>";
184                          input[nfile].fp = stdin;
185                  } else {
186 <                        input[nfile].name = argv[an];
187 <                        if ((input[nfile].fp = argv[an][0] == '!' ?
188 <                                        popen(argv[an]+1, "r") :
189 <                                        fopen(argv[an], "r")) == NULL) {
186 >                        if (argv[an][0] == '!') {
187 >                                input[nfile].name = Command;
188 >                                input[nfile].fp = popen(argv[an]+1, "r");
189 >                        } else {
190 >                                input[nfile].name = argv[an];
191 >                                input[nfile].fp = fopen(argv[an], "r");
192 >                        }
193 >                        if (input[nfile].fp == NULL) {
194                                  perror(argv[an]);
195                                  quit(1);
196                          }
# Line 179 | Line 206 | getfile:
206                  }
207                                                  /* get picture size */
208                  if (fgetresolu(&input[nfile].xres, &input[nfile].yres,
209 <                                input[nfile].fp) != (YMAJOR|YDECR)) {
209 >                                input[nfile].fp) < 0) {
210                          fprintf(stderr, "%s: bad picture size\n",
211                                          input[nfile].name);
212                          quit(1);
213                  }
214                  if (ncolumns > 0) {
215                          if (curcol >= ncolumns) {
216 <                                cury = ymax;
217 <                                curx = 0;
216 >                                cury = ymax + spacing;
217 >                                curx = x0;
218                                  curcol = 0;
219                          }
220                          input[nfile].xloc = curx;
221                          input[nfile].yloc = cury;
222 <                        curx += input[nfile].xres;
222 >                        curx += input[nfile].xres + spacing;
223                          curcol++;
224                  } else {
225                          input[nfile].xloc = atoi(argv[an++]);
# Line 206 | Line 233 | getfile:
233                          xmax = input[nfile].xloc+input[nfile].xres;
234                  if (input[nfile].yloc+input[nfile].yres > ymax)
235                          ymax = input[nfile].yloc+input[nfile].yres;
236 <                if (dolabels) {
237 <                        input[++nfile].name = "<Label>";
238 <                        setpscom(tmpbuf, input[nfile-1].name);
239 <                        if ((input[nfile].fp = popen(tmpbuf, "r")) == NULL)
236 >                if (thislabel != NULL) {
237 >                        if (++nfile >= MAXFILE)
238 >                                goto toomany;
239 >                        input[nfile].name = Label;
240 >                        input[nfile].hasmin = input[nfile].hasmax = 0;
241 >                        input[nfile].xres = input[nfile-1].xres;
242 >                        input[nfile].yres = labelht;
243 >                        if ((input[nfile].fp = lblopen(thislabel,
244 >                                        &input[nfile].xres,
245 >                                        &input[nfile].yres)) == NULL)
246                                  goto labelerr;
214                        if (checkheader(input[nfile].fp, COLRFMT, NULL) < 0)
215                                goto labelerr;
216                        if (fgetresolu(&input[nfile].xres, &input[nfile].yres,
217                                        input[nfile].fp) != (YMAJOR|YDECR))
218                                goto labelerr;
247                          input[nfile].xloc = input[nfile-1].xloc;
248                          input[nfile].yloc = input[nfile-1].yloc +
249 <                                        input[nfile-1].yres - SIGNHT;
222 <                        input[nfile].hasmin = input[nfile].hasmax = 0;
249 >                                        input[nfile-1].yres-input[nfile].yres;
250                  }
251          }
252          if (xsiz <= 0)
253                  xsiz = xmax;
254 +        else if (xsiz > xmax)
255 +                xmax = xsiz;
256          if (ysiz <= 0)
257                  ysiz = ymax;
258 +        else if (ysiz > ymax)
259 +                ymax = ysiz;
260                                          /* add new header info. */
261          printargs(argc, argv, stdout);
262          fputformat(COLRFMT, stdout);
263 <        printf("\n-Y %d +X %d\n", ysiz, xsiz);
263 >        putchar('\n');
264 >        fprtresolu(xsiz, ysiz, stdout);
265  
266          compos();
267          
268          quit(0);
269   userr:
270 <        fprintf(stderr, "Usage: %s [-x xres][-y yres][-b r g b] ", progname);
271 <        fprintf(stderr, "[-t min1][+t max1] file1 x1 y1 ..\n");
270 >        fprintf(stderr,
271 >        "Usage: %s [-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ",
272 >                        progname);
273 >        fprintf(stderr, "[-t min1][+t max1][-l lab] pic1 x1 y1 ..\n");
274          quit(1);
275 + toomany:
276 +        fprintf(stderr, "%s: only %d files and labels allowed\n",
277 +                        progname, MAXFILE);
278 +        quit(1);
279   labelerr:
280          fprintf(stderr, "%s: error opening label\n", progname);
281          quit(1);
# Line 319 | Line 357 | register COLR  c1, c2;
357   }
358  
359  
360 + FILE *
361 + lblopen(s, xp, yp)              /* open pipe to label generator */
362 + char  *s;
363 + int  *xp, *yp;
364 + {
365 +        char  com[128];
366 +        FILE  *fp;
367 +
368 +        sprintf(com, "psign -s -.15 -a 2 -x %d -y %d '%.90s'", *xp, *yp, s);
369 +        if ((fp = popen(com, "r")) == NULL)
370 +                return(NULL);
371 +        if (checkheader(fp, COLRFMT, NULL) < 0)
372 +                goto err;
373 +        if (fgetresolu(xp, yp, fp) < 0)
374 +                goto err;
375 +        return(fp);
376 + err:
377 +        pclose(fp);
378 +        return(NULL);
379 + }
380 +
381 +
382   quit(code)              /* exit gracefully */
383   int  code;
384   {
385 +        register int  i;
386 +                                /* close input files */
387 +        for (i = 0; i < nfile; i++)
388 +                if (input[i].name == Command || input[i].name == Label)
389 +                        pclose(input[i].fp);
390 +                else
391 +                        fclose(input[i].fp);
392          exit(code);
393   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines