diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-01-19 09:51:57 +0000 |
---|---|---|
committer | Lewis Russell <lewis6991@gmail.com> | 2023-01-25 11:48:52 +0000 |
commit | d5119db2fa9a1a5a43f44d13ac06b95958e7061c (patch) | |
tree | f644f8a8fe986d45e92ca09f4ae24d1d70b7bb5f /src | |
parent | 8fd3d2b61fdf0fd29801903f04cdf37cfa27f0e6 (diff) | |
download | rneovim-d5119db2fa9a1a5a43f44d13ac06b95958e7061c.tar.gz rneovim-d5119db2fa9a1a5a43f44d13ac06b95958e7061c.tar.bz2 rneovim-d5119db2fa9a1a5a43f44d13ac06b95958e7061c.zip |
refactor(optionstr.c): break up did_set_string_option 1
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/optionstr.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index b4383b6794..89cbf8ffd2 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -640,6 +640,34 @@ char *check_stl_option(char *s) static int shada_idx = -1; +static void did_set_backupcopy(buf_T *buf, char *oldval, int opt_flags, char **errmsg) +{ + char *bkc = p_bkc; + unsigned int *flags = &bkc_flags; + + if (opt_flags & OPT_LOCAL) { + bkc = buf->b_p_bkc; + flags = &buf->b_bkc_flags; + } + + if ((opt_flags & OPT_LOCAL) && *bkc == NUL) { + // make the local value empty: use the global value + *flags = 0; + } else { + if (opt_strings_flags(bkc, p_bkc_values, flags, true) != OK) { + *errmsg = e_invarg; + } + + if (((*flags & BKC_AUTO) != 0) + + ((*flags & BKC_YES) != 0) + + ((*flags & BKC_NO) != 0) != 1) { + // Must have exactly one of "auto", "yes" and "no". + (void)opt_strings_flags(oldval, p_bkc_values, flags, true); + *errmsg = e_invarg; + } + } +} + /// Handle string options that need some action to perform when changed. /// The new value must be allocated. /// @@ -678,30 +706,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf // are often illegal in a file name. Be more permissive if "secure" is off. errmsg = e_invarg; } else if (gvarp == &p_bkc) { // 'backupcopy' - char *bkc = p_bkc; - unsigned int *flags = &bkc_flags; - - if (opt_flags & OPT_LOCAL) { - bkc = curbuf->b_p_bkc; - flags = &curbuf->b_bkc_flags; - } - - if ((opt_flags & OPT_LOCAL) && *bkc == NUL) { - // make the local value empty: use the global value - *flags = 0; - } else { - if (opt_strings_flags(bkc, p_bkc_values, flags, true) != OK) { - errmsg = e_invarg; - } - - if (((*flags & BKC_AUTO) != 0) - + ((*flags & BKC_YES) != 0) - + ((*flags & BKC_NO) != 0) != 1) { - // Must have exactly one of "auto", "yes" and "no". - (void)opt_strings_flags(oldval, p_bkc_values, flags, true); - errmsg = e_invarg; - } - } + did_set_backupcopy(curbuf, oldval, opt_flags, &errmsg); } else if (varp == &p_bex || varp == &p_pm) { // 'backupext' and 'patchmode' if (strcmp(*p_bex == '.' ? p_bex + 1 : p_bex, *p_pm == '.' ? p_pm + 1 : p_pm) == 0) { |