--- ray/src/util/ranimate.c 2003/02/25 02:47:24 2.31 +++ ray/src/util/ranimate.c 2003/10/27 10:32:06 2.43 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ranimate.c,v 2.31 2003/02/25 02:47:24 greg Exp $"; +static const char RCSid[] = "$Id: ranimate.c,v 2.43 2003/10/27 10:32:06 schorsch Exp $"; #endif /* * Radiance animation control program @@ -15,9 +15,16 @@ static const char RCSid[] = "$Id: ranimate.c,v 2.31 20 #include "copyright.h" -#include "standard.h" +#include #include #include +#include + +/*#include "standard.h"*/ +#include "platform.h" +#include "paths.h" +#include "rtio.h" +#include "rterror.h" #include "view.h" #include "vars.h" #include "netproc.h" @@ -26,11 +33,7 @@ static const char RCSid[] = "$Id: ranimate.c,v 2.31 20 #define DEF_NBLUR 5 #endif /* default remote shell */ -#ifdef _AUX_SOURCE -#define REMSH "remsh" -#else #define REMSH "rsh" -#endif /* input variables (alphabetical by name) */ #define ANIMATE 0 /* animation command */ #define ARCHIVE 1 /* archiving command */ @@ -119,16 +122,39 @@ struct pslot { int npslots; /* number of process slots */ #define phostname(ps) ((ps)->hostname[0] ? (ps)->hostname : astat.host) - -struct pslot *findpslot(); - PSERVER *lastpserver; /* last process server with error */ -VIEW *getview(); -char *getexp(), *dirfile(); -int getblur(); +static struct pslot * findpslot(int pid); +static void checkdir(void); +static VIEW * getview(int n); -extern time_t time(); +static char * dirfile(char *df, register char *path); +static char * getexp(int n); +static int getblur(double *bf); +static int getastat(void); +static void getradfile(char *rfargs); +static void badvalue(int vc); +static int rmfile(char *fn); +static int runcom(char *cs); +static int pruncom(char *com, char *ppins, int maxcopies); +static void bwait(int ncoms); +static int bruncom(char *com, int fout, int (*rf)()); +static int serverdown(void); +static int donecom(PSERVER *ps, int pn, int status); +static int countviews(void); +static int dofilt(int frame, int rvr); +static void archive(void); +static int frecover(int frame); +static int recover(int frame); +static void sethosts(void); +static void walkwait(int first, int last, char *vfn); +static void animrend(int frame, VIEW *vp); +static void transferframes(void); +static void filterframes(void); +static void renderframes(int nframes); +static void animate(void); +static void setdefaults(void); +static void putastat(void); main(argc, argv) @@ -202,7 +228,8 @@ userr: } -getastat() /* check/set animation status */ +static int +getastat(void) /* check/set animation status */ { char sfname[256]; FILE *fp; @@ -266,7 +293,8 @@ fmterr: } -putastat() /* put out current status */ +static void +putastat(void) /* put out current status */ { char buf[256]; FILE *fp; @@ -288,7 +316,8 @@ putastat() /* put out current status */ } -checkdir() /* make sure we have our directory */ +static void +checkdir(void) /* make sure we have our directory */ { struct stat stb; @@ -310,7 +339,8 @@ checkdir() /* make sure we have our directory */ } -setdefaults() /* set default values */ +static void +setdefaults(void) /* set default values */ { extern char *atos(); int decades; @@ -398,7 +428,8 @@ setdefaults() /* set default values */ } -sethosts() /* set up process servers */ +static void +sethosts(void) /* set up process servers */ { extern char *iskip(); char buf[256], *dir, *uname; @@ -453,9 +484,8 @@ sethosts() /* set up process servers */ } } - -getradfile(rfargs) /* run rad and get needed variables */ -char *rfargs; +static void +getradfile(char *rfargs) /* run rad and get needed variables */ { static short mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1}; char combuf[256]; @@ -480,7 +510,7 @@ char *rfargs; pippt = NULL; } if (pippt != NULL) - strcpy(pippt, "> /dev/null"); /* nothing to match */ + strcpy(pippt, "> " NULL_DEVICE); /* nothing to match */ else { sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); cp += 11; /* point to file name */ @@ -493,7 +523,8 @@ char *rfargs; } -animate() /* run animation */ +static void +animate(void) /* run animation */ { int xres, yres; float pa, mult; @@ -564,8 +595,8 @@ animate() /* run animation */ } -renderframes(nframes) /* render next nframes frames */ -int nframes; +static void +renderframes(int nframes) /* render next nframes frames */ { static char vendbuf[16]; VIEW *vp; @@ -621,7 +652,8 @@ int nframes; } -filterframes() /* catch up with filtering */ +static void +filterframes(void) /* catch up with filtering */ { VIEW *vp; register int i; @@ -629,15 +661,9 @@ filterframes() /* catch up with filtering */ if (astat.tnext < astat.fnext) /* other work to do first */ return; /* filter each view */ - for (i = astat.fnext; i < astat.rnext; i++) { - if ((vp = getview(i)) == NULL) { /* get view i */ - fprintf(stderr, - "%s: unexpected error reading view for frame %d\n", - progname, i); - quit(1); - } - dofilt(i, vp, getexp(i), 0); /* filter frame */ - } + for (i = astat.fnext; i < astat.rnext; i++) + dofilt(i, 0); + bwait(0); /* wait for filter processes */ archive(); /* archive originals */ astat.fnext = i; /* update status */ @@ -645,7 +671,8 @@ filterframes() /* catch up with filtering */ } -transferframes() /* catch up with picture transfers */ +static void +transferframes(void) /* catch up with picture transfers */ { char combuf[10240], *fbase; register char *cp; @@ -685,9 +712,11 @@ transferframes() /* catch up with picture transfers } -animrend(frame, vp) /* start animation frame */ -int frame; -VIEW *vp; +static void +animrend( /* start animation frame */ +int frame, +VIEW *vp +) { extern int recover(); char combuf[2048]; @@ -703,9 +732,12 @@ VIEW *vp; } -walkwait(first, last, vfn) /* walk-through frames */ -int first, last; -char *vfn; +static void +walkwait( /* walk-through frames */ +int first, +int last, +char *vfn +) { double blurf; int nblur = getblur(&blurf); @@ -755,9 +787,8 @@ char *vfn; } -int -recover(frame) /* recover the specified frame */ -int frame; +static int +recover(int frame) /* recover the specified frame */ { static int *rfrm; /* list of recovered frames */ static int nrfrms = 0; @@ -798,7 +829,7 @@ int frame; return(1); /* add frame to recovered list */ if (nrfrms) - rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int)); + rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int)); else rfrm = (int *)malloc(sizeof(int)); if (rfrm == NULL) { @@ -810,22 +841,17 @@ int frame; } -int -frecover(frame) /* recover filtered frame */ -int frame; +static int +frecover(int frame) /* recover filtered frame */ { - VIEW *vp; - char *ex; - - vp = getview(frame); - ex = getexp(frame); - if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1)) + if (dofilt(frame, 2) && dofilt(frame, 1)) return(1); return(0); } -archive() /* archive and remove renderings */ +static void +archive(void) /* archive and remove renderings */ { #define RMCOML (sizeof(rmcom)-1) static char rmcom[] = "rm -f"; @@ -868,24 +894,37 @@ archive() /* archive and remove renderings */ } -int -dofilt(frame, vp, ep, rvr) /* filter frame */ -int frame; -VIEW *vp; -char *ep; -int rvr; +static int +dofilt( /* filter frame */ +int frame, +int rvr +) { extern int frecover(); static int iter = 0; double blurf; int nblur = getblur(&blurf); + VIEW *vp = getview(frame); + char *ep = getexp(frame); char fnbefore[128], fnafter[128], *fbase; char combuf[1024], fname0[128], fname1[128]; int usepinterp, usepfilt, nora_rgbe; int frseq[2]; /* check what is needed */ + if (vp == NULL) { + fprintf(stderr, + "%s: unexpected error reading view for frame %d\n", + progname, frame); + quit(1); + } + if (ep == NULL) { + fprintf(stderr, + "%s: unexpected error reading exposure for frame %d\n", + progname, frame); + quit(1); + } usepinterp = (nblur > 1); - usepfilt = pfiltalways | ep==NULL; + usepfilt = pfiltalways | (ep==NULL); if (ep != NULL && !strcmp(ep, "1")) ep = "+0"; nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL || @@ -971,7 +1010,7 @@ int rvr; if (usepfilt) sprintf(combuf+strlen(combuf), " %s", rresopt); else - sprintf(combuf+strlen(combuf), "-a %s -e %s", + sprintf(combuf+strlen(combuf), " -a %s -e %s", fresopt, ep); sprintf(combuf+strlen(combuf), " %s.unf %s.zbf", fnbefore, fnbefore); @@ -1018,9 +1057,8 @@ int rvr; } -VIEW * -getview(n) /* get view number n */ -int n; +static VIEW * +getview(int n) /* get view number n */ { static FILE *viewfp = NULL; /* view file pointer */ static int viewnum = 0; /* current view number */ @@ -1032,7 +1070,7 @@ int n; fclose(viewfp); viewfp = NULL; viewnum = 0; - copystruct(&curview, &stdview); + curview = stdview; } return(NULL); } @@ -1048,7 +1086,7 @@ int n; perror(vval(VIEWFILE)); quit(1); } - copystruct(&curview, &stdview); + curview = stdview; viewnum = 0; } if (n < 0) { /* get next view */ @@ -1068,8 +1106,8 @@ int n; } -int -countviews() /* count views in view file */ +static int +countviews(void) /* count views in view file */ { int n; @@ -1081,9 +1119,8 @@ countviews() /* count views in view file */ } -char * -getexp(n) /* get exposure for nth frame */ -int n; +static char * +getexp(int n) /* get exposure for nth frame */ { extern char *fskip(); static char expval[32]; @@ -1152,9 +1189,8 @@ int n; } -struct pslot * -findpslot(pid) /* find or allocate a process slot */ -int pid; +static struct pslot * +findpslot(int pid) /* find or allocate a process slot */ { register struct pslot *psempty = NULL; register int i; @@ -1169,13 +1205,14 @@ int pid; } -int -donecom(ps, pn, status) /* clean up after finished process */ -PSERVER *ps; -int pn; -int status; +static int +donecom( /* clean up after finished process */ +PSERVER *ps, +int pn, +int status +) { - register PROC *pp; + register NETPROC *pp; register struct pslot *psl; pp = ps->proc + pn; @@ -1210,8 +1247,8 @@ int status; } -int -serverdown() /* check status of last process server */ +static int +serverdown(void) /* check status of last process server */ { if (lastpserver == NULL || !lastpserver->hostname[0]) return(0); @@ -1227,11 +1264,12 @@ serverdown() /* check status of last process server } -int -bruncom(com, fout, rf) /* run a command in the background */ -char *com; -int fout; -int (*rf)(); +static int +bruncom( /* run a command in the background */ +char *com, +int fout, +int (*rf)() +) { int pid; register struct pslot *psl; @@ -1260,8 +1298,8 @@ int (*rf)(); } -bwait(ncoms) /* wait for batch job(s) to finish */ -int ncoms; +static void +bwait(int ncoms) /* wait for batch job(s) to finish */ { int status; @@ -1275,10 +1313,12 @@ int ncoms; } -int -pruncom(com, ppins, maxcopies) /* run a command in parallel over network */ -char *com, *ppins; -int maxcopies; +static int +pruncom( /* run a command in parallel over network */ +char *com, +char *ppins, +int maxcopies +) { int retstatus = 0; int hostcopies; @@ -1300,6 +1340,7 @@ int maxcopies; strcpy(com1=buf, com); /* build -PP command */ sprintf(com1+(ppins-com), " -PP %s/%s.persist", vval(DIRECTORY), phostname(ps)); + unlink(com1+(ppins-com)+5); strcat(com1, ppins); } else com1 = com; @@ -1344,8 +1385,8 @@ int maxcopies; } -runcom(cs) /* run a command locally and wait for it */ -char *cs; +static int +runcom(char *cs) /* run a command locally and wait for it */ { if (!silent) /* echo it */ printf("\t%s\n", cs); @@ -1356,11 +1397,11 @@ char *cs; } -rmfile(fn) /* remove a file */ -char *fn; +static int +rmfile(char *fn) /* remove a file */ { if (!silent) -#ifdef MSDOS +#ifdef _WIN32 printf("\tdel %s\n", fn); #else printf("\trm -f %s\n", fn); @@ -1371,8 +1412,8 @@ char *fn; } -badvalue(vc) /* report bad variable value and exit */ -int vc; +static void +badvalue(int vc) /* report bad variable value and exit */ { fprintf(stderr, "%s: bad value for variable '%s'\n", progname, vnam(vc)); @@ -1380,10 +1421,11 @@ int vc; } -char * -dirfile(df, path) /* separate path into directory and file */ -char *df; -register char *path; +static char * +dirfile( /* separate path into directory and file */ +char *df, +register char *path +) { register int i; int psep; @@ -1391,7 +1433,7 @@ register char *path; for (i = 0, psep = -1; path[i]; i++) if (path[i] == '/') psep = i; - if (df != NULL) + if (df != NULL) { if (psep == 0) { df[0] = '/'; df[1] = '\0'; @@ -1400,11 +1442,12 @@ register char *path; df[psep] = '\0'; } else df[0] = '\0'; + } return(path+psep+1); } -int +static int getblur(double *bf) /* get # blur samples (and fraction) */ { double blurf;