mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
refactor(optionstr.c): break up did_set_string_option 52
This commit is contained in:
@@ -640,6 +640,17 @@ char *check_stl_option(char *s)
|
|||||||
|
|
||||||
static int shada_idx = -1;
|
static int shada_idx = -1;
|
||||||
|
|
||||||
|
static bool check_illegal_path_names(char *val, uint32_t flags)
|
||||||
|
{
|
||||||
|
// Disallow a path separator (slash and/or backslash), wildcards and
|
||||||
|
// characters that are often illegal in a file name. Be more permissive
|
||||||
|
// if "secure" is off.
|
||||||
|
return (((flags & P_NFNAME)
|
||||||
|
&& strpbrk(val, (secure ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
|
||||||
|
|| ((flags & P_NDNAME)
|
||||||
|
&& strpbrk(val, "*?[|;&<>\r\n") != NULL));
|
||||||
|
}
|
||||||
|
|
||||||
static void did_set_backupcopy(buf_T *buf, char *oldval, int opt_flags, char **errmsg)
|
static void did_set_backupcopy(buf_T *buf, char *oldval, int opt_flags, char **errmsg)
|
||||||
{
|
{
|
||||||
char *bkc = p_bkc;
|
char *bkc = p_bkc;
|
||||||
@@ -687,6 +698,17 @@ static void did_set_breakindentopt(win_T *win, char **errmsg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void did_set_isopt(buf_T *buf, bool *did_chartab, char **errmsg)
|
||||||
|
{
|
||||||
|
// 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
|
||||||
|
// If the new option is invalid, use old value. 'lisp' option: refill
|
||||||
|
// g_chartab[] for '-' char
|
||||||
|
if (buf_init_chartab(buf, true) == FAIL) {
|
||||||
|
*did_chartab = true; // need to restore it below
|
||||||
|
*errmsg = e_invarg; // error in value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void did_set_helpfile(void)
|
static void did_set_helpfile(void)
|
||||||
{
|
{
|
||||||
// May compute new values for $VIM and $VIMRUNTIME
|
// May compute new values for $VIM and $VIMRUNTIME
|
||||||
@@ -1623,7 +1645,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf
|
|||||||
int opt_flags, int *value_checked)
|
int opt_flags, int *value_checked)
|
||||||
{
|
{
|
||||||
char *errmsg = NULL;
|
char *errmsg = NULL;
|
||||||
int did_chartab = false;
|
bool did_chartab = false;
|
||||||
vimoption_T *opt = get_option(opt_idx);
|
vimoption_T *opt = get_option(opt_idx);
|
||||||
bool free_oldval = (opt->flags & P_ALLOCED);
|
bool free_oldval = (opt->flags & P_ALLOCED);
|
||||||
bool value_changed = false;
|
bool value_changed = false;
|
||||||
@@ -1636,13 +1658,8 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf
|
|||||||
if ((secure || sandbox != 0)
|
if ((secure || sandbox != 0)
|
||||||
&& (opt->flags & P_SECURE)) {
|
&& (opt->flags & P_SECURE)) {
|
||||||
errmsg = e_secure;
|
errmsg = e_secure;
|
||||||
} else if (((opt->flags & P_NFNAME)
|
} else if (check_illegal_path_names(*varp, opt->flags)) {
|
||||||
&& strpbrk(*varp, (secure ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
|
// Check for a "normal" directory or file name in some options.
|
||||||
|| ((opt->flags & P_NDNAME)
|
|
||||||
&& strpbrk(*varp, "*?[|;&<>\r\n") != NULL)) {
|
|
||||||
// Check for a "normal" directory or file name in some options. Disallow a
|
|
||||||
// path separator (slash and/or backslash), wildcards and characters that
|
|
||||||
// are often illegal in a file name. Be more permissive if "secure" is off.
|
|
||||||
errmsg = e_invarg;
|
errmsg = e_invarg;
|
||||||
} else if (gvarp == &p_bkc) { // 'backupcopy'
|
} else if (gvarp == &p_bkc) { // 'backupcopy'
|
||||||
did_set_backupcopy(curbuf, oldval, opt_flags, &errmsg);
|
did_set_backupcopy(curbuf, oldval, opt_flags, &errmsg);
|
||||||
@@ -1654,13 +1671,8 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf
|
|||||||
|| varp == &(curbuf->b_p_isk)
|
|| varp == &(curbuf->b_p_isk)
|
||||||
|| varp == &p_isp
|
|| varp == &p_isp
|
||||||
|| varp == &p_isf) {
|
|| varp == &p_isf) {
|
||||||
// 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
|
// 'isident', 'iskeyword', 'isprint or 'isfname' option
|
||||||
// If the new option is invalid, use old value. 'lisp' option: refill
|
did_set_isopt(buf, &did_chartab, &errmsg);
|
||||||
// g_chartab[] for '-' char
|
|
||||||
if (init_chartab() == FAIL) {
|
|
||||||
did_chartab = true; // need to restore it below
|
|
||||||
errmsg = e_invarg; // error in value
|
|
||||||
}
|
|
||||||
} else if (varp == &p_hf) { // 'helpfile'
|
} else if (varp == &p_hf) { // 'helpfile'
|
||||||
did_set_helpfile();
|
did_set_helpfile();
|
||||||
} else if (varp == &p_rtp || varp == &p_pp) { // 'runtimepath' 'packpath'
|
} else if (varp == &p_rtp || varp == &p_pp) { // 'runtimepath' 'packpath'
|
||||||
@@ -1868,7 +1880,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf
|
|||||||
*varp = oldval;
|
*varp = oldval;
|
||||||
// When resetting some values, need to act on it.
|
// When resetting some values, need to act on it.
|
||||||
if (did_chartab) {
|
if (did_chartab) {
|
||||||
(void)init_chartab();
|
(void)buf_init_chartab(buf, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Remember where the option was set.
|
// Remember where the option was set.
|
||||||
|
Reference in New Issue
Block a user