--- ray/src/util/rfluxmtx.c 2015/03/27 18:58:06 2.26 +++ ray/src/util/rfluxmtx.c 2015/09/13 21:09:20 2.31 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rfluxmtx.c,v 2.26 2015/03/27 18:58:06 greg Exp $"; +static const char RCSid[] = "$Id: rfluxmtx.c,v 2.31 2015/09/13 21:09:20 greg Exp $"; #endif /* * Calculate flux transfer matrix or matrices using rcontrib @@ -142,6 +142,20 @@ surf_type(const char *otype) return(ST_NONE); } +/* Check if any of the characters in str2 are found in str1 */ +static int +matchany(const char *str1, const char *str2) +{ + while (*str1) { + const char *cp = str2; + while (*cp) + if (*cp++ == *str1) + return(*str1); + ++str1; + } + return(0); +} + /* Add arguments to oconv command */ static char * oconv_command(int ac, char *av[]) @@ -156,31 +170,28 @@ oconv_command(int ac, char *av[]) strcpy(cp, *av++); while (*cp) cp++; *cp++ = ' '; - if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) { - fputs(progname, stderr); - fputs(": too many file arguments!\n", stderr); - exit(1); - } + if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) + goto overrun; } - strcpy(cp, recv); /* receiver goes last */ + /* receiver goes last */ + if (matchany(recv, SPECIALS)) { + *cp++ = QUOTCHAR; + while (*recv) { + if (cp >= oconvbuf+(sizeof(oconvbuf)-3)) + goto overrun; + *cp++ = *recv++; + } + *cp++ = QUOTCHAR; + *cp = '\0'; + } else + strcpy(cp, recv); return(oconvbuf); +overrun: + fputs(progname, stderr); + fputs(": too many file arguments!\n", stderr); + exit(1); } -/* Check if any of the characters in str2 are found in str1 */ -static int -matchany(const char *str1, const char *str2) -{ - while (*str1) { - const char *cp = str2; - while (*cp) - if (*cp++ == *str1) - return(*str1); - ++str1; - } - return(0); -} - - /* Convert a set of arguments into a command line for pipe() or system() */ static char * convert_commandline(char *cmd, const int len, char *av[]) @@ -194,10 +205,10 @@ convert_commandline(char *cmd, const int len, char *av fputs(progname, stderr); return(NULL); } - if ((match = matchany(*av, SPECIALS))) { + if (matchany(*av, SPECIALS)) { const int quote = #ifdef ALTQUOT - (match == QUOTCHAR) ? ALTQUOT : + strchr(*av, QUOTCHAR) ? ALTQUOT : #endif QUOTCHAR; *cp++ = quote; @@ -530,7 +541,7 @@ make_axes(FVECT uva[2], const FVECT nrm) { int i; - if (!getperpendicular(uva[0], nrm)) { + if (!getperpendicular(uva[0], nrm, 1)) { fputs(progname, stderr); fputs(": bad surface normal in make_axes!\n", stderr); exit(1); @@ -674,7 +685,7 @@ sample_origin(PARAMS *p, FVECT orig, const FVECT rdir, /* special case for lone surface */ if (p->nsurfs == 1) { sp = p->slist; - if (DOT(sp->snrm, rdir) >= -FTINY) { + if (DOT(sp->snrm, rdir) >= FTINY) { fprintf(stderr, "%s: internal - sample behind sender '%s'\n", progname, sp->sname); @@ -849,7 +860,7 @@ sample_klems(PARAMS *p, int b, FILE *fp) while (n--) { /* stratified sampling */ SDmultiSamp(samp2, 2, (n+frandom())/sampcnt); - if (!fi_getvec(duvw, b+samp2[1], kbasis[bi])) + if (!fo_getvec(duvw, b+samp2[1], kbasis[bi])) return(0); for (i = 3; i--; ) orig_dir[1][i] = -duvw[0]*p->udir[i] - @@ -1292,7 +1303,12 @@ main(int argc, char *argv[]) if (argv[a][2] != 'v') na = 2; break; case 'a': /* special case */ - na = (argv[a][2] == 'v') ? 4 : 2; + if (argv[a][2] == 'p') { + na = 2; /* photon map [+ bandwidth(s)] */ + if (a < argc-3 && atoi(argv[a+1]) > 0) + na += 1 + (a < argc-4 && atoi(argv[a+2]) > 0); + } else + na = (argv[a][2] == 'v') ? 4 : 2; break; case 'm': /* special case */ if (!argv[a][2]) goto userr;