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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines