| 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 |
| 24 |
|
* To copy header from input to output, use getheader(fin, fputs, fout) |
| 25 |
|
*/ |
| 26 |
|
|
| 27 |
+ |
/* ==================================================================== |
| 28 |
+ |
* The Radiance Software License, Version 1.0 |
| 29 |
+ |
* |
| 30 |
+ |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
| 31 |
+ |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
| 32 |
+ |
* |
| 33 |
+ |
* Redistribution and use in source and binary forms, with or without |
| 34 |
+ |
* modification, are permitted provided that the following conditions |
| 35 |
+ |
* are met: |
| 36 |
+ |
* |
| 37 |
+ |
* 1. Redistributions of source code must retain the above copyright |
| 38 |
+ |
* notice, this list of conditions and the following disclaimer. |
| 39 |
+ |
* |
| 40 |
+ |
* 2. Redistributions in binary form must reproduce the above copyright |
| 41 |
+ |
* notice, this list of conditions and the following disclaimer in |
| 42 |
+ |
* the documentation and/or other materials provided with the |
| 43 |
+ |
* distribution. |
| 44 |
+ |
* |
| 45 |
+ |
* 3. The end-user documentation included with the redistribution, |
| 46 |
+ |
* if any, must include the following acknowledgment: |
| 47 |
+ |
* "This product includes Radiance software |
| 48 |
+ |
* (http://radsite.lbl.gov/) |
| 49 |
+ |
* developed by the Lawrence Berkeley National Laboratory |
| 50 |
+ |
* (http://www.lbl.gov/)." |
| 51 |
+ |
* Alternately, this acknowledgment may appear in the software itself, |
| 52 |
+ |
* if and wherever such third-party acknowledgments normally appear. |
| 53 |
+ |
* |
| 54 |
+ |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
| 55 |
+ |
* and "The Regents of the University of California" must |
| 56 |
+ |
* not be used to endorse or promote products derived from this |
| 57 |
+ |
* software without prior written permission. For written |
| 58 |
+ |
* permission, please contact [email protected]. |
| 59 |
+ |
* |
| 60 |
+ |
* 5. Products derived from this software may not be called "Radiance", |
| 61 |
+ |
* nor may "Radiance" appear in their name, without prior written |
| 62 |
+ |
* permission of Lawrence Berkeley National Laboratory. |
| 63 |
+ |
* |
| 64 |
+ |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
| 65 |
+ |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 66 |
+ |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 67 |
+ |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
| 68 |
+ |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 69 |
+ |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 70 |
+ |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 71 |
+ |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 72 |
+ |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 73 |
+ |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 74 |
+ |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 75 |
+ |
* SUCH DAMAGE. |
| 76 |
+ |
* ==================================================================== |
| 77 |
+ |
* |
| 78 |
+ |
* This software consists of voluntary contributions made by many |
| 79 |
+ |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
| 80 |
+ |
* information on Lawrence Berkeley National Laboratory, please see |
| 81 |
+ |
* <http://www.lbl.gov/>. |
| 82 |
+ |
*/ |
| 83 |
+ |
|
| 84 |
|
#include <stdio.h> |
| 85 |
+ |
#include <string.h> |
| 86 |
+ |
#include <time.h> |
| 87 |
|
#include <ctype.h> |
| 88 |
|
|
| 89 |
|
#define MAXLINE 512 |
| 98 |
|
|
| 99 |
|
char FMTSTR[] = "FORMAT="; /* format identifier */ |
| 100 |
|
|
| 101 |
+ |
char TMSTR[] = "CAPDATE="; /* capture date identifier */ |
| 102 |
|
|
| 103 |
+ |
static int mycheck(); |
| 104 |
+ |
|
| 105 |
+ |
|
| 106 |
+ |
void |
| 107 |
|
newheader(s, fp) /* identifying line of information header */ |
| 108 |
|
char *s; |
| 109 |
|
register FILE *fp; |
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
|
| 139 |
+ |
int |
| 140 |
+ |
dateval(tloc, s) /* get capture date value */ |
| 141 |
+ |
time_t *tloc; |
| 142 |
+ |
char *s; |
| 143 |
+ |
{ |
| 144 |
+ |
struct tm tms; |
| 145 |
+ |
register char *cp = TMSTR; |
| 146 |
+ |
|
| 147 |
+ |
while (*cp) if (*cp++ != *s++) return(0); |
| 148 |
+ |
while (isspace(*s)) s++; |
| 149 |
+ |
if (!*s) return(0); |
| 150 |
+ |
if (sscanf(s, "%d:%d:%d %d:%d:%d", |
| 151 |
+ |
&tms.tm_year, &tms.tm_mon, &tms.tm_mday, |
| 152 |
+ |
&tms.tm_hour, &tms.tm_min, &tms.tm_sec) != 6) |
| 153 |
+ |
return(0); |
| 154 |
+ |
if (tloc == NULL) |
| 155 |
+ |
return(1); |
| 156 |
+ |
tms.tm_mon--; |
| 157 |
+ |
tms.tm_year -= 1900; |
| 158 |
+ |
tms.tm_isdst = -1; /* ask mktime() to figure out DST */ |
| 159 |
+ |
*tloc = mktime(&tms); |
| 160 |
+ |
return(1); |
| 161 |
+ |
} |
| 162 |
+ |
|
| 163 |
+ |
|
| 164 |
+ |
int |
| 165 |
+ |
isdate(s) /* is the given line a capture date? */ |
| 166 |
+ |
char *s; |
| 167 |
+ |
{ |
| 168 |
+ |
return(dateval(NULL, s)); |
| 169 |
+ |
} |
| 170 |
+ |
|
| 171 |
+ |
|
| 172 |
+ |
void |
| 173 |
+ |
fputdate(tv, fp) /* write out the given time value */ |
| 174 |
+ |
time_t tv; |
| 175 |
+ |
FILE *fp; |
| 176 |
+ |
{ |
| 177 |
+ |
struct tm *tm = localtime(&tv); |
| 178 |
+ |
if (tm == NULL) |
| 179 |
+ |
return; |
| 180 |
+ |
fprintf(fp, "%s %04d:%02d:%02d %02d:%02d:%02d\n", TMSTR, |
| 181 |
+ |
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, |
| 182 |
+ |
tm->tm_hour, tm->tm_min, tm->tm_sec); |
| 183 |
+ |
} |
| 184 |
+ |
|
| 185 |
+ |
|
| 186 |
+ |
void |
| 187 |
+ |
fputnow(fp) /* write out the current time */ |
| 188 |
+ |
FILE *fp; |
| 189 |
+ |
{ |
| 190 |
+ |
time_t tv; |
| 191 |
+ |
time(&tv); |
| 192 |
+ |
fputdate(tv, fp); |
| 193 |
+ |
} |
| 194 |
+ |
|
| 195 |
+ |
|
| 196 |
+ |
void |
| 197 |
|
printargs(ac, av, fp) /* print arguments to a file */ |
| 198 |
|
int ac; |
| 199 |
|
char **av; |
| 200 |
< |
register FILE *fp; |
| 200 |
> |
FILE *fp; |
| 201 |
|
{ |
| 202 |
|
int quote; |
| 203 |
|
|
| 204 |
|
while (ac-- > 0) { |
| 205 |
< |
if (index(*av, ' ') != NULL) { /* quote it */ |
| 206 |
< |
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); |
| 205 |
> |
fputword(*av++, fp); |
| 206 |
> |
fputc(ac ? ' ' : '\n', fp); |
| 207 |
|
} |
| 208 |
|
} |
| 209 |
|
|
| 235 |
|
} |
| 236 |
|
|
| 237 |
|
|
| 238 |
+ |
void |
| 239 |
|
fputformat(s, fp) /* put out a format value */ |
| 240 |
|
char *s; |
| 241 |
|
FILE *fp; |
| 268 |
|
ungetc(buf[MAXLINE-2], fp); /* prevent false end */ |
| 269 |
|
buf[MAXLINE-2] = '\0'; |
| 270 |
|
} |
| 271 |
< |
if (f != NULL) |
| 272 |
< |
(*f)(buf, p); |
| 271 |
> |
if (f != NULL && (*f)(buf, p) < 0) |
| 272 |
> |
return(-1); |
| 273 |
|
} |
| 274 |
|
} |
| 275 |
|
|
| 280 |
|
}; |
| 281 |
|
|
| 282 |
|
|
| 283 |
< |
static |
| 283 |
> |
static int |
| 284 |
|
mycheck(s, cp) /* check a header line for format info. */ |
| 285 |
|
char *s; |
| 286 |
|
register struct check *cp; |
| 287 |
|
{ |
| 288 |
|
if (!formatval(cp->fs, s) && cp->fp != NULL) |
| 289 |
|
fputs(s, cp->fp); |
| 290 |
+ |
return(0); |
| 291 |
|
} |
| 292 |
|
|
| 293 |
|
|
| 294 |
|
int |
| 295 |
< |
globmatch(pat, str) /* check for glob match of str against pat */ |
| 296 |
< |
char *pat, *str; |
| 295 |
> |
globmatch(p, s) /* check for match of s against pattern p */ |
| 296 |
> |
register char *p, *s; |
| 297 |
|
{ |
| 298 |
< |
register char *p = pat, *s = str; |
| 298 |
> |
int setmatch; |
| 299 |
|
|
| 300 |
|
do { |
| 301 |
|
switch (*p) { |
| 311 |
|
return(1); |
| 312 |
|
while (*s++); |
| 313 |
|
return(0); |
| 314 |
+ |
case '[': /* character set */ |
| 315 |
+ |
setmatch = *s == *++p; |
| 316 |
+ |
if (!*p) |
| 317 |
+ |
return(0); |
| 318 |
+ |
while (*++p != ']') { |
| 319 |
+ |
if (!*p) |
| 320 |
+ |
return(0); |
| 321 |
+ |
if (*p == '-') { |
| 322 |
+ |
setmatch += p[-1] <= *s && *s <= p[1]; |
| 323 |
+ |
if (!*++p) |
| 324 |
+ |
break; |
| 325 |
+ |
} else |
| 326 |
+ |
setmatch += *p == *s; |
| 327 |
+ |
} |
| 328 |
+ |
if (!setmatch) |
| 329 |
+ |
return(0); |
| 330 |
+ |
s++; |
| 331 |
+ |
break; |
| 332 |
|
case '\\': /* literal next */ |
| 333 |
|
p++; |
| 334 |
|
/* fall through */ |