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 1.2 by greg, Thu Apr 18 12:56:58 1991 UTC vs.
Revision 1.3 by greg, Fri Apr 19 10:33:25 1991 UTC

# Line 8 | Line 8 | static char SCCSid[] = "$SunId$ LBL";
8   *  header.c - routines for reading and writing information headers.
9   *
10   *      8/19/88
11 + *
12 + *  printargs(ac,av,fp) print an argument list to fp, followed by '\n'
13 + *  isformat(s)         returns true if s is of the form "FORMAT=*"
14 + *  formatval(r,s)      copy the format value in s to r
15 + *  fputformat(s,fp)    write "FORMAT=%s" to fp
16 + *  getheader(fp,f,p)   read header from fp, calling f(s,p) on each line
17 + *  checkheader(i,p,o)  check header format from i against p and copy to o
18 + *
19 + *  To copy header from input to output, use getheader(fin, fputs, fout)
20   */
21  
22   #include  <stdio.h>
23 + #include  <ctype.h>
24  
25   #define  MAXLINE        512
26  
# Line 43 | Line 53 | register char  *r;
53   register char  *s;
54   {
55          s += FMTSTRL;
56 <        while (*s && *s != '\n')
57 <                *r++ = *s++;
56 >        while (isspace(*s)) s++;
57 >        if (!*s) { *r = '\0'; return; }
58 >        while(*s) *r++ = *s++;
59 >        while (isspace(r[-1])) r--;
60          *r = '\0';
61   }
62  
# Line 84 | Line 96 | char  *p;
96  
97   struct check {
98          FILE    *fp;
99 <        char    fs[32];
99 >        char    fs[64];
100   };
101  
102  
# Line 100 | Line 112 | register struct check  *cp;
112   }
113  
114  
115 < checkheader(fin, fmt, fout)     /* check data format in header */
115 > /*
116 > * Copymatch(pat,str) checks pat for wildcards, and
117 > * copies str into pat if there is a match (returning true).
118 > */
119 >
120 > #ifdef COPYMATCH
121 > copymatch(pat, str)
122 > char    *pat, *str;
123 > {
124 >        int     docopy = 0;
125 >        register char   *p = pat, *s = str;
126 >
127 >        do {
128 >                switch (*p) {
129 >                case '?':                       /* match any character */
130 >                        if (!*s++)
131 >                                return(0);
132 >                        docopy++;
133 >                        break;
134 >                case '*':                       /* match any string */
135 >                        while (p[1] == '*') p++;
136 >                        do
137 >                                if ( (p[1] == '?' || p[1] == *s)
138 >                                                && copymatch(p+1,s) ) {
139 >                                        strcpy(pat, str);
140 >                                        return(1);
141 >                                }
142 >                        while (*s++);
143 >                        return(0);
144 >                case '\\':                      /* literal next */
145 >                        p++;
146 >                /* fall through */
147 >                default:                        /* normal character */
148 >                        if (*p != *s)
149 >                                return(0);
150 >                        s++;
151 >                        break;
152 >                }
153 >        } while (*p++);
154 >        if (docopy)
155 >                strcpy(pat, str);
156 >        return(1);
157 > }
158 > #else
159 > #define copymatch(pat, s)       (!strcmp(pat, s))
160 > #endif
161 >
162 >
163 > /*
164 > * Checkheader(fin,fmt,fout) returns a value of 1 if the input format
165 > * matches the specification in fmt, 0 if no input format was found,
166 > * and -1 if the input format does not match or there is an
167 > * error reading the header.  If fmt is NULL, then -1 is returned
168 > * if any input format is found (or there is an error), and 0 otherwise.
169 > * If fmt contains any '*' or '?' characters, then checkheader
170 > * does wildcard expansion and copies a matching result into fmt.
171 > * Be sure that fmt is big enough to hold the match in such cases!
172 > * The input header (minus any format lines) is copied to fout
173 > * if fout is not NULL.
174 > */
175 >
176 > checkheader(fin, fmt, fout)
177   FILE  *fin;
178   char  *fmt;
179   FILE  *fout;
# Line 111 | Line 184 | FILE  *fout;
184          cdat.fs[0] = '\0';
185          if (getheader(fin, mycheck, &cdat) < 0)
186                  return(-1);
187 <        if (fmt != NULL && cdat.fs[0] != '\0')
188 <                return(strcmp(fmt, cdat.fs) ? -1 : 1);
187 >        if (fmt == NULL && cdat.fs[0] != '\0')
188 >                return(-1);
189 >        if (cdat.fs[0] != '\0')
190 >                return(copymatch(fmt, cdat.fs) ? 1 : -1);
191          return(0);
192   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines