--- ray/src/common/header.c 2009/03/12 18:37:24 2.24 +++ ray/src/common/header.c 2014/05/30 23:43:48 2.29 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: header.c,v 2.24 2009/03/12 18:37:24 greg Exp $"; +static const char RCSid[] = "$Id: header.c,v 2.29 2014/05/30 23:43:48 greg Exp $"; #endif /* * header.c - routines for reading and writing information headers. @@ -7,14 +7,12 @@ static const char RCSid[] = "$Id: header.c,v 2.24 2009 * Externals declared in resolu.h * * newheader(t,fp) start new information header identified by string t - * isheadid(s) returns true if s is a header id line * headidval(r,s) copy header identifier value in s to r - * dateval(t,s) get capture date value - * isdate(s) returns true if s is a date line - * fputdate(t,fp) put out the given capture date and time + * dateval(t,s) get capture date value as UTC + * 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' - * isformat(s) returns true if s is of the form "FORMAT=*" * formatval(r,s) copy the format value in s to r * fputformat(s,fp) write "FORMAT=%s" to fp * getheader(fp,f,p) read header from fp, calling f(s,p) on each line @@ -33,19 +31,22 @@ static const char RCSid[] = "$Id: header.c,v 2.24 2009 #define MAXLINE 2048 -char HDRSTR[] = "#?"; /* information header magic number */ +extern time_t timegm(struct tm *tm); -char FMTSTR[] = "FORMAT="; /* format identifier */ +const char HDRSTR[] = "#?"; /* information header magic number */ -char TMSTR[] = "CAPDATE="; /* capture date identifier */ +const char FMTSTR[] = "FORMAT="; /* format identifier */ +const char TMSTR[] = "CAPDATE="; /* capture date identifier */ +const char GMTSTR[] = "GMT="; /* GMT identifier */ + static gethfunc mycheck; -extern void +void newheader( /* identifying line of information header */ char *s, - register FILE *fp + FILE *fp ) { fputs(HDRSTR, fp); @@ -54,13 +55,13 @@ newheader( /* identifying line of information header } -extern int +int headidval( /* get header id (return true if is id) */ - register char *r, - register char *s + char *r, + char *s ) { - register char *cp = HDRSTR; + const char *cp = HDRSTR; while (*cp) if (*cp++ != *s++) return(0); if (r == NULL) return(1); @@ -70,23 +71,14 @@ headidval( /* get header id (return true if is id) * } -extern int -isheadid( /* check to see if line is header id */ - char *s -) -{ - return(headidval(NULL, s)); -} - - -extern int -dateval( /* get capture date value */ +int +dateval( /* convert capture date line to UTC */ time_t *tloc, char *s ) { struct tm tms; - register char *cp = TMSTR; + const char *cp = TMSTR; while (*cp) if (*cp++ != *s++) return(0); while (isspace(*s)) s++; @@ -105,31 +97,53 @@ dateval( /* get capture date value */ } -extern int -isdate( /* is the given line a capture date? */ - char *s +int +gmtval( /* convert GMT date line to UTC */ + time_t *tloc, + char *s ) { - return(dateval(NULL, s)); + struct tm tms; + const char *cp = GMTSTR; + + while (*cp) if (*cp++ != *s++) return(0); + while (isspace(*s)) s++; + if (!*s) return(0); + if (sscanf(s, "%d:%d:%d %d:%d:%d", + &tms.tm_year, &tms.tm_mon, &tms.tm_mday, + &tms.tm_hour, &tms.tm_min, &tms.tm_sec) != 6) + return(0); + if (tloc == NULL) + return(1); + tms.tm_mon--; + tms.tm_year -= 1900; + *tloc = timegm(&tms); + return(1); } -extern void -fputdate( /* write out the given time value */ +void +fputdate( /* write out the given time value (local & GMT) */ time_t tv, FILE *fp ) { - struct tm *tm = localtime(&tv); - if (tm == NULL) - return; - fprintf(fp, "%s %04d:%02d:%02d %02d:%02d:%02d\n", TMSTR, - tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec); + struct tm *tms; + + tms = localtime(&tv); + if (tms != NULL) + fprintf(fp, "%s %04d:%02d:%02d %02d:%02d:%02d\n", TMSTR, + tms->tm_year+1900, tms->tm_mon+1, tms->tm_mday, + tms->tm_hour, tms->tm_min, tms->tm_sec); + tms = gmtime(&tv); + if (tms != NULL) + fprintf(fp, "%s %04d:%02d:%02d %02d:%02d:%02d\n", GMTSTR, + tms->tm_year+1900, tms->tm_mon+1, tms->tm_mday, + tms->tm_hour, tms->tm_min, tms->tm_sec); } -extern void +void fputnow( /* write out the current time */ FILE *fp ) @@ -140,7 +154,7 @@ fputnow( /* write out the current time */ } -extern void +void printargs( /* print arguments to a file */ int ac, char **av, @@ -154,13 +168,13 @@ printargs( /* print arguments to a file */ } -extern int +int formatval( /* get format value (return true if format) */ - register char *r, - register char *s + char *r, + char *s ) { - register char *cp = FMTSTR; + const char *cp = FMTSTR; while (*cp) if (*cp++ != *s++) return(0); while (isspace(*s)) s++; @@ -168,22 +182,13 @@ 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 = '\0'; return(1); } -extern int -isformat( /* is line a format line? */ - char *s -) -{ - return(formatval(NULL, s)); -} - - -extern void +void fputformat( /* put out a format value */ char *s, FILE *fp @@ -195,7 +200,7 @@ fputformat( /* put out a format value */ } -extern int +int getheader( /* get header from file */ FILE *fp, gethfunc *f, @@ -208,12 +213,8 @@ getheader( /* get header from file */ buf[MAXLINE-2] = '\n'; if (fgets(buf, MAXLINE, fp) == NULL) return(-1); - if (buf[0] == '\n') + if (buf[buf[0]=='\r'] == '\n') return(0); -#ifdef MSDOS - if (buf[0] == '\r' && buf[1] == '\n') - return(0); -#endif if (buf[MAXLINE-2] != '\n') { ungetc(buf[MAXLINE-2], fp); /* prevent false end */ buf[MAXLINE-2] = '\0'; @@ -244,10 +245,10 @@ mycheck( /* check a header line for format info. */ } -extern int +int globmatch( /* check for match of s against pattern p */ - register char *p, - register char *s + char *p, + char *s ) { int setmatch; @@ -261,7 +262,7 @@ globmatch( /* check for match of s against pattern p case '*': /* match any string */ while (p[1] == '*') p++; do - if ( (p[1]=='?' || p[1]==*s) && + if ( (p[1]=='?') | (p[1]==*s) && globmatch(p+1,s) ) return(1); while (*s++); @@ -274,11 +275,11 @@ globmatch( /* check for match of s against pattern 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 - setmatch += *p == *s; + setmatch += (*p == *s); } if (!setmatch) return(0); @@ -312,7 +313,7 @@ globmatch( /* check for match of s against pattern p * if fout is not NULL. */ -extern int +int checkheader( FILE *fin, char *fmt, @@ -320,7 +321,7 @@ checkheader( ) { struct check cdat; - register char *cp; + char *cp; cdat.fp = fout; cdat.fs[0] = '\0';