Changeset ca54fd6 for commands.c


Ignore:
Timestamp:
Jul 3, 2011, 8:42:55 PM (10 years ago)
Author:
Jason Gross <jgross@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
ca749a9
Parents:
bc1d648
git-author:
Jason Gross <jgross@mit.edu> (06/27/11 01:14:13)
git-committer:
Jason Gross <jgross@mit.edu> (07/03/11 20:42:55)
Message:
Pass owl_variable * around instead of owl_vardict *.

This allows (forces) functions to do their own NULL- and type- checking
on variables.  The functions in varsubs.c get less checking, but if
these auto-generated functions are failing, something more serious is
probably wrong.

The owl_variable_get_* functions type-check their arguments, and
owl_function_error if the argument is the wrong type (it's a programmer
error and we should make some noise).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    re6d7e4e rca54fd6  
    15721572  int  silent=0;
    15731573  int requirebool=0;
     1574  owl_variable *v;
    15741575
    15751576  if (argc == 1) {
     
    15941595    return NULL;
    15951596  }
    1596   owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, requirebool);
     1597
     1598  v = owl_variable_get_var(owl_global_get_vardict(&g), var);
     1599  if (v == NULL) {
     1600    if (!silent) owl_function_error("Unknown variable '%s'", var);
     1601  } else if (requirebool && owl_variable_get_type(v) != OWL_VARIABLE_BOOL) {
     1602    if (!silent) owl_function_error("Variable '%s' is not a boolean", var);
     1603  } else {
     1604    owl_variable_set_fromstring(v, val, !silent);
     1605  }
    15971606  return NULL;
    15981607}
     
    16001609char *owl_command_unset(int argc, const char *const *argv, const char *buff)
    16011610{
     1611  owl_variable *v;
    16021612  const char *var, *val;
    16031613  int  silent=0;
     
    16141624    return NULL;
    16151625  }
    1616   owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, 1);
     1626
     1627  v = owl_variable_get_var(owl_global_get_vardict(&g), var);
     1628  if (v == NULL) {
     1629    if (!silent) owl_function_error("Unknown variable '%s'", var);
     1630  } else if (owl_variable_get_type(v) != OWL_VARIABLE_BOOL) {
     1631    if (!silent) owl_function_error("Variable '%s' is not a boolean", var);
     1632  } else {
     1633    owl_variable_set_fromstring(v, val, !silent);
     1634  }
    16171635  return NULL;
    16181636}
     
    16221640  const char *var;
    16231641  char *value;
     1642  const owl_variable *v;
    16241643
    16251644  if (argc==1) {
     
    16331652  var=argv[1];
    16341653   
    1635   value = owl_variable_get_tostring(owl_global_get_vardict(&g), var);
    1636   if (value) {
     1654  v = owl_variable_get_var(owl_global_get_vardict(&g), var);
     1655  if (v) {
     1656    value = owl_variable_get_tostring(v);
    16371657    owl_function_makemsg("%s = '%s'", var, value);
    16381658    g_free(value);
     
    25052525}
    25062526
    2507 char *owl_command_getvar(int argc, const char *const *argv, const char *buff)
    2508 {
     2527CALLER_OWN char *owl_command_getvar(int argc, const char *const *argv, const char *buff)
     2528{
     2529  const owl_variable *v;
    25092530  if (argc != 2) {
    25102531    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
    25112532    return NULL;
    25122533  }
    2513   return owl_variable_get_tostring(owl_global_get_vardict(&g), argv[1]);
     2534  v = owl_variable_get_var(owl_global_get_vardict(&g), argv[1]);
     2535  if (v == NULL) return NULL;
     2536  return owl_variable_get_tostring(v);
    25142537}
    25152538
Note: See TracChangeset for help on using the changeset viewer.