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

Comparing ray/src/util/rad.c (file contents):
Revision 2.73 by greg, Sat Oct 18 04:46:24 2003 UTC vs.
Revision 2.77 by greg, Thu Sep 9 20:08:21 2004 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
11   #include <time.h>
12  
13   #include "platform.h"
14 + #include "rtprocess.h"
15   #include "view.h"
16   #include "paths.h"
17   #include "vars.h"
# Line 21 | Line 22 | static const char      RCSid[] = "$Id$";
22   #else
23    #define DELCMD "rm -f"
24    #define RENAMECMD "mv"
25 +  #include <sys/types.h>
26 +  #include <sys/wait.h>
27   #endif
28  
29                                  /* variables (alphabetical by name) */
# Line 106 | Line 109 | int    silent = 0;             /* do work silently */
109   int     touchonly = 0;          /* touch files only */
110   int     nprocs = 1;             /* maximum executing processes */
111   int     sayview = 0;            /* print view out */
112 < char    *rvdevice = NULL;       /* rview output device */
112 > char    *rvdevice = NULL;       /* rvu output device */
113   char    *viewselect = NULL;     /* specific view only */
114  
115   int     overture = 0;           /* overture calculation needed */
# Line 120 | Line 123 | char   radname[PATH_MAX];      /* root Radiance file name */
123  
124   #define inchild()       (children_running < 0)
125  
126 + static void rootname(char       *rn, char       *fn);
127 + static time_t checklast(char    *fnames);
128 + static char * newfname(char     *orig, int      pred);
129 + static void checkfiles(void);
130 + static void getoctcube(double   org[3], double  *sizp);
131 + static void setdefaults(void);
132 + static void oconv(void);
133 + static char * addarg(char       *op, char       *arg);
134 + static void oconvopts(char      *oo);
135 + static void mkillumopts(char    *mo);
136 + static void checkambfile(void);
137 + static double ambval(void);
138 + static void renderopts(char     *op, char       *po);
139 + static void lowqopts(char       *op, char       *po);
140 + static void medqopts(char       *op, char       *po);
141 + static void hiqopts(char        *op, char       *po);
142 + static void xferopts(char       *ro);
143 + static void pfiltopts(char      *po);
144 + static int matchword(char       *s1, char       *s2);
145 + static char * specview(char     *vs);
146 + static char * getview(int       n, char *vn);
147 + static int myprintview(char     *vopts, FILE    *fp);
148 + static void rvu(char    *opts, char     *po);
149 + static void rpict(char  *opts, char     *po);
150 + static int touch(char   *fn);
151 + static int runcom(char  *cs);
152 + static int rmfile(char  *fn);
153 + static int mvfile(char  *fold, char     *fnew);
154 + static int next_process(void);
155 + static void wait_process(int    all);
156 + static void finish_process(void);
157 + static void badvalue(int        vc);
158 + static void syserr(char *s);
159  
160 < main(argc, argv)
161 < int     argc;
162 < char    *argv[];
160 >
161 > int
162 > main(
163 >        int     argc,
164 >        char    *argv[]
165 > )
166   {
167          char    ropts[512];
168          char    popts[64];
# Line 199 | Line 238 | char   *argv[];
238          renderopts(ropts, popts);
239          xferopts(ropts);
240          if (rvdevice != NULL)
241 <                rview(ropts, popts);
241 >                rvu(ropts, popts);
242          else
243                  rpict(ropts, popts);
244          quit(0);
# Line 208 | Line 247 | userr:
247   "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
248                          progname);
249          quit(1);
250 +        return 1; /* pro forma return */
251   }
252  
253  
254 < rootname(rn, fn)                /* remove tail from end of fn */
255 < register char   *rn, *fn;
254 > static void
255 > rootname(               /* remove tail from end of fn */
256 >        register char   *rn,
257 >        register char   *fn
258 > )
259   {
260          char    *tp, *dp;
261  
# Line 226 | Line 269 | register char  *rn, *fn;
269   }
270  
271  
272 < time_t
273 < checklast(fnames)                       /* check files and find most recent */
274 < register char   *fnames;
272 > static time_t
273 > checklast(                      /* check files and find most recent */
274 >        register char   *fnames
275 > )
276   {
277          char    thisfile[PATH_MAX];
278          time_t  thisdate, lastdate = 0;
# Line 237 | Line 281 | register char  *fnames;
281                  return(0);
282          while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
283                  if (thisfile[0] == '!' ||
284 <                                (thisfile[0] == '\\' && thisfile[1] == '!'))
284 >                                (thisfile[0] == '\\' && thisfile[1] == '!')) {
285 >                        if (!lastdate)
286 >                                lastdate = 1;
287                          continue;
288 +                }
289                  if (!(thisdate = fdate(thisfile)))
290                          syserr(thisfile);
291                  if (thisdate > lastdate)
# Line 248 | Line 295 | register char  *fnames;
295   }
296  
297  
298 < char *
299 < newfname(orig, pred)            /* create modified file name */
300 < char    *orig;
301 < int     pred;
298 > static char *
299 > newfname(               /* create modified file name */
300 >        char    *orig,
301 >        int     pred
302 > )
303   {
304          register char   *cp;
305          register int    n;
# Line 273 | Line 321 | int    pred;
321   }
322  
323  
324 < checkfiles()                    /* check for existence and modified times */
324 > static void
325 > checkfiles(void)                        /* check for existence and modified times */
326   {
327          time_t  objdate;
328  
# Line 308 | Line 357 | checkfiles()                   /* check for existence and modified tim
357   }      
358  
359  
360 < getoctcube(org, sizp)           /* get octree bounding cube */
361 < double  org[3], *sizp;
360 > static void
361 > getoctcube(             /* get octree bounding cube */
362 >        double  org[3],
363 >        double  *sizp
364 > )
365   {
314        extern FILE     *popen();
366          static double   oorg[3], osiz = 0.;
367          double  min[3], max[3];
368          char    buf[1024];
# Line 359 | Line 410 | double org[3], *sizp;
410   }
411  
412  
413 < setdefaults()                   /* set default values for unassigned var's */
413 > static void
414 > setdefaults(void)                       /* set default values for unassigned var's */
415   {
416          double  org[3], lim[3], size;
417          char    buf[128];
# Line 416 | Line 468 | setdefaults()                  /* set default values for unassigned v
468   }
469  
470  
471 < oconv()                         /* run oconv and mkillum if necessary */
471 > static void
472 > oconv(void)                             /* run oconv and mkillum if necessary */
473   {
474          static char     illumtmp[] = "ilXXXXXX";
475          char    combuf[PATH_MAX], ocopts[64], mkopts[64];
# Line 518 | Line 571 | oconv()                                /* run oconv and mkillum if necessary */
571   }
572  
573  
574 < char *
575 < addarg(op, arg)                         /* add argument and advance pointer */
576 < register char   *op, *arg;
574 > static char *
575 > addarg(                         /* add argument and advance pointer */
576 > register char   *op,
577 > register char   *arg
578 > )
579   {
580          *op = ' ';
581          while ( (*++op = *arg++) )
# Line 529 | Line 584 | register char  *op, *arg;
584   }
585  
586  
587 < oconvopts(oo)                           /* get oconv options */
588 < register char   *oo;
587 > static void
588 > oconvopts(                              /* get oconv options */
589 >        register char   *oo
590 > )
591   {
592          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
593  
# Line 540 | Line 597 | register char  *oo;
597   }
598  
599  
600 < mkillumopts(mo)                         /* get mkillum options */
601 < register char   *mo;
600 > static void
601 > mkillumopts(                            /* get mkillum options */
602 >        register char   *mo
603 > )
604   {
605          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
606  
# Line 551 | Line 610 | register char  *mo;
610   }
611  
612  
613 < checkambfile()                  /* check date on ambient file */
613 > static void
614 > checkambfile(void)                      /* check date on ambient file */
615   {
616          time_t  afdate;
617  
# Line 568 | Line 628 | checkambfile()                 /* check date on ambient file */
628   }
629  
630  
631 < double
632 < ambval()                                /* compute ambient value */
631 > static double
632 > ambval(void)                            /* compute ambient value */
633   {
634          if (vdef(EXPOSURE)) {
635                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
# Line 581 | Line 641 | ambval()                               /* compute ambient value */
641          if (vlet(ZONE) == 'I')
642                  return(.01);
643          badvalue(ZONE);
644 +        return 0; /* pro forma return */
645   }
646  
647  
648 < renderopts(op, po)                      /* set rendering options */
649 < char    *op, *po;
648 > static void
649 > renderopts(                     /* set rendering options */
650 >        char    *op,
651 >        char    *po
652 > )
653   {
654          switch(vscale(QUALITY)) {
655          case LOW:
# Line 601 | Line 665 | char   *op, *po;
665   }
666  
667  
668 < lowqopts(op, po)                        /* low quality rendering options */
669 < register char   *op;
670 < char    *po;
668 > static void
669 > lowqopts(                       /* low quality rendering options */
670 >        register char   *op,
671 >        char    *po
672 > )
673   {
674          double  d, org[3], siz[3];
675  
# Line 669 | Line 735 | char   *po;
735   }
736  
737  
738 < medqopts(op, po)                        /* medium quality rendering options */
739 < register char   *op;
740 < char    *po;
738 > static void
739 > medqopts(                       /* medium quality rendering options */
740 >        register char   *op,
741 >        char    *po
742 > )
743   {
744          double  d, org[3], siz[3], asz;
745  
# Line 747 | Line 815 | char   *po;
815   }
816  
817  
818 < hiqopts(op, po)                         /* high quality rendering options */
819 < register char   *op;
820 < char    *po;
818 > static void
819 > hiqopts(                                /* high quality rendering options */
820 >        register char   *op,
821 >        char    *po
822 > )
823   {
824          double  d, org[3], siz[3], asz;
825  
# Line 823 | Line 893 | char   *po;
893   }
894  
895  
896 < xferopts(ro)                            /* transfer options if indicated */
897 < char    *ro;
896 > static void
897 > xferopts(                               /* transfer options if indicated */
898 >        char    *ro
899 > )
900   {
901          int     fd, n;
902          register char   *cp;
# Line 854 | Line 926 | char   *ro;
926   }
927  
928  
929 < pfiltopts(po)                           /* get pfilt options */
930 < register char   *po;
929 > static void
930 > pfiltopts(                              /* get pfilt options */
931 >        register char   *po
932 > )
933   {
934          *po = '\0';
935          if (vdef(EXPOSURE)) {
# Line 875 | Line 949 | register char  *po;
949   }
950  
951  
952 < matchword(s1, s2)                       /* match white-delimited words */
953 < register char   *s1, *s2;
952 > static int
953 > matchword(                      /* match white-delimited words */
954 >        register char   *s1,
955 >        register char   *s2
956 > )
957   {
958          while (isspace(*s1)) s1++;
959          while (isspace(*s2)) s2++;
# Line 887 | Line 964 | register char  *s1, *s2;
964   }
965  
966  
967 < char *
968 < specview(vs)                            /* get proper view spec from vs */
969 < register char   *vs;
967 > static char *
968 > specview(                               /* get proper view spec from vs */
969 >        register char   *vs
970 > )
971   {
972          static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
973                          "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
# Line 1011 | Line 1089 | register char  *vs;
1089   }
1090  
1091  
1092 < char *
1093 < getview(n, vn)                          /* get view n, or NULL if none */
1094 < int     n;
1095 < char    *vn;            /* returned view name */
1092 > static char *
1093 > getview(                                /* get view n, or NULL if none */
1094 >        int     n,
1095 >        char    *vn             /* returned view name */
1096 > )
1097   {
1098          register char   *mv;
1099  
# Line 1052 | Line 1131 | char   *vn;            /* returned view name */
1131   }
1132  
1133  
1134 < int
1135 < myprintview(vopts, fp)                  /* print out selected view */
1136 < register char   *vopts;
1137 < FILE    *fp;
1134 > static int
1135 > myprintview(                    /* print out selected view */
1136 >        register char   *vopts,
1137 >        FILE    *fp
1138 > )
1139   {
1140          VIEW    vwr;
1141          char    buf[128];
1142          register char   *cp;
1063 again:
1143          if (vopts == NULL)
1144                  return(-1);
1145   #ifdef _WIN32
# Line 1083 | Line 1162 | again:
1162   }
1163  
1164  
1165 < rview(opts, po)                         /* run rview with first view */
1166 < char    *opts, *po;
1165 > static void
1166 > rvu(                            /* run rvu with first view */
1167 >        char    *opts,
1168 >        char    *po
1169 > )
1170   {
1171          char    *vw;
1172          char    combuf[PATH_MAX];
# Line 1093 | Line 1175 | char   *opts, *po;
1175                  return;
1176          if (sayview)
1177                  myprintview(vw, stdout);
1178 <        sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1178 >        sprintf(combuf, "rvu %s%s%s -R %s ", vw, po, opts, rifname);
1179          if (rvdevice != NULL)
1180                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1181          if (vdef(EXPOSURE))
1182                  sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1183          strcat(combuf, oct1name);
1184          if (runcom(combuf)) {           /* run it */
1185 <                fprintf(stderr, "%s: error running rview\n", progname);
1185 >                fprintf(stderr, "%s: error running rvu\n", progname);
1186                  quit(1);
1187          }
1188   }
1189  
1190  
1191 < rpict(opts, po)                         /* run rpict and pfilt for each view */
1192 < char    *opts, *po;
1191 > static void
1192 > rpict(                          /* run rpict and pfilt for each view */
1193 >        char    *opts,
1194 >        char    *po
1195 > )
1196   {
1197          char    combuf[PATH_MAX];
1198          char    rawfile[PATH_MAX], picfile[PATH_MAX];
# Line 1284 | Line 1369 | rperror:
1369   }
1370  
1371  
1372 < touch(fn)                       /* update a file */
1373 < char    *fn;
1372 > static int
1373 > touch(                  /* update a file */
1374 >        char    *fn
1375 > )
1376   {
1377          if (!silent)
1378                  printf("\ttouch %s\n", fn);
# Line 1300 | Line 1387 | char   *fn;
1387   }
1388  
1389  
1390 < runcom(cs)                      /* run command */
1391 < char    *cs;
1390 > static int
1391 > runcom(                 /* run command */
1392 >        char    *cs
1393 > )
1394   {
1395          if (!silent)            /* echo it */
1396                  printf("\t%s\n", cs);
# Line 1312 | Line 1401 | char   *cs;
1401   }
1402  
1403  
1404 < rmfile(fn)                      /* remove a file */
1405 < char    *fn;
1404 > static int
1405 > rmfile(                 /* remove a file */
1406 >        char    *fn
1407 > )
1408   {
1409          if (!silent)
1410                  printf("\t%s %s\n", DELCMD, fn);
# Line 1323 | Line 1414 | char   *fn;
1414   }
1415  
1416  
1417 < mvfile(fold, fnew)              /* move a file */
1418 < char    *fold, *fnew;
1417 > static int
1418 > mvfile(         /* move a file */
1419 >        char    *fold,
1420 >        char    *fnew
1421 > )
1422   {
1423          if (!silent)
1424                  printf("\t%s %s %s\n", RENAMECMD, fold, fnew);
# Line 1335 | Line 1429 | char   *fold, *fnew;
1429  
1430  
1431   #ifdef RHAS_FORK_EXEC
1432 < int
1433 < next_process()                  /* fork the next process (max. nprocs) */
1432 > static int
1433 > next_process(void)                      /* fork the next process (max. nprocs) */
1434   {
1435          int     child_pid;
1436  
# Line 1363 | Line 1457 | next_process()                 /* fork the next process (max. nprocs
1457          return(0);
1458   }
1459  
1460 < wait_process(all)                       /* wait for process(es) to finish */
1461 < int     all;
1460 > static void
1461 > wait_process(                   /* wait for process(es) to finish */
1462 >        int     all
1463 > )
1464   {
1465          int     ourstatus = 0;
1466          int     pid, status;
# Line 1391 | Line 1487 | int    all;
1487                  quit(ourstatus);        /* bad status from child */
1488   }
1489   #else   /* ! RHAS_FORK_EXEC */
1490 < int
1491 < next_process()
1490 > static int
1491 > next_process(void)
1492   {
1493          return(0);                      /* cannot start new process */
1494   }
1495 + static void
1496   wait_process(all)
1497   int     all;
1498   {
# Line 1409 | Line 1506 | int pid, sig;
1506   }
1507   #endif  /* ! RHAS_FORK_EXEC */
1508  
1509 < finish_process()                        /* exit a child process */
1509 > static void
1510 > finish_process(void)                    /* exit a child process */
1511   {
1512          if (!inchild())
1513                  return;                 /* in parent -- noop */
# Line 1436 | Line 1534 | char   *vname, *value;
1534   #endif
1535  
1536  
1537 < badvalue(vc)                    /* report bad variable value and exit */
1538 < int     vc;
1537 > static void
1538 > badvalue(                       /* report bad variable value and exit */
1539 >        int     vc
1540 > )
1541   {
1542          fprintf(stderr, "%s: bad value for variable '%s'\n",
1543                          progname, vnam(vc));
# Line 1445 | Line 1545 | int    vc;
1545   }
1546  
1547  
1548 < syserr(s)                       /* report a system error and exit */
1549 < char    *s;
1548 > static void
1549 > syserr(                 /* report a system error and exit */
1550 >        char    *s
1551 > )
1552   {
1553          perror(s);
1554          quit(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines