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.7 by greg, Tue Mar 12 11:29:16 1996 UTC vs.
Revision 2.12 by greg, Tue Feb 25 02:47:21 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1994 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
# Line 38 | Line 43 | char  HDRSTR[] = "#?";         /* information header magic nu
43  
44   char  FMTSTR[] = "FORMAT=";     /* format identifier */
45  
46 + char  TMSTR[] = "CAPDATE=";     /* capture date identifier */
47  
48 + static int mycheck();
49 +
50 +
51 + void
52   newheader(s, fp)                /* identifying line of information header */
53   char  *s;
54   register FILE  *fp;
# Line 57 | Line 67 | register char  *r, *s;
67  
68          while (*cp) if (*cp++ != *s++) return(0);
69          if (r == NULL) return(1);
70 <        while (*s) *r++ = *s++;
70 >        while (*s && !isspace(*s)) *r++ = *s++;
71          *r = '\0';
72          return(1);
73   }
# Line 71 | Line 81 | char  *s;
81   }
82  
83  
84 + int
85 + dateval(tloc, s)                /* get capture date value */
86 + time_t  *tloc;
87 + char    *s;
88 + {
89 +        struct tm       tms;
90 +        register char  *cp = TMSTR;
91 +
92 +        while (*cp) if (*cp++ != *s++) return(0);
93 +        while (isspace(*s)) s++;
94 +        if (!*s) return(0);
95 +        if (sscanf(s, "%d:%d:%d %d:%d:%d",
96 +                        &tms.tm_year, &tms.tm_mon, &tms.tm_mday,
97 +                        &tms.tm_hour, &tms.tm_min, &tms.tm_sec) != 6)
98 +                return(0);
99 +        if (tloc == NULL)
100 +                return(1);
101 +        tms.tm_mon--;
102 +        tms.tm_year -= 1900;
103 +        tms.tm_isdst = -1;      /* ask mktime() to figure out DST */
104 +        *tloc = mktime(&tms);
105 +        return(1);
106 + }
107 +
108 +
109 + int
110 + isdate(s)                       /* is the given line a capture date? */
111 + char *s;
112 + {
113 +        return(dateval(NULL, s));
114 + }
115 +
116 +
117 + void
118 + fputdate(tv, fp)                /* write out the given time value */
119 + time_t  tv;
120 + FILE    *fp;
121 + {
122 +        struct tm       *tm = localtime(&tv);
123 +        if (tm == NULL)
124 +                return;
125 +        fprintf(fp, "%s %04d:%02d:%02d %02d:%02d:%02d\n", TMSTR,
126 +                        tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
127 +                        tm->tm_hour, tm->tm_min, tm->tm_sec);
128 + }
129 +
130 +
131 + void
132 + fputnow(fp)                     /* write out the current time */
133 + FILE    *fp;
134 + {
135 +        time_t  tv;
136 +        time(&tv);
137 +        fputdate(tv, fp);
138 + }
139 +
140 +
141 + void
142   printargs(ac, av, fp)           /* print arguments to a file */
143   int  ac;
144   char  **av;
145 < register FILE  *fp;
145 > FILE  *fp;
146   {
147          int  quote;
148  
149          while (ac-- > 0) {
150 <                if (index(*av, ' ') != NULL) {          /* quote it */
151 <                        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(' ', fp);
150 >                fputword(*av++, fp);
151 >                fputc(ac ? ' ' : '\n', fp);
152          }
94        putc('\n', fp);
153   }
154  
155  
# Line 122 | Line 180 | char  *s;
180   }
181  
182  
183 + void
184   fputformat(s, fp)               /* put out a format value */
185   char  *s;
186   FILE  *fp;
# Line 154 | Line 213 | char  *p;
213                          ungetc(buf[MAXLINE-2], fp);     /* prevent false end */
214                          buf[MAXLINE-2] = '\0';
215                  }
216 <                if (f != NULL)
217 <                        (*f)(buf, p);
216 >                if (f != NULL && (*f)(buf, p) < 0)
217 >                        return(-1);
218          }
219   }
220  
# Line 166 | Line 225 | struct check {
225   };
226  
227  
228 < static
228 > static int
229   mycheck(s, cp)                  /* check a header line for format info. */
230   char  *s;
231   register struct check  *cp;
232   {
233          if (!formatval(cp->fs, s) && cp->fp != NULL)
234                  fputs(s, cp->fp);
235 +        return(0);
236   }
237  
238  
239   int
240 < globmatch(pat, str)             /* check for glob match of str against pat */
241 < char    *pat, *str;
240 > globmatch(p, s)                 /* check for match of s against pattern p */
241 > register char   *p, *s;
242   {
243 <        register char   *p = pat, *s = str;
243 >        int     setmatch;
244  
245          do {
246                  switch (*p) {
# Line 196 | Line 256 | char   *pat, *str;
256                                          return(1);
257                          while (*s++);
258                          return(0);
259 +                case '[':                       /* character set */
260 +                        setmatch = *s == *++p;
261 +                        if (!*p)
262 +                                return(0);
263 +                        while (*++p != ']') {
264 +                                if (!*p)
265 +                                        return(0);
266 +                                if (*p == '-') {
267 +                                        setmatch += p[-1] <= *s && *s <= p[1];
268 +                                        if (!*++p)
269 +                                                break;
270 +                                } else
271 +                                        setmatch += *p == *s;
272 +                        }
273 +                        if (!setmatch)
274 +                                return(0);
275 +                        s++;
276 +                        break;
277                  case '\\':                      /* literal next */
278                          p++;
279                  /* fall through */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines