source: variable.c @ 897fc1c

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