Changeset 0d935a1
- Timestamp:
- Jun 27, 2011, 4:28:51 AM (13 years ago)
- 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)
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
commands.c
re6d7e4e r0d935a1 1572 1572 int silent=0; 1573 1573 int requirebool=0; 1574 owl_variable *v; 1574 1575 1575 1576 if (argc == 1) { … … 1594 1595 return NULL; 1595 1596 } 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 } 1597 1606 return NULL; 1598 1607 } … … 1600 1609 char *owl_command_unset(int argc, const char *const *argv, const char *buff) 1601 1610 { 1611 owl_variable *v; 1602 1612 const char *var, *val; 1603 1613 int silent=0; … … 1614 1624 return NULL; 1615 1625 } 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 } 1617 1635 return NULL; 1618 1636 } … … 1622 1640 const char *var; 1623 1641 char *value; 1642 const owl_variable *v; 1624 1643 1625 1644 if (argc==1) { … … 1633 1652 var=argv[1]; 1634 1653 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); 1638 1661 g_free(value); 1639 1662 } else { … … 2505 2528 } 2506 2529 2507 char *owl_command_getvar(int argc, const char *const *argv, const char *buff) 2508 { 2530 CALLER_OWN char *owl_command_getvar(int argc, const char *const *argv, const char *buff) 2531 { 2532 const owl_variable *v; 2509 2533 if (argc != 2) { 2510 2534 owl_function_makemsg("Wrong number of arguments for %s", argv[0]); 2511 2535 return NULL; 2512 2536 } 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); 2514 2540 } 2515 2541 -
functions.c
rb8a3e00 r0d935a1 1572 1572 void owl_function_printallvars(void) 1573 1573 { 1574 const owl_variable *v; 1574 1575 const char *name; 1575 1576 char *var; … … 1585 1586 if (name && name[0]!='_') { 1586 1587 g_string_append_printf(str, "\n%-20s = ", name); 1587 var = owl_variable_get_tostring(owl_global_get_vardict(&g), name); 1588 v = owl_variable_get_var(owl_global_get_vardict(&g), name); 1589 var = owl_variable_get_tostring(v); 1588 1590 if (var) { 1589 1591 g_string_append(str, var); 1590 1592 g_free(var); 1593 } else { 1594 g_string_append(str, "<null>"); 1591 1595 } 1592 1596 } … … 1601 1605 void owl_function_show_variables(void) 1602 1606 { 1607 const owl_variable *v; 1603 1608 GPtrArray *varnames; 1604 1609 owl_fmtext fm; … … 1613 1618 varname = varnames->pdata[i]; 1614 1619 if (varname && varname[0]!='_') { 1615 owl_variable_describe(owl_global_get_vardict(&g), varname, &fm); 1620 v = owl_variable_get_var(owl_global_get_vardict(&g), varname); 1621 owl_variable_describe(v, &fm); 1616 1622 } 1617 1623 } … … 1623 1629 void owl_function_show_variable(const char *name) 1624 1630 { 1631 const owl_variable *v; 1625 1632 owl_fmtext fm; 1626 1633 1627 1634 owl_fmtext_init_null(&fm); 1628 owl_variable_get_help(owl_global_get_vardict(&g), name, &fm); 1635 v = owl_variable_get_var(owl_global_get_vardict(&g), name); 1636 if (v) 1637 owl_variable_get_help(v, &fm); 1638 else 1639 owl_fmtext_append_normal(&fm, "No such variable...\n"); 1629 1640 owl_function_popless_fmtext(&fm); 1630 1641 owl_fmtext_cleanup(&fm); -
help.c
rce68f23 r0d935a1 4 4 void owl_help(void) 5 5 { 6 const owl_variable *v; 6 7 owl_fmtext fm; 7 8 const char *varname; … … 133 134 varname = varnames->pdata[i]; 134 135 if (varname && varname[0]!='_') { 135 owl_variable_describe(owl_global_get_vardict(&g), varname, &fm); 136 v = owl_variable_get_var(owl_global_get_vardict(&g), varname); 137 owl_variable_describe(v, &fm); 136 138 } 137 139 } -
stubgen.pl
rfd03b12 r0d935a1 14 14 if ($vartype =~ /^BOOL/) { 15 15 print "void owl_global_set_${altvarname}_on(owl_global *g) {\n"; 16 print " owl_variable_set_bool_on( &g->vars, \"$varname\");\n}\n";16 print " owl_variable_set_bool_on(owl_variable_get_var(&g->vars, \"$varname\"));\n}\n"; 17 17 print "void owl_global_set_${altvarname}_off(owl_global *g) {\n"; 18 print " owl_variable_set_bool_off( &g->vars, \"$varname\");\n}\n";18 print " owl_variable_set_bool_off(owl_variable_get_var(&g->vars, \"$varname\"));\n}\n"; 19 19 print "int owl_global_is_$altvarname(const owl_global *g) {\n"; 20 print " return owl_variable_get_bool( &g->vars, \"$varname\");\n}\n";20 print " return owl_variable_get_bool(owl_variable_get_var(&g->vars, \"$varname\"));\n}\n"; 21 21 } elsif ($vartype =~ /^PATH/ or $vartype =~ /^STRING/) { 22 22 print "void owl_global_set_$altvarname(owl_global *g, const char *text) {\n"; 23 print " owl_variable_set_string( &g->vars, \"$varname\", text);\n}\n";23 print " owl_variable_set_string(owl_variable_get_var(&g->vars, \"$varname\"), text);\n}\n"; 24 24 print "const char *owl_global_get_$altvarname(const owl_global *g) {\n"; 25 print " return owl_variable_get_string( &g->vars, \"$varname\");\n}\n";25 print " return owl_variable_get_string(owl_variable_get_var(&g->vars, \"$varname\"));\n}\n"; 26 26 } elsif ($vartype =~ /^INT/ or $vartype =~ /^ENUM/) { 27 27 print "void owl_global_set_$altvarname(owl_global *g, int n) {\n"; 28 print " owl_variable_set_int( &g->vars, \"$varname\", n);\n}\n";28 print " owl_variable_set_int(owl_variable_get_var(&g->vars, \"$varname\"), n);\n}\n"; 29 29 print "int owl_global_get_$altvarname(const owl_global *g) {\n"; 30 print " return owl_variable_get_int( &g->vars, \"$varname\");\n}\n";30 print " return owl_variable_get_int(owl_variable_get_var(&g->vars, \"$varname\"));\n}\n"; 31 31 } 32 32 } -
tester.c
reeba011 r0d935a1 276 276 int owl_variable_regtest(void) { 277 277 owl_vardict vd; 278 owl_variable *var; 278 279 int numfailed=0; 279 280 char *value; … … 283 284 FAIL_UNLESS("setup", 0==owl_variable_dict_setup(&vd)); 284 285 285 FAIL_UNLESS("get bool", 0==owl_variable_get_bool(&vd,"rxping")); 286 FAIL_UNLESS("get bool (no such)", -1==owl_variable_get_bool(&vd,"mumble")); 286 FAIL_UNLESS("get bool var", NULL != (var = owl_variable_get_var(&vd, "rxping"))); 287 FAIL_UNLESS("get bool", 0 == owl_variable_get_bool(var)); 288 FAIL_UNLESS("get bool (no such)", NULL == owl_variable_get_var(&vd, "mumble")); 287 289 FAIL_UNLESS("get bool as string", 288 !strcmp((value = owl_variable_get_tostring( &vd,"rxping")), "off"));290 !strcmp((value = owl_variable_get_tostring(var)), "off")); 289 291 g_free(value); 290 FAIL_UNLESS("set bool 1", 0==owl_variable_set_bool_on(&vd,"rxping")); 291 FAIL_UNLESS("get bool 2", 1==owl_variable_get_bool(&vd,"rxping")); 292 FAIL_UNLESS("set bool 3", 0==owl_variable_set_fromstring(&vd,"rxping","off",0,0)); 293 FAIL_UNLESS("get bool 4", 0==owl_variable_get_bool(&vd,"rxping")); 294 FAIL_UNLESS("set bool 5", -1==owl_variable_set_fromstring(&vd,"rxping","xxx",0,0)); 295 FAIL_UNLESS("get bool 6", 0==owl_variable_get_bool(&vd,"rxping")); 296 297 298 FAIL_UNLESS("get string", 0==strcmp("~/zlog/people", owl_variable_get_string(&vd,"logpath"))); 299 FAIL_UNLESS("set string 7", 0==owl_variable_set_string(&vd,"logpath","whee")); 300 FAIL_UNLESS("get string", 0==strcmp("whee", owl_variable_get_string(&vd,"logpath"))); 301 302 FAIL_UNLESS("get int", 8==owl_variable_get_int(&vd,"typewinsize")); 303 FAIL_UNLESS("get int (no such)", -1==owl_variable_get_int(&vd,"mmble")); 292 FAIL_UNLESS("set bool 1", 0 == owl_variable_set_bool_on(var)); 293 FAIL_UNLESS("get bool 2", 1 == owl_variable_get_bool(var)); 294 FAIL_UNLESS("set bool 3", 0 == owl_variable_set_fromstring(var, "off", 0)); 295 FAIL_UNLESS("get bool 4", 0 == owl_variable_get_bool(var)); 296 FAIL_UNLESS("set bool 5", -1 == owl_variable_set_fromstring(var, "xxx", 0)); 297 FAIL_UNLESS("get bool 6", 0 == owl_variable_get_bool(var)); 298 299 300 FAIL_UNLESS("get string var", NULL != (var = owl_variable_get_var(&vd, "logpath"))); 301 FAIL_UNLESS("get string", 0 == strcmp("~/zlog/people", owl_variable_get_string(var))); 302 FAIL_UNLESS("set string 7", 0 == owl_variable_set_string(var, "whee")); 303 FAIL_UNLESS("get string", !strcmp("whee", owl_variable_get_string(var))); 304 305 FAIL_UNLESS("get int var", NULL != (var = owl_variable_get_var(&vd, "typewinsize"))); 306 FAIL_UNLESS("get int", 8 == owl_variable_get_int(var)); 307 FAIL_UNLESS("get int (no such)", NULL == owl_variable_get_var(&vd, "mumble")); 304 308 FAIL_UNLESS("get int as string", 305 !strcmp( (value = owl_variable_get_tostring(&vd,"typewinsize")), "8"));309 !strcmp(value = owl_variable_get_tostring(var), "8")); 306 310 g_free(value); 307 FAIL_UNLESS("set int 1", 0 ==owl_variable_set_int(&vd,"typewinsize",12));308 FAIL_UNLESS("get int 2", 12 ==owl_variable_get_int(&vd,"typewinsize"));309 FAIL_UNLESS("set int 1b", -1 ==owl_variable_set_int(&vd,"typewinsize",-3));310 FAIL_UNLESS("get int 2b", 12 ==owl_variable_get_int(&vd,"typewinsize"));311 FAIL_UNLESS("set int 3", 0 ==owl_variable_set_fromstring(&vd,"typewinsize","9",0,0));312 FAIL_UNLESS("get int 4", 9 ==owl_variable_get_int(&vd,"typewinsize"));313 FAIL_UNLESS("set int 5", -1 ==owl_variable_set_fromstring(&vd,"typewinsize","xxx",0,0));314 FAIL_UNLESS("set int 6", -1 ==owl_variable_set_fromstring(&vd,"typewinsize","",0,0));315 FAIL_UNLESS("get int 7", 9 ==owl_variable_get_int(&vd,"typewinsize"));311 FAIL_UNLESS("set int 1", 0 == owl_variable_set_int(var, 12)); 312 FAIL_UNLESS("get int 2", 12 == owl_variable_get_int(var)); 313 FAIL_UNLESS("set int 1b", -1 == owl_variable_set_int(var, -3)); 314 FAIL_UNLESS("get int 2b", 12 == owl_variable_get_int(var)); 315 FAIL_UNLESS("set int 3", 0 == owl_variable_set_fromstring(var, "9", 0)); 316 FAIL_UNLESS("get int 4", 9 == owl_variable_get_int(var)); 317 FAIL_UNLESS("set int 5", -1 == owl_variable_set_fromstring(var, "xxx", 0)); 318 FAIL_UNLESS("set int 6", -1 == owl_variable_set_fromstring(var, "", 0)); 319 FAIL_UNLESS("get int 7", 9 == owl_variable_get_int(var)); 316 320 317 321 owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval"); 318 FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(&vd, "stringvar"))); 319 FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(&vd, "stringvar"))); 320 owl_variable_set_string(&vd, "stringvar", "new val"); 321 FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(&vd, "stringvar"))); 322 FAIL_UNLESS("get new string var", NULL != (var = owl_variable_get_var(&vd, "stringvar"))); 323 FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(var))); 324 FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(var))); 325 owl_variable_set_string(var, "new val"); 326 FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(var))); 322 327 323 328 owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47); 324 FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(&vd, "intvar"))); 325 FAIL_UNLESS("get new int val", 47 == owl_variable_get_int(&vd, "intvar")); 326 owl_variable_set_int(&vd, "intvar", 17); 327 FAIL_UNLESS("update bool val", 17 == owl_variable_get_int(&vd, "intvar")); 329 FAIL_UNLESS("get new int var", NULL != (var = owl_variable_get_var(&vd, "intvar"))); 330 FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(var))); 331 FAIL_UNLESS("get new int val", 47 == owl_variable_get_int(var)); 332 owl_variable_set_int(var, 17); 333 FAIL_UNLESS("update int val", 17 == owl_variable_get_int(var)); 328 334 329 335 owl_variable_dict_newvar_bool(&vd, "boolvar", "", "", 1); 330 FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(&vd, "boolvar"))); 331 FAIL_UNLESS("get new bool val", owl_variable_get_bool(&vd, "boolvar")); 332 owl_variable_set_bool_off(&vd, "boolvar"); 333 FAIL_UNLESS("update string val", !owl_variable_get_bool(&vd, "boolvar")); 336 FAIL_UNLESS("get new bool var", NULL != (var = owl_variable_get_var(&vd, "boolvar"))); 337 FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(var))); 338 FAIL_UNLESS("get new bool val", owl_variable_get_bool(var)); 339 owl_variable_set_bool_off(var); 340 FAIL_UNLESS("update bool val", !owl_variable_get_bool(var)); 334 341 335 342 owl_variable_dict_cleanup(&vd); -
variable.c
rf4e857f r0d935a1 717 717 718 718 719 const char *owl_variable_get_name(const owl_variable *v) 720 { 721 return v->name; 722 } 723 719 724 const char *owl_variable_get_description(const owl_variable *v) { 720 725 return v->description; … … 732 737 733 738 /* returns 0 on success, prints a status msg if msg is true */ 734 int owl_variable_set_fromstring(owl_vardict *d, const char *name, const char *value, int msg, int requirebool) { 735 owl_variable *v; 739 int owl_variable_set_fromstring(owl_variable *v, const char *value, int msg) { 736 740 char *tostring; 737 if (!name) return(-1);738 v = owl_dict_find_element(d, name);739 if (v == NULL) {740 if (msg) owl_function_error("Unknown variable %s", name);741 return -1;742 }743 741 if (!v->set_fromstring_fn) { 744 if (msg) owl_function_error("Variable %s is read-only", name);742 if (msg) owl_function_error("Variable %s is read-only", owl_variable_get_name(v)); 745 743 return -1; 746 744 } 747 if (requirebool && v->type!=OWL_VARIABLE_BOOL) {748 if (msg) owl_function_error("Variable %s is not a boolean", name);749 return -1;750 }751 745 if (0 != v->set_fromstring_fn(v, value)) { 752 if (msg) owl_function_error("Unable to set %s (must be %s)", name,753 746 if (msg) owl_function_error("Unable to set %s (must be %s)", owl_variable_get_name(v), 747 owl_variable_get_validsettings(v)); 754 748 return -1; 755 749 } 756 750 if (msg) { 757 751 tostring = v->get_tostring_fn(v, v->get_fn(v)); 758 owl_function_makemsg("%s = '%s'", name, tostring); 752 if (tostring) 753 owl_function_makemsg("%s = '%s'", owl_variable_get_name(v), tostring); 754 else 755 owl_function_makemsg("%s = <null>", owl_variable_get_name(v)); 759 756 g_free(tostring); 760 757 } … … 762 759 } 763 760 764 int owl_variable_set_string(owl_vardict *d, const char *name, const char *newval) { 765 owl_variable *v; 766 if (!name) return(-1); 767 v = owl_dict_find_element(d, name); 768 if (v == NULL || !v->set_fn) return(-1); 769 if (v->type!=OWL_VARIABLE_STRING) return(-1); 761 int owl_variable_set_string(owl_variable *v, const char *newval) 762 { 763 if (v->type != OWL_VARIABLE_STRING) return -1; 770 764 return v->set_fn(v, newval); 771 765 } 772 766 773 int owl_variable_set_int(owl_vardict *d, const char *name, int newval) { 774 owl_variable *v; 775 if (!name) return(-1); 776 v = owl_dict_find_element(d, name); 777 if (v == NULL || !v->set_fn) return(-1); 778 if (v->type!=OWL_VARIABLE_INT && v->type!=OWL_VARIABLE_BOOL) return(-1); 767 int owl_variable_set_int(owl_variable *v, int newval) 768 { 769 if (v->type != OWL_VARIABLE_INT && v->type != OWL_VARIABLE_BOOL) return -1; 779 770 return v->set_fn(v, &newval); 780 771 } 781 772 782 int owl_variable_set_bool_on(owl_var dict *d, const char *name) {783 return owl_variable_set_int(d,name,1); 784 } 785 786 int owl_variable_set_bool_off(owl_vardict *d, const char *name) { 787 return owl_variable_set_int(d,name,0); 788 } 789 790 CALLER_OWN char *owl_variable_get_tostring(const owl_vardict *d, const char *name) 791 { 792 owl_variable *v; 793 if (!name) return NULL; 794 v = owl_dict_find_element(d, name); 795 if (v == NULL) return NULL; 773 int owl_variable_set_bool_on(owl_variable *v) 774 { 775 if (v->type != OWL_VARIABLE_BOOL) return -1; 776 return owl_variable_set_int(v, true); 777 } 778 779 int owl_variable_set_bool_off(owl_variable *v) 780 { 781 if (v->type != OWL_VARIABLE_BOOL) return -1; 782 return owl_variable_set_int(v, false); 783 } 784 785 CALLER_OWN char *owl_variable_get_tostring(const owl_variable *v) 786 { 796 787 return v->get_tostring_fn(v, v->get_fn(v)); 797 788 } 798 789 799 CALLER_OWN char *owl_variable_get_default_tostring(const owl_vardict *d, const char *name) 800 { 801 owl_variable *v; 802 if (!name) return NULL; 803 v = owl_dict_find_element(d, name); 804 if (v == NULL) return NULL; 790 CALLER_OWN char *owl_variable_get_default_tostring(const owl_variable *v) 791 { 805 792 if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { 806 793 return v->get_tostring_fn(v, &(v->ival_default)); … … 812 799 owl_variable *owl_variable_get_var(const owl_vardict *d, const char *name) 813 800 { 814 owl_variable *v; 815 if (!name) return(NULL); 816 v = owl_dict_find_element(d, name); 817 if (v == NULL) return NULL; 818 return v; 801 if (name == NULL) return NULL; 802 return owl_dict_find_element(d, name); 819 803 } 820 804 821 805 /* returns a reference */ 822 const void *owl_variable_get(const owl_vardict *d, const char *name) 823 { 824 const owl_variable *v = owl_variable_get_var(d, name); 825 if(v == NULL) return NULL; 806 const void *owl_variable_get(const owl_variable *v) 807 { 826 808 return v->get_fn(v); 827 809 } 828 810 829 811 /* returns a reference */ 830 const char *owl_variable_get_string(const owl_vardict *d, const char *name) { 812 const char *owl_variable_get_string(const owl_variable *v) 813 { 831 814 /* XXX TODO: Put type checking back in */ 832 return owl_variable_get( d, name);815 return owl_variable_get(v); 833 816 } 834 817 835 818 /* returns a reference */ 836 const void *owl_variable_get_other(const owl_vardict *d, const char *name) { 819 const void *owl_variable_get_other(const owl_variable *v) 820 { 837 821 /* XXX TODO: Put type checking back in */ 838 return owl_variable_get(d, name); 839 } 840 841 int owl_variable_get_int(const owl_vardict *d, const char *name) { 822 return owl_variable_get(v); 823 } 824 825 int owl_variable_get_int(const owl_variable *v) 826 { 842 827 /* XXX TODO: Put type checking back in */ 843 const int *pi = owl_variable_get( d, name);828 const int *pi = owl_variable_get(v); 844 829 if (!pi) return(-1); 845 830 return(*pi); 846 831 } 847 832 848 int owl_variable_get_bool(const owl_vardict *d, const char *name) { 833 int owl_variable_get_bool(const owl_variable *v) 834 { 849 835 /* XXX TODO: Put type checking back in */ 850 const int *pi = owl_variable_get( d, name);836 const int *pi = owl_variable_get(v); 851 837 if (!pi) return(-1); 852 838 return(*pi); 853 839 } 854 840 855 void owl_variable_describe(const owl_vardict *d, const char *name, owl_fmtext *fm) { 841 void owl_variable_describe(const owl_variable *v, owl_fmtext *fm) 842 { 843 char *tostring = owl_variable_get_default_tostring(v); 856 844 char *default_buf; 857 owl_variable *v; 858 859 if (!name 860 || (v = owl_dict_find_element(d, name)) == NULL) { 861 owl_fmtext_appendf_normal(fm, " No such variable '%s'\n", name); 862 return; 863 } 864 if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { 865 default_buf = v->get_tostring_fn(v, &(v->ival_default)); 866 } else { 867 default_buf = v->get_tostring_fn(v, v->pval_default); 868 } 869 owl_fmtext_appendf_normal(fm, OWL_TABSTR "%-20s - %s (default: '%s')\n", 870 v->name, 871 owl_variable_get_summary(v), default_buf); 845 846 if (tostring) 847 default_buf = g_strdup_printf("'%s'", tostring); 848 else 849 default_buf = g_strdup("<null>"); 850 owl_fmtext_appendf_normal(fm, OWL_TABSTR "%-20s - %s (default: %s)\n", 851 owl_variable_get_name(v), 852 owl_variable_get_summary(v), default_buf); 872 853 g_free(default_buf); 873 } 874 875 void owl_variable_get_help(const owl_vardict *d, const char *name, owl_fmtext *fm) { 854 g_free(tostring); 855 } 856 857 void owl_variable_get_help(const owl_variable *v, owl_fmtext *fm) { 876 858 char *tostring; 877 owl_variable *v;878 879 if (!name880 || (v = owl_dict_find_element(d, name)) == NULL) {881 owl_fmtext_append_normal(fm, "No such variable...\n");882 return;883 }884 859 885 860 owl_fmtext_append_bold(fm, "OWL VARIABLE\n\n"); 886 861 owl_fmtext_append_normal(fm, OWL_TABSTR); 887 owl_fmtext_append_normal(fm, name);862 owl_fmtext_append_normal(fm, v->name); 888 863 owl_fmtext_append_normal(fm, " - "); 889 864 owl_fmtext_append_normal(fm, v->summary); … … 891 866 892 867 owl_fmtext_append_normal(fm, "Current: "); 893 tostring = owl_variable_get_tostring(d, name); 894 owl_fmtext_append_normal(fm, tostring); 868 tostring = owl_variable_get_tostring(v); 869 if (tostring) 870 owl_fmtext_append_normal(fm, tostring); 871 else 872 owl_fmtext_append_normal(fm, "<null>"); 895 873 g_free(tostring); 896 874 owl_fmtext_append_normal(fm, "\n\n"); 897 875 898 876 899 if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { 900 tostring = v->get_tostring_fn(v, &(v->ival_default)); 901 } else { 902 tostring = v->get_tostring_fn(v, v->pval_default); 903 } 877 tostring = owl_variable_get_default_tostring(v); 904 878 owl_fmtext_append_normal(fm, "Default: "); 905 owl_fmtext_append_normal(fm, tostring); 879 if (tostring) 880 owl_fmtext_append_normal(fm, tostring); 881 else 882 owl_fmtext_append_normal(fm, "<null>"); 906 883 owl_fmtext_append_normal(fm, "\n\n"); 907 884
Note: See TracChangeset
for help on using the changeset viewer.