[dab82f29] | 1 | /* Copyright (c) 2002,2003,2004,2009 James M. Kretchmar |
---|
| 2 | * |
---|
| 3 | * This file is part of Owl. |
---|
| 4 | * |
---|
| 5 | * Owl is free software: you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU General Public License as published by |
---|
| 7 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 8 | * (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * Owl is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU General Public License |
---|
| 16 | * along with Owl. If not, see <http://www.gnu.org/licenses/>. |
---|
| 17 | * |
---|
| 18 | * --------------------------------------------------------------- |
---|
| 19 | * |
---|
| 20 | * As of Owl version 2.1.12 there are patches contributed by |
---|
| 21 | * developers of the the branched BarnOwl project, Copyright (c) |
---|
| 22 | * 2006-2008 The BarnOwl Developers. All rights reserved. |
---|
| 23 | */ |
---|
| 24 | |
---|
[7d4fbcd] | 25 | #include <stdio.h> |
---|
| 26 | #include <stdlib.h> |
---|
| 27 | #include <string.h> |
---|
| 28 | #include <unistd.h> |
---|
| 29 | #include <ctype.h> |
---|
| 30 | #include "owl.h" |
---|
| 31 | |
---|
[1aee7d9] | 32 | static const char fileIdent[] = "$Id$"; |
---|
| 33 | |
---|
[e1c4636] | 34 | static int in_regtest = 0; |
---|
| 35 | |
---|
[aa2f33b3] | 36 | #define OWLVAR_BOOL(name,default,summary,description) \ |
---|
| 37 | { name, OWL_VARIABLE_BOOL, NULL, default, "on,off", summary,description, NULL, \ |
---|
[7d4fbcd] | 38 | NULL, NULL, NULL, NULL, NULL } |
---|
| 39 | |
---|
[aa2f33b3] | 40 | #define OWLVAR_BOOL_FULL(name,default,summary,description,validate,set,get) \ |
---|
| 41 | { name, OWL_VARIABLE_BOOL, NULL, default, "on,off", summary,description, NULL, \ |
---|
[7d4fbcd] | 42 | validate, set, NULL, get, NULL } |
---|
| 43 | |
---|
[aa2f33b3] | 44 | #define OWLVAR_INT(name,default,summary,description) \ |
---|
| 45 | { name, OWL_VARIABLE_INT, NULL, default, "<int>", summary,description, NULL, \ |
---|
[7d4fbcd] | 46 | NULL, NULL, NULL, NULL, NULL, NULL } |
---|
| 47 | |
---|
[aa2f33b3] | 48 | #define OWLVAR_INT_FULL(name,default,summary,description,validset,validate,set,get) \ |
---|
| 49 | { name, OWL_VARIABLE_INT, NULL, default, validset, summary,description, NULL, \ |
---|
[7d4fbcd] | 50 | validate, set, NULL, get, NULL, NULL } |
---|
| 51 | |
---|
[aa2f33b3] | 52 | #define OWLVAR_PATH(name,default,summary,description) \ |
---|
| 53 | { name, OWL_VARIABLE_STRING, default, 0, "<path>", summary,description, NULL, \ |
---|
[7d4fbcd] | 54 | NULL, NULL, NULL, NULL, NULL, NULL } |
---|
| 55 | |
---|
[aa2f33b3] | 56 | #define OWLVAR_STRING(name,default,summary,description) \ |
---|
| 57 | { name, OWL_VARIABLE_STRING, default, 0, "<string>", summary,description, NULL, \ |
---|
[7d4fbcd] | 58 | NULL, NULL, NULL, NULL, NULL, NULL } |
---|
| 59 | |
---|
[c01e477] | 60 | #define OWLVAR_STRING_FULL(name,default,summary,description,validate,set,get) \ |
---|
| 61 | { name, OWL_VARIABLE_STRING, default, 0, "<string>", summary,description, NULL, \ |
---|
| 62 | validate, set, NULL, get, NULL, NULL } |
---|
| 63 | |
---|
[7d4fbcd] | 64 | /* enums are really integers, but where validset is a comma-separated |
---|
| 65 | * list of strings which can be specified. The tokens, starting at 0, |
---|
| 66 | * correspond to the values that may be specified. */ |
---|
[aa2f33b3] | 67 | #define OWLVAR_ENUM(name,default,summary,description,validset) \ |
---|
| 68 | { name, OWL_VARIABLE_INT, NULL, default, validset, summary,description, NULL, \ |
---|
[7d4fbcd] | 69 | owl_variable_enum_validate, \ |
---|
| 70 | NULL, owl_variable_enum_set_fromstring, \ |
---|
| 71 | NULL, owl_variable_enum_get_tostring, \ |
---|
| 72 | NULL } |
---|
| 73 | |
---|
[aa2f33b3] | 74 | #define OWLVAR_ENUM_FULL(name,default,summary,description,validset,validate, set, get) \ |
---|
| 75 | { name, OWL_VARIABLE_INT, NULL, default, validset, summary,description, NULL, \ |
---|
[217a43e] | 76 | validate, \ |
---|
| 77 | set, owl_variable_enum_set_fromstring, \ |
---|
| 78 | get, owl_variable_enum_get_tostring, \ |
---|
| 79 | NULL } |
---|
| 80 | |
---|
[7d4fbcd] | 81 | static owl_variable variables_to_init[] = { |
---|
| 82 | |
---|
[5d365f6] | 83 | OWLVAR_STRING( "personalbell" /* %OwlVarStub */, "off", |
---|
[213a3eb] | 84 | "ring the terminal bell when personal messages are received", |
---|
[5d365f6] | 85 | "Can be set to 'on', 'off', or the name of a filter which\n" |
---|
| 86 | "messages need to match in order to ring the bell"), |
---|
[7d4fbcd] | 87 | |
---|
| 88 | OWLVAR_BOOL( "bell" /* %OwlVarStub */, 1, |
---|
[aa2f33b3] | 89 | "enable / disable the terminal bell", "" ), |
---|
[7d4fbcd] | 90 | |
---|
| 91 | OWLVAR_BOOL_FULL( "debug" /* %OwlVarStub */, OWL_DEBUG, |
---|
| 92 | "whether debugging is enabled", |
---|
[aa2f33b3] | 93 | "If set to 'on', debugging messages are logged to the\n" |
---|
| 94 | "file specified by the debugfile variable.\n", |
---|
[7d4fbcd] | 95 | NULL, owl_variable_debug_set, NULL), |
---|
| 96 | |
---|
| 97 | OWLVAR_BOOL( "startuplogin" /* %OwlVarStub */, 1, |
---|
[aa2f33b3] | 98 | "send a login message when owl starts", "" ), |
---|
[7d4fbcd] | 99 | |
---|
| 100 | OWLVAR_BOOL( "shutdownlogout" /* %OwlVarStub */, 1, |
---|
[aa2f33b3] | 101 | "send a logout message when owl exits", "" ), |
---|
[7d4fbcd] | 102 | |
---|
| 103 | OWLVAR_BOOL( "rxping" /* %OwlVarStub */, 0, |
---|
[aa2f33b3] | 104 | "display received pings", "" ), |
---|
[7d4fbcd] | 105 | |
---|
| 106 | OWLVAR_BOOL( "txping" /* %OwlVarStub */, 1, |
---|
[aa2f33b3] | 107 | "send pings", "" ), |
---|
[7d4fbcd] | 108 | |
---|
[73624b4] | 109 | OWLVAR_BOOL( "sepbar_disable" /* %OwlVarStub */, 0, |
---|
| 110 | "disable printing information in the seperator bar", "" ), |
---|
| 111 | |
---|
[f9c43ae] | 112 | OWLVAR_BOOL( "smartstrip" /* %OwlVarStub */, 1, |
---|
| 113 | "strip kerberos instance for reply", ""), |
---|
| 114 | |
---|
[7e3e00a] | 115 | OWLVAR_BOOL( "newlinestrip" /* %OwlVarStub */, 1, |
---|
| 116 | "strip leading and trailing newlines", ""), |
---|
| 117 | |
---|
[7d4fbcd] | 118 | OWLVAR_BOOL( "displayoutgoing" /* %OwlVarStub */, 1, |
---|
[aa2f33b3] | 119 | "display outgoing messages", "" ), |
---|
[7d4fbcd] | 120 | |
---|
| 121 | OWLVAR_BOOL( "loginsubs" /* %OwlVarStub */, 1, |
---|
[aa2f33b3] | 122 | "load logins from .anyone on startup", "" ), |
---|
[7d4fbcd] | 123 | |
---|
| 124 | OWLVAR_BOOL( "logging" /* %OwlVarStub */, 0, |
---|
[aa2f33b3] | 125 | "turn personal logging on or off", |
---|
| 126 | "If this is set to on, personal messages are\n" |
---|
| 127 | "logged in the directory specified\n" |
---|
| 128 | "by the 'logpath' variable. The filename in that\n" |
---|
| 129 | "directory is derived from the sender of the message.\n" ), |
---|
[7d4fbcd] | 130 | |
---|
| 131 | OWLVAR_BOOL( "classlogging" /* %OwlVarStub */, 0, |
---|
[aa2f33b3] | 132 | "turn class logging on or off", |
---|
| 133 | "If this is set to on, class messages are\n" |
---|
| 134 | "logged in the directory specified\n" |
---|
| 135 | "by the 'classlogpath' variable.\n" |
---|
| 136 | "The filename in that directory is derived from\n" |
---|
| 137 | "the name of the class to which the message was sent.\n" ), |
---|
[7d4fbcd] | 138 | |
---|
[12c35df] | 139 | OWLVAR_ENUM( "loggingdirection" /* %OwlVarStub */, OWL_LOGGING_DIRECTION_BOTH, |
---|
| 140 | "specifices which kind of messages should be logged", |
---|
| 141 | "Can be one of 'both', 'in', or 'out'. If 'in' is\n" |
---|
| 142 | "selected, only incoming messages are logged, if 'out'\n" |
---|
| 143 | "is selected only outgoing messages are logged. If 'both'\n" |
---|
| 144 | "is selected both incoming and outgoing messages are\n" |
---|
| 145 | "logged.", |
---|
| 146 | "both,in,out"), |
---|
| 147 | |
---|
[e1c4636] | 148 | OWLVAR_BOOL( "colorztext" /* %OwlVarStub */, 1, |
---|
[aa2f33b3] | 149 | "allow @color() in zephyrs to change color", |
---|
| 150 | "Note that only messages received after this variable\n" |
---|
| 151 | "is set will be affected." ), |
---|
[e1c4636] | 152 | |
---|
[c15bbfb] | 153 | OWLVAR_BOOL( "fancylines" /* %OwlVarStub */, 1, |
---|
| 154 | "Use 'nice' line drawing on the terminal.", |
---|
| 155 | "If turned off, dashes, pipes and pluses will be used\n" |
---|
| 156 | "to draw lines on the screen. Useful when the terminal\n" |
---|
| 157 | "is causing problems" ), |
---|
| 158 | |
---|
[d309eb3] | 159 | OWLVAR_BOOL( "zcrypt" /* %OwlVarStub */, 1, |
---|
| 160 | "Do automatic zcrypt processing", |
---|
| 161 | "" ), |
---|
| 162 | |
---|
[4357be8] | 163 | OWLVAR_BOOL_FULL( "pseudologins" /* %OwlVarStub */, 0, |
---|
| 164 | "Enable zephyr pseudo logins", |
---|
| 165 | "When this is enabled, Owl will periodically check the zephyr\n" |
---|
| 166 | "location of users in your .anyone file. If a user is present\n" |
---|
| 167 | "but sent no login message, or a user is not present that sent no\n" |
---|
| 168 | "logout message a pseudo login or logout message wil be created\n", |
---|
| 169 | NULL, owl_variable_pseudologins_set, NULL), |
---|
[5a95b69] | 170 | |
---|
[280ddc6] | 171 | OWLVAR_BOOL( "ignorelogins" /* %OwlVarStub */, 0, |
---|
| 172 | "Enable printing of login notifications", |
---|
| 173 | "When this is enabled, Owl will print login and logout notifications\n" |
---|
[3038d13] | 174 | "for AIM, zephyr, or other protocols. If disabled Owl will not print\n" |
---|
| 175 | "login or logout notifications.\n"), |
---|
[280ddc6] | 176 | |
---|
[15b34fd] | 177 | OWLVAR_STRING( "logfilter" /* %OwlVarStub */, "", |
---|
| 178 | "name of a filter controlling which messages to log", |
---|
| 179 | |
---|
| 180 | "If non empty, any messages matching the given filter will be logged.\n" |
---|
| 181 | "This is a completely separate mechanisim from the other logging\n" |
---|
| 182 | "variables like logging, classlogging, loglogins, loggingdirection,\n" |
---|
| 183 | "etc. If you want this variable to control all logging, make sure\n" |
---|
| 184 | "all other logging variables are in their default state.\n"), |
---|
| 185 | |
---|
[e22f27c] | 186 | OWLVAR_BOOL( "loglogins" /* %OwlVarStub */, 0, |
---|
| 187 | "Enable logging of login notifications", |
---|
| 188 | "When this is enabled, Owl will login login and logout notifications\n" |
---|
| 189 | "for AIM, zephyr, or other protocols. If disabled Owl will not print\n" |
---|
| 190 | "login or logout notifications.\n"), |
---|
| 191 | |
---|
[217a43e] | 192 | OWLVAR_ENUM_FULL( "disable-ctrl-d" /* %OwlVarStub:lockout_ctrld */, 1, |
---|
[aa2f33b3] | 193 | "don't send zephyrs on C-d", |
---|
| 194 | "If set to 'off', C-d won't send a zephyr from the edit\n" |
---|
| 195 | "window. If set to 'on', C-d will always send a zephyr\n" |
---|
| 196 | "being composed in the edit window. If set to 'middle',\n" |
---|
| 197 | "C-d will only ever send a zephyr if the cursor is at\n" |
---|
| 198 | "the end of the message being composed.\n\n" |
---|
| 199 | "Note that this works by changing the C-d keybinding\n" |
---|
| 200 | "in the editmulti keymap.\n", |
---|
| 201 | "off,middle,on", |
---|
[7d4fbcd] | 202 | NULL, owl_variable_disable_ctrl_d_set, NULL), |
---|
| 203 | |
---|
| 204 | OWLVAR_BOOL( "_burningears" /* %OwlVarStub:burningears */, 0, |
---|
[aa2f33b3] | 205 | "[NOT YET IMPLEMENTED] beep on messages matching patterns", "" ), |
---|
[7d4fbcd] | 206 | |
---|
| 207 | OWLVAR_BOOL( "_summarymode" /* %OwlVarStub:summarymode */, 0, |
---|
[aa2f33b3] | 208 | "[NOT YET IMPLEMENTED]", "" ), |
---|
[7d4fbcd] | 209 | |
---|
| 210 | OWLVAR_PATH( "logpath" /* %OwlVarStub */, "~/zlog/people", |
---|
[aa2f33b3] | 211 | "path for logging personal zephyrs", |
---|
| 212 | "Specifies a directory which must exist.\n" |
---|
| 213 | "Files will be created in the directory for each sender.\n"), |
---|
[7d4fbcd] | 214 | |
---|
| 215 | OWLVAR_PATH( "classlogpath" /* %OwlVarStub:classlogpath */, "~/zlog/class", |
---|
[aa2f33b3] | 216 | "path for logging class zephyrs", |
---|
| 217 | "Specifies a directory which must exist.\n" |
---|
| 218 | "Files will be created in the directory for each class.\n"), |
---|
[7d4fbcd] | 219 | |
---|
| 220 | OWLVAR_PATH( "debug_file" /* %OwlVarStub */, OWL_DEBUG_FILE, |
---|
[aa2f33b3] | 221 | "path for logging debug messages when debugging is enabled", |
---|
| 222 | "This file will be logged to if 'debug' is set to 'on'.\n"), |
---|
[7d4fbcd] | 223 | |
---|
[ced25d1] | 224 | OWLVAR_PATH( "zsigproc" /* %OwlVarStub:zsigproc */, NULL, |
---|
[aa2f33b3] | 225 | "name of a program to run that will generate zsigs", |
---|
| 226 | "This program should produce a zsig on stdout when run.\n" |
---|
| 227 | "Note that it is important that this program not block.\n" ), |
---|
[7d4fbcd] | 228 | |
---|
[700c712] | 229 | OWLVAR_PATH( "newmsgproc" /* %OwlVarStub:newmsgproc */, NULL, |
---|
| 230 | "name of a program to run when new messages are present", |
---|
| 231 | "The named program will be run when owl recevies new.\n" |
---|
| 232 | "messages. It will not be run again until the first\n" |
---|
| 233 | "instance exits"), |
---|
| 234 | |
---|
[7d4fbcd] | 235 | OWLVAR_STRING( "zsig" /* %OwlVarStub */, "", |
---|
[aa2f33b3] | 236 | "zephyr signature", |
---|
| 237 | "If 'zsigproc' is not set, this string will be used\n" |
---|
| 238 | "as a zsig. If this is also unset, the 'zwrite-signature'\n" |
---|
| 239 | "zephyr variable will be used instead.\n"), |
---|
[7d4fbcd] | 240 | |
---|
| 241 | OWLVAR_STRING( "appendtosepbar" /* %OwlVarStub */, "", |
---|
[aa2f33b3] | 242 | "string to append to the end of the sepbar", |
---|
| 243 | "The sepbar is the bar separating the top and bottom\n" |
---|
| 244 | "of the owl screen. Any string specified here will\n" |
---|
| 245 | "be displayed on the right of the sepbar\n"), |
---|
[7d4fbcd] | 246 | |
---|
| 247 | OWLVAR_BOOL( "zaway" /* %OwlVarStub */, 0, |
---|
[aa2f33b3] | 248 | "turn zaway on or off", "" ), |
---|
[7d4fbcd] | 249 | |
---|
| 250 | OWLVAR_STRING( "zaway_msg" /* %OwlVarStub */, |
---|
| 251 | OWL_DEFAULT_ZAWAYMSG, |
---|
[aa2f33b3] | 252 | "zaway msg for responding to zephyrs when away", "" ), |
---|
[7d4fbcd] | 253 | |
---|
| 254 | OWLVAR_STRING( "zaway_msg_default" /* %OwlVarStub */, |
---|
| 255 | OWL_DEFAULT_ZAWAYMSG, |
---|
[aa2f33b3] | 256 | "default zaway message", "" ), |
---|
[7d4fbcd] | 257 | |
---|
[4b660cc] | 258 | OWLVAR_BOOL_FULL( "aaway" /* %OwlVarStub */, 0, |
---|
| 259 | "Set AIM away status", |
---|
| 260 | "", |
---|
| 261 | NULL, owl_variable_aaway_set, NULL), |
---|
| 262 | |
---|
| 263 | OWLVAR_STRING( "aaway_msg" /* %OwlVarStub */, |
---|
| 264 | OWL_DEFAULT_AAWAYMSG, |
---|
| 265 | "AIM away msg for responding when away", "" ), |
---|
| 266 | |
---|
| 267 | OWLVAR_STRING( "aaway_msg_default" /* %OwlVarStub */, |
---|
| 268 | OWL_DEFAULT_AAWAYMSG, |
---|
| 269 | "default AIM away message", "" ), |
---|
| 270 | |
---|
[7d4fbcd] | 271 | OWLVAR_STRING( "view_home" /* %OwlVarStub */, "all", |
---|
[aa2f33b3] | 272 | "home view to switch to after 'X' and 'V'", |
---|
| 273 | "SEE ALSO: view, filter\n" ), |
---|
[7d4fbcd] | 274 | |
---|
[ecd5dc5] | 275 | OWLVAR_STRING( "alert_filter" /* %OwlVarStub */, "none", |
---|
| 276 | "filter on which to trigger alert actions", |
---|
| 277 | "" ), |
---|
| 278 | |
---|
| 279 | OWLVAR_STRING( "alert_action" /* %OwlVarStub */, "nop", |
---|
[b278973] | 280 | "owl command to execute for alert actions", |
---|
[ecd5dc5] | 281 | "" ), |
---|
| 282 | |
---|
[c01e477] | 283 | OWLVAR_STRING_FULL( "tty" /* %OwlVarStub */, "", "tty name for zephyr location", "", |
---|
| 284 | NULL, owl_variable_tty_set, NULL), |
---|
[bd3f232] | 285 | |
---|
[27c3a93] | 286 | OWLVAR_STRING( "default_style" /* %OwlVarStub */, "__unspecified__", |
---|
[c3ab155] | 287 | "name of the default formatting style", |
---|
[f1e629d] | 288 | "This sets the default message formatting style.\n" |
---|
| 289 | "Styles may be created with the 'style' command.\n" |
---|
| 290 | "Some built-in styles include:\n" |
---|
| 291 | " default - the default owl formatting\n" |
---|
| 292 | " basic - simple formatting\n" |
---|
| 293 | " oneline - one line per-message\n" |
---|
| 294 | " perl - legacy perl interface\n" |
---|
| 295 | "\nSEE ALSO: style, show styles, view -s <style>\n" |
---|
| 296 | ), |
---|
| 297 | |
---|
[c3ab155] | 298 | |
---|
[d36f2cb] | 299 | OWLVAR_INT( "edit:maxfillcols" /* %OwlVarStub:edit_maxfillcols */, 70, |
---|
[aa2f33b3] | 300 | "maximum number of columns for M-q to fill text to", |
---|
| 301 | "This specifies the maximum number of columns for M-q\n" |
---|
| 302 | "to fill text to. If set to 0, ther will be no maximum\n" |
---|
| 303 | "limit. In all cases, the current width of the screen\n" |
---|
| 304 | "will also be taken into account. It will be used instead\n" |
---|
| 305 | "if it is narrower than the maximum, or if this\n" |
---|
| 306 | "is set to 0.\n" ), |
---|
[d36f2cb] | 307 | |
---|
[039213e] | 308 | OWLVAR_INT( "edit:maxwrapcols" /* %OwlVarStub:edit_maxwrapcols */, 0, |
---|
[aa2f33b3] | 309 | "maximum number of columns for line-wrapping", |
---|
| 310 | "This specifies the maximum number of columns for\n" |
---|
| 311 | "auto-line-wrapping. If set to 0, ther will be no maximum\n" |
---|
| 312 | "limit. In all cases, the current width of the screen\n" |
---|
| 313 | "will also be taken into account. It will be used instead\n" |
---|
| 314 | "if it is narrower than the maximum, or if this\n" |
---|
| 315 | "is set to 0.\n\n" |
---|
| 316 | "It is recommended that outgoing messages be no wider\n" |
---|
| 317 | "than 60 columns, as a courtesy to recipients.\n"), |
---|
[d36f2cb] | 318 | |
---|
[1db061d] | 319 | OWLVAR_INT( "aim_ignorelogin_timer" /* %OwlVarStub */, 15, |
---|
[6a415e9] | 320 | "number of seconds after AIM login to ignore login messages", |
---|
| 321 | "This specifies the number of seconds to wait after an\n" |
---|
| 322 | "AIM login before allowing the recipt of AIM login notifications.\n" |
---|
[1db061d] | 323 | "By default this is set to 15. If you would like to view login\n" |
---|
| 324 | "notifications of buddies as soon as you login, set it to 0 instead."), |
---|
[6a415e9] | 325 | |
---|
| 326 | |
---|
[7d4fbcd] | 327 | OWLVAR_INT_FULL( "typewinsize" /* %OwlVarStub:typwin_lines */, |
---|
| 328 | OWL_TYPWIN_SIZE, |
---|
[aa2f33b3] | 329 | "number of lines in the typing window", |
---|
| 330 | "This specifies the height of the window at the\n" |
---|
| 331 | "bottom of the screen where commands are entered\n" |
---|
| 332 | "and where messages are composed.\n", |
---|
| 333 | "int > 0", |
---|
[7d4fbcd] | 334 | owl_variable_int_validate_gt0, |
---|
| 335 | owl_variable_typewinsize_set, |
---|
| 336 | NULL /* use default for get */ |
---|
| 337 | ), |
---|
| 338 | |
---|
[aa2f33b3] | 339 | OWLVAR_ENUM( "scrollmode" /* %OwlVarStub */, OWL_SCROLLMODE_NORMAL, |
---|
| 340 | "how to scroll up and down", |
---|
| 341 | "This controls how the screen is scrolled as the\n" |
---|
| 342 | "cursor moves between messages being displayed.\n" |
---|
| 343 | "The following modes are supported:\n\n" |
---|
| 344 | " normal - This is the owl default. Scrolling happens\n" |
---|
| 345 | " when it needs to, and an attempt is made to\n" |
---|
| 346 | " keep the current message roughly near\n" |
---|
| 347 | " the middle of the screen.\n" |
---|
| 348 | " top - The current message will always be the\n" |
---|
| 349 | " the top message displayed.\n" |
---|
| 350 | " neartop - The current message will be one down\n" |
---|
| 351 | " from the top message displayed,\n" |
---|
| 352 | " where possible.\n" |
---|
| 353 | " center - An attempt is made to keep the current\n" |
---|
| 354 | " message near the center of the screen.\n" |
---|
| 355 | " paged - The top message displayed only changes\n" |
---|
| 356 | " when user moves the cursor to the top\n" |
---|
| 357 | " or bottom of the screen. When it moves,\n" |
---|
| 358 | " the screen will be paged up or down and\n" |
---|
| 359 | " the cursor will be near the top or\n" |
---|
| 360 | " the bottom.\n" |
---|
| 361 | " pagedcenter - The top message displayed only changes\n" |
---|
| 362 | " when user moves the cursor to the top\n" |
---|
| 363 | " or bottom of the screen. When it moves,\n" |
---|
| 364 | " the screen will be paged up or down and\n" |
---|
| 365 | " the cursor will be near the center.\n", |
---|
| 366 | "normal,top,neartop,center,paged,pagedcenter" ), |
---|
| 367 | |
---|
[ecd5dc5] | 368 | |
---|
[7d4fbcd] | 369 | OWLVAR_BOOL( "_followlast" /* %OwlVarStub */, 0, |
---|
[aa2f33b3] | 370 | "enable automatic following of the last zephyr", |
---|
| 371 | "If the cursor is at the last message, it will\n" |
---|
| 372 | "continue to follow the last message if this is set.\n" |
---|
| 373 | "Note that this is currently risky as you might accidentally\n" |
---|
| 374 | "delete a message right as it came in.\n" ), |
---|
[7d4fbcd] | 375 | |
---|
| 376 | /* This MUST be last... */ |
---|
[aa2f33b3] | 377 | { NULL, 0, NULL, 0, NULL, NULL, NULL, NULL, |
---|
| 378 | NULL, NULL, NULL, NULL, NULL, NULL } |
---|
[7d4fbcd] | 379 | |
---|
| 380 | }; |
---|
| 381 | |
---|
| 382 | /**************************************************************************/ |
---|
| 383 | /*********************** SPECIFIC TO VARIABLES ****************************/ |
---|
| 384 | /**************************************************************************/ |
---|
| 385 | |
---|
| 386 | |
---|
| 387 | /* commonly useful */ |
---|
| 388 | |
---|
[4357be8] | 389 | int owl_variable_int_validate_gt0(owl_variable *v, void *newval) |
---|
| 390 | { |
---|
[7d4fbcd] | 391 | if (newval == NULL) return(0); |
---|
| 392 | else if (*(int*)newval < 1) return(0); |
---|
| 393 | else return (1); |
---|
| 394 | } |
---|
| 395 | |
---|
[4357be8] | 396 | int owl_variable_int_validate_positive(owl_variable *v, void *newval) |
---|
| 397 | { |
---|
[7d4fbcd] | 398 | if (newval == NULL) return(0); |
---|
| 399 | else if (*(int*)newval < 0) return(0); |
---|
| 400 | else return (1); |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | /* typewinsize */ |
---|
[4357be8] | 404 | int owl_variable_typewinsize_set(owl_variable *v, void *newval) |
---|
| 405 | { |
---|
[7d4fbcd] | 406 | int rv; |
---|
| 407 | rv = owl_variable_int_set_default(v, newval); |
---|
| 408 | if (0 == rv) owl_function_resize(); |
---|
| 409 | return(rv); |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | /* debug (cache value in g->debug) */ |
---|
[4357be8] | 413 | int owl_variable_debug_set(owl_variable *v, void *newval) |
---|
| 414 | { |
---|
[7d4fbcd] | 415 | if (newval && (*(int*)newval == 1 || *(int*)newval == 0)) { |
---|
| 416 | g.debug = *(int*)newval; |
---|
| 417 | } |
---|
| 418 | return owl_variable_bool_set_default(v, newval); |
---|
[4b660cc] | 419 | } |
---|
| 420 | |
---|
| 421 | /* When 'aaway' is changed, need to notify the AIM server */ |
---|
[4357be8] | 422 | int owl_variable_aaway_set(owl_variable *v, void *newval) |
---|
| 423 | { |
---|
[4b660cc] | 424 | if (newval) { |
---|
| 425 | if (*(int*)newval == 1) { |
---|
| 426 | owl_aim_set_awaymsg(owl_global_get_aaway_msg(&g)); |
---|
| 427 | } else if (*(int*)newval == 0) { |
---|
| 428 | owl_aim_set_awaymsg(""); |
---|
| 429 | } |
---|
| 430 | } |
---|
| 431 | return owl_variable_bool_set_default(v, newval); |
---|
[7d4fbcd] | 432 | } |
---|
| 433 | |
---|
[4357be8] | 434 | int owl_variable_pseudologins_set(owl_variable *v, void *newval) |
---|
| 435 | { |
---|
| 436 | if (newval) { |
---|
| 437 | if (*(int*)newval == 1) { |
---|
| 438 | owl_function_zephyr_buddy_check(0); |
---|
| 439 | } |
---|
| 440 | } |
---|
| 441 | return owl_variable_bool_set_default(v, newval); |
---|
| 442 | } |
---|
| 443 | |
---|
[7d4fbcd] | 444 | /* note that changing the value of this will clobber |
---|
| 445 | * any user setting of this */ |
---|
[4357be8] | 446 | int owl_variable_disable_ctrl_d_set(owl_variable *v, void *newval) |
---|
| 447 | { |
---|
[e1c4636] | 448 | |
---|
| 449 | if (in_regtest) return owl_variable_int_set_default(v, newval); |
---|
| 450 | |
---|
[217a43e] | 451 | if (newval && !owl_context_is_startup(owl_global_get_context(&g))) { |
---|
| 452 | if (*(int*)newval == 2) { |
---|
[7d4fbcd] | 453 | owl_function_command_norv("bindkey editmulti C-d command edit:delete-next-char"); |
---|
[217a43e] | 454 | } else if (*(int*)newval == 1) { |
---|
| 455 | owl_function_command_norv("bindkey editmulti C-d command editmulti:done-or-delete"); |
---|
[7d4fbcd] | 456 | } else { |
---|
| 457 | owl_function_command_norv("bindkey editmulti C-d command editmulti:done"); |
---|
| 458 | } |
---|
| 459 | } |
---|
[217a43e] | 460 | return owl_variable_int_set_default(v, newval); |
---|
[7d4fbcd] | 461 | } |
---|
| 462 | |
---|
[4357be8] | 463 | int owl_variable_tty_set(owl_variable *v, void *newval) |
---|
| 464 | { |
---|
[09489b89] | 465 | owl_zephyr_set_locationinfo(owl_global_get_hostname(&g), newval); |
---|
[c01e477] | 466 | return(owl_variable_string_set_default(v, newval)); |
---|
| 467 | } |
---|
| 468 | |
---|
[7d4fbcd] | 469 | |
---|
| 470 | /**************************************************************************/ |
---|
| 471 | /****************************** GENERAL ***********************************/ |
---|
| 472 | /**************************************************************************/ |
---|
| 473 | |
---|
| 474 | int owl_variable_dict_setup(owl_vardict *vd) { |
---|
| 475 | owl_variable *cur; |
---|
| 476 | if (owl_dict_create(vd)) return(-1); |
---|
| 477 | for (cur = variables_to_init; cur->name != NULL; cur++) { |
---|
| 478 | switch (cur->type) { |
---|
| 479 | case OWL_VARIABLE_OTHER: |
---|
| 480 | cur->set_fn(cur, cur->pval_default); |
---|
| 481 | break; |
---|
| 482 | case OWL_VARIABLE_STRING: |
---|
| 483 | if (!cur->validate_fn) |
---|
| 484 | cur->validate_fn = owl_variable_string_validate_default; |
---|
| 485 | if (!cur->set_fn) |
---|
| 486 | cur->set_fn = owl_variable_string_set_default; |
---|
| 487 | if (!cur->set_fromstring_fn) |
---|
| 488 | cur->set_fromstring_fn = owl_variable_string_set_fromstring_default; |
---|
| 489 | if (!cur->get_fn) |
---|
| 490 | cur->get_fn = owl_variable_get_default; |
---|
| 491 | if (!cur->get_tostring_fn) |
---|
| 492 | cur->get_tostring_fn = owl_variable_string_get_tostring_default; |
---|
| 493 | if (!cur->free_fn) |
---|
| 494 | cur->free_fn = owl_variable_free_default; |
---|
| 495 | cur->set_fn(cur, cur->pval_default); |
---|
| 496 | break; |
---|
| 497 | case OWL_VARIABLE_BOOL: |
---|
| 498 | if (!cur->validate_fn) |
---|
| 499 | cur->validate_fn = owl_variable_bool_validate_default; |
---|
| 500 | if (!cur->set_fn) |
---|
| 501 | cur->set_fn = owl_variable_bool_set_default; |
---|
| 502 | if (!cur->set_fromstring_fn) |
---|
| 503 | cur->set_fromstring_fn = owl_variable_bool_set_fromstring_default; |
---|
| 504 | if (!cur->get_fn) |
---|
| 505 | cur->get_fn = owl_variable_get_default; |
---|
| 506 | if (!cur->get_tostring_fn) |
---|
| 507 | cur->get_tostring_fn = owl_variable_bool_get_tostring_default; |
---|
| 508 | if (!cur->free_fn) |
---|
| 509 | cur->free_fn = owl_variable_free_default; |
---|
| 510 | cur->val = owl_malloc(sizeof(int)); |
---|
| 511 | cur->set_fn(cur, &cur->ival_default); |
---|
| 512 | break; |
---|
| 513 | case OWL_VARIABLE_INT: |
---|
| 514 | if (!cur->validate_fn) |
---|
| 515 | cur->validate_fn = owl_variable_int_validate_default; |
---|
| 516 | if (!cur->set_fn) |
---|
| 517 | cur->set_fn = owl_variable_int_set_default; |
---|
| 518 | if (!cur->set_fromstring_fn) |
---|
| 519 | cur->set_fromstring_fn = owl_variable_int_set_fromstring_default; |
---|
| 520 | if (!cur->get_fn) |
---|
| 521 | cur->get_fn = owl_variable_get_default; |
---|
| 522 | if (!cur->get_tostring_fn) |
---|
| 523 | cur->get_tostring_fn = owl_variable_int_get_tostring_default; |
---|
| 524 | if (!cur->free_fn) |
---|
| 525 | cur->free_fn = owl_variable_free_default; |
---|
| 526 | cur->val = owl_malloc(sizeof(int)); |
---|
| 527 | cur->set_fn(cur, &cur->ival_default); |
---|
| 528 | break; |
---|
| 529 | default: |
---|
| 530 | fprintf(stderr, "owl_variable_setup: invalid variable type\n"); |
---|
| 531 | return(-2); |
---|
| 532 | } |
---|
| 533 | owl_dict_insert_element(vd, cur->name, (void*)cur, NULL); |
---|
| 534 | } |
---|
| 535 | return 0; |
---|
| 536 | } |
---|
| 537 | |
---|
| 538 | void owl_variable_dict_free(owl_vardict *d) { |
---|
| 539 | owl_dict_free_all(d, (void(*)(void*))owl_variable_free); |
---|
| 540 | } |
---|
| 541 | |
---|
| 542 | /* free the list with owl_variable_dict_namelist_free */ |
---|
| 543 | void owl_variable_dict_get_names(owl_vardict *d, owl_list *l) { |
---|
| 544 | owl_dict_get_keys(d, l); |
---|
| 545 | } |
---|
| 546 | |
---|
| 547 | void owl_variable_dict_namelist_free(owl_list *l) { |
---|
| 548 | owl_list_free_all(l, owl_free); |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | void owl_variable_free(owl_variable *v) { |
---|
| 552 | if (v->free_fn) v->free_fn(v); |
---|
| 553 | } |
---|
| 554 | |
---|
| 555 | |
---|
[aa2f33b3] | 556 | char *owl_variable_get_description(owl_variable *v) { |
---|
| 557 | return v->description; |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | char *owl_variable_get_summary(owl_variable *v) { |
---|
| 561 | return v->summary; |
---|
[7d4fbcd] | 562 | } |
---|
| 563 | |
---|
| 564 | char *owl_variable_get_validsettings(owl_variable *v) { |
---|
| 565 | if (v->validsettings) { |
---|
| 566 | return v->validsettings; |
---|
| 567 | } else { |
---|
| 568 | return ""; |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | /* functions for getting and setting variable values */ |
---|
| 573 | |
---|
| 574 | /* returns 0 on success, prints a status msg if msg is true */ |
---|
[486688f] | 575 | int owl_variable_set_fromstring(owl_vardict *d, char *name, char *value, int msg, int requirebool) { |
---|
[7d4fbcd] | 576 | owl_variable *v; |
---|
| 577 | char buff2[1024]; |
---|
| 578 | if (!name) return(-1); |
---|
| 579 | v = owl_dict_find_element(d, name); |
---|
| 580 | if (v == NULL) { |
---|
[836ea3a3] | 581 | if (msg) owl_function_error("Unknown variable %s", name); |
---|
[7d4fbcd] | 582 | return -1; |
---|
| 583 | } |
---|
| 584 | if (!v->set_fromstring_fn) { |
---|
[836ea3a3] | 585 | if (msg) owl_function_error("Variable %s is read-only", name); |
---|
[486688f] | 586 | return -1; |
---|
| 587 | } |
---|
| 588 | if (requirebool && v->type!=OWL_VARIABLE_BOOL) { |
---|
[836ea3a3] | 589 | if (msg) owl_function_error("Variable %s is not a boolean", name); |
---|
[486688f] | 590 | return -1; |
---|
[7d4fbcd] | 591 | } |
---|
| 592 | if (0 != v->set_fromstring_fn(v, value)) { |
---|
[836ea3a3] | 593 | if (msg) owl_function_error("Unable to set %s (must be %s)", name, |
---|
[7d4fbcd] | 594 | owl_variable_get_validsettings(v)); |
---|
| 595 | return -1; |
---|
| 596 | } |
---|
| 597 | if (msg && v->get_tostring_fn) { |
---|
| 598 | v->get_tostring_fn(v, buff2, 1024, v->val); |
---|
| 599 | owl_function_makemsg("%s = '%s'", name, buff2); |
---|
| 600 | } |
---|
| 601 | return 0; |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | int owl_variable_set_string(owl_vardict *d, char *name, char *newval) { |
---|
| 605 | owl_variable *v; |
---|
| 606 | if (!name) return(-1); |
---|
| 607 | v = owl_dict_find_element(d, name); |
---|
| 608 | if (v == NULL || !v->set_fn) return(-1); |
---|
| 609 | if (v->type!=OWL_VARIABLE_STRING) return(-1); |
---|
| 610 | return v->set_fn(v, (void*)newval); |
---|
| 611 | } |
---|
| 612 | |
---|
| 613 | int owl_variable_set_int(owl_vardict *d, char *name, int newval) { |
---|
| 614 | owl_variable *v; |
---|
| 615 | if (!name) return(-1); |
---|
| 616 | v = owl_dict_find_element(d, name); |
---|
| 617 | if (v == NULL || !v->set_fn) return(-1); |
---|
| 618 | if (v->type!=OWL_VARIABLE_INT && v->type!=OWL_VARIABLE_BOOL) return(-1); |
---|
| 619 | return v->set_fn(v, &newval); |
---|
| 620 | } |
---|
| 621 | |
---|
| 622 | int owl_variable_set_bool_on(owl_vardict *d, char *name) { |
---|
| 623 | return owl_variable_set_int(d,name,1); |
---|
| 624 | } |
---|
| 625 | |
---|
| 626 | int owl_variable_set_bool_off(owl_vardict *d, char *name) { |
---|
| 627 | return owl_variable_set_int(d,name,0); |
---|
| 628 | } |
---|
| 629 | |
---|
| 630 | int owl_variable_get_tostring(owl_vardict *d, char *name, char *buf, int bufsize) { |
---|
| 631 | owl_variable *v; |
---|
| 632 | if (!name) return(-1); |
---|
| 633 | v = owl_dict_find_element(d, name); |
---|
| 634 | if (v == NULL || !v->get_tostring_fn) return(-1); |
---|
| 635 | return v->get_tostring_fn(v, buf, bufsize, v->val); |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | int owl_variable_get_default_tostring(owl_vardict *d, char *name, char *buf, int bufsize) { |
---|
| 639 | owl_variable *v; |
---|
| 640 | if (!name) return(-1); |
---|
| 641 | v = owl_dict_find_element(d, name); |
---|
| 642 | if (v == NULL || !v->get_tostring_fn) return(-1); |
---|
| 643 | if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { |
---|
| 644 | return v->get_tostring_fn(v, buf, bufsize, &(v->ival_default)); |
---|
| 645 | } else { |
---|
| 646 | return v->get_tostring_fn(v, buf, bufsize, v->pval_default); |
---|
| 647 | } |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | /* returns a reference */ |
---|
| 651 | void *owl_variable_get(owl_vardict *d, char *name, int require_type) { |
---|
| 652 | owl_variable *v; |
---|
| 653 | if (!name) return(NULL); |
---|
| 654 | v = owl_dict_find_element(d, name); |
---|
| 655 | if (v == NULL || !v->get_fn || v->type != require_type) return(NULL); |
---|
| 656 | return v->get_fn(v); |
---|
| 657 | } |
---|
| 658 | |
---|
| 659 | /* returns a reference */ |
---|
| 660 | char *owl_variable_get_string(owl_vardict *d, char *name) { |
---|
| 661 | return (char*)owl_variable_get(d,name, OWL_VARIABLE_STRING); |
---|
| 662 | } |
---|
| 663 | |
---|
| 664 | /* returns a reference */ |
---|
| 665 | void *owl_variable_get_other(owl_vardict *d, char *name) { |
---|
| 666 | return (char*)owl_variable_get(d,name, OWL_VARIABLE_OTHER); |
---|
| 667 | } |
---|
| 668 | |
---|
| 669 | int owl_variable_get_int(owl_vardict *d, char *name) { |
---|
| 670 | int *pi; |
---|
| 671 | pi = (int*)owl_variable_get(d,name,OWL_VARIABLE_INT); |
---|
| 672 | if (!pi) return(-1); |
---|
| 673 | return(*pi); |
---|
| 674 | } |
---|
| 675 | |
---|
| 676 | int owl_variable_get_bool(owl_vardict *d, char *name) { |
---|
| 677 | int *pi; |
---|
| 678 | pi = (int*)owl_variable_get(d,name,OWL_VARIABLE_BOOL); |
---|
| 679 | if (!pi) return(-1); |
---|
| 680 | return(*pi); |
---|
| 681 | } |
---|
| 682 | |
---|
[aa2f33b3] | 683 | void owl_variable_describe(owl_vardict *d, char *name, owl_fmtext *fm) { |
---|
| 684 | char defaultbuf[50]; |
---|
[7d4fbcd] | 685 | char buf[1024]; |
---|
| 686 | int buflen = 1023; |
---|
| 687 | owl_variable *v; |
---|
| 688 | |
---|
| 689 | if (!name |
---|
| 690 | || (v = owl_dict_find_element(d, name)) == NULL |
---|
| 691 | || !v->get_fn) { |
---|
| 692 | snprintf(buf, buflen, " No such variable '%s'\n", name); |
---|
| 693 | owl_fmtext_append_normal(fm, buf); |
---|
| 694 | return; |
---|
| 695 | } |
---|
| 696 | if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { |
---|
[aa2f33b3] | 697 | v->get_tostring_fn(v, defaultbuf, 50, &(v->ival_default)); |
---|
[7d4fbcd] | 698 | } else { |
---|
[aa2f33b3] | 699 | v->get_tostring_fn(v, defaultbuf, 50, v->pval_default); |
---|
[7d4fbcd] | 700 | } |
---|
[aa2f33b3] | 701 | snprintf(buf, buflen, OWL_TABSTR "%-20s - %s (default: '%s')\n", |
---|
[7d4fbcd] | 702 | v->name, |
---|
[aa2f33b3] | 703 | owl_variable_get_summary(v), defaultbuf); |
---|
[7d4fbcd] | 704 | owl_fmtext_append_normal(fm, buf); |
---|
| 705 | } |
---|
| 706 | |
---|
| 707 | void owl_variable_get_help(owl_vardict *d, char *name, owl_fmtext *fm) { |
---|
| 708 | char buff[1024]; |
---|
| 709 | int bufflen = 1023; |
---|
| 710 | owl_variable *v; |
---|
| 711 | |
---|
| 712 | if (!name |
---|
| 713 | || (v = owl_dict_find_element(d, name)) == NULL |
---|
| 714 | || !v->get_fn) { |
---|
| 715 | owl_fmtext_append_normal(fm, "No such variable...\n"); |
---|
| 716 | return; |
---|
| 717 | } |
---|
| 718 | |
---|
| 719 | owl_fmtext_append_bold(fm, "OWL VARIABLE\n\n"); |
---|
| 720 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
| 721 | owl_fmtext_append_normal(fm, name); |
---|
| 722 | owl_fmtext_append_normal(fm, " - "); |
---|
[aa2f33b3] | 723 | owl_fmtext_append_normal(fm, v->summary); |
---|
[7d4fbcd] | 724 | owl_fmtext_append_normal(fm, "\n\n"); |
---|
| 725 | |
---|
| 726 | owl_fmtext_append_normal(fm, "Current: "); |
---|
| 727 | owl_variable_get_tostring(d, name, buff, bufflen); |
---|
| 728 | owl_fmtext_append_normal(fm, buff); |
---|
| 729 | owl_fmtext_append_normal(fm, "\n\n"); |
---|
| 730 | |
---|
| 731 | |
---|
| 732 | if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { |
---|
| 733 | v->get_tostring_fn(v, buff, bufflen, &(v->ival_default)); |
---|
| 734 | } else { |
---|
| 735 | v->get_tostring_fn(v, buff, bufflen, v->pval_default); |
---|
| 736 | } |
---|
| 737 | owl_fmtext_append_normal(fm, "Default: "); |
---|
| 738 | owl_fmtext_append_normal(fm, buff); |
---|
| 739 | owl_fmtext_append_normal(fm, "\n\n"); |
---|
| 740 | |
---|
| 741 | owl_fmtext_append_normal(fm, "Valid Settings: "); |
---|
| 742 | owl_fmtext_append_normal(fm, owl_variable_get_validsettings(v)); |
---|
| 743 | owl_fmtext_append_normal(fm, "\n\n"); |
---|
[aa2f33b3] | 744 | |
---|
| 745 | if (v->description && *v->description) { |
---|
| 746 | owl_fmtext_append_normal(fm, "Description:\n"); |
---|
| 747 | owl_fmtext_append_normal(fm, owl_variable_get_description(v)); |
---|
| 748 | owl_fmtext_append_normal(fm, "\n\n"); |
---|
| 749 | } |
---|
[7d4fbcd] | 750 | } |
---|
| 751 | |
---|
| 752 | |
---|
| 753 | |
---|
| 754 | |
---|
| 755 | /**************************************************************************/ |
---|
| 756 | /*********************** GENERAL TYPE-SPECIFIC ****************************/ |
---|
| 757 | /**************************************************************************/ |
---|
| 758 | |
---|
| 759 | /* default common functions */ |
---|
| 760 | |
---|
| 761 | void *owl_variable_get_default(owl_variable *v) { |
---|
| 762 | return v->val; |
---|
| 763 | } |
---|
| 764 | |
---|
| 765 | void owl_variable_free_default(owl_variable *v) { |
---|
| 766 | if (v->val) owl_free(v->val); |
---|
| 767 | } |
---|
| 768 | |
---|
| 769 | /* default functions for booleans */ |
---|
| 770 | |
---|
| 771 | int owl_variable_bool_validate_default(owl_variable *v, void *newval) { |
---|
| 772 | if (newval == NULL) return(0); |
---|
| 773 | else if (*(int*)newval==1 || *(int*)newval==0) return(1); |
---|
| 774 | else return (0); |
---|
| 775 | } |
---|
| 776 | |
---|
| 777 | int owl_variable_bool_set_default(owl_variable *v, void *newval) { |
---|
| 778 | if (v->validate_fn) { |
---|
| 779 | if (!v->validate_fn(v, newval)) return(-1); |
---|
| 780 | } |
---|
| 781 | *(int*)v->val = *(int*)newval; |
---|
| 782 | return(0); |
---|
| 783 | } |
---|
| 784 | |
---|
| 785 | int owl_variable_bool_set_fromstring_default(owl_variable *v, char *newval) { |
---|
| 786 | int i; |
---|
| 787 | if (!strcmp(newval, "on")) i=1; |
---|
| 788 | else if (!strcmp(newval, "off")) i=0; |
---|
| 789 | else return(-1); |
---|
| 790 | return (v->set_fn(v, &i)); |
---|
| 791 | } |
---|
| 792 | |
---|
| 793 | int owl_variable_bool_get_tostring_default(owl_variable *v, char* buf, int bufsize, void *val) { |
---|
| 794 | if (val == NULL) { |
---|
| 795 | snprintf(buf, bufsize, "<null>"); |
---|
| 796 | return -1; |
---|
| 797 | } else if (*(int*)val == 0) { |
---|
| 798 | snprintf(buf, bufsize, "off"); |
---|
| 799 | return 0; |
---|
| 800 | } else if (*(int*)val == 1) { |
---|
| 801 | snprintf(buf, bufsize, "on"); |
---|
| 802 | return 0; |
---|
| 803 | } else { |
---|
| 804 | snprintf(buf, bufsize, "<invalid>"); |
---|
| 805 | return -1; |
---|
| 806 | } |
---|
| 807 | } |
---|
| 808 | |
---|
| 809 | /* default functions for integers */ |
---|
| 810 | |
---|
| 811 | int owl_variable_int_validate_default(owl_variable *v, void *newval) { |
---|
| 812 | if (newval == NULL) return(0); |
---|
| 813 | else return (1); |
---|
| 814 | } |
---|
| 815 | |
---|
| 816 | int owl_variable_int_set_default(owl_variable *v, void *newval) { |
---|
| 817 | if (v->validate_fn) { |
---|
| 818 | if (!v->validate_fn(v, newval)) return(-1); |
---|
| 819 | } |
---|
| 820 | *(int*)v->val = *(int*)newval; |
---|
| 821 | return(0); |
---|
| 822 | } |
---|
| 823 | |
---|
| 824 | int owl_variable_int_set_fromstring_default(owl_variable *v, char *newval) { |
---|
| 825 | int i; |
---|
| 826 | char *ep = "x"; |
---|
| 827 | i = strtol(newval, &ep, 10); |
---|
| 828 | if (*ep || ep==newval) return(-1); |
---|
| 829 | return (v->set_fn(v, &i)); |
---|
| 830 | } |
---|
| 831 | |
---|
| 832 | int owl_variable_int_get_tostring_default(owl_variable *v, char* buf, int bufsize, void *val) { |
---|
| 833 | if (val == NULL) { |
---|
| 834 | snprintf(buf, bufsize, "<null>"); |
---|
| 835 | return -1; |
---|
| 836 | } else { |
---|
| 837 | snprintf(buf, bufsize, "%d", *(int*)val); |
---|
| 838 | return 0; |
---|
| 839 | } |
---|
| 840 | } |
---|
| 841 | |
---|
| 842 | /* default functions for enums (a variant of integers) */ |
---|
| 843 | |
---|
| 844 | int owl_variable_enum_validate(owl_variable *v, void *newval) { |
---|
| 845 | char **enums; |
---|
| 846 | int nenums, val; |
---|
| 847 | if (newval == NULL) return(0); |
---|
| 848 | enums = atokenize(v->validsettings, ",", &nenums); |
---|
| 849 | if (enums == NULL) return(0); |
---|
| 850 | atokenize_free(enums, nenums); |
---|
| 851 | val = *(int*)newval; |
---|
| 852 | if (val < 0 || val >= nenums) { |
---|
| 853 | return(0); |
---|
| 854 | } |
---|
| 855 | return(1); |
---|
| 856 | } |
---|
| 857 | |
---|
| 858 | int owl_variable_enum_set_fromstring(owl_variable *v, char *newval) { |
---|
| 859 | char **enums; |
---|
| 860 | int nenums, i, val=-1; |
---|
| 861 | if (newval == NULL) return(-1); |
---|
| 862 | enums = atokenize(v->validsettings, ",", &nenums); |
---|
| 863 | if (enums == NULL) return(-1); |
---|
| 864 | for (i=0; i<nenums; i++) { |
---|
| 865 | if (0==strcmp(newval, enums[i])) { |
---|
| 866 | val = i; |
---|
| 867 | } |
---|
| 868 | } |
---|
| 869 | atokenize_free(enums, nenums); |
---|
| 870 | if (val == -1) return(-1); |
---|
| 871 | return (v->set_fn(v, &val)); |
---|
| 872 | } |
---|
| 873 | |
---|
| 874 | int owl_variable_enum_get_tostring(owl_variable *v, char* buf, int bufsize, void *val) { |
---|
| 875 | char **enums; |
---|
| 876 | int nenums, i; |
---|
| 877 | |
---|
| 878 | if (val == NULL) { |
---|
| 879 | snprintf(buf, bufsize, "<null>"); |
---|
| 880 | return -1; |
---|
| 881 | } |
---|
| 882 | enums = atokenize(v->validsettings, ",", &nenums); |
---|
| 883 | i = *(int*)val; |
---|
| 884 | if (i<0 || i>=nenums) { |
---|
| 885 | snprintf(buf, bufsize, "<invalid:%d>",i); |
---|
| 886 | atokenize_free(enums, nenums); |
---|
| 887 | return(-1); |
---|
| 888 | } |
---|
| 889 | snprintf(buf, bufsize, "%s", enums[i]); |
---|
| 890 | return 0; |
---|
| 891 | } |
---|
| 892 | |
---|
| 893 | /* default functions for stringeans */ |
---|
| 894 | |
---|
| 895 | int owl_variable_string_validate_default(struct _owl_variable *v, void *newval) { |
---|
| 896 | if (newval == NULL) return(0); |
---|
| 897 | else return (1); |
---|
| 898 | } |
---|
| 899 | |
---|
| 900 | int owl_variable_string_set_default(owl_variable *v, void *newval) { |
---|
| 901 | if (v->validate_fn) { |
---|
| 902 | if (!v->validate_fn(v, newval)) return(-1); |
---|
| 903 | } |
---|
| 904 | if (v->val) owl_free(v->val); |
---|
| 905 | v->val = owl_strdup(newval); |
---|
| 906 | return(0); |
---|
| 907 | } |
---|
| 908 | |
---|
| 909 | int owl_variable_string_set_fromstring_default(owl_variable *v, char *newval) { |
---|
| 910 | return (v->set_fn(v, newval)); |
---|
| 911 | } |
---|
| 912 | |
---|
| 913 | int owl_variable_string_get_tostring_default(owl_variable *v, char* buf, int bufsize, void *val) { |
---|
| 914 | if (val == NULL) { |
---|
| 915 | snprintf(buf, bufsize, "<null>"); |
---|
| 916 | return -1; |
---|
| 917 | } else { |
---|
| 918 | snprintf(buf, bufsize, "%s", (char*)val); |
---|
| 919 | return 0; |
---|
| 920 | } |
---|
| 921 | } |
---|
| 922 | |
---|
| 923 | |
---|
| 924 | |
---|
| 925 | /**************************************************************************/ |
---|
| 926 | /************************* REGRESSION TESTS *******************************/ |
---|
| 927 | /**************************************************************************/ |
---|
| 928 | |
---|
| 929 | #ifdef OWL_INCLUDE_REG_TESTS |
---|
| 930 | |
---|
| 931 | #define FAIL_UNLESS(desc,pred) printf("\t%-4s: %s\n", (pred)?"ok":(numfailed++,"FAIL"), desc) |
---|
| 932 | |
---|
| 933 | int owl_variable_regtest(void) { |
---|
| 934 | owl_vardict vd; |
---|
| 935 | int numfailed=0; |
---|
| 936 | char buf[1024]; |
---|
| 937 | |
---|
[e1c4636] | 938 | in_regtest = 1; |
---|
| 939 | |
---|
[7d4fbcd] | 940 | printf("BEGIN testing owl_variable\n"); |
---|
| 941 | FAIL_UNLESS("setup", 0==owl_variable_dict_setup(&vd)); |
---|
| 942 | |
---|
| 943 | FAIL_UNLESS("get bool", 0==owl_variable_get_bool(&vd,"personalbell")); |
---|
| 944 | FAIL_UNLESS("get bool (no such)", -1==owl_variable_get_bool(&vd,"mumble")); |
---|
| 945 | FAIL_UNLESS("get bool as string 1", 0==owl_variable_get_tostring(&vd,"personalbell", buf, 1024)); |
---|
| 946 | FAIL_UNLESS("get bool as string 2", 0==strcmp(buf,"off")); |
---|
| 947 | FAIL_UNLESS("set bool 1", 0==owl_variable_set_bool_on(&vd,"personalbell")); |
---|
| 948 | FAIL_UNLESS("get bool 2", 1==owl_variable_get_bool(&vd,"personalbell")); |
---|
[486688f] | 949 | FAIL_UNLESS("set bool 3", 0==owl_variable_set_fromstring(&vd,"personalbell","off",0,0)); |
---|
[7d4fbcd] | 950 | FAIL_UNLESS("get bool 4", 0==owl_variable_get_bool(&vd,"personalbell")); |
---|
[486688f] | 951 | FAIL_UNLESS("set bool 5", -1==owl_variable_set_fromstring(&vd,"personalbell","xxx",0,0)); |
---|
[7d4fbcd] | 952 | FAIL_UNLESS("get bool 6", 0==owl_variable_get_bool(&vd,"personalbell")); |
---|
| 953 | |
---|
| 954 | |
---|
| 955 | FAIL_UNLESS("get string", 0==strcmp("~/zlog/people", owl_variable_get_string(&vd,"logpath"))); |
---|
| 956 | FAIL_UNLESS("set string 7", 0==owl_variable_set_string(&vd,"logpath","whee")); |
---|
| 957 | FAIL_UNLESS("get string", 0==strcmp("whee", owl_variable_get_string(&vd,"logpath"))); |
---|
| 958 | |
---|
| 959 | FAIL_UNLESS("get int", 8==owl_variable_get_int(&vd,"typewinsize")); |
---|
| 960 | FAIL_UNLESS("get int (no such)", -1==owl_variable_get_int(&vd,"mmble")); |
---|
| 961 | FAIL_UNLESS("get int as string 1", 0==owl_variable_get_tostring(&vd,"typewinsize", buf, 1024)); |
---|
| 962 | FAIL_UNLESS("get int as string 2", 0==strcmp(buf,"8")); |
---|
| 963 | FAIL_UNLESS("set int 1", 0==owl_variable_set_int(&vd,"typewinsize",12)); |
---|
| 964 | FAIL_UNLESS("get int 2", 12==owl_variable_get_int(&vd,"typewinsize")); |
---|
| 965 | FAIL_UNLESS("set int 1b", -1==owl_variable_set_int(&vd,"typewinsize",-3)); |
---|
| 966 | FAIL_UNLESS("get int 2b", 12==owl_variable_get_int(&vd,"typewinsize")); |
---|
[486688f] | 967 | FAIL_UNLESS("set int 3", 0==owl_variable_set_fromstring(&vd,"typewinsize","9",0,0)); |
---|
[7d4fbcd] | 968 | FAIL_UNLESS("get int 4", 9==owl_variable_get_int(&vd,"typewinsize")); |
---|
[486688f] | 969 | FAIL_UNLESS("set int 5", -1==owl_variable_set_fromstring(&vd,"typewinsize","xxx",0,0)); |
---|
| 970 | FAIL_UNLESS("set int 6", -1==owl_variable_set_fromstring(&vd,"typewinsize","",0,0)); |
---|
[7d4fbcd] | 971 | FAIL_UNLESS("get int 7", 9==owl_variable_get_int(&vd,"typewinsize")); |
---|
| 972 | |
---|
| 973 | |
---|
| 974 | |
---|
| 975 | owl_variable_dict_free(&vd); |
---|
| 976 | |
---|
| 977 | if (numfailed) printf("*** WARNING: failures encountered with owl_variable\n"); |
---|
| 978 | printf("END testing owl_variable (%d failures)\n", numfailed); |
---|
| 979 | return(numfailed); |
---|
| 980 | } |
---|
| 981 | |
---|
| 982 | |
---|
| 983 | #endif /* OWL_INCLUDE_REG_TESTS */ |
---|