Changeset 0d935a1 for commands.c


Ignore:
Timestamp:
Jun 27, 2011, 4:28:51 AM (14 years ago)
Author:
Jason Gross <jgross@mit.edu>
Children:
b75a8ac
Parents:
f4e857f
git-author:
Jason Gross <jgross@mit.edu> (06/27/11 01:14:13)
git-committer:
Jason Gross <jgross@mit.edu> (06/27/11 04:28:51)
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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    re6d7e4e r0d935a1  
    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 && v->type != 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 (v->type != 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) {
    1637     owl_function_makemsg("%s = '%s'", var, value);
     1654  v = owl_variable_get_var(owl_global_get_vardict(&g), var);
     1655  if (v) {
     1656    value = owl_variable_get_tostring(v);
     1657    if (value == NULL)
     1658      owl_function_makemsg("%s = <null>", var);
     1659    else
     1660      owl_function_makemsg("%s = '%s'", var, value);
    16381661    g_free(value);
    16391662  } else {
     
    25052528}
    25062529
    2507 char *owl_command_getvar(int argc, const char *const *argv, const char *buff)
    2508 {
     2530CALLER_OWN char *owl_command_getvar(int argc, const char *const *argv, const char *buff)
     2531{
     2532  const owl_variable *v;
    25092533  if (argc != 2) {
    25102534    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
    25112535    return NULL;
    25122536  }
    2513   return owl_variable_get_tostring(owl_global_get_vardict(&g), argv[1]);
     2537  v = owl_variable_get_var(owl_global_get_vardict(&g), argv[1]);
     2538  if (v == NULL) return NULL;
     2539  return owl_variable_get_tostring(v);
    25142540}
    25152541
Note: See TracChangeset for help on using the changeset viewer.