ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/header.c
(Generate patch)

Comparing ray/src/common/header.c (file contents):
Revision 2.18 by greg, Sat Jul 12 15:14:44 2003 UTC vs.
Revision 2.25 by greg, Thu May 21 18:08:43 2009 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *  Externals declared in resolu.h
8   *
9   *  newheader(t,fp)     start new information header identified by string t
10 *  isheadid(s)         returns true if s is a header id line
10   *  headidval(r,s)      copy header identifier value in s to r
11 < *  dateval(t,s)        get capture date value
12 < *  isdate(s)           returns true if s is a date line
13 < *  fputdate(t,fp)      put out the given capture date and time
11 > *  dateval(t,s)        get capture date value as UTC
12 > *  gmtval(t,s)         get GMT as UTC
13 > *  fputdate(t,fp)      put out the given UTC
14   *  fputnow(fp)         put out the current date and time
15   *  printargs(ac,av,fp) print an argument list to fp, followed by '\n'
17 *  isformat(s)         returns true if s is of the form "FORMAT=*"
16   *  formatval(r,s)      copy the format value in s to r
17   *  fputformat(s,fp)    write "FORMAT=%s" to fp
18   *  getheader(fp,f,p)   read header from fp, calling f(s,p) on each line
# Line 26 | Line 24 | static const char      RCSid[] = "$Id$";
24  
25   #include "copyright.h"
26  
29 #include  <time.h>
27   #include  <ctype.h>
28  
29   #include  "rtio.h"
30   #include  "resolu.h"
31  
32 < #define  MAXLINE        512
32 > #define  MAXLINE        2048
33  
34 < char  HDRSTR[] = "#?";          /* information header magic number */
34 > const char  HDRSTR[] = "#?";            /* information header magic number */
35  
36 < char  FMTSTR[] = "FORMAT=";     /* format identifier */
36 > const char  FMTSTR[] = "FORMAT=";       /* format identifier */
37  
38 < char  TMSTR[] = "CAPDATE=";     /* capture date identifier */
38 > const char  TMSTR[] = "CAPDATE=";       /* capture date identifier */
39 > const char  GMTSTR[] = "GMT=";          /* GMT identifier */
40  
41 < static int mycheck();
41 > static gethfunc mycheck;
42  
43  
44 < void
45 < newheader(s, fp)                /* identifying line of information header */
46 < char  *s;
47 < register FILE  *fp;
44 > extern void
45 > newheader(              /* identifying line of information header */
46 >        char  *s,
47 >        FILE  *fp
48 > )
49   {
50          fputs(HDRSTR, fp);
51          fputs(s, fp);
# Line 54 | Line 53 | register FILE  *fp;
53   }
54  
55  
56 < int
57 < headidval(r,s)                  /* get header id (return true if is id) */
58 < register char  *r, *s;
56 > extern int
57 > headidval(                      /* get header id (return true if is id) */
58 >        char  *r,
59 >        char    *s
60 > )
61   {
62 <        register char  *cp = HDRSTR;
62 >        const char  *cp = HDRSTR;
63  
64          while (*cp) if (*cp++ != *s++) return(0);
65          if (r == NULL) return(1);
# Line 68 | Line 69 | register char  *r, *s;
69   }
70  
71  
72 < int
73 < isheadid(s)                     /* check to see if line is header id */
74 < char  *s;
72 > extern int
73 > dateval(                /* convert capture date line to UTC */
74 >        time_t  *tloc,
75 >        char    *s
76 > )
77   {
75        return(headidval(NULL, s));
76 }
77
78
79 int
80 dateval(tloc, s)                /* get capture date value */
81 time_t  *tloc;
82 char    *s;
83 {
78          struct tm       tms;
79 <        register char  *cp = TMSTR;
79 >        const char      *cp = TMSTR;
80  
81          while (*cp) if (*cp++ != *s++) return(0);
82          while (isspace(*s)) s++;
# Line 101 | Line 95 | char   *s;
95   }
96  
97  
98 < int
99 < isdate(s)                       /* is the given line a capture date? */
100 < char *s;
98 > extern int
99 > gmtval(                 /* convert GMT date line to UTC */
100 >        time_t  *tloc,
101 >        char    *s
102 > )
103   {
104 <        return(dateval(NULL, s));
104 >        struct tm       tms;
105 >        const char      *cp = GMTSTR;
106 >
107 >        while (*cp) if (*cp++ != *s++) return(0);
108 >        while (isspace(*s)) s++;
109 >        if (!*s) return(0);
110 >        if (sscanf(s, "%d:%d:%d %d:%d:%d",
111 >                        &tms.tm_year, &tms.tm_mon, &tms.tm_mday,
112 >                        &tms.tm_hour, &tms.tm_min, &tms.tm_sec) != 6)
113 >                return(0);
114 >        if (tloc == NULL)
115 >                return(1);
116 >        tms.tm_mon--;
117 >        tms.tm_year -= 1900;
118 >        *tloc = timegm(&tms);
119 >        return(1);
120   }
121  
122  
123 < void
124 < fputdate(tv, fp)                /* write out the given time value */
125 < time_t  tv;
126 < FILE    *fp;
123 > extern void
124 > fputdate(               /* write out the given time value (local & GMT) */
125 >        time_t  tv,
126 >        FILE    *fp
127 > )
128   {
129 <        struct tm       *tm = localtime(&tv);
130 <        if (tm == NULL)
131 <                return;
132 <        fprintf(fp, "%s %04d:%02d:%02d %02d:%02d:%02d\n", TMSTR,
133 <                        tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
134 <                        tm->tm_hour, tm->tm_min, tm->tm_sec);
129 >        struct tm       *tms;
130 >
131 >        tms = localtime(&tv);
132 >        if (tms != NULL)
133 >                fprintf(fp, "%s %04d:%02d:%02d %02d:%02d:%02d\n", TMSTR,
134 >                                tms->tm_year+1900, tms->tm_mon+1, tms->tm_mday,
135 >                                tms->tm_hour, tms->tm_min, tms->tm_sec);
136 >        tms = gmtime(&tv);
137 >        if (tms != NULL)
138 >                fprintf(fp, "%s %04d:%02d:%02d %02d:%02d:%02d\n", GMTSTR,
139 >                                tms->tm_year+1900, tms->tm_mon+1, tms->tm_mday,
140 >                                tms->tm_hour, tms->tm_min, tms->tm_sec);
141   }
142  
143  
144 < void
145 < fputnow(fp)                     /* write out the current time */
146 < FILE    *fp;
144 > extern void
145 > fputnow(                        /* write out the current time */
146 >        FILE    *fp
147 > )
148   {
149          time_t  tv;
150          time(&tv);
# Line 133 | Line 152 | FILE   *fp;
152   }
153  
154  
155 < void
156 < printargs(ac, av, fp)           /* print arguments to a file */
157 < int  ac;
158 < char  **av;
159 < FILE  *fp;
155 > extern void
156 > printargs(              /* print arguments to a file */
157 >        int  ac,
158 >        char  **av,
159 >        FILE  *fp
160 > )
161   {
162          while (ac-- > 0) {
163                  fputword(*av++, fp);
# Line 146 | Line 166 | FILE  *fp;
166   }
167  
168  
169 < int
170 < formatval(r, s)                 /* get format value (return true if format) */
171 < register char  *r;
172 < register char  *s;
169 > extern int
170 > formatval(                      /* get format value (return true if format) */
171 >        char  *r,
172 >        char  *s
173 > )
174   {
175 <        register char  *cp = FMTSTR;
175 >        const char  *cp = FMTSTR;
176  
177          while (*cp) if (*cp++ != *s++) return(0);
178          while (isspace(*s)) s++;
# Line 165 | Line 186 | register char  *s;
186   }
187  
188  
189 < int
190 < isformat(s)                     /* is line a format line? */
191 < char  *s;
189 > extern void
190 > fputformat(             /* put out a format value */
191 >        char  *s,
192 >        FILE  *fp
193 > )
194   {
172        return(formatval(NULL, s));
173 }
174
175
176 void
177 fputformat(s, fp)               /* put out a format value */
178 char  *s;
179 FILE  *fp;
180 {
195          fputs(FMTSTR, fp);
196          fputs(s, fp);
197          putc('\n', fp);
198   }
199  
200  
201 < int
202 < getheader(fp, f, p)             /* get header from file */
203 < FILE  *fp;
204 < int  (*f)();
205 < char  *p;
201 > extern int
202 > getheader(              /* get header from file */
203 >        FILE  *fp,
204 >        gethfunc *f,
205 >        void  *p
206 > )
207   {
208          char  buf[MAXLINE];
209  
# Line 219 | Line 234 | struct check {
234  
235  
236   static int
237 < mycheck(s, cp)                  /* check a header line for format info. */
238 < char  *s;
239 < register struct check  *cp;
237 > mycheck(                        /* check a header line for format info. */
238 >        char  *s,
239 >        void  *cp
240 > )
241   {
242 <        if (!formatval(cp->fs, s) && cp->fp != NULL)
243 <                fputs(s, cp->fp);
242 >        if (!formatval(((struct check*)cp)->fs, s)
243 >                        && ((struct check*)cp)->fp != NULL) {
244 >                fputs(s, ((struct check*)cp)->fp);
245 >        }
246          return(0);
247   }
248  
249  
250 < int
251 < globmatch(p, s)                 /* check for match of s against pattern p */
252 < register char   *p, *s;
250 > extern int
251 > globmatch(                      /* check for match of s against pattern p */
252 >        char    *p,
253 >        char    *s
254 > )
255   {
256          int     setmatch;
257  
# Line 295 | Line 315 | register char  *p, *s;
315   * if fout is not NULL.
316   */
317  
318 < int
319 < checkheader(fin, fmt, fout)
320 < FILE  *fin;
321 < char  *fmt;
322 < FILE  *fout;
318 > extern int
319 > checkheader(
320 >        FILE  *fin,
321 >        char  *fmt,
322 >        FILE  *fout
323 > )
324   {
325          struct check    cdat;
326 <        register char   *cp;
326 >        char    *cp;
327  
328          cdat.fp = fout;
329          cdat.fs[0] = '\0';
330 <        if (getheader(fin, mycheck, (char *)&cdat) < 0)
330 >        if (getheader(fin, mycheck, &cdat) < 0)
331                  return(-1);
332          if (!cdat.fs[0])
333                  return(0);
334          for (cp = fmt; *cp; cp++)               /* check for globbing */
335 <                if (*cp == '?' | *cp == '*')
335 >                if ((*cp == '?') | (*cp == '*')) {
336                          if (globmatch(fmt, cdat.fs)) {
337                                  strcpy(fmt, cdat.fs);
338                                  return(1);
339                          } else
340                                  return(-1);
341 +                }
342          return(strcmp(fmt, cdat.fs) ? -1 : 1);  /* literal match */
343   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines