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