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.4 by greg, Sun Feb 27 10:16:45 1994 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 + *  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 48 | Line 49 | register FILE  *fp;
49   }
50  
51  
52 + int
53   headidval(r,s)                  /* get header id (return true if is id) */
54   register char  *r, *s;
55   {
# Line 61 | Line 63 | register char  *r, *s;
63   }
64  
65  
66 + int
67   isheadid(s)                     /* check to see if line is header id */
68   char  *s;
69   {
# Line 92 | Line 95 | register FILE  *fp;
95   }
96  
97  
98 + int
99   formatval(r, s)                 /* get format value (return true if format) */
100   register char  *r;
101   register char  *s;
# Line 102 | Line 106 | register char  *s;
106          while (isspace(*s)) s++;
107          if (!*s) return(0);
108          if (r == NULL) return(1);
109 <        while(*s) *r++ = *s++;
110 <        while (isspace(r[-1])) r--;
109 >        do
110 >                *r++ = *s++;
111 >        while(*s && !isspace(*s));
112          *r = '\0';
113          return(1);
114   }
115  
116  
117 + int
118   isformat(s)                     /* is line a format line? */
119   char  *s;
120   {
# Line 126 | Line 132 | FILE  *fp;
132   }
133  
134  
135 + int
136   getheader(fp, f, p)             /* get header from file */
137   FILE  *fp;
138   int  (*f)();
# Line 169 | Line 176 | register struct check  *cp;
176   }
177  
178  
179 < /*
180 < * Copymatch(pat,str) checks pat for wildcards, and
174 < * copies str into pat if there is a match (returning true).
175 < */
176 <
177 < #ifdef COPYMATCH
178 < copymatch(pat, str)
179 > int
180 > globmatch(pat, str)             /* check for glob match of str against pat */
181   char    *pat, *str;
182   {
181        int     docopy = 0;
183          register char   *p = pat, *s = str;
184  
185          do {
# Line 186 | Line 187 | char   *pat, *str;
187                  case '?':                       /* match any character */
188                          if (!*s++)
189                                  return(0);
189                        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) ) {
196 <                                        strcpy(pat, str);
194 >                                if ( (p[1]=='?' || p[1]==*s) &&
195 >                                                globmatch(p+1,s) )
196                                          return(1);
198                                }
197                          while (*s++);
198                          return(0);
199                  case '\\':                      /* literal next */
# Line 208 | Line 206 | char   *pat, *str;
206                          break;
207                  }
208          } while (*p++);
211        if (docopy)
212                strcpy(pat, str);
209          return(1);
210   }
215 #else
216 #define copymatch(pat, s)       (!strcmp(pat, s))
217 #endif
211  
212  
213   /*
# Line 225 | 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   */
226  
227 + int
228   checkheader(fin, fmt, fout)
229   FILE  *fin;
230   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