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.3 by greg, Sun Feb 9 02:18:16 2014 UTC vs.
Revision 2.7 by greg, Tue Feb 11 23:30:11 2014 UTC

# Line 44 | Line 44 | idf_newparam(IDF_LOADED *idf, const char *pname, const
44          if (pnew == NULL)
45                  return(NULL);
46          strcpy(pnew->rem, comm);
47 +        pnew->nfield = 0;
48          pnew->flist = NULL;
49          pnew->pname = pent->key;        /* add to table */
50          pnew->pnext = (IDF_PARAMETER *)pent->data;
# Line 76 | Line 77 | idf_addfield(IDF_PARAMETER *param, const char *fval, c
77          if (fnew == NULL)
78                  return(0);
79          fnew->next = NULL;
80 <        cp = fnew->arg;                 /* copy argument and comments */
80 >        cp = fnew->val;                 /* copy value and comments */
81          while ((*cp++ = *fval++))
82                  ;
83          fnew->rem = cp;
# Line 94 | Line 95 | idf_addfield(IDF_PARAMETER *param, const char *fval, c
95                  param->flist = fnew;
96          else
97                  flast->next = fnew;
98 +        param->nfield++;
99          return(fnum);
100   }
101  
# Line 134 | Line 136 | idf_delparam(IDF_LOADED *idf, IDF_PARAMETER *param)
136                  plast->pnext = param->pnext;
137                                          /* remove from global list */
138          for (plast = NULL, pptr = idf->pfirst;
139 <                                pptr != NULL; plast = pptr, pptr = pptr->dnext)
140 <                if (pptr == param)
141 <                        break;
140 <        if (pptr == NULL)
141 <                return(0);
139 >                                pptr != param; plast = pptr, pptr = pptr->dnext)
140 >                if (pptr == NULL)
141 >                        return(0);
142          if (plast == NULL)
143                  idf->pfirst = param->dnext;
144          else
# Line 155 | Line 155 | idf_delparam(IDF_LOADED *idf, IDF_PARAMETER *param)
155          return(1);
156   }
157  
158 + /* Move the specified parameter to the given position in the IDF */
159 + int
160 + idf_movparam(IDF_LOADED *idf, IDF_PARAMETER *param, IDF_PARAMETER *prev)
161 + {
162 +        IDF_PARAMETER   *pptr, *plast;
163 +
164 +        if ((idf == NULL) | (param == NULL))
165 +                return(0);
166 +                                        /* quick check if already there */
167 +        if (param == (prev==NULL ? idf->pfirst : prev->dnext))
168 +                return(1);
169 +                                        /* find in IDF list, first*/
170 +        for (plast = NULL, pptr = idf->pfirst;
171 +                                pptr != param; plast = pptr, pptr = pptr->dnext)
172 +                if (pptr == NULL)
173 +                        return(0);
174 +        if (plast == NULL)
175 +                idf->pfirst = param->dnext;
176 +        else
177 +                plast->dnext = param->dnext;
178 +        if (idf->plast == param)
179 +                idf->plast = plast;
180 +        if (prev == NULL) {             /* means they want it at beginning */
181 +                param->dnext = idf->pfirst;
182 +                idf->pfirst = param;
183 +        } else {
184 +                param->dnext = prev->dnext;
185 +                prev->dnext = param;
186 +        }
187 +        return(1);
188 + }
189 +
190   /* Get a named parameter list */
191   IDF_PARAMETER *
192   idf_getparam(IDF_LOADED *idf, const char *pname)
# Line 269 | Line 301 | idf_create(const char *hdrcomm)
301          return(idf);
302   }
303  
304 + /* Add comment(s) to header */
305 + int
306 + idf_add2hdr(IDF_LOADED *idf, const char *hdrcomm)
307 + {
308 +        int     olen, len;
309 +
310 +        if ((idf == NULL) | (hdrcomm == NULL))
311 +                return(0);
312 +        len = strlen(hdrcomm);
313 +        if (!len)
314 +                return(0);
315 +        if (idf->hrem == NULL)
316 +                olen = 0;
317 +        else
318 +                olen = strlen(idf->hrem);
319 +        if (olen)
320 +                idf->hrem = (char *)realloc(idf->hrem, olen+len+1);
321 +        else
322 +                idf->hrem = (char *)malloc(len+1);
323 +        if (idf->hrem == NULL)
324 +                return(0);
325 +        strcpy(idf->hrem+olen, hdrcomm);
326 +        return(1);
327 + }
328 +
329   /* Load an Input Data File */
330   IDF_LOADED *
331   idf_load(const char *fname)
332   {
333 <        char            hdrcomm[300*IF_MAXLINE];
333 >        char            hdrcomm[256*IDF_MAXLINE];
334          FILE            *fp;
335          IDF_LOADED      *idf;
336  
# Line 296 | Line 353 | idf_load(const char *fname)
353  
354   /* Write a parameter and fields to an open file */
355   int
356 < idf_writeparam(IDF_PARAMETER *param, FILE *fp)
356 > idf_writeparam(IDF_PARAMETER *param, FILE *fp, int incl_comm)
357   {
358          IDF_FIELD       *fptr;
359  
# Line 304 | Line 361 | idf_writeparam(IDF_PARAMETER *param, FILE *fp)
361                  return(0);
362          fputs(param->pname, fp);
363          fputc(',', fp);
364 <        fputs(param->rem, fp);
364 >        if (incl_comm)
365 >                fputs(param->rem, fp);
366          for (fptr = param->flist; fptr != NULL; fptr = fptr->next) {
367 <                fputs(fptr->arg, fp);
367 >                if (!incl_comm)
368 >                        fputs("\n    ", fp);
369 >                fputs(fptr->val, fp);
370                  fputc((fptr->next==NULL ? ';' : ','), fp);
371 <                fputs(fptr->rem, fp);
371 >                if (incl_comm)
372 >                        fputs(fptr->rem, fp);
373          }
374 +        if (!incl_comm)
375 +                fputs("\n\n", fp);
376          return(!ferror(fp));
377   }
378  
379   /* Write out an Input Data File */
380   int
381 < idf_write(IDF_LOADED *idf, const char *fname)
381 > idf_write(IDF_LOADED *idf, const char *fname, int incl_comm)
382   {
383          FILE            *fp;
384          IDF_PARAMETER   *pptr;
# Line 326 | Line 389 | idf_write(IDF_LOADED *idf, const char *fname)
389                  fp = stdout;            /* open file if not stdout */
390          else if ((fp = fopen(fname, "w")) == NULL)
391                  return(0);
392 <        fputs(idf->hrem, fp);           /* write header then parameters */
392 >        if (incl_comm)
393 >                fputs(idf->hrem, fp);   /* write header then parameters */
394          for (pptr = idf->pfirst; pptr != NULL; pptr = pptr->dnext)
395 <                if (!idf_writeparam(pptr, fp)) {
395 >                if (!idf_writeparam(pptr, fp, incl_comm>0)) {
396                          fclose(fp);
397                          return(0);
398                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines