--- ray/src/util/rad.c 2004/01/01 19:31:46 2.75 +++ ray/src/util/rad.c 2008/12/18 23:26:57 2.91 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rad.c,v 2.75 2004/01/01 19:31:46 greg Exp $"; +static const char RCSid[] = "$Id: rad.c,v 2.91 2008/12/18 23:26:57 greg Exp $"; #endif /* * Executive program for oconv, rpict and pfilt @@ -22,6 +22,8 @@ static const char RCSid[] = "$Id: rad.c,v 2.75 2004/01 #else #define DELCMD "rm -f" #define RENAMECMD "mv" + #include + #include #endif /* variables (alphabetical by name) */ @@ -45,14 +47,16 @@ static const char RCSid[] = "$Id: rad.c,v 2.75 2004/01 #define RENDER 17 /* rendering options */ #define REPORT 18 /* report frequency and errfile */ #define RESOLUTION 19 /* maximum picture resolution */ -#define SCENE 20 /* scene files */ -#define UP 21 /* view up (X, Y or Z) */ -#define VARIABILITY 22 /* level of light variability */ -#define VIEWS 23 /* view(s) for picture(s) */ -#define ZFILE 24 /* distance file root name */ -#define ZONE 25 /* simulation zone */ +#define RPICT 20 /* rpict parameters */ +#define RVU 21 /* rvu parameters */ +#define SCENE 22 /* scene files */ +#define UP 23 /* view up (X, Y or Z) */ +#define VARIABILITY 24 /* level of light variability */ +#define VIEWS 25 /* view(s) for picture(s) */ +#define ZFILE 26 /* distance file root name */ +#define ZONE 27 /* simulation zone */ /* total number of variables */ -int NVARS = 26; +int NVARS = 28; VARIABLE vv[] = { /* variable-value pairs */ {"AMBFILE", 3, 0, NULL, onevalue}, @@ -75,6 +79,8 @@ VARIABLE vv[] = { /* variable-value pairs */ {"render", 3, 0, NULL, catvalues}, {"REPORT", 3, 0, NULL, onevalue}, {"RESOLUTION", 3, 0, NULL, onevalue}, + {"rpict", 3, 0, NULL, catvalues}, + {"rvu", 3, 0, NULL, catvalues}, {"scene", 3, 0, NULL, catvalues}, {"UP", 2, 0, NULL, onevalue}, {"VARIABILITY", 3, 0, NULL, qualvalue}, @@ -110,6 +116,13 @@ int sayview = 0; /* print view out */ char *rvdevice = NULL; /* rvu output device */ char *viewselect = NULL; /* specific view only */ + /* command paths */ +char c_oconv[256] = "oconv"; +char c_mkillum[256] = "mkillum"; +char c_rvu[256] = "rvu"; +char c_rpict[256] = "rpict"; +char c_pfilt[256] = "pfilt"; + int overture = 0; /* overture calculation needed */ int children_running = 0; /* set negative in children */ @@ -121,10 +134,46 @@ char radname[PATH_MAX]; /* root Radiance file name */ #define inchild() (children_running < 0) +static void rootname(char *rn, char *fn); +static time_t checklast(char *fnames); +static char * newfname(char *orig, int pred); +static void checkfiles(void); +static void getoctcube(double org[3], double *sizp); +static void setdefaults(void); +static void oconv(void); +static char * addarg(char *op, char *arg); +static void oconvopts(char *oo); +static void mkillumopts(char *mo); +static void checkambfile(void); +static double ambval(void); +static void renderopts(char *op, char *po); +static void lowqopts(char *op, char *po); +static void medqopts(char *op, char *po); +static void hiqopts(char *op, char *po); +static void xferopts(char *ro); +static void pfiltopts(char *po); +static int matchword(char *s1, char *s2); +static char * specview(char *vs); +static char * getview(int n, char *vn); +static int myprintview(char *vopts, FILE *fp); +static void rvu(char *opts, char *po); +static void rpict(char *opts, char *po); +static int touch(char *fn); +static int runcom(char *cs); +static int rmfile(char *fn); +static int mvfile(char *fold, char *fnew); +static int next_process(void); +static void wait_process(int all); +static void finish_process(void); +static void badvalue(int vc); +static void syserr(char *s); -main(argc, argv) -int argc; -char *argv[]; + +int +main( + int argc, + char *argv[] +) { char ropts[512]; char popts[64]; @@ -170,7 +219,7 @@ char *argv[]; goto userr; rifname = argv[i]; /* check command-line options */ - if ((nprocs > 1) & (viewselect != NULL)) + if ((nprocs > 1) & (viewselect != NULL) & (rvdevice == NULL)) nprocs = 1; /* assign Radiance root file name */ rootname(radname, rifname); @@ -209,11 +258,15 @@ userr: "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", progname); quit(1); + return 1; /* pro forma return */ } -rootname(rn, fn) /* remove tail from end of fn */ -register char *rn, *fn; +static void +rootname( /* remove tail from end of fn */ + register char *rn, + register char *fn +) { char *tp, *dp; @@ -227,9 +280,10 @@ register char *rn, *fn; } -time_t -checklast(fnames) /* check files and find most recent */ -register char *fnames; +static time_t +checklast( /* check files and find most recent */ + register char *fnames +) { char thisfile[PATH_MAX]; time_t thisdate, lastdate = 0; @@ -238,8 +292,11 @@ register char *fnames; return(0); while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) { if (thisfile[0] == '!' || - (thisfile[0] == '\\' && thisfile[1] == '!')) + (thisfile[0] == '\\' && thisfile[1] == '!')) { + if (!lastdate) + lastdate = 1; continue; + } if (!(thisdate = fdate(thisfile))) syserr(thisfile); if (thisdate > lastdate) @@ -249,10 +306,11 @@ register char *fnames; } -char * -newfname(orig, pred) /* create modified file name */ -char *orig; -int pred; +static char * +newfname( /* create modified file name */ + char *orig, + int pred +) { register char *cp; register int n; @@ -274,7 +332,8 @@ int pred; } -checkfiles() /* check for existence and modified times */ +static void +checkfiles(void) /* check for existence and modified times */ { time_t objdate; @@ -309,8 +368,11 @@ checkfiles() /* check for existence and modified tim } -getoctcube(org, sizp) /* get octree bounding cube */ -double org[3], *sizp; +static void +getoctcube( /* get octree bounding cube */ + double org[3], + double *sizp +) { static double oorg[3], osiz = 0.; double min[3], max[3]; @@ -359,7 +421,8 @@ double org[3], *sizp; } -setdefaults() /* set default values for unassigned var's */ +static void +setdefaults(void) /* set default values for unassigned var's */ { double org[3], lim[3], size; char buf[128]; @@ -416,10 +479,11 @@ setdefaults() /* set default values for unassigned v } -oconv() /* run oconv and mkillum if necessary */ +static void +oconv(void) /* run oconv and mkillum if necessary */ { static char illumtmp[] = "ilXXXXXX"; - char combuf[PATH_MAX], ocopts[64], mkopts[64]; + char combuf[PATH_MAX], ocopts[64], mkopts[1024]; oconvopts(ocopts); /* get options */ if (octreedate < scenedate) { /* check date on original octree */ @@ -427,11 +491,11 @@ oconv() /* run oconv and mkillum if necessary */ touch(vval(OCTREE)); else { /* build command */ if (vdef(MATERIAL)) - sprintf(combuf, "oconv%s %s %s > %s", ocopts, - vval(MATERIAL), vval(SCENE), - vval(OCTREE)); + sprintf(combuf, "%s%s %s %s > %s", c_oconv, + ocopts, vval(MATERIAL), + vval(SCENE), vval(OCTREE)); else - sprintf(combuf, "oconv%s %s > %s", ocopts, + sprintf(combuf, "%s%s %s > %s", c_oconv, ocopts, vval(SCENE), vval(OCTREE)); if (runcom(combuf)) { /* run it */ @@ -457,14 +521,16 @@ oconv() /* run oconv and mkillum if necessary */ touch(oct0name); else { /* build command */ if (octreedate) - sprintf(combuf, "oconv%s -i %s %s > %s", ocopts, - vval(OCTREE), vval(ILLUM), oct0name); + sprintf(combuf, "%s%s -i %s %s > %s", c_oconv, + ocopts, vval(OCTREE), + vval(ILLUM), oct0name); else if (vdef(MATERIAL)) - sprintf(combuf, "oconv%s %s %s > %s", ocopts, - vval(MATERIAL), vval(ILLUM), oct0name); - else - sprintf(combuf, "oconv%s %s > %s", ocopts, + sprintf(combuf, "%s%s %s %s > %s", c_oconv, + ocopts, vval(MATERIAL), vval(ILLUM), oct0name); + else + sprintf(combuf, "%s%s %s > %s", c_oconv, + ocopts, vval(ILLUM), oct0name); if (runcom(combuf)) { /* run it */ fprintf(stderr, "%s: error generating octree\n\t%s removed\n", @@ -484,23 +550,23 @@ oconv() /* run oconv and mkillum if necessary */ else { mkillumopts(mkopts); /* build mkillum command */ mktemp(illumtmp); - sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts, + sprintf(combuf, "%s%s %s \"<\" %s > %s", c_mkillum, mkopts, oct0name, vval(ILLUM), illumtmp); if (runcom(combuf)) { /* run it */ - fprintf(stderr, "%s: error running mkillum\n", - progname); + fprintf(stderr, "%s: error running %s\n", + progname, c_mkillum); unlink(illumtmp); quit(1); } /* make octree1 (frozen) */ if (octreedate) - sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts, - vval(OCTREE), illumtmp, oct1name); + sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv, + ocopts, vval(OCTREE), illumtmp, oct1name); else if (vdef(MATERIAL)) - sprintf(combuf, "oconv%s -f %s %s > %s", ocopts, - vval(MATERIAL), illumtmp, oct1name); + sprintf(combuf, "%s%s -f %s %s > %s", c_oconv, + ocopts, vval(MATERIAL), illumtmp, oct1name); else - sprintf(combuf, "oconv%s -f %s > %s", ocopts, + sprintf(combuf, "%s%s -f %s > %s", c_oconv, ocopts, illumtmp, oct1name); if (runcom(combuf)) { /* run it */ fprintf(stderr, @@ -518,10 +584,14 @@ oconv() /* run oconv and mkillum if necessary */ } -char * -addarg(op, arg) /* add argument and advance pointer */ -register char *op, *arg; +static char * +addarg( /* append argument and advance pointer */ +register char *op, +register char *arg +) { + while (*op) + op++; *op = ' '; while ( (*++op = *arg++) ) ; @@ -529,29 +599,45 @@ register char *op, *arg; } -oconvopts(oo) /* get oconv options */ -register char *oo; +static void +oconvopts( /* get oconv options */ + register char *oo +) { /* BEWARE: This may be called via setdefaults(), so no assumptions */ *oo = '\0'; if (vdef(OCONV)) - addarg(oo, vval(OCONV)); + if (vval(OCONV)[0] != '-') { + atos(c_oconv, sizeof(c_oconv), vval(OCONV)); + oo = addarg(oo, sskip2(vval(OCONV), 1)); + } else + oo = addarg(oo, vval(OCONV)); } -mkillumopts(mo) /* get mkillum options */ -register char *mo; +static void +mkillumopts( /* get mkillum options */ + char *mo +) { /* BEWARE: This may be called via setdefaults(), so no assumptions */ - *mo = '\0'; + if (nprocs > 1) + sprintf(mo, " -n %d", nprocs); + else + *mo = '\0'; if (vdef(MKILLUM)) - addarg(mo, vval(MKILLUM)); + if (vval(MKILLUM)[0] != '-') { + atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM)); + mo = addarg(mo, sskip2(vval(MKILLUM), 1)); + } else + mo = addarg(mo, vval(MKILLUM)); } -checkambfile() /* check date on ambient file */ +static void +checkambfile(void) /* check date on ambient file */ { time_t afdate; @@ -568,8 +654,8 @@ checkambfile() /* check date on ambient file */ } -double -ambval() /* compute ambient value */ +static double +ambval(void) /* compute ambient value */ { if (vdef(EXPOSURE)) { if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-') @@ -581,11 +667,15 @@ ambval() /* compute ambient value */ if (vlet(ZONE) == 'I') return(.01); badvalue(ZONE); + return 0; /* pro forma return */ } -renderopts(op, po) /* set rendering options */ -char *op, *po; +static void +renderopts( /* set rendering options */ + char *op, + char *po +) { switch(vscale(QUALITY)) { case LOW: @@ -598,12 +688,31 @@ char *op, *po; hiqopts(op, po); break; } + if (vdef(RENDER)) + op = addarg(op, vval(RENDER)); + if (rvdevice != NULL) { + if (vdef(RVU)) + if (vval(RVU)[0] != '-') { + atos(c_rvu, sizeof(c_rvu), vval(RVU)); + po = addarg(po, sskip2(vval(RVU), 1)); + } else + po = addarg(po, vval(RVU)); + } else { + if (vdef(RPICT)) + if (vval(RPICT)[0] != '-') { + atos(c_rpict, sizeof(c_rpict), vval(RPICT)); + po = addarg(po, sskip2(vval(RPICT), 1)); + } else + po = addarg(po, vval(RPICT)); + } } -lowqopts(op, po) /* low quality rendering options */ -register char *op; -char *po; +static void +lowqopts( /* low quality rendering options */ + register char *op, + char *po +) { double d, org[3], siz[3]; @@ -664,14 +773,14 @@ char *po; sprintf(op, " -av %.2g %.2g %.2g", d, d, d); op += strlen(op); op = addarg(op, "-lr 6 -lw .01"); - if (vdef(RENDER)) - op = addarg(op, vval(RENDER)); } -medqopts(op, po) /* medium quality rendering options */ -register char *op; -char *po; +static void +medqopts( /* medium quality rendering options */ + register char *op, + char *po +) { double d, org[3], siz[3], asz; @@ -714,7 +823,7 @@ char *po; } po = addarg(po, "-pt .08"); if (vbool(PENUMBRAS)) - op = addarg(op, "-ds .2 -dj .5"); + op = addarg(op, "-ds .2 -dj .9"); else op = addarg(op, "-ds .3"); op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1"); @@ -742,14 +851,14 @@ char *po; sprintf(op, " -av %.2g %.2g %.2g", d, d, d); op += strlen(op); op = addarg(op, "-lr 8 -lw .002"); - if (vdef(RENDER)) - op = addarg(op, vval(RENDER)); } -hiqopts(op, po) /* high quality rendering options */ -register char *op; -char *po; +static void +hiqopts( /* high quality rendering options */ + register char *op, + char *po +) { double d, org[3], siz[3], asz; @@ -792,7 +901,7 @@ char *po; } po = addarg(po, "-pt .04"); if (vbool(PENUMBRAS)) - op = addarg(op, "-ds .1 -dj .65"); + op = addarg(op, "-ds .1 -dj .9"); else op = addarg(op, "-ds .2"); op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01"); @@ -818,13 +927,13 @@ char *po; sprintf(op, " -av %.2g %.2g %.2g", d, d, d); op += strlen(op); op = addarg(op, "-lr 12 -lw .0005"); - if (vdef(RENDER)) - op = addarg(op, vval(RENDER)); } -xferopts(ro) /* transfer options if indicated */ -char *ro; +static void +xferopts( /* transfer options if indicated */ + char *ro +) { int fd, n; register char *cp; @@ -854,8 +963,10 @@ char *ro; } -pfiltopts(po) /* get pfilt options */ -register char *po; +static void +pfiltopts( /* get pfilt options */ + register char *po +) { *po = '\0'; if (vdef(EXPOSURE)) { @@ -871,12 +982,19 @@ register char *po; break; } if (vdef(PFILT)) - po = addarg(po, vval(PFILT)); + if (vval(PFILT)[0] != '-') { + atos(c_pfilt, sizeof(c_pfilt), vval(PFILT)); + po = addarg(po, sskip2(vval(PFILT), 1)); + } else + po = addarg(po, vval(PFILT)); } -matchword(s1, s2) /* match white-delimited words */ -register char *s1, *s2; +static int +matchword( /* match white-delimited words */ + register char *s1, + register char *s2 +) { while (isspace(*s1)) s1++; while (isspace(*s2)) s2++; @@ -887,9 +1005,10 @@ register char *s1, *s2; } -char * -specview(vs) /* get proper view spec from vs */ -register char *vs; +static char * +specview( /* get proper view spec from vs */ + register char *vs +) { static char vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0", "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"}; @@ -929,9 +1048,19 @@ register char *vs; } else if (*vs == 'z') { zpos = -1; vs++; } - viewtype = 'v'; - if((*vs == 'v') | (*vs == 'l') | (*vs == 'a') | (*vs == 'h') | (*vs == 'c')) + switch (*vs) { + case VT_PER: + case VT_PAR: + case VT_ANG: + case VT_HEM: + case VT_PLS: + case VT_CYL: viewtype = *vs++; + break; + default: + viewtype = VT_PER; + break; + } cp = viewopts; if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) { /* got one! */ *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype; @@ -973,19 +1102,20 @@ register char *vs; } cp = addarg(cp, vup[upax+3]); switch (viewtype) { - case 'v': + case VT_PER: cp = addarg(cp, "-vh 45 -vv 45"); break; - case 'l': + case VT_PAR: d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]); sprintf(cp, " -vh %.2g -vv %.2g", d, d); cp += strlen(cp); break; - case 'a': - case 'h': + case VT_ANG: + case VT_HEM: + case VT_PLS: cp = addarg(cp, "-vh 180 -vv 180"); break; - case 'c': + case VT_CYL: cp = addarg(cp, "-vh 180 -vv 90"); break; } @@ -1011,10 +1141,11 @@ register char *vs; } -char * -getview(n, vn) /* get view n, or NULL if none */ -int n; -char *vn; /* returned view name */ +static char * +getview( /* get view n, or NULL if none */ + int n, + char *vn /* returned view name */ +) { register char *mv; @@ -1052,15 +1183,20 @@ char *vn; /* returned view name */ } -int -myprintview(vopts, fp) /* print out selected view */ -register char *vopts; -FILE *fp; +static int +myprintview( /* print out selected view */ + register char *vopts, + FILE *fp +) { VIEW vwr; char buf[128]; register char *cp; +#ifdef _WIN32 +/* XXX Should we allow something like this for all platforms? */ +/* XXX Or is it still required at all? */ again: +#endif if (vopts == NULL) return(-1); #ifdef _WIN32 @@ -1083,8 +1219,11 @@ again: } -rvu(opts, po) /* run rvu with first view */ -char *opts, *po; +static void +rvu( /* run rvu with first view */ + char *opts, + char *po +) { char *vw; char combuf[PATH_MAX]; @@ -1093,21 +1232,26 @@ char *opts, *po; return; if (sayview) myprintview(vw, stdout); - sprintf(combuf, "rvu %s%s%s -R %s ", vw, po, opts, rifname); + sprintf(combuf, "%s %s%s%s -R %s ", c_rvu, vw, opts, po, rifname); + if (nprocs > 1) + sprintf(combuf+strlen(combuf), "-n %d ", nprocs); if (rvdevice != NULL) sprintf(combuf+strlen(combuf), "-o %s ", rvdevice); if (vdef(EXPOSURE)) sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE)); strcat(combuf, oct1name); if (runcom(combuf)) { /* run it */ - fprintf(stderr, "%s: error running rvu\n", progname); + fprintf(stderr, "%s: error running %s\n", progname, c_rvu); quit(1); } } -rpict(opts, po) /* run rpict and pfilt for each view */ -char *opts, *po; +static void +rpict( /* run rpict and pfilt for each view */ + char *opts, + char *po +) { char combuf[PATH_MAX]; char rawfile[PATH_MAX], picfile[PATH_MAX]; @@ -1171,7 +1315,7 @@ char *opts, *po; myprintview(vw, stdout); if (!vs[0]) sprintf(vs, "%d", vn); - sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs); + sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs); if (vdef(ZFILE)) sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs); else @@ -1200,15 +1344,15 @@ char *opts, *po; /* XXX Remember to call finish_process() */ /* build rpict command */ if (rfdt >= oct1date) { /* recover */ - sprintf(combuf, "rpict%s%s%s%s -ro %s %s", - rep, po, opts, zopt, rawfile, oct1name); + sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict, + rep, opts, po, zopt, rawfile, oct1name); if (runcom(combuf)) /* run rpict */ goto rperror; } else { if (overture) { /* run overture calculation */ sprintf(combuf, - "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s", - rep, vw, opts, + "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s", + c_rpict, rep, vw, opts, oct1name, overfile); if (runcom(combuf)) { fprintf(stderr, @@ -1220,17 +1364,17 @@ char *opts, *po; rmfile(overfile); #endif } - sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s", - rep, vw, res, po, opts, + sprintf(combuf, "%s%s %s %s%s%s%s %s > %s", + c_rpict, rep, vw, res, opts, po, zopt, oct1name, rawfile); if (pfile != NULL && inchild()) { /* rpict persistent mode */ if (!silent) printf("\t%s\n", combuf); - sprintf(combuf, "rpict%s %s %s%s%s %s > %s", - rep, rppopt, res, po, opts, - oct1name, rawfile); fflush(stdout); + sprintf(combuf, "%s%s %s %s%s%s %s > %s", + c_rpict, rep, rppopt, res, opts, + po, oct1name, rawfile); fp = popen(combuf, "w"); if (fp == NULL) goto rperror; @@ -1245,11 +1389,12 @@ char *opts, *po; if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { /* build pfilt command */ if (mult > 1) - sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s", - pfopts, mult, mult, rawfile, picfile); + sprintf(combuf, "%s%s -x /%d -y /%d %s > %s", + c_pfilt, pfopts, mult, mult, + rawfile, picfile); else - sprintf(combuf, "pfilt%s %s > %s", pfopts, - rawfile, picfile); + sprintf(combuf, "%s%s %s > %s", c_pfilt, + pfopts, rawfile, picfile); if (runcom(combuf)) { /* run pfilt */ fprintf(stderr, "%s: error filtering view %s\n\t%s removed\n", @@ -1260,7 +1405,7 @@ char *opts, *po; } /* remove/rename raw file */ if (vdef(RAWFILE)) { - sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs); + sprintf(combuf, "%s_%s.hdr", vval(RAWFILE), vs); mvfile(rawfile, combuf); } else rmfile(rawfile); @@ -1268,7 +1413,7 @@ char *opts, *po; } wait_process(1); /* wait for children to finish */ if (pfile != NULL) { /* clean up rpict persistent mode */ - int pid; + RT_PID pid; fp = fopen(pfile, "r"); if (fp != NULL) { if (fscanf(fp, "%*s %d", &pid) != 1 || @@ -1284,8 +1429,10 @@ rperror: } -touch(fn) /* update a file */ -char *fn; +static int +touch( /* update a file */ + char *fn +) { if (!silent) printf("\ttouch %s\n", fn); @@ -1300,20 +1447,24 @@ char *fn; } -runcom(cs) /* run command */ -char *cs; +static int +runcom( /* run command */ + char *cs +) { if (!silent) /* echo it */ printf("\t%s\n", cs); if (!nprocs) return(0); - fflush(stdout); /* flush output and pass to shell */ + fflush(NULL); /* flush output and pass to shell */ return(system(cs)); } -rmfile(fn) /* remove a file */ -char *fn; +static int +rmfile( /* remove a file */ + char *fn +) { if (!silent) printf("\t%s %s\n", DELCMD, fn); @@ -1323,8 +1474,11 @@ char *fn; } -mvfile(fold, fnew) /* move a file */ -char *fold, *fnew; +static int +mvfile( /* move a file */ + char *fold, + char *fnew +) { if (!silent) printf("\t%s %s %s\n", RENAMECMD, fold, fnew); @@ -1335,10 +1489,10 @@ char *fold, *fnew; #ifdef RHAS_FORK_EXEC -int -next_process() /* fork the next process (max. nprocs) */ +static int +next_process(void) /* fork the next process (max. nprocs) */ { - int child_pid; + RT_PID child_pid; if (nprocs <= 1) return(0); /* it's us or no one */ @@ -1349,7 +1503,7 @@ next_process() /* fork the next process (max. nprocs } if (children_running >= nprocs) wait_process(0); /* wait for someone to finish */ - fflush(stdout); + fflush(NULL); /* flush output */ child_pid = fork(); /* split process */ if (child_pid == 0) { /* we're the child */ children_running = -1; @@ -1363,11 +1517,13 @@ next_process() /* fork the next process (max. nprocs return(0); } -wait_process(all) /* wait for process(es) to finish */ -int all; +static void +wait_process( /* wait for process(es) to finish */ + int all +) { - int ourstatus = 0; - int pid, status; + int ourstatus = 0, status; + RT_PID pid; if (all) all = children_running; @@ -1391,11 +1547,12 @@ int all; quit(ourstatus); /* bad status from child */ } #else /* ! RHAS_FORK_EXEC */ -int -next_process() +static int +next_process(void) { return(0); /* cannot start new process */ } +static void wait_process(all) int all; { @@ -1403,13 +1560,15 @@ int all; } int kill(pid, sig) /* win|unix_process.c should also wait and kill */ -int pid, sig; +RT_PID pid; +int sig; { return 0; } #endif /* ! RHAS_FORK_EXEC */ -finish_process() /* exit a child process */ +static void +finish_process(void) /* exit a child process */ { if (!inchild()) return; /* in parent -- noop */ @@ -1436,8 +1595,10 @@ char *vname, *value; #endif -badvalue(vc) /* report bad variable value and exit */ -int vc; +static void +badvalue( /* report bad variable value and exit */ + int vc +) { fprintf(stderr, "%s: bad value for variable '%s'\n", progname, vnam(vc)); @@ -1445,8 +1606,10 @@ int vc; } -syserr(s) /* report a system error and exit */ -char *s; +static void +syserr( /* report a system error and exit */ + char *s +) { perror(s); quit(1);