ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/eplus_idf.c
(Generate patch)

Comparing ray/src/util/eplus_idf.c (file contents):
Revision 2.9 by greg, Thu Feb 13 17:33:37 2014 UTC vs.
Revision 2.11 by greg, Tue Mar 4 17:06:42 2014 UTC

# Line 225 | Line 225 | idf_read_comment(char *buf, int len, FILE *fp)
225   {
226          int     incomm = 0;
227          char    *cp = buf;
228 <        char    dummyc;
228 >        char    dummys[2];
229          int     c;
230  
231          if ((buf == NULL) | (len <= 0)) {
232 <                buf = &dummyc;
233 <                len = 1;
232 >                buf = dummys;
233 >                len = sizeof(dummys);
234          }
235          while ((c = getc(fp)) != EOF &&
236                          (isspace(c) || (incomm += (c == '!')))) {
237                  if (c == '\n')
238                          incomm = 0;
239 <                if (cp-buf < len-1)
239 >                if (cp-buf < len-2)
240                          *cp++ = c;
241 +                else if (cp-buf == len-2)
242 +                        *cp++ = '\n';
243          }
244          *cp = '\0';
245          if (c != EOF)
# Line 351 | Line 353 | idf_load(const char *fname)
353          return(idf);                    /* success! */
354   }
355  
356 + /* Check string for end-of-line */
357 + static int
358 + idf_hasEOL(const char *s)
359 + {
360 +        while (*s)
361 +                if (*s++ == '\n')
362 +                        return(1);
363 +        return(0);
364 + }
365 +
366   /* Write a object and fields to an open file */
367   int
368   idf_writeparam(IDF_OBJECT *param, FILE *fp, int incl_comm)
# Line 363 | Line 375 | idf_writeparam(IDF_OBJECT *param, FILE *fp, int incl_c
375          fputc(',', fp);
376          if (incl_comm)
377                  fputs(param->rem, fp);
378 +        else
379 +                fputc('\n', fp);
380          for (fptr = param->flist; fptr != NULL; fptr = fptr->next) {
381                  if (!incl_comm)
382 <                        fputs("\n    ", fp);
382 >                        fputs("    ", fp);
383                  fputs(fptr->val, fp);
384 <                fputc((fptr->next==NULL ? ';' : ','), fp);
384 >                if (fptr->next == NULL) {
385 >                        fputc(';', fp);
386 >                        if (incl_comm && !idf_hasEOL(fptr->rem))
387 >                                fputc('\n', fp);
388 >                } else
389 >                        fputc(',', fp);
390                  if (incl_comm)
391                          fputs(fptr->rem, fp);
392 +                else
393 +                        fputc('\n', fp);
394          }
395          if (!incl_comm)
396 <                fputs("\n\n", fp);
396 >                fputc('\n', fp);
397          return(!ferror(fp));
398   }
399  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines