mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
refactor(option.c): use intermediate for options ref
This commit is contained in:
@@ -335,24 +335,24 @@ void set_init_1(bool clean_arg)
|
|||||||
// Don't set the P_ALLOCED flag, because we don't want to free the
|
// Don't set the P_ALLOCED flag, because we don't want to free the
|
||||||
// default.
|
// default.
|
||||||
for (int opt_idx = 0; options[opt_idx].fullname; opt_idx++) {
|
for (int opt_idx = 0; options[opt_idx].fullname; opt_idx++) {
|
||||||
if (options[opt_idx].flags & P_NO_DEF_EXP) {
|
vimoption_T *opt = &options[opt_idx];
|
||||||
|
if (opt->flags & P_NO_DEF_EXP) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
char *p;
|
char *p;
|
||||||
if ((options[opt_idx].flags & P_GETTEXT)
|
if ((opt->flags & P_GETTEXT) && opt->var != NULL) {
|
||||||
&& options[opt_idx].var != NULL) {
|
p = _(*(char **)opt->var);
|
||||||
p = _(*(char **)options[opt_idx].var);
|
|
||||||
} else {
|
} else {
|
||||||
p = option_expand(opt_idx, NULL);
|
p = option_expand(opt_idx, NULL);
|
||||||
}
|
}
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
p = xstrdup(p);
|
p = xstrdup(p);
|
||||||
*(char **)options[opt_idx].var = p;
|
*(char **)opt->var = p;
|
||||||
if (options[opt_idx].flags & P_DEF_ALLOCED) {
|
if (opt->flags & P_DEF_ALLOCED) {
|
||||||
xfree(options[opt_idx].def_val);
|
xfree(opt->def_val);
|
||||||
}
|
}
|
||||||
options[opt_idx].def_val = p;
|
opt->def_val = p;
|
||||||
options[opt_idx].flags |= P_DEF_ALLOCED;
|
opt->flags |= P_DEF_ALLOCED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,32 +395,32 @@ void set_init_1(bool clean_arg)
|
|||||||
/// This does not take care of side effects!
|
/// This does not take care of side effects!
|
||||||
///
|
///
|
||||||
/// @param opt_flags OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL
|
/// @param opt_flags OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL
|
||||||
static void set_option_default(int opt_idx, int opt_flags)
|
static void set_option_default(const int opt_idx, int opt_flags)
|
||||||
{
|
{
|
||||||
int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
|
int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
|
||||||
|
|
||||||
// pointer to variable for current option
|
// pointer to variable for current option
|
||||||
char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
|
vimoption_T *opt = &options[opt_idx];
|
||||||
uint32_t flags = options[opt_idx].flags;
|
char_u *varp = (char_u *)get_varp_scope(opt, both ? OPT_LOCAL : opt_flags);
|
||||||
|
uint32_t flags = opt->flags;
|
||||||
if (varp != NULL) { // skip hidden option, nothing to do for it
|
if (varp != NULL) { // skip hidden option, nothing to do for it
|
||||||
if (flags & P_STRING) {
|
if (flags & P_STRING) {
|
||||||
// Use set_string_option_direct() for local options to handle
|
// Use set_string_option_direct() for local options to handle
|
||||||
// freeing and allocating the value.
|
// freeing and allocating the value.
|
||||||
if (options[opt_idx].indir != PV_NONE) {
|
if (opt->indir != PV_NONE) {
|
||||||
set_string_option_direct(NULL, opt_idx,
|
set_string_option_direct(NULL, opt_idx, opt->def_val, opt_flags, 0);
|
||||||
options[opt_idx].def_val, opt_flags, 0);
|
|
||||||
} else {
|
} else {
|
||||||
if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) {
|
if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) {
|
||||||
free_string_option(*(char **)(varp));
|
free_string_option(*(char **)(varp));
|
||||||
}
|
}
|
||||||
*(char **)varp = options[opt_idx].def_val;
|
*(char **)varp = opt->def_val;
|
||||||
options[opt_idx].flags &= ~P_ALLOCED;
|
opt->flags &= ~P_ALLOCED;
|
||||||
}
|
}
|
||||||
} else if (flags & P_NUM) {
|
} else if (flags & P_NUM) {
|
||||||
if (options[opt_idx].indir == PV_SCROLL) {
|
if (opt->indir == PV_SCROLL) {
|
||||||
win_comp_scroll(curwin);
|
win_comp_scroll(curwin);
|
||||||
} else {
|
} else {
|
||||||
long def_val = (long)options[opt_idx].def_val;
|
long def_val = (long)opt->def_val;
|
||||||
if ((long *)varp == &curwin->w_p_so
|
if ((long *)varp == &curwin->w_p_so
|
||||||
|| (long *)varp == &curwin->w_p_siso) {
|
|| (long *)varp == &curwin->w_p_siso) {
|
||||||
// 'scrolloff' and 'sidescrolloff' local values have a
|
// 'scrolloff' and 'sidescrolloff' local values have a
|
||||||
@@ -431,21 +431,21 @@ static void set_option_default(int opt_idx, int opt_flags)
|
|||||||
}
|
}
|
||||||
// May also set global value for local option.
|
// May also set global value for local option.
|
||||||
if (both) {
|
if (both) {
|
||||||
*(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
|
*(long *)get_varp_scope(opt, OPT_GLOBAL) =
|
||||||
def_val;
|
def_val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // P_BOOL
|
} else { // P_BOOL
|
||||||
*(int *)varp = (int)(intptr_t)options[opt_idx].def_val;
|
*(int *)varp = (int)(intptr_t)opt->def_val;
|
||||||
#ifdef UNIX
|
#ifdef UNIX
|
||||||
// 'modeline' defaults to off for root
|
// 'modeline' defaults to off for root
|
||||||
if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID) {
|
if (opt->indir == PV_ML && getuid() == ROOT_UID) {
|
||||||
*(int *)varp = false;
|
*(int *)varp = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// May also set global value for local option.
|
// May also set global value for local option.
|
||||||
if (both) {
|
if (both) {
|
||||||
*(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
|
*(int *)get_varp_scope(opt, OPT_GLOBAL) =
|
||||||
*(int *)varp;
|
*(int *)varp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -488,12 +488,13 @@ static void set_string_default(const char *name, char *val, bool allocated)
|
|||||||
{
|
{
|
||||||
int opt_idx = findoption(name);
|
int opt_idx = findoption(name);
|
||||||
if (opt_idx >= 0) {
|
if (opt_idx >= 0) {
|
||||||
if (options[opt_idx].flags & P_DEF_ALLOCED) {
|
vimoption_T *opt = &options[opt_idx];
|
||||||
xfree(options[opt_idx].def_val);
|
if (opt->flags & P_DEF_ALLOCED) {
|
||||||
|
xfree(opt->def_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
options[opt_idx].def_val = allocated ? val : xstrdup(val);
|
opt->def_val = allocated ? val : xstrdup(val);
|
||||||
options[opt_idx].flags |= P_DEF_ALLOCED;
|
opt->flags |= P_DEF_ALLOCED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user