diff options
author | Famiu Haque <famiuhaque@proton.me> | 2023-12-07 23:59:30 +0600 |
---|---|---|
committer | Famiu Haque <famiuhaque@proton.me> | 2023-12-09 17:54:43 +0600 |
commit | bf3bc1cec9f00b9644815001a8732ecedf3ce07f (patch) | |
tree | ab98b7277c368b8c37ddac13d9e27299a45b60b2 /src/nvim/option.c | |
parent | 6346987601a28b00564295ee8be0a8b00d9ff911 (diff) | |
download | rneovim-bf3bc1cec9f00b9644815001a8732ecedf3ce07f.tar.gz rneovim-bf3bc1cec9f00b9644815001a8732ecedf3ce07f.tar.bz2 rneovim-bf3bc1cec9f00b9644815001a8732ecedf3ce07f.zip |
refactor(options): convert `opt_idx` variables to `OptIndex`
Diffstat (limited to 'src/nvim/option.c')
-rw-r--r-- | src/nvim/option.c | 191 |
1 files changed, 95 insertions, 96 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 71d9a2800c..cf469d6e5e 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -157,12 +157,12 @@ typedef enum { #endif static int p_bin_dep_opts[] = { - kOptTextwidth, kOptWrapmargin, kOptModeline, kOptExpandtab, -1 + kOptTextwidth, kOptWrapmargin, kOptModeline, kOptExpandtab, kOptInvalid }; static int p_paste_dep_opts[] = { - kOptAutoindent, kOptExpandtab, kOptRuler, kOptShowmatch, kOptSmarttab, - kOptSofttabstop, kOptTextwidth, kOptWrapmargin, kOptRevins, kOptVarsofttabstop, -1 + kOptAutoindent, kOptExpandtab, kOptRuler, kOptShowmatch, kOptSmarttab, kOptSofttabstop, + kOptTextwidth, kOptWrapmargin, kOptRevins, kOptVarsofttabstop, kOptInvalid }; void set_init_tablocal(void) @@ -199,7 +199,7 @@ static void set_init_default_backupskip(void) static char *(names[3]) = { "TMPDIR", "TEMP", "TMP" }; #endif garray_T ga; - int opt_idx = kOptBackupskip; + OptIndex opt_idx = kOptBackupskip; ga_init(&ga, 1, 100); for (size_t n = 0; n < ARRAY_SIZE(names); n++) { @@ -269,8 +269,8 @@ static void set_init_default_cdpath(void) } } buf[j] = NUL; - int opt_idx = kOptCdpath; - if (opt_idx >= 0) { + OptIndex opt_idx = kOptCdpath; + if (opt_idx != kOptInvalid) { options[opt_idx].def_val = buf; options[opt_idx].flags |= P_DEF_ALLOCED; } else { @@ -288,7 +288,7 @@ static void set_init_default_cdpath(void) /// default. static void set_init_expand_env(void) { - for (int opt_idx = 0; options[opt_idx].fullname; opt_idx++) { + for (OptIndex opt_idx = 0; options[opt_idx].fullname; opt_idx++) { vimoption_T *opt = &options[opt_idx]; if (opt->flags & P_NO_DEF_EXP) { continue; @@ -420,7 +420,7 @@ void set_init_1(bool clean_arg) /// This does not take care of side effects! /// /// @param opt_flags OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL -static void set_option_default(const int opt_idx, int opt_flags) +static void set_option_default(const OptIndex opt_idx, int opt_flags) { int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; @@ -507,10 +507,10 @@ static void set_options_default(int opt_flags) /// @param opt_idx Option index in options[] table. /// @param val The value of the option. /// @param allocated If true, do not copy default as it was already allocated. -static void set_string_default(int opt_idx, char *val, bool allocated) +static void set_string_default(OptIndex opt_idx, char *val, bool allocated) FUNC_ATTR_NONNULL_ALL { - if (opt_idx < 0) { + if (opt_idx == kOptInvalid) { return; } @@ -556,9 +556,9 @@ static char *find_dup_item(char *origval, const char *newval, uint32_t flags) /// Set the Vi-default value of a number option. /// Used for 'lines' and 'columns'. -void set_number_default(int opt_idx, OptInt val) +void set_number_default(OptIndex opt_idx, OptInt val) { - if (opt_idx >= 0) { + if (opt_idx != kOptInvalid) { options[opt_idx].def_val = (void *)(intptr_t)val; } } @@ -744,7 +744,7 @@ void ex_set(exarg_T *eap) } /// Get the default value for a string option. -static char *stropt_get_default_val(int opt_idx, uint64_t flags) +static char *stropt_get_default_val(OptIndex opt_idx, uint64_t flags) { char *newval = options[opt_idx].def_val; // expand environment variables and ~ since the default value was @@ -813,7 +813,7 @@ static char *stropt_copy_value(char *origval, char **argp, set_op_T op, } /// Expand environment variables and ~ in string option value 'newval'. -static char *stropt_expand_envvar(int opt_idx, char *origval, char *newval, set_op_T op) +static char *stropt_expand_envvar(OptIndex opt_idx, char *origval, char *newval, set_op_T op) { char *s = option_expand(opt_idx, newval); if (s == NULL) { @@ -913,8 +913,8 @@ static void stropt_remove_dupflags(char *newval, uint32_t flags) /// set {opt}< /// set {opt}={val} /// set {opt}:{val} -static char *stropt_get_newval(int nextchar, int opt_idx, char **argp, void *varp, char *origval, - set_op_T *op_arg, uint32_t flags) +static char *stropt_get_newval(int nextchar, OptIndex opt_idx, char **argp, void *varp, + char *origval, set_op_T *op_arg, uint32_t flags) { char *arg = *argp; set_op_T op = *op_arg; @@ -1020,15 +1020,15 @@ static set_prefix_T get_option_prefix(char **argp) /// @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) +static int parse_option_name(char *arg, int *keyp, int *lenp, OptIndex *opt_idxp) { // find end of name int key = 0; int len; - int opt_idx; + OptIndex opt_idx; if (*arg == '<') { - opt_idx = -1; + opt_idx = kOptInvalid; // look out for <t_>;> if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4]) { len = 5; @@ -1045,7 +1045,7 @@ static int parse_option_name(char *arg, int *keyp, int *lenp, int *opt_idxp) opt_idx = findoption_len(arg + 1, (size_t)(len - 1)); } len++; - if (opt_idx == -1) { + if (opt_idx == kOptInvalid) { key = find_key_option(arg + 1, true); } } else { @@ -1059,7 +1059,7 @@ static int parse_option_name(char *arg, int *keyp, int *lenp, int *opt_idxp) } } opt_idx = findoption_len(arg, (size_t)len); - if (opt_idx == -1) { + if (opt_idx == kOptInvalid) { key = find_key_option(arg, false); } } @@ -1071,7 +1071,7 @@ 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, +static int validate_opt_idx(win_T *win, OptIndex opt_idx, int opt_flags, uint32_t flags, set_prefix_T prefix, const char **errmsg) { // Only bools can have a prefix of 'inv' or 'no' @@ -1083,12 +1083,12 @@ static int validate_opt_idx(win_T *win, int opt_idx, int opt_flags, uint32_t fla // Skip all options that are not window-local (used when showing // an already loaded buffer in a window). if ((opt_flags & OPT_WINONLY) - && (opt_idx < 0 || options[opt_idx].var != VAR_WIN)) { + && (opt_idx == kOptInvalid || options[opt_idx].var != VAR_WIN)) { return FAIL; } // Skip all options that are window-local (used for :vimgrep). - if ((opt_flags & OPT_NOWIN) && opt_idx >= 0 + if ((opt_flags & OPT_NOWIN) && opt_idx != kOptInvalid && options[opt_idx].var == VAR_WIN) { return FAIL; } @@ -1107,7 +1107,7 @@ static int validate_opt_idx(win_T *win, int opt_idx, int opt_flags, uint32_t fla // 'foldmethod' becomes "marker" instead of "diff" and that // "wrap" gets set. if (win->w_p_diff - && opt_idx >= 0 // shut up coverity warning + && opt_idx != kOptInvalid // shut up coverity warning && (options[opt_idx].indir == PV_FDM || options[opt_idx].indir == PV_WRAP)) { return FAIL; @@ -1124,7 +1124,7 @@ static int validate_opt_idx(win_T *win, int opt_idx, int opt_flags, uint32_t fla } /// Get new option value from argp. Allocated OptVal must be freed by caller. -static OptVal get_option_newval(int opt_idx, int opt_flags, set_prefix_T prefix, char **argp, +static OptVal get_option_newval(OptIndex opt_idx, int opt_flags, set_prefix_T prefix, char **argp, int nextchar, set_op_T op, uint32_t flags, void *varp, char *errbuf, const size_t errbuflen, const char **errmsg) FUNC_ATTR_WARN_UNUSED_RESULT @@ -1264,7 +1264,7 @@ static void do_one_set_option(int opt_flags, char **argp, bool *did_show, char * // find end of name int key = 0; int len; - int opt_idx; + OptIndex opt_idx; if (parse_option_name(arg, &key, &len, &opt_idx) == FAIL) { *errmsg = e_invarg; return; @@ -1285,7 +1285,7 @@ static void do_one_set_option(int opt_flags, char **argp, bool *did_show, char * uint8_t nextchar = (uint8_t)arg[len]; // next non-white char after option name - if (opt_idx == -1 && key == 0) { // found a mismatch: skip + if (opt_idx == kOptInvalid && key == 0) { // found a mismatch: skip *errmsg = e_unknown_option; return; } @@ -1293,7 +1293,7 @@ static void do_one_set_option(int opt_flags, char **argp, bool *did_show, char * uint32_t flags; // flags for current option void *varp = NULL; // pointer to variable for current option - if (opt_idx >= 0) { + if (opt_idx != kOptInvalid) { if (options[opt_idx].var == NULL) { // hidden option: skip // Only give an error message when requesting the value of // a hidden option, ignore setting it. @@ -1346,7 +1346,7 @@ static void do_one_set_option(int opt_flags, char **argp, bool *did_show, char * gotocmdline(true); // cursor at status line *did_show = true; // remember that we did a line } - if (opt_idx >= 0) { + if (opt_idx != kOptInvalid) { showoneopt(&options[opt_idx], opt_flags); if (p_verbose > 0) { // Mention where the option was last set. @@ -1614,7 +1614,7 @@ char *find_shada_parameter(int type) /// These string options cannot be indirect! /// If "val" is NULL expand the current value of the option. /// Return pointer to NameBuff, or NULL when not expanded. -static char *option_expand(int opt_idx, char *val) +static char *option_expand(OptIndex opt_idx, char *val) { // if option doesn't need expansion nothing to do if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL) { @@ -1689,7 +1689,7 @@ static void didset_options2(void) /// Check for string options that are NULL (normally only termcap options). void check_options(void) { - for (int opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++) { + for (OptIndex opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++) { if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL) { check_string_option((char **)get_varp(&(options[opt_idx]))); } @@ -1703,9 +1703,9 @@ void check_options(void) /// @param opt_flags Option flags. /// /// @return True if option was set from a modeline or in secure mode, false if it wasn't. -int was_set_insecurely(win_T *const wp, int opt_idx, int opt_flags) +int was_set_insecurely(win_T *const wp, OptIndex opt_idx, int opt_flags) { - assert(opt_idx >= 0); + assert(opt_idx != kOptInvalid); uint32_t *flagp = insecure_flag(wp, opt_idx, opt_flags); return (*flagp & P_INSECURE) != 0; @@ -1715,7 +1715,7 @@ int was_set_insecurely(win_T *const wp, int opt_idx, int opt_flags) /// "opt_idx". For some local options a local flags field is used. /// NOTE: Caller must make sure that "wp" is set to the window from which /// the option is used. -uint32_t *insecure_flag(win_T *const wp, int opt_idx, int opt_flags) +uint32_t *insecure_flag(win_T *const wp, OptIndex opt_idx, int opt_flags) { if (opt_flags & OPT_LOCAL) { assert(wp != NULL); @@ -1819,15 +1819,15 @@ bool parse_winhl_opt(win_T *wp) } /// Get the script context of global option at index opt_idx. -sctx_T *get_option_sctx(int opt_idx) +sctx_T *get_option_sctx(OptIndex opt_idx) { - assert(opt_idx >= 0); + assert(opt_idx != kOptInvalid); return &options[opt_idx].last_set.script_ctx; } /// Set the script_ctx for an option, taking care of setting the buffer- or /// window-local value. -void set_option_sctx(int opt_idx, int opt_flags, sctx_T script_ctx) +void set_option_sctx(OptIndex opt_idx, int opt_flags, sctx_T script_ctx) { int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; int indir = (int)options[opt_idx].indir; @@ -1861,7 +1861,7 @@ void set_option_sctx(int opt_idx, int opt_flags, sctx_T script_ctx) } /// Apply the OptionSet autocommand. -static void apply_optionset_autocmd(int opt_idx, int opt_flags, OptVal oldval, OptVal oldval_g, +static void apply_optionset_autocmd(OptIndex opt_idx, int opt_flags, OptVal oldval, OptVal oldval_g, OptVal oldval_l, OptVal newval, const char *errmsg) { // Don't do this while starting up, failure or recursively. @@ -3013,8 +3013,8 @@ void check_redraw(uint32_t flags) /// @param[in] arg Option to find index for. /// @param[in] len Length of the option. /// -/// @return Index of the option or -1 if option was not found. -int findoption_len(const char *const arg, const size_t len) +/// @return Index of the option or kOptInvalid if option was not found. +OptIndex findoption_len(const char *const arg, const size_t len) { const char *s; static int quick_tab[27] = { 0, 0 }; // quick access table @@ -3038,10 +3038,10 @@ int findoption_len(const char *const arg, const size_t len) // Check for name starting with an illegal character. if (len == 0 || arg[0] < 'a' || arg[0] > 'z') { - return -1; + return kOptInvalid; } - int opt_idx; + OptIndex opt_idx; const bool is_term_opt = (len > 2 && arg[0] == 't' && arg[1] == '_'); if (is_term_opt) { opt_idx = quick_tab[26]; @@ -3069,7 +3069,7 @@ int findoption_len(const char *const arg, const size_t len) } } if (s == NULL) { - opt_idx = -1; + opt_idx = kOptInvalid; } else { // Nvim: handle option aliases. if (strncmp(options[opt_idx].fullname, "viminfo", 7) == 0) { @@ -3143,8 +3143,8 @@ bool set_tty_option(const char *name, char *value) /// /// @param[in] arg Option name. /// -/// @return Option index or -1 if option was not found. -int findoption(const char *const arg) +/// @return Option index or kOptInvalid if option was not found. +OptIndex findoption(const char *const arg) FUNC_ATTR_NONNULL_ALL { return findoption_len(arg, strlen(arg)); @@ -3204,9 +3204,9 @@ bool optval_equal(OptVal o1, OptVal o2) /// Match type of OptVal with the type of the target option. Returns true if the types match and /// false otherwise. -static bool optval_match_type(OptVal o, int opt_idx) +static bool optval_match_type(OptVal o, OptIndex opt_idx) { - assert(opt_idx >= 0); + assert(opt_idx != kOptInvalid); uint32_t flags = options[opt_idx].flags; switch (o.type) { @@ -3226,7 +3226,7 @@ static bool optval_match_type(OptVal o, int opt_idx) /// /// @param opt_idx Option index in options[] table. /// @param[out] varp Pointer to option variable. -OptVal optval_from_varp(int opt_idx, void *varp) +OptVal optval_from_varp(OptIndex opt_idx, void *varp) { // Special case: 'modified' is b_changed, but we also want to consider it set when 'ff' or 'fenc' // changed. @@ -3266,7 +3266,7 @@ OptVal optval_from_varp(int opt_idx, void *varp) /// @param[out] varp Pointer to option variable. /// @param[in] value New option value. /// @param free_oldval Free old value. -static void set_option_varp(int opt_idx, void *varp, OptVal value, bool free_oldval) +static void set_option_varp(OptIndex opt_idx, void *varp, OptVal value, bool free_oldval) FUNC_ATTR_NONNULL_ARG(2) { assert(optval_match_type(value, opt_idx)); @@ -3362,7 +3362,7 @@ OptVal object_as_optval(Object o, bool *error) /// @param[in] varp Pointer to option variable. /// /// @return [allocated] Option value equal to the unset value for the option. -static OptVal optval_unset_local(int opt_idx, void *varp) +static OptVal optval_unset_local(OptIndex opt_idx, void *varp) { vimoption_T *opt = &options[opt_idx]; // For global-local options, use the unset value of the local value. @@ -3391,7 +3391,7 @@ static OptVal optval_unset_local(int opt_idx, void *varp) /// For options with a singular type, it returns the name of the type. For options with multiple /// possible types, it returns a slash separated list of types. For example, if an option can be a /// number, boolean or string, the function returns "Number/Boolean/String" -static char *option_get_valid_types(int opt_idx) +static char *option_get_valid_types(OptIndex opt_idx) { uint32_t flags = options[opt_idx].flags; uint32_t type_count = 0; @@ -3435,9 +3435,9 @@ static char *option_get_valid_types(int opt_idx) /// @param opt_idx Option index in options[] table. /// /// @return True if option is hidden, false otherwise. Returns false if option name is invalid. -bool is_option_hidden(int opt_idx) +bool is_option_hidden(OptIndex opt_idx) { - return opt_idx < 0 ? false : get_varp(&options[opt_idx]) == NULL; + return opt_idx == kOptInvalid ? false : get_varp(&options[opt_idx]) == NULL; } /// Get option flags. @@ -3445,9 +3445,9 @@ bool is_option_hidden(int opt_idx) /// @param opt_idx Option index in options[] table. /// /// @return Option flags. Returns 0 for invalid option name. -uint32_t get_option_flags(int opt_idx) +uint32_t get_option_flags(OptIndex opt_idx) { - return opt_idx < 0 ? 0 : options[opt_idx].flags; + return opt_idx == kOptInvalid ? 0 : options[opt_idx].flags; } /// Gets the value for an option. @@ -3456,9 +3456,9 @@ uint32_t get_option_flags(int opt_idx) /// @param[in] scope Option scope (can be OPT_LOCAL, OPT_GLOBAL or a combination). /// /// @return [allocated] Option value. Returns NIL_OPTVAL for invalid option index. -OptVal get_option_value(int opt_idx, int scope) +OptVal get_option_value(OptIndex opt_idx, int scope) { - if (opt_idx < 0) { // option not in the options[] table. + if (opt_idx == kOptInvalid) { // option not in the options[] table. return NIL_OPTVAL; } @@ -3469,8 +3469,9 @@ OptVal get_option_value(int opt_idx, int scope) } /// Return information for option at 'opt_idx' -vimoption_T *get_option(int opt_idx) +vimoption_T *get_option(OptIndex opt_idx) { + assert(opt_idx != kOptInvalid); return &options[opt_idx]; } @@ -3496,7 +3497,7 @@ static bool is_option_local_value_unset(vimoption_T *opt, buf_T *buf, win_T *win /// Handle side-effects of setting an option. /// -/// @param opt_idx Index in options[] table. Must be >= 0. +/// @param opt_idx Index in options[] table. Must not be kOptInvalid. /// @param[in] varp Option variable pointer, cannot be NULL. /// @param old_value Old option value. /// @param new_value New option value. @@ -3507,7 +3508,7 @@ static bool is_option_local_value_unset(vimoption_T *opt, buf_T *buf, win_T *win /// @param errbuflen Length of error buffer. /// /// @return NULL on success, an untranslated error message on error. -static const char *did_set_option(int opt_idx, void *varp, OptVal old_value, OptVal new_value, +static const char *did_set_option(OptIndex opt_idx, void *varp, OptVal old_value, OptVal new_value, int opt_flags, bool *value_checked, bool value_replaced, char *errbuf, size_t errbuflen) { @@ -3654,7 +3655,7 @@ static const char *did_set_option(int opt_idx, void *varp, OptVal old_value, Opt /// Set the value of an option using an OptVal. /// -/// @param opt_idx Index in options[] table. Must be >= 0. +/// @param opt_idx Index in options[] table. Must not be kOptInvalid. /// @param[in] varp Option variable pointer, cannot be NULL. /// @param value New option value. Might get freed. /// @param opt_flags Option flags. @@ -3663,10 +3664,10 @@ static const char *did_set_option(int opt_idx, void *varp, OptVal old_value, Opt /// @param errbuflen Length of error buffer. /// /// @return NULL on success, an untranslated error message on error. -static const char *set_option(const int opt_idx, void *varp, OptVal value, int opt_flags, +static const char *set_option(const OptIndex opt_idx, void *varp, OptVal value, int opt_flags, const bool value_replaced, char *errbuf, size_t errbuflen) { - assert(opt_idx >= 0 && varp != NULL); + assert(opt_idx != kOptInvalid && varp != NULL); const char *errmsg = NULL; bool value_checked = false; @@ -3796,14 +3797,14 @@ err: /// Set the value of an option. /// -/// @param opt_idx Index in options[] table. Must be >= 0. +/// @param opt_idx Index in options[] table. Must not be kOptInvalid. /// @param[in] value Option value. If NIL_OPTVAL, the option value is cleared. /// @param[in] opt_flags Flags: OPT_LOCAL, OPT_GLOBAL, or 0 (both). /// /// @return NULL on success, an untranslated error message on error. -const char *set_option_value(const int opt_idx, const OptVal value, int opt_flags) +const char *set_option_value(const OptIndex opt_idx, const OptVal value, int opt_flags) { - assert(opt_idx >= 0); + assert(opt_idx != kOptInvalid); static char errbuf[IOSIZE]; uint32_t flags = options[opt_idx].flags; @@ -3832,13 +3833,13 @@ const char *set_option_value(const int opt_idx, const OptVal value, int opt_flag /// @param[in] opt_flags Flags: OPT_LOCAL, OPT_GLOBAL, or 0 (both). /// /// @return NULL on success, an untranslated error message on error. -const char *set_option_value_handle_tty(const char *name, int opt_idx, const OptVal value, +const char *set_option_value_handle_tty(const char *name, OptIndex opt_idx, const OptVal value, int opt_flags) FUNC_ATTR_NONNULL_ARG(1) { static char errbuf[IOSIZE]; - if (opt_idx < 0) { + if (opt_idx == kOptInvalid) { if (is_tty_option(name)) { return NULL; // Fail silently; many old vimrcs set t_xx options. } @@ -3855,7 +3856,7 @@ const char *set_option_value_handle_tty(const char *name, int opt_idx, const Opt /// @param opt_idx Option index in options[] table. /// @param value Option value. If NIL_OPTVAL, the option value is cleared. /// @param opt_flags OPT_LOCAL or 0 (both) -void set_option_value_give_err(const int opt_idx, OptVal value, int opt_flags) +void set_option_value_give_err(const OptIndex opt_idx, OptVal value, int opt_flags) { const char *errmsg = set_option_value(opt_idx, value, opt_flags); @@ -4003,7 +4004,7 @@ static int optval_default(vimoption_T *p, const void *varp) /// Send update to UIs with values of UI relevant options void ui_refresh_options(void) { - for (int opt_idx = 0; options[opt_idx].fullname; opt_idx++) { + for (OptIndex opt_idx = 0; options[opt_idx].fullname; opt_idx++) { uint32_t flags = options[opt_idx].flags; if (!(flags & P_UI_OPTION)) { continue; @@ -4382,7 +4383,7 @@ void *get_varp_scope(vimoption_T *p, int scope) /// Get pointer to option variable at 'opt_idx', depending on local or global /// scope. -void *get_option_varp_scope_from(int opt_idx, int scope, buf_T *buf, win_T *win) +void *get_option_varp_scope_from(OptIndex opt_idx, int scope, buf_T *buf, win_T *win) { return get_varp_scope_from(&(options[opt_idx]), scope, buf, win); } @@ -4849,19 +4850,19 @@ void didset_window_options(win_T *wp, bool valid_cursor) } /// Index into the options table for a buffer-local option enum. -static int buf_opt_idx[BV_COUNT]; +static OptIndex buf_opt_idx[BV_COUNT]; #define COPY_OPT_SCTX(buf, bv) buf->b_p_script_ctx[bv] = options[buf_opt_idx[bv]].last_set /// Initialize buf_opt_idx[] if not done already. static void init_buf_opt_idx(void) { - static int did_init_buf_opt_idx = false; + static bool did_init_buf_opt_idx = false; if (did_init_buf_opt_idx) { return; } did_init_buf_opt_idx = true; - for (int i = 0; options[i].fullname != NULL; i++) { + for (OptIndex i = 0; options[i].fullname != NULL; i++) { if (options[i].indir & PV_BUF) { buf_opt_idx[options[i].indir & PV_MASK] = i; } @@ -5167,7 +5168,7 @@ void set_imsearch_global(buf_T *buf) p_imsearch = buf->b_p_imsearch; } -static int expand_option_idx = -1; +static int expand_option_idx = kOptInvalid; static int expand_option_start_col = 0; static char expand_option_name[5] = { 't', '_', NUL, NUL, NUL }; static int expand_option_flags = 0; @@ -5217,7 +5218,7 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) char nextchar; uint32_t flags = 0; - int opt_idx = 0; + OptIndex opt_idx = 0; int is_term_option = false; if (*arg == '<') { @@ -5258,7 +5259,7 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) } nextchar = *p; opt_idx = findoption_len(arg, (size_t)(p - arg)); - if (opt_idx == -1 || options[opt_idx].var == NULL) { + if (opt_idx == kOptInvalid || options[opt_idx].var == NULL) { xp->xp_context = EXPAND_NOTHING; return; } @@ -5291,7 +5292,7 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) // Below are for handling expanding a specific option's value after the '=' or ':' if (is_term_option) { - expand_option_idx = -1; + expand_option_idx = kOptInvalid; } else { expand_option_idx = opt_idx; } @@ -5315,8 +5316,7 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) if (expand_option_subtract) { xp->xp_context = EXPAND_SETTING_SUBTRACT; return; - } else if (expand_option_idx >= 0 - && options[expand_option_idx].opt_expand_cb != NULL) { + } else if (expand_option_idx != kOptInvalid && options[expand_option_idx].opt_expand_cb != NULL) { xp->xp_context = EXPAND_STRING_SETTING; } else if (*xp->xp_pattern == NUL) { xp->xp_context = EXPAND_OLD_SETTING; @@ -5542,7 +5542,7 @@ static char *escape_option_str_cmdline(char *var) // The reverse is found at stropt_copy_value(). for (var = buf; *var != NUL; MB_PTR_ADV(var)) { if (var[0] == '\\' && var[1] == '\\' - && expand_option_idx >= 0 + && expand_option_idx != kOptInvalid && (options[expand_option_idx].flags & P_EXPAND) && vim_isfilec((uint8_t)var[2]) && (var[2] != '\\' || (var == buf && var[4] != '\\'))) { @@ -5561,12 +5561,12 @@ int ExpandOldSetting(int *numMatches, char ***matches) *numMatches = 0; *matches = xmalloc(sizeof(char *)); - // For a terminal key code expand_option_idx is < 0. - if (expand_option_idx < 0) { + // For a terminal key code expand_option_idx is kOptInvalid. + if (expand_option_idx == kOptInvalid) { expand_option_idx = findoption(expand_option_name); } - if (expand_option_idx >= 0) { + if (expand_option_idx != kOptInvalid) { // Put string of option value in NameBuff. option_value2string(&options[expand_option_idx], expand_option_flags); var = NameBuff; @@ -5584,8 +5584,7 @@ int ExpandOldSetting(int *numMatches, char ***matches) /// Expansion handler for :set=/:set+= when the option has a custom expansion handler. int ExpandStringSetting(expand_T *xp, regmatch_T *regmatch, int *numMatches, char ***matches) { - if (expand_option_idx < 0 - || options[expand_option_idx].opt_expand_cb == NULL) { + if (expand_option_idx == kOptInvalid || options[expand_option_idx].opt_expand_cb == NULL) { // Not supposed to reach this. This function is only for options with // custom expansion callbacks. return FAIL; @@ -5617,7 +5616,7 @@ int ExpandStringSetting(expand_T *xp, regmatch_T *regmatch, int *numMatches, cha /// Expansion handler for :set-= int ExpandSettingSubtract(expand_T *xp, regmatch_T *regmatch, int *numMatches, char ***matches) { - if (expand_option_idx < 0) { + if (expand_option_idx == kOptInvalid) { // term option return ExpandOldSetting(numMatches, matches); } @@ -5802,18 +5801,18 @@ void vimrc_found(char *fname, char *envname) /// @param[in] name Option name. /// /// @return True if option was set. -bool option_was_set(int opt_idx) +bool option_was_set(OptIndex opt_idx) { - assert(opt_idx >= 0); + assert(opt_idx != kOptInvalid); return options[opt_idx].flags & P_WAS_SET; } /// Reset the flag indicating option "name" was set. /// /// @param[in] name Option name. -void reset_option_was_set(int opt_idx) +void reset_option_was_set(OptIndex opt_idx) { - assert(opt_idx >= 0); + assert(opt_idx != kOptInvalid); options[opt_idx].flags &= ~P_WAS_SET; } @@ -5916,7 +5915,7 @@ int option_set_callback_func(char *optval, Callback *optcb) static void didset_options_sctx(int opt_flags, int *buf) { for (int i = 0;; i++) { - if (buf[i] == -1) { + if (buf[i] == kOptInvalid) { break; } @@ -6137,7 +6136,7 @@ dict_T *get_winbuf_options(const int bufopt) { dict_T *const d = tv_dict_alloc(); - for (int opt_idx = 0; options[opt_idx].fullname; opt_idx++) { + for (OptIndex opt_idx = 0; options[opt_idx].fullname; opt_idx++) { struct vimoption *opt = &options[opt_idx]; if ((bufopt && (opt->indir & PV_BUF)) @@ -6181,8 +6180,8 @@ int get_sidescrolloff_value(win_T *wp) Dictionary get_vimoption(String name, int scope, buf_T *buf, win_T *win, Error *err) { - int opt_idx = findoption_len(name.data, name.size); - VALIDATE_S(opt_idx >= 0, "option (not found)", name.data, { + OptIndex opt_idx = findoption_len(name.data, name.size); + VALIDATE_S(opt_idx != kOptInvalid, "option (not found)", name.data, { return (Dictionary)ARRAY_DICT_INIT; }); |