Changeset c0e728a


Ignore:
Timestamp:
Sep 30, 2011, 8:12:25 AM (12 years ago)
Author:
Jason Gross <jgross@mit.edu>
Children:
b54b06a
Parents:
5f784ec
git-author:
Jason Gross <jgross@mit.edu> (06/27/11 01:41:01)
git-committer:
Jason Gross <jgross@mit.edu> (09/30/11 08:12:25)
Message:
Added functionality to create new enum variables from C
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • owl.h

    rb9517cf rc0e728a  
    237237  void *pval_default;  /* for types other and string */
    238238  int   ival_default;  /* for types int and bool     */
    239   const char *validsettings;    /* documentation of valid settings */
     239  char *validsettings;          /* documentation of valid settings */
    240240  char *summary;                /* summary of usage */
    241241  char *description;            /* detailed description */
  • variable.c

    r5f784ec rc0e728a  
    33
    44#define OWLVAR_BOOL(name,default,summary,description) \
    5         { g_strdup(name), OWL_VARIABLE_BOOL, NULL, default, "on,off", g_strdup(summary), g_strdup(description), NULL, \
     5        { g_strdup(name), OWL_VARIABLE_BOOL, NULL, default, g_strdup("on,off"), g_strdup(summary), g_strdup(description), NULL, \
    66        NULL, NULL, NULL, NULL, NULL, NULL }
    77
    88#define OWLVAR_BOOL_FULL(name,default,summary,description,validate,set,get) \
    9         { g_strdup(name), OWL_VARIABLE_BOOL, NULL, default, "on,off", g_strdup(summary), g_strdup(description), NULL, \
     9        { g_strdup(name), OWL_VARIABLE_BOOL, NULL, default, g_strdup("on,off"), g_strdup(summary), g_strdup(description), NULL, \
    1010        validate, set, NULL, get, NULL, NULL }
    1111
    1212#define OWLVAR_INT(name,default,summary,description) \
    13         { g_strdup(name), OWL_VARIABLE_INT, NULL, default, "<int>", g_strdup(summary), g_strdup(description), NULL, \
     13        { g_strdup(name), OWL_VARIABLE_INT, NULL, default, g_strdup("<int>"), g_strdup(summary), g_strdup(description), NULL, \
    1414        NULL, NULL, NULL, NULL, NULL, NULL }
    1515
    1616#define OWLVAR_INT_FULL(name,default,summary,description,validset,validate,set,get) \
    17         { g_strdup(name), OWL_VARIABLE_INT, NULL, default, validset, g_strdup(summary), g_strdup(description), NULL, \
     17        { g_strdup(name), OWL_VARIABLE_INT, NULL, default, g_strdup(validset), g_strdup(summary), g_strdup(description), NULL, \
    1818        validate, set, NULL, get, NULL, NULL }
    1919
    2020#define OWLVAR_PATH(name,default,summary,description) \
    21         { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, "<path>", g_strdup(summary), g_strdup(description),  NULL, \
     21        { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, g_strdup("<path>"), g_strdup(summary), g_strdup(description),  NULL, \
    2222        NULL, NULL, NULL, NULL, NULL, NULL }
    2323
    2424#define OWLVAR_STRING(name,default,summary,description) \
    25         { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, "<string>", g_strdup(summary), g_strdup(description), NULL, \
     25        { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, g_strdup("<string>"), g_strdup(summary), g_strdup(description), NULL, \
    2626        NULL, NULL, NULL, NULL, NULL, NULL }
    2727
    2828#define OWLVAR_STRING_FULL(name,default,validset,summary,description,validate,set,get) \
    29         { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, validset, g_strdup(summary), g_strdup(description), NULL, \
     29        { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, g_strdup(validset), g_strdup(summary), g_strdup(description), NULL, \
    3030        validate, set, NULL, get, NULL, NULL }
    3131
     
    3434 * correspond to the values that may be specified. */
    3535#define OWLVAR_ENUM(name,default,summary,description,validset) \
    36         { g_strdup(name), OWL_VARIABLE_INT, NULL, default, validset, g_strdup(summary), g_strdup(description), NULL, \
     36        { g_strdup(name), OWL_VARIABLE_INT, NULL, default, g_strdup(validset), g_strdup(summary), g_strdup(description), NULL, \
    3737        owl_variable_enum_validate, \
    3838        NULL, owl_variable_enum_set_fromstring, \
     
    4141
    4242#define OWLVAR_ENUM_FULL(name,default,summary,description,validset,validate, set, get) \
    43         { g_strdup(name), OWL_VARIABLE_INT, NULL, default, validset, g_strdup(summary), g_strdup(description), NULL, \
     43        { g_strdup(name), OWL_VARIABLE_INT, NULL, default, g_strdup(validset), g_strdup(summary), g_strdup(description), NULL, \
    4444        validate, \
    4545        set, owl_variable_enum_set_fromstring, \
     
    577577    cur->summary = g_strdup(var->summary);
    578578    cur->description = g_strdup(var->description);
     579    cur->validsettings = g_strdup(var->validsettings);
    579580    if (cur->type == OWL_VARIABLE_STRING)
    580581      cur->pval_default = g_strdup(var->pval_default);
     
    659660  var->summary = g_strdup(summary);
    660661  var->description = g_strdup(description);
    661   var->validsettings = validsettings;
     662  var->validsettings = g_strdup(validsettings);
    662663  var->type = type;
    663664  return var;
     
    696697{
    697698  owl_variable *old = owl_variable_get_var(vd, name);
    698   bool oldval;
     699  int oldval;
    699700  if (old && owl_variable_get_type(old) == OWL_VARIABLE_BOOL)
    700701    oldval = owl_variable_get_bool(old);
     
    707708}
    708709
     710void owl_variable_dict_newvar_enum(owl_vardict *vd, const char *name, const char *summ, const char *desc, int initval, const char *validsettings)
     711{
     712  owl_variable *old = owl_variable_get_var(vd, name);
     713  int oldval;
     714  if (old && owl_variable_get_type(old) == OWL_VARIABLE_INT)
     715    oldval = owl_variable_get_int(old);
     716  owl_variable *var = owl_variable_newvar(name, summ, desc, validsettings, OWL_VARIABLE_INT);
     717  var->ival_default = initval;
     718  var->validate_fn = owl_variable_enum_validate;
     719  var->set_fromstring_fn = owl_variable_enum_set_fromstring;
     720  var->get_tostring_fn = owl_variable_enum_get_tostring;
     721  owl_variable_init_defaults(var);
     722  if (old && owl_variable_get_type(old) == OWL_VARIABLE_INT)
     723    var->set_fn(var, &oldval);
     724  owl_variable_dict_add_variable(vd, var);
     725}
     726
    709727void owl_variable_dict_cleanup(owl_vardict *d)
    710728{
     
    722740  g_free(v->summary);
    723741  g_free(v->description);
     742  g_free(v->validsettings);
    724743  if (v->type == OWL_VARIABLE_STRING)
    725744    g_free(v->pval_default);
Note: See TracChangeset for help on using the changeset viewer.