Changeset 4584d1f
- Timestamp:
- Feb 21, 2013, 4:42:20 PM (12 years ago)
- Branches:
- master, release-1.10
- Children:
- 1a4508b
- Parents:
- 3b9ca71
- git-author:
- David Benjamin <davidben@mit.edu> (06/10/12 15:04:10)
- git-committer:
- David Benjamin <davidben@mit.edu> (02/21/13 16:42:20)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
owl.h
r3b9ca71 r4584d1f 266 266 * returns 0 on success. */ 267 267 } owl_variable; 268 269 typedef struct _owl_variable_init_params {270 const char *name;271 int type; /* OWL_VARIABLE_* */272 const char *pval_default; /* for string */273 int ival_default; /* for types int and bool */274 const char *validsettings; /* documentation of valid settings */275 const char *summary; /* summary of usage */276 const char *description; /* detailed description */277 void *val; /* current value */278 GCallback validate_fn;279 /* returns 1 if newval is valid */280 GCallback set_fn;281 /* sets the variable to a value282 * of the appropriate type.283 * unless documented, this284 * should make a copy.285 * returns 0 on success. */286 GCallback set_fromstring_fn;287 /* sets the variable to a value288 * of the appropriate type.289 * unless documented, this290 * should make a copy.291 * returns 0 on success. */292 GCallback get_fn;293 /* returns a reference to the current value.294 * WARNING: this approach is hard to make295 * thread-safe... */296 GCallback get_tostring_fn;297 /* converts val to a string;298 * caller must free the result */299 } owl_variable_init_params;300 268 301 269 -
variable.c
r3b9ca71 r4584d1f 10 10 typedef const char *(*get_string_t)(const owl_variable *); 11 11 typedef int (*get_int_t)(const owl_variable *); 12 typedef gboolean(*get_bool_t)(const owl_variable *);12 typedef bool (*get_bool_t)(const owl_variable *); 13 13 14 14 typedef int (*set_string_t)(owl_variable *, const char *); 15 15 typedef int (*set_int_t)(owl_variable *, int); 16 typedef int (*set_bool_t)(owl_variable *, gboolean); 17 18 typedef int (*validate_string_t)(owl_variable *, const char *); 19 typedef int (*validate_int_t)(owl_variable *, int); 20 typedef int (*validate_bool_t)(owl_variable *, gboolean); 21 22 #define OWLVAR_BOOL(name,default,summary,description) \ 23 { name, OWL_VARIABLE_BOOL, NULL, default, "on,off", summary, description, NULL, \ 24 NULL, NULL, NULL, NULL, NULL } 25 26 #define OWLVAR_BOOL_FULL(name,default,summary,description,validate,set,get) \ 27 { name, OWL_VARIABLE_BOOL, NULL, default, "on,off", summary, description, NULL, \ 28 G_CALLBACK(validate), G_CALLBACK(set), NULL, G_CALLBACK(get), NULL } 29 30 #define OWLVAR_INT(name,default,summary,description) \ 31 { name, OWL_VARIABLE_INT, NULL, default, "<int>", summary, description, NULL, \ 32 NULL, NULL, NULL, NULL, NULL } 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) 33 70 34 71 #define OWLVAR_INT_FULL(name,default,summary,description,validset,validate,set,get) \ 35 { name, OWL_VARIABLE_INT, NULL, default, validset, summary, description, NULL, \ 36 G_CALLBACK(validate), G_CALLBACK(set), NULL, G_CALLBACK(get), NULL } 37 38 #define OWLVAR_PATH(name,default,summary,description) \ 39 { name, OWL_VARIABLE_STRING, default, 0, "<path>", summary, description, NULL, \ 40 NULL, NULL, NULL, NULL, NULL } 41 42 #define OWLVAR_STRING(name,default,summary,description) \ 43 { name, OWL_VARIABLE_STRING, default, 0, "<string>", summary, description, NULL, \ 44 NULL, NULL, NULL, NULL, NULL } 45 46 #define OWLVAR_STRING_FULL(name,default,validset,summary,description,validate,set,get) \ 47 { name, OWL_VARIABLE_STRING, default, 0, validset, summary, description, NULL, \ 48 G_CALLBACK(validate), G_CALLBACK(set), NULL, G_CALLBACK(get), NULL } 72 owl_variable_dict_newvar_int_full(vd, name, default, summary, description, \ 73 validset, validate, set, get) 74 75 #define OWLVAR_PATH(name, default, summary, description) \ 76 owl_variable_dict_newvar_path(vd, name, default, summary, description) 77 78 #define OWLVAR_STRING(name, default, summary, description) \ 79 owl_variable_dict_newvar_string(vd, name, default, summary, description) 80 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) 49 84 50 85 /* enums are really integers, but where validset is a comma-separated 51 86 * list of strings which can be specified. The tokens, starting at 0, 52 87 * correspond to the values that may be specified. */ 53 #define OWLVAR_ENUM(name,default,summary,description,validset) \ 54 { name, OWL_VARIABLE_INT, NULL, default, validset, summary, description, NULL, \ 55 G_CALLBACK(owl_variable_enum_validate), \ 56 NULL, G_CALLBACK(owl_variable_enum_set_fromstring), \ 57 NULL, G_CALLBACK(owl_variable_enum_get_tostring), \ 58 } 88 #define OWLVAR_ENUM(name, default, summary, description, validset) \ 89 owl_variable_dict_newvar_enum(vd, name, default, summary, description, validset) 59 90 60 91 #define OWLVAR_ENUM_FULL(name,default,summary,description,validset,validate, set, get) \ 61 { name, OWL_VARIABLE_INT, NULL, default, validset, summary, description, NULL, \ 62 G_CALLBACK(validate), \ 63 G_CALLBACK(set), G_CALLBACK(owl_variable_enum_set_fromstring), \ 64 G_CALLBACK(get), G_CALLBACK(owl_variable_enum_get_tostring), \ 65 } 92 owl_variable_dict_newvar_enum_full(vd, name, default, summary, description, \ 93 validset, validate, set, get) 66 94 67 95 int owl_variable_add_defaults(owl_vardict *vd) 68 96 { 69 owl_variable_init_params variables_to_init[] = {70 71 97 OWLVAR_STRING( "personalbell" /* %OwlVarStub */, "off", 72 98 "ring the terminal bell when personal messages are received", 73 99 "Can be set to 'on', 'off', or the name of a filter which\n" 74 "messages need to match in order to ring the bell") ,100 "messages need to match in order to ring the bell"); 75 101 76 102 OWLVAR_BOOL( "bell" /* %OwlVarStub */, 1, 77 "enable / disable the terminal bell", "" ) ,103 "enable / disable the terminal bell", "" ); 78 104 79 105 OWLVAR_BOOL_FULL( "debug" /* %OwlVarStub */, OWL_DEBUG, … … 81 107 "If set to 'on', debugging messages are logged to the\n" 82 108 "file specified by the debugfile variable.\n", 83 NULL, owl_variable_debug_set, NULL) ,109 NULL, owl_variable_debug_set, NULL); 84 110 85 111 OWLVAR_BOOL( "startuplogin" /* %OwlVarStub */, 1, 86 "send a login message when BarnOwl starts", "" ) ,112 "send a login message when BarnOwl starts", "" ); 87 113 88 114 OWLVAR_BOOL( "shutdownlogout" /* %OwlVarStub */, 1, 89 "send a logout message when BarnOwl exits", "" ) ,115 "send a logout message when BarnOwl exits", "" ); 90 116 91 117 OWLVAR_BOOL( "rxping" /* %OwlVarStub */, 0, 92 "display received pings", "" ) ,118 "display received pings", "" ); 93 119 94 120 OWLVAR_BOOL( "txping" /* %OwlVarStub */, 1, 95 "send pings", "" ) ,121 "send pings", "" ); 96 122 97 123 OWLVAR_BOOL( "sepbar_disable" /* %OwlVarStub */, 0, 98 "disable printing information in the separator bar", "" ) ,124 "disable printing information in the separator bar", "" ); 99 125 100 126 OWLVAR_BOOL( "smartstrip" /* %OwlVarStub */, 1, 101 "strip kerberos instance for reply", "") ,127 "strip kerberos instance for reply", ""); 102 128 103 129 OWLVAR_BOOL( "newlinestrip" /* %OwlVarStub */, 1, 104 "strip leading and trailing newlines", "") ,130 "strip leading and trailing newlines", ""); 105 131 106 132 OWLVAR_BOOL( "displayoutgoing" /* %OwlVarStub */, 1, 107 "display outgoing messages", "" ) ,133 "display outgoing messages", "" ); 108 134 109 135 OWLVAR_BOOL( "loginsubs" /* %OwlVarStub */, 1, 110 "load logins from .anyone on startup", "" ) ,136 "load logins from .anyone on startup", "" ); 111 137 112 138 OWLVAR_BOOL( "logging" /* %OwlVarStub */, 0, … … 115 141 "logged in the directory specified\n" 116 142 "by the 'logpath' variable. The filename in that\n" 117 "directory is derived from the sender of the message.\n" ) ,143 "directory is derived from the sender of the message.\n" ); 118 144 119 145 OWLVAR_BOOL( "classlogging" /* %OwlVarStub */, 0, … … 123 149 "by the 'classlogpath' variable.\n" 124 150 "The filename in that directory is derived from\n" 125 "the name of the class to which the message was sent.\n" ) ,151 "the name of the class to which the message was sent.\n" ); 126 152 127 153 OWLVAR_ENUM( "loggingdirection" /* %OwlVarStub */, OWL_LOGGING_DIRECTION_BOTH, … … 132 158 "is selected both incoming and outgoing messages are\n" 133 159 "logged.", 134 "both,in,out") ,160 "both,in,out"); 135 161 136 162 OWLVAR_BOOL_FULL( "colorztext" /* %OwlVarStub */, 1, 137 163 "allow @color() in zephyrs to change color", 138 NULL, NULL, owl_variable_colorztext_set, NULL) ,164 NULL, NULL, owl_variable_colorztext_set, NULL); 139 165 140 166 OWLVAR_BOOL( "fancylines" /* %OwlVarStub */, 1, … … 142 168 "If turned off, dashes, pipes and pluses will be used\n" 143 169 "to draw lines on the screen. Useful when the terminal\n" 144 "is causing problems" ) ,170 "is causing problems" ); 145 171 146 172 OWLVAR_BOOL( "zcrypt" /* %OwlVarStub */, 1, 147 173 "Do automatic zcrypt processing", 148 "" ) ,174 "" ); 149 175 150 176 OWLVAR_BOOL_FULL( "pseudologins" /* %OwlVarStub */, 0, … … 154 180 "but sent no login message, or a user is not present that sent no\n" 155 181 "logout message, a pseudo login or logout message will be created\n", 156 NULL, owl_variable_pseudologins_set, NULL) ,182 NULL, owl_variable_pseudologins_set, NULL); 157 183 158 184 OWLVAR_BOOL( "ignorelogins" /* %OwlVarStub */, 0, … … 160 186 "When this is enabled, BarnOwl will print login and logout notifications\n" 161 187 "for AIM, zephyr, or other protocols. If disabled BarnOwl will not print\n" 162 "login or logout notifications.\n") ,188 "login or logout notifications.\n"); 163 189 164 190 OWLVAR_STRING( "logfilter" /* %OwlVarStub */, "", … … 169 195 "variables like logging, classlogging, loglogins, loggingdirection,\n" 170 196 "etc. If you want this variable to control all logging, make sure\n" 171 "all other logging variables are in their default state.\n") ,197 "all other logging variables are in their default state.\n"); 172 198 173 199 OWLVAR_BOOL( "loglogins" /* %OwlVarStub */, 0, … … 175 201 "When this is enabled, BarnOwl will log login and logout notifications\n" 176 202 "for AIM, zephyr, or other protocols. If disabled BarnOwl will not print\n" 177 "login or logout notifications.\n") ,203 "login or logout notifications.\n"); 178 204 179 205 OWLVAR_ENUM_FULL( "disable-ctrl-d" /* %OwlVarStub:lockout_ctrld */, 1, … … 187 213 "in the editmulti keymap.\n", 188 214 "off,middle,on", 189 NULL, owl_variable_disable_ctrl_d_set, NULL) ,215 NULL, owl_variable_disable_ctrl_d_set, NULL); 190 216 191 217 OWLVAR_PATH( "logpath" /* %OwlVarStub */, "~/zlog/people", 192 218 "path for logging personal zephyrs", 193 219 "Specifies a directory which must exist.\n" 194 "Files will be created in the directory for each sender.\n") ,220 "Files will be created in the directory for each sender.\n"); 195 221 196 222 OWLVAR_PATH( "classlogpath" /* %OwlVarStub:classlogpath */, "~/zlog/class", 197 223 "path for logging class zephyrs", 198 224 "Specifies a directory which must exist.\n" 199 "Files will be created in the directory for each class.\n") ,225 "Files will be created in the directory for each class.\n"); 200 226 201 227 OWLVAR_PATH( "debug_file" /* %OwlVarStub */, OWL_DEBUG_FILE, 202 228 "path for logging debug messages when debugging is enabled", 203 229 "This file will be logged to if 'debug' is set to 'on'.\n" 204 "BarnOwl will append a dot and the current process's pid to the filename.") ,230 "BarnOwl will append a dot and the current process's pid to the filename."); 205 231 206 232 OWLVAR_PATH( "zsigproc" /* %OwlVarStub:zsigproc */, NULL, … … 210 236 "See the documentation for 'zsig' for more information about\n" 211 237 "how the outgoing zsig is chosen." 212 ) ,238 ); 213 239 214 240 OWLVAR_PATH( "newmsgproc" /* %OwlVarStub:newmsgproc */, NULL, … … 216 242 "The named program will be run when BarnOwl receives new\n" 217 243 "messages. It will not be run again until the first\n" 218 "instance exits") ,244 "instance exits"); 219 245 220 246 OWLVAR_STRING( "zsender" /* %OwlVarStub */, "", … … 223 249 "zephyrs. If this is unset, it will use your Kerberos\n" 224 250 "principal. Note that customizing the sender name will\n" 225 "cause your zephyrs to be sent unauthenticated.") ,251 "cause your zephyrs to be sent unauthenticated."); 226 252 227 253 OWLVAR_STRING( "zsigfunc" /* %OwlVarStub */, "BarnOwl::default_zephyr_signature()", … … 230 256 "explicit zsig. The default setting implements the policy\n" 231 257 "described in the documentation for the 'zsig' variable.\n" 232 "See also BarnOwl::random_zephyr_signature().\n") ,258 "See also BarnOwl::random_zephyr_signature().\n"); 233 259 234 260 OWLVAR_STRING( "zsig" /* %OwlVarStub */, "", … … 237 263 "unset, 'zsigproc' will be run to generate a zsig. If that is\n" 238 264 "also unset, the 'zwrite-signature' zephyr variable will be\n" 239 "used instead.\n") ,265 "used instead.\n"); 240 266 241 267 OWLVAR_STRING( "appendtosepbar" /* %OwlVarStub */, "", … … 243 269 "The sepbar is the bar separating the top and bottom\n" 244 270 "of the BarnOwl screen. Any string specified here will\n" 245 "be displayed on the right of the sepbar\n") ,271 "be displayed on the right of the sepbar\n"); 246 272 247 273 OWLVAR_BOOL( "zaway" /* %OwlVarStub */, 0, 248 "turn zaway on or off", "" ) ,274 "turn zaway on or off", "" ); 249 275 250 276 OWLVAR_STRING( "zaway_msg" /* %OwlVarStub */, 251 277 OWL_DEFAULT_ZAWAYMSG, 252 "zaway msg for responding to zephyrs when away", "" ) ,278 "zaway msg for responding to zephyrs when away", "" ); 253 279 254 280 OWLVAR_STRING( "zaway_msg_default" /* %OwlVarStub */, 255 281 OWL_DEFAULT_ZAWAYMSG, 256 "default zaway message", "" ) ,282 "default zaway message", "" ); 257 283 258 284 OWLVAR_BOOL_FULL( "aaway" /* %OwlVarStub */, 0, 259 285 "Set AIM away status", 260 286 "", 261 NULL, owl_variable_aaway_set, NULL) ,287 NULL, owl_variable_aaway_set, NULL); 262 288 263 289 OWLVAR_STRING( "aaway_msg" /* %OwlVarStub */, 264 290 OWL_DEFAULT_AAWAYMSG, 265 "AIM away msg for responding when away", "" ) ,291 "AIM away msg for responding when away", "" ); 266 292 267 293 OWLVAR_STRING( "aaway_msg_default" /* %OwlVarStub */, 268 294 OWL_DEFAULT_AAWAYMSG, 269 "default AIM away message", "" ) ,295 "default AIM away message", "" ); 270 296 271 297 OWLVAR_STRING( "view_home" /* %OwlVarStub */, "all", 272 298 "home view to switch to after 'X' and 'V'", 273 "SEE ALSO: view, filter\n" ) ,299 "SEE ALSO: view, filter\n" ); 274 300 275 301 OWLVAR_STRING( "alert_filter" /* %OwlVarStub */, "none", 276 302 "filter on which to trigger alert actions", 277 "" ) ,303 "" ); 278 304 279 305 OWLVAR_STRING( "alert_action" /* %OwlVarStub */, "nop", 280 306 "BarnOwl command to execute for alert actions", 281 "" ) ,307 "" ); 282 308 283 309 OWLVAR_STRING_FULL( "tty" /* %OwlVarStub */, "", "<string>", "tty name for zephyr location", "", 284 NULL, owl_variable_tty_set, NULL) ,310 NULL, owl_variable_tty_set, NULL); 285 311 286 312 OWLVAR_STRING( "default_style" /* %OwlVarStub */, "default", … … 293 319 " perl - legacy perl interface\n" 294 320 "\nSEE ALSO: style, show styles, view -s <style>\n" 295 ) ,321 ); 296 322 297 323 … … 300 326 "This specifies the maximum number of columns for M-q to fill text\n" 301 327 "to. If set to 0, M-q will wrap to the width of the window, and\n" 302 "values less than 0 disable M-q entirely.\n") ,328 "values less than 0 disable M-q entirely.\n"); 303 329 304 330 OWLVAR_INT( "edit:maxwrapcols" /* %OwlVarStub:edit_maxwrapcols */, 70, … … 309 335 "\n" 310 336 "As a courtesy to recipients, it is recommended that outgoing\n" 311 "Zephyr messages be no wider than 70 columns.\n") ,337 "Zephyr messages be no wider than 70 columns.\n"); 312 338 313 339 OWLVAR_INT( "aim_ignorelogin_timer" /* %OwlVarStub */, 15, … … 316 342 "AIM login before allowing the receipt of AIM login notifications.\n" 317 343 "By default this is set to 15. If you would like to view login\n" 318 "notifications of buddies as soon as you login, set it to 0 instead.") ,344 "notifications of buddies as soon as you login, set it to 0 instead."); 319 345 320 346 … … 329 355 owl_variable_typewinsize_set, 330 356 NULL /* use default for get */ 331 ) ,357 ); 332 358 333 359 OWLVAR_INT( "typewindelta" /* %OwlVarStub */, 0, … … 339 365 "typewinsize to 1.\n\n" 340 366 "This works a lot better with a non-default scrollmode;\n" 341 "try :set scrollmode pagedcenter.\n") ,367 "try :set scrollmode pagedcenter.\n"); 342 368 343 369 OWLVAR_ENUM( "scrollmode" /* %OwlVarStub */, OWL_SCROLLMODE_NORMAL, … … 368 394 " the screen will be paged up or down and\n" 369 395 " the cursor will be near the center.\n", 370 "normal,top,neartop,center,paged,pagedcenter" ) ,396 "normal,top,neartop,center,paged,pagedcenter" ); 371 397 372 398 OWLVAR_BOOL( "narrow-related" /* %OwlVarStub:narrow_related */, 1, … … 376 402 "for Zephyr, this controls whether to narrow to e.g. class-help or\n" 377 403 "class-help.d alone, or to related-class-help, which includes\n" 378 "help, unhelp, help.d, etc.\n\nDefault is true (include unclasses, etc.).\n" ) ,404 "help, unhelp, help.d, etc.\n\nDefault is true (include unclasses, etc.).\n" ); 379 405 380 406 OWLVAR_BOOL( "_followlast" /* %OwlVarStub */, 0, … … 383 409 "continue to follow the last message if this is set.\n" 384 410 "Note that this is currently risky as you might accidentally\n" 385 "delete a message right as it came in.\n" ) ,411 "delete a message right as it came in.\n" ); 386 412 387 413 OWLVAR_STRING_FULL( "default_exposure" /* %OwlVarStub */, "", … … 392 418 "~/.zephyr.vars.\n" 393 419 "See the description of exposure for the values this can be.", 394 NULL, owl_variable_default_exposure_set, owl_variable_default_exposure_get ) ,420 NULL, owl_variable_default_exposure_set, owl_variable_default_exposure_get ); 395 421 396 422 OWLVAR_STRING_FULL( "exposure" /* %OwlVarStub */, "", … … 448 474 " personal subscriptions will be entered for the\n" 449 475 " user.\n", 450 NULL, owl_variable_exposure_set, NULL /* use default for get */ ), 451 452 /* This MUST be last... */ 453 { NULL, 0, NULL, 0, NULL, NULL, NULL, NULL, 454 NULL, NULL, NULL, NULL, NULL } 455 456 }; 457 458 return owl_variable_dict_add_from_list(vd, variables_to_init); 476 NULL, owl_variable_exposure_set, NULL /* use default for get */ ); 477 return 0; 459 478 } 460 479 … … 486 505 487 506 /* debug (cache value in g->debug) */ 488 int owl_variable_debug_set(owl_variable *v, int newval) 489 { 490 if (newval == 1 || newval == 0) { 491 g.debug = newval; 492 } 507 int owl_variable_debug_set(owl_variable *v, bool newval) 508 { 509 g.debug = newval; 493 510 return owl_variable_bool_set_default(v, newval); 494 511 } 495 512 496 513 /* When 'aaway' is changed, need to notify the AIM server */ 497 int owl_variable_aaway_set(owl_variable *v, gbooleannewval)498 { 499 if (newval == 1) {514 int owl_variable_aaway_set(owl_variable *v, bool newval) 515 { 516 if (newval) { 500 517 owl_aim_set_awaymsg(owl_global_get_aaway_msg(&g)); 501 } else if (newval == 0){518 } else { 502 519 owl_aim_set_awaymsg(""); 503 520 } … … 505 522 } 506 523 507 int owl_variable_colorztext_set(owl_variable *v, const void *newval)524 int owl_variable_colorztext_set(owl_variable *v, bool newval) 508 525 { 509 526 int ret = owl_variable_bool_set_default(v, newval); … … 518 535 } 519 536 520 int owl_variable_pseudologins_set(owl_variable *v, intnewval)537 int owl_variable_pseudologins_set(owl_variable *v, bool newval) 521 538 { 522 539 static guint timer = 0; 523 if (newval == 1) {540 if (newval) { 524 541 owl_function_zephyr_buddy_check(0); 525 542 if (timer == 0) { … … 594 611 } 595 612 596 #define OWL_VARIABLE_SETUP_FUNC(variable, initializer, func_name, default_func, marshal_func, temp) do { \597 if(initializer->func_name) { \598 temp = initializer->func_name; \599 } else { \600 temp = default_func; \601 } \602 variable->func_name = owl_variable_make_closure(variable, G_CALLBACK(temp), \603 marshal_func); \604 } while(0)605 606 #define DEFAULT_CB(a, b) (a ? a : G_CALLBACK(b))607 608 #define SET_CBS(type) \609 newvar->get_fn = DEFAULT_CB(init_params->get_fn, owl_variable_##type##_get_default); \610 newvar->set_fn = DEFAULT_CB(init_params->set_fn, owl_variable_##type##_set_default); \611 newvar->validate_fn = \612 DEFAULT_CB(init_params->validate_fn, owl_variable_##type##_validate_default);613 614 int owl_variable_dict_add_from_list(owl_vardict *vd, owl_variable_init_params *variables_to_init)615 {616 owl_variable *newvar = NULL;617 owl_variable_init_params *init_params = NULL;618 for (init_params = variables_to_init; init_params->name; init_params++) {619 newvar = g_new0(owl_variable, 1);620 newvar->type = init_params->type;621 newvar->takes_on_off = (newvar->type == OWL_VARIABLE_BOOL);622 /* strdup all the strings so we can delete them consistently. */623 newvar->name = g_strdup(init_params->name);624 newvar->summary = g_strdup(init_params->summary);625 newvar->description = g_strdup(init_params->description);626 newvar->validsettings = g_strdup(init_params->validsettings);627 GCallback fn = NULL;628 switch (init_params->type) {629 case OWL_VARIABLE_STRING:630 SET_CBS(string);631 OWL_VARIABLE_SETUP_FUNC(newvar, init_params, set_fromstring_fn,632 G_CALLBACK(owl_variable_string_set_fromstring_default),633 g_cclosure_user_marshal_INT__STRING, fn);634 OWL_VARIABLE_SETUP_FUNC(newvar, init_params, get_tostring_fn,635 G_CALLBACK(owl_variable_string_get_tostring_default),636 g_cclosure_user_marshal_STRING__VOID, fn);637 638 g_value_init(&newvar->val, G_TYPE_STRING);639 owl_variable_set_string(newvar, init_params->pval_default);640 break;641 case OWL_VARIABLE_BOOL:642 SET_CBS(bool);643 OWL_VARIABLE_SETUP_FUNC(newvar, init_params, set_fromstring_fn,644 G_CALLBACK(owl_variable_bool_set_fromstring_default),645 g_cclosure_user_marshal_INT__STRING, fn);646 OWL_VARIABLE_SETUP_FUNC(newvar, init_params, get_tostring_fn,647 G_CALLBACK(owl_variable_bool_get_tostring_default),648 g_cclosure_user_marshal_STRING__VOID, fn);649 650 g_value_init(&newvar->val, G_TYPE_BOOLEAN);651 owl_variable_set_bool(newvar, !!(init_params->ival_default));652 break;653 case OWL_VARIABLE_INT:654 SET_CBS(int);655 OWL_VARIABLE_SETUP_FUNC(newvar, init_params, set_fromstring_fn,656 G_CALLBACK(owl_variable_int_set_fromstring_default),657 g_cclosure_user_marshal_INT__STRING, fn);658 OWL_VARIABLE_SETUP_FUNC(newvar, init_params, get_tostring_fn,659 G_CALLBACK(owl_variable_int_get_tostring_default),660 g_cclosure_user_marshal_STRING__VOID, fn);661 662 g_value_init(&newvar->val, G_TYPE_INT);663 owl_variable_set_int(newvar, init_params->ival_default);664 break;665 default:666 fprintf(stderr, "owl_variable_setup: invalid variable type\n");667 return(-2);668 }669 670 /* record the initial value as a string */671 newvar->default_str = owl_variable_get_tostring(newvar);672 673 owl_dict_insert_element(vd, newvar->name, newvar, NULL);674 }675 return 0;676 }677 678 613 void owl_variable_dict_add_variable(owl_vardict * vardict, 679 614 owl_variable * var) { … … 681 616 } 682 617 683 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) 684 { 618 static owl_variable *owl_variable_newvar(int type, const char *name, const char *summary, const char *description, const char *validsettings) { 685 619 owl_variable *var = g_new0(owl_variable, 1); 620 var->type = type; 686 621 var->name = g_strdup(name); 687 622 var->summary = g_strdup(summary); 688 623 var->description = g_strdup(description); 689 624 var->validsettings = g_strdup(validsettings); 625 return var; 626 } 627 628 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) 629 { 630 owl_variable *var = owl_variable_newvar(OWL_VARIABLE_INT, name, summary, 631 description, validsettings); 632 var->takes_on_off = false; 633 var->get_fn = G_CALLBACK(get_fn ? get_fn : owl_variable_int_get_default); 634 var->set_fn = G_CALLBACK(set_fn ? set_fn : owl_variable_int_set_default); 635 var->validate_fn = G_CALLBACK(validate_fn ? validate_fn : owl_variable_int_validate_default); 636 637 var->get_tostring_fn = owl_variable_make_closure( 638 var, G_CALLBACK(owl_variable_int_get_tostring_default), 639 g_cclosure_user_marshal_STRING__VOID); 640 var->set_fromstring_fn = owl_variable_make_closure( 641 var, G_CALLBACK(owl_variable_int_set_fromstring_default), 642 g_cclosure_user_marshal_INT__STRING); 643 644 g_value_init(&var->val, G_TYPE_INT); 645 owl_variable_set_int(var, default_val); 646 647 var->default_str = owl_variable_get_tostring(var); 648 owl_variable_dict_add_variable(vd, var); 649 } 650 651 void owl_variable_dict_newvar_int(owl_vardict *vd, const char *name, int default_val, const char *summary, const char *description) { 652 owl_variable_dict_newvar_int_full(vd, name, default_val, summary, description, 653 "<int>", NULL, NULL, NULL); 654 } 655 656 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) 657 { 658 owl_variable *var = owl_variable_newvar(OWL_VARIABLE_BOOL, name, summary, 659 description, "on,off"); 660 var->takes_on_off = true; 661 var->get_fn = G_CALLBACK(get_fn ? get_fn : owl_variable_bool_get_default); 662 var->set_fn = G_CALLBACK(set_fn ? set_fn : owl_variable_bool_set_default); 663 var->validate_fn = G_CALLBACK(validate_fn ? validate_fn : owl_variable_bool_validate_default); 664 665 var->get_tostring_fn = owl_variable_make_closure( 666 var, G_CALLBACK(owl_variable_bool_get_tostring_default), 667 g_cclosure_user_marshal_STRING__VOID); 668 var->set_fromstring_fn = owl_variable_make_closure( 669 var, G_CALLBACK(owl_variable_bool_set_fromstring_default), 670 g_cclosure_user_marshal_INT__STRING); 671 672 g_value_init(&var->val, G_TYPE_BOOLEAN); 673 owl_variable_set_bool(var, default_val); 674 675 var->default_str = owl_variable_get_tostring(var); 676 owl_variable_dict_add_variable(vd, var); 677 } 678 679 void owl_variable_dict_newvar_bool(owl_vardict *vd, const char *name, bool default_val, const char *summary, const char *description) { 680 owl_variable_dict_newvar_bool_full(vd, name, default_val, summary, description, 681 NULL, NULL, NULL); 682 } 683 684 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) 685 { 686 owl_variable *var = owl_variable_newvar(OWL_VARIABLE_STRING, name, summary, 687 description, validsettings); 688 var->takes_on_off = false; 689 var->get_fn = G_CALLBACK(get_fn ? get_fn : owl_variable_string_get_default); 690 var->set_fn = G_CALLBACK(set_fn ? set_fn : owl_variable_string_set_default); 691 var->validate_fn = G_CALLBACK(validate_fn ? validate_fn : owl_variable_string_validate_default); 692 693 var->get_tostring_fn = owl_variable_make_closure( 694 var, G_CALLBACK(owl_variable_string_get_tostring_default), 695 g_cclosure_user_marshal_STRING__VOID); 696 var->set_fromstring_fn = owl_variable_make_closure( 697 var, G_CALLBACK(owl_variable_string_set_fromstring_default), 698 g_cclosure_user_marshal_INT__STRING); 699 700 g_value_init(&var->val, G_TYPE_STRING); 701 owl_variable_set_string(var, default_val); 702 703 var->default_str = owl_variable_get_tostring(var); 704 owl_variable_dict_add_variable(vd, var); 705 } 706 707 void owl_variable_dict_newvar_string(owl_vardict *vd, const char *name, const char *default_val, const char *summary, const char *description) { 708 owl_variable_dict_newvar_string_full(vd, name, default_val, summary, description, 709 "<string>", NULL, NULL, NULL); 710 } 711 712 void owl_variable_dict_newvar_path(owl_vardict *vd, const char *name, const char *default_val, const char *summary, const char *description) { 713 owl_variable_dict_newvar_string_full(vd, name, default_val, summary, description, 714 "<path>", NULL, NULL, NULL); 715 } 716 717 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) 718 { 719 owl_variable *var = owl_variable_newvar(OWL_VARIABLE_INT, name, summary, 720 description, validsettings); 721 var->takes_on_off = false; 722 var->get_fn = G_CALLBACK(get_fn ? get_fn : owl_variable_int_get_default); 723 var->set_fn = G_CALLBACK(set_fn ? set_fn : owl_variable_int_set_default); 724 var->validate_fn = G_CALLBACK(validate_fn ? validate_fn : owl_variable_enum_validate); 725 726 var->get_tostring_fn = owl_variable_make_closure( 727 var, G_CALLBACK(owl_variable_enum_get_tostring), 728 g_cclosure_user_marshal_STRING__VOID); 729 var->set_fromstring_fn = owl_variable_make_closure( 730 var, G_CALLBACK(owl_variable_enum_set_fromstring), 731 g_cclosure_user_marshal_INT__STRING); 732 733 g_value_init(&var->val, G_TYPE_INT); 734 owl_variable_set_int(var, default_val); 735 736 var->default_str = owl_variable_get_tostring(var); 737 owl_variable_dict_add_variable(vd, var); 738 } 739 740 void owl_variable_dict_newvar_enum(owl_vardict *vd, const char *name, int default_val, const char *summary, const char *description, const char *validset) { 741 owl_variable_dict_newvar_enum_full(vd, name, default_val, summary, description, 742 validset, NULL, NULL, NULL); 743 } 744 745 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) 746 { 747 owl_variable *var = owl_variable_newvar(OWL_VARIABLE_OTHER, name, summary, 748 description, validsettings); 690 749 var->takes_on_off = takes_on_off; 691 750 … … 803 862 } 804 863 805 int owl_variable_set_bool(owl_variable *v, gbooleannewval) {864 int owl_variable_set_bool(owl_variable *v, bool newval) { 806 865 g_return_val_if_fail(v->type == OWL_VARIABLE_BOOL, -1); 807 866 … … 865 924 } 866 925 867 gbooleanowl_variable_get_bool(const owl_variable *v)926 bool owl_variable_get_bool(const owl_variable *v) 868 927 { 869 928 g_return_val_if_fail(v->type == OWL_VARIABLE_BOOL, FALSE); … … 938 997 } 939 998 940 gbooleanowl_variable_bool_get_default(const owl_variable *v) {999 bool owl_variable_bool_get_default(const owl_variable *v) { 941 1000 return g_value_get_boolean(&(v->val)); 942 1001 } … … 944 1003 /* default functions for booleans */ 945 1004 946 int owl_variable_bool_validate_default(const owl_variable *v, gbooleannewval) {1005 int owl_variable_bool_validate_default(const owl_variable *v, bool newval) { 947 1006 return (newval == 1) || (newval == 0); 948 1007 } … … 957 1016 958 1017 int owl_variable_bool_set_fromstring_default(owl_variable *v, const char *newval, void *dummy) { 959 gbooleani;1018 bool i; 960 1019 if (!strcmp(newval, "on")) { 961 i = TRUE;1020 i = true; 962 1021 } else if (!strcmp(newval, "off")) { 963 i = FALSE;1022 i = false; 964 1023 } else { 965 1024 return(-1);
Note: See TracChangeset
for help on using the changeset viewer.