1 /* Options variables manipulation core */
12 #include "bfu/dialog.h"
13 #include "cache/cache.h"
14 #include "config/conf.h"
15 #include "config/dialogs.h"
16 #include "config/options.h"
17 #include "config/opttypes.h"
18 #include "dialogs/status.h"
19 #include "document/document.h"
20 #include "globhist/globhist.h"
21 #include "intl/charsets.h"
22 #include "intl/gettext/libintl.h"
23 #include "main/main.h" /* shrink_memory() */
24 #include "main/select.h"
25 #include "network/connection.h"
26 #include "session/session.h"
27 #include "terminal/color.h"
28 #include "terminal/screen.h"
29 #include "terminal/terminal.h"
30 #include "util/color.h"
31 #include "util/error.h"
32 #include "util/memory.h"
33 #include "util/string.h"
34 #include "viewer/text/draw.h"
37 /* TODO? In the past, covered by shadow and legends, remembered only by the
38 * ELinks Elders now, options were in hashes (it was not for a long time, after
39 * we started to use dynamic options lists and before we really started to use
40 * hierarchic options). Hashes might be swift and deft, but they had a flaw and
41 * the flaw showed up as the fatal flaw. They were unsorted, and it was
42 * unfriendly to mere mortal users, without pasky's options handlers in their
43 * brain, but their own poor-written software. And thus pasky went and rewrote
44 * options so that they were in lists from then to now and for all the ages of
45 * men, to the glory of mankind. However, one true hero may arise in future
46 * fabulous and implement possibility to have both lists and hashes for trees,
47 * as it may be useful for some supernatural entities. And when that age will
51 /* TODO: We should remove special case for root options and use some auxiliary
52 * (struct option *) instead. This applies to bookmarks, global history and
53 * listbox items as well, though. --pasky */
55 static INIT_LIST_HEAD(options_root_tree
);
57 static struct option options_root
= INIT_OPTION(
62 /* value: */ &options_root_tree
,
67 struct option
*config_options
;
68 struct option
*cmdline_options
;
70 static void add_opt_rec(struct option
*, unsigned char *, struct option
*);
71 static void free_options_tree(struct list_head
*, int recursive
);
74 /* Detect ending '.' (and some others) in options captions.
75 * It will emit a message in debug mode only. --Zas */
77 #define bad_punct(c) (c != ')' && c != '>' && !isquote(c) && ispunct(c))
80 check_caption(unsigned char *caption
)
87 len
= strlen(caption
);
91 if (isspace(c
) || bad_punct(c
))
92 DBG("bad char at end of caption [%s]", caption
);
95 caption
= gettext(caption
);
96 len
= strlen(caption
);
100 if (isspace(c
) || bad_punct(c
))
101 DBG("bad char at end of i18n caption [%s]", caption
);
108 check_description(unsigned char *desc
)
120 DBG("bad char at end of description [%s]", desc
);
123 desc
= gettext(desc
);
127 if (ispunct(c
) != ispunct(desc
[len
- 1]))
128 DBG("punctuation char possibly missing at end of i18n description [%s]", desc
);
132 DBG("bad char at end of i18n description [%s]", desc
);
137 debug_check_option_syntax(struct option
*option
)
140 check_caption(option
->capt
);
141 check_description(option
->desc
);
145 #define debug_check_option_syntax(option)
149 /**********************************************************************
151 **********************************************************************/
153 /* If option name contains dots, they are created as "categories" - first,
154 * first category is retrieved from list, taken as a list, second category
155 * is retrieved etc. */
158 static int no_autocreate
= 0;
160 /* Get record of option of given name, or NULL if there's no such option. */
162 get_opt_rec(struct option
*tree
, unsigned char *name_
)
164 struct option
*option
;
165 unsigned char *aname
= stracpy(name_
);
166 unsigned char *name
= aname
;
169 if (!aname
) return NULL
;
171 /* We iteratively call get_opt_rec() each for path_elements-1, getting
172 * appropriate tree for it and then resolving [path_elements]. */
173 if ((sep
= strrchr(name
, '.'))) {
176 tree
= get_opt_rec(tree
, name
);
177 if (!tree
|| tree
->type
!= OPT_TREE
|| tree
->flags
& OPT_HIDDEN
) {
179 DBG("ERROR in get_opt_rec() crawl: %s (%d) -> %s",
180 name
, tree
? tree
->type
: -1, sep
+ 1);
190 foreach (option
, *tree
->value
.tree
) {
191 if (option
->name
&& !strcmp(option
->name
, name
)) {
197 if (tree
&& tree
->flags
& OPT_AUTOCREATE
&& !no_autocreate
) {
198 struct option
*template = get_opt_rec(tree
, "_template_");
200 assertm(template, "Requested %s should be autocreated but "
201 "%.*s._template_ is missing!", name_
, sep
- name_
,
208 /* We will just create the option and return pointer to it
209 * automagically. And, we will create it by cloning _template_
210 * option. By having _template_ OPT_AUTOCREATE and _template_
211 * inside, you can have even multi-level autocreating. */
213 option
= copy_option(template);
218 mem_free_set(&option
->name
, stracpy(name
));
220 add_opt_rec(tree
, "", option
);
230 /* Get record of option of given name, or NULL if there's no such option. But
231 * do not create the option if it doesn't exist and there's autocreation
234 get_opt_rec_real(struct option
*tree
, unsigned char *name
)
239 opt
= get_opt_rec(tree
, name
);
244 /* Fetch pointer to value of certain option. It is guaranteed to never return
245 * NULL. Note that you are supposed to use wrapper get_opt(). */
249 unsigned char *file
, int line
, enum option_type option_type
,
251 struct option
*tree
, unsigned char *name
)
253 struct option
*opt
= get_opt_rec(tree
, name
);
258 if (!opt
) elinks_internal("Attempted to fetch nonexisting option %s!", name
);
260 /* Various sanity checks. */
261 if (option_type
!= opt
->type
)
262 DBG("get_opt_*(\"%s\") @ %s:%d: call with wrapper for %s for option of type %s",
264 get_option_type_name(option_type
),
265 get_option_type_name(opt
->type
));
269 if (!opt
->value
.tree
)
270 elinks_internal("Option %s has no value!", name
);
273 elinks_internal("Invalid use of alias %s for option %s!",
274 name
, opt
->value
.string
);
277 if (!opt
->value
.string
)
278 elinks_internal("Option %s has no value!", name
);
283 if (opt
->value
.number
< opt
->min
284 || opt
->value
.number
> opt
->max
)
285 elinks_internal("Option %s has invalid value %d!", name
, opt
->value
.number
);
288 if (!opt
->value
.command
)
289 elinks_internal("Option %s has no value!", name
);
291 case OPT_CODEPAGE
: /* TODO: check these too. */
302 add_opt_sort(struct option
*tree
, struct option
*option
, int abi
)
304 struct list_head
*cat
= tree
->value
.tree
;
305 struct list_head
*bcat
= &tree
->box_item
->child
;
308 /* The list is empty, just add it there. */
309 if (list_empty(*cat
)) {
310 add_to_list(*cat
, option
);
311 if (abi
) add_to_list(*bcat
, option
->box_item
);
313 /* This fits as the last list entry, add it there. This
314 * optimizes the most expensive BUT most common case ;-). */
315 } else if ((option
->type
!= OPT_TREE
316 || ((struct option
*) cat
->prev
)->type
== OPT_TREE
)
317 && strcmp(((struct option
*) cat
->prev
)->name
,
318 option
->name
) <= 0) {
320 add_to_list_end(*cat
, option
);
321 if (abi
) add_to_list_end(*bcat
, option
->box_item
);
323 /* At the end of the list is tree and we are ordinary. That's
324 * clear case then. */
325 } else if (option
->type
!= OPT_TREE
326 && ((struct option
*) cat
->prev
)->type
== OPT_TREE
) {
329 /* Scan the list linearly. This could be probably optimized ie.
330 * to choose direction based on the first letter or so. */
332 struct listbox_item
*bpos
= (struct listbox_item
*) bcat
;
334 foreach (pos
, *cat
) {
335 /* First move the box item to the current position but
336 * only if the position has not been marked as deleted
337 * and actually has a box_item -- else we will end up
338 * 'overflowing' and causing assertion failure. */
339 if (!(pos
->flags
& OPT_DELETED
) && pos
->box_item
) {
341 assert(bpos
!= (struct listbox_item
*) bcat
);
344 if ((option
->type
!= OPT_TREE
345 || pos
->type
== OPT_TREE
)
346 && strcmp(pos
->name
, option
->name
) <= 0)
349 /* Ordinary options always sort behind trees. */
350 if (option
->type
!= OPT_TREE
351 && pos
->type
== OPT_TREE
)
354 /* The (struct option) add_at_pos() can mess up the
355 * order so that we add the box_item to itself, so
356 * better do it first. */
358 /* Always ensure that them _template_ options are
359 * before anything else so a lonely autocreated option
360 * (with _template_ options set to invisible) will be
361 * connected with an upper corner (ascii: `-) instead
362 * of a rotated T (ascii: +-) when displaying it. */
363 if (option
->type
== pos
->type
364 && *option
->name
<= '_'
365 && !strcmp(pos
->name
, "_template_")) {
366 if (abi
) add_at_pos(bpos
, option
->box_item
);
367 add_at_pos(pos
, option
);
371 if (abi
) add_at_pos(bpos
->prev
, option
->box_item
);
372 add_at_pos(pos
->prev
, option
);
376 assert(pos
!= (struct option
*) cat
);
377 assert(bpos
!= (struct listbox_item
*) bcat
);
381 /* Add option to tree. */
383 add_opt_rec(struct option
*tree
, unsigned char *path
, struct option
*option
)
387 assert(path
&& option
&& tree
);
388 if (*path
) tree
= get_opt_rec(tree
, path
);
390 assertm(tree
, "Missing option tree for '%s'", path
);
391 if (!tree
->value
.tree
) return;
393 object_nolock(option
, "option");
395 if (option
->box_item
&& option
->name
&& !strcmp(option
->name
, "_template_"))
396 option
->box_item
->visible
= get_opt_bool("config.show_template");
398 if (tree
->flags
& OPT_AUTOCREATE
&& !option
->desc
) {
399 struct option
*template = get_opt_rec(tree
, "_template_");
402 option
->desc
= template->desc
;
407 abi
= (tree
->box_item
&& option
->box_item
);
410 /* The config_root tree is a just a placeholder for the
411 * box_items, it actually isn't a real box_item by itself;
412 * these ghosts are indicated by the fact that they have
414 if (tree
->box_item
->next
) {
415 option
->box_item
->depth
= tree
->box_item
->depth
+ 1;
419 if (tree
->flags
& OPT_SORT
) {
420 add_opt_sort(tree
, option
, abi
);
423 add_to_list_end(*tree
->value
.tree
, option
);
424 if (abi
) add_to_list_end(tree
->box_item
->child
, option
->box_item
);
427 update_hierbox_browser(&option_browser
);
430 static inline struct listbox_item
*
431 init_option_listbox_item(struct option
*option
)
433 struct listbox_item
*item
= mem_calloc(1, sizeof(*item
));
435 if (!item
) return NULL
;
437 init_list(item
->child
);
439 item
->udata
= option
;
440 item
->type
= (option
->type
== OPT_TREE
) ? BI_FOLDER
: BI_LEAF
;
446 add_opt(struct option
*tree
, unsigned char *path
, unsigned char *capt
,
447 unsigned char *name
, enum option_flags flags
, enum option_type type
,
448 int min
, int max
, void *value
, unsigned char *desc
)
450 struct option
*option
= mem_calloc(1, sizeof(*option
));
452 if (!option
) return NULL
;
454 option
->name
= stracpy(name
);
459 option
->flags
= (flags
| OPT_ALLOC
);
466 debug_check_option_syntax(option
);
468 if (option
->type
!= OPT_ALIAS
469 && ((tree
->flags
& OPT_LISTBOX
) || (option
->flags
& OPT_LISTBOX
))) {
470 option
->box_item
= init_option_listbox_item(option
);
471 if (!option
->box_item
) {
472 delete_option(option
);
477 /* XXX: For allocated values we allocate in the add_opt_<type>() macro.
478 * This involves OPT_TREE and OPT_STRING. */
482 delete_option(option
);
485 option
->value
.tree
= value
;
489 delete_option(option
);
492 option
->value
.string
= value
;
495 option
->value
.string
= value
;
501 option
->value
.number
= (long) value
;
504 decode_color(value
, strlen((unsigned char *) value
),
505 &option
->value
.color
);
508 option
->value
.command
= value
;
514 add_opt_rec(tree
, path
, option
);
519 done_option(struct option
*option
)
521 switch (option
->type
) {
523 mem_free_if(option
->value
.string
);
526 mem_free_if(option
->value
.tree
);
532 if (option
->box_item
)
533 done_listbox_item(&option_browser
, option
->box_item
);
535 if (option
->flags
& OPT_ALLOC
) {
536 mem_free_if(option
->name
);
538 } else if (!option
->capt
) {
539 /* We are probably dealing with a built-in autocreated option
540 * that will be attempted to be deleted when shutting down. */
541 /* Clear it so nothing will be done later. */
542 memset(option
, 0, sizeof(*option
));
546 /* The namespace may start to seem a bit chaotic here; it indeed is, maybe the
547 * function names above should be renamed and only macros should keep their old
549 /* The simple rule I took as an apologize is that functions which take already
550 * completely filled (struct option *) have long name and functions which take
551 * only option specs have short name. */
554 delete_option_do(struct option
*option
, int recursive
)
557 del_from_list(option
);
558 option
->prev
= option
->next
= NULL
;
561 if (recursive
== -1) {
562 ERROR("Orphaned option %s", option
->name
);
565 if (option
->type
== OPT_TREE
&& option
->value
.tree
566 && !list_empty(*option
->value
.tree
)) {
568 if (option
->flags
& OPT_AUTOCREATE
) {
571 ERROR("Orphaned unregistered "
572 "option in subtree %s!",
577 free_options_tree(option
->value
.tree
, recursive
);
584 mark_option_as_deleted(struct option
*option
)
586 if (option
->type
== OPT_TREE
) {
587 struct option
*unmarked
;
589 assert(option
->value
.tree
);
591 foreach (unmarked
, *option
->value
.tree
)
592 mark_option_as_deleted(unmarked
);
595 option
->box_item
->visible
= 0;
597 option
->flags
|= (OPT_TOUCHED
| OPT_DELETED
);
601 delete_option(struct option
*option
)
603 delete_option_do(option
, 1);
607 copy_option(struct option
*template)
609 struct option
*option
= mem_calloc(1, sizeof(*option
));
611 if (!option
) return NULL
;
613 option
->name
= null_or_stracpy(template->name
);
614 option
->flags
= (template->flags
| OPT_ALLOC
);
615 option
->type
= template->type
;
616 option
->min
= template->min
;
617 option
->max
= template->max
;
618 option
->capt
= template->capt
;
619 option
->desc
= template->desc
;
620 option
->change_hook
= template->change_hook
;
622 option
->box_item
= init_option_listbox_item(option
);
623 if (option
->box_item
) {
624 if (template->box_item
) {
625 option
->box_item
->type
= template->box_item
->type
;
626 option
->box_item
->depth
= template->box_item
->depth
;
630 if (option_types
[template->type
].dup
) {
631 option_types
[template->type
].dup(option
, template);
633 option
->value
= template->value
;
640 init_options_tree(void)
642 struct list_head
*ptr
= mem_alloc(sizeof(*ptr
));
644 if (ptr
) init_list(*ptr
);
648 /* Some default pre-autocreated options. Doh. */
650 register_autocreated_options(void)
652 /* TODO: Use table-driven initialization. --jonas */
653 get_opt_int("terminal.linux.type") = 2;
654 get_opt_int("terminal.linux.colors") = 1;
655 get_opt_bool("terminal.linux.m11_hack") = 1;
656 get_opt_int("terminal.vt100.type") = 1;
657 get_opt_int("terminal.vt110.type") = 1;
658 get_opt_int("terminal.xterm.type") = 1;
659 get_opt_bool("terminal.xterm.underline") = 1;
660 get_opt_int("terminal.xterm-color.type") = 1;
661 get_opt_int("terminal.xterm-color.colors") = COLOR_MODE_16
;
662 get_opt_bool("terminal.xterm-color.underline") = 1;
663 #ifdef CONFIG_88_COLORS
664 get_opt_int("terminal.xterm-88color.type") = 1;
665 get_opt_int("terminal.xterm-88color.colors") = COLOR_MODE_88
;
666 get_opt_bool("terminal.xterm-88color.underline") = 1;
668 #ifdef CONFIG_256_COLORS
669 get_opt_int("terminal.xterm-256color.type") = 1;
670 get_opt_int("terminal.xterm-256color.colors") = COLOR_MODE_256
;
671 get_opt_bool("terminal.xterm-256color.underline") = 1;
675 static struct option_info config_options_info
[];
676 extern struct option_info cmdline_options_info
[];
677 static struct change_hook_info change_hooks
[];
682 cmdline_options
= add_opt_tree_tree(&options_root
, "", "",
684 register_options(cmdline_options_info
, cmdline_options
);
686 config_options
= add_opt_tree_tree(&options_root
, "", "",
687 "config", OPT_SORT
, "");
688 config_options
->flags
|= OPT_LISTBOX
;
689 config_options
->box_item
= &option_browser
.root
;
690 register_options(config_options_info
, config_options
);
692 register_autocreated_options();
693 register_change_hooks(change_hooks
);
697 free_options_tree(struct list_head
*tree
, int recursive
)
699 while (!list_empty(*tree
))
700 delete_option_do(tree
->next
, recursive
);
706 unregister_options(config_options_info
, config_options
);
707 unregister_options(cmdline_options_info
, cmdline_options
);
708 config_options
->box_item
= NULL
;
709 free_options_tree(&options_root_tree
, 0);
713 register_change_hooks(struct change_hook_info
*change_hooks
)
717 for (i
= 0; change_hooks
[i
].name
; i
++) {
718 struct option
*option
= get_opt_rec(config_options
,
719 change_hooks
[i
].name
);
722 option
->change_hook
= change_hooks
[i
].change_hook
;
727 unmark_options_tree(struct list_head
*tree
)
729 struct option
*option
;
731 foreach (option
, *tree
) {
732 option
->flags
&= ~OPT_WATERMARK
;
733 if (option
->type
== OPT_TREE
)
734 unmark_options_tree(option
->value
.tree
);
739 watermark_deleted_options(struct list_head
*tree
)
741 struct option
*option
;
743 foreach (option
, *tree
) {
744 if (option
->flags
& OPT_DELETED
)
745 option
->flags
|= OPT_WATERMARK
;
746 else if (option
->type
== OPT_TREE
)
747 watermark_deleted_options(option
->value
.tree
);
752 check_nonempty_tree(struct list_head
*options
)
756 foreach (opt
, *options
) {
757 if (opt
->type
== OPT_TREE
) {
758 if (check_nonempty_tree(opt
->value
.tree
))
760 } else if (!(opt
->flags
& OPT_WATERMARK
)) {
769 smart_config_string(struct string
*str
, int print_comment
, int i18n
,
770 struct list_head
*options
, unsigned char *path
, int depth
,
771 void (*fn
)(struct string
*, struct option
*,
772 unsigned char *, int, int, int, int))
774 struct option
*option
;
776 foreach (option
, *options
) {
777 int do_print_comment
= 1;
779 if (option
->flags
& OPT_HIDDEN
||
780 option
->flags
& OPT_WATERMARK
||
781 option
->type
== OPT_ALIAS
||
782 !strcmp(option
->name
, "_template_"))
785 /* Is there anything to be printed anyway? */
786 if (option
->type
== OPT_TREE
787 && !check_nonempty_tree(option
->value
.tree
))
790 /* We won't pop out the description when we're in autocreate
791 * category and not template. It'd be boring flood of
792 * repetitive comments otherwise ;). */
794 /* This print_comment parameter is weird. If it is negative, it
795 * means that we shouldn't print comments at all. If it is 1,
796 * we shouldn't print comment UNLESS the option is _template_
797 * or not-an-autocreating-tree (it is set for the first-level
798 * autocreation tree). When it is 2, we can print out comments
800 /* It is still broken somehow, as it didn't work for terminal.*
801 * (the first autocreated level) by the time I wrote this. Good
802 * summer job for bored mad hackers with spare boolean mental
803 * power. I have better things to think about, personally.
804 * Maybe we should just mark autocreated options somehow ;). */
805 if (!print_comment
|| (print_comment
== 1
806 && (strcmp(option
->name
, "_template_")
807 && (option
->flags
& OPT_AUTOCREATE
808 && option
->type
== OPT_TREE
))))
809 do_print_comment
= 0;
811 /* Pop out the comment */
813 /* For config file, we ignore do_print_comment everywhere
814 * except 1, but sometimes we want to skip the option totally.
816 fn(str
, option
, path
, depth
,
817 option
->type
== OPT_TREE
? print_comment
821 fn(str
, option
, path
, depth
, do_print_comment
, 1, i18n
);
823 /* And the option itself */
825 if (option_types
[option
->type
].write
) {
826 fn(str
, option
, path
, depth
,
827 do_print_comment
, 2, i18n
);
829 } else if (option
->type
== OPT_TREE
) {
830 struct string newpath
;
831 int pc
= print_comment
;
833 if (!init_string(&newpath
)) continue; /* OK? */
835 if (pc
== 2 && option
->flags
& OPT_AUTOCREATE
)
837 else if (pc
== 1 && strcmp(option
->name
, "_template_"))
840 fn(str
, option
, path
, depth
, /*pc*/1, 3, i18n
);
843 add_to_string(&newpath
, path
);
844 add_char_to_string(&newpath
, '.');
846 add_to_string(&newpath
, option
->name
);
847 smart_config_string(str
, pc
, i18n
, option
->value
.tree
,
848 newpath
.source
, depth
+ 1, fn
);
849 done_string(&newpath
);
851 fn(str
, option
, path
, depth
, /*pc*/1, 3, i18n
);
854 /* TODO: We should maybe clear the touched flag only when really
855 * saving the stuff...? --pasky */
856 option
->flags
&= ~OPT_TOUCHED
;
862 change_hook_cache(struct session
*ses
, struct option
*current
, struct option
*changed
)
869 change_hook_connection(struct session
*ses
, struct option
*current
, struct option
*changed
)
871 register_check_queue();
876 change_hook_html(struct session
*ses
, struct option
*current
, struct option
*changed
)
878 foreach (ses
, sessions
) ses
->tab
->resize
= 1;
884 change_hook_insert_mode(struct session
*ses
, struct option
*current
, struct option
*changed
)
891 change_hook_active_link(struct session
*ses
, struct option
*current
, struct option
*changed
)
893 update_cached_document_options();
898 change_hook_terminal(struct session
*ses
, struct option
*current
, struct option
*changed
)
900 cls_redraw_all_terminals();
905 change_hook_ui(struct session
*ses
, struct option
*current
, struct option
*changed
)
911 /* Bit 2 of show means we should always set visibility, otherwise we set it
912 * only on templates. */
914 update_visibility(struct list_head
*tree
, int show
)
918 foreach (opt
, *tree
) {
919 if (opt
->flags
& OPT_DELETED
) continue;
921 if (!strcmp(opt
->name
, "_template_")) {
923 opt
->box_item
->visible
= (show
& 1);
925 if (opt
->type
== OPT_TREE
)
926 update_visibility(opt
->value
.tree
, show
| 2);
928 if (opt
->box_item
&& (show
& 2))
929 opt
->box_item
->visible
= (show
& 1);
931 if (opt
->type
== OPT_TREE
)
932 update_visibility(opt
->value
.tree
, show
);
938 update_options_visibility(void)
940 update_visibility(config_options
->value
.tree
,
941 get_opt_bool("config.show_template"));
945 toggle_option(struct session
*ses
, struct option
*option
)
947 long number
= option
->value
.number
+ 1;
949 assert(option
->type
== OPT_BOOL
|| option
->type
== OPT_INT
);
952 /* TODO: call change hooks. --jonas */
953 option
->value
.number
= (number
<= option
->max
) ? number
: option
->min
;
954 option_changed(ses
, option
, option
);
958 change_hook_stemplate(struct session
*ses
, struct option
*current
, struct option
*changed
)
960 update_visibility(config_options
->value
.tree
, changed
->value
.number
);
965 change_hook_language(struct session
*ses
, struct option
*current
, struct option
*changed
)
968 set_language(changed
->value
.number
);
973 static struct change_hook_info change_hooks
[] = {
974 { "config.show_template", change_hook_stemplate
},
975 { "connection", change_hook_connection
},
976 { "document.browse", change_hook_html
},
977 { "document.browse.forms.insert_mode",
978 change_hook_insert_mode
},
979 { "document.browse.links.active_link",
980 change_hook_active_link
},
981 { "document.cache", change_hook_cache
},
982 { "document.codepage", change_hook_html
},
983 { "document.colors", change_hook_html
},
984 { "document.html", change_hook_html
},
985 { "document.plain", change_hook_html
},
986 { "terminal", change_hook_terminal
},
987 { "ui.language", change_hook_language
},
988 { "ui", change_hook_ui
},
993 call_change_hooks(struct session
*ses
, struct option
*current
, struct option
*option
)
995 /* This boolean thing can look a little weird - it
996 * basically says that we should proceed when there's
997 * no change_hook or there's one and its return value
999 while (current
&& (!current
->change_hook
||
1000 !current
->change_hook(ses
, current
, option
))) {
1004 current
= current
->root
;
1009 option_changed(struct session
*ses
, struct option
*current
, struct option
*option
)
1011 option
->flags
|= OPT_TOUCHED
;
1012 /* Notify everyone out there! */
1013 call_change_hooks(ses
, current
, option
);
1017 commit_option_values(struct option_resolver
*resolvers
,
1018 struct option
*root
, union option_value
*values
, int size
)
1023 assert(resolvers
&& root
&& values
&& size
);
1025 for (i
= 0; i
< size
; i
++) {
1026 unsigned char *name
= resolvers
[i
].name
;
1027 struct option
*option
= get_opt_rec(root
, name
);
1028 int id
= resolvers
[i
].id
;
1030 if (memcmp(&option
->value
, &values
[id
], sizeof(union option_value
))) {
1031 option
->value
= values
[id
];
1032 option
->flags
|= OPT_TOUCHED
;
1033 /* Speed hack: Directly call the change-hook for each
1034 * option in resolvers and later call call_change_hooks
1035 * on the root; if we were to call call_change_hooks
1036 * on each option in resolvers, we would end up calling
1037 * the change-hooks of root, its parents, its
1038 * grandparents, and so on for each option in resolvers
1039 * because call_change_hooks is recursive. -- Miciah */
1040 if (option
->change_hook
)
1041 option
->change_hook(NULL
, option
, NULL
);
1046 /* See above 'Speed hack' comment. */
1047 call_change_hooks(NULL
, root
, NULL
);
1053 checkout_option_values(struct option_resolver
*resolvers
,
1054 struct option
*root
,
1055 union option_value
*values
, int size
)
1059 for (i
= 0; i
< size
; i
++) {
1060 unsigned char *name
= resolvers
[i
].name
;
1061 struct option
*option
= get_opt_rec(root
, name
);
1062 int id
= resolvers
[i
].id
;
1064 values
[id
] = option
->value
;
1068 /**********************************************************************
1070 **********************************************************************/
1072 #include "config/options.inc"
1075 register_options(struct option_info info
[], struct option
*tree
)
1079 for (i
= 0; info
[i
].path
; i
++) {
1080 struct option
*option
= &info
[i
].option
;
1081 unsigned char *string
;
1083 debug_check_option_syntax(option
);
1085 if (option
->type
!= OPT_ALIAS
1086 && ((tree
->flags
& OPT_LISTBOX
)
1087 || (option
->flags
& OPT_LISTBOX
))) {
1088 option
->box_item
= init_option_listbox_item(option
);
1089 if (!option
->box_item
) {
1090 delete_option(option
);
1095 switch (option
->type
) {
1097 option
->value
.tree
= init_options_tree();
1098 if (!option
->value
.tree
) {
1099 delete_option(option
);
1104 string
= mem_alloc(MAX_STR_LEN
);
1106 delete_option(option
);
1109 safe_strncpy(string
, option
->value
.string
, MAX_STR_LEN
);
1110 option
->value
.string
= string
;
1113 string
= option
->value
.string
;
1115 decode_color(string
, strlen(string
),
1116 &option
->value
.color
);
1119 string
= option
->value
.string
;
1121 option
->value
.number
= get_cp_index(string
);
1132 add_opt_rec(tree
, info
[i
].path
, option
);
1137 unregister_options(struct option_info info
[], struct option
*tree
)
1141 /* We need to remove the options in inverse order to the order how we
1144 while (info
[i
].path
) i
++;
1146 for (i
--; i
>= 0; i
--)
1147 delete_option_do(&info
[i
].option
, 0);