source: variable.c @ 650fb2c

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