--- ray/src/common/header.c 2022/03/04 17:16:12 2.43 +++ ray/src/common/header.c 2025/06/07 05:09:45 2.51 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: header.c,v 2.43 2022/03/04 17:16:12 greg Exp $"; +static const char RCSid[] = "$Id: header.c,v 2.51 2025/06/07 05:09:45 greg Exp $"; #endif /* * header.c - routines for reading and writing information headers. @@ -12,7 +12,6 @@ static const char RCSid[] = "$Id: header.c,v 2.43 2022 * gmtval(t,s) get GMT as UTC * fputdate(t,fp) put out the given UTC * fputnow(fp) put out the current date and time - * printargs(ac,av,fp) print an argument list to fp, followed by '\n' * formatval(r,s) copy the format value in s to r * fputformat(s,fp) write "FORMAT=%s" to fp * nativebigendian() are we native on big-endian machine? @@ -31,6 +30,7 @@ static const char RCSid[] = "$Id: header.c,v 2.43 2022 #include "tiff.h" /* for int32 */ #include "rtio.h" +#include "color.h" #include "resolu.h" #define MAXLINE 2048 @@ -160,28 +160,6 @@ fputnow( /* write out the current time */ } -void -printargs( /* print 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); - } -} - - int formatval( /* get format value (return true if format) */ char fmt[MAXFMTLEN], @@ -190,15 +168,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); } @@ -214,15 +197,17 @@ fputformat( /* put out a format value */ fputs(FMTSTR, fp); fputs(s, fp); /* pad to align binary type for mmap() */ - if (!strncmp(s, "float", 5)) + if (globmatch(PICFMT, s)) + align = 0; /* not needed for picture data */ + else if (!strncmp("float", s, 5)) align = sizeof(float); - else if (!strncmp(s, "double", 6)) + else if (!strncmp("double", s, 6)) align = sizeof(double); - else if (!strncmp(s, "16-bit", 6)) + else if (!strncmp("16-bit", s, 6)) align = 2; - else if (!strncmp(s, "32-bit", 6)) + else if (!strncmp("32-bit", s, 6)) align = 4; - else if (!strncmp(s, "64-bit", 6)) + else if (!strncmp("64-bit", s, 6)) align = 8; if (align) { long pos = ftell(fp); @@ -360,14 +345,14 @@ 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 != ']') { if (!*p) return(0); if (*p == '-') { - setmatch += (p[-1] <= *s && *s <= p[1]); + setmatch += (p[-1] <= *s) & (*s <= p[1]); if (!*++p) break; } else @@ -378,7 +363,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)