source: variable.c @ 6772d19

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