aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-01-25 17:33:09 +0000
committerLewis Russell <lewis6991@gmail.com>2023-01-26 10:02:00 +0000
commit2c601787ab2fead995fdecce08d0bd21d23eb284 (patch)
treea9f052128440f7b6f13d126e62881ab89277d41c /src
parent9a9129c60b76cdfae5752071ec4c998c2f873c7c (diff)
downloadrneovim-2c601787ab2fead995fdecce08d0bd21d23eb284.tar.gz
rneovim-2c601787ab2fead995fdecce08d0bd21d23eb284.tar.bz2
rneovim-2c601787ab2fead995fdecce08d0bd21d23eb284.zip
refactor(option.c): factor out option name parsing
Diffstat (limited to 'src')
-rw-r--r--src/nvim/option.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index a54dd4d877..babbe7e1b3 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -1192,18 +1192,18 @@ static int get_option_prefix(char **argp)
return 1;
}
-static void do_set_option(int opt_flags, char **argp, bool *did_show, char *errbuf,
- size_t errbuflen, char **errmsg)
+/// @param[in] arg Pointer to start option name
+/// @param[out] opt_idxp Option index in options[] table.
+/// @param[out] keyp
+/// @param[out] len Length of option name
+/// @return FAIL if an error is detected, OK otherwise
+static int parse_option_name(char *arg, int *keyp, int *lenp, int *opt_idxp)
{
- // 1: nothing, 0: "no", 2: "inv" in front of name
- int prefix = get_option_prefix(argp);
-
- char *arg = *argp;
-
// find end of name
int key = 0;
int len;
int opt_idx;
+
if (*arg == '<') {
opt_idx = -1;
// look out for <t_>;>
@@ -1216,8 +1216,7 @@ static void do_set_option(int opt_flags, char **argp, bool *did_show, char *errb
}
}
if (arg[len] != '>') {
- *errmsg = e_invarg;
- return;
+ return FAIL;
}
if (arg[1] == 't' && arg[2] == '_') { // could be term code
opt_idx = findoption_len((const char *)arg + 1, (size_t)(len - 1));
@@ -1242,6 +1241,30 @@ static void do_set_option(int opt_flags, char **argp, bool *did_show, char *errb
}
}
+ *keyp = key;
+ *lenp = len;
+ *opt_idxp = opt_idx;
+
+ return OK;
+}
+
+static void do_set_option(int opt_flags, char **argp, bool *did_show, char *errbuf,
+ size_t errbuflen, char **errmsg)
+{
+ // 1: nothing, 0: "no", 2: "inv" in front of name
+ int prefix = get_option_prefix(argp);
+
+ char *arg = *argp;
+
+ // find end of name
+ int key = 0;
+ int len;
+ int opt_idx;
+ if (parse_option_name(arg, &key, &len, &opt_idx) == FAIL) {
+ *errmsg = e_invarg;
+ return;
+ }
+
// remember character after option name
int afterchar = (uint8_t)arg[len];