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.5 by greg, Sun Oct 15 14:07:58 1995 UTC vs.
Revision 2.7 by greg, Tue Mar 12 11:29:16 1996 UTC

# Line 17 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17   *  formatval(r,s)      copy the format value in s to r
18   *  fputformat(s,fp)    write "FORMAT=%s" to fp
19   *  getheader(fp,f,p)   read header from fp, calling f(s,p) on each line
20 < *  copymatch(pat, str) copy str into pat if glob match
20 > *  globmatch(pat, str) check for glob match of str against pat
21   *  checkheader(i,p,o)  check header format from i against p and copy to o
22   *
23   *  To copy header from input to output, use getheader(fin, fputs, fout)
# Line 176 | Line 176 | register struct check  *cp;
176   }
177  
178  
179 /*
180 * Copymatch(pat,str) checks pat for wildcards, and
181 * copies str into pat if there is a match (returning true).
182 */
183
179   int
180 < copymatch(pat, str)
180 > globmatch(pat, str)             /* check for glob match of str against pat */
181   char    *pat, *str;
182   {
188        int     docopy = 0;
183          register char   *p = pat, *s = str;
184  
185          do {
# Line 193 | Line 187 | char   *pat, *str;
187                  case '?':                       /* match any character */
188                          if (!*s++)
189                                  return(0);
196                        docopy++;
190                          break;
191                  case '*':                       /* match any string */
192                          while (p[1] == '*') p++;
193                          do
194 <                                if ( (p[1]=='?' || p[1]==*s)
195 <                                                && copymatch(p+1,s) ) {
203 <                                        strcpy(pat, str);
194 >                                if ( (p[1]=='?' || p[1]==*s) &&
195 >                                                globmatch(p+1,s) )
196                                          return(1);
205                                }
197                          while (*s++);
198                          return(0);
199                  case '\\':                      /* literal next */
# Line 215 | Line 206 | char   *pat, *str;
206                          break;
207                  }
208          } while (*p++);
218        if (docopy)
219                strcpy(pat, str);
209          return(1);
210   }
211  
# Line 229 | Line 218 | char   *pat, *str;
218   * if any input format is found (or there is an error), and 0 otherwise.
219   * If fmt contains any '*' or '?' characters, then checkheader
220   * does wildcard expansion and copies a matching result into fmt.
221 < * Be sure that fmt is big enough to hold the match in such cases!
221 > * Be sure that fmt is big enough to hold the match in such cases,
222 > * and that it is not a static, read-only string!
223   * The input header (minus any format lines) is copied to fout
224   * if fout is not NULL.
225   */
# Line 241 | Line 231 | char  *fmt;
231   FILE  *fout;
232   {
233          struct check    cdat;
234 +        register char   *cp;
235  
236          cdat.fp = fout;
237          cdat.fs[0] = '\0';
238          if (getheader(fin, mycheck, &cdat) < 0)
239                  return(-1);
240 <        if (cdat.fs[0] != '\0')
241 <                return(copymatch(fmt, cdat.fs) ? 1 : -1);
242 <        return(0);
240 >        if (!cdat.fs[0])
241 >                return(0);
242 >        for (cp = fmt; *cp; cp++)               /* check for globbing */
243 >                if (*cp == '?' | *cp == '*')
244 >                        if (globmatch(fmt, cdat.fs)) {
245 >                                strcpy(fmt, cdat.fs);
246 >                                return(1);
247 >                        } else
248 >                                return(-1);
249 >        return(strcmp(fmt, cdat.fs) ? -1 : 1);  /* literal match */
250   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines