--- ray/src/common/header.c 2014/05/30 23:43:48 2.29 +++ ray/src/common/header.c 2019/06/09 18:22:20 2.34 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: header.c,v 2.29 2014/05/30 23:43:48 greg Exp $"; +static const char RCSid[] = "$Id: header.c,v 2.34 2019/06/09 18:22:20 greg Exp $"; #endif /* * header.c - routines for reading and writing information headers. @@ -45,7 +45,7 @@ static gethfunc mycheck; void newheader( /* identifying line of information header */ - char *s, + const char *s, FILE *fp ) { @@ -58,7 +58,7 @@ newheader( /* identifying line of information header int headidval( /* get header id (return true if is id) */ char *r, - char *s + const char *s ) { const char *cp = HDRSTR; @@ -74,7 +74,7 @@ headidval( /* get header id (return true if is id) * int dateval( /* convert capture date line to UTC */ time_t *tloc, - char *s + const char *s ) { struct tm tms; @@ -100,7 +100,7 @@ dateval( /* convert capture date line to UTC */ int gmtval( /* convert GMT date line to UTC */ time_t *tloc, - char *s + const char *s ) { struct tm tms; @@ -170,11 +170,12 @@ printargs( /* print arguments to a file */ int formatval( /* get format value (return true if format) */ - char *r, - char *s + char fmt[MAXFMTLEN], + const char *s ) { const char *cp = FMTSTR; + char *r = fmt; while (*cp) if (*cp++ != *s++) return(0); while (isspace(*s)) s++; @@ -182,7 +183,7 @@ formatval( /* get format value (return true if forma if (r == NULL) return(1); do *r++ = *s++; - while (*s && !isspace(*s)); + while (*s && !isspace(*s) && r-fmt < MAXFMTLEN-1); *r = '\0'; return(1); } @@ -190,7 +191,7 @@ formatval( /* get format value (return true if forma void fputformat( /* put out a format value */ - char *s, + const char *s, FILE *fp ) { @@ -207,27 +208,34 @@ getheader( /* get header from file */ void *p ) { + int rtotal = 0; char buf[MAXLINE]; + int firstc = fgetc(fp); + if (!isprint(firstc)) + return(-1); /* messed up */ + ungetc(firstc, fp); for ( ; ; ) { + int rval = 0; buf[MAXLINE-2] = '\n'; if (fgets(buf, MAXLINE, fp) == NULL) return(-1); - if (buf[buf[0]=='\r'] == '\n') - return(0); + if (buf[buf[0]=='\r'] == '\n') /* end of header? */ + return(rtotal); if (buf[MAXLINE-2] != '\n') { ungetc(buf[MAXLINE-2], fp); /* prevent false end */ buf[MAXLINE-2] = '\0'; } - if (f != NULL && (*f)(buf, p) < 0) + if (f != NULL && (rval = (*f)(buf, p)) < 0) return(-1); + rtotal += rval; } } struct check { FILE *fp; - char fs[64]; + char fs[MAXFMTLEN]; }; @@ -237,18 +245,19 @@ mycheck( /* check a header line for format info. */ void *cp ) { - if (!formatval(((struct check*)cp)->fs, s) - && ((struct check*)cp)->fp != NULL) { - fputs(s, ((struct check*)cp)->fp); - } + struct check *scp = (struct check *)cp; + + if (!formatval(scp->fs, s) && scp->fp != NULL) + fputs(s, scp->fp); + return(0); } int globmatch( /* check for match of s against pattern p */ - char *p, - char *s + const char *p, + const char *s ) { int setmatch; @@ -316,7 +325,7 @@ globmatch( /* check for match of s against pattern p int checkheader( FILE *fin, - char *fmt, + char fmt[MAXFMTLEN], FILE *fout ) {