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.6 by greg, Mon Feb 10 04:51:26 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 +                                        /* find in IDF list, first*/
167 +        for (plast = NULL, pptr = idf->pfirst;
168 +                                pptr != param; plast = pptr, pptr = pptr->dnext)
169 +                if (pptr == NULL)
170 +                        return(0);
171 +        if (plast == NULL) {
172 +                if (prev == NULL)
173 +                        return(1);      /* already in place */
174 +                idf->pfirst = param->dnext;
175 +        } else {
176 +                if (prev == plast)
177 +                        return(1);      /* already in place */
178 +                plast->dnext = param->dnext;
179 +        }
180 +        if (idf->plast == param)
181 +                idf->plast = plast;
182 +        if (prev == NULL) {             /* means they want it at beginning */
183 +                param->dnext = idf->pfirst;
184 +                idf->pfirst = param;
185 +        } else {
186 +                param->dnext = prev->dnext;
187 +                prev->dnext = param;
188 +        }
189 +        return(1);
190 + }
191 +
192   /* Get a named parameter list */
193   IDF_PARAMETER *
194   idf_getparam(IDF_LOADED *idf, const char *pname)
# Line 269 | Line 303 | idf_create(const char *hdrcomm)
303          return(idf);
304   }
305  
306 + /* Add comment(s) to header */
307 + int
308 + idf_add2hdr(IDF_LOADED *idf, const char *hdrcomm)
309 + {
310 +        int     olen, len;
311 +
312 +        if ((idf == NULL) | (hdrcomm == NULL))
313 +                return(0);
314 +        len = strlen(hdrcomm);
315 +        if (!len)
316 +                return(0);
317 +        if (idf->hrem == NULL)
318 +                olen = 0;
319 +        else
320 +                olen = strlen(idf->hrem);
321 +        if (olen)
322 +                idf->hrem = (char *)realloc(idf->hrem, olen+len+1);
323 +        else
324 +                idf->hrem = (char *)malloc(len+1);
325 +        if (idf->hrem == NULL)
326 +                return(0);
327 +        strcpy(idf->hrem+olen, hdrcomm);
328 +        return(1);
329 + }
330 +
331   /* Load an Input Data File */
332   IDF_LOADED *
333   idf_load(const char *fname)
334   {
335 <        char            hdrcomm[300*IF_MAXLINE];
335 >        char            hdrcomm[256*IDF_MAXLINE];
336          FILE            *fp;
337          IDF_LOADED      *idf;
338  
# Line 296 | Line 355 | idf_load(const char *fname)
355  
356   /* Write a parameter and fields to an open file */
357   int
358 < idf_writeparam(IDF_PARAMETER *param, FILE *fp)
358 > idf_writeparam(IDF_PARAMETER *param, FILE *fp, int incl_comm)
359   {
360          IDF_FIELD       *fptr;
361  
# Line 304 | Line 363 | idf_writeparam(IDF_PARAMETER *param, FILE *fp)
363                  return(0);
364          fputs(param->pname, fp);
365          fputc(',', fp);
366 <        fputs(param->rem, fp);
366 >        if (incl_comm)
367 >                fputs(param->rem, fp);
368          for (fptr = param->flist; fptr != NULL; fptr = fptr->next) {
369 <                fputs(fptr->arg, fp);
369 >                if (!incl_comm)
370 >                        fputs("\n    ", fp);
371 >                fputs(fptr->val, fp);
372                  fputc((fptr->next==NULL ? ';' : ','), fp);
373 <                fputs(fptr->rem, fp);
373 >                if (incl_comm)
374 >                        fputs(fptr->rem, fp);
375          }
376 +        if (!incl_comm)
377 +                fputs("\n\n", fp);
378          return(!ferror(fp));
379   }
380  
381   /* Write out an Input Data File */
382   int
383 < idf_write(IDF_LOADED *idf, const char *fname)
383 > idf_write(IDF_LOADED *idf, const char *fname, int incl_comm)
384   {
385          FILE            *fp;
386          IDF_PARAMETER   *pptr;
# Line 326 | Line 391 | idf_write(IDF_LOADED *idf, const char *fname)
391                  fp = stdout;            /* open file if not stdout */
392          else if ((fp = fopen(fname, "w")) == NULL)
393                  return(0);
394 <        fputs(idf->hrem, fp);           /* write header then parameters */
394 >        if (incl_comm)
395 >                fputs(idf->hrem, fp);   /* write header then parameters */
396          for (pptr = idf->pfirst; pptr != NULL; pptr = pptr->dnext)
397 <                if (!idf_writeparam(pptr, fp)) {
397 >                if (!idf_writeparam(pptr, fp, incl_comm>0)) {
398                          fclose(fp);
399                          return(0);
400                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines