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.6 by greg, Thu Apr 18 14:35:19 1991 UTC vs.
Revision 2.3 by greg, Tue Feb 11 08:51:50 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include  "color.h"
16  
17 + #include  "resolu.h"
18  
19   #define  MAXFILE        32
20  
# Line 28 | Line 29 | int  ymax = 0;
29  
30   COLR  bgcolr = BLKCOLR;                 /* background color */
31  
32 + int  labelht = 24;                      /* label height */
33 +
34   int  checkthresh = 0;                   /* check threshold value */
35  
36   char  *progname;
37  
38   struct {
39 <        char  *name;                    /* file name */
39 >        char  *name;                    /* file or command name */
40          FILE  *fp;                      /* stream pointer */
41          int  xres, yres;                /* picture size */
42          int  xloc, yloc;                /* anchor point */
# Line 45 | Line 48 | int  nfile;                    /* number of files */
48  
49   int  wrongformat = 0;
50  
51 + FILE  *popen(), *lblopen();
52  
53 +
54   tabputs(s)                      /* print line preceded by a tab */
55   char  *s;
56   {
# Line 65 | Line 70 | main(argc, argv)
70   int  argc;
71   char  *argv[];
72   {
73 <        double  atof();
73 >        int  ncolumns = 0;
74 >        int  autolabel = 0;
75 >        int  curcol = 0, curx = 0, cury = 0;
76 >        char  *thislabel;
77          int  an;
78  
79          progname = argv[0];
# Line 84 | Line 92 | char  *argv[];
92                                          atof(argv[an+3]));
93                          an += 3;
94                          break;
95 +                case 'a':
96 +                        ncolumns = atoi(argv[++an]);
97 +                        break;
98 +                case 'l':
99 +                        switch (argv[an][2]) {
100 +                        case 'a':
101 +                                autolabel++;
102 +                                break;
103 +                        case 'h':
104 +                                labelht = atoi(argv[++an]);
105 +                                break;
106 +                        case '\0':
107 +                                goto dofiles;
108 +                        default:
109 +                                goto userr;
110 +                        }
111 +                        break;
112                  case '\0':
113                  case 't':
114                          goto dofiles;
# Line 92 | Line 117 | char  *argv[];
117                  }
118   dofiles:
119          for (nfile = 0; an < argc; nfile++) {
120 <                if (nfile >= MAXFILE) {
121 <                        fprintf(stderr, "%s: too many files\n", progname);
122 <                        quit(1);
123 <                }
120 >                if (nfile >= MAXFILE)
121 >                        goto toomany;
122 >                if (autolabel)
123 >                        thislabel = argv[an];
124 >                else
125 >                        thislabel = NULL;
126                  input[nfile].hasmin = input[nfile].hasmax = 0;
127                  while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+'))
128                          switch (argv[an][1]) {
# Line 116 | Line 143 | dofiles:
143                                  }
144                                  an += 2;
145                                  break;
146 +                        case 'l':
147 +                                if (strcmp(argv[an], "-l"))
148 +                                        goto userr;
149 +                                thislabel = argv[an+1];
150 +                                an += 2;
151 +                                break;
152                          case '\0':
153                                  if (argv[an][0] == '-')
154                                          goto getfile;
155 <                        /* fall through */
155 >                                goto userr;
156                          default:
157                                  goto userr;
158                          }
159   getfile:
160 <                if (argc-an < 3)
160 >                if (argc-an < (ncolumns ? 1 : 3))
161                          goto userr;
162                  if (!strcmp(argv[an], "-")) {
163                          input[nfile].name = "<stdin>";
164                          input[nfile].fp = stdin;
165                  } else {
166                          input[nfile].name = argv[an];
167 <                        if ((input[nfile].fp = fopen(argv[an], "r")) == NULL) {
167 >                        if ((input[nfile].fp = argv[an][0] == '!' ?
168 >                                        popen(argv[an]+1, "r") :
169 >                                        fopen(argv[an], "r")) == NULL) {
170                                  perror(argv[an]);
171                                  quit(1);
172                          }
# Line 147 | Line 182 | getfile:
182                  }
183                                                  /* get picture size */
184                  if (fgetresolu(&input[nfile].xres, &input[nfile].yres,
185 <                                input[nfile].fp) != (YMAJOR|YDECR)) {
185 >                                input[nfile].fp) < 0) {
186                          fprintf(stderr, "%s: bad picture size\n",
187                                          input[nfile].name);
188                          quit(1);
189                  }
190 <                input[nfile].xloc = atoi(argv[an++]);
191 <                input[nfile].yloc = atoi(argv[an++]);
190 >                if (ncolumns > 0) {
191 >                        if (curcol >= ncolumns) {
192 >                                cury = ymax;
193 >                                curx = 0;
194 >                                curcol = 0;
195 >                        }
196 >                        input[nfile].xloc = curx;
197 >                        input[nfile].yloc = cury;
198 >                        curx += input[nfile].xres;
199 >                        curcol++;
200 >                } else {
201 >                        input[nfile].xloc = atoi(argv[an++]);
202 >                        input[nfile].yloc = atoi(argv[an++]);
203 >                }
204                  if (input[nfile].xloc < xmin)
205                          xmin = input[nfile].xloc;
206                  if (input[nfile].yloc < ymin)
# Line 162 | Line 209 | getfile:
209                          xmax = input[nfile].xloc+input[nfile].xres;
210                  if (input[nfile].yloc+input[nfile].yres > ymax)
211                          ymax = input[nfile].yloc+input[nfile].yres;
212 +                if (thislabel != NULL) {
213 +                        if (++nfile >= MAXFILE)
214 +                                goto toomany;
215 +                        input[nfile].name = "<Label>";
216 +                        input[nfile].hasmin = input[nfile].hasmax = 0;
217 +                        if ((input[nfile].fp = lblopen(thislabel,
218 +                                        &input[nfile].xres,
219 +                                        &input[nfile].yres)) == NULL)
220 +                                goto labelerr;
221 +                        input[nfile].xloc = input[nfile-1].xloc;
222 +                        input[nfile].yloc = input[nfile-1].yloc +
223 +                                        input[nfile-1].yres-input[nfile].yres;
224 +                }
225          }
226          if (xsiz <= 0)
227                  xsiz = xmax;
# Line 170 | Line 230 | getfile:
230                                          /* add new header info. */
231          printargs(argc, argv, stdout);
232          fputformat(COLRFMT, stdout);
233 <        printf("\n-Y %d +X %d\n", ysiz, xsiz);
233 >        putchar('\n');
234 >        fprtresolu(xsiz, ysiz, stdout);
235  
236          compos();
237          
238          quit(0);
239   userr:
240 <        fprintf(stderr, "Usage: %s [-x xres][-y yres][-b r g b] ", progname);
241 <        fprintf(stderr, "[-t min1][+t max1] file1 x1 y1 ..\n");
240 >        fprintf(stderr, "Usage: %s [-x xr][-y yr][-b r g b][-a n][-la][-lh h] ",
241 >                        progname);
242 >        fprintf(stderr, "[-t min1][+t max1][-l lab] pic1 x1 y1 ..\n");
243          quit(1);
244 + toomany:
245 +        fprintf(stderr, "%s: only %d files and labels allowed\n",
246 +                        progname, MAXFILE);
247 +        quit(1);
248 + labelerr:
249 +        fprintf(stderr, "%s: error opening label\n", progname);
250 +        quit(1);
251   }
252  
253  
# Line 254 | Line 323 | register COLR  c1, c2;
323                  if (i = c1[j] - c2[j])
324                          return(i);
325          return(0);
326 + }
327 +
328 +
329 + FILE *
330 + lblopen(s, xp, yp)              /* open pipe to label generator */
331 + char  *s;
332 + int  *xp, *yp;
333 + {
334 +        char  com[128];
335 +        FILE  *fp;
336 +
337 +        sprintf(com, "psign -h %d '%.30s' | pfilt -1 -x /2 -y /2",
338 +                        2*labelht, s);
339 +        if ((fp = popen(com, "r")) == NULL)
340 +                return(NULL);
341 +        if (checkheader(fp, COLRFMT, NULL) < 0)
342 +                goto err;
343 +        if (fgetresolu(xp, yp, fp) < 0)
344 +                goto err;
345 +        return(fp);
346 + err:
347 +        pclose(fp);
348 +        return(NULL);
349   }
350  
351  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines