--- ray/src/common/header.c 2019/08/14 18:20:02 2.36 +++ ray/src/common/header.c 2022/03/21 17:03:51 2.48 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: header.c,v 2.36 2019/08/14 18:20:02 greg Exp $"; +static const char RCSid[] = "$Id: header.c,v 2.48 2022/03/21 17:03:51 greg Exp $"; #endif /* * header.c - routines for reading and writing information headers. @@ -31,6 +31,7 @@ static const char RCSid[] = "$Id: header.c,v 2.36 2019 #include "tiff.h" /* for int32 */ #include "rtio.h" +#include "color.h" #include "resolu.h" #define MAXLINE 2048 @@ -57,7 +58,7 @@ newheader( /* identifying line of information header { fputs(HDRSTR, fp); fputs(s, fp); - putc('\n', fp); + fputc('\n', fp); } @@ -167,6 +168,14 @@ printargs( /* print arguments to a file */ 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); @@ -182,15 +191,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); } @@ -201,9 +215,35 @@ fputformat( /* put out a format value */ FILE *fp ) { + int align = 0; + fputs(FMTSTR, fp); fputs(s, fp); - putc('\n', fp); + /* pad to align binary type for mmap() */ + if (globmatch(PICFMT, s)) + align = 0; /* not needed for picture data */ + else if (!strncmp("float", s, 5)) + align = sizeof(float); + else if (!strncmp("double", s, 6)) + align = sizeof(double); + else if (!strncmp("16-bit", s, 6)) + align = 2; + else if (!strncmp("32-bit", s, 6)) + align = 4; + else if (!strncmp("64-bit", s, 6)) + align = 8; + if (align) { + long pos = ftell(fp); + if (pos >= 0) { + pos = (pos + 2) % align; + if (pos) align -= pos; + else align = 0; + } else + align = 0; + } + while (align-- > 0) + putc(' ', fp); + fputc('\n', fp); } @@ -225,7 +265,7 @@ isbigendian( /* header line says "BigEndian=1" (-1 if { const char *be = BIGEND; - while (*s & (*be != '=') && *s++ == *be) + while ((*s != '\0') & (*be != '=') && *s++ == *be) ++be; if (*be != '=') return(-1); /* irrelevant */ @@ -299,7 +339,7 @@ mycheck( /* check a header line for format info. */ struct check *scp = (struct check *)cp; if (!formatval(scp->fs, s) && scp->fp != NULL) - fputs(s, scp->fp); + return(fputs(s, scp->fp)); return(0); } @@ -328,14 +368,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 @@ -346,7 +386,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)