--- ray/src/util/rfluxmtx.c 2015/04/01 01:38:36 2.27 +++ ray/src/util/rfluxmtx.c 2015/12/04 22:16:18 2.32 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rfluxmtx.c,v 2.27 2015/04/01 01:38:36 greg Exp $"; +static const char RCSid[] = "$Id: rfluxmtx.c,v 2.32 2015/12/04 22:16:18 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; @@ -318,6 +329,7 @@ parse_params(PARAMS *p, char *pargs) { char *cp = pargs; int nparams = 0; + int quot; int i; for ( ; ; ) { @@ -354,14 +366,23 @@ parse_params(PARAMS *p, char *pargs) case 'o': if (*cp++ != '=') break; + quot = 0; + if ((*cp == '"') | (*cp == '\'')) + quot = *cp++; i = 0; - while (*cp && !isspace(*cp++)) - i++; + while (*cp && (quot ? (*cp != quot) : !isspace(*cp))) { + i++; cp++; + } if (!i) break; - *--cp = '\0'; + if (!*cp) { + if (quot) + break; + cp[1] = '\0'; + } + *cp = '\0'; p->outfn = savqstr(cp-i); - *cp++ = ' '; + *cp++ = quot ? quot : ' '; ++nparams; continue; case ' ': @@ -530,7 +551,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 +695,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); @@ -1292,7 +1313,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;