Changeset a695a68 for variable.c


Ignore:
Timestamp:
May 18, 2007, 4:54:51 PM (14 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
cd57601
Parents:
ec53338
git-author:
Nelson Elhage <nelhage@mit.edu> (05/18/07 16:54:42)
git-committer:
Nelson Elhage <nelhage@mit.edu> (05/18/07 16:54:51)
Message:
Adding the ability to define new variables from perl.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • variable.c

    r2fa15f0 ra695a68  
    518518}
    519519
     520void owl_variable_dict_add_variable(owl_vardict * vardict,
     521                                    owl_variable * var) {
     522  owl_dict_insert_element(vardict, var->name, (void*)var, NULL);
     523}
     524
     525owl_variable * owl_variable_newvar(char *name, char *summary, char * description) {
     526  owl_variable * var = (owl_variable*)owl_malloc(sizeof(owl_variable));
     527  memset(var, 0, sizeof(owl_variable));
     528  var->name = owl_strdup(name);
     529  var->summary = owl_strdup(summary);
     530  var->description = owl_strdup(description);
     531  return var;
     532}
     533
     534void owl_variable_dict_newvar_string(owl_vardict * vd, char *name, char *summ, char * desc, char * initval) {
     535  owl_variable * var = owl_variable_newvar(name, summ, desc);
     536  var->type = OWL_VARIABLE_STRING;
     537  var->pval_default = owl_strdup(initval);
     538  var->set_fn = owl_variable_string_set_default;
     539  var->set_fromstring_fn = owl_variable_string_set_fromstring_default;
     540  var->get_fn = owl_variable_get_default;
     541  var->get_tostring_fn = owl_variable_string_get_tostring_default;
     542  var->free_fn = owl_variable_free_default;
     543  var->set_fn(var, initval);
     544  owl_variable_dict_add_variable(vd, var);
     545}
     546
     547void owl_variable_dict_newvar_int(owl_vardict * vd, char *name, char *summ, char * desc, int initval) {
     548  owl_variable * var = owl_variable_newvar(name, summ, desc);
     549  var->type = OWL_VARIABLE_INT;
     550  var->ival_default = initval;
     551  var->validate_fn = owl_variable_int_validate_default;
     552  var->set_fn = owl_variable_int_set_default;
     553  var->set_fromstring_fn = owl_variable_int_set_fromstring_default;
     554  var->get_fn = owl_variable_get_default;
     555  var->get_tostring_fn = owl_variable_int_get_tostring_default;
     556  var->free_fn = owl_variable_free_default;
     557  var->val = owl_malloc(sizeof(int));
     558  var->set_fn(var, &initval);
     559  owl_variable_dict_add_variable(vd, var);
     560}
     561
     562void owl_variable_dict_newvar_bool(owl_vardict * vd, char *name, char *summ, char * desc, int initval) {
     563  owl_variable * var = owl_variable_newvar(name, summ, desc);
     564  var->type = OWL_VARIABLE_BOOL;
     565  var->ival_default = initval;
     566  var->validate_fn = owl_variable_bool_validate_default;
     567  var->set_fn = owl_variable_bool_set_default;
     568  var->set_fromstring_fn = owl_variable_bool_set_fromstring_default;
     569  var->get_fn = owl_variable_get_default;
     570  var->get_tostring_fn = owl_variable_bool_get_tostring_default;
     571  var->free_fn = owl_variable_free_default;
     572  var->val = owl_malloc(sizeof(int));
     573  var->set_fn(var, &initval);
     574  owl_variable_dict_add_variable(vd, var);
     575}
     576
    520577void owl_variable_dict_free(owl_vardict *d) {
    521578  owl_dict_free_all(d, (void(*)(void*))owl_variable_free);
     
    9701027  FAIL_UNLESS("get enum 10", OWL_WEBBROWSER_NETSCAPE==owl_variable_get_int(&vd,"webbrowser"));
    9711028
    972 
     1029  owl_variable * v;
     1030 
     1031  owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval");
     1032  FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(&vd, "stringvar", OWL_VARIABLE_STRING)));
     1033  FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(&vd, "stringvar")));
     1034  owl_variable_set_string(&vd, "stringvar", "new val");
     1035  FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(&vd, "stringvar")));
     1036
     1037  owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47);
     1038  FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(&vd, "intvar", OWL_VARIABLE_INT)));
     1039  FAIL_UNLESS("get new int val", 47 == owl_variable_get_int(&vd, "intvar"));
     1040  owl_variable_set_int(&vd, "intvar", 17);
     1041  FAIL_UNLESS("update bool val", 17 == owl_variable_get_int(&vd, "intvar"));
     1042
     1043  owl_variable_dict_newvar_bool(&vd, "boolvar", "", "", 1);
     1044  FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(&vd, "boolvar", OWL_VARIABLE_BOOL)));
     1045  FAIL_UNLESS("get new bool val", owl_variable_get_bool(&vd, "boolvar"));
     1046  owl_variable_set_bool_off(&vd, "boolvar");
     1047  FAIL_UNLESS("update string val", !owl_variable_get_bool(&vd, "boolvar"));
    9731048
    9741049  owl_variable_dict_free(&vd);
Note: See TracChangeset for help on using the changeset viewer.