Changes in variable.c [ce68f23:a16d7e5]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
variable.c
rce68f23 ra16d7e5 70 70 71 71 OWLVAR_BOOL( "startuplogin" /* %OwlVarStub */, 1, 72 "send a login message when owl starts", "" ),72 "send a login message when BarnOwl starts", "" ), 73 73 74 74 OWLVAR_BOOL( "shutdownlogout" /* %OwlVarStub */, 1, 75 "send a logout message when owl exits", "" ),75 "send a logout message when BarnOwl exits", "" ), 76 76 77 77 OWLVAR_BOOL( "rxping" /* %OwlVarStub */, 0, … … 137 137 OWLVAR_BOOL_FULL( "pseudologins" /* %OwlVarStub */, 0, 138 138 "Enable zephyr pseudo logins", 139 "When this is enabled, Owl will periodically check the zephyr\n"139 "When this is enabled, BarnOwl will periodically check the zephyr\n" 140 140 "location of users in your .anyone file. If a user is present\n" 141 141 "but sent no login message, or a user is not present that sent no\n" … … 145 145 OWLVAR_BOOL( "ignorelogins" /* %OwlVarStub */, 0, 146 146 "Enable printing of login notifications", 147 "When this is enabled, Owl will print login and logout notifications\n"148 "for AIM, zephyr, or other protocols. If disabled Owl will not print\n"147 "When this is enabled, BarnOwl will print login and logout notifications\n" 148 "for AIM, zephyr, or other protocols. If disabled BarnOwl will not print\n" 149 149 "login or logout notifications.\n"), 150 150 … … 160 160 OWLVAR_BOOL( "loglogins" /* %OwlVarStub */, 0, 161 161 "Enable logging of login notifications", 162 "When this is enabled, Owl will loginlogin and logout notifications\n"162 "When this is enabled, BarnOwl will log login and logout notifications\n" 163 163 "for AIM, zephyr, or other protocols. If disabled Owl will not print\n" 164 164 "login or logout notifications.\n"), … … 201 201 OWLVAR_PATH( "newmsgproc" /* %OwlVarStub:newmsgproc */, NULL, 202 202 "name of a program to run when new messages are present", 203 "The named program will be run when owl receives new\n"203 "The named program will be run when BarnOwl receives new\n" 204 204 "messages. It will not be run again until the first\n" 205 205 "instance exits"), … … 229 229 "string to append to the end of the sepbar", 230 230 "The sepbar is the bar separating the top and bottom\n" 231 "of the owl screen. Any string specified here will\n"231 "of the BarnOwl screen. Any string specified here will\n" 232 232 "be displayed on the right of the sepbar\n"), 233 233 … … 265 265 266 266 OWLVAR_STRING( "alert_action" /* %OwlVarStub */, "nop", 267 " owl command to execute for alert actions",267 "BarnOwl command to execute for alert actions", 268 268 "" ), 269 269 … … 276 276 "Styles may be created with the 'style' command.\n" 277 277 "Some built-in styles include:\n" 278 " default - the default owl formatting\n"278 " default - the default BarnOwl formatting\n" 279 279 " oneline - one line per-message\n" 280 280 " perl - legacy perl interface\n" … … 333 333 "cursor moves between messages being displayed.\n" 334 334 "The following modes are supported:\n\n" 335 " normal - This is the owl default. Scrolling happens\n"335 " normal - This is the BarnOwl default. Scrolling happens\n" 336 336 " when it needs to, and an attempt is made to\n" 337 337 " keep the current message roughly near\n" … … 662 662 } 663 663 664 void owl_variable_dict_newvar_string(owl_vardict * vd, const char *name, const char *summ, const char * desc, const char * initval) { 665 owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_STRING); 666 if(old) { 664 void owl_variable_dict_newvar_string(owl_vardict *vd, const char *name, const char *summ, const char *desc, const char *initval) 665 { 666 owl_variable *old = owl_variable_get_var(vd, name); 667 if (old && owl_variable_get_type(old) == OWL_VARIABLE_STRING) { 667 668 owl_variable_update(old, summ, desc); 668 669 g_free(old->pval_default); … … 671 672 owl_variable * var = owl_variable_newvar(name, summ, desc); 672 673 var->type = OWL_VARIABLE_STRING; 674 var->validsettings = "<string>"; 673 675 var->pval_default = g_strdup(initval); 674 676 var->set_fn = owl_variable_string_set_default; … … 682 684 } 683 685 684 void owl_variable_dict_newvar_int(owl_vardict * vd, const char *name, const char *summ, const char * desc, int initval) { 685 owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_INT); 686 if(old) { 686 void owl_variable_dict_newvar_int(owl_vardict *vd, const char *name, const char *summ, const char *desc, int initval) 687 { 688 owl_variable *old = owl_variable_get_var(vd, name); 689 if (old && owl_variable_get_type(old) == OWL_VARIABLE_INT) { 687 690 owl_variable_update(old, summ, desc); 688 691 old->ival_default = initval; … … 690 693 owl_variable * var = owl_variable_newvar(name, summ, desc); 691 694 var->type = OWL_VARIABLE_INT; 695 var->validsettings = "<int>"; 692 696 var->ival_default = initval; 693 697 var->validate_fn = owl_variable_int_validate_default; … … 703 707 } 704 708 705 void owl_variable_dict_newvar_bool(owl_vardict * vd, const char *name, const char *summ, const char * desc, int initval) { 706 owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_BOOL); 707 if(old) { 709 void owl_variable_dict_newvar_bool(owl_vardict *vd, const char *name, const char *summ, const char *desc, bool initval) 710 { 711 owl_variable *old = owl_variable_get_var(vd, name); 712 if (old && owl_variable_get_type(old) == OWL_VARIABLE_BOOL) { 708 713 owl_variable_update(old, summ, desc); 709 714 old->ival_default = initval; … … 711 716 owl_variable * var = owl_variable_newvar(name, summ, desc); 712 717 var->type = OWL_VARIABLE_BOOL; 718 var->validsettings = "on,off"; 713 719 var->ival_default = initval; 714 720 var->validate_fn = owl_variable_bool_validate_default; … … 750 756 751 757 758 const char *owl_variable_get_name(const owl_variable *v) 759 { 760 return v->name; 761 } 762 752 763 const char *owl_variable_get_description(const owl_variable *v) { 753 764 return v->description; … … 759 770 760 771 const char *owl_variable_get_validsettings(const owl_variable *v) { 761 if (v->validsettings) { 762 return v->validsettings; 763 } else { 764 return ""; 765 } 772 return v->validsettings; 773 } 774 775 int owl_variable_get_type(const owl_variable *v) 776 { 777 return v->type; 766 778 } 767 779 … … 769 781 770 782 /* returns 0 on success, prints a status msg if msg is true */ 771 int owl_variable_set_fromstring(owl_vardict *d, const char *name, const char *value, int msg, int requirebool) { 772 owl_variable *v; 783 int owl_variable_set_fromstring(owl_variable *v, const char *value, int msg) { 773 784 char *tostring; 774 if (!name) return(-1); 775 v = owl_dict_find_element(d, name); 776 if (v == NULL) { 777 if (msg) owl_function_error("Unknown variable %s", name); 785 if (!v->set_fromstring_fn) { 786 if (msg) owl_function_error("Variable %s is read-only", owl_variable_get_name(v)); 787 return -1; 788 } 789 if (0 != v->set_fromstring_fn(v, value)) { 790 if (msg) owl_function_error("Unable to set %s (must be %s)", owl_variable_get_name(v), 791 owl_variable_get_validsettings(v)); 778 792 return -1; 779 793 } 780 if (!v->set_fromstring_fn) { 781 if (msg) owl_function_error("Variable %s is read-only", name); 782 return -1; 783 } 784 if (requirebool && v->type!=OWL_VARIABLE_BOOL) { 785 if (msg) owl_function_error("Variable %s is not a boolean", name); 786 return -1; 787 } 788 if (0 != v->set_fromstring_fn(v, value)) { 789 if (msg) owl_function_error("Unable to set %s (must be %s)", name, 790 owl_variable_get_validsettings(v)); 791 return -1; 792 } 793 if (msg && v->get_tostring_fn) { 794 if (msg) { 794 795 tostring = v->get_tostring_fn(v, v->get_fn(v)); 795 owl_function_makemsg("%s = '%s'", name, tostring); 796 if (tostring) 797 owl_function_makemsg("%s = '%s'", owl_variable_get_name(v), tostring); 798 else 799 owl_function_makemsg("%s = <null>", owl_variable_get_name(v)); 796 800 g_free(tostring); 797 801 } … … 799 803 } 800 804 801 int owl_variable_set_string(owl_vardict *d, const char *name, const char *newval) { 802 owl_variable *v; 803 if (!name) return(-1); 804 v = owl_dict_find_element(d, name); 805 if (v == NULL || !v->set_fn) return(-1); 806 if (v->type!=OWL_VARIABLE_STRING) return(-1); 805 int owl_variable_set_string(owl_variable *v, const char *newval) 806 { 807 if (v->type != OWL_VARIABLE_STRING) return -1; 807 808 return v->set_fn(v, newval); 808 809 } 809 810 810 int owl_variable_set_int(owl_vardict *d, const char *name, int newval) { 811 owl_variable *v; 812 if (!name) return(-1); 813 v = owl_dict_find_element(d, name); 814 if (v == NULL || !v->set_fn) return(-1); 815 if (v->type!=OWL_VARIABLE_INT && v->type!=OWL_VARIABLE_BOOL) return(-1); 811 int owl_variable_set_int(owl_variable *v, int newval) 812 { 813 if (v->type != OWL_VARIABLE_INT && v->type != OWL_VARIABLE_BOOL) return -1; 816 814 return v->set_fn(v, &newval); 817 815 } 818 816 819 int owl_variable_set_bool_on(owl_var dict *d, const char *name) {820 return owl_variable_set_int(d,name,1); 821 } 822 823 int owl_variable_set_bool_off(owl_vardict *d, const char *name) { 824 return owl_variable_set_int(d,name,0); 825 } 826 827 CALLER_OWN char *owl_variable_get_tostring(const owl_vardict *d, const char *name) 828 { 829 owl_variable *v; 830 if (!name) return NULL; 831 v = owl_dict_find_element(d, name); 832 if (v == NULL || !v->get_tostring_fn) return NULL; 817 int owl_variable_set_bool_on(owl_variable *v) 818 { 819 if (v->type != OWL_VARIABLE_BOOL) return -1; 820 return owl_variable_set_int(v, true); 821 } 822 823 int owl_variable_set_bool_off(owl_variable *v) 824 { 825 if (v->type != OWL_VARIABLE_BOOL) return -1; 826 return owl_variable_set_int(v, false); 827 } 828 829 CALLER_OWN char *owl_variable_get_tostring(const owl_variable *v) 830 { 833 831 return v->get_tostring_fn(v, v->get_fn(v)); 834 832 } 835 833 836 CALLER_OWN char *owl_variable_get_default_tostring(const owl_vardict *d, const char *name) 837 { 838 owl_variable *v; 839 if (!name) return NULL; 840 v = owl_dict_find_element(d, name); 841 if (v == NULL || !v->get_tostring_fn) return NULL; 834 CALLER_OWN char *owl_variable_get_default_tostring(const owl_variable *v) 835 { 842 836 if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { 843 837 return v->get_tostring_fn(v, &(v->ival_default)); … … 847 841 } 848 842 849 owl_variable *owl_variable_get_var(const owl_vardict *d, const char *name, int require_type) { 850 owl_variable *v; 851 if (!name) return(NULL); 852 v = owl_dict_find_element(d, name); 853 if (v == NULL || !v->get_fn || v->type != require_type) return(NULL); 854 return v; 843 owl_variable *owl_variable_get_var(const owl_vardict *d, const char *name) 844 { 845 return owl_dict_find_element(d, name); 855 846 } 856 847 857 848 /* returns a reference */ 858 const void *owl_variable_get(const owl_vardict *d, const char *name, int require_type) { 859 owl_variable *v = owl_variable_get_var(d, name, require_type); 860 if(v == NULL) return NULL; 849 const void *owl_variable_get(const owl_variable *v) 850 { 861 851 return v->get_fn(v); 862 852 } 863 853 854 const char *owl_variable_get_string(const owl_variable *v) 855 { 856 if (owl_variable_get_type(v) != OWL_VARIABLE_STRING) { 857 owl_function_error("Variable '%s' is not a string.", owl_variable_get_name(v)); 858 return NULL; 859 } 860 return owl_variable_get(v); 861 } 862 864 863 /* returns a reference */ 865 const char *owl_variable_get_string(const owl_vardict *d, const char *name) { 866 return owl_variable_get(d,name, OWL_VARIABLE_STRING); 867 } 868 869 /* returns a reference */ 870 const void *owl_variable_get_other(const owl_vardict *d, const char *name) { 871 return owl_variable_get(d,name, OWL_VARIABLE_OTHER); 872 } 873 874 int owl_variable_get_int(const owl_vardict *d, const char *name) { 875 const int *pi; 876 pi = owl_variable_get(d,name,OWL_VARIABLE_INT); 877 if (!pi) return(-1); 878 return(*pi); 879 } 880 881 int owl_variable_get_bool(const owl_vardict *d, const char *name) { 882 const int *pi; 883 pi = owl_variable_get(d,name,OWL_VARIABLE_BOOL); 884 if (!pi) return(-1); 885 return(*pi); 886 } 887 888 void owl_variable_describe(const owl_vardict *d, const char *name, owl_fmtext *fm) { 864 const void *owl_variable_get_other(const owl_variable *v) 865 { 866 if (owl_variable_get_type(v) != OWL_VARIABLE_OTHER) { 867 owl_function_error("Variable '%s' is not type other.", owl_variable_get_name(v)); 868 return NULL; 869 } 870 return owl_variable_get(v); 871 } 872 873 int owl_variable_get_int(const owl_variable *v) 874 { 875 if (owl_variable_get_type(v) != OWL_VARIABLE_INT) { 876 owl_function_error("Variable '%s' is an int.", owl_variable_get_name(v)); 877 return -1; 878 } 879 const int *pi = owl_variable_get(v); 880 if (!pi) return -1; 881 return *pi; 882 } 883 884 int owl_variable_get_bool(const owl_variable *v) 885 { 886 if (owl_variable_get_type(v) != OWL_VARIABLE_BOOL) { 887 owl_function_error("Variable '%s' is a boolean.", owl_variable_get_name(v)); 888 return -1; 889 } 890 const int *pi = owl_variable_get(v); 891 if (!pi) return -1; 892 return *pi; 893 } 894 895 void owl_variable_describe(const owl_variable *v, owl_fmtext *fm) 896 { 897 char *tostring = owl_variable_get_default_tostring(v); 889 898 char *default_buf; 890 owl_variable *v; 891 892 if (!name 893 || (v = owl_dict_find_element(d, name)) == NULL 894 || !v->get_fn) { 895 owl_fmtext_appendf_normal(fm, " No such variable '%s'\n", name); 896 return; 897 } 898 if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { 899 default_buf = v->get_tostring_fn(v, &(v->ival_default)); 900 } else { 901 default_buf = v->get_tostring_fn(v, v->pval_default); 902 } 903 owl_fmtext_appendf_normal(fm, OWL_TABSTR "%-20s - %s (default: '%s')\n", 904 v->name, 905 owl_variable_get_summary(v), default_buf); 899 900 if (tostring) 901 default_buf = g_strdup_printf("'%s'", tostring); 902 else 903 default_buf = g_strdup("<null>"); 904 owl_fmtext_appendf_normal(fm, OWL_TABSTR "%-20s - %s (default: %s)\n", 905 owl_variable_get_name(v), 906 owl_variable_get_summary(v), default_buf); 906 907 g_free(default_buf); 907 } 908 909 void owl_variable_get_help(const owl_vardict *d, const char *name, owl_fmtext *fm) { 908 g_free(tostring); 909 } 910 911 void owl_variable_get_help(const owl_variable *v, owl_fmtext *fm) { 910 912 char *tostring; 911 owl_variable *v;912 913 if (!name914 || (v = owl_dict_find_element(d, name)) == NULL915 || !v->get_fn) {916 owl_fmtext_append_normal(fm, "No such variable...\n");917 return;918 }919 913 920 914 owl_fmtext_append_bold(fm, "OWL VARIABLE\n\n"); 921 915 owl_fmtext_append_normal(fm, OWL_TABSTR); 922 owl_fmtext_append_normal(fm, name);916 owl_fmtext_append_normal(fm, owl_variable_get_name(v)); 923 917 owl_fmtext_append_normal(fm, " - "); 924 owl_fmtext_append_normal(fm, v->summary);918 owl_fmtext_append_normal(fm, owl_variable_get_summary(v)); 925 919 owl_fmtext_append_normal(fm, "\n\n"); 926 920 927 921 owl_fmtext_append_normal(fm, "Current: "); 928 tostring = owl_variable_get_tostring( d, name);929 owl_fmtext_append_normal(fm, tostring);922 tostring = owl_variable_get_tostring(v); 923 owl_fmtext_append_normal(fm, (tostring ? tostring : "<null>")); 930 924 g_free(tostring); 931 925 owl_fmtext_append_normal(fm, "\n\n"); 932 926 933 927 934 if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { 935 tostring = v->get_tostring_fn(v, &(v->ival_default)); 936 } else { 937 tostring = v->get_tostring_fn(v, v->pval_default); 938 } 928 tostring = owl_variable_get_default_tostring(v); 939 929 owl_fmtext_append_normal(fm, "Default: "); 940 owl_fmtext_append_normal(fm, tostring);930 owl_fmtext_append_normal(fm, (tostring ? tostring : "<null>")); 941 931 owl_fmtext_append_normal(fm, "\n\n"); 942 932 … … 998 988 { 999 989 if (val == NULL) { 1000 return g_strdup("<null>");990 return NULL; 1001 991 } else if (*(const int*)val == 0) { 1002 992 return g_strdup("off"); … … 1034 1024 { 1035 1025 if (val == NULL) { 1036 return g_strdup("<null>");1026 return NULL; 1037 1027 } else { 1038 1028 return g_strdup_printf("%d", *(const int*)val); … … 1078 1068 1079 1069 if (val == NULL) { 1080 return g_strdup("<null>");1070 return NULL; 1081 1071 } 1082 1072 enums = g_strsplit_set(v->validsettings, ",", 0); … … 1114 1104 CALLER_OWN char *owl_variable_string_get_tostring_default(const owl_variable *v, const void *val) 1115 1105 { 1116 if (val == NULL) { 1117 return g_strdup("<null>"); 1118 } else { 1119 return g_strdup((const char*)val); 1120 } 1121 } 1122 1106 return g_strdup((const char*)val); 1107 } 1108
Note: See TracChangeset
for help on using the changeset viewer.