--- ray/src/util/rfluxmtx.c 2015/05/21 05:54:54 2.29 +++ 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.29 2015/05/21 05:54:54 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; @@ -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);