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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines