Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/lib/common/input.c
ViewVC logotype

Diff of /branches/pure-cfg/src/lib/common/input.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1252, Sun May 22 22:11:07 2011 UTC revision 1253, Mon May 23 16:55:42 2011 UTC
# Line 114  Line 114 
114    
115  //! Option type tags  //! Option type tags
116  typedef enum {  typedef enum {
117      optTypeUnknown,      optTypeUnknown,       // 0
118      optTypeFlag,      optTypeFlag,          // 1
119      optTypeBool,      optTypeBool,          // 2
120      optTypeInt,      optTypeInt,           // 3
121      optTypeReal,      optTypeReal,          // 4
122      optTypeReal2,      optTypeReal2,         // 5
123      optTypeReal3,      optTypeReal3,         // 6
124      optTypeReal4,      optTypeReal4,         // 7
125      optTypeString      optTypeString         // 8
126  } optType_t;  } optType_t;
127    
128  typedef struct {  typedef struct {
# Line 143  Line 143 
143                            // intended to be one or more sentences                            // intended to be one or more sentences
144      hestOpt *hopt;        // dynamically managed hest options      hestOpt *hopt;        // dynamically managed hest options
145      hestParm *hparm;      // hest parameters      hestParm *hparm;      // hest parameters
146      optDef_t *odef;       // dynamically reallocated via odefArr      optDef_t **odef;      // dynamically reallocated via odefArr
147      unsigned int odefNum; // length of meaningful values in odef[]      unsigned int odefNum; // length of meaningful values in odef[]
148      airArray *odefArr;    // manages odef and odefNum;      airArray *odefArr;    // manages odef and odefNum;
149      airArray *mop;        // manages hopt, hparm, and odefArr      airArray *mop;        // manages hopt, hparm, and odefArr
150  };  };
151    
152  static void optDefInit (void *_odef) {  static void *optDefNew () {
153      optDef_t *odef = (optDef_t *)_odef;      optDef_t *odef = AIR_CALLOC(1, optDef_t);
154      odef->name = odef->desc = NULL;      odef->name = odef->desc = NULL;
155      odef->ty = optTypeUnknown;      odef->ty = optTypeUnknown;
156        /* not trying to initialize hval */
157      odef->valp = NULL;      odef->valp = NULL;
158      return;      return (void*)odef;
159  }  }
160    
161  static void optDefDone (void *_odef) {  static void *optDefNix (void *_odef) {
162      optDef_t *odef = (optDef_t *)_odef;      optDef_t *odef = (optDef_t *)_odef;
163      airFree(odef->name);      airFree(odef->name);
164      airFree(odef->desc);      airFree(odef->desc);
165      if (optTypeString == odef->ty) {      if (optTypeString == odef->ty) {
166          airFree(odef->hval.s);          airFree(odef->hval.s);
167      }      }
168      return;      airFree(odef);
169        return NULL;
170  }  }
171    
172  struct Diderot_Options_s *Diderot_Options_New (void) {  struct Diderot_Options_s *Diderot_Options_New (void) {
# Line 183  Line 185 
185      dopts->odef = NULL;      dopts->odef = NULL;
186      dopts->odefNum = 0;      dopts->odefNum = 0;
187      dopts->odefArr = airArrayNew((void**)(&dopts->odef), &dopts->odefNum,      dopts->odefArr = airArrayNew((void**)(&dopts->odef), &dopts->odefNum,
188                                   sizeof(optDef_t), 16 /* allocation increment */);                                   sizeof(optDef_t*), 8 /* allocation increment */);
189      if (!(dopts->odefArr)) {      if (!(dopts->odefArr)) {
190          fprintf (stderr, "%s: unable to allocate option array\n", me);          fprintf (stderr, "%s: unable to allocate option array\n", me);
191          exit (1);          exit (1);
192      }      }
     airArrayStructCB(dopts->odefArr, optDefInit, optDefDone);  
193      airMopAdd(dopts->mop, dopts->odefArr, (airMopper)airArrayNuke, airMopAlways);      airMopAdd(dopts->mop, dopts->odefArr, (airMopper)airArrayNuke, airMopAlways);
194    
195      return dopts;      return dopts;
# Line 231  Line 232 
232          fprintf (stderr, "%s: unable to reallocate option array\n", me);          fprintf (stderr, "%s: unable to reallocate option array\n", me);
233          exit (1);          exit (1);
234      }      }
235      optDef_t *odef = dopts->odef + nidx;      optDef_t *odef = dopts->odef[nidx];
236      odef->name = airStrdup(name);      odef->name = airStrdup(name);
237      odef->desc = airStrdup(desc);      odef->desc = airStrdup(desc);
238      if (!(odef->name && odef->desc)) {      if (!(odef->name && odef->desc)) {
# Line 353  Line 354 
354    
355      // convert values learned by hest to their Diderot representations      // convert values learned by hest to their Diderot representations
356      for (int i = 0;  i < dopts->odefNum;  i++) {      for (int i = 0;  i < dopts->odefNum;  i++) {
357          optDef_t *odef = dopts->odef + i;          optDef_t *odef = dopts->odef[i];
358          switch (odef->ty) {          switch (odef->ty) {
359          case optTypeFlag:          case optTypeFlag:
360          case optTypeBool:          case optTypeBool:

Legend:
Removed from v.1252  
changed lines
  Added in v.1253

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0