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.31 by greg, Wed May 10 18:02:08 2017 UTC vs.
Revision 2.35 by greg, Fri Jul 19 17:37:56 2019 UTC

# Line 4 | Line 4 | static const char      RCSid[] = "$Id$";
4   /*
5   *  header.c - routines for reading and writing information headers.
6   *
7 < *  Externals declared in resolu.h
7 > *  Externals declared in rtio.h
8   *
9   *  newheader(t,fp)     start new information header identified by string t
10   *  headidval(r,s)      copy header identifier value in s to r
# Line 170 | Line 170 | printargs(             /* print arguments to a file */
170  
171   int
172   formatval(                      /* get format value (return true if format) */
173 <        char  *r,
173 >        char  fmt[MAXFMTLEN],
174          const char  *s
175   )
176   {
177          const char  *cp = FMTSTR;
178 +        char  *r = fmt;
179  
180          while (*cp) if (*cp++ != *s++) return(0);
181          while (isspace(*s)) s++;
# Line 182 | Line 183 | formatval(                     /* get format value (return true if forma
183          if (r == NULL) return(1);
184          do
185                  *r++ = *s++;
186 <        while (*s && !isspace(*s));
186 >        while (*s && !isspace(*s) && r-fmt < MAXFMTLEN-1);
187          *r = '\0';
188          return(1);
189   }
# Line 209 | Line 210 | getheader(             /* get header from file */
210   {
211          int   rtotal = 0;
212          char  buf[MAXLINE];
213 +        int   firstc = fgetc(fp);
214  
215 +        if (!isprint(firstc))
216 +                return(-1);                             /* messed up */
217 +        ungetc(firstc, fp);
218          for ( ; ; ) {
219                  int     rval = 0;
220                  buf[MAXLINE-2] = '\n';
221                  if (fgets(buf, MAXLINE, fp) == NULL)
222                          return(-1);
223 <                if (buf[buf[0]=='\r'] == '\n')
223 >                if (buf[buf[0]=='\r'] == '\n')          /* end of header? */
224                          return(rtotal);
225                  if (buf[MAXLINE-2] != '\n') {
226                          ungetc(buf[MAXLINE-2], fp);     /* prevent false end */
# Line 230 | Line 235 | getheader(             /* get header from file */
235  
236   struct check {
237          FILE    *fp;
238 <        char    fs[64];
238 >        char    fs[MAXFMTLEN];
239   };
240  
241  
# Line 240 | Line 245 | mycheck(                       /* check a header line for format info. */
245          void  *cp
246   )
247   {
248 <        if (!formatval(((struct check*)cp)->fs, s)
249 <                        && ((struct check*)cp)->fp != NULL) {
250 <                fputs(s, ((struct check*)cp)->fp);
251 <        }
248 >        struct check    *scp = (struct check *)cp;
249 >
250 >        if (!formatval(scp->fs, s) && scp->fp != NULL)
251 >                fputs(s, scp->fp);
252 >
253          return(0);
254   }
255  
# Line 319 | Line 325 | globmatch(                     /* check for match of s against pattern p
325   int
326   checkheader(
327          FILE  *fin,
328 <        char  *fmt,
328 >        char  fmt[MAXFMTLEN],
329          FILE  *fout
330   )
331   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines