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