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.9 by gregl, Fri Oct 31 11:40:52 1997 UTC vs.
Revision 2.16 by greg, Fri Jun 27 06:53:21 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1996 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  header.c - routines for reading and writing information headers.
6   *
7 < *      8/19/88
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
11   *  headidval(r,s)      copy header identifier value in s to r
12 + *  dateval(t,s)        get capture date value
13 + *  isdate(s)           returns true if s is a date line
14 + *  fputdate(t,fp)      put out the given capture date and time
15 + *  fputnow(fp)         put out the current date and time
16   *  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=*"
18   *  formatval(r,s)      copy the format value in s to r
# Line 23 | Line 24 | static char SCCSid[] = "$SunId$ LBL";
24   *  To copy header from input to output, use getheader(fin, fputs, fout)
25   */
26  
27 + #include "copyright.h"
28 + #include "resolu.h"
29 +
30   #include  <stdio.h>
31 + #include  <string.h>
32 + #include  <time.h>
33   #include  <ctype.h>
34  
35   #define  MAXLINE        512
36  
31 #ifndef BSD
32 #define  index  strchr
33 #endif
34
35 extern char  *index();
36
37   char  HDRSTR[] = "#?";          /* information header magic number */
38  
39   char  FMTSTR[] = "FORMAT=";     /* format identifier */
40  
41 + char  TMSTR[] = "CAPDATE=";     /* capture date identifier */
42  
43 + extern void     fputword(char *s, FILE *fp);
44 +
45 + static int mycheck();
46 +
47 +
48 + void
49   newheader(s, fp)                /* identifying line of information header */
50   char  *s;
51   register FILE  *fp;
# Line 71 | Line 78 | char  *s;
78   }
79  
80  
81 + int
82 + dateval(tloc, s)                /* get capture date value */
83 + time_t  *tloc;
84 + char    *s;
85 + {
86 +        struct tm       tms;
87 +        register char  *cp = TMSTR;
88 +
89 +        while (*cp) if (*cp++ != *s++) return(0);
90 +        while (isspace(*s)) s++;
91 +        if (!*s) return(0);
92 +        if (sscanf(s, "%d:%d:%d %d:%d:%d",
93 +                        &tms.tm_year, &tms.tm_mon, &tms.tm_mday,
94 +                        &tms.tm_hour, &tms.tm_min, &tms.tm_sec) != 6)
95 +                return(0);
96 +        if (tloc == NULL)
97 +                return(1);
98 +        tms.tm_mon--;
99 +        tms.tm_year -= 1900;
100 +        tms.tm_isdst = -1;      /* ask mktime() to figure out DST */
101 +        *tloc = mktime(&tms);
102 +        return(1);
103 + }
104 +
105 +
106 + int
107 + isdate(s)                       /* is the given line a capture date? */
108 + char *s;
109 + {
110 +        return(dateval(NULL, s));
111 + }
112 +
113 +
114 + void
115 + fputdate(tv, fp)                /* write out the given time value */
116 + time_t  tv;
117 + FILE    *fp;
118 + {
119 +        struct tm       *tm = localtime(&tv);
120 +        if (tm == NULL)
121 +                return;
122 +        fprintf(fp, "%s %04d:%02d:%02d %02d:%02d:%02d\n", TMSTR,
123 +                        tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
124 +                        tm->tm_hour, tm->tm_min, tm->tm_sec);
125 + }
126 +
127 +
128 + void
129 + fputnow(fp)                     /* write out the current time */
130 + FILE    *fp;
131 + {
132 +        time_t  tv;
133 +        time(&tv);
134 +        fputdate(tv, fp);
135 + }
136 +
137 +
138 + void
139   printargs(ac, av, fp)           /* print arguments to a file */
140   int  ac;
141   char  **av;
142 < register FILE  *fp;
142 > FILE  *fp;
143   {
79        int  quote;
80
144          while (ac-- > 0) {
145 <                if (index(*av, ' ') != NULL) {          /* quote it */
146 <                        if (index(*av, '\'') != NULL)
84 <                                quote = '"';
85 <                        else
86 <                                quote = '\'';
87 <                        putc(quote, fp);
88 <                        fputs(*av++, fp);
89 <                        putc(quote, fp);
90 <                } else
91 <                        fputs(*av++, fp);
92 <                putc(ac ? ' ' : '\n', fp);
145 >                fputword(*av++, fp);
146 >                fputc(ac ? ' ' : '\n', fp);
147          }
148   }
149  
# Line 121 | Line 175 | char  *s;
175   }
176  
177  
178 + void
179   fputformat(s, fp)               /* put out a format value */
180   char  *s;
181   FILE  *fp;
# Line 153 | Line 208 | char  *p;
208                          ungetc(buf[MAXLINE-2], fp);     /* prevent false end */
209                          buf[MAXLINE-2] = '\0';
210                  }
211 <                if (f != NULL)
212 <                        (*f)(buf, p);
211 >                if (f != NULL && (*f)(buf, p) < 0)
212 >                        return(-1);
213          }
214   }
215  
# Line 165 | Line 220 | struct check {
220   };
221  
222  
223 < static
223 > static int
224   mycheck(s, cp)                  /* check a header line for format info. */
225   char  *s;
226   register struct check  *cp;
227   {
228          if (!formatval(cp->fs, s) && cp->fp != NULL)
229                  fputs(s, cp->fp);
230 +        return(0);
231   }
232  
233  
234   int
235 < globmatch(pat, str)             /* check for glob match of str against pat */
236 < char    *pat, *str;
235 > globmatch(p, s)                 /* check for match of s against pattern p */
236 > register char   *p, *s;
237   {
238 <        register char   *p = pat, *s = str;
238 >        int     setmatch;
239  
240          do {
241                  switch (*p) {
# Line 195 | Line 251 | char   *pat, *str;
251                                          return(1);
252                          while (*s++);
253                          return(0);
254 +                case '[':                       /* character set */
255 +                        setmatch = *s == *++p;
256 +                        if (!*p)
257 +                                return(0);
258 +                        while (*++p != ']') {
259 +                                if (!*p)
260 +                                        return(0);
261 +                                if (*p == '-') {
262 +                                        setmatch += p[-1] <= *s && *s <= p[1];
263 +                                        if (!*++p)
264 +                                                break;
265 +                                } else
266 +                                        setmatch += *p == *s;
267 +                        }
268 +                        if (!setmatch)
269 +                                return(0);
270 +                        s++;
271 +                        break;
272                  case '\\':                      /* literal next */
273                          p++;
274                  /* fall through */
# Line 234 | Line 308 | FILE  *fout;
308  
309          cdat.fp = fout;
310          cdat.fs[0] = '\0';
311 <        if (getheader(fin, mycheck, &cdat) < 0)
311 >        if (getheader(fin, mycheck, (char *)&cdat) < 0)
312                  return(-1);
313          if (!cdat.fs[0])
314                  return(0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines