[7d4fbcd] | 1 | #include "owl.h" |
---|
[f271129] | 2 | #include <stdio.h> |
---|
[06e04a9] | 3 | #include "gmarshal_funcs.h" |
---|
| 4 | |
---|
[353719a] | 5 | /* TODO(davidben): When we can require 2.30 and up, remove this. */ |
---|
| 6 | #ifndef G_VALUE_INIT |
---|
| 7 | #define G_VALUE_INIT { 0, { { 0 } } } |
---|
| 8 | #endif |
---|
| 9 | |
---|
| 10 | typedef const char *(*get_string_t)(const owl_variable *); |
---|
| 11 | typedef int (*get_int_t)(const owl_variable *); |
---|
[4584d1f] | 12 | typedef bool (*get_bool_t)(const owl_variable *); |
---|
[353719a] | 13 | |
---|
| 14 | typedef int (*set_string_t)(owl_variable *, const char *); |
---|
| 15 | typedef int (*set_int_t)(owl_variable *, int); |
---|
[4584d1f] | 16 | typedef int (*set_bool_t)(owl_variable *, bool); |
---|
| 17 | |
---|
| 18 | typedef int (*validate_string_t)(const owl_variable *, const char *); |
---|
| 19 | typedef int (*validate_int_t)(const owl_variable *, int); |
---|
| 20 | typedef int (*validate_bool_t)(const owl_variable *, bool); |
---|
| 21 | |
---|
| 22 | static void owl_variable_dict_newvar_bool_full(owl_vardict *vd, |
---|
| 23 | const char *name, |
---|
| 24 | bool default_val, |
---|
| 25 | const char *summary, |
---|
| 26 | const char *description, |
---|
| 27 | validate_bool_t validate_fn, |
---|
| 28 | set_bool_t set_fn, |
---|
| 29 | get_bool_t get_fn); |
---|
| 30 | |
---|
| 31 | static void owl_variable_dict_newvar_string_full(owl_vardict *vd, |
---|
| 32 | const char *name, |
---|
| 33 | const char *default_val, |
---|
| 34 | const char *summary, |
---|
| 35 | const char *description, |
---|
| 36 | const char *validsettings, |
---|
| 37 | validate_string_t validate_fn, |
---|
| 38 | set_string_t set_fn, |
---|
| 39 | get_string_t get_fn); |
---|
| 40 | |
---|
| 41 | static void owl_variable_dict_newvar_int_full(owl_vardict *vd, |
---|
| 42 | const char *name, |
---|
| 43 | int default_val, |
---|
| 44 | const char *summary, |
---|
| 45 | const char *description, |
---|
| 46 | const char *validsettings, |
---|
| 47 | validate_int_t validate_fn, |
---|
| 48 | set_int_t set_fn, |
---|
| 49 | get_int_t get_fn); |
---|
| 50 | |
---|
| 51 | static void owl_variable_dict_newvar_enum_full(owl_vardict *vd, |
---|
| 52 | const char *name, |
---|
| 53 | int default_val, |
---|
| 54 | const char *summary, |
---|
| 55 | const char *description, |
---|
| 56 | const char *validsettings, |
---|
| 57 | validate_int_t validate_fn, |
---|
| 58 | set_int_t set_fn, |
---|
| 59 | get_int_t get_fn); |
---|
| 60 | |
---|
| 61 | #define OWLVAR_BOOL(name, default, summary, description) \ |
---|
| 62 | owl_variable_dict_newvar_bool(vd, name, default, summary, description) |
---|
| 63 | |
---|
| 64 | #define OWLVAR_BOOL_FULL(name, default, summary, description, validate, set, get) \ |
---|
| 65 | owl_variable_dict_newvar_bool_full(vd, name, default, summary, description, \ |
---|
| 66 | validate, set, get) |
---|
| 67 | |
---|
| 68 | #define OWLVAR_INT(name, default, summary, description) \ |
---|
| 69 | owl_variable_dict_newvar_int(vd, name, default, summary, description) |
---|
[7d4fbcd] | 70 | |
---|
[aa2f33b3] | 71 | #define OWLVAR_INT_FULL(name,default,summary,description,validset,validate,set,get) \ |
---|
[4584d1f] | 72 | owl_variable_dict_newvar_int_full(vd, name, default, summary, description, \ |
---|
| 73 | validset, validate, set, get) |
---|
[7d4fbcd] | 74 | |
---|
[4584d1f] | 75 | #define OWLVAR_PATH(name, default, summary, description) \ |
---|
| 76 | owl_variable_dict_newvar_path(vd, name, default, summary, description) |
---|
[7d4fbcd] | 77 | |
---|
[4584d1f] | 78 | #define OWLVAR_STRING(name, default, summary, description) \ |
---|
| 79 | owl_variable_dict_newvar_string(vd, name, default, summary, description) |
---|
[7d4fbcd] | 80 | |
---|
[4584d1f] | 81 | #define OWLVAR_STRING_FULL(name, default, validset, summary, description, validate, set, get) \ |
---|
| 82 | owl_variable_dict_newvar_string_full(vd, name, default, summary, description, \ |
---|
| 83 | validset, validate, set, get) |
---|
[c01e477] | 84 | |
---|
[7d4fbcd] | 85 | /* enums are really integers, but where validset is a comma-separated |
---|
| 86 | * list of strings which can be specified. The tokens, starting at 0, |
---|
| 87 | * correspond to the values that may be specified. */ |
---|
[4584d1f] | 88 | #define OWLVAR_ENUM(name, default, summary, description, validset) \ |
---|
| 89 | owl_variable_dict_newvar_enum(vd, name, default, summary, description, validset) |
---|
[7d4fbcd] | 90 | |
---|
[aa2f33b3] | 91 | #define OWLVAR_ENUM_FULL(name,default,summary,description,validset,validate, set, get) \ |
---|
[4584d1f] | 92 | owl_variable_dict_newvar_enum_full(vd, name, default, summary, description, \ |
---|
| 93 | validset, validate, set, get) |
---|
[217a43e] | 94 | |
---|
[6a8b519] | 95 | void owl_variable_add_defaults(owl_vardict *vd) |
---|
[9e86f6f] | 96 | { |
---|
[5d365f6] | 97 | OWLVAR_STRING( "personalbell" /* %OwlVarStub */, "off", |
---|
[213a3eb] | 98 | "ring the terminal bell when personal messages are received", |
---|
[5d365f6] | 99 | "Can be set to 'on', 'off', or the name of a filter which\n" |
---|
[4584d1f] | 100 | "messages need to match in order to ring the bell"); |
---|
[7d4fbcd] | 101 | |
---|
| 102 | OWLVAR_BOOL( "bell" /* %OwlVarStub */, 1, |
---|
[4584d1f] | 103 | "enable / disable the terminal bell", "" ); |
---|
[7d4fbcd] | 104 | |
---|
| 105 | OWLVAR_BOOL_FULL( "debug" /* %OwlVarStub */, OWL_DEBUG, |
---|
| 106 | "whether debugging is enabled", |
---|
[aa2f33b3] | 107 | "If set to 'on', debugging messages are logged to the\n" |
---|
| 108 | "file specified by the debugfile variable.\n", |
---|
[4584d1f] | 109 | NULL, owl_variable_debug_set, NULL); |
---|
[7d4fbcd] | 110 | |
---|
| 111 | OWLVAR_BOOL( "startuplogin" /* %OwlVarStub */, 1, |
---|
[4584d1f] | 112 | "send a login message when BarnOwl starts", "" ); |
---|
[7d4fbcd] | 113 | |
---|
| 114 | OWLVAR_BOOL( "shutdownlogout" /* %OwlVarStub */, 1, |
---|
[4584d1f] | 115 | "send a logout message when BarnOwl exits", "" ); |
---|
[7d4fbcd] | 116 | |
---|
| 117 | OWLVAR_BOOL( "rxping" /* %OwlVarStub */, 0, |
---|
[4584d1f] | 118 | "display received pings", "" ); |
---|
[7d4fbcd] | 119 | |
---|
| 120 | OWLVAR_BOOL( "txping" /* %OwlVarStub */, 1, |
---|
[4584d1f] | 121 | "send pings", "" ); |
---|
[7d4fbcd] | 122 | |
---|
[73624b4] | 123 | OWLVAR_BOOL( "sepbar_disable" /* %OwlVarStub */, 0, |
---|
[4584d1f] | 124 | "disable printing information in the separator bar", "" ); |
---|
[73624b4] | 125 | |
---|
[f9c43ae] | 126 | OWLVAR_BOOL( "smartstrip" /* %OwlVarStub */, 1, |
---|
[4584d1f] | 127 | "strip kerberos instance for reply", ""); |
---|
[f9c43ae] | 128 | |
---|
[7e3e00a] | 129 | OWLVAR_BOOL( "newlinestrip" /* %OwlVarStub */, 1, |
---|
[4584d1f] | 130 | "strip leading and trailing newlines", ""); |
---|
[7e3e00a] | 131 | |
---|
[7d4fbcd] | 132 | OWLVAR_BOOL( "displayoutgoing" /* %OwlVarStub */, 1, |
---|
[4584d1f] | 133 | "display outgoing messages", "" ); |
---|
[7d4fbcd] | 134 | |
---|
| 135 | OWLVAR_BOOL( "loginsubs" /* %OwlVarStub */, 1, |
---|
[4584d1f] | 136 | "load logins from .anyone on startup", "" ); |
---|
[7d4fbcd] | 137 | |
---|
[d126a19] | 138 | OWLVAR_BOOL_FULL( "colorztext" /* %OwlVarStub */, 1, |
---|
| 139 | "allow @color() in zephyrs to change color", |
---|
[a95b564] | 140 | "", NULL, owl_variable_colorztext_set, NULL); |
---|
[e1c4636] | 141 | |
---|
[c15bbfb] | 142 | OWLVAR_BOOL( "fancylines" /* %OwlVarStub */, 1, |
---|
| 143 | "Use 'nice' line drawing on the terminal.", |
---|
| 144 | "If turned off, dashes, pipes and pluses will be used\n" |
---|
| 145 | "to draw lines on the screen. Useful when the terminal\n" |
---|
[4584d1f] | 146 | "is causing problems" ); |
---|
[c15bbfb] | 147 | |
---|
[d309eb3] | 148 | OWLVAR_BOOL( "zcrypt" /* %OwlVarStub */, 1, |
---|
| 149 | "Do automatic zcrypt processing", |
---|
[4584d1f] | 150 | "" ); |
---|
[d309eb3] | 151 | |
---|
[4357be8] | 152 | OWLVAR_BOOL_FULL( "pseudologins" /* %OwlVarStub */, 0, |
---|
| 153 | "Enable zephyr pseudo logins", |
---|
[a16d7e5] | 154 | "When this is enabled, BarnOwl will periodically check the zephyr\n" |
---|
[4357be8] | 155 | "location of users in your .anyone file. If a user is present\n" |
---|
| 156 | "but sent no login message, or a user is not present that sent no\n" |
---|
[d544237] | 157 | "logout message, a pseudo login or logout message will be created\n", |
---|
[4584d1f] | 158 | NULL, owl_variable_pseudologins_set, NULL); |
---|
[5a95b69] | 159 | |
---|
[280ddc6] | 160 | OWLVAR_BOOL( "ignorelogins" /* %OwlVarStub */, 0, |
---|
| 161 | "Enable printing of login notifications", |
---|
[a16d7e5] | 162 | "When this is enabled, BarnOwl will print login and logout notifications\n" |
---|
| 163 | "for AIM, zephyr, or other protocols. If disabled BarnOwl will not print\n" |
---|
[4584d1f] | 164 | "login or logout notifications.\n"); |
---|
[280ddc6] | 165 | |
---|
[217a43e] | 166 | OWLVAR_ENUM_FULL( "disable-ctrl-d" /* %OwlVarStub:lockout_ctrld */, 1, |
---|
[aa2f33b3] | 167 | "don't send zephyrs on C-d", |
---|
[40de7394] | 168 | "If set to 'on', C-d won't send a zephyr from the edit\n" |
---|
| 169 | "window. If set to 'off', C-d will always send a zephyr\n" |
---|
[aa2f33b3] | 170 | "being composed in the edit window. If set to 'middle',\n" |
---|
| 171 | "C-d will only ever send a zephyr if the cursor is at\n" |
---|
| 172 | "the end of the message being composed.\n\n" |
---|
| 173 | "Note that this works by changing the C-d keybinding\n" |
---|
| 174 | "in the editmulti keymap.\n", |
---|
| 175 | "off,middle,on", |
---|
[4584d1f] | 176 | NULL, owl_variable_disable_ctrl_d_set, NULL); |
---|
[7d4fbcd] | 177 | |
---|
| 178 | OWLVAR_PATH( "debug_file" /* %OwlVarStub */, OWL_DEBUG_FILE, |
---|
[aa2f33b3] | 179 | "path for logging debug messages when debugging is enabled", |
---|
[26ad412] | 180 | "This file will be logged to if 'debug' is set to 'on'.\n" |
---|
[4584d1f] | 181 | "BarnOwl will append a dot and the current process's pid to the filename."); |
---|
[7d4fbcd] | 182 | |
---|
[ced25d1] | 183 | OWLVAR_PATH( "zsigproc" /* %OwlVarStub:zsigproc */, NULL, |
---|
[aa2f33b3] | 184 | "name of a program to run that will generate zsigs", |
---|
| 185 | "This program should produce a zsig on stdout when run.\n" |
---|
[81a96af] | 186 | "Note that it is important that this program not block.\n\n" |
---|
| 187 | "See the documentation for 'zsig' for more information about\n" |
---|
| 188 | "how the outgoing zsig is chosen." |
---|
[4584d1f] | 189 | ); |
---|
[7d4fbcd] | 190 | |
---|
[700c712] | 191 | OWLVAR_PATH( "newmsgproc" /* %OwlVarStub:newmsgproc */, NULL, |
---|
| 192 | "name of a program to run when new messages are present", |
---|
[a16d7e5] | 193 | "The named program will be run when BarnOwl receives new\n" |
---|
[700c712] | 194 | "messages. It will not be run again until the first\n" |
---|
[4584d1f] | 195 | "instance exits"); |
---|
[700c712] | 196 | |
---|
[247cbc9] | 197 | OWLVAR_STRING( "zsender" /* %OwlVarStub */, "", |
---|
| 198 | "zephyr sender name", |
---|
| 199 | "Allows you to customize the outgoing username in\n" |
---|
| 200 | "zephyrs. If this is unset, it will use your Kerberos\n" |
---|
| 201 | "principal. Note that customizing the sender name will\n" |
---|
[4584d1f] | 202 | "cause your zephyrs to be sent unauthenticated."); |
---|
[247cbc9] | 203 | |
---|
[de3f641] | 204 | OWLVAR_STRING( "zsigfunc" /* %OwlVarStub */, "BarnOwl::default_zephyr_signature()", |
---|
| 205 | "zsig perl function", |
---|
| 206 | "Called every time you start a zephyrgram without an\n" |
---|
| 207 | "explicit zsig. The default setting implements the policy\n" |
---|
[b120bd3] | 208 | "described in the documentation for the 'zsig' variable.\n" |
---|
[4584d1f] | 209 | "See also BarnOwl::random_zephyr_signature().\n"); |
---|
[de3f641] | 210 | |
---|
[7d4fbcd] | 211 | OWLVAR_STRING( "zsig" /* %OwlVarStub */, "", |
---|
[81a96af] | 212 | "zephyr signature", |
---|
| 213 | "The zsig to get on outgoing messages. If this variable is\n" |
---|
| 214 | "unset, 'zsigproc' will be run to generate a zsig. If that is\n" |
---|
| 215 | "also unset, the 'zwrite-signature' zephyr variable will be\n" |
---|
[4584d1f] | 216 | "used instead.\n"); |
---|
[7d4fbcd] | 217 | |
---|
| 218 | OWLVAR_STRING( "appendtosepbar" /* %OwlVarStub */, "", |
---|
[aa2f33b3] | 219 | "string to append to the end of the sepbar", |
---|
| 220 | "The sepbar is the bar separating the top and bottom\n" |
---|
[a16d7e5] | 221 | "of the BarnOwl screen. Any string specified here will\n" |
---|
[4584d1f] | 222 | "be displayed on the right of the sepbar\n"); |
---|
[7d4fbcd] | 223 | |
---|
| 224 | OWLVAR_BOOL( "zaway" /* %OwlVarStub */, 0, |
---|
[4584d1f] | 225 | "turn zaway on or off", "" ); |
---|
[7d4fbcd] | 226 | |
---|
| 227 | OWLVAR_STRING( "zaway_msg" /* %OwlVarStub */, |
---|
| 228 | OWL_DEFAULT_ZAWAYMSG, |
---|
[4584d1f] | 229 | "zaway msg for responding to zephyrs when away", "" ); |
---|
[7d4fbcd] | 230 | |
---|
| 231 | OWLVAR_STRING( "zaway_msg_default" /* %OwlVarStub */, |
---|
| 232 | OWL_DEFAULT_ZAWAYMSG, |
---|
[4584d1f] | 233 | "default zaway message", "" ); |
---|
[7d4fbcd] | 234 | |
---|
[4b660cc] | 235 | OWLVAR_BOOL_FULL( "aaway" /* %OwlVarStub */, 0, |
---|
| 236 | "Set AIM away status", |
---|
| 237 | "", |
---|
[4584d1f] | 238 | NULL, owl_variable_aaway_set, NULL); |
---|
[4b660cc] | 239 | |
---|
| 240 | OWLVAR_STRING( "aaway_msg" /* %OwlVarStub */, |
---|
| 241 | OWL_DEFAULT_AAWAYMSG, |
---|
[4584d1f] | 242 | "AIM away msg for responding when away", "" ); |
---|
[4b660cc] | 243 | |
---|
| 244 | OWLVAR_STRING( "aaway_msg_default" /* %OwlVarStub */, |
---|
| 245 | OWL_DEFAULT_AAWAYMSG, |
---|
[4584d1f] | 246 | "default AIM away message", "" ); |
---|
[4b660cc] | 247 | |
---|
[7d4fbcd] | 248 | OWLVAR_STRING( "view_home" /* %OwlVarStub */, "all", |
---|
[aa2f33b3] | 249 | "home view to switch to after 'X' and 'V'", |
---|
[4584d1f] | 250 | "SEE ALSO: view, filter\n" ); |
---|
[7d4fbcd] | 251 | |
---|
[ecd5dc5] | 252 | OWLVAR_STRING( "alert_filter" /* %OwlVarStub */, "none", |
---|
| 253 | "filter on which to trigger alert actions", |
---|
[4584d1f] | 254 | "" ); |
---|
[ecd5dc5] | 255 | |
---|
| 256 | OWLVAR_STRING( "alert_action" /* %OwlVarStub */, "nop", |
---|
[a16d7e5] | 257 | "BarnOwl command to execute for alert actions", |
---|
[4584d1f] | 258 | "" ); |
---|
[ecd5dc5] | 259 | |
---|
[f203cad] | 260 | OWLVAR_STRING_FULL( "tty" /* %OwlVarStub */, "", "<string>", "tty name for zephyr location", "", |
---|
[4584d1f] | 261 | NULL, owl_variable_tty_set, NULL); |
---|
[bd3f232] | 262 | |
---|
[bc14adc] | 263 | OWLVAR_STRING( "default_style" /* %OwlVarStub */, "default", |
---|
[c3ab155] | 264 | "name of the default formatting style", |
---|
[f1e629d] | 265 | "This sets the default message formatting style.\n" |
---|
| 266 | "Styles may be created with the 'style' command.\n" |
---|
| 267 | "Some built-in styles include:\n" |
---|
[a16d7e5] | 268 | " default - the default BarnOwl formatting\n" |
---|
[f1e629d] | 269 | " oneline - one line per-message\n" |
---|
| 270 | " perl - legacy perl interface\n" |
---|
| 271 | "\nSEE ALSO: style, show styles, view -s <style>\n" |
---|
[4584d1f] | 272 | ); |
---|
[f1e629d] | 273 | |
---|
[c3ab155] | 274 | |
---|
[d36f2cb] | 275 | OWLVAR_INT( "edit:maxfillcols" /* %OwlVarStub:edit_maxfillcols */, 70, |
---|
[4d9e4254] | 276 | "maximum number of columns for M-q (edit:fill-paragraph) to fill text to", |
---|
| 277 | "This specifies the maximum number of columns for M-q to fill text\n" |
---|
| 278 | "to. If set to 0, M-q will wrap to the width of the window, and\n" |
---|
[4584d1f] | 279 | "values less than 0 disable M-q entirely.\n"); |
---|
[d36f2cb] | 280 | |
---|
[a4bbd80] | 281 | OWLVAR_INT( "edit:maxwrapcols" /* %OwlVarStub:edit_maxwrapcols */, 70, |
---|
[aa2f33b3] | 282 | "maximum number of columns for line-wrapping", |
---|
[4d9e4254] | 283 | "This specifies the maximum number of columns for\n" |
---|
| 284 | "auto-line-wrapping. If set to 0, text will be wrapped at the\n" |
---|
| 285 | "window width. Values less than 0 disable automatic wrapping.\n" |
---|
| 286 | "\n" |
---|
| 287 | "As a courtesy to recipients, it is recommended that outgoing\n" |
---|
[4584d1f] | 288 | "Zephyr messages be no wider than 70 columns.\n"); |
---|
[d36f2cb] | 289 | |
---|
[1db061d] | 290 | OWLVAR_INT( "aim_ignorelogin_timer" /* %OwlVarStub */, 15, |
---|
[6a415e9] | 291 | "number of seconds after AIM login to ignore login messages", |
---|
| 292 | "This specifies the number of seconds to wait after an\n" |
---|
[d544237] | 293 | "AIM login before allowing the receipt of AIM login notifications.\n" |
---|
[1db061d] | 294 | "By default this is set to 15. If you would like to view login\n" |
---|
[4584d1f] | 295 | "notifications of buddies as soon as you login, set it to 0 instead."); |
---|
[6a415e9] | 296 | |
---|
| 297 | |
---|
[7d4fbcd] | 298 | OWLVAR_INT_FULL( "typewinsize" /* %OwlVarStub:typwin_lines */, |
---|
| 299 | OWL_TYPWIN_SIZE, |
---|
[aa2f33b3] | 300 | "number of lines in the typing window", |
---|
| 301 | "This specifies the height of the window at the\n" |
---|
| 302 | "bottom of the screen where commands are entered\n" |
---|
| 303 | "and where messages are composed.\n", |
---|
| 304 | "int > 0", |
---|
[7d4fbcd] | 305 | owl_variable_int_validate_gt0, |
---|
| 306 | owl_variable_typewinsize_set, |
---|
| 307 | NULL /* use default for get */ |
---|
[4584d1f] | 308 | ); |
---|
[7d4fbcd] | 309 | |
---|
[da466e0] | 310 | OWLVAR_INT( "typewindelta" /* %OwlVarStub */, 0, |
---|
| 311 | "number of lines to add to the typing window when in use", |
---|
| 312 | "On small screens you may want the typing window to\n" |
---|
| 313 | "auto-hide when not entering a command or message.\n" |
---|
| 314 | "This variable is the number of lines to add to the\n" |
---|
| 315 | "typing window when it is in use; you can then set\n" |
---|
| 316 | "typewinsize to 1.\n\n" |
---|
| 317 | "This works a lot better with a non-default scrollmode;\n" |
---|
[4584d1f] | 318 | "try :set scrollmode pagedcenter.\n"); |
---|
[da466e0] | 319 | |
---|
[aa2f33b3] | 320 | OWLVAR_ENUM( "scrollmode" /* %OwlVarStub */, OWL_SCROLLMODE_NORMAL, |
---|
| 321 | "how to scroll up and down", |
---|
| 322 | "This controls how the screen is scrolled as the\n" |
---|
| 323 | "cursor moves between messages being displayed.\n" |
---|
| 324 | "The following modes are supported:\n\n" |
---|
[a16d7e5] | 325 | " normal - This is the BarnOwl default. Scrolling happens\n" |
---|
[aa2f33b3] | 326 | " when it needs to, and an attempt is made to\n" |
---|
| 327 | " keep the current message roughly near\n" |
---|
| 328 | " the middle of the screen.\n" |
---|
| 329 | " top - The current message will always be the\n" |
---|
| 330 | " the top message displayed.\n" |
---|
| 331 | " neartop - The current message will be one down\n" |
---|
| 332 | " from the top message displayed,\n" |
---|
| 333 | " where possible.\n" |
---|
| 334 | " center - An attempt is made to keep the current\n" |
---|
| 335 | " message near the center of the screen.\n" |
---|
| 336 | " paged - The top message displayed only changes\n" |
---|
| 337 | " when user moves the cursor to the top\n" |
---|
| 338 | " or bottom of the screen. When it moves,\n" |
---|
| 339 | " the screen will be paged up or down and\n" |
---|
| 340 | " the cursor will be near the top or\n" |
---|
| 341 | " the bottom.\n" |
---|
| 342 | " pagedcenter - The top message displayed only changes\n" |
---|
| 343 | " when user moves the cursor to the top\n" |
---|
| 344 | " or bottom of the screen. When it moves,\n" |
---|
| 345 | " the screen will be paged up or down and\n" |
---|
| 346 | " the cursor will be near the center.\n", |
---|
[4584d1f] | 347 | "normal,top,neartop,center,paged,pagedcenter" ); |
---|
[aa2f33b3] | 348 | |
---|
[66e409c] | 349 | OWLVAR_BOOL( "narrow-related" /* %OwlVarStub:narrow_related */, 1, |
---|
| 350 | "Make smartnarrow use broader filters", |
---|
[8258ea5] | 351 | "Causes smartfilter to narrow to messages \"related\" to \n" |
---|
[66e409c] | 352 | "the current message, as well as ones to the same place.\n\n" |
---|
| 353 | "for Zephyr, this controls whether to narrow to e.g. class-help or\n" |
---|
| 354 | "class-help.d alone, or to related-class-help, which includes\n" |
---|
[4584d1f] | 355 | "help, unhelp, help.d, etc.\n\nDefault is true (include unclasses, etc.).\n" ); |
---|
[ecd5dc5] | 356 | |
---|
[7d4fbcd] | 357 | OWLVAR_BOOL( "_followlast" /* %OwlVarStub */, 0, |
---|
[aa2f33b3] | 358 | "enable automatic following of the last zephyr", |
---|
| 359 | "If the cursor is at the last message, it will\n" |
---|
| 360 | "continue to follow the last message if this is set.\n" |
---|
| 361 | "Note that this is currently risky as you might accidentally\n" |
---|
[4584d1f] | 362 | "delete a message right as it came in.\n" ); |
---|
[7d4fbcd] | 363 | |
---|
[f203cad] | 364 | OWLVAR_STRING_FULL( "default_exposure" /* %OwlVarStub */, "", |
---|
| 365 | "none,opstaff,realm-visible,realm-announced,net-visible,net-announced", |
---|
| 366 | "controls the persistent value for exposure", |
---|
| 367 | "The default exposure level corresponds to the Zephyr exposure value\n" |
---|
| 368 | "in ~/.zephyr.vars. Defaults to realm-visible if there is no value in\n" |
---|
| 369 | "~/.zephyr.vars.\n" |
---|
| 370 | "See the description of exposure for the values this can be.", |
---|
[4584d1f] | 371 | NULL, owl_variable_default_exposure_set, owl_variable_default_exposure_get ); |
---|
[f203cad] | 372 | |
---|
| 373 | OWLVAR_STRING_FULL( "exposure" /* %OwlVarStub */, "", |
---|
| 374 | "none,opstaff,realm-visible,realm-announced,net-visible,net-announced", |
---|
| 375 | "controls who can zlocate you", |
---|
| 376 | "The exposure level, defaulting to the value of default_exposure,\n" |
---|
| 377 | "can be one of the following (from least exposure to widest exposure,\n" |
---|
| 378 | "as listed in zctl(1)):\n" |
---|
| 379 | "\n" |
---|
| 380 | " none - This completely disables Zephyr for the user. \n" |
---|
| 381 | " The user is not registered with Zephyr. No user\n" |
---|
| 382 | " location information is retained by Zephyr. No\n" |
---|
| 383 | " login or logout announcements will be sent. No\n" |
---|
| 384 | " subscriptions will be entered for the user, and\n" |
---|
| 385 | " no notices will be displayed by zwgc(1).\n" |
---|
| 386 | " opstaff - The user is registered with Zephyr. No login or\n" |
---|
| 387 | " logout announcements will be sent, and location\n" |
---|
| 388 | " information will only be visible to Operations\n" |
---|
| 389 | " staff. Default subscriptions and any additional\n" |
---|
| 390 | " personal subscriptions will be entered for the\n" |
---|
| 391 | " user.\n" |
---|
| 392 | " realm-visible - The user is registered with Zephyr. User\n" |
---|
| 393 | " location information is retained by Zephyr and\n" |
---|
| 394 | " made available only to users within the user’s\n" |
---|
| 395 | " Kerberos realm. No login or logout\n" |
---|
| 396 | " announcements will be sent. This is the system\n" |
---|
| 397 | " default. Default subscriptions and any\n" |
---|
| 398 | " additional personal subscriptions will be\n" |
---|
| 399 | " entered for the user.\n" |
---|
| 400 | " realm-announced - The user is registered with Zephyr. User\n" |
---|
| 401 | " location information is retained by Zephyr and\n" |
---|
| 402 | " made available only to users authenticated\n" |
---|
| 403 | " within the user’s Kerberos realm. Login and\n" |
---|
| 404 | " logout announcements will be sent, but only to\n" |
---|
| 405 | " users within the user’s Kerberos realm who have\n" |
---|
| 406 | " explicitly requested such via subscriptions. \n" |
---|
| 407 | " Default subscriptions and any additional\n" |
---|
| 408 | " personal subscriptions will be entered for the\n" |
---|
| 409 | " user.\n" |
---|
| 410 | " net-visible - The user is registered with Zephyr. User\n" |
---|
| 411 | " location information is retained by Zephyr and\n" |
---|
| 412 | " made available to any authenticated user who\n" |
---|
| 413 | " requests such. Login and logout announcements\n" |
---|
| 414 | " will be sent only to users within the user’s\n" |
---|
| 415 | " Kerberos realm who have explicitly requested\n" |
---|
| 416 | " such via subscriptions. Default subscriptions\n" |
---|
| 417 | " and any additional personal subscriptions will\n" |
---|
| 418 | " be entered for the user.\n" |
---|
| 419 | " net-announced - The user is registered with Zephyr. User\n" |
---|
| 420 | " location information is retained by Zephyr and\n" |
---|
| 421 | " made available to any authenticated user who\n" |
---|
| 422 | " requests such. Login and logout announcements\n" |
---|
| 423 | " will be sent to any user has requested such. \n" |
---|
| 424 | " Default subscriptions and any additional\n" |
---|
| 425 | " personal subscriptions will be entered for the\n" |
---|
| 426 | " user.\n", |
---|
[4584d1f] | 427 | NULL, owl_variable_exposure_set, NULL /* use default for get */ ); |
---|
[9e86f6f] | 428 | } |
---|
[7d4fbcd] | 429 | |
---|
| 430 | /**************************************************************************/ |
---|
| 431 | /*********************** SPECIFIC TO VARIABLES ****************************/ |
---|
| 432 | /**************************************************************************/ |
---|
| 433 | |
---|
| 434 | |
---|
| 435 | /* commonly useful */ |
---|
| 436 | |
---|
[353719a] | 437 | int owl_variable_int_validate_gt0(const owl_variable *v, int newval) |
---|
[4357be8] | 438 | { |
---|
[06e04a9] | 439 | return !(newval < 1); |
---|
[7d4fbcd] | 440 | } |
---|
| 441 | |
---|
[353719a] | 442 | int owl_variable_int_validate_positive(const owl_variable *v, int newval) |
---|
[4357be8] | 443 | { |
---|
[06e04a9] | 444 | return !(newval < 0); |
---|
[7d4fbcd] | 445 | } |
---|
| 446 | |
---|
| 447 | /* typewinsize */ |
---|
[353719a] | 448 | int owl_variable_typewinsize_set(owl_variable *v, int newval) |
---|
[4357be8] | 449 | { |
---|
[7d4fbcd] | 450 | int rv; |
---|
[353719a] | 451 | rv = owl_variable_int_set_default(v, newval); |
---|
[f6fae8d] | 452 | if (0 == rv) owl_mainpanel_layout_contents(&g.mainpanel); |
---|
[7d4fbcd] | 453 | return(rv); |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | /* debug (cache value in g->debug) */ |
---|
[4584d1f] | 457 | int owl_variable_debug_set(owl_variable *v, bool newval) |
---|
[4357be8] | 458 | { |
---|
[4584d1f] | 459 | g.debug = newval; |
---|
[353719a] | 460 | return owl_variable_bool_set_default(v, newval); |
---|
[4b660cc] | 461 | } |
---|
| 462 | |
---|
| 463 | /* When 'aaway' is changed, need to notify the AIM server */ |
---|
[4584d1f] | 464 | int owl_variable_aaway_set(owl_variable *v, bool newval) |
---|
[4357be8] | 465 | { |
---|
[4584d1f] | 466 | if (newval) { |
---|
[06e04a9] | 467 | owl_aim_set_awaymsg(owl_global_get_aaway_msg(&g)); |
---|
[4584d1f] | 468 | } else { |
---|
[06e04a9] | 469 | owl_aim_set_awaymsg(""); |
---|
[4b660cc] | 470 | } |
---|
[353719a] | 471 | return owl_variable_bool_set_default(v, newval); |
---|
[7d4fbcd] | 472 | } |
---|
| 473 | |
---|
[4584d1f] | 474 | int owl_variable_colorztext_set(owl_variable *v, bool newval) |
---|
[d126a19] | 475 | { |
---|
[353719a] | 476 | int ret = owl_variable_bool_set_default(v, newval); |
---|
[d126a19] | 477 | /* flush the format cache so that we see the update, but only if we're done initializing BarnOwl */ |
---|
| 478 | if (owl_global_get_msglist(&g) != NULL) |
---|
| 479 | owl_messagelist_invalidate_formats(owl_global_get_msglist(&g)); |
---|
| 480 | if (owl_global_get_mainwin(&g) != NULL) { |
---|
| 481 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
| 482 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 483 | } |
---|
| 484 | return ret; |
---|
| 485 | } |
---|
| 486 | |
---|
[4584d1f] | 487 | int owl_variable_pseudologins_set(owl_variable *v, bool newval) |
---|
[4357be8] | 488 | { |
---|
[72146c7] | 489 | static guint timer = 0; |
---|
[4584d1f] | 490 | if (newval) { |
---|
[06e04a9] | 491 | owl_function_zephyr_buddy_check(0); |
---|
| 492 | if (timer == 0) { |
---|
| 493 | timer = g_timeout_add_seconds(180, owl_zephyr_buddycheck_timer, NULL); |
---|
| 494 | } |
---|
| 495 | } else { |
---|
| 496 | if (timer != 0) { |
---|
| 497 | g_source_remove(timer); |
---|
| 498 | timer = 0; |
---|
[4357be8] | 499 | } |
---|
| 500 | } |
---|
[353719a] | 501 | return owl_variable_bool_set_default(v, newval); |
---|
[4357be8] | 502 | } |
---|
| 503 | |
---|
[7d4fbcd] | 504 | /* note that changing the value of this will clobber |
---|
| 505 | * any user setting of this */ |
---|
[353719a] | 506 | int owl_variable_disable_ctrl_d_set(owl_variable *v, int newval) |
---|
[4357be8] | 507 | { |
---|
[06e04a9] | 508 | if (!owl_context_is_startup(owl_global_get_context(&g))) { |
---|
| 509 | if (newval == 2) { |
---|
[7d4fbcd] | 510 | owl_function_command_norv("bindkey editmulti C-d command edit:delete-next-char"); |
---|
[06e04a9] | 511 | } else if (newval == 1) { |
---|
[3b42640] | 512 | owl_function_command_norv("bindkey editmulti C-d command edit:done-or-delete"); |
---|
[7d4fbcd] | 513 | } else { |
---|
[3b42640] | 514 | owl_function_command_norv("bindkey editmulti C-d command edit:done"); |
---|
[7d4fbcd] | 515 | } |
---|
| 516 | } |
---|
[353719a] | 517 | return owl_variable_int_set_default(v, newval); |
---|
[7d4fbcd] | 518 | } |
---|
| 519 | |
---|
[353719a] | 520 | int owl_variable_tty_set(owl_variable *v, const char *newval) |
---|
[4357be8] | 521 | { |
---|
[f54b07d] | 522 | owl_zephyr_set_locationinfo(g_get_host_name(), newval); |
---|
[353719a] | 523 | return owl_variable_string_set_default(v, newval); |
---|
[c01e477] | 524 | } |
---|
| 525 | |
---|
[353719a] | 526 | int owl_variable_default_exposure_set(owl_variable *v, const char *newval) |
---|
[f203cad] | 527 | { |
---|
| 528 | return owl_zephyr_set_default_exposure(newval); |
---|
| 529 | } |
---|
| 530 | |
---|
[353719a] | 531 | const char *owl_variable_default_exposure_get(const owl_variable *v) |
---|
[f203cad] | 532 | { |
---|
| 533 | return owl_zephyr_get_default_exposure(); |
---|
| 534 | } |
---|
| 535 | |
---|
[353719a] | 536 | int owl_variable_exposure_set(owl_variable *v, const char *newval) |
---|
[f203cad] | 537 | { |
---|
| 538 | int ret = owl_zephyr_set_exposure(newval); |
---|
| 539 | if (ret != 0) |
---|
| 540 | return ret; |
---|
[353719a] | 541 | return owl_variable_string_set_default(v, owl_zephyr_normalize_exposure(newval)); |
---|
[f203cad] | 542 | } |
---|
[7d4fbcd] | 543 | |
---|
| 544 | /**************************************************************************/ |
---|
| 545 | /****************************** GENERAL ***********************************/ |
---|
| 546 | /**************************************************************************/ |
---|
| 547 | |
---|
[6a8b519] | 548 | void owl_variable_dict_setup(owl_vardict *vd) { |
---|
[4c7c21f] | 549 | owl_dict_create(vd); |
---|
[6a8b519] | 550 | owl_variable_add_defaults(vd); |
---|
[9e86f6f] | 551 | } |
---|
| 552 | |
---|
[06e04a9] | 553 | CALLER_OWN GClosure *owl_variable_make_closure(owl_variable *v, |
---|
[353719a] | 554 | GCallback fn, |
---|
| 555 | GClosureMarshal marshal) { |
---|
| 556 | GClosure *closure = g_cclosure_new_swap(fn, v, NULL); |
---|
[06e04a9] | 557 | g_closure_set_marshal(closure,marshal); |
---|
| 558 | g_closure_ref(closure); |
---|
| 559 | g_closure_sink(closure); |
---|
| 560 | return closure; |
---|
| 561 | } |
---|
| 562 | |
---|
[a695a68] | 563 | void owl_variable_dict_add_variable(owl_vardict * vardict, |
---|
| 564 | owl_variable * var) { |
---|
[9d4dfdc] | 565 | char *oldvalue = NULL; |
---|
| 566 | owl_variable *oldvar = owl_variable_get_var(vardict, var->name); |
---|
| 567 | /* Save the old value as a string. */ |
---|
| 568 | if (oldvar) { |
---|
| 569 | oldvalue = owl_variable_get_tostring(oldvar); |
---|
| 570 | } |
---|
[3b0edaa] | 571 | owl_dict_insert_element(vardict, var->name, var, (void (*)(void *))owl_variable_delete); |
---|
[9d4dfdc] | 572 | /* Restore the old value. */ |
---|
| 573 | if (oldvalue) { |
---|
| 574 | owl_variable_set_fromstring(var, oldvalue, 0); |
---|
| 575 | g_free(oldvalue); |
---|
| 576 | } |
---|
[a695a68] | 577 | } |
---|
| 578 | |
---|
[4584d1f] | 579 | static owl_variable *owl_variable_newvar(int type, const char *name, const char *summary, const char *description, const char *validsettings) { |
---|
[7dcef03] | 580 | owl_variable *var = g_slice_new0(owl_variable); |
---|
[4584d1f] | 581 | var->type = type; |
---|
[d4927a7] | 582 | var->name = g_strdup(name); |
---|
| 583 | var->summary = g_strdup(summary); |
---|
| 584 | var->description = g_strdup(description); |
---|
[69f74c2] | 585 | var->validsettings = g_strdup(validsettings); |
---|
[4584d1f] | 586 | return var; |
---|
| 587 | } |
---|
| 588 | |
---|
| 589 | static void owl_variable_dict_newvar_int_full(owl_vardict *vd, const char *name, int default_val, const char *summary, const char *description, const char *validsettings, validate_int_t validate_fn, set_int_t set_fn, get_int_t get_fn) |
---|
| 590 | { |
---|
| 591 | owl_variable *var = owl_variable_newvar(OWL_VARIABLE_INT, name, summary, |
---|
| 592 | description, validsettings); |
---|
| 593 | var->takes_on_off = false; |
---|
| 594 | var->get_fn = G_CALLBACK(get_fn ? get_fn : owl_variable_int_get_default); |
---|
| 595 | var->set_fn = G_CALLBACK(set_fn ? set_fn : owl_variable_int_set_default); |
---|
| 596 | var->validate_fn = G_CALLBACK(validate_fn ? validate_fn : owl_variable_int_validate_default); |
---|
| 597 | |
---|
| 598 | var->get_tostring_fn = owl_variable_make_closure( |
---|
| 599 | var, G_CALLBACK(owl_variable_int_get_tostring_default), |
---|
| 600 | g_cclosure_user_marshal_STRING__VOID); |
---|
| 601 | var->set_fromstring_fn = owl_variable_make_closure( |
---|
| 602 | var, G_CALLBACK(owl_variable_int_set_fromstring_default), |
---|
| 603 | g_cclosure_user_marshal_INT__STRING); |
---|
| 604 | |
---|
| 605 | g_value_init(&var->val, G_TYPE_INT); |
---|
| 606 | owl_variable_set_int(var, default_val); |
---|
| 607 | |
---|
| 608 | var->default_str = owl_variable_get_tostring(var); |
---|
| 609 | owl_variable_dict_add_variable(vd, var); |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | void owl_variable_dict_newvar_int(owl_vardict *vd, const char *name, int default_val, const char *summary, const char *description) { |
---|
| 613 | owl_variable_dict_newvar_int_full(vd, name, default_val, summary, description, |
---|
| 614 | "<int>", NULL, NULL, NULL); |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | static void owl_variable_dict_newvar_bool_full(owl_vardict *vd, const char *name, bool default_val, const char *summary, const char *description, validate_bool_t validate_fn, set_bool_t set_fn, get_bool_t get_fn) |
---|
| 618 | { |
---|
| 619 | owl_variable *var = owl_variable_newvar(OWL_VARIABLE_BOOL, name, summary, |
---|
| 620 | description, "on,off"); |
---|
| 621 | var->takes_on_off = true; |
---|
| 622 | var->get_fn = G_CALLBACK(get_fn ? get_fn : owl_variable_bool_get_default); |
---|
| 623 | var->set_fn = G_CALLBACK(set_fn ? set_fn : owl_variable_bool_set_default); |
---|
| 624 | var->validate_fn = G_CALLBACK(validate_fn ? validate_fn : owl_variable_bool_validate_default); |
---|
| 625 | |
---|
| 626 | var->get_tostring_fn = owl_variable_make_closure( |
---|
| 627 | var, G_CALLBACK(owl_variable_bool_get_tostring_default), |
---|
| 628 | g_cclosure_user_marshal_STRING__VOID); |
---|
| 629 | var->set_fromstring_fn = owl_variable_make_closure( |
---|
| 630 | var, G_CALLBACK(owl_variable_bool_set_fromstring_default), |
---|
| 631 | g_cclosure_user_marshal_INT__STRING); |
---|
| 632 | |
---|
| 633 | g_value_init(&var->val, G_TYPE_BOOLEAN); |
---|
| 634 | owl_variable_set_bool(var, default_val); |
---|
| 635 | |
---|
| 636 | var->default_str = owl_variable_get_tostring(var); |
---|
| 637 | owl_variable_dict_add_variable(vd, var); |
---|
| 638 | } |
---|
| 639 | |
---|
| 640 | void owl_variable_dict_newvar_bool(owl_vardict *vd, const char *name, bool default_val, const char *summary, const char *description) { |
---|
| 641 | owl_variable_dict_newvar_bool_full(vd, name, default_val, summary, description, |
---|
| 642 | NULL, NULL, NULL); |
---|
| 643 | } |
---|
| 644 | |
---|
| 645 | static void owl_variable_dict_newvar_string_full(owl_vardict *vd, const char *name, const char *default_val, const char *summary, const char *description, const char *validsettings, validate_string_t validate_fn, set_string_t set_fn, get_string_t get_fn) |
---|
| 646 | { |
---|
| 647 | owl_variable *var = owl_variable_newvar(OWL_VARIABLE_STRING, name, summary, |
---|
| 648 | description, validsettings); |
---|
| 649 | var->takes_on_off = false; |
---|
| 650 | var->get_fn = G_CALLBACK(get_fn ? get_fn : owl_variable_string_get_default); |
---|
| 651 | var->set_fn = G_CALLBACK(set_fn ? set_fn : owl_variable_string_set_default); |
---|
| 652 | var->validate_fn = G_CALLBACK(validate_fn ? validate_fn : owl_variable_string_validate_default); |
---|
| 653 | |
---|
| 654 | var->get_tostring_fn = owl_variable_make_closure( |
---|
| 655 | var, G_CALLBACK(owl_variable_string_get_tostring_default), |
---|
| 656 | g_cclosure_user_marshal_STRING__VOID); |
---|
| 657 | var->set_fromstring_fn = owl_variable_make_closure( |
---|
| 658 | var, G_CALLBACK(owl_variable_string_set_fromstring_default), |
---|
| 659 | g_cclosure_user_marshal_INT__STRING); |
---|
| 660 | |
---|
| 661 | g_value_init(&var->val, G_TYPE_STRING); |
---|
| 662 | owl_variable_set_string(var, default_val); |
---|
| 663 | |
---|
| 664 | var->default_str = owl_variable_get_tostring(var); |
---|
| 665 | owl_variable_dict_add_variable(vd, var); |
---|
| 666 | } |
---|
| 667 | |
---|
| 668 | void owl_variable_dict_newvar_string(owl_vardict *vd, const char *name, const char *default_val, const char *summary, const char *description) { |
---|
| 669 | owl_variable_dict_newvar_string_full(vd, name, default_val, summary, description, |
---|
| 670 | "<string>", NULL, NULL, NULL); |
---|
| 671 | } |
---|
| 672 | |
---|
| 673 | void owl_variable_dict_newvar_path(owl_vardict *vd, const char *name, const char *default_val, const char *summary, const char *description) { |
---|
| 674 | owl_variable_dict_newvar_string_full(vd, name, default_val, summary, description, |
---|
| 675 | "<path>", NULL, NULL, NULL); |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | static void owl_variable_dict_newvar_enum_full(owl_vardict *vd, const char *name, int default_val, const char *summary, const char *description, const char *validsettings, validate_int_t validate_fn, set_int_t set_fn, get_int_t get_fn) |
---|
| 679 | { |
---|
| 680 | owl_variable *var = owl_variable_newvar(OWL_VARIABLE_INT, name, summary, |
---|
| 681 | description, validsettings); |
---|
| 682 | var->takes_on_off = false; |
---|
| 683 | var->get_fn = G_CALLBACK(get_fn ? get_fn : owl_variable_int_get_default); |
---|
| 684 | var->set_fn = G_CALLBACK(set_fn ? set_fn : owl_variable_int_set_default); |
---|
| 685 | var->validate_fn = G_CALLBACK(validate_fn ? validate_fn : owl_variable_enum_validate); |
---|
| 686 | |
---|
| 687 | var->get_tostring_fn = owl_variable_make_closure( |
---|
| 688 | var, G_CALLBACK(owl_variable_enum_get_tostring), |
---|
| 689 | g_cclosure_user_marshal_STRING__VOID); |
---|
| 690 | var->set_fromstring_fn = owl_variable_make_closure( |
---|
| 691 | var, G_CALLBACK(owl_variable_enum_set_fromstring), |
---|
| 692 | g_cclosure_user_marshal_INT__STRING); |
---|
| 693 | |
---|
| 694 | g_value_init(&var->val, G_TYPE_INT); |
---|
| 695 | owl_variable_set_int(var, default_val); |
---|
| 696 | |
---|
| 697 | var->default_str = owl_variable_get_tostring(var); |
---|
| 698 | owl_variable_dict_add_variable(vd, var); |
---|
| 699 | } |
---|
| 700 | |
---|
| 701 | void owl_variable_dict_newvar_enum(owl_vardict *vd, const char *name, int default_val, const char *summary, const char *description, const char *validset) { |
---|
| 702 | owl_variable_dict_newvar_enum_full(vd, name, default_val, summary, description, |
---|
| 703 | validset, NULL, NULL, NULL); |
---|
| 704 | } |
---|
| 705 | |
---|
| 706 | void owl_variable_dict_newvar_other(owl_vardict *vd, const char *name, const char *summary, const char *description, const char *validsettings, bool takes_on_off, GClosure *get_tostring_fn, GClosure *set_fromstring_fn) |
---|
| 707 | { |
---|
| 708 | owl_variable *var = owl_variable_newvar(OWL_VARIABLE_OTHER, name, summary, |
---|
| 709 | description, validsettings); |
---|
[3b9ca71] | 710 | var->takes_on_off = takes_on_off; |
---|
[353719a] | 711 | |
---|
[69f74c2] | 712 | var->get_tostring_fn = g_closure_ref(get_tostring_fn); |
---|
| 713 | g_closure_sink(get_tostring_fn); |
---|
[a695a68] | 714 | |
---|
[69f74c2] | 715 | var->set_fromstring_fn = g_closure_ref(set_fromstring_fn); |
---|
| 716 | g_closure_sink(set_fromstring_fn); |
---|
[06e04a9] | 717 | |
---|
[69f74c2] | 718 | var->default_str = owl_variable_get_tostring(var); |
---|
[353719a] | 719 | |
---|
[69f74c2] | 720 | /* Note: this'll overwrite any existing variable of that name, even a C one, |
---|
| 721 | but it's consistent with previous behavior and commands. */ |
---|
| 722 | owl_variable_dict_add_variable(vd, var); |
---|
[a695a68] | 723 | } |
---|
| 724 | |
---|
[0fef6eb] | 725 | void owl_variable_dict_cleanup(owl_vardict *d) |
---|
| 726 | { |
---|
[bf7aa1d] | 727 | owl_dict_cleanup(d, (void (*)(void *))owl_variable_delete); |
---|
[7d4fbcd] | 728 | } |
---|
| 729 | |
---|
[ce68f23] | 730 | CALLER_OWN GPtrArray *owl_variable_dict_get_names(const owl_vardict *d) { |
---|
| 731 | return owl_dict_get_keys(d); |
---|
[7d4fbcd] | 732 | } |
---|
| 733 | |
---|
[f41956d] | 734 | void owl_variable_delete(owl_variable *v) |
---|
[3b0edaa] | 735 | { |
---|
[06e04a9] | 736 | g_free(v->name); |
---|
| 737 | g_free(v->summary); |
---|
| 738 | g_free(v->description); |
---|
[353719a] | 739 | g_free(v->default_str); |
---|
[5001a3d] | 740 | g_free(v->validsettings); |
---|
[f20daff] | 741 | if (v->type != OWL_VARIABLE_OTHER) |
---|
| 742 | g_value_unset(&(v->val)); |
---|
[06e04a9] | 743 | g_closure_unref(v->get_tostring_fn); |
---|
| 744 | g_closure_unref(v->set_fromstring_fn); |
---|
[9efc154] | 745 | |
---|
[7dcef03] | 746 | g_slice_free(owl_variable, v); |
---|
[7d4fbcd] | 747 | } |
---|
| 748 | |
---|
| 749 | |
---|
[ca54fd6] | 750 | const char *owl_variable_get_name(const owl_variable *v) |
---|
| 751 | { |
---|
| 752 | return v->name; |
---|
| 753 | } |
---|
| 754 | |
---|
[64735f0] | 755 | const char *owl_variable_get_description(const owl_variable *v) { |
---|
[aa2f33b3] | 756 | return v->description; |
---|
| 757 | } |
---|
| 758 | |
---|
[64735f0] | 759 | const char *owl_variable_get_summary(const owl_variable *v) { |
---|
[aa2f33b3] | 760 | return v->summary; |
---|
[7d4fbcd] | 761 | } |
---|
| 762 | |
---|
[64735f0] | 763 | const char *owl_variable_get_validsettings(const owl_variable *v) { |
---|
[fa981f3] | 764 | return v->validsettings; |
---|
[7d4fbcd] | 765 | } |
---|
| 766 | |
---|
[81e93c3] | 767 | bool owl_variable_takes_on_off(const owl_variable *v) { |
---|
| 768 | return v->takes_on_off; |
---|
| 769 | } |
---|
| 770 | |
---|
[ca54fd6] | 771 | int owl_variable_get_type(const owl_variable *v) |
---|
| 772 | { |
---|
| 773 | return v->type; |
---|
| 774 | } |
---|
| 775 | |
---|
[7d4fbcd] | 776 | /* returns 0 on success, prints a status msg if msg is true */ |
---|
[ca54fd6] | 777 | int owl_variable_set_fromstring(owl_variable *v, const char *value, int msg) { |
---|
[010a951] | 778 | char *tostring; |
---|
[353719a] | 779 | GValue values[] = {G_VALUE_INIT, G_VALUE_INIT}; |
---|
| 780 | GValue return_box = G_VALUE_INIT; |
---|
[f0a7c09] | 781 | int set_successfully; |
---|
[63d3e4e] | 782 | |
---|
[353719a] | 783 | g_value_init(&values[0], G_TYPE_POINTER); |
---|
| 784 | g_value_set_pointer(&values[0], NULL); |
---|
[63d3e4e] | 785 | g_value_init(&values[1], G_TYPE_STRING); |
---|
| 786 | g_value_set_static_string(&values[1], value); |
---|
[353719a] | 787 | g_value_init(&return_box, G_TYPE_INT); |
---|
[06e04a9] | 788 | g_closure_invoke(v->set_fromstring_fn, &return_box, 2, values, NULL); |
---|
[63d3e4e] | 789 | |
---|
[06e04a9] | 790 | set_successfully = g_value_get_int(&return_box); |
---|
| 791 | if (0 != set_successfully) { |
---|
[ca54fd6] | 792 | if (msg) owl_function_error("Unable to set %s (must be %s)", owl_variable_get_name(v), |
---|
| 793 | owl_variable_get_validsettings(v)); |
---|
[897fc1c] | 794 | } else if (msg) { |
---|
[353719a] | 795 | tostring = owl_variable_get_tostring(v); |
---|
[06e04a9] | 796 | if (tostring) { |
---|
[ca749a9] | 797 | owl_function_makemsg("%s = '%s'", owl_variable_get_name(v), tostring); |
---|
[06e04a9] | 798 | } else { |
---|
[ca749a9] | 799 | owl_function_makemsg("%s = <null>", owl_variable_get_name(v)); |
---|
[06e04a9] | 800 | } |
---|
[010a951] | 801 | g_free(tostring); |
---|
[06e04a9] | 802 | } |
---|
[63d3e4e] | 803 | |
---|
| 804 | g_value_unset(&return_box); |
---|
| 805 | g_value_unset(&values[1]); |
---|
| 806 | g_value_unset(&values[0]); |
---|
[06e04a9] | 807 | return set_successfully; |
---|
| 808 | } |
---|
[7d4fbcd] | 809 | |
---|
[ca54fd6] | 810 | int owl_variable_set_string(owl_variable *v, const char *newval) |
---|
| 811 | { |
---|
[353719a] | 812 | g_return_val_if_fail(v->type == OWL_VARIABLE_STRING, -1); |
---|
| 813 | |
---|
| 814 | set_string_t cb = (set_string_t) v->set_fn; |
---|
| 815 | return cb(v, newval); |
---|
[7d4fbcd] | 816 | } |
---|
[06e04a9] | 817 | |
---|
[ca54fd6] | 818 | int owl_variable_set_int(owl_variable *v, int newval) |
---|
| 819 | { |
---|
[353719a] | 820 | g_return_val_if_fail(v->type == OWL_VARIABLE_INT, -1); |
---|
| 821 | |
---|
| 822 | set_int_t cb = (set_int_t) v->set_fn; |
---|
| 823 | return cb(v, newval); |
---|
[7d4fbcd] | 824 | } |
---|
[06e04a9] | 825 | |
---|
[4584d1f] | 826 | int owl_variable_set_bool(owl_variable *v, bool newval) { |
---|
[353719a] | 827 | g_return_val_if_fail(v->type == OWL_VARIABLE_BOOL, -1); |
---|
| 828 | |
---|
| 829 | set_bool_t cb = (set_bool_t) v->set_fn; |
---|
| 830 | return cb(v, newval); |
---|
[06e04a9] | 831 | } |
---|
| 832 | |
---|
[ca54fd6] | 833 | int owl_variable_set_bool_on(owl_variable *v) |
---|
| 834 | { |
---|
| 835 | if (v->type != OWL_VARIABLE_BOOL) return -1; |
---|
[06e04a9] | 836 | return owl_variable_set_bool(v, true); |
---|
[7d4fbcd] | 837 | } |
---|
| 838 | |
---|
[ca54fd6] | 839 | int owl_variable_set_bool_off(owl_variable *v) |
---|
| 840 | { |
---|
| 841 | if (v->type != OWL_VARIABLE_BOOL) return -1; |
---|
[06e04a9] | 842 | return owl_variable_set_bool(v, false); |
---|
[7d4fbcd] | 843 | } |
---|
| 844 | |
---|
[ca54fd6] | 845 | CALLER_OWN char *owl_variable_get_tostring(const owl_variable *v) |
---|
[d427f08] | 846 | { |
---|
[353719a] | 847 | GValue instance = G_VALUE_INIT; |
---|
| 848 | GValue tostring_box = G_VALUE_INIT; |
---|
[06e04a9] | 849 | char *ret = NULL; |
---|
[353719a] | 850 | |
---|
| 851 | g_value_init(&instance, G_TYPE_POINTER); |
---|
| 852 | g_value_set_pointer(&instance, NULL); |
---|
| 853 | g_value_init(&tostring_box, G_TYPE_STRING); |
---|
| 854 | g_closure_invoke(v->get_tostring_fn, &tostring_box, 1, &instance, NULL); |
---|
| 855 | |
---|
| 856 | ret = g_value_dup_string(&tostring_box); |
---|
| 857 | |
---|
[63d3e4e] | 858 | g_value_unset(&tostring_box); |
---|
| 859 | g_value_unset(&instance); |
---|
[06e04a9] | 860 | return ret; |
---|
[7d4fbcd] | 861 | } |
---|
| 862 | |
---|
[353719a] | 863 | const char *owl_variable_get_default_tostring(const owl_variable *v) |
---|
[bc1d648] | 864 | { |
---|
[353719a] | 865 | return v->default_str; |
---|
[d536e72] | 866 | } |
---|
| 867 | |
---|
[353719a] | 868 | owl_variable *owl_variable_get_var(const owl_vardict *d, const char *name) |
---|
[bc1d648] | 869 | { |
---|
[353719a] | 870 | return owl_dict_find_element(d, name); |
---|
[7d4fbcd] | 871 | } |
---|
| 872 | |
---|
[ca54fd6] | 873 | const char *owl_variable_get_string(const owl_variable *v) |
---|
| 874 | { |
---|
[353719a] | 875 | g_return_val_if_fail(v->type == OWL_VARIABLE_STRING, NULL); |
---|
| 876 | |
---|
| 877 | get_string_t cb = (get_string_t) v->get_fn; |
---|
| 878 | return cb(v); |
---|
[7d4fbcd] | 879 | } |
---|
| 880 | |
---|
[ca54fd6] | 881 | int owl_variable_get_int(const owl_variable *v) |
---|
| 882 | { |
---|
[353719a] | 883 | g_return_val_if_fail(v->type == OWL_VARIABLE_INT, 0); |
---|
| 884 | |
---|
| 885 | get_int_t cb = (get_int_t) v->get_fn; |
---|
| 886 | return cb(v); |
---|
[7d4fbcd] | 887 | } |
---|
| 888 | |
---|
[4584d1f] | 889 | bool owl_variable_get_bool(const owl_variable *v) |
---|
[ca54fd6] | 890 | { |
---|
[353719a] | 891 | g_return_val_if_fail(v->type == OWL_VARIABLE_BOOL, FALSE); |
---|
| 892 | |
---|
| 893 | get_bool_t cb = (get_bool_t) v->get_fn; |
---|
| 894 | return cb(v); |
---|
[7d4fbcd] | 895 | } |
---|
| 896 | |
---|
[ca54fd6] | 897 | void owl_variable_describe(const owl_variable *v, owl_fmtext *fm) |
---|
| 898 | { |
---|
[353719a] | 899 | const char *default_str = owl_variable_get_default_tostring(v); |
---|
[ca749a9] | 900 | char *default_buf; |
---|
| 901 | |
---|
[353719a] | 902 | if (default_str) |
---|
| 903 | default_buf = g_strdup_printf("'%s'", default_str); |
---|
[ca749a9] | 904 | else |
---|
| 905 | default_buf = g_strdup("<null>"); |
---|
| 906 | owl_fmtext_appendf_normal(fm, OWL_TABSTR "%-20s - %s (default: %s)\n", |
---|
| 907 | owl_variable_get_name(v), |
---|
| 908 | owl_variable_get_summary(v), default_buf); |
---|
[010a951] | 909 | g_free(default_buf); |
---|
[7d4fbcd] | 910 | } |
---|
| 911 | |
---|
[ca54fd6] | 912 | void owl_variable_get_help(const owl_variable *v, owl_fmtext *fm) { |
---|
[010a951] | 913 | char *tostring; |
---|
[353719a] | 914 | const char *default_str; |
---|
[7d4fbcd] | 915 | |
---|
| 916 | owl_fmtext_append_bold(fm, "OWL VARIABLE\n\n"); |
---|
| 917 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
[ca54fd6] | 918 | owl_fmtext_append_normal(fm, owl_variable_get_name(v)); |
---|
[7d4fbcd] | 919 | owl_fmtext_append_normal(fm, " - "); |
---|
[ca54fd6] | 920 | owl_fmtext_append_normal(fm, owl_variable_get_summary(v)); |
---|
[7d4fbcd] | 921 | owl_fmtext_append_normal(fm, "\n\n"); |
---|
| 922 | |
---|
| 923 | owl_fmtext_append_normal(fm, "Current: "); |
---|
[ca54fd6] | 924 | tostring = owl_variable_get_tostring(v); |
---|
[ca749a9] | 925 | owl_fmtext_append_normal(fm, (tostring ? tostring : "<null>")); |
---|
[010a951] | 926 | g_free(tostring); |
---|
[7d4fbcd] | 927 | owl_fmtext_append_normal(fm, "\n\n"); |
---|
| 928 | |
---|
[353719a] | 929 | default_str = owl_variable_get_default_tostring(v); |
---|
[7d4fbcd] | 930 | owl_fmtext_append_normal(fm, "Default: "); |
---|
[353719a] | 931 | owl_fmtext_append_normal(fm, (default_str ? default_str : "<null>")); |
---|
[7d4fbcd] | 932 | owl_fmtext_append_normal(fm, "\n\n"); |
---|
| 933 | |
---|
| 934 | owl_fmtext_append_normal(fm, "Valid Settings: "); |
---|
| 935 | owl_fmtext_append_normal(fm, owl_variable_get_validsettings(v)); |
---|
| 936 | owl_fmtext_append_normal(fm, "\n\n"); |
---|
[aa2f33b3] | 937 | |
---|
| 938 | if (v->description && *v->description) { |
---|
| 939 | owl_fmtext_append_normal(fm, "Description:\n"); |
---|
| 940 | owl_fmtext_append_normal(fm, owl_variable_get_description(v)); |
---|
| 941 | owl_fmtext_append_normal(fm, "\n\n"); |
---|
| 942 | } |
---|
[7d4fbcd] | 943 | } |
---|
| 944 | |
---|
| 945 | |
---|
| 946 | |
---|
| 947 | |
---|
| 948 | /**************************************************************************/ |
---|
| 949 | /*********************** GENERAL TYPE-SPECIFIC ****************************/ |
---|
| 950 | /**************************************************************************/ |
---|
| 951 | |
---|
| 952 | /* default common functions */ |
---|
| 953 | |
---|
[353719a] | 954 | const char *owl_variable_string_get_default(const owl_variable *v) { |
---|
[06e04a9] | 955 | return g_value_get_string(&(v->val)); |
---|
[7d4fbcd] | 956 | } |
---|
| 957 | |
---|
[353719a] | 958 | int owl_variable_int_get_default(const owl_variable *v) { |
---|
[06e04a9] | 959 | return g_value_get_int(&(v->val)); |
---|
| 960 | } |
---|
| 961 | |
---|
[4584d1f] | 962 | bool owl_variable_bool_get_default(const owl_variable *v) { |
---|
[06e04a9] | 963 | return g_value_get_boolean(&(v->val)); |
---|
| 964 | } |
---|
| 965 | |
---|
[7d4fbcd] | 966 | /* default functions for booleans */ |
---|
| 967 | |
---|
[4584d1f] | 968 | int owl_variable_bool_validate_default(const owl_variable *v, bool newval) { |
---|
[06e04a9] | 969 | return (newval == 1) || (newval == 0); |
---|
| 970 | } |
---|
| 971 | |
---|
[353719a] | 972 | int owl_variable_bool_set_default(owl_variable *v, bool newval) { |
---|
| 973 | if (!((validate_bool_t)v->validate_fn)(v, newval)) |
---|
| 974 | return -1; |
---|
[7d4fbcd] | 975 | |
---|
[06e04a9] | 976 | g_value_set_boolean(&(v->val), newval); |
---|
[7d4fbcd] | 977 | return(0); |
---|
| 978 | } |
---|
| 979 | |
---|
[06e04a9] | 980 | int owl_variable_bool_set_fromstring_default(owl_variable *v, const char *newval, void *dummy) { |
---|
[4584d1f] | 981 | bool i; |
---|
[06e04a9] | 982 | if (!strcmp(newval, "on")) { |
---|
[4584d1f] | 983 | i = true; |
---|
[06e04a9] | 984 | } else if (!strcmp(newval, "off")) { |
---|
[4584d1f] | 985 | i = false; |
---|
[06e04a9] | 986 | } else { |
---|
| 987 | return(-1); |
---|
| 988 | } |
---|
[353719a] | 989 | |
---|
| 990 | return owl_variable_set_bool(v, i); |
---|
[7d4fbcd] | 991 | } |
---|
| 992 | |
---|
[353719a] | 993 | CALLER_OWN char *owl_variable_bool_get_tostring_default(const owl_variable *v, void *dummy) |
---|
[d427f08] | 994 | { |
---|
[94b9ee0] | 995 | return g_strdup(owl_variable_get_bool(v) ? "on" : "off"); |
---|
[7d4fbcd] | 996 | } |
---|
| 997 | |
---|
| 998 | /* default functions for integers */ |
---|
| 999 | |
---|
[353719a] | 1000 | int owl_variable_int_validate_default(const owl_variable *v, int newval) |
---|
[06e04a9] | 1001 | { |
---|
| 1002 | return (1); |
---|
[7d4fbcd] | 1003 | } |
---|
| 1004 | |
---|
[353719a] | 1005 | int owl_variable_int_set_default(owl_variable *v, int newval) { |
---|
| 1006 | if (!((validate_int_t)v->validate_fn)(v, newval)) |
---|
| 1007 | return -1; |
---|
| 1008 | |
---|
[06e04a9] | 1009 | g_value_set_int(&(v->val), newval); |
---|
[7d4fbcd] | 1010 | return(0); |
---|
| 1011 | } |
---|
| 1012 | |
---|
[06e04a9] | 1013 | int owl_variable_int_set_fromstring_default(owl_variable *v, const char *newval, void *dummy) { |
---|
[7d4fbcd] | 1014 | int i; |
---|
[99525be] | 1015 | char *ep; |
---|
| 1016 | i = strtol(newval, &ep, 10); |
---|
[7d4fbcd] | 1017 | if (*ep || ep==newval) return(-1); |
---|
[353719a] | 1018 | return owl_variable_set_int(v, i); |
---|
[7d4fbcd] | 1019 | } |
---|
| 1020 | |
---|
[353719a] | 1021 | CALLER_OWN char *owl_variable_int_get_tostring_default(const owl_variable *v, void *dummy) |
---|
[d427f08] | 1022 | { |
---|
[353719a] | 1023 | return g_strdup_printf("%d", owl_variable_get_int(v)); |
---|
[7d4fbcd] | 1024 | } |
---|
| 1025 | |
---|
| 1026 | /* default functions for enums (a variant of integers) */ |
---|
| 1027 | |
---|
[353719a] | 1028 | int owl_variable_enum_validate(const owl_variable *v, int newval) { |
---|
[7d4fbcd] | 1029 | char **enums; |
---|
| 1030 | int nenums, val; |
---|
[d275eb2] | 1031 | enums = g_strsplit_set(v->validsettings, ",", 0); |
---|
| 1032 | nenums = g_strv_length(enums); |
---|
| 1033 | g_strfreev(enums); |
---|
[06e04a9] | 1034 | val = newval; |
---|
[7d4fbcd] | 1035 | if (val < 0 || val >= nenums) { |
---|
| 1036 | return(0); |
---|
| 1037 | } |
---|
| 1038 | return(1); |
---|
| 1039 | } |
---|
| 1040 | |
---|
[06e04a9] | 1041 | int owl_variable_enum_set_fromstring(owl_variable *v, const char *newval, void *dummy) { |
---|
[7d4fbcd] | 1042 | char **enums; |
---|
[d275eb2] | 1043 | int i, val=-1; |
---|
[7d4fbcd] | 1044 | if (newval == NULL) return(-1); |
---|
[d275eb2] | 1045 | enums = g_strsplit_set(v->validsettings, ",", 0); |
---|
| 1046 | for (i = 0; enums[i] != NULL; i++) { |
---|
[7d4fbcd] | 1047 | if (0==strcmp(newval, enums[i])) { |
---|
| 1048 | val = i; |
---|
| 1049 | } |
---|
| 1050 | } |
---|
[d275eb2] | 1051 | g_strfreev(enums); |
---|
[7d4fbcd] | 1052 | if (val == -1) return(-1); |
---|
[353719a] | 1053 | return owl_variable_set_int(v, val); |
---|
[7d4fbcd] | 1054 | } |
---|
| 1055 | |
---|
[353719a] | 1056 | CALLER_OWN char *owl_variable_enum_get_tostring(const owl_variable *v, void *dummy) |
---|
[d427f08] | 1057 | { |
---|
[7d4fbcd] | 1058 | char **enums; |
---|
| 1059 | int nenums, i; |
---|
[010a951] | 1060 | char *tostring; |
---|
[7d4fbcd] | 1061 | |
---|
[d275eb2] | 1062 | enums = g_strsplit_set(v->validsettings, ",", 0); |
---|
| 1063 | nenums = g_strv_length(enums); |
---|
[353719a] | 1064 | i = owl_variable_get_int(v); |
---|
[7d4fbcd] | 1065 | if (i<0 || i>=nenums) { |
---|
[d275eb2] | 1066 | g_strfreev(enums); |
---|
[010a951] | 1067 | return g_strdup_printf("<invalid:%d>", i); |
---|
[7d4fbcd] | 1068 | } |
---|
[010a951] | 1069 | tostring = g_strdup(enums[i]); |
---|
[d275eb2] | 1070 | g_strfreev(enums); |
---|
[010a951] | 1071 | return tostring; |
---|
[7d4fbcd] | 1072 | } |
---|
| 1073 | |
---|
| 1074 | /* default functions for stringeans */ |
---|
| 1075 | |
---|
[353719a] | 1076 | int owl_variable_string_validate_default(const owl_variable *v, const char *newval) { |
---|
[7d4fbcd] | 1077 | if (newval == NULL) return(0); |
---|
| 1078 | else return (1); |
---|
| 1079 | } |
---|
| 1080 | |
---|
[353719a] | 1081 | int owl_variable_string_set_default(owl_variable *v, const char *newval) { |
---|
| 1082 | if (!((validate_string_t)v->validate_fn)(v, newval)) |
---|
| 1083 | return -1; |
---|
[06e04a9] | 1084 | |
---|
| 1085 | g_value_set_string(&(v->val), newval); |
---|
[7d4fbcd] | 1086 | return(0); |
---|
| 1087 | } |
---|
| 1088 | |
---|
[06e04a9] | 1089 | int owl_variable_string_set_fromstring_default(owl_variable *v, const char *newval, void *dummy) |
---|
| 1090 | { |
---|
[353719a] | 1091 | return owl_variable_set_string(v, newval); |
---|
[7d4fbcd] | 1092 | } |
---|
| 1093 | |
---|
[353719a] | 1094 | CALLER_OWN char *owl_variable_string_get_tostring_default(const owl_variable *v, void *dummy) |
---|
[d427f08] | 1095 | { |
---|
[353719a] | 1096 | return g_strdup(owl_variable_get_string(v)); |
---|
[7d4fbcd] | 1097 | } |
---|
| 1098 | |
---|