diff options
author | Yee Cheng Chin <ychin.git@gmail.com> | 2023-10-02 21:38:39 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-10-02 21:38:39 +0200 |
commit | 6d113472601fa6f3a444a95ef7b11d4309215117 (patch) | |
tree | 054b1c6276bd690339784083c19f27eb0a605123 /src/optionstr.c | |
parent | 4a1ad5556423dca5f5b7ee39f143579e67569ae1 (diff) |
patch 9.0.1973: Clean up cmdline option completion codev9.0.1973
Problem: Clean up cmdline option completion code
Solution: Fix various minor problems
- Fix manual array size calculations to just use `ARRAY_LENGTH()`.
- Fix unintentional typo in comments due to copy-paste error.
- Fix assert_equal() usages to pass the expected value to first
parameter instead of 2nd one to avoid confusion.
- Fix signed vs unsigned warnings
- Correct misplaced comments about set_op_T and set_prefix_T
and fix a typo in another comment
closes: #13249
closes: #13237
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Diffstat (limited to 'src/optionstr.c')
-rw-r--r-- | src/optionstr.c | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/src/optionstr.c b/src/optionstr.c index 5a3dd6e758..dbef8ea1c6 100644 --- a/src/optionstr.c +++ b/src/optionstr.c @@ -737,7 +737,7 @@ did_set_option_listflag(char_u *val, char_u *flags, char *errbuf) expand_set_opt_string( optexpand_T *args, char **values, - int numValues, + size_t numValues, int *numMatches, char_u ***matches) { @@ -863,7 +863,7 @@ expand_set_opt_listflag( int append = args->oe_append; int include_orig_val = args->oe_include_orig_val && (*option_val != NUL); - int num_flags = STRLEN(flags); + size_t num_flags = STRLEN(flags); // Assume we only have small number of flags, so just allocate max size. *matches = ALLOC_MULT(char_u *, num_flags + 1); @@ -940,7 +940,7 @@ expand_set_ambiwidth(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_ambw_values, - sizeof(p_ambw_values) / sizeof(p_ambw_values[0]) - 1, + ARRAY_LENGTH(p_ambw_values) - 1, numMatches, matches); } @@ -987,7 +987,7 @@ expand_set_background(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_bg_values, - sizeof(p_bg_values) / sizeof(p_bg_values[0]) - 1, + ARRAY_LENGTH(p_bg_values) - 1, numMatches, matches); } @@ -1015,7 +1015,7 @@ expand_set_backspace(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_bs_values, - sizeof(p_bs_values) / sizeof(p_bs_values[0]) - 1, + ARRAY_LENGTH(p_bs_values) - 1, numMatches, matches); } @@ -1063,7 +1063,7 @@ expand_set_backupcopy(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_bkc_values, - sizeof(p_bkc_values) / sizeof(p_bkc_values[0]) - 1, + ARRAY_LENGTH(p_bkc_values) - 1, numMatches, matches); } @@ -1096,7 +1096,7 @@ expand_set_belloff(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_bo_values, - sizeof(p_bo_values) / sizeof(p_bo_values[0]) - 1, + ARRAY_LENGTH(p_bo_values) - 1, numMatches, matches); } @@ -1125,7 +1125,7 @@ expand_set_breakindentopt(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_briopt_values, - sizeof(p_briopt_values) / sizeof(p_briopt_values[0]) - 1, + ARRAY_LENGTH(p_briopt_values) - 1, numMatches, matches); } @@ -1151,7 +1151,7 @@ expand_set_browsedir(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_bsdir_values, - sizeof(p_bsdir_values) / sizeof(p_bsdir_values[0]) - 1, + ARRAY_LENGTH(p_bsdir_values) - 1, numMatches, matches); } @@ -1172,7 +1172,7 @@ expand_set_bufhidden(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_bufhidden_values, - sizeof(p_bufhidden_values) / sizeof(p_bufhidden_values[0]) - 1, + ARRAY_LENGTH(p_bufhidden_values) - 1, numMatches, matches); } @@ -1203,7 +1203,7 @@ expand_set_buftype(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_buftype_values, - sizeof(p_buftype_values) / sizeof(p_buftype_values[0]) - 1, + ARRAY_LENGTH(p_buftype_values) - 1, numMatches, matches); } @@ -1223,7 +1223,7 @@ expand_set_casemap(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_cmp_values, - sizeof(p_cmp_values) / sizeof(p_cmp_values[0]) - 1, + ARRAY_LENGTH(p_cmp_values) - 1, numMatches, matches); } @@ -1235,7 +1235,7 @@ expand_set_clipboard(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_cb_values, - sizeof(p_cb_values) / sizeof(p_cb_values[0]) - 1, + ARRAY_LENGTH(p_cb_values) - 1, numMatches, matches); } @@ -1461,7 +1461,7 @@ expand_set_complete(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_cpt_values, - sizeof(p_cpt_values) / sizeof(p_cpt_values[0]) - 1, + ARRAY_LENGTH(p_cpt_values) - 1, numMatches, matches); } @@ -1485,7 +1485,7 @@ expand_set_completeopt(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_cot_values, - sizeof(p_cot_values) / sizeof(p_cot_values[0]) - 1, + ARRAY_LENGTH(p_cot_values) - 1, numMatches, matches); } @@ -1525,7 +1525,7 @@ expand_set_completeslash(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_csl_values, - sizeof(p_csl_values) / sizeof(p_csl_values[0]) - 1, + ARRAY_LENGTH(p_csl_values) - 1, numMatches, matches); } @@ -1664,7 +1664,7 @@ expand_set_cryptmethod(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_cm_values, - sizeof(p_cm_values) / sizeof(p_cm_values[0]) - 1, + ARRAY_LENGTH(p_cm_values) - 1, numMatches, matches); } @@ -1722,7 +1722,7 @@ expand_set_cursorlineopt(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_culopt_values, - sizeof(p_culopt_values) / sizeof(p_culopt_values[0]) - 1, + ARRAY_LENGTH(p_culopt_values) - 1, numMatches, matches); } @@ -1743,7 +1743,7 @@ expand_set_debug(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_debug_values, - sizeof(p_debug_values) / sizeof(p_debug_values[0]) - 1, + ARRAY_LENGTH(p_debug_values) - 1, numMatches, matches); } @@ -1769,14 +1769,14 @@ expand_set_diffopt(optexpand_T *args, int *numMatches, char_u ***matches) if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':') { // Within "algorithm:", we have a subgroup of possible options. - int algo_len = STRLEN("algorithm:"); + int algo_len = (int)STRLEN("algorithm:"); if (xp->xp_pattern - args->oe_set_arg >= algo_len && STRNCMP(xp->xp_pattern - algo_len, "algorithm:", algo_len) == 0) { return expand_set_opt_string( args, p_dip_algorithm_values, - sizeof(p_dip_algorithm_values) / sizeof(p_dip_algorithm_values[0]) - 1, + ARRAY_LENGTH(p_dip_algorithm_values) - 1, numMatches, matches); } @@ -1786,7 +1786,7 @@ expand_set_diffopt(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_dip_values, - sizeof(p_dip_values) / sizeof(p_dip_values[0]) - 1, + ARRAY_LENGTH(p_dip_values) - 1, numMatches, matches); } @@ -1811,7 +1811,7 @@ expand_set_display(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_dy_values, - sizeof(p_dy_values) / sizeof(p_dy_values[0]) - 1, + ARRAY_LENGTH(p_dy_values) - 1, numMatches, matches); } @@ -1831,7 +1831,7 @@ expand_set_eadirection(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_ead_values, - sizeof(p_ead_values) / sizeof(p_ead_values[0]) - 1, + ARRAY_LENGTH(p_ead_values) - 1, numMatches, matches); } @@ -2005,7 +2005,7 @@ expand_set_fileformat(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_ff_values, - sizeof(p_ff_values) / sizeof(p_ff_values[0]) - 1, + ARRAY_LENGTH(p_ff_values) - 1, numMatches, matches); } @@ -2064,7 +2064,7 @@ expand_set_foldclose(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_fcl_values, - sizeof(p_fcl_values) / sizeof(p_fcl_values[0]) - 1, + ARRAY_LENGTH(p_fcl_values) - 1, numMatches, matches); } @@ -2140,7 +2140,7 @@ expand_set_foldmethod(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_fdm_values, - sizeof(p_fdm_values) / sizeof(p_fdm_values[0]) - 1, + ARRAY_LENGTH(p_fdm_values) - 1, numMatches, matches); } @@ -2160,7 +2160,7 @@ expand_set_foldopen(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_fdo_values, - sizeof(p_fdo_values) / sizeof(p_fdo_values[0]) - 1, + ARRAY_LENGTH(p_fdo_values) - 1, numMatches, matches); } @@ -2381,7 +2381,7 @@ expand_set_highlight(optexpand_T *args, int *numMatches, char_u ***matches) char_u *p; expand_T *xp = args->oe_xp; static char_u hl_flags[HLF_COUNT] = HL_FLAGS; - int i; + size_t i; int count = 0; if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':') @@ -2446,15 +2446,15 @@ expand_set_highlight(optexpand_T *args, int *numMatches, char_u ***matches) // the returned match. // Note: Keep this in sync with highlight_changed() - static char p_hl_mode_values[] = + static char_u p_hl_mode_values[] = {':', 'b', 'i', '-', 'n', 'r', 's', 'u', 'c', '2', 'd', '=', 't'}; - int num_hl_modes = sizeof(p_hl_mode_values) / sizeof(p_hl_mode_values[0]); + size_t num_hl_modes = ARRAY_LENGTH(p_hl_mode_values); *matches = ALLOC_MULT(char_u *, num_hl_modes); if (*matches == NULL) return FAIL; - int pattern_len = STRLEN(xp->xp_pattern); + size_t pattern_len = STRLEN(xp->xp_pattern); for (i = 0; i < num_hl_modes; i++) { @@ -2576,7 +2576,7 @@ expand_set_jumpoptions(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_jop_values, - sizeof(p_jop_values) / sizeof(p_jop_values[0]) - 1, + ARRAY_LENGTH(p_jop_values) - 1, numMatches, matches); } @@ -2660,7 +2660,7 @@ expand_set_keymodel(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_km_values, - sizeof(p_km_values) / sizeof(p_km_values[0]) - 1, + ARRAY_LENGTH(p_km_values) - 1, numMatches, matches); } @@ -2692,7 +2692,7 @@ expand_set_keyprotocol(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_kpc_protocol_values, - sizeof(p_kpc_protocol_values) / sizeof(p_kpc_protocol_values[0]) - 1, + ARRAY_LENGTH(p_kpc_protocol_values) - 1, numMatches, matches); } @@ -2725,7 +2725,7 @@ expand_set_lispoptions(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_lop_values, - sizeof(p_lop_values) / sizeof(p_lop_values[0]) - 1, + ARRAY_LENGTH(p_lop_values) - 1, numMatches, matches); } @@ -2831,7 +2831,7 @@ expand_set_mousemodel(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_mousem_values, - sizeof(p_mousem_values) / sizeof(p_mousem_values[0]) - 1, + ARRAY_LENGTH(p_mousem_values) - 1, numMatches, matches); } @@ -2866,7 +2866,7 @@ expand_set_nrformats(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_nf_values, - sizeof(p_nf_values) / sizeof(p_nf_values[0]) - 1, + ARRAY_LENGTH(p_nf_values) - 1, numMatches, matches); } @@ -2940,29 +2940,29 @@ expand_set_popupoption(optexpand_T *args, int *numMatches, char_u ***matches) if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':') { // Within "highlight:"/"border:"/"align:", we have a subgroup of possible options. - int border_len = STRLEN("border:"); + int border_len = (int)STRLEN("border:"); if (xp->xp_pattern - args->oe_set_arg >= border_len && STRNCMP(xp->xp_pattern - border_len, "border:", border_len) == 0) { return expand_set_opt_string( args, p_popup_option_border_values, - sizeof(p_popup_option_border_values) / sizeof(p_popup_option_border_values[0]) - 1, + ARRAY_LENGTH(p_popup_option_border_values) - 1, numMatches, matches); } - int align_len = STRLEN("align:"); + int align_len = (int)STRLEN("align:"); if (xp->xp_pattern - args->oe_set_arg >= align_len && STRNCMP(xp->xp_pattern - align_len, "align:", align_len) == 0) { return expand_set_opt_string( args, p_popup_option_align_values, - sizeof(p_popup_option_align_values) / sizeof(p_popup_option_align_values[0]) - 1, + ARRAY_LENGTH(p_popup_option_align_values) - 1, numMatches, matches); } - int highlight_len = STRLEN("highlight:"); + int highlight_len = (int)STRLEN("highlight:"); if (xp->xp_pattern - args->oe_set_arg >= highlight_len && STRNCMP(xp->xp_pattern - highlight_len, "highlight:", highlight_len) == 0) { @@ -2979,7 +2979,7 @@ expand_set_popupoption(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_popup_option_values, - sizeof(p_popup_option_values) / sizeof(p_popup_option_values[0]) - 1, + ARRAY_LENGTH(p_popup_option_values) - 1, numMatches, matches); } @@ -3022,7 +3022,7 @@ did_set_printencoding(optset_T *args UNUSED) static char_u * get_printoptions_names(expand_T *xp UNUSED, int idx) { - if (idx >= (int)(sizeof(printer_opts) / sizeof(printer_opts[0]))) + if (idx >= (int)ARRAY_LENGTH(printer_opts)) return NULL; return (char_u*)printer_opts[idx].name; } @@ -3115,7 +3115,7 @@ expand_set_rightleftcmd(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_rlc_values, - sizeof(p_rlc_values) / sizeof(p_rlc_values[0]) - 1, + ARRAY_LENGTH(p_rlc_values) - 1, numMatches, matches); } @@ -3147,7 +3147,7 @@ expand_set_scrollopt(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_scbopt_values, - sizeof(p_scbopt_values) / sizeof(p_scbopt_values[0]) - 1, + ARRAY_LENGTH(p_scbopt_values) - 1, numMatches, matches); } @@ -3170,7 +3170,7 @@ expand_set_selection(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_sel_values, - sizeof(p_sel_values) / sizeof(p_sel_values[0]) - 1, + ARRAY_LENGTH(p_sel_values) - 1, numMatches, matches); } @@ -3190,7 +3190,7 @@ expand_set_selectmode(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_slm_values, - sizeof(p_slm_values) / sizeof(p_slm_values[0]) - 1, + ARRAY_LENGTH(p_slm_values) - 1, numMatches, matches); } @@ -3221,7 +3221,7 @@ expand_set_sessionoptions(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_ssop_values, - sizeof(p_ssop_values) / sizeof(p_ssop_values[0]) - 1, + ARRAY_LENGTH(p_ssop_values) - 1, numMatches, matches); } @@ -3280,7 +3280,7 @@ expand_set_showcmdloc(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_sloc_values, - sizeof(p_sloc_values) / sizeof(p_sloc_values[0]) - 1, + ARRAY_LENGTH(p_sloc_values) - 1, numMatches, matches); } @@ -3312,7 +3312,7 @@ expand_set_signcolumn(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_scl_values, - sizeof(p_scl_values) / sizeof(p_scl_values[0]) - 1, + ARRAY_LENGTH(p_scl_values) - 1, numMatches, matches); } @@ -3382,7 +3382,7 @@ expand_set_spelloptions(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_spo_values, - sizeof(p_spo_values) / sizeof(p_spo_values[0]) - 1, + ARRAY_LENGTH(p_spo_values) - 1, numMatches, matches); } @@ -3405,7 +3405,7 @@ expand_set_spellsuggest(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_sps_values, - sizeof(p_sps_values) / sizeof(p_sps_values[0]) - 1, + ARRAY_LENGTH(p_sps_values) - 1, numMatches, matches); } @@ -3426,7 +3426,7 @@ expand_set_splitkeep(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_spk_values, - sizeof(p_spk_values) / sizeof(p_spk_values[0]) - 1, + ARRAY_LENGTH(p_spk_values) - 1, numMatches, matches); } @@ -3457,7 +3457,7 @@ expand_set_swapsync(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_sws_values, - sizeof(p_sws_values) / sizeof(p_sws_values[0]) - 1, + ARRAY_LENGTH(p_sws_values) - 1, numMatches, matches); } @@ -3477,7 +3477,7 @@ expand_set_switchbuf(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_swb_values, - sizeof(p_swb_values) / sizeof(p_swb_values[0]) - 1, + ARRAY_LENGTH(p_swb_values) - 1, numMatches, matches); } @@ -3529,7 +3529,7 @@ expand_set_tagcase(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_tc_values, - sizeof(p_tc_values) / sizeof(p_tc_values[0]) - 1, + ARRAY_LENGTH(p_tc_values) - 1, numMatches, matches); } @@ -3674,7 +3674,7 @@ expand_set_termwintype(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_twt_values, - sizeof(p_twt_values) / sizeof(p_twt_values[0]) - 1, + ARRAY_LENGTH(p_twt_values) - 1, numMatches, matches); } @@ -3718,7 +3718,7 @@ expand_set_toolbar(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_toolbar_values, - sizeof(p_toolbar_values) / sizeof(p_toolbar_values[0]) - 1, + ARRAY_LENGTH(p_toolbar_values) - 1, numMatches, matches); } @@ -3746,7 +3746,7 @@ expand_set_toolbariconsize(optexpand_T *args, int *numMatches, char_u ***matches return expand_set_opt_string( args, p_tbis_values, - sizeof(p_tbis_values) / sizeof(p_tbis_values[0]) - 1, + ARRAY_LENGTH(p_tbis_values) - 1, numMatches, matches); } @@ -3780,7 +3780,7 @@ expand_set_ttymouse(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_ttym_values, - sizeof(p_ttym_values) / sizeof(p_ttym_values[0]) - 1, + ARRAY_LENGTH(p_ttym_values) - 1, numMatches, matches); } @@ -3996,7 +3996,7 @@ expand_set_virtualedit(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_ve_values, - sizeof(p_ve_values) / sizeof(p_ve_values[0]) - 1, + ARRAY_LENGTH(p_ve_values) - 1, numMatches, matches); } @@ -4037,7 +4037,7 @@ expand_set_wildmode(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_wim_values, - sizeof(p_wim_values) / sizeof(p_wim_values[0]) - 1, + ARRAY_LENGTH(p_wim_values) - 1, numMatches, matches); } @@ -4057,7 +4057,7 @@ expand_set_wildoptions(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_wop_values, - sizeof(p_wop_values) / sizeof(p_wop_values[0]) - 1, + ARRAY_LENGTH(p_wop_values) - 1, numMatches, matches); } @@ -4091,7 +4091,7 @@ expand_set_winaltkeys(optexpand_T *args, int *numMatches, char_u ***matches) return expand_set_opt_string( args, p_wak_values, - sizeof(p_wak_values) / sizeof(p_wak_values[0]) - 1, + ARRAY_LENGTH(p_wak_values) - 1, numMatches, matches); } |