Changeset 4584d1f


Ignore:
Timestamp:
Feb 21, 2013, 4:42:20 PM (12 years ago)
Author:
David Benjamin <davidben@mit.edu>
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)
Message:
Pipe all C-created variables through function calls

Gets us some long-overdue type checking in the various type-specific
callbacks.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • owl.h

    r3b9ca71 r4584d1f  
    266266                                 * returns 0 on success. */
    267267} 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 value
    282                                  * of the appropriate type.
    283                                  * unless documented, this
    284                                  * should make a copy.
    285                                  * returns 0 on success. */
    286   GCallback set_fromstring_fn;
    287                                 /* sets the variable to a value
    288                                  * of the appropriate type.
    289                                  * unless documented, this
    290                                  * 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 make
    295                                  * thread-safe... */
    296   GCallback get_tostring_fn;
    297                                 /* converts val to a string;
    298                                  * caller must free the result */
    299 } owl_variable_init_params;
    300268
    301269
  • variable.c

    r3b9ca71 r4584d1f  
    1010typedef const char *(*get_string_t)(const owl_variable *);
    1111typedef int (*get_int_t)(const owl_variable *);
    12 typedef gboolean (*get_bool_t)(const owl_variable *);
     12typedef bool (*get_bool_t)(const owl_variable *);
    1313
    1414typedef int (*set_string_t)(owl_variable *, const char *);
    1515typedef 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 }
     16typedef int (*set_bool_t)(owl_variable *, bool);
     17
     18typedef int (*validate_string_t)(const owl_variable *, const char *);
     19typedef int (*validate_int_t)(const owl_variable *, int);
     20typedef int (*validate_bool_t)(const owl_variable *, bool);
     21
     22static 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
     31static 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
     41static 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
     51static 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)
    3370
    3471#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)
    4984
    5085/* enums are really integers, but where validset is a comma-separated
    5186 * list of strings which can be specified.  The tokens, starting at 0,
    5287 * 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)
    5990
    6091#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)
    6694
    6795int owl_variable_add_defaults(owl_vardict *vd)
    6896{
    69   owl_variable_init_params variables_to_init[] = {
    70 
    7197  OWLVAR_STRING( "personalbell" /* %OwlVarStub */, "off",
    7298                 "ring the terminal bell when personal messages are received",
    7399                 "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");
    75101
    76102  OWLVAR_BOOL( "bell" /* %OwlVarStub */, 1,
    77                "enable / disable the terminal bell", "" ),
     103               "enable / disable the terminal bell", "" );
    78104
    79105  OWLVAR_BOOL_FULL( "debug" /* %OwlVarStub */, OWL_DEBUG,
     
    81107                    "If set to 'on', debugging messages are logged to the\n"
    82108                    "file specified by the debugfile variable.\n",
    83                     NULL, owl_variable_debug_set, NULL),
     109                    NULL, owl_variable_debug_set, NULL);
    84110
    85111  OWLVAR_BOOL( "startuplogin" /* %OwlVarStub */, 1,
    86                "send a login message when BarnOwl starts", "" ),
     112               "send a login message when BarnOwl starts", "" );
    87113
    88114  OWLVAR_BOOL( "shutdownlogout" /* %OwlVarStub */, 1,
    89                "send a logout message when BarnOwl exits", "" ),
     115               "send a logout message when BarnOwl exits", "" );
    90116
    91117  OWLVAR_BOOL( "rxping" /* %OwlVarStub */, 0,
    92                "display received pings", "" ),
     118               "display received pings", "" );
    93119
    94120  OWLVAR_BOOL( "txping" /* %OwlVarStub */, 1,
    95                "send pings", "" ),
     121               "send pings", "" );
    96122
    97123  OWLVAR_BOOL( "sepbar_disable" /* %OwlVarStub */, 0,
    98                "disable printing information in the separator bar", "" ),
     124               "disable printing information in the separator bar", "" );
    99125
    100126  OWLVAR_BOOL( "smartstrip" /* %OwlVarStub */, 1,
    101                "strip kerberos instance for reply", ""),
     127               "strip kerberos instance for reply", "");
    102128
    103129  OWLVAR_BOOL( "newlinestrip" /* %OwlVarStub */, 1,
    104                "strip leading and trailing newlines", ""),
     130               "strip leading and trailing newlines", "");
    105131
    106132  OWLVAR_BOOL( "displayoutgoing" /* %OwlVarStub */, 1,
    107                "display outgoing messages", "" ),
     133               "display outgoing messages", "" );
    108134
    109135  OWLVAR_BOOL( "loginsubs" /* %OwlVarStub */, 1,
    110                "load logins from .anyone on startup", "" ),
     136               "load logins from .anyone on startup", "" );
    111137
    112138  OWLVAR_BOOL( "logging" /* %OwlVarStub */, 0,
     
    115141               "logged in the directory specified\n"
    116142               "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" );
    118144
    119145  OWLVAR_BOOL( "classlogging" /* %OwlVarStub */, 0,
     
    123149               "by the 'classlogpath' variable.\n"
    124150               "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" );
    126152
    127153  OWLVAR_ENUM( "loggingdirection" /* %OwlVarStub */, OWL_LOGGING_DIRECTION_BOTH,
     
    132158               "is selected both incoming and outgoing messages are\n"
    133159               "logged.",
    134                "both,in,out"),
     160               "both,in,out");
    135161
    136162  OWLVAR_BOOL_FULL( "colorztext" /* %OwlVarStub */, 1,
    137163                    "allow @color() in zephyrs to change color",
    138                     NULL, NULL, owl_variable_colorztext_set, NULL),
     164                    NULL, NULL, owl_variable_colorztext_set, NULL);
    139165
    140166  OWLVAR_BOOL( "fancylines" /* %OwlVarStub */, 1,
     
    142168               "If turned off, dashes, pipes and pluses will be used\n"
    143169               "to draw lines on the screen.  Useful when the terminal\n"
    144                "is causing problems" ),
     170               "is causing problems" );
    145171
    146172  OWLVAR_BOOL( "zcrypt" /* %OwlVarStub */, 1,
    147173               "Do automatic zcrypt processing",
    148                "" ),
     174               "" );
    149175
    150176  OWLVAR_BOOL_FULL( "pseudologins" /* %OwlVarStub */, 0,
     
    154180                    "but sent no login message, or a user is not present that sent no\n"
    155181                    "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);
    157183
    158184  OWLVAR_BOOL( "ignorelogins" /* %OwlVarStub */, 0,
     
    160186               "When this is enabled, BarnOwl will print login and logout notifications\n"
    161187               "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");
    163189
    164190  OWLVAR_STRING( "logfilter" /* %OwlVarStub */, "",
     
    169195                 "variables like logging, classlogging, loglogins, loggingdirection,\n"
    170196                 "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");
    172198
    173199  OWLVAR_BOOL( "loglogins" /* %OwlVarStub */, 0,
     
    175201               "When this is enabled, BarnOwl will log login and logout notifications\n"
    176202               "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");
    178204
    179205  OWLVAR_ENUM_FULL( "disable-ctrl-d" /* %OwlVarStub:lockout_ctrld */, 1,
     
    187213                    "in the editmulti keymap.\n",
    188214                    "off,middle,on",
    189                     NULL, owl_variable_disable_ctrl_d_set, NULL),
     215                    NULL, owl_variable_disable_ctrl_d_set, NULL);
    190216
    191217  OWLVAR_PATH( "logpath" /* %OwlVarStub */, "~/zlog/people",
    192218               "path for logging personal zephyrs",
    193219               "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");
    195221
    196222  OWLVAR_PATH( "classlogpath" /* %OwlVarStub:classlogpath */, "~/zlog/class",
    197223               "path for logging class zephyrs",
    198224               "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");
    200226
    201227  OWLVAR_PATH( "debug_file" /* %OwlVarStub */, OWL_DEBUG_FILE,
    202228               "path for logging debug messages when debugging is enabled",
    203229               "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.");
    205231 
    206232  OWLVAR_PATH( "zsigproc" /* %OwlVarStub:zsigproc */, NULL,
     
    210236               "See the documentation for 'zsig' for more information about\n"
    211237               "how the outgoing zsig is chosen."
    212                ),
     238               );
    213239
    214240  OWLVAR_PATH( "newmsgproc" /* %OwlVarStub:newmsgproc */, NULL,
     
    216242               "The named program will be run when BarnOwl receives new\n"
    217243               "messages.  It will not be run again until the first\n"
    218                "instance exits"),
     244               "instance exits");
    219245
    220246  OWLVAR_STRING( "zsender" /* %OwlVarStub */, "",
     
    223249         "zephyrs.  If this is unset, it will use your Kerberos\n"
    224250         "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.");
    226252
    227253  OWLVAR_STRING( "zsigfunc" /* %OwlVarStub */, "BarnOwl::default_zephyr_signature()",
     
    230256                 "explicit zsig.  The default setting implements the policy\n"
    231257                 "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");
    233259
    234260  OWLVAR_STRING( "zsig" /* %OwlVarStub */, "",
     
    237263                 "unset, 'zsigproc' will be run to generate a zsig. If that is\n"
    238264                 "also unset, the 'zwrite-signature' zephyr variable will be\n"
    239                  "used instead.\n"),
     265                 "used instead.\n");
    240266
    241267  OWLVAR_STRING( "appendtosepbar" /* %OwlVarStub */, "",
     
    243269                 "The sepbar is the bar separating the top and bottom\n"
    244270                 "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");
    246272
    247273  OWLVAR_BOOL( "zaway" /* %OwlVarStub */, 0,
    248                "turn zaway on or off", "" ),
     274               "turn zaway on or off", "" );
    249275
    250276  OWLVAR_STRING( "zaway_msg" /* %OwlVarStub */,
    251277                 OWL_DEFAULT_ZAWAYMSG,
    252                  "zaway msg for responding to zephyrs when away", "" ),
     278                 "zaway msg for responding to zephyrs when away", "" );
    253279
    254280  OWLVAR_STRING( "zaway_msg_default" /* %OwlVarStub */,
    255281                 OWL_DEFAULT_ZAWAYMSG,
    256                  "default zaway message", "" ),
     282                 "default zaway message", "" );
    257283
    258284  OWLVAR_BOOL_FULL( "aaway" /* %OwlVarStub */, 0,
    259285                    "Set AIM away status",
    260286                    "",
    261                     NULL, owl_variable_aaway_set, NULL),
     287                    NULL, owl_variable_aaway_set, NULL);
    262288
    263289  OWLVAR_STRING( "aaway_msg" /* %OwlVarStub */,
    264290                 OWL_DEFAULT_AAWAYMSG,
    265                  "AIM away msg for responding when away", "" ),
     291                 "AIM away msg for responding when away", "" );
    266292
    267293  OWLVAR_STRING( "aaway_msg_default" /* %OwlVarStub */,
    268294                 OWL_DEFAULT_AAWAYMSG,
    269                  "default AIM away message", "" ),
     295                 "default AIM away message", "" );
    270296
    271297  OWLVAR_STRING( "view_home" /* %OwlVarStub */, "all",
    272298                 "home view to switch to after 'X' and 'V'",
    273                  "SEE ALSO: view, filter\n" ),
     299                 "SEE ALSO: view, filter\n" );
    274300
    275301  OWLVAR_STRING( "alert_filter" /* %OwlVarStub */, "none",
    276302                 "filter on which to trigger alert actions",
    277                  "" ),
     303                 "" );
    278304
    279305  OWLVAR_STRING( "alert_action" /* %OwlVarStub */, "nop",
    280306                 "BarnOwl command to execute for alert actions",
    281                  "" ),
     307                 "" );
    282308
    283309  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);
    285311
    286312  OWLVAR_STRING( "default_style" /* %OwlVarStub */, "default",
     
    293319                 "   perl     - legacy perl interface\n"
    294320                 "\nSEE ALSO: style, show styles, view -s <style>\n"
    295                  ),
     321                 );
    296322
    297323
     
    300326                 "This specifies the maximum number of columns for M-q to fill text\n"
    301327                 "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");
    303329
    304330  OWLVAR_INT(    "edit:maxwrapcols" /* %OwlVarStub:edit_maxwrapcols */, 70,
     
    309335                 "\n"
    310336                 "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");
    312338
    313339  OWLVAR_INT( "aim_ignorelogin_timer" /* %OwlVarStub */, 15,
     
    316342              "AIM login before allowing the receipt of AIM login notifications.\n"
    317343              "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.");
    319345
    320346             
     
    329355                   owl_variable_typewinsize_set,
    330356                   NULL /* use default for get */
    331                    ),
     357                   );
    332358
    333359  OWLVAR_INT( "typewindelta" /* %OwlVarStub */, 0,
     
    339365           "typewinsize to 1.\n\n"
    340366           "This works a lot better with a non-default scrollmode;\n"
    341            "try :set scrollmode pagedcenter.\n"),
     367           "try :set scrollmode pagedcenter.\n");
    342368
    343369  OWLVAR_ENUM( "scrollmode" /* %OwlVarStub */, OWL_SCROLLMODE_NORMAL,
     
    368394               "                 the screen will be paged up or down and\n"
    369395               "                 the cursor will be near the center.\n",
    370                "normal,top,neartop,center,paged,pagedcenter" ),
     396               "normal,top,neartop,center,paged,pagedcenter" );
    371397
    372398  OWLVAR_BOOL( "narrow-related" /* %OwlVarStub:narrow_related */, 1,
     
    376402               "for Zephyr, this controls whether to narrow to e.g. class-help or\n"
    377403               "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" );
    379405
    380406  OWLVAR_BOOL( "_followlast" /* %OwlVarStub */, 0,
     
    383409               "continue to follow the last message if this is set.\n"
    384410               "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" );
    386412
    387413  OWLVAR_STRING_FULL( "default_exposure" /* %OwlVarStub */, "",
     
    392418                      "~/.zephyr.vars.\n"
    393419                      "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 );
    395421
    396422  OWLVAR_STRING_FULL( "exposure" /* %OwlVarStub */, "",
     
    448474                      "                     personal subscriptions will be entered for the\n"
    449475                      "                     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;
    459478}
    460479
     
    486505
    487506/* 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   }
     507int owl_variable_debug_set(owl_variable *v, bool newval)
     508{
     509  g.debug = newval;
    493510  return owl_variable_bool_set_default(v, newval);
    494511}
    495512
    496513/* When 'aaway' is changed, need to notify the AIM server */
    497 int owl_variable_aaway_set(owl_variable *v, gboolean newval)
    498 {
    499   if (newval == 1) {
     514int owl_variable_aaway_set(owl_variable *v, bool newval)
     515{
     516  if (newval) {
    500517    owl_aim_set_awaymsg(owl_global_get_aaway_msg(&g));
    501   } else if (newval == 0) {
     518  } else {
    502519    owl_aim_set_awaymsg("");
    503520  }
     
    505522}
    506523
    507 int owl_variable_colorztext_set(owl_variable *v, const void *newval)
     524int owl_variable_colorztext_set(owl_variable *v, bool newval)
    508525{
    509526  int ret = owl_variable_bool_set_default(v, newval);
     
    518535}
    519536
    520 int owl_variable_pseudologins_set(owl_variable *v, int newval)
     537int owl_variable_pseudologins_set(owl_variable *v, bool newval)
    521538{
    522539  static guint timer = 0;
    523   if (newval == 1) {
     540  if (newval) {
    524541    owl_function_zephyr_buddy_check(0);
    525542    if (timer == 0) {
     
    594611}
    595612
    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 
    678613void owl_variable_dict_add_variable(owl_vardict * vardict,
    679614                                    owl_variable * var) {
     
    681616}
    682617
    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 {
     618static owl_variable *owl_variable_newvar(int type, const char *name, const char *summary, const char *description, const char *validsettings) {
    685619  owl_variable *var = g_new0(owl_variable, 1);
     620  var->type = type;
    686621  var->name = g_strdup(name);
    687622  var->summary = g_strdup(summary);
    688623  var->description = g_strdup(description);
    689624  var->validsettings = g_strdup(validsettings);
     625  return var;
     626}
     627
     628static 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
     651void 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
     656static 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
     679void 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
     684static 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
     707void 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
     712void 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
     717static 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
     740void 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
     745void 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);
    690749  var->takes_on_off = takes_on_off;
    691750
     
    803862}
    804863
    805 int owl_variable_set_bool(owl_variable *v, gboolean newval) {
     864int owl_variable_set_bool(owl_variable *v, bool newval) {
    806865  g_return_val_if_fail(v->type == OWL_VARIABLE_BOOL, -1);
    807866
     
    865924}
    866925
    867 gboolean owl_variable_get_bool(const owl_variable *v)
     926bool owl_variable_get_bool(const owl_variable *v)
    868927{
    869928  g_return_val_if_fail(v->type == OWL_VARIABLE_BOOL, FALSE);
     
    938997}
    939998
    940 gboolean owl_variable_bool_get_default(const owl_variable *v) {
     999bool owl_variable_bool_get_default(const owl_variable *v) {
    9411000  return g_value_get_boolean(&(v->val));
    9421001}
     
    9441003/* default functions for booleans */
    9451004
    946 int owl_variable_bool_validate_default(const owl_variable *v, gboolean newval) {
     1005int owl_variable_bool_validate_default(const owl_variable *v, bool newval) {
    9471006  return (newval == 1) || (newval == 0);
    9481007}
     
    9571016
    9581017int owl_variable_bool_set_fromstring_default(owl_variable *v, const char *newval, void *dummy) {
    959   gboolean i;
     1018  bool i;
    9601019  if (!strcmp(newval, "on")) {
    961     i = TRUE;
     1020    i = true;
    9621021  } else if (!strcmp(newval, "off")) {
    963     i = FALSE;
     1022    i = false;
    9641023  } else {
    9651024    return(-1);
Note: See TracChangeset for help on using the changeset viewer.