Changeset ca749a9 for variable.c


Ignore:
Timestamp:
Jul 3, 2011, 8:43:06 PM (10 years ago)
Author:
Jason Gross <jgross@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
b4a678a
Parents:
ca54fd6
git-author:
Jason Gross <jgross@mit.edu> (06/27/11 04:14:36)
git-committer:
Jason Gross <jgross@mit.edu> (07/03/11 20:43:06)
Message:
Make variable getters return NULL instead of "<null>"

This fixes trac-#184:
Since commit 010a9511420887329269aa51e7598533e826c57f, the default zsigs
show up as empty; BarnOwl::default_zephyr_signature() checks
BarnOwl::getvar('zsigproc') as a boolean (which may be incorrect if you
happen to have a zsigproc called 0). As of that commit, BarnOwl::getvar
returns "<null>" instead of undef.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • variable.c

    rca54fd6 rca749a9  
    795795  if (msg && v->get_tostring_fn) {
    796796    tostring = v->get_tostring_fn(v, v->get_fn(v));
    797     owl_function_makemsg("%s = '%s'", owl_variable_get_name(v), tostring);
     797    if (tostring)
     798      owl_function_makemsg("%s = '%s'", owl_variable_get_name(v), tostring);
     799    else
     800      owl_function_makemsg("%s = <null>", owl_variable_get_name(v));
    798801    g_free(tostring);
    799802  }   
     
    897900void owl_variable_describe(const owl_variable *v, owl_fmtext *fm)
    898901{
    899   char *default_buf = owl_variable_get_default_tostring(v);
    900 
    901   owl_fmtext_appendf_normal(fm, OWL_TABSTR "%-20s - %s (default: '%s')\n",
    902                             owl_variable_get_name(v),
    903                             owl_variable_get_summary(v), default_buf);
     902  char *tostring = owl_variable_get_default_tostring(v);
     903  char *default_buf;
     904
     905  if (tostring)
     906    default_buf = g_strdup_printf("'%s'", tostring);
     907  else
     908    default_buf = g_strdup("<null>");
     909  owl_fmtext_appendf_normal(fm, OWL_TABSTR "%-20s - %s (default: %s)\n",
     910                            owl_variable_get_name(v),
     911                            owl_variable_get_summary(v), default_buf);
    904912  g_free(default_buf);
     913  g_free(tostring);
    905914}
    906915
     
    917926  owl_fmtext_append_normal(fm, "Current:        ");
    918927  tostring = owl_variable_get_tostring(v);
    919   owl_fmtext_append_normal(fm, tostring);
     928  owl_fmtext_append_normal(fm, (tostring ? tostring : "<null>"));
    920929  g_free(tostring);
    921930  owl_fmtext_append_normal(fm, "\n\n");
     
    924933  tostring = owl_variable_get_default_tostring(v);
    925934  owl_fmtext_append_normal(fm, "Default:        ");
    926   owl_fmtext_append_normal(fm, tostring);
     935  owl_fmtext_append_normal(fm, (tostring ? tostring : "<null>"));
    927936  owl_fmtext_append_normal(fm, "\n\n");
    928937
     
    984993{
    985994  if (val == NULL) {
    986     return g_strdup("<null>");
     995    return NULL;
    987996  } else if (*(const int*)val == 0) {
    988997    return g_strdup("off");
     
    10201029{
    10211030  if (val == NULL) {
    1022     return g_strdup("<null>");
     1031    return NULL;
    10231032  } else {
    10241033    return g_strdup_printf("%d", *(const int*)val);
     
    10641073
    10651074  if (val == NULL) {
    1066     return g_strdup("<null>");
     1075    return NULL;
    10671076  }
    10681077  enums = g_strsplit_set(v->validsettings, ",", 0);
     
    11001109CALLER_OWN char *owl_variable_string_get_tostring_default(const owl_variable *v, const void *val)
    11011110{
    1102   if (val == NULL) {
    1103     return g_strdup("<null>");
    1104   } else {
    1105     return g_strdup((const char*)val);
    1106   }
    1107 }
    1108 
     1111  return g_strdup((const char*)val);
     1112}
     1113
Note: See TracChangeset for help on using the changeset viewer.