--- ray/src/common/header.c 2022/03/06 16:33:44 2.45 +++ ray/src/common/header.c 2025/06/06 19:11:21 2.50 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: header.c,v 2.45 2022/03/06 16:33:44 greg Exp $"; +static const char RCSid[] = "$Id: header.c,v 2.50 2025/06/06 19:11:21 greg Exp $"; #endif /* * header.c - routines for reading and writing information headers. @@ -30,6 +30,7 @@ static const char RCSid[] = "$Id: header.c,v 2.45 2022 #include #include "tiff.h" /* for int32 */ +#include "paths.h" /* for fixargv0() */ #include "rtio.h" #include "color.h" #include "resolu.h" @@ -162,24 +163,26 @@ fputnow( /* write out the current time */ void -printargs( /* print arguments to a file */ +printargs( /* print command arguments to a file */ int ac, char **av, FILE *fp ) { -#if defined(_WIN32) || defined(_WIN64) - extern char *fixargv0(char *arg0); - char myav0[128]; - /* clean up Windows executable path */ - if (ac-- <= 0) return; - fputs(fixargv0(strcpy(myav0, *av++)), fp); - fputc(ac ? ' ' : '\n', fp); -#endif - while (ac-- > 0) { - fputword(*av++, fp); - fputc(ac ? ' ' : '\n', fp); + if (ac <= 0) + return; + if (progname == NULL) + fixargv0(av[0]); /* sets global progname */ + + if (progname >= av[0] && progname - av[0] < strlen(av[0])) + fputword(progname, fp); + else + fputword(av[0], fp); + while (--ac > 0) { + fputc(' ', fp); + fputword(*++av, fp); } + fputc('\n', fp); } @@ -191,15 +194,20 @@ formatval( /* get format value (return true if forma { const char *cp = FMTSTR; char *r = fmt; - + /* check against format string */ while (*cp) if (*cp++ != *s++) return(0); while (isspace(*s)) s++; if (!*s) return(0); - if (r == NULL) return(1); - do + if (r == NULL) /* just checking if format? */ + return(1); + do /* copy format ID */ *r++ = *s++; - while (*s && !isspace(*s) && r-fmt < MAXFMTLEN-1); - *r = '\0'; + while (*s && r-fmt < MAXFMTLEN-1); + + do /* remove trailing white space */ + *r-- = '\0'; + while (r > fmt && isspace(*r)); + return(1); } @@ -363,7 +371,7 @@ globmatch( /* check for match of s against pattern p while (*s++); return(0); case '[': /* character set */ - setmatch = *s == *++p; + setmatch = (*s == *++p); if (!*p) return(0); while (*++p != ']') { @@ -381,7 +389,8 @@ globmatch( /* check for match of s against pattern p s++; break; case '\\': /* literal next */ - p++; + if (!*++p) + return(0); /* fall through */ default: /* normal character */ if (*p != *s)