--- ray/src/util/eplus_idf.c 2014/02/13 17:39:39 2.10 +++ ray/src/util/eplus_idf.c 2014/03/05 19:49:39 2.12 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: eplus_idf.c,v 2.10 2014/02/13 17:39:39 greg Exp $"; +static const char RCSid[] = "$Id: eplus_idf.c,v 2.12 2014/03/05 19:49:39 greg Exp $"; #endif /* * eplus_idf.c @@ -353,6 +353,16 @@ idf_load(const char *fname) return(idf); /* success! */ } +/* Check string for end-of-line */ +static int +idf_hasEOL(const char *s) +{ + while (*s) + if (*s++ == '\n') + return(1); + return(0); +} + /* Write a object and fields to an open file */ int idf_writeparam(IDF_OBJECT *param, FILE *fp, int incl_comm) @@ -365,16 +375,25 @@ idf_writeparam(IDF_OBJECT *param, FILE *fp, int incl_c fputc(',', fp); if (incl_comm) fputs(param->rem, fp); + else + fputc('\n', fp); for (fptr = param->flist; fptr != NULL; fptr = fptr->next) { if (!incl_comm) - fputs("\n ", fp); + fputs(" ", fp); fputs(fptr->val, fp); - fputc((fptr->next==NULL ? ';' : ','), fp); + if (fptr->next == NULL) { + fputc(';', fp); + if (incl_comm && !idf_hasEOL(fptr->rem)) + fputc('\n', fp); + } else + fputc(',', fp); if (incl_comm) fputs(fptr->rem, fp); + else + fputc('\n', fp); } if (!incl_comm) - fputs("\n\n", fp); + fputc('\n', fp); return(!ferror(fp)); } @@ -409,9 +428,18 @@ idf_free(IDF_LOADED *idf) { if (idf == NULL) return; + while (idf->pfirst != NULL) { + IDF_OBJECT *pdel = idf->pfirst; + idf->pfirst = pdel->dnext; + while (pdel->flist != NULL) { + IDF_FIELD *fdel = pdel->flist; + pdel->flist = fdel->next; + free(fdel); + } + free(pdel); + } + lu_done(&idf->ptab); if (idf->hrem != NULL) free(idf->hrem); - while (idf->pfirst != NULL) - idf_delobject(idf, idf->pfirst); - lu_done(&idf->ptab); + free(idf); }