aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-01-26 09:59:37 +0000
committerLewis Russell <lewis6991@gmail.com>2023-01-26 10:26:07 +0000
commit0170219e92ce211d935b78895825000f074c4cff (patch)
tree63c09070cac5433dab1674e7047044e2f23352e9
parentc6907ea895694ea675ba8c912c3d8e9f67f5c7d4 (diff)
downloadrneovim-0170219e92ce211d935b78895825000f074c4cff.tar.gz
rneovim-0170219e92ce211d935b78895825000f074c4cff.tar.bz2
rneovim-0170219e92ce211d935b78895825000f074c4cff.zip
refactor(option.c): move bool prefix check
-rw-r--r--src/nvim/option.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 1d5ceb70e6..50ccf9d302 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -1248,8 +1248,15 @@ static int parse_option_name(char *arg, int *keyp, int *lenp, int *opt_idxp)
return OK;
}
-static int validate_opt_idx(win_T *win, int opt_idx, int opt_flags, uint32_t flags, char **errmsg)
+static int validate_opt_idx(win_T *win, int opt_idx, int opt_flags, uint32_t flags, int prefix,
+ char **errmsg)
{
+ // Only bools can have a prefix of 'inv' or 'no'
+ if (!(flags & P_BOOL) && prefix != 1) {
+ *errmsg = e_invarg;
+ return FAIL;
+ }
+
// Skip all options that are not window-local (used when showing
// an already loaded buffer in a window).
if ((opt_flags & OPT_WINONLY)
@@ -1351,7 +1358,7 @@ static void do_set_option(int opt_flags, char **argp, bool *did_show, char *errb
flags = P_STRING;
}
- if (validate_opt_idx(curwin, opt_idx, opt_flags, flags, errmsg) == FAIL) {
+ if (validate_opt_idx(curwin, opt_idx, opt_flags, flags, prefix, errmsg) == FAIL) {
return;
}
@@ -1408,24 +1415,22 @@ static void do_set_option(int opt_flags, char **argp, bool *did_show, char *errb
return;
}
+ if (!(flags & P_BOOL) && vim_strchr("=:&<", nextchar) == NULL) {
+ *errmsg = e_invarg;
+ return;
+ }
+
int value_checked = false;
- if (flags & P_BOOL) { // boolean
+ if (flags & P_BOOL) { // boolean
do_set_bool(opt_idx, opt_flags, prefix, nextchar, afterchar, varp, errmsg);
- } else { // Numeric or string.
- if (vim_strchr("=:&<", nextchar) == NULL || prefix != 1) {
- *errmsg = e_invarg;
- return;
- }
-
- if (flags & P_NUM) { // numeric
- do_set_num(opt_idx, opt_flags, argp, nextchar, op, varp, errbuf, errbuflen, errmsg);
- } else if (opt_idx >= 0) { // String.
- do_set_string(opt_idx, opt_flags, argp, nextchar, op, flags, varp, errbuf,
- errbuflen, &value_checked, errmsg);
- } else {
- // key code option(FIXME(tarruda): Show a warning or something
- // similar)
- }
+ } else if (flags & P_NUM) { // numeric
+ do_set_num(opt_idx, opt_flags, argp, nextchar, op, varp, errbuf, errbuflen, errmsg);
+ } else if (opt_idx >= 0) { // string.
+ do_set_string(opt_idx, opt_flags, argp, nextchar, op, flags, varp, errbuf,
+ errbuflen, &value_checked, errmsg);
+ } else {
+ // key code option(FIXME(tarruda): Show a warning or something
+ // similar)
}
if (*errmsg != NULL) {