1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-28 03:06:20 -04:00

config: Access OPT_MUST_SAVE in the real option, not alias.

So, if elinks.conf contains a "set" command for an alias and ELinks
updates that, it now knows it doesn't have to append another "set"
command for the underlying option.
(cherry picked from commit 92b430f3dc)
This commit is contained in:
Kalle Olavi Niemitalo 2008-02-03 13:57:13 +02:00 committed by Kalle Olavi Niemitalo
parent cc2ce681e3
commit a4fdf122d1
3 changed files with 31 additions and 5 deletions

View File

@ -292,7 +292,9 @@ parse_set(struct option *opt_tree, struct conf_parsing_state *state,
}
} else {
/* rewriting a configuration file */
if (opt->flags & OPT_DELETED) {
struct option *flagsite = indirect_option(opt);
if (flagsite->flags & OPT_DELETED) {
/* Replace the "set" command with an
* "unset" command. */
add_to_string(mirror, "unset ");
@ -308,7 +310,7 @@ parse_set(struct option *opt_tree, struct conf_parsing_state *state,
}
/* Remember that the option need not be
* written to the end of the file. */
opt->flags &= ~OPT_MUST_SAVE;
flagsite->flags &= ~OPT_MUST_SAVE;
}
mem_free(val);
}
@ -360,7 +362,9 @@ parse_unset(struct option *opt_tree, struct conf_parsing_state *state,
else mark_option_as_deleted(opt);
} else {
/* rewriting a configuration file */
if (opt->flags & OPT_DELETED) {
struct option *flagsite = indirect_option(opt);
if (flagsite->flags & OPT_DELETED) {
/* The "unset" command is already in the file,
* and unlike with "set", there is no value
* to be updated. */
@ -376,7 +380,7 @@ parse_unset(struct option *opt_tree, struct conf_parsing_state *state,
}
/* Remember that the option need not be
* written to the end of the file. */
opt->flags &= ~OPT_MUST_SAVE;
flagsite->flags &= ~OPT_MUST_SAVE;
}
}

View File

@ -164,7 +164,7 @@ static int no_autocreate = 0;
* work this way because the alias may have the ::OPT_ALIAS_NEGATE flag.
* Instead, if the caller tries to read or set the value of the alias,
* the functions associated with ::OPT_ALIAS will forward the operation
* to the underlying option. */
* to the underlying option. However, see indirect_option(). */
struct option *
get_opt_rec(struct option *tree, unsigned char *name_)
{
@ -248,6 +248,27 @@ get_opt_rec_real(struct option *tree, unsigned char *name)
return opt;
}
/** If @a opt is an alias, return the option to which it refers.
*
* @warning Because the alias may have the ::OPT_ALIAS_NEGATE flag,
* the caller must not access the value of the returned option as if
* it were also the value of the alias. However, it is safe to access
* flags such as ::OPT_MUST_SAVE and ::OPT_DELETED. */
struct option *
indirect_option(struct option *alias)
{
struct option *real;
if (alias->type != OPT_ALIAS) return alias; /* not an error */
real = get_opt_rec(config_options, alias->value.string);
assertm(real != NULL, "%s aliased to unknown option %s!",
alias->name, alias->value.string);
if_assert_failed return alias;
return real;
}
/* Fetch pointer to value of certain option. It is guaranteed to never return
* NULL. Note that you are supposed to use wrapper get_opt(). */
union option_value *

View File

@ -211,6 +211,7 @@ extern void checkout_option_values(struct option_resolver *resolvers,
extern struct option *get_opt_rec(struct option *, unsigned char *);
extern struct option *get_opt_rec_real(struct option *, unsigned char *);
struct option *indirect_option(struct option *);
#ifdef CONFIG_DEBUG
extern union option_value *get_opt_(unsigned char *, int, enum option_type, struct option *, unsigned char *);
#define get_opt(tree, name, type) get_opt_(__FILE__, __LINE__, type, tree, name)