diff options
71 files changed, 1602 insertions, 1615 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index a388592981..89baf84c86 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -750,7 +750,7 @@ nvim_eval_statusline({str}, {*opts}) *nvim_eval_statusline()* • highlights: (boolean) Return highlight information. • use_winbar: (boolean) Evaluate winbar instead of statusline. • use_tabline: (boolean) Evaluate tabline instead of - statusline. When |TRUE|, {winid} is ignored. Mutually + statusline. When true, {winid} is ignored. Mutually exclusive with {use_winbar}. Return: ~ @@ -759,7 +759,7 @@ nvim_eval_statusline({str}, {*opts}) *nvim_eval_statusline()* • width: (number) Display width of the statusline. • highlights: Array containing highlight information of the statusline. Only included when the "highlights" key in {opts} is - |TRUE|. Each element of the array is a |Dictionary| with these keys: + true. Each element of the array is a |Dictionary| with these keys: • start: (number) Byte index (0-based) of first character that uses the highlight. • group: (string) Name of highlight group. diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 2e0c1f8cc4..164e09ccce 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -2454,28 +2454,30 @@ A jump table for the options with a short description can be found at |Q_op|. *'fillchars'* *'fcs'* 'fillchars' 'fcs' string (default "") global or local to window |global-local| - Characters to fill the statuslines and vertical separators. - It is a comma-separated list of items: + Characters to fill the statuslines, vertical separators and special + lines in the window. + It is a comma-separated list of items. Each item has a name, a colon + and the value of that item: item default Used for ~ - stl:c ' ' or '^' statusline of the current window - stlnc:c ' ' or '=' statusline of the non-current windows - wbr:c ' ' window bar - horiz:c '─' or '-' horizontal separators |:split| - horizup:c '┴' or '-' upwards facing horizontal separator - horizdown:c '┬' or '-' downwards facing horizontal separator - vert:c '│' or '|' vertical separators |:vsplit| - vertleft:c '┤' or '|' left facing vertical separator - vertright:c '├' or '|' right facing vertical separator - verthoriz:c '┼' or '+' overlapping vertical and horizontal + stl ' ' or '^' statusline of the current window + stlnc ' ' or '=' statusline of the non-current windows + wbr ' ' window bar + horiz '─' or '-' horizontal separators |:split| + horizup '┴' or '-' upwards facing horizontal separator + horizdown '┬' or '-' downwards facing horizontal separator + vert '│' or '|' vertical separators |:vsplit| + vertleft '┤' or '|' left facing vertical separator + vertright '├' or '|' right facing vertical separator + verthoriz '┼' or '+' overlapping vertical and horizontal separator - fold:c '·' or '-' filling 'foldtext' - foldopen:c '-' mark the beginning of a fold - foldclose:c '+' show a closed fold - foldsep:c '│' or '|' open fold middle marker - diff:c '-' deleted lines of the 'diff' option - msgsep:c ' ' message separator 'display' - eob:c '~' empty lines at the end of a buffer + fold '·' or '-' filling 'foldtext' + foldopen '-' mark the beginning of a fold + foldclose '+' show a closed fold + foldsep '│' or '|' open fold middle marker + diff '-' deleted lines of the 'diff' option + msgsep ' ' message separator 'display' + eob '~' empty lines at the end of a buffer Any one that is omitted will fall back to the default. For "stl" and "stlnc" the space will be used when there is highlighting, '^' or '=' @@ -2500,19 +2502,19 @@ A jump table for the options with a short description can be found at |Q_op|. The highlighting used for these items: item highlight group ~ - stl:c StatusLine |hl-StatusLine| - stlnc:c StatusLineNC |hl-StatusLineNC| - wbr:c WinBar |hl-WinBar| or |hl-WinBarNC| - horiz:c WinSeparator |hl-WinSeparator| - horizup:c WinSeparator |hl-WinSeparator| - horizdown:c WinSeparator |hl-WinSeparator| - vert:c WinSeparator |hl-WinSeparator| - vertleft:c WinSeparator |hl-WinSeparator| - vertright:c WinSeparator |hl-WinSeparator| - verthoriz:c WinSeparator |hl-WinSeparator| - fold:c Folded |hl-Folded| - diff:c DiffDelete |hl-DiffDelete| - eob:c EndOfBuffer |hl-EndOfBuffer| + stl StatusLine |hl-StatusLine| + stlnc StatusLineNC |hl-StatusLineNC| + wbr WinBar |hl-WinBar| or |hl-WinBarNC| + horiz WinSeparator |hl-WinSeparator| + horizup WinSeparator |hl-WinSeparator| + horizdown WinSeparator |hl-WinSeparator| + vert WinSeparator |hl-WinSeparator| + vertleft WinSeparator |hl-WinSeparator| + vertright WinSeparator |hl-WinSeparator| + verthoriz WinSeparator |hl-WinSeparator| + fold Folded |hl-Folded| + diff DiffDelete |hl-DiffDelete| + eob EndOfBuffer |hl-EndOfBuffer| *'fixendofline'* *'fixeol'* *'nofixendofline'* *'nofixeol'* 'fixendofline' 'fixeol' boolean (default on) diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 43027473a0..199650fc55 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1031,7 +1031,7 @@ String nvim_buf_get_name(Buffer buffer, Arena *arena, Error *err) return rv; } - return cstr_as_string((char *)buf->b_ffname); + return cstr_as_string(buf->b_ffname); } /// Sets the full file name for a buffer diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 2fa0277df7..b164106cef 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2044,7 +2044,7 @@ Array nvim_get_mark(String name, Dictionary opts, Error *err) // Marks are from an open buffer it fnum is non zero if (mark->fmark.fnum != 0) { bufnr = mark->fmark.fnum; - filename = (char *)buflist_nr2name(bufnr, true, true); + filename = buflist_nr2name(bufnr, true, true); allocated = true; // Marks comes from shada } else { @@ -2092,7 +2092,7 @@ Array nvim_get_mark(String name, Dictionary opts, Error *err) /// 'fillchars'). Treated as single-width even if it isn't. /// - highlights: (boolean) Return highlight information. /// - use_winbar: (boolean) Evaluate winbar instead of statusline. -/// - use_tabline: (boolean) Evaluate tabline instead of statusline. When |TRUE|, {winid} +/// - use_tabline: (boolean) Evaluate tabline instead of statusline. When true, {winid} /// is ignored. Mutually exclusive with {use_winbar}. /// /// @param[out] err Error details, if any. @@ -2100,7 +2100,7 @@ Array nvim_get_mark(String name, Dictionary opts, Error *err) /// - str: (string) Characters that will be displayed on the statusline. /// - width: (number) Display width of the statusline. /// - highlights: Array containing highlight information of the statusline. Only included when -/// the "highlights" key in {opts} is |TRUE|. Each element of the array is a +/// the "highlights" key in {opts} is true. Each element of the array is a /// |Dictionary| with these keys: /// - start: (number) Byte index (0-based) of first character that uses the highlight. /// - group: (string) Name of highlight group. @@ -2232,7 +2232,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * // If first character doesn't have a defined highlight, // add the default highlight at the beginning of the highlight list - if (hltab->start == NULL || ((char *)hltab->start - buf) != 0) { + if (hltab->start == NULL || (hltab->start - buf) != 0) { Dictionary hl_info = ARRAY_DICT_INIT; grpname = get_default_stl_hl(wp, use_winbar); diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c index 4f940f2fa5..21aa5afbae 100644 --- a/src/nvim/arglist.c +++ b/src/nvim/arglist.c @@ -157,7 +157,7 @@ void alist_add(alist_T *al, char *fname, int set_fnum) #ifdef BACKSLASH_IN_FILENAME slash_adjust(fname); #endif - AARGLIST(al)[al->al_ga.ga_len].ae_fname = (char_u *)fname; + AARGLIST(al)[al->al_ga.ga_len].ae_fname = fname; if (set_fnum > 0) { AARGLIST(al)[al->al_ga.ga_len].ae_fnum = buflist_add(fname, BLN_LISTED | (set_fnum == 2 ? BLN_CURBUF : 0)); @@ -226,7 +226,7 @@ static char *do_one_arg(char *str) /// growarray "gap". static void get_arglist(garray_T *gap, char *str, int escaped) { - ga_init(gap, (int)sizeof(char_u *), 20); + ga_init(gap, (int)sizeof(char *), 20); while (*str != NUL) { GA_APPEND(char *, gap, str); @@ -244,12 +244,12 @@ static void get_arglist(garray_T *gap, char *str, int escaped) /// "fnames[fcountp]". When "wig" is true, removes files matching 'wildignore'. /// /// @return FAIL or OK. -int get_arglist_exp(char_u *str, int *fcountp, char ***fnamesp, bool wig) +int get_arglist_exp(char *str, int *fcountp, char ***fnamesp, bool wig) { garray_T ga; int i; - get_arglist(&ga, (char *)str, true); + get_arglist(&ga, str, true); if (wig) { i = expand_wildcards(ga.ga_len, ga.ga_data, @@ -297,7 +297,7 @@ static void alist_add_list(int count, char **files, int after, bool will_edit) } for (int i = 0; i < count; i++) { const int flags = BLN_LISTED | (will_edit ? BLN_CURBUF : 0); - ARGLIST[after + i].ae_fname = (char_u *)files[i]; + ARGLIST[after + i].ae_fname = files[i]; ARGLIST[after + i].ae_fnum = buflist_add(files[i], flags); } ALIST(curwin)->al_ga.ga_len += count; @@ -377,7 +377,7 @@ static int do_arglist(char *str, int what, int after, bool will_edit) vim_regfree(regmatch.regprog); xfree(p); if (!didone) { - semsg(_(e_nomatch2), ((char_u **)new_ga.ga_data)[i]); + semsg(_(e_nomatch2), ((char **)new_ga.ga_data)[i]); } } ga_clear(&new_ga); @@ -472,7 +472,7 @@ void ex_args(exarg_T *eap) } else if (eap->cmdidx == CMD_args) { // ":args": list arguments. if (ARGCOUNT > 0) { - char **items = xmalloc(sizeof(char_u *) * (size_t)ARGCOUNT); + char **items = xmalloc(sizeof(char *) * (size_t)ARGCOUNT); // Overwrite the command, for a short list there is no scrolling // required and no wait_return(). gotocmdline(true); @@ -489,10 +489,8 @@ void ex_args(exarg_T *eap) ga_grow(gap, GARGCOUNT); for (int i = 0; i < GARGCOUNT; i++) { if (GARGLIST[i].ae_fname != NULL) { - AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname = - vim_strsave(GARGLIST[i].ae_fname); - AARGLIST(curwin->w_alist)[gap->ga_len].ae_fnum = - GARGLIST[i].ae_fnum; + AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname = xstrdup(GARGLIST[i].ae_fname); + AARGLIST(curwin->w_alist)[gap->ga_len].ae_fnum = GARGLIST[i].ae_fnum; gap->ga_len++; } } @@ -742,7 +740,7 @@ char *alist_name(aentry_T *aep) // Use the name from the associated buffer if it exists. bp = buflist_findnr(aep->ae_fnum); if (bp == NULL || bp->b_fname == NULL) { - return (char *)aep->ae_fname; + return aep->ae_fname; } return bp->b_fname; } diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 50e873dc55..e970387456 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -1720,9 +1720,9 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force fname = NULL; } else { if (event == EVENT_SYNTAX) { - fname = (char *)buf->b_p_syn; + fname = buf->b_p_syn; } else if (event == EVENT_FILETYPE) { - fname = (char *)buf->b_p_ft; + fname = buf->b_p_ft; } else { if (buf->b_sfname != NULL) { sfname = xstrdup(buf->b_sfname); diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index c56fd9e6a8..d22ab266f8 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -116,11 +116,11 @@ typedef uint64_t disptick_T; // display tick type * The taggy struct is used to store the information about a :tag command. */ typedef struct taggy { - char_u *tagname; // tag name + char *tagname; // tag name fmark_T fmark; // cursor position BEFORE ":tag" int cur_match; // match number int cur_fnum; // buffer number used for cur_match - char_u *user_data; // used with tagfunc + char *user_data; // used with tagfunc } taggy_T; typedef struct buffblock buffblock_T; @@ -131,7 +131,7 @@ typedef struct buffheader buffheader_T; */ struct buffblock { buffblock_T *b_next; // pointer to next buffblock - char_u b_str[1]; // contents (actually longer) + char b_str[1]; // contents (actually longer) }; /* @@ -159,39 +159,39 @@ typedef struct { #define w_p_arab w_onebuf_opt.wo_arab // 'arabic' int wo_bri; #define w_p_bri w_onebuf_opt.wo_bri // 'breakindent' - char_u *wo_briopt; + char *wo_briopt; #define w_p_briopt w_onebuf_opt.wo_briopt // 'breakindentopt' int wo_diff; #define w_p_diff w_onebuf_opt.wo_diff // 'diff' - char_u *wo_fdc; + char *wo_fdc; #define w_p_fdc w_onebuf_opt.wo_fdc // 'foldcolumn' - char_u *wo_fdc_save; + char *wo_fdc_save; #define w_p_fdc_save w_onebuf_opt.wo_fdc_save // 'fdc' saved for diff mode int wo_fen; #define w_p_fen w_onebuf_opt.wo_fen // 'foldenable' int wo_fen_save; // 'foldenable' saved for diff mode #define w_p_fen_save w_onebuf_opt.wo_fen_save - char_u *wo_fdi; + char *wo_fdi; #define w_p_fdi w_onebuf_opt.wo_fdi // 'foldignore' long wo_fdl; #define w_p_fdl w_onebuf_opt.wo_fdl // 'foldlevel' long wo_fdl_save; // 'foldlevel' state saved for diff mode #define w_p_fdl_save w_onebuf_opt.wo_fdl_save - char_u *wo_fdm; + char *wo_fdm; #define w_p_fdm w_onebuf_opt.wo_fdm // 'foldmethod' - char_u *wo_fdm_save; + char *wo_fdm_save; #define w_p_fdm_save w_onebuf_opt.wo_fdm_save // 'fdm' saved for diff mode long wo_fml; #define w_p_fml w_onebuf_opt.wo_fml // 'foldminlines' long wo_fdn; #define w_p_fdn w_onebuf_opt.wo_fdn // 'foldnestmax' - char_u *wo_fde; + char *wo_fde; #define w_p_fde w_onebuf_opt.wo_fde // 'foldexpr' - char_u *wo_fdt; + char *wo_fdt; #define w_p_fdt w_onebuf_opt.wo_fdt // 'foldtext' - char_u *wo_fmr; + char *wo_fmr; #define w_p_fmr w_onebuf_opt.wo_fmr // 'foldmarker' int wo_lbr; #define w_p_lbr w_onebuf_opt.wo_lbr // 'linebreak' @@ -201,7 +201,7 @@ typedef struct { #define w_p_nu w_onebuf_opt.wo_nu // 'number' int wo_rnu; #define w_p_rnu w_onebuf_opt.wo_rnu // 'relativenumber' - char_u *wo_ve; + char *wo_ve; #define w_p_ve w_onebuf_opt.wo_ve // 'virtualedit' unsigned wo_ve_flags; #define w_ve_flags w_onebuf_opt.wo_ve_flags // flags for 'virtualedit' @@ -215,7 +215,7 @@ typedef struct { #define w_p_pvw w_onebuf_opt.wo_pvw // 'previewwindow' int wo_rl; #define w_p_rl w_onebuf_opt.wo_rl // 'rightleft' - char_u *wo_rlc; + char *wo_rlc; #define w_p_rlc w_onebuf_opt.wo_rlc // 'rightleftcmd' long wo_scr; #define w_p_scr w_onebuf_opt.wo_scr // 'scroll' @@ -225,13 +225,13 @@ typedef struct { #define w_p_cuc w_onebuf_opt.wo_cuc // 'cursorcolumn' int wo_cul; #define w_p_cul w_onebuf_opt.wo_cul // 'cursorline' - char_u *wo_culopt; + char *wo_culopt; #define w_p_culopt w_onebuf_opt.wo_culopt // 'cursorlineopt' - char_u *wo_cc; + char *wo_cc; #define w_p_cc w_onebuf_opt.wo_cc // 'colorcolumn' - char_u *wo_sbr; + char *wo_sbr; #define w_p_sbr w_onebuf_opt.wo_sbr // 'showbreak' - char_u *wo_stl; + char *wo_stl; #define w_p_stl w_onebuf_opt.wo_stl // 'statusline' char *wo_wbr; #define w_p_wbr w_onebuf_opt.wo_wbr // 'winbar' @@ -245,7 +245,7 @@ typedef struct { #define w_p_wrap w_onebuf_opt.wo_wrap // 'wrap' int wo_wrap_save; // 'wrap' state saved for diff mode #define w_p_wrap_save w_onebuf_opt.wo_wrap_save - char_u *wo_cocu; // 'concealcursor' + char *wo_cocu; // 'concealcursor' #define w_p_cocu w_onebuf_opt.wo_cocu long wo_cole; // 'conceallevel' #define w_p_cole w_onebuf_opt.wo_cole @@ -253,14 +253,14 @@ typedef struct { #define w_p_crb w_onebuf_opt.wo_crb // 'cursorbind' int wo_crb_save; // 'cursorbind' state saved for diff mode #define w_p_crb_save w_onebuf_opt.wo_crb_save - char_u *wo_scl; + char *wo_scl; #define w_p_scl w_onebuf_opt.wo_scl // 'signcolumn' - char_u *wo_winhl; + char *wo_winhl; #define w_p_winhl w_onebuf_opt.wo_winhl // 'winhighlight' - char_u *wo_fcs; -#define w_p_fcs w_onebuf_opt.wo_fcs // 'fillchars' - char_u *wo_lcs; + char *wo_lcs; #define w_p_lcs w_onebuf_opt.wo_lcs // 'listchars' + char *wo_fcs; +#define w_p_fcs w_onebuf_opt.wo_fcs // 'fillchars' long wo_winbl; #define w_p_winbl w_onebuf_opt.wo_winbl // 'winblend' @@ -308,8 +308,8 @@ typedef struct arglist { // // TODO(Felipe): move aentry_T to another header typedef struct argentry { - char_u *ae_fname; // file name as specified - int ae_fnum; // buffer number with expanded file name + char *ae_fname; // file name as specified + int ae_fnum; // buffer number with expanded file name } aentry_T; #define ALIST(win) (win)->w_alist @@ -326,7 +326,7 @@ typedef struct argentry { */ typedef struct { char_u *tb_buf; // buffer for typed characters - char_u *tb_noremap; // mapping flags for characters in tb_buf[] + uint8_t *tb_noremap; // mapping flags for characters in tb_buf[] int tb_buflen; // size of tb_buf[] int tb_off; // current position in tb_buf[] int tb_len; // number of valid bytes in tb_buf[] @@ -352,11 +352,11 @@ typedef struct { */ typedef struct mapblock mapblock_T; struct mapblock { - mapblock_T *m_next; // next mapblock in list - char_u *m_keys; // mapped from, lhs - char_u *m_str; // mapped to, rhs - char_u *m_orig_str; // rhs as entered by the user - LuaRef m_luaref; // lua function reference as rhs + mapblock_T *m_next; // next mapblock in list + char_u *m_keys; // mapped from, lhs + char *m_str; // mapped to, rhs + char *m_orig_str; // rhs as entered by the user + LuaRef m_luaref; // lua function reference as rhs int m_keylen; // strlen(m_keys) int m_mode; // valid mode int m_simplified; // m_keys was simplified, do no use this map @@ -440,14 +440,14 @@ typedef struct { garray_T b_syn_clusters; // table for syntax clusters int b_spell_cluster_id; // @Spell cluster ID or 0 int b_nospell_cluster_id; // @NoSpell cluster ID or 0 - int b_syn_containedin; // TRUE when there is an item with a + int b_syn_containedin; // true when there is an item with a // "containedin" argument int b_syn_sync_flags; // flags about how to sync int16_t b_syn_sync_id; // group to sync on linenr_T b_syn_sync_minlines; // minimal sync lines offset linenr_T b_syn_sync_maxlines; // maximal sync lines offset linenr_T b_syn_sync_linebreaks; // offset for multi-line pattern - char_u *b_syn_linecont_pat; // line continuation pattern + char *b_syn_linecont_pat; // line continuation pattern regprog_T *b_syn_linecont_prog; // line continuation program syn_time_T b_syn_linecont_time; int b_syn_linecont_ic; // ignore-case flag for above @@ -476,17 +476,17 @@ typedef struct { disptick_T b_sst_lasttick; // last display tick // for spell checking - garray_T b_langp; // list of pointers to slang_T, see spell.c - bool b_spell_ismw[256]; // flags: is midword char - char_u *b_spell_ismw_mb; // multi-byte midword chars - char_u *b_p_spc; // 'spellcapcheck' + garray_T b_langp; // list of pointers to slang_T, see spell.c + bool b_spell_ismw[256]; // flags: is midword char + char *b_spell_ismw_mb; // multi-byte midword chars + char *b_p_spc; // 'spellcapcheck' regprog_T *b_cap_prog; // program for 'spellcapcheck' - char_u *b_p_spf; // 'spellfile' - char_u *b_p_spl; // 'spelllang' - char_u *b_p_spo; // 'spelloptions' - int b_cjk; // all CJK letters as OK - char_u b_syn_chartab[32]; // syntax iskeyword option - char_u *b_syn_isk; // iskeyword option + char *b_p_spf; // 'spellfile' + char *b_p_spl; // 'spelllang' + char *b_p_spo; // 'spelloptions' + int b_cjk; // all CJK letters as OK + uint8_t b_syn_chartab[32]; // syntax iskeyword option + char *b_syn_isk; // iskeyword option } synblock_T; /// Type used for changedtick_di member in buf_T @@ -600,7 +600,7 @@ struct file_buffer { fmark_T b_namedm[NMARKS]; // current named marks (mark.c) - // These variables are set when VIsual_active becomes FALSE + // These variables are set when VIsual_active becomes false visualinfo_T b_visual; int b_visual_mode_eval; // b_visual.vi_mode for visualmode() @@ -653,10 +653,8 @@ struct file_buffer { time_t b_u_time_cur; // uh_time of header below which we are now long b_u_save_nr_cur; // file write nr after which we are now - /* - * variables for "U" command in undo.c - */ - char_u *b_u_line_ptr; // saved line for "U" command + // variables for "U" command in undo.c + char *b_u_line_ptr; // saved line for "U" command linenr_T b_u_line_lnum; // line number of line in u_line colnr_T b_u_line_colnr; // optional column number @@ -686,72 +684,72 @@ struct file_buffer { int b_p_ai; ///< 'autoindent' int b_p_ai_nopaste; ///< b_p_ai saved for paste mode - char_u *b_p_bkc; ///< 'backupco + char *b_p_bkc; ///< 'backupco unsigned int b_bkc_flags; ///< flags for 'backupco int b_p_ci; ///< 'copyindent' int b_p_bin; ///< 'binary' int b_p_bomb; ///< 'bomb' - char_u *b_p_bh; ///< 'bufhidden' - char_u *b_p_bt; ///< 'buftype' + char *b_p_bh; ///< 'bufhidden' + char *b_p_bt; ///< 'buftype' int b_has_qf_entry; ///< quickfix exists for buffer int b_p_bl; ///< 'buflisted' long b_p_channel; ///< 'channel' int b_p_cin; ///< 'cindent' - char_u *b_p_cino; ///< 'cinoptions' - char_u *b_p_cink; ///< 'cinkeys' - char_u *b_p_cinw; ///< 'cinwords' - char_u *b_p_cinsd; ///< 'cinscopedecls' - char_u *b_p_com; ///< 'comments' - char_u *b_p_cms; ///< 'commentstring' - char_u *b_p_cpt; ///< 'complete' + char *b_p_cino; ///< 'cinoptions' + char *b_p_cink; ///< 'cinkeys' + char *b_p_cinw; ///< 'cinwords' + char *b_p_cinsd; ///< 'cinscopedecls' + char *b_p_com; ///< 'comments' + char *b_p_cms; ///< 'commentstring' + char *b_p_cpt; ///< 'complete' #ifdef BACKSLASH_IN_FILENAME char_u *b_p_csl; ///< 'completeslash' #endif - char_u *b_p_cfu; ///< 'completefunc' - char_u *b_p_ofu; ///< 'omnifunc' - char_u *b_p_tfu; ///< 'tagfunc' + char *b_p_cfu; ///< 'completefunc' + char *b_p_ofu; ///< 'omnifunc' + char *b_p_tfu; ///< 'tagfunc' int b_p_eol; ///< 'endofline' int b_p_fixeol; ///< 'fixendofline' int b_p_et; ///< 'expandtab' int b_p_et_nobin; ///< b_p_et saved for binary mode int b_p_et_nopaste; ///< b_p_et saved for paste mode - char_u *b_p_fenc; ///< 'fileencoding' - char_u *b_p_ff; ///< 'fileformat' - char_u *b_p_ft; ///< 'filetype' - char_u *b_p_fo; ///< 'formatoptions' - char_u *b_p_flp; ///< 'formatlistpat' + char *b_p_fenc; ///< 'fileencoding' + char *b_p_ff; ///< 'fileformat' + char *b_p_ft; ///< 'filetype' + char *b_p_fo; ///< 'formatoptions' + char *b_p_flp; ///< 'formatlistpat' int b_p_inf; ///< 'infercase' - char_u *b_p_isk; ///< 'iskeyword' - char_u *b_p_def; ///< 'define' local value - char_u *b_p_inc; ///< 'include' - char_u *b_p_inex; ///< 'includeexpr' + char *b_p_isk; ///< 'iskeyword' + char *b_p_def; ///< 'define' local value + char *b_p_inc; ///< 'include' + char *b_p_inex; ///< 'includeexpr' uint32_t b_p_inex_flags; ///< flags for 'includeexpr' - char_u *b_p_inde; ///< 'indentexpr' + char *b_p_inde; ///< 'indentexpr' uint32_t b_p_inde_flags; ///< flags for 'indentexpr' - char_u *b_p_indk; ///< 'indentkeys' - char_u *b_p_fp; ///< 'formatprg' - char_u *b_p_fex; ///< 'formatexpr' + char *b_p_indk; ///< 'indentkeys' + char *b_p_fp; ///< 'formatprg' + char *b_p_fex; ///< 'formatexpr' uint32_t b_p_fex_flags; ///< flags for 'formatexpr' - char_u *b_p_kp; ///< 'keywordprg' + char *b_p_kp; ///< 'keywordprg' int b_p_lisp; ///< 'lisp' - char_u *b_p_menc; ///< 'makeencoding' - char_u *b_p_mps; ///< 'matchpairs' + char *b_p_menc; ///< 'makeencoding' + char *b_p_mps; ///< 'matchpairs' int b_p_ml; ///< 'modeline' int b_p_ml_nobin; ///< b_p_ml saved for binary mode int b_p_ma; ///< 'modifiable' - char_u *b_p_nf; ///< 'nrformats' + char *b_p_nf; ///< 'nrformats' int b_p_pi; ///< 'preserveindent' - char_u *b_p_qe; ///< 'quoteescape' + char *b_p_qe; ///< 'quoteescape' int b_p_ro; ///< 'readonly' long b_p_sw; ///< 'shiftwidth' long b_p_scbk; ///< 'scrollback' int b_p_si; ///< 'smartindent' long b_p_sts; ///< 'softtabstop' long b_p_sts_nopaste; ///< b_p_sts saved for paste mode - char_u *b_p_sua; ///< 'suffixesadd' + char *b_p_sua; ///< 'suffixesadd' int b_p_swf; ///< 'swapfile' long b_p_smc; ///< 'synmaxcol' - char_u *b_p_syn; ///< 'syntax' + char *b_p_syn; ///< 'syntax' long b_p_ts; ///< 'tabstop' long b_p_tw; ///< 'textwidth' long b_p_tw_nobin; ///< b_p_tw saved for binary mode @@ -759,29 +757,29 @@ struct file_buffer { long b_p_wm; ///< 'wrapmargin' long b_p_wm_nobin; ///< b_p_wm saved for binary mode long b_p_wm_nopaste; ///< b_p_wm saved for paste mode - char_u *b_p_vsts; ///< 'varsofttabstop' - long *b_p_vsts_array; ///< 'varsofttabstop' in internal format - char_u *b_p_vsts_nopaste; ///< b_p_vsts saved for paste mode - char_u *b_p_vts; ///< 'vartabstop' - long *b_p_vts_array; ///< 'vartabstop' in internal format - char_u *b_p_keymap; ///< 'keymap' + char *b_p_vsts; ///< 'varsofttabstop' + long *b_p_vsts_array; ///< 'varsofttabstop' in internal format + char *b_p_vsts_nopaste; ///< b_p_vsts saved for paste mode + char *b_p_vts; ///< 'vartabstop' + long *b_p_vts_array; ///< 'vartabstop' in internal format + char *b_p_keymap; ///< 'keymap' // local values for options which are normally global - char_u *b_p_gp; ///< 'grepprg' local value - char_u *b_p_mp; ///< 'makeprg' local value - char_u *b_p_efm; ///< 'errorformat' local value - char_u *b_p_ep; ///< 'equalprg' local value - char_u *b_p_path; ///< 'path' local value + char *b_p_gp; ///< 'grepprg' local value + char *b_p_mp; ///< 'makeprg' local value + char *b_p_efm; ///< 'errorformat' local value + char *b_p_ep; ///< 'equalprg' local value + char *b_p_path; ///< 'path' local value int b_p_ar; ///< 'autoread' local value - char_u *b_p_tags; ///< 'tags' local value - char_u *b_p_tc; ///< 'tagcase' local value + char *b_p_tags; ///< 'tags' local value + char *b_p_tc; ///< 'tagcase' local value unsigned b_tc_flags; ///< flags for 'tagcase' - char_u *b_p_dict; ///< 'dictionary' local value - char_u *b_p_tsr; ///< 'thesaurus' local value - char_u *b_p_tsrfu; ///< 'thesaurusfunc' local value + char *b_p_dict; ///< 'dictionary' local value + char *b_p_tsr; ///< 'thesaurus' local value + char *b_p_tsrfu; ///< 'thesaurusfunc' local value long b_p_ul; ///< 'undolevels' local value int b_p_udf; ///< 'undofile' - char_u *b_p_lw; ///< 'lispwords' local value + char *b_p_lw; ///< 'lispwords' local value // end of buffer options @@ -849,7 +847,7 @@ struct file_buffer { * spell buffer - used for spell info, never displayed and doesn't have a * file name. */ - bool b_help; // TRUE for help file buffer (when set b_p_bt + bool b_help; // true for help file buffer (when set b_p_bt // is "help") bool b_spell; // True for a spell file buffer, most fields // are not used! Use the B_SPELL macro to @@ -974,15 +972,15 @@ struct tabpage_S { * When the display is changed (e.g., when clearing the screen) w_lines_valid * is changed to exclude invalid entries. * When making changes to the buffer, wl_valid is reset to indicate wl_size - * may not reflect what is actually in the buffer. When wl_valid is FALSE, + * may not reflect what is actually in the buffer. When wl_valid is false, * the entries can only be used to count the number of displayed lines used. * wl_lnum and wl_lastlnum are invalid too. */ typedef struct w_line { linenr_T wl_lnum; // buffer line number for logical line uint16_t wl_size; // height in screen lines - char wl_valid; // TRUE values are valid for text in buffer - char wl_folded; // TRUE when this is a range of folded lines + char wl_valid; // true values are valid for text in buffer + char wl_folded; // true when this is a range of folded lines linenr_T wl_lastlnum; // last buffer line number for logical line } wline_T; @@ -1229,8 +1227,8 @@ struct window_S { */ linenr_T w_topline; /* buffer line number of the line at the top of the window */ - char w_topline_was_set; /* flag set to TRUE when topline is set, - e.g. by winrestview() */ + char w_topline_was_set; // flag set to true when topline is set, + // e.g. by winrestview() int w_topfill; // number of filler lines above w_topline int w_old_topfill; // w_topfill at last redraw bool w_botfill; // true when filler lines are actually @@ -1365,7 +1363,7 @@ struct window_S { linenr_T w_ru_topline; // topline shown in ruler linenr_T w_ru_line_count; // line count used for ruler int w_ru_topfill; // topfill shown in ruler - char w_ru_empty; // TRUE if ruler shows 0-1 (empty line) + char w_ru_empty; // true if ruler shows 0-1 (empty line) int w_alt_fnum; // alternate file (for # and CTRL-^) diff --git a/src/nvim/change.c b/src/nvim/change.c index ab54c3ea88..9ea970edb5 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -96,8 +96,7 @@ void changed(void) // Create a swap file if that is wanted. // Don't do this for "nofile" and "nowrite" buffer types. - if (curbuf->b_may_swap - && !bt_dontwrite(curbuf)) { + if (curbuf->b_may_swap && !bt_dontwrite(curbuf)) { bool save_need_wait_return = need_wait_return; need_wait_return = false; @@ -534,11 +533,62 @@ void unchanged(buf_T *buf, int ff, bool always_inc_changedtick) } } +/// Save the current values of 'fileformat' and 'fileencoding', so that we know +/// the file must be considered changed when the value is different. +void save_file_ff(buf_T *buf) +{ + buf->b_start_ffc = (unsigned char)(*buf->b_p_ff); + buf->b_start_eol = buf->b_p_eol; + buf->b_start_bomb = buf->b_p_bomb; + + // Only use free/alloc when necessary, they take time. + if (buf->b_start_fenc == NULL + || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) { + xfree(buf->b_start_fenc); + buf->b_start_fenc = xstrdup(buf->b_p_fenc); + } +} + +/// Return true if 'fileformat' and/or 'fileencoding' has a different value +/// from when editing started (save_file_ff() called). +/// Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was +/// changed and 'binary' is not set. +/// Also when 'endofline' was changed and 'fixeol' is not set. +/// When "ignore_empty" is true don't consider a new, empty buffer to be +/// changed. +bool file_ff_differs(buf_T *buf, bool ignore_empty) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT +{ + // In a buffer that was never loaded the options are not valid. + if (buf->b_flags & BF_NEVERLOADED) { + return false; + } + if (ignore_empty + && (buf->b_flags & BF_NEW) + && buf->b_ml.ml_line_count == 1 + && *ml_get_buf(buf, (linenr_T)1, false) == NUL) { + return false; + } + if (buf->b_start_ffc != *buf->b_p_ff) { + return true; + } + if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol) { + return true; + } + if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb) { + return true; + } + if (buf->b_start_fenc == NULL) { + return *buf->b_p_fenc != NUL; + } + return STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0; +} + /// Insert string "p" at the cursor position. Stops at a NUL byte. /// Handles Replace mode and multi-byte characters. -void ins_bytes(char_u *p) +void ins_bytes(char *p) { - ins_bytes_len(p, STRLEN(p)); + ins_bytes_len((char_u *)p, STRLEN(p)); } /// Insert string "p" with length "len" at the cursor position. @@ -1309,10 +1359,10 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // Doing "O" on the end of a comment inserts the middle leader. // Find the string for the middle leader, searching backwards. - while (p > (char *)curbuf->b_p_com && *p != ',') { + while (p > curbuf->b_p_com && *p != ',') { p--; } - for (lead_repl = p; lead_repl > (char *)curbuf->b_p_com + for (lead_repl = p; lead_repl > curbuf->b_p_com && lead_repl[-1] != ':'; lead_repl--) {} lead_repl_len = (int)(p - lead_repl); @@ -1795,7 +1845,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // Insert new stuff into line again curwin->w_cursor.col = 0; curwin->w_cursor.coladd = 0; - ins_bytes(p_extra); // will call changed_bytes() + ins_bytes((char *)p_extra); // will call changed_bytes() xfree(p_extra); next_line = NULL; } @@ -1814,16 +1864,16 @@ theend: /// If "fixpos" is true fix the cursor position when done. void truncate_line(int fixpos) { - char_u *newp; + char *newp; linenr_T lnum = curwin->w_cursor.lnum; colnr_T col = curwin->w_cursor.col; if (col == 0) { - newp = vim_strsave((char_u *)""); + newp = xstrdup(""); } else { - newp = vim_strnsave(ml_get(lnum), (size_t)col); + newp = (char *)vim_strnsave(ml_get(lnum), (size_t)col); } - ml_replace(lnum, (char *)newp, false); + ml_replace(lnum, newp, false); // mark the buffer as changed and prepare for displaying changed_bytes(lnum, curwin->w_cursor.col); @@ -1900,7 +1950,7 @@ int get_leader_len(char *line, char **flags, bool backward, bool include_space) while (line[i] != NUL) { // scan through the 'comments' option for a match int found_one = false; - for (list = (char *)curbuf->b_p_com; *list;) { + for (list = curbuf->b_p_com; *list;) { // Get one option part into part_buf[]. Advance "list" to next // one. Put "string" at start of string. if (!got_com && flags != NULL) { @@ -2037,7 +2087,7 @@ int get_last_leader_offset(char *line, char **flags) while (--i >= lower_check_bound) { // scan through the 'comments' option for a match int found_one = false; - for (list = (char *)curbuf->b_p_com; *list;) { + for (list = curbuf->b_p_com; *list;) { char *flags_save = list; // Get one option part into part_buf[]. Advance list to next one. @@ -2122,7 +2172,7 @@ int get_last_leader_offset(char *line, char **flags) } len1 = (int)STRLEN(com_leader); - for (list = (char *)curbuf->b_p_com; *list;) { + for (list = curbuf->b_p_com; *list;) { char *flags_save = list; (void)copy_option_part(&list, part_buf2, COM_MAX_LEN, ","); diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 6238d85b3a..d48cadf356 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -149,7 +149,7 @@ int buf_init_chartab(buf_T *buf, int global) p = p_isf; } else { // i == 3 // fourth round: 'iskeyword' - p = buf->b_p_isk; + p = (char_u *)buf->b_p_isk; } while (*p) { @@ -1655,7 +1655,7 @@ int hex2nr(int c) /// Convert two hex characters to a byte. /// Return -1 if one of the characters is not hex. -int hexhex2nr(char_u *p) +int hexhex2nr(const char_u *p) FUNC_ATTR_PURE { if (!ascii_isxdigit(p[0]) || !ascii_isxdigit(p[1])) { diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 90d621ae1e..fa1c669aaf 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -797,8 +797,8 @@ static int diff_write(buf_T *buf, diffin_T *din) } // Always use 'fileformat' set to "unix". - char_u *save_ff = buf->b_p_ff; - buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); + char *save_ff = buf->b_p_ff; + buf->b_p_ff = xstrdup(FF_UNIX); const bool save_cmod_flags = cmdmod.cmod_flags; // Writing the buffer is an implementation detail of performing the diff, // so it shouldn't update the '[ and '] marks. @@ -1413,7 +1413,7 @@ void diff_win_options(win_T *wp, int addbuf) if (wp->w_p_diff_saved) { free_string_option(wp->w_p_fdm_save); } - wp->w_p_fdm_save = vim_strsave(wp->w_p_fdm); + wp->w_p_fdm_save = xstrdup(wp->w_p_fdm); } set_string_option_direct_in_win(wp, "fdm", -1, "diff", OPT_LOCAL | OPT_FREE, 0); @@ -1424,12 +1424,12 @@ void diff_win_options(win_T *wp, int addbuf) if (wp->w_p_diff_saved) { free_string_option(wp->w_p_fdc_save); } - wp->w_p_fdc_save = vim_strsave(wp->w_p_fdc); + wp->w_p_fdc_save = xstrdup(wp->w_p_fdc); } free_string_option(wp->w_p_fdc); - wp->w_p_fdc = (char_u *)xstrdup("2"); + wp->w_p_fdc = xstrdup("2"); assert(diff_foldcolumn >= 0 && diff_foldcolumn <= 9); - snprintf((char *)wp->w_p_fdc, STRLEN(wp->w_p_fdc) + 1, "%d", diff_foldcolumn); + snprintf(wp->w_p_fdc, STRLEN(wp->w_p_fdc) + 1, "%d", diff_foldcolumn); wp->w_p_fen = true; wp->w_p_fdl = 0; foldUpdateAll(wp); @@ -1480,11 +1480,9 @@ void ex_diffoff(exarg_T *eap) } } free_string_option(wp->w_p_fdm); - wp->w_p_fdm = vim_strsave(*wp->w_p_fdm_save - ? wp->w_p_fdm_save - : (char_u *)"manual"); + wp->w_p_fdm = xstrdup(*wp->w_p_fdm_save ? wp->w_p_fdm_save : "manual"); free_string_option(wp->w_p_fdc); - wp->w_p_fdc = vim_strsave(wp->w_p_fdc_save); + wp->w_p_fdc = xstrdup(wp->w_p_fdc_save); if (wp->w_p_fdl == 0) { wp->w_p_fdl = wp->w_p_fdl_save; diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 2b1b2607fb..9132d6666e 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -277,7 +277,7 @@ static bool use_cursor_line_sign(win_T *wp, linenr_T lnum) } // Get information needed to display the sign in line 'lnum' in window 'wp'. -// If 'nrcol' is TRUE, the sign is going to be displayed in the number column. +// If 'nrcol' is true, the sign is going to be displayed in the number column. // Otherwise the sign is going to be displayed in the sign column. // // @param count max number of signs @@ -1247,7 +1247,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, } char_attr = 0; } else if (filler_todo > 0) { - // draw "deleted" diff line(s) + // Draw "deleted" diff line(s) if (char2cells(wp->w_p_fcs_chars.diff) > 1) { c_extra = '-'; c_final = NUL; @@ -2082,7 +2082,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, if (wp->w_p_cole > 0 && (wp != curwin || lnum != wp->w_cursor.lnum || conceal_cursor_line(wp)) && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0 || decor_conceal > 0) - && !(lnum_in_visual_area && vim_strchr((char *)wp->w_p_cocu, 'v') == NULL)) { + && !(lnum_in_visual_area && vim_strchr(wp->w_p_cocu, 'v') == NULL)) { char_attr = conceal_attr; if (((prev_syntax_id != syntax_seqnr && (syntax_flags & HL_CONCEAL) != 0) || has_match_conc > 1 || decor_conceal > 1) diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index 012c4ecb19..cf8178a30f 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -1920,8 +1920,9 @@ win_update_start: wp->w_botline = lnum; } - // make sure the rest of the screen is blank - // write the 'eob' character to rows that aren't part of the file. + // Make sure the rest of the screen is blank. + // write the "eob" character from 'fillchars' to rows that aren't part + // of the file. win_draw_end(wp, wp->w_p_fcs_chars.eob, ' ', false, row, wp->w_grid.rows, HLF_EOB); } diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 79317d3df6..82429d6542 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1575,7 +1575,7 @@ static void undisplay_dollar(void) /// type == INDENT_DEC decrease indent (for CTRL-D) /// type == INDENT_SET set indent to "amount" /// -/// @param round if TRUE, round the indent to 'shiftwidth' (only with _INC and _Dec). +/// @param round if true, round the indent to 'shiftwidth' (only with _INC and _Dec). /// @param replaced replaced character, put on replace stack /// @param call_changed_bytes call changed_bytes() void change_indent(int type, int amount, int round, int replaced, int call_changed_bytes) @@ -1599,7 +1599,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang // for the following tricks we don't want list mode save_p_list = curwin->w_p_list; - curwin->w_p_list = FALSE; + curwin->w_p_list = false; vc = getvcol_nolist(&curwin->w_cursor); vcol = vc; @@ -1718,7 +1718,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang } else { curwin->w_cursor.col = (colnr_T)new_cursor_col; } - curwin->w_set_curswant = TRUE; + curwin->w_set_curswant = true; changed_cline_bef_curs(); /* @@ -1780,7 +1780,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang backspace_until_column(0); // Insert new stuff into line again - ins_bytes(new_line); + ins_bytes((char *)new_line); xfree(new_line); @@ -1978,7 +1978,7 @@ static void insert_special(int c, int allow_modmask, int ctrlv) // inserted with ins_str(), so as not to replace characters in replace // mode. // Only use mod_mask for special keys, to avoid things like <S-Space>, - // unless 'allow_modmask' is TRUE. + // unless 'allow_modmask' is true. if (mod_mask & MOD_MASK_CMD) { // Command-key never produces a normal key. allow_modmask = true; } @@ -2595,7 +2595,7 @@ static void internal_format(int textwidth, int second_indent, int flags, int for if (State & VREPLACE_FLAG) { // In MODE_VREPLACE state we have backspaced over the text to be // moved, now we re-insert it into the new line. - ins_bytes(saved_text); + ins_bytes((char *)saved_text); xfree(saved_text); } else { /* @@ -3086,7 +3086,7 @@ void beginline(int flags) curwin->w_cursor.col++; } } - curwin->w_set_curswant = TRUE; + curwin->w_set_curswant = true; } } @@ -3130,7 +3130,7 @@ int oneright(void) } curwin->w_cursor.col += l; - curwin->w_set_curswant = TRUE; + curwin->w_set_curswant = true; return OK; } @@ -3165,7 +3165,7 @@ int oneleft(void) } } - curwin->w_set_curswant = TRUE; + curwin->w_set_curswant = true; return OK; } @@ -3182,7 +3182,7 @@ int oneleft(void) return OK; } -/// @oaram upd_topline When TRUE: update topline +/// @oaram upd_topline When true: update topline int cursor_up(long n, int upd_topline) { linenr_T lnum; @@ -3237,7 +3237,7 @@ int cursor_up(long n, int upd_topline) /// Cursor down a number of logical lines. /// -/// @param upd_topline When TRUE: update topline +/// @param upd_topline When true: update topline int cursor_down(long n, int upd_topline) { linenr_T lnum; @@ -3689,9 +3689,9 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) } if (*curbuf->b_p_inde != NUL) { - look = curbuf->b_p_indk; // 'indentexpr' set: use 'indentkeys' + look = (char_u *)curbuf->b_p_indk; // 'indentexpr' set: use 'indentkeys' } else { - look = curbuf->b_p_cink; // 'indentexpr' empty: use 'cinkeys' + look = (char_u *)curbuf->b_p_cink; // 'indentexpr' empty: use 'cinkeys' } while (*look) { /* @@ -4007,13 +4007,13 @@ static void ins_reg(void) no_mapping++; allow_keys++; regname = plain_vgetc(); - LANGMAP_ADJUST(regname, TRUE); + LANGMAP_ADJUST(regname, true); if (regname == Ctrl_R || regname == Ctrl_O || regname == Ctrl_P) { // Get a third key for literal register insertion literally = regname; add_to_showcmd_c(literally); regname = plain_vgetc(); - LANGMAP_ADJUST(regname, TRUE); + LANGMAP_ADJUST(regname, true); } no_mapping--; allow_keys--; @@ -4051,7 +4051,7 @@ static void ins_reg(void) need_redraw = true; // remove the '"' } else if (stop_insert_mode) { // When the '=' register was used and a function was invoked that - // did ":stopinsert" then stuff_empty() returns FALSE but we won't + // did ":stopinsert" then stuff_empty() returns false but we won't // insert anything, need to remove the '"' need_redraw = true; } @@ -4202,7 +4202,7 @@ static bool ins_esc(long *count, int cmdchar, bool nomove) // Repeat the insert return false; } - stop_insert(&curwin->w_cursor, TRUE, nomove); + stop_insert(&curwin->w_cursor, true, nomove); undisplay_dollar(); } @@ -4400,9 +4400,9 @@ static void ins_shift(int c, int lastc) if (lastc == '^') { old_indent = get_indent(); // remember curr. indent } - change_indent(INDENT_SET, 0, TRUE, 0, TRUE); + change_indent(INDENT_SET, 0, true, 0, true); } else { - change_indent(c == Ctrl_D ? INDENT_DEC : INDENT_INC, 0, TRUE, 0, TRUE); + change_indent(c == Ctrl_D ? INDENT_DEC : INDENT_INC, 0, true, 0, true); } if (did_ai && *skipwhite((char *)get_cursor_line_ptr()) != NUL) { @@ -4574,7 +4574,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) } } - do_join(2, FALSE, FALSE, FALSE, false); + do_join(2, false, false, false, false); if (temp == NUL && gchar_cursor() != NUL) { inc_cursor(); } @@ -4856,7 +4856,7 @@ static void ins_mousescroll(int dir) } } - curwin->w_redr_status = TRUE; + curwin->w_redr_status = true; curwin = old_curwin; curbuf = curwin->w_buffer; @@ -5024,7 +5024,7 @@ static void ins_up(bool startcol) undisplay_dollar(); tpos = curwin->w_cursor; - if (cursor_up(1L, TRUE) == OK) { + if (cursor_up(1L, true) == OK) { if (startcol) { coladvance(getvcol_nolist(&Insstart)); } @@ -5072,7 +5072,7 @@ static void ins_down(bool startcol) undisplay_dollar(); tpos = curwin->w_cursor; - if (cursor_down(1L, TRUE) == OK) { + if (cursor_down(1L, true) == OK) { if (startcol) { coladvance(getvcol_nolist(&Insstart)); } @@ -5407,7 +5407,7 @@ static int ins_digraph(void) if (IS_SPECIAL(c) || mod_mask) { // special key clear_showcmd(); - insert_special(c, TRUE, FALSE); + insert_special(c, true, false); return NUL; } if (c != ESC) { @@ -5508,7 +5508,7 @@ static int ins_ctrl_ey(int tc) } tw_save = curbuf->b_p_tw; curbuf->b_p_tw = -1; - insert_special(c, TRUE, FALSE); + insert_special(c, true, false); curbuf->b_p_tw = tw_save; revins_chars++; revins_legal++; @@ -5557,7 +5557,7 @@ static void ins_try_si(int c) i = get_indent(); curwin->w_cursor = old_pos; if (State & VREPLACE_FLAG) { - change_indent(INDENT_SET, i, FALSE, NUL, TRUE); + change_indent(INDENT_SET, i, false, NUL, true); } else { (void)set_indent(i, SIN_CHANGED); } @@ -5582,7 +5582,7 @@ static void ins_try_si(int c) curwin->w_cursor = old_pos; } if (temp) { - shift_line(TRUE, FALSE, 1, TRUE); + shift_line(true, false, 1, true); } } } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 1458d1ff36..adcc173c71 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -101,7 +101,7 @@ static garray_T ga_loaded = { 0, 0, sizeof(char *), 4, NULL }; /// Info used by a ":for" loop. typedef struct { - int fi_semicolon; // TRUE if ending in '; var]' + int fi_semicolon; // true if ending in '; var]' int fi_varcount; // nr of variables in the list listwatch_T fi_lw; // keep an eye on the item used. list_T *fi_list; // list being used @@ -691,11 +691,11 @@ void eval_patch(const char *const origfile, const char *const difffile, const ch } /// Top level evaluation function, returning a boolean. -/// Sets "error" to TRUE if there was an error. +/// Sets "error" to true if there was an error. /// /// @param skip only parse, don't execute /// -/// @return TRUE or FALSE. +/// @return true or false. int eval_to_bool(char *arg, bool *error, char **nextcmd, int skip) { typval_T tv; @@ -895,7 +895,7 @@ char *eval_to_string(char *arg, char **nextcmd, bool convert) /// Call eval_to_string() without using current local variables and using /// textlock. /// -/// @param use_sandbox when TRUE, use the sandbox. +/// @param use_sandbox when true, use the sandbox. char *eval_to_string_safe(char *arg, char **nextcmd, int use_sandbox) { char *retval; @@ -1812,7 +1812,7 @@ notify: /// Evaluate the expression used in a ":for var in expr" command. /// "arg" points to "var". /// -/// @param[out] *errp set to TRUE for an error, FALSE otherwise; +/// @param[out] *errp set to true for an error, false otherwise; /// /// @return a pointer that holds the info. Null when there is an error. void *eval_for_line(const char *arg, bool *errp, char **nextcmdp, int skip) @@ -2184,7 +2184,7 @@ char *get_user_var_name(expand_T *xp, int idx) /// Does not use 'cpo' and always uses 'magic'. /// -/// @return TRUE if "pat" matches "text". +/// @return true if "pat" matches "text". int pattern_match(char *pat, char *text, bool ic) { int matches = 0; @@ -2192,7 +2192,7 @@ int pattern_match(char *pat, char *text, bool ic) // avoid 'l' flag in 'cpoptions' char *save_cpo = p_cpo; - p_cpo = (char *)empty_option; + p_cpo = empty_option; regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); if (regmatch.regprog != NULL) { regmatch.rm_ic = ic; @@ -2263,13 +2263,13 @@ static int eval_func(char **const arg, char *const name, const int name_len, typ // TODO(ZyX-I): move to eval/expressions -/// The "evaluate" argument: When FALSE, the argument is only parsed but not +/// The "evaluate" argument: When false, the argument is only parsed but not /// executed. The function may return OK, but the rettv will be of type /// VAR_UNKNOWN. The function still returns FAIL for a syntax error. /// Handle zero level expression. /// This calls eval1() and handles error message and nextcmd. -/// Put the result in "rettv" when returning OK and "evaluate" is TRUE. +/// Put the result in "rettv" when returning OK and "evaluate" is true. /// Note: "rettv.v_lock" is not set. /// /// @return OK or FAIL. @@ -6786,14 +6786,14 @@ static char *make_expanded_name(const char *in_start, char *expr_start, char *ex return retval; } -/// @return TRUE if character "c" can be used in a variable or function name. +/// @return true if character "c" can be used in a variable or function name. /// Does not include '{' or '}' for magic braces. int eval_isnamec(int c) { return ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR; } -/// @return TRUE if character "c" can be used as the first character in a +/// @return true if character "c" can be used as the first character in a /// variable or function name (excluding '{' and '}'). int eval_isnamec1(int c) { @@ -6846,7 +6846,7 @@ void set_vim_var_char(int c) /// Set v:count to "count" and v:count1 to "count1". /// -/// @param set_prevcount if TRUE, first set v:prevcount from v:count. +/// @param set_prevcount if true, first set v:prevcount from v:count. void set_vcount(long count, long count1, int set_prevcount) { if (set_prevcount) { @@ -8326,7 +8326,7 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, char *flags // Make 'cpoptions' empty, so that the 'l' flag doesn't work here char *save_cpo = p_cpo; - p_cpo = (char *)empty_option; + p_cpo = empty_option; ga_init(&ga, 1, 200); @@ -8386,7 +8386,7 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, char *flags char *ret = xstrdup(ga.ga_data == NULL ? str : ga.ga_data); ga_clear(&ga); - if ((char_u *)p_cpo == empty_option) { + if (p_cpo == empty_option) { p_cpo = save_cpo; } else { // Darn, evaluating {sub} expression or {expr} changed the value. @@ -8395,7 +8395,7 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, char *flags if (*p_cpo == NUL) { set_option_value_give_err("cpo", 0L, save_cpo, 0); } - free_string_option((char_u *)save_cpo); + free_string_option(save_cpo); } return ret; diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index fc926cf5a9..78298765a0 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -234,7 +234,7 @@ int call_internal_method(const char_u *const fname, const int argcount, typval_T return ERROR_NONE; } -/// @return TRUE for a non-zero Number and a non-empty String. +/// @return true for a non-zero Number and a non-empty String. static int non_zero_arg(typval_T *argvars) { return ((argvars[0].v_type == VAR_NUMBER @@ -591,7 +591,7 @@ buf_T *tv_get_buf(typval_T *tv, int curtab_only) int save_magic = p_magic; p_magic = true; char *save_cpo = p_cpo; - p_cpo = (char *)empty_option; + p_cpo = empty_option; buf_T *buf = buflist_findnr(buflist_findpat((char *)name, (char *)name + STRLEN(name), true, false, curtab_only)); @@ -2224,7 +2224,7 @@ static void f_filewritable(typval_T *argvars, typval_T *rettv, EvalFuncData fptr static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what) { char_u *fresult = NULL; - char_u *path = *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path; + char_u *path = *curbuf->b_p_path == NUL ? p_path : (char_u *)curbuf->b_p_path; int count = 1; bool first = true; bool error = false; @@ -2265,7 +2265,7 @@ static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what) find_what, (char_u *)curbuf->b_ffname, (find_what == FINDFILE_DIR ? (char_u *)"" - : curbuf->b_p_sua)); + : (char_u *)curbuf->b_p_sua)); first = false; if (fresult != NULL && rettv->v_type == VAR_LIST) { @@ -2548,7 +2548,7 @@ static void f_getbufinfo(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// Get line or list of lines from buffer "buf" into "rettv". /// -/// @param retlist if TRUE, then the lines are returned as a Vim List. +/// @param retlist if true, then the lines are returned as a Vim List. /// /// @return range (from start to end) of lines in rettv from the specified /// buffer. @@ -4903,7 +4903,7 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv, // Make 'cpoptions' empty, the 'l' flag should not be used here. char *save_cpo = p_cpo; - p_cpo = (char *)empty_option; + p_cpo = empty_option; rettv->vval.v_number = -1; switch (type) { @@ -6312,7 +6312,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) v = os_realpath(fname, v); } } - rettv->vval.v_string = (char_u *)(v == NULL ? xstrdup(fname) : v); + rettv->vval.v_string = (v == NULL ? xstrdup(fname) : v); #else # ifdef HAVE_READLINK { @@ -7293,7 +7293,7 @@ long do_searchpair(const char *spat, const char *mpat, const char *epat, int dir // Make 'cpoptions' empty, the 'l' flag should not be used here. char *save_cpo = p_cpo; - p_cpo = (char *)empty_option; + p_cpo = empty_option; // Set the time limit, if there is one. proftime_T tm = profile_setlimit(time_limit); @@ -7419,7 +7419,7 @@ long do_searchpair(const char *spat, const char *mpat, const char *epat, int dir xfree(pat2); xfree(pat3); - if ((char_u *)p_cpo == empty_option) { + if (p_cpo == empty_option) { p_cpo = save_cpo; } else { // Darn, evaluating the {skip} expression changed the value. @@ -7428,7 +7428,7 @@ long do_searchpair(const char *spat, const char *mpat, const char *epat, int dir if (*p_cpo == NUL) { set_option_value_give_err("cpo", 0L, save_cpo, 0); } - free_string_option((char_u *)save_cpo); + free_string_option(save_cpo); } return retval; @@ -7549,7 +7549,7 @@ static void f_setbufline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } /// Set the cursor or mark position. -/// If 'charpos' is TRUE, then use the column number as a character offset. +/// If 'charpos' is true, then use the column number as a character offset. /// Otherwise use the column number as a byte offset. static void set_position(typval_T *argvars, typval_T *rettv, bool charpos) { @@ -8182,7 +8182,7 @@ static void f_split(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) // Make 'cpoptions' empty, the 'l' flag should not be used here. char *save_cpo = p_cpo; - p_cpo = (char *)empty_option; + p_cpo = empty_option; const char *str = tv_get_string(&argvars[0]); const char *pat = NULL; diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index bb2e2b19c2..8cb7a075cb 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1083,7 +1083,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett const sctx_T save_current_sctx = current_sctx; current_sctx = fp->uf_script_ctx; save_did_emsg = did_emsg; - did_emsg = FALSE; + did_emsg = false; if (default_arg_err && (fp->uf_flags & FC_ABORT)) { did_emsg = true; @@ -2012,14 +2012,14 @@ void ex_function(exarg_T *eap) xfree(fudi.fd_newkey); return; } else { - eap->skip = TRUE; + eap->skip = true; } } // An error in a function call during evaluation of an expression in magic // braces should not cause the function not to be defined. saved_did_emsg = did_emsg; - did_emsg = FALSE; + did_emsg = false; // // ":function func" with only function name: list function. @@ -2853,7 +2853,7 @@ void ex_return(exarg_T *eap) { char_u *arg = (char_u *)eap->arg; typval_T rettv; - int returning = FALSE; + int returning = false; if (current_funccal == NULL) { emsg(_("E133: :return not inside a function")); @@ -3035,8 +3035,8 @@ end: /// @param is_cmd set when called due to a ":return" command. /// @param rettv may point to a typval_T with the return rettv. /// -/// @return TRUE when the return can be carried out, -/// FALSE when the return gets pending. +/// @return true when the return can be carried out, +/// false when the return gets pending. int do_return(exarg_T *eap, int reanimate, int is_cmd, void *rettv) { int idx; @@ -3086,7 +3086,7 @@ int do_return(exarg_T *eap, int reanimate, int is_cmd, void *rettv) } report_make_pending(CSTP_RETURN, rettv); } else { - current_funccal->returned = TRUE; + current_funccal->returned = true; // If the return is carried out now, store the return value. For // a return immediately after reanimation, the value is already @@ -3178,7 +3178,7 @@ char *get_func_line(int c, void *cookie, int indent, bool do_concat) return (char *)retval; } -/// @return TRUE if the currently active function should be ended, because a +/// @return true if the currently active function should be ended, because a /// return was encountered or an error occurred. Used inside a ":while". int func_has_ended(void *cookie) { @@ -3190,7 +3190,7 @@ int func_has_ended(void *cookie) || fcp->returned; } -/// @return TRUE if cookie indicates a function which "abort"s on errors. +/// @return true if cookie indicates a function which "abort"s on errors. int func_has_abort(void *cookie) { return ((funccall_T *)cookie)->func->uf_flags & FC_ABORT; @@ -3281,7 +3281,7 @@ int func_level(void *cookie) return ((funccall_T *)cookie)->level; } -/// @return TRUE when a function was ended by a ":return" command. +/// @return true when a function was ended by a ":return" command. int current_func_returned(void) { return current_funccal->returned; diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index d1336b4e28..0086cc41ca 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -1119,7 +1119,7 @@ void vars_clear(hashtab_T *ht) vars_clear_ext(ht, true); } -/// Like vars_clear(), but only free the value if "free_val" is TRUE. +/// Like vars_clear(), but only free the value if "free_val" is true. void vars_clear_ext(hashtab_T *ht, int free_val) { int todo; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index e08e977ff5..91df8c169a 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -274,7 +274,7 @@ void ex_align(exarg_T *eap) if (eap->cmdidx == CMD_left) { // left align new_indent = indent; } else { - has_tab = FALSE; // avoid uninit warnings + has_tab = false; // avoid uninit warnings len = linelen(eap->cmdidx == CMD_right ? &has_tab : NULL) - get_indent(); @@ -404,7 +404,7 @@ static int sort_compare(const void *s1, const void *s2) } fast_breakcheck(); if (got_int) { - sort_abort = TRUE; + sort_abort = true; } // When sorting numbers "start_col_nr" is the number, not the column @@ -1150,7 +1150,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } if (addr_count == 0) { // :! - msg_scroll = FALSE; // don't scroll here + msg_scroll = false; // don't scroll here autowrite_all(); msg_scroll = scroll_save; } @@ -1376,14 +1376,14 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b call_shell((char_u *)cmd_buf, (ShellOpts)(kShellOptFilter | shell_flags), NULL); xfree(cmd_buf); - did_check_timestamps = FALSE; - need_check_timestamps = TRUE; + did_check_timestamps = false; + need_check_timestamps = true; // When interrupting the shell command, it may still have produced some // useful output. Reset got_int here, so that readfile() won't cancel // reading. os_breakcheck(); - got_int = FALSE; + got_int = false; if (do_out) { if (otmp != NULL) { @@ -1714,7 +1714,7 @@ void print_line(linenr_T lnum, int use_number, int list) } msg_start(); - silent_mode = FALSE; + silent_mode = false; info_message = true; // use mch_msg(), not mch_errmsg() print_line_no_prefix(lnum, use_number, list); if (save_silent) { @@ -1822,7 +1822,7 @@ void ex_write(exarg_T *eap) } /// write current buffer to file 'eap->arg' -/// if 'eap->append' is TRUE, append to the file +/// if 'eap->append' is true, append to the file /// /// if *eap->arg == NUL write to current file /// @@ -1847,7 +1847,7 @@ int do_write(exarg_T *eap) emsg(_(e_argreq)); goto theend; } - other = FALSE; + other = false; } else { fname = ffname; free_fname = fix_fname(ffname); @@ -1880,8 +1880,7 @@ int do_write(exarg_T *eap) // Writing to the current file is not allowed in readonly mode // and a file name is required. // "nofile" and "nowrite" buffers cannot be written implicitly either. - if (!other && (bt_dontwrite_msg(curbuf) - || check_fname() == FAIL + if (!other && (bt_dontwrite_msg(curbuf) || check_fname() == FAIL || check_readonly(&eap->forceit, curbuf))) { goto theend; } @@ -1900,7 +1899,7 @@ int do_write(exarg_T *eap) (char_u *)_("Write partial file?"), 2) != VIM_YES) { goto theend; } - eap->forceit = TRUE; + eap->forceit = true; } else { emsg(_("E140: Use ! to write partial buffer")); goto theend; @@ -1937,8 +1936,8 @@ int do_write(exarg_T *eap) apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, false, curbuf); apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, false, alt_buf); if (!alt_buf->b_p_bl) { - alt_buf->b_p_bl = TRUE; - apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, alt_buf); + alt_buf->b_p_bl = true; + apply_autocmds(EVENT_BUFADD, NULL, NULL, false, alt_buf); } if (curbuf != was_curbuf || aborting()) { // buffer changed, don't write the file @@ -1966,7 +1965,7 @@ int do_write(exarg_T *eap) // After ":saveas fname" reset 'readonly'. if (eap->cmdidx == CMD_saveas) { if (retval == OK) { - curbuf->b_p_ro = FALSE; + curbuf->b_p_ro = false; redraw_tabline = true; } } @@ -2018,7 +2017,7 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, int oth if (vim_dialog_yesno(VIM_QUESTION, NULL, (char_u *)buff, 2) != VIM_YES) { return FAIL; } - eap->forceit = TRUE; + eap->forceit = true; } else { emsg(_(e_exists)); return FAIL; @@ -2058,7 +2057,7 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, int oth xfree(swapname); return FAIL; } - eap->forceit = TRUE; + eap->forceit = true; } else { semsg(_("E768: Swap file exists: %s (:silent! overrides)"), swapname); @@ -2159,7 +2158,7 @@ bool not_writing(void) } /// Check if a buffer is read-only (either 'readonly' option is set or file is -/// read-only). Ask for overruling in a dialog. Return TRUE and give an error +/// read-only). Ask for overruling in a dialog. Return true and give an error /// message when the buffer is readonly. static int check_readonly(int *forceit, buf_T *buf) { @@ -2184,10 +2183,10 @@ static int check_readonly(int *forceit, buf_T *buf) if (vim_dialog_yesno(VIM_QUESTION, NULL, (char_u *)buff, 2) == VIM_YES) { // Set forceit, to force the writing of a readonly file - *forceit = TRUE; - return FALSE; + *forceit = true; + return false; } else { - return TRUE; + return true; } } else if (buf->b_p_ro) { emsg(_(e_readonly)); @@ -2195,10 +2194,10 @@ static int check_readonly(int *forceit, buf_T *buf) semsg(_("E505: \"%s\" is read-only (add ! to override)"), buf->b_fname); } - return TRUE; + return true; } - return FALSE; + return false; } /// Try to abandon the current file and edit a new or existing file. @@ -2292,7 +2291,7 @@ theend: /// ECMD_LASTL: use last position in loaded file /// ECMD_LAST: use last position in all files /// ECMD_ONE: use first line -/// @param flags ECMD_HIDE: if TRUE don't free the current buffer +/// @param flags ECMD_HIDE: if true don't free the current buffer /// ECMD_SET_HELP: set b_help flag of (new) buffer before /// opening file /// ECMD_OLDBUF: use existing buffer if it exists @@ -2310,7 +2309,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum win_T *oldwin) { bool other_file; // true if editing another file - int oldbuf; // TRUE if using existing buffer + int oldbuf; // true if using existing buffer bool auto_buf = false; // true if autocommands brought us // into the buffer unexpectedly char *new_name = NULL; @@ -2386,7 +2385,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // If the file was changed we may not be allowed to abandon it: // - if we are going to re-edit the same file - // - or if we are the only window on this file and if ECMD_HIDE is FALSE + // - or if we are the only window on this file and if ECMD_HIDE is false if (((!other_file && !(flags & ECMD_OLDBUF)) || (curbuf->b_nwindows == 1 && !(flags & (ECMD_HIDE | ECMD_ADDBUF | ECMD_ALTBUF)))) @@ -2504,7 +2503,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum /* * Make the (new) buffer the one used by the current window. - * If the old buffer becomes unused, free it if ECMD_HIDE is FALSE. + * If the old buffer becomes unused, free it if ECMD_HIDE is false. * If the current buffer was empty and has no file name, curbuf * is returned by buflist_new(), nothing to do here. */ @@ -2605,7 +2604,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // Set 'fileformat', 'binary' and 'fenc' when forced. if (!oldbuf && eap != NULL) { - set_file_options(TRUE, eap); + set_file_options(true, eap); set_forced_fenc(eap); } } @@ -2641,7 +2640,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum } else if (!curbuf->b_help) { // Don't make a buffer listed if it's a help buffer. Useful when using // CTRL-O to go back to a help file. - set_buflisted(TRUE); + set_buflisted(true); } // If autocommands change buffers under our fingers, forget about @@ -2660,10 +2659,10 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum /* * other_file oldbuf - * FALSE FALSE re-edit same file, buffer is re-used - * FALSE TRUE re-edit same file, nothing changes - * TRUE FALSE start editing new file, new buffer - * TRUE TRUE start editing in existing buffer (nothing to do) + * false false re-edit same file, buffer is re-used + * false true re-edit same file, nothing changes + * true false start editing new file, new buffer + * true true start editing in existing buffer (nothing to do) */ if (!other_file && !oldbuf) { // re-use the buffer set_last_cursor(curwin); // may set b_last_cursor @@ -2790,7 +2789,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // changed by the user. do_modelines(OPT_WINONLY); - apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, + apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, false, curbuf, &retval); if ((flags & ECMD_NOWINENTER) == 0) { apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, false, curbuf, @@ -2848,7 +2847,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum curwin->w_cursor.col = solcol; check_cursor_col(); curwin->w_cursor.coladd = 0; - curwin->w_set_curswant = TRUE; + curwin->w_set_curswant = true; } else { beginline(BL_SOL | BL_FIX); } @@ -2874,7 +2873,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // Obey the 'O' flag in 'cpoptions': overwrite any previous file // message. if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) { - msg_scroll = FALSE; + msg_scroll = false; } if (!msg_scroll) { // wait a bit when overwriting an error msg check_for_delay(false); @@ -3804,7 +3803,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // Save the line number of the last change for the final // cursor position (just like Vi). curwin->w_cursor.lnum = lnum; - do_again = FALSE; + do_again = false; /* * 1. Match empty string does not count, except for first @@ -3955,7 +3954,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T - regmatch.startpos[0].lnum; search_match_endcol = regmatch.endpos[0].col + len_change; - highlight_match = TRUE; + highlight_match = true; update_topline(curwin); validate_cursor(); @@ -4768,10 +4767,9 @@ bool prepare_tagpreview(bool undo_sync) == FAIL) { return false; } - curwin->w_p_pvw = TRUE; - curwin->w_p_wfh = TRUE; - RESET_BINDING(curwin); /* don't take over 'scrollbind' - and 'cursorbind' */ + curwin->w_p_pvw = true; + curwin->w_p_wfh = true; + RESET_BINDING(curwin); // don't take over 'scrollbind' and 'cursorbind' curwin->w_p_diff = false; // no 'diff' set_string_option_direct("fdc", -1, // no 'foldcolumn' "0", OPT_FREE, SID_NONE); diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 2ed45f7ab8..41512205dc 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -680,11 +680,11 @@ void ex_listdo(exarg_T *eap) // buffer was opened while Syntax autocommands were disabled, // need to trigger them now. if (buf == curbuf) { - apply_autocmds(EVENT_SYNTAX, (char *)curbuf->b_p_syn, curbuf->b_fname, true, + apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname, true, curbuf); } else { aucmd_prepbuf(&aco, buf); - apply_autocmds(EVENT_SYNTAX, (char *)buf->b_p_syn, buf->b_fname, true, buf); + apply_autocmds(EVENT_SYNTAX, buf->b_p_syn, buf->b_fname, true, buf); aucmd_restbuf(&aco); } diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h index e80e47bcff..5d8ed64c60 100644 --- a/src/nvim/ex_cmds_defs.h +++ b/src/nvim/ex_cmds_defs.h @@ -188,7 +188,7 @@ struct exarg { cmdidx_T cmdidx; ///< the index for the command uint32_t argt; ///< flags for the command int skip; ///< don't execute the command, only parse it - int forceit; ///< TRUE if ! present + int forceit; ///< true if ! present int addr_count; ///< the number of addresses given linenr_T line1; ///< the first line number linenr_T line2; ///< the second line number or count @@ -196,8 +196,8 @@ struct exarg { int flags; ///< extra flags after count: EXFLAG_ char *do_ecmd_cmd; ///< +command arg to be used in edited file linenr_T do_ecmd_lnum; ///< the line number in an edited file - int append; ///< TRUE with ":w >>file" command - int usefilter; ///< TRUE with ":w !command" and ":r!command" + int append; ///< true with ":w >>file" command + int usefilter; ///< true with ":w !command" and ":r!command" int amount; ///< number of '>' or '<' for shift command int regname; ///< register name (NUL if none) int force_bin; ///< 0, FORCE_BIN or FORCE_NOBIN @@ -230,7 +230,7 @@ struct expand { sctx_T xp_script_ctx; // SCTX for completion function int xp_backslash; // one of the XP_BS_ values #ifndef BACKSLASH_IN_FILENAME - int xp_shell; // TRUE for a shell command, more + int xp_shell; // true for a shell command, more // characters need to be escaped #endif int xp_numfiles; // number of files found by file name completion diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 8f2a98b401..29812dd8fe 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2602,7 +2602,7 @@ void undo_cmdmod(cmdmod_T *cmod) if (cmod->cmod_save_ei != NULL) { // Restore 'eventignore' to the value before ":noautocmd". set_string_option_direct("ei", -1, cmod->cmod_save_ei, OPT_FREE, SID_NONE); - free_string_option((char_u *)cmod->cmod_save_ei); + free_string_option(cmod->cmod_save_ei); cmod->cmod_save_ei = NULL; } @@ -3646,8 +3646,8 @@ char *replace_makeprg(exarg_T *eap, char *arg, char **cmdlinep) // Don't do it when ":vimgrep" is used for ":grep". if ((eap->cmdidx == CMD_make || eap->cmdidx == CMD_lmake || isgrep) && !grep_internal(eap->cmdidx)) { - const char *program = isgrep ? (*curbuf->b_p_gp == NUL ? (char *)p_gp : (char *)curbuf->b_p_gp) - : (*curbuf->b_p_mp == NUL ? (char *)p_mp : (char *)curbuf->b_p_mp); + const char *program = isgrep ? (*curbuf->b_p_gp == NUL ? (char *)p_gp : curbuf->b_p_gp) + : (*curbuf->b_p_mp == NUL ? (char *)p_mp : curbuf->b_p_mp); arg = skipwhite(arg); diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 5ddcb0270b..19dcc06825 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -45,7 +45,7 @@ // there or even outside the try conditional. Try conditionals may be nested. // Configuration whether an exception is thrown on error or interrupt. When -// the preprocessor macros below evaluate to FALSE, an error (did_emsg) or +// the preprocessor macros below evaluate to false, an error (did_emsg) or // interrupt (got_int) under an active try conditional terminates the script // after the non-active finally clauses of all active try conditionals have been // executed. Otherwise, errors and/or interrupts are converted into catchable @@ -82,14 +82,14 @@ static void discard_pending_return(typval_T *p) /* * When several errors appear in a row, setting "force_abort" is delayed until - * the failing command returned. "cause_abort" is set to TRUE meanwhile, in + * the failing command returned. "cause_abort" is set to true meanwhile, in * order to indicate that situation. This is useful when "force_abort" was set * during execution of a function call from an expression: the aborting of the * expression evaluation is done without producing any error messages, but all * error messages on parsing errors during the expression evaluation are given * (even if a try conditional is active). */ -static int cause_abort = FALSE; +static int cause_abort = false; /// @return true when immediately aborting on error, or when an interrupt /// occurred or an exception was thrown but not caught. @@ -114,11 +114,11 @@ int aborting(void) void update_force_abort(void) { if (cause_abort) { - force_abort = TRUE; + force_abort = true; } } -/// @return TRUE if a command with a subcommand resulting in "retcode" should +/// @return true if a command with a subcommand resulting in "retcode" should /// abort the script processing. Can be used to suppress an autocommand after /// execution of a failing subcommand as long as the error message has not been /// displayed and actually caused the abortion. @@ -127,7 +127,7 @@ int should_abort(int retcode) return (retcode == FAIL && trylevel != 0 && !emsg_silent) || aborting(); } -/// @return TRUE if a function with the "abort" flag should not be considered +/// @return true if a function with the "abort" flag should not be considered /// ended on an error. This means that parsing commands is continued in order /// to find finally clauses to be executed, and that some errors in skipped /// commands are still reported. @@ -175,7 +175,7 @@ bool cause_errthrow(const char *mesg, bool severe, bool *ignore) */ if (!did_emsg) { cause_abort = force_abort; - force_abort = FALSE; + force_abort = false; } /* @@ -206,7 +206,7 @@ bool cause_errthrow(const char *mesg, bool severe, bool *ignore) * Ensure that all commands in nested function calls and sourced files * are aborted immediately. */ - cause_abort = TRUE; + cause_abort = true; /* * When an exception is being thrown, some commands (like conditionals) are @@ -318,8 +318,8 @@ void do_errthrow(cstack_T *cstack, char *cmdname) * are aborted immediately. */ if (cause_abort) { - cause_abort = FALSE; - force_abort = TRUE; + cause_abort = false; + force_abort = true; } // If no exception is to be thrown or the conversion should be done after @@ -334,7 +334,7 @@ void do_errthrow(cstack_T *cstack, char *cmdname) if (cstack != NULL) { do_throw(cstack); } else { - need_rethrow = TRUE; + need_rethrow = true; } } *msg_list = NULL; @@ -343,8 +343,8 @@ void do_errthrow(cstack_T *cstack, char *cmdname) /// do_intthrow(): Replace the current exception by an interrupt or interrupt /// exception if appropriate. /// -/// @return TRUE if the current exception is discarded or, -/// FALSE otherwise. +/// @return true if the current exception is discarded or, +/// false otherwise. int do_intthrow(cstack_T *cstack) { // If no interrupt occurred or no try conditional is active and no exception @@ -501,13 +501,13 @@ static int throw_exception(void *value, except_type_T type, char *cmdname) int save_msg_silent = msg_silent; if (debug_break_level > 0) { - msg_silent = FALSE; // display messages + msg_silent = false; // display messages } else { verbose_enter(); } no_wait_return++; if (debug_break_level > 0 || *p_vfile == NUL) { - msg_scroll = TRUE; // always scroll up, don't overwrite + msg_scroll = true; // always scroll up, don't overwrite } smsg(_("Exception thrown: %s"), excp->value); msg_puts("\n"); // don't overwrite this either @@ -554,13 +554,13 @@ static void discard_exception(except_T *excp, bool was_finished) saved_IObuff = (char *)vim_strsave(IObuff); if (debug_break_level > 0) { - msg_silent = FALSE; // display messages + msg_silent = false; // display messages } else { verbose_enter(); } no_wait_return++; if (debug_break_level > 0 || *p_vfile == NUL) { - msg_scroll = TRUE; // always scroll up, don't overwrite + msg_scroll = true; // always scroll up, don't overwrite } smsg(was_finished ? _("Exception finished: %s") : _("Exception discarded: %s"), @@ -622,13 +622,13 @@ static void catch_exception(except_T *excp) int save_msg_silent = msg_silent; if (debug_break_level > 0) { - msg_silent = FALSE; // display messages + msg_silent = false; // display messages } else { verbose_enter(); } no_wait_return++; if (debug_break_level > 0 || *p_vfile == NUL) { - msg_scroll = TRUE; // always scroll up, don't overwrite + msg_scroll = true; // always scroll up, don't overwrite } smsg(_("Exception caught: %s"), excp->value); msg_puts("\n"); // don't overwrite this either @@ -746,7 +746,7 @@ static void report_pending(int action, int pending, void *value) save_msg_silent = msg_silent; if (debug_break_level > 0) { - msg_silent = FALSE; // display messages + msg_silent = false; // display messages } no_wait_return++; msg_scroll = true; // always scroll up, don't overwrite @@ -987,7 +987,7 @@ void ex_while(exarg_T *eap) // Jumping here from a ":continue" or ":endfor": use the // previously evaluated list. fi = cstack->cs_forinfo[cstack->cs_idx]; - error = FALSE; + error = false; } else { // Evaluate the argument and get the info in a structure. fi = eval_for_line(eap->arg, &error, &eap->nextcmd, skip); @@ -998,7 +998,7 @@ void ex_while(exarg_T *eap) if (!error && fi != NULL && !skip) { result = next_for_item(fi, eap->arg); } else { - result = FALSE; + result = false; } if (!result) { @@ -1131,7 +1131,7 @@ void ex_endwhile(exarg_T *eap) } } // Cleanup and rewind all contained (and unclosed) conditionals. - (void)cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE); + (void)cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, false); rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel); } else if (cstack->cs_flags[cstack->cs_idx] & CSF_TRUE && !(cstack->cs_flags[cstack->cs_idx] & CSF_ACTIVE) @@ -1186,7 +1186,7 @@ void ex_throw(exarg_T *eap) void do_throw(cstack_T *cstack) { int idx; - int inactivate_try = FALSE; + int inactivate_try = false; // // Cleanup and deactivate up to the next surrounding try conditional that @@ -1199,14 +1199,14 @@ void do_throw(cstack_T *cstack) // #ifndef THROW_ON_ERROR_TRUE if (did_emsg && !THROW_ON_ERROR) { - inactivate_try = TRUE; - did_emsg = FALSE; + inactivate_try = true; + did_emsg = false; } #endif #ifndef THROW_ON_INTERRUPT_TRUE if (got_int && !THROW_ON_INTERRUPT) { - inactivate_try = TRUE; - got_int = FALSE; + inactivate_try = true; + got_int = false; } #endif idx = cleanup_conditionals(cstack, 0, inactivate_try); @@ -1376,7 +1376,7 @@ void ex_catch(exarg_T *eap) *end = NUL; } save_cpo = p_cpo; - p_cpo = (char *)empty_option; + p_cpo = empty_option; // Disable error messages, it will make current exception // invalid emsg_off++; @@ -1434,7 +1434,7 @@ void ex_catch(exarg_T *eap) * a ":continue", ":break", ":return", or ":finish", discard the * pending action. */ - cleanup_conditionals(cstack, CSF_TRY, TRUE); + cleanup_conditionals(cstack, CSF_TRY, true); } } @@ -1447,7 +1447,7 @@ void ex_catch(exarg_T *eap) void ex_finally(exarg_T *eap) { int idx; - int skip = FALSE; + int skip = false; int pending = CSTP_NONE; cstack_T *const cstack = eap->cstack; @@ -1507,7 +1507,7 @@ void ex_finally(exarg_T *eap) * ":continue", ":break", ":finish", or ":return" from the preceding * try block or catch clause. */ - cleanup_conditionals(cstack, CSF_TRY, FALSE); + cleanup_conditionals(cstack, CSF_TRY, false); /* * Make did_emsg, got_int, current_exception pending. If set, they @@ -1683,7 +1683,7 @@ void ex_endtry(exarg_T *eap) * after errors except when this ":endtry" is not within a ":try". * Restore "emsg_silent" if it has been reset by this try conditional. */ - (void)cleanup_conditionals(cstack, CSF_TRY | CSF_SILENT, TRUE); + (void)cleanup_conditionals(cstack, CSF_TRY | CSF_SILENT, true); if (cstack->cs_idx >= 0 && (cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { cstack->cs_idx--; @@ -1712,10 +1712,10 @@ void ex_endtry(exarg_T *eap) ex_break(eap); break; case CSTP_RETURN: - do_return(eap, FALSE, FALSE, rettv); + do_return(eap, false, false, rettv); break; case CSTP_FINISH: - do_finish(eap, FALSE); + do_finish(eap, false); break; // When the finally clause was entered due to an error, @@ -1792,7 +1792,7 @@ void enter_cleanup(cleanup_T *csp) csp->exception = NULL; if (did_emsg) { force_abort |= cause_abort; - cause_abort = FALSE; + cause_abort = false; } } did_emsg = got_int = need_rethrow = false; @@ -1863,7 +1863,7 @@ void leave_cleanup(cleanup_T *csp) // enter_cleanup() was called, let "cause_abort" take the part of // "force_abort" (as done by cause_errthrow()). cause_abort = force_abort; - force_abort = FALSE; + force_abort = false; } // Restore the pending values of did_emsg, got_int, and current_exception. @@ -1895,7 +1895,7 @@ void leave_cleanup(cleanup_T *csp) /// inactive itself (a try conditional not in its finally /// clause possibly find before is always made inactive). /// -/// If "inclusive" is TRUE and "searched_cond" is CSF_TRY|CSF_SILENT, the saved +/// If "inclusive" is true and "searched_cond" is CSF_TRY|CSF_SILENT, the saved /// former value of "emsg_silent", if reset when the try conditional finally /// reached was entered, is restored (used by ex_endtry()). This is normally /// done only when such a try conditional is left. @@ -1904,7 +1904,7 @@ void leave_cleanup(cleanup_T *csp) int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive) { int idx; - int stop = FALSE; + int stop = false; for (idx = cstack->cs_idx; idx >= 0; idx--) { if (cstack->cs_flags[idx] & CSF_TRY) { @@ -1968,20 +1968,20 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive) if (searched_cond == 0 && !inclusive) { break; } - stop = TRUE; + stop = true; } } } // Stop on the searched conditional type (even when the surrounding // conditional is not active or something has been made pending). - // If "inclusive" is TRUE and "searched_cond" is CSF_TRY|CSF_SILENT, + // If "inclusive" is true and "searched_cond" is CSF_TRY|CSF_SILENT, // check first whether "emsg_silent" needs to be restored. if (cstack->cs_flags[idx] & searched_cond) { if (!inclusive) { break; } - stop = TRUE; + stop = true; } cstack->cs_flags[idx] &= ~CSF_ACTIVE; if (stop && searched_cond != (CSF_TRY | CSF_SILENT)) { @@ -2046,7 +2046,7 @@ void ex_endfunction(exarg_T *eap) emsg(_("E193: :endfunction not inside a function")); } -/// @return TRUE if the string "p" looks like a ":while" or ":for" command. +/// @return true if the string "p" looks like a ":while" or ":for" command. int has_loop_cmd(char *p) { int len; @@ -2064,7 +2064,7 @@ int has_loop_cmd(char *p) } if ((p[0] == 'w' && p[1] == 'h') || (p[0] == 'f' && p[1] == 'o' && p[2] == 'r')) { - return TRUE; + return true; } - return FALSE; + return false; } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index ce4930d33e..26ed318c10 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -105,8 +105,8 @@ typedef struct command_line_state { long count; int indent; int c; - int gotesc; // TRUE when <ESC> just typed - int do_abbr; // when TRUE check for abbr. + int gotesc; // true when <ESC> just typed + int do_abbr; // when true check for abbr. char_u *lookfor; // string to match int hiscnt; // current history line in use int save_hiscnt; // history line before attempting @@ -170,6 +170,8 @@ static Array cmdline_block = ARRAY_DICT_INIT; /// user interrupting highlight function to not interrupt command-line. static bool getln_interrupted_highlight = false; +static int cedit_key = -1; ///< key value of 'cedit' option + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ex_getln.c.generated.h" #endif @@ -2532,6 +2534,59 @@ char_u *get_cmdprompt(void) return ccline.cmdprompt; } +/// Read the 'wildmode' option, fill wim_flags[]. +int check_opt_wim(void) +{ + char_u new_wim_flags[4]; + char_u *p; + int i; + int idx = 0; + + for (i = 0; i < 4; i++) { + new_wim_flags[i] = 0; + } + + for (p = p_wim; *p; p++) { + for (i = 0; ASCII_ISALPHA(p[i]); i++) {} + if (p[i] != NUL && p[i] != ',' && p[i] != ':') { + return FAIL; + } + if (i == 7 && STRNCMP(p, "longest", 7) == 0) { + new_wim_flags[idx] |= WIM_LONGEST; + } else if (i == 4 && STRNCMP(p, "full", 4) == 0) { + new_wim_flags[idx] |= WIM_FULL; + } else if (i == 4 && STRNCMP(p, "list", 4) == 0) { + new_wim_flags[idx] |= WIM_LIST; + } else if (i == 8 && STRNCMP(p, "lastused", 8) == 0) { + new_wim_flags[idx] |= WIM_BUFLASTUSED; + } else { + return FAIL; + } + p += i; + if (*p == NUL) { + break; + } + if (*p == ',') { + if (idx == 3) { + return FAIL; + } + idx++; + } + } + + // fill remaining entries with last flag + while (idx < 3) { + new_wim_flags[idx + 1] = new_wim_flags[idx]; + idx++; + } + + // only when there are no errors, wim_flags[] is changed + for (i = 0; i < 4; i++) { + wim_flags[i] = new_wim_flags[i]; + } + return OK; +} + /// Return true when the text must not be changed and we can't switch to /// another window or buffer. True when editing the command line etc. bool text_locked(void) @@ -3029,7 +3084,7 @@ color_cmdline_error: /* * Draw part of the cmdline at the current cursor position. But draw stars - * when cmdline_star is TRUE. + * when cmdline_star is true. */ static void draw_cmdline(int start, int len) { @@ -3283,7 +3338,7 @@ void cmdline_ui_flush(void) /* * Put a character on the command line. Shifts the following text to the - * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. + * right when "shift" is true. Used for CTRL-V, CTRL-K, etc. * "c" must be printable (fit in one display cell)! */ void putcmdline(char c, int shift) @@ -3309,7 +3364,7 @@ void putcmdline(char c, int shift) ui_cursor_shape(); } -/// Undo a putcmdline(c, FALSE). +/// Undo a putcmdline(c, false). void unputcmdline(void) { if (cmd_silent) { @@ -3330,9 +3385,9 @@ void unputcmdline(void) /* * Put the given string, of the given length, onto the command line. * If len is -1, then STRLEN() is used to calculate the length. - * If 'redraw' is TRUE then the new part of the command line, and the remaining + * If 'redraw' is true then the new part of the command line, and the remaining * part will be redrawn, otherwise it will not. If this function is called - * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be + * twice in a row, then 'redraw' should be false and redrawcmd() should be * called afterwards. */ void put_on_cmdline(char_u *str, int len, int redraw) @@ -3409,7 +3464,7 @@ void put_on_cmdline(char_u *str, int len, int redraw) } if (redraw && !cmd_silent) { - msg_no_more = TRUE; + msg_no_more = true; i = cmdline_row; cursorcmd(); draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); @@ -3417,7 +3472,7 @@ void put_on_cmdline(char_u *str, int len, int redraw) if (cmdline_row != i || ccline.overstrike) { msg_clr_eos(); } - msg_no_more = FALSE; + msg_no_more = false; } if (KeyTyped) { m = Columns * Rows; @@ -3544,8 +3599,8 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) /* * Put a string on the command line. - * When "literally" is TRUE, insert literally. - * When "literally" is FALSE, insert as typed, but don't leave the command + * When "literally" is true, insert literally. + * When "literally" is false, insert as typed, but don't leave the command * line. */ void cmdline_paste_str(char_u *s, int literally) @@ -3553,7 +3608,7 @@ void cmdline_paste_str(char_u *s, int literally) int c, cv; if (literally) { - put_on_cmdline(s, -1, TRUE); + put_on_cmdline(s, -1, true); } else { while (*s != NUL) { cv = *s; @@ -3642,7 +3697,7 @@ void redrawcmd(void) redrawcmdprompt(); // Don't use more prompt, truncate the cmdline if it doesn't fit. - msg_no_more = TRUE; + msg_no_more = true; draw_cmdline(0, ccline.cmdlen); msg_clr_eos(); msg_no_more = false; @@ -3657,7 +3712,7 @@ void redrawcmd(void) * An emsg() before may have set msg_scroll. This is used in normal mode, * in cmdline mode we can reset them now. */ - msg_scroll = FALSE; // next message overwrites cmdline + msg_scroll = false; // next message overwrites cmdline // Typing ':' at the more prompt may set skip_redraw. We don't want this // in cmdline mode. @@ -4026,6 +4081,24 @@ void cmdline_init(void) CLEAR_FIELD(ccline); } +/// Check value of 'cedit' and set cedit_key. +/// Returns NULL if value is OK, error message otherwise. +char *check_cedit(void) +{ + int n; + + if (*p_cedit == NUL) { + cedit_key = -1; + } else { + n = string_to_key(p_cedit); + if (vim_isprintc(n)) { + return e_invarg; + } + cedit_key = n; + } + return NULL; +} + /// Open a window on the current command line and history. Allow editing in /// the window. Returns when the window is closed. /// Returns: diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index 9495ae1c4b..453de89aea 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -359,7 +359,7 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr // Then ":help" will re-use both the buffer and the window and set // the options, even when "options" is not in 'sessionoptions'. if (0 < wp->w_tagstackidx && wp->w_tagstackidx <= wp->w_tagstacklen) { - curtag = (char *)wp->w_tagstack[wp->w_tagstackidx - 1].tagname; + curtag = wp->w_tagstack[wp->w_tagstackidx - 1].tagname; } if (put_line(fd, "enew | setl bt=help") == FAIL diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 53f87d0e42..273fe12d31 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -110,16 +110,15 @@ typedef struct ff_stack { typedef struct ff_visited { struct ff_visited *ffv_next; - /* Visited directories are different if the wildcard string are - * different. So we have to save it. - */ + // Visited directories are different if the wildcard string are + // different. So we have to save it. char_u *ffv_wc_path; + // use FileID for comparison (needed because of links), else use filename. bool file_id_valid; FileID file_id; - /* The memory for this struct is allocated according to the length of - * ffv_fname. - */ + // The memory for this struct is allocated according to the length of + // ffv_fname. char_u ffv_fname[1]; // actually longer } ff_visited_T; @@ -221,8 +220,8 @@ static char_u e_pathtoolong[] = N_("E854: path too long for completion"); /// /// Upward search is only done on the starting dir. /// -/// If 'free_visited' is TRUE the list of already visited files/directories is -/// cleared. Set this to FALSE if you just want to search from another +/// If 'free_visited' is true the list of already visited files/directories is +/// cleared. Set this to false if you just want to search from another /// directory, but want to be sure that no directory from a previous search is /// searched again. This is useful if you search for a file at different places. /// The list of visited files/dirs can also be cleared with the function @@ -269,7 +268,7 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le ff_clear(search_ctx); // clear visited list if wanted - if (free_visited == TRUE) { + if (free_visited == true) { vim_findfile_free_visited(search_ctx); } else { /* Reuse old visited lists. Get the visited list for the given @@ -302,7 +301,7 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le if (!vim_isAbsName(rel_fname) && len + 1 < MAXPATHL) { // Make the start dir an absolute path name. STRLCPY(ff_expand_buffer, rel_fname, len + 1); - search_ctx->ffsc_start_dir = (char_u *)FullName_save((char *)ff_expand_buffer, FALSE); + search_ctx->ffsc_start_dir = (char_u *)FullName_save((char *)ff_expand_buffer, false); } else { search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len); } @@ -510,9 +509,7 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le xfree(buf); } - sptr = ff_create_stack_element(ff_expand_buffer, - search_ctx->ffsc_wc_path, - level, 0); + sptr = ff_create_stack_element(ff_expand_buffer, search_ctx->ffsc_wc_path, level, 0); ff_push(search_ctx, sptr); search_ctx->ffsc_file_to_search = vim_strsave(filename); @@ -641,11 +638,8 @@ char_u *vim_findfile(void *search_ctx_arg) * first time (hence stackp->ff_filearray == NULL) */ if (stackp->ffs_filearray == NULL - && ff_check_visited(&search_ctx->ffsc_dir_visited_list - ->ffvl_visited_list, - stackp->ffs_fix_path, - stackp->ffs_wc_path - ) == FAIL) { + && ff_check_visited(&search_ctx->ffsc_dir_visited_list->ffvl_visited_list, + stackp->ffs_fix_path, stackp->ffs_wc_path) == FAIL) { #ifdef FF_VERBOSE if (p_verbose >= 5) { verbose_enter_scroll(); @@ -790,8 +784,7 @@ char_u *vim_findfile(void *search_ctx_arg) stackp->ffs_filearray_cur = 0; stackp->ffs_stage = 0; } else { - rest_of_wildcards = &stackp->ffs_wc_path[ - STRLEN(stackp->ffs_wc_path)]; + rest_of_wildcards = &stackp->ffs_wc_path[STRLEN(stackp->ffs_wc_path)]; } if (stackp->ffs_stage == 0) { @@ -827,29 +820,23 @@ char_u *vim_findfile(void *search_ctx_arg) if (search_ctx->ffsc_tagfile) { suf = ""; } else { - suf = (char *)curbuf->b_p_sua; + suf = curbuf->b_p_sua; } for (;;) { // if file exists and we didn't already find it if ((path_with_url((char *)file_path) || (os_path_exists(file_path) - && (search_ctx->ffsc_find_what - == FINDFILE_BOTH - || ((search_ctx->ffsc_find_what - == FINDFILE_DIR) + && (search_ctx->ffsc_find_what == FINDFILE_BOTH + || ((search_ctx->ffsc_find_what == FINDFILE_DIR) == os_isdir(file_path))))) #ifndef FF_VERBOSE && (ff_check_visited(&search_ctx->ffsc_visited_list->ffvl_visited_list, - file_path, - (char_u *)"" - ) == OK) + file_path, (char_u *)"") == OK) #endif ) { #ifdef FF_VERBOSE if (ff_check_visited(&search_ctx->ffsc_visited_list->ffvl_visited_list, - file_path, - (char_u *)"" - ) == FAIL) { + file_path, (char_u *)"") == FAIL) { if (p_verbose >= 5) { verbose_enter_scroll(); smsg("Already: %s", file_path); @@ -945,7 +932,7 @@ char_u *vim_findfile(void *search_ctx_arg) // is the last starting directory in the stop list? if (ff_path_in_stoplist(search_ctx->ffsc_start_dir, (int)(path_end - search_ctx->ffsc_start_dir), - search_ctx->ffsc_stopdirs_v) == TRUE) { + search_ctx->ffsc_stopdirs_v) == true) { break; } @@ -1289,7 +1276,7 @@ static void ff_clear(ff_search_ctx_T *search_ctx) /// check if the given path is in the stopdirs /// -/// @return TRUE if yes else FALSE +/// @return true if yes else false static int ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v) { int i = 0; @@ -1301,7 +1288,7 @@ static int ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v) // if no path consider it as match if (path_len == 0) { - return TRUE; + return true; } for (i = 0; stopdirs_v[i] != NULL; i++) { @@ -1312,7 +1299,7 @@ static int ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v) */ if (FNAMENCMP(stopdirs_v[i], path, path_len) == 0 && vim_ispathsep(stopdirs_v[i][path_len])) { - return TRUE; + return true; } } else { if (FNAMECMP(stopdirs_v[i], path) == 0) { @@ -1320,13 +1307,13 @@ static int ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v) } } } - return FALSE; + return false; } /// Find the file name "ptr[len]" in the path. Also finds directory names. /// -/// On the first call set the parameter 'first' to TRUE to initialize -/// the search. For repeating calls to FALSE. +/// On the first call set the parameter 'first' to true to initialize +/// the search. For repeating calls to false. /// /// Repeating calls will return other files called 'ptr[len]' from the path. /// @@ -1355,8 +1342,8 @@ char_u *find_file_in_path(char_u *ptr, size_t len, int options, int first, char_ return find_file_in_path_option(ptr, len, options, first, (*curbuf->b_p_path == NUL ? p_path - : curbuf->b_p_path), - FINDFILE_BOTH, rel_fname, curbuf->b_p_sua); + : (char_u *)curbuf->b_p_path), + FINDFILE_BOTH, rel_fname, (char_u *)curbuf->b_p_sua); } static char_u *ff_file_to_find = NULL; @@ -1387,7 +1374,7 @@ void free_findfile(void) /// @return an allocated string for the file name. NULL for error. char_u *find_directory_in_path(char_u *ptr, size_t len, int options, char_u *rel_fname) { - return find_file_in_path_option(ptr, len, options, TRUE, p_cdpath, + return find_file_in_path_option(ptr, len, options, true, p_cdpath, FINDFILE_DIR, rel_fname, (char_u *)""); } @@ -1458,7 +1445,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first * If this is not a first call, return NULL. We already returned a * filename on the first call. */ - if (first == TRUE) { + if (first == true) { if (path_with_url((char *)ff_file_to_find)) { file_name = vim_strsave(ff_file_to_find); goto theend; @@ -1507,7 +1494,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first * When "first" is set, first setup to the start of the option. * Otherwise continue to find the next match. */ - if (first == TRUE) { + if (first == true) { // vim_findfile_free_visited can handle a possible NULL pointer vim_findfile_free_visited(fdip_search_ctx); dir = (char *)path_option; @@ -1521,7 +1508,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first break; } - did_findfile_init = FALSE; + did_findfile_init = false; } else { char_u *r_ptr; @@ -1545,14 +1532,14 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first r_ptr, 100, false, find_what, fdip_search_ctx, false, rel_fname); if (fdip_search_ctx != NULL) { - did_findfile_init = TRUE; + did_findfile_init = true; } xfree(buf); } } } if (file_name == NULL && (options & FNAME_MESS)) { - if (first == TRUE) { + if (first == true) { if (find_what == FINDFILE_DIR) { semsg(_("E344: Can't find directory \"%s\" in cdpath"), ff_file_to_find); diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 39bf1b3670..206ef7c98d 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -134,7 +134,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr) // calling filemess(). msg_scroll_save = msg_scroll; if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) { - msg_scroll = FALSE; + msg_scroll = false; } if (!msg_scroll) { // wait a bit when overwriting an error msg check_for_delay(false); @@ -143,7 +143,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr) msg_scroll = msg_scroll_save; msg_scrolled_ign = true; // may truncate the message to avoid a hit-return prompt - msg_outtrans_attr(msg_may_trunc(FALSE, IObuff), attr); + msg_outtrans_attr(msg_may_trunc(false, IObuff), attr); msg_clr_eos(); ui_flush(); msg_scrolled_ign = false; @@ -337,9 +337,9 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, } if ((shortmess(SHM_OVER) || curbuf->b_help) && p_verbose == 0) { - msg_scroll = FALSE; // overwrite previous file message + msg_scroll = false; // overwrite previous file message } else { - msg_scroll = TRUE; // don't overwrite previous file message + msg_scroll = true; // don't overwrite previous file message } // If the name is too long we might crash further on, quit here. if (fname != NULL && *fname != NUL) { @@ -402,7 +402,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, */ check_readonly = (newfile && (curbuf->b_flags & BF_CHECK_RO)); if (check_readonly && !readonlymode) { - curbuf->b_p_ro = FALSE; + curbuf->b_p_ro = false; } if (newfile && !read_stdin && !read_buffer && !read_fifo) { @@ -518,18 +518,18 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, * loaded. Help files always get readonly mode */ if ((check_readonly && file_readonly) || curbuf->b_help) { - curbuf->b_p_ro = TRUE; + curbuf->b_p_ro = true; } if (set_options) { // Don't change 'eol' if reading from buffer as it will already be // correctly set when reading stdin. if (!read_buffer) { - curbuf->b_p_eol = TRUE; - curbuf->b_start_eol = TRUE; + curbuf->b_p_eol = true; + curbuf->b_start_eol = true; } - curbuf->b_p_bomb = FALSE; - curbuf->b_start_bomb = FALSE; + curbuf->b_p_bomb = false; + curbuf->b_start_bomb = false; } // Create a swap file now, so that other Vims are warned that we are @@ -635,7 +635,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, if (aborting()) { // autocmds may abort script processing no_wait_return--; msg_scroll = msg_save; - curbuf->b_p_ro = TRUE; // must use "w!" now + curbuf->b_p_ro = true; // must use "w!" now return FAIL; } /* @@ -656,7 +656,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, } else { emsg(_("E201: *ReadPre autocommands must not change current buffer")); } - curbuf->b_p_ro = TRUE; // must use "w!" now + curbuf->b_p_ro = true; // must use "w!" now return FAIL; } } @@ -670,7 +670,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, } } - msg_scroll = FALSE; // overwrite the file message + msg_scroll = false; // overwrite the file message /* * Set linecnt now, before the "retry" caused by a wrong guess for @@ -708,7 +708,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, fenc_alloced = false; } else if (*p_fencs == NUL) { - fenc = (char *)curbuf->b_p_fenc; // use format from buffer + fenc = curbuf->b_p_fenc; // use format from buffer fenc_alloced = false; } else { fenc_next = (char *)p_fencs; // try items in 'fileencodings' @@ -751,8 +751,8 @@ retry: } file_rewind = false; if (set_options) { - curbuf->b_p_bomb = FALSE; - curbuf->b_start_bomb = FALSE; + curbuf->b_p_bomb = false; + curbuf->b_start_bomb = false; } conv_error = 0; } @@ -766,7 +766,7 @@ retry: } else { if (eap != NULL && eap->force_ff != 0) { fileformat = get_fileformat_force(curbuf, eap); - try_unix = try_dos = try_mac = FALSE; + try_unix = try_dos = try_mac = false; } else if (curbuf->b_p_bin) { fileformat = EOL_UNIX; // binary: use Unix format } else if (*p_ffs == @@ -892,7 +892,7 @@ retry: } // Set "can_retry" when it's possible to rewind the file and try with - // another "fenc" value. It's FALSE when no other "fenc" to try, reading + // another "fenc" value. It's false when no other "fenc" to try, reading // stdin or fixed at a specific encoding. can_retry = (*fenc != NUL && !read_stdin && !keep_dest_enc && !read_fifo); @@ -1138,8 +1138,8 @@ retry: size -= blen; memmove(ptr, ptr + blen, (size_t)size); if (set_options) { - curbuf->b_p_bomb = TRUE; - curbuf->b_start_bomb = TRUE; + curbuf->b_p_bomb = true; + curbuf->b_start_bomb = true; } } @@ -1672,7 +1672,7 @@ failed: && ptr == line_start + 1)) { // remember for when writing if (set_options) { - curbuf->b_p_eol = FALSE; + curbuf->b_p_eol = false; } *ptr = NUL; len = (colnr_T)(ptr - line_start + 1); @@ -1773,7 +1773,7 @@ failed: if (!(flags & READ_DUMMY)) { filemess(curbuf, (char_u *)sfname, (char_u *)_(e_interr), 0); if (newfile) { - curbuf->b_p_ro = TRUE; // must use "w!" now + curbuf->b_p_ro = true; // must use "w!" now } } msg_scroll = msg_save; @@ -1788,30 +1788,30 @@ failed: #ifdef UNIX if (S_ISFIFO(perm)) { // fifo STRCAT(IObuff, _("[fifo]")); - c = TRUE; + c = true; } if (S_ISSOCK(perm)) { // or socket STRCAT(IObuff, _("[socket]")); - c = TRUE; + c = true; } # ifdef OPEN_CHR_FILES if (S_ISCHR(perm)) { // or character special STRCAT(IObuff, _("[character special]")); - c = TRUE; + c = true; } # endif #endif if (curbuf->b_p_ro) { STRCAT(IObuff, shortmess(SHM_RO) ? _("[RO]") : _("[readonly]")); - c = TRUE; + c = true; } if (read_no_eol_lnum) { msg_add_eol(); - c = TRUE; + c = true; } if (ff_error == EOL_DOS) { STRCAT(IObuff, _("[CR missing]")); - c = TRUE; + c = true; } if (split) { STRCAT(IObuff, _("[long lines split]")); @@ -1819,25 +1819,25 @@ failed: } if (notconverted) { STRCAT(IObuff, _("[NOT converted]")); - c = TRUE; + c = true; } else if (converted) { STRCAT(IObuff, _("[converted]")); - c = TRUE; + c = true; } if (conv_error != 0) { sprintf((char *)IObuff + STRLEN(IObuff), _("[CONVERSION ERROR in line %" PRId64 "]"), (int64_t)conv_error); - c = TRUE; + c = true; } else if (illegal_byte > 0) { sprintf((char *)IObuff + STRLEN(IObuff), _("[ILLEGAL BYTE in line %" PRId64 "]"), (int64_t)illegal_byte); - c = TRUE; + c = true; } else if (error) { STRCAT(IObuff, _("[READ ERRORS]")); - c = TRUE; + c = true; } if (msg_add_fileformat(fileformat)) { - c = TRUE; + c = true; } msg_add_lines(c, (long)linecnt, filesize); @@ -1865,9 +1865,8 @@ failed: // with errors writing the file requires ":w!" if (newfile && (error || conv_error != 0 - || (illegal_byte > 0 && bad_char_behavior != BAD_KEEP) - )) { - curbuf->b_p_ro = TRUE; + || (illegal_byte > 0 && bad_char_behavior != BAD_KEEP))) { + curbuf->b_p_ro = true; } u_clearline(); // cannot use "U" command after adding lines @@ -1948,7 +1947,7 @@ failed: if (!au_did_filetype && *curbuf->b_p_ft != NUL) { // EVENT_FILETYPE was not triggered but the buffer already has a // filetype. Trigger EVENT_FILETYPE using the existing filetype. - apply_autocmds(EVENT_FILETYPE, (char *)curbuf->b_p_ft, curbuf->b_fname, true, curbuf); + apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname, true, curbuf); } } else { apply_autocmds_exarg(EVENT_FILEREADPOST, sfname, sfname, @@ -2021,8 +2020,8 @@ void prep_exarg(exarg_T *eap, const buf_T *buf) eap->force_ff = *buf->b_p_ff; eap->force_bin = buf->b_p_bin ? FORCE_BIN : FORCE_NOBIN; - eap->read_edit = FALSE; - eap->forceit = FALSE; + eap->read_edit = false; + eap->forceit = false; } /// Set default or forced 'fileformat' and 'binary'. @@ -2161,9 +2160,9 @@ char *new_file_message(void) /// /// If "forceit" is true, we don't care for errors when attempting backups. /// In case of an error everything possible is done to restore the original -/// file. But when "forceit" is TRUE, we risk losing it. +/// file. But when "forceit" is true, we risk losing it. /// -/// When "reset_changed" is TRUE and "append" == FALSE and "start" == 1 and +/// When "reset_changed" is true and "append" == false and "start" == 1 and /// "end" == curbuf->b_ml.ml_line_count, reset curbuf->b_changed. /// /// This function must NOT use NameBuff (because it's called by autowrite()). @@ -2204,9 +2203,9 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en int bufsize; long perm; // file permissions int retval = OK; - int newfile = false; // TRUE if file doesn't exist yet + int newfile = false; // true if file doesn't exist yet int msg_save = msg_scroll; - int overwriting; // TRUE if writing over original + int overwriting; // true if writing over original int no_eol = false; // no end-of-line written int device = false; // writing to a device int prev_got_int = got_int; @@ -2215,7 +2214,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en static char *err_readonly = "is read-only (cannot override: \"W\" in 'cpoptions')"; #if defined(UNIX) - int made_writable = FALSE; // 'w' bit has been set + int made_writable = false; // 'w' bit has been set #endif // writing everything int whole = (start == 1 && end == buf->b_ml.ml_line_count); @@ -2234,7 +2233,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en vim_acl_T acl = NULL; /* ACL copied from original file to backup or new file */ #endif - int write_undo_file = FALSE; + int write_undo_file = false; context_sha256_T sha_ctx; unsigned int bkc = get_bkc_value(buf); const pos_T orig_start = buf->b_op_start; @@ -2266,7 +2265,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en // must init bw_conv_buf and bw_iconv_fd before jumping to "fail" write_info.bw_conv_buf = NULL; - write_info.bw_conv_error = FALSE; + write_info.bw_conv_error = false; write_info.bw_conv_error_lnum = 0; write_info.bw_restlen = 0; #ifdef HAVE_ICONV @@ -2314,7 +2313,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en if (buf->b_ffname != NULL && FNAMECMP(ffname, buf->b_ffname) == 0) { overwriting = true; } else { - overwriting = FALSE; + overwriting = false; } no_wait_return++; // don't wait for return yet @@ -2329,12 +2328,12 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en { aco_save_T aco; - int buf_ffname = FALSE; - int buf_sfname = FALSE; - int buf_fname_f = FALSE; - int buf_fname_s = FALSE; - int did_cmd = FALSE; - int nofile_err = FALSE; + int buf_ffname = false; + int buf_sfname = false; + int buf_fname_f = false; + int buf_fname_s = false; + int did_cmd = false; + int nofile_err = false; int empty_memline = (buf->b_ml.ml_mfp == NULL); bufref_T bufref; @@ -2512,9 +2511,9 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en } if (shortmess(SHM_OVER) && !exiting) { - msg_scroll = FALSE; // overwrite previous file message + msg_scroll = false; // overwrite previous file message } else { - msg_scroll = TRUE; // don't overwrite previous file message + msg_scroll = true; // don't overwrite previous file message } if (!filtering) { filemess(buf, @@ -2525,7 +2524,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en #endif (char_u *)"", 0); // show that we are busy } - msg_scroll = FALSE; // always overwrite the file message now + msg_scroll = false; // always overwrite the file message now buffer = verbose_try_malloc(BUFSIZE); // can't allocate big buffer, use small one (to be able to write when out of @@ -2558,8 +2557,8 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en } /* It's a device of some kind (or a fifo) which we can write to * but for which we can't make a backup. */ - device = TRUE; - newfile = TRUE; + device = true; + newfile = true; perm = -1; } } @@ -2571,8 +2570,8 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en goto fail; } if (c == NODE_WRITABLE) { - device = TRUE; - newfile = TRUE; + device = true; + newfile = true; perm = -1; } else { perm = os_getperm((const char *)fname); @@ -2638,7 +2637,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en * abort it. */ prev_got_int = got_int; - got_int = FALSE; + got_int = false; // Mark the buffer as 'being saved' to prevent changed buffer warnings buf->b_saving = true; @@ -2656,7 +2655,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en const bool no_prepend_dot = false; if ((bkc & BKC_YES) || append) { // "yes" - backup_copy = TRUE; + backup_copy = true; } else if ((bkc & BKC_AUTO)) { // "auto" int i; @@ -2669,7 +2668,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en if (os_fileinfo_hardlinks(&file_info_old) > 1 || !os_fileinfo_link(fname, &file_info) || !os_fileinfo_id_equal(&file_info, &file_info_old)) { - backup_copy = TRUE; + backup_copy = true; } else { /* * Check if we can create a file and set the owner/group to @@ -2689,7 +2688,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en fd = os_open((char *)IObuff, O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, (int)perm); if (fd < 0) { // can't write in directory - backup_copy = TRUE; + backup_copy = true; } else { #ifdef UNIX os_fchown(fd, (uv_uid_t)file_info_old.stat.st_uid, (uv_gid_t)file_info_old.stat.st_gid); @@ -2697,7 +2696,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en || file_info.stat.st_uid != file_info_old.stat.st_uid || file_info.stat.st_gid != file_info_old.stat.st_gid || (long)file_info.stat.st_mode != perm) { - backup_copy = TRUE; + backup_copy = true; } #endif /* Close the file before removing it, on MS-Windows we @@ -2719,7 +2718,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en if ((bkc & BKC_BREAKSYMLINK) && file_info_link_ok && !os_fileinfo_id_equal(&file_info, &file_info_old)) { - backup_copy = FALSE; + backup_copy = false; } // Hardlinks. @@ -2727,7 +2726,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en && os_fileinfo_hardlinks(&file_info_old) > 1 && (!file_info_link_ok || os_fileinfo_id_equal(&file_info, &file_info_old))) { - backup_copy = FALSE; + backup_copy = false; } #endif } @@ -2789,7 +2788,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en rootname = (char *)get_file_in_dir((char_u *)fname, IObuff); if (rootname == NULL) { - some_error = TRUE; // out of memory + some_error = true; // out of memory goto nobackup; } @@ -2804,7 +2803,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en if (backup == NULL) { xfree(rootname); - some_error = TRUE; // out of memory + some_error = true; // out of memory goto nobackup; } @@ -2889,7 +2888,7 @@ nobackup: if (backup == NULL && errmsg == NULL) { SET_ERRMSG(_("E509: Cannot create backup file (add ! to override)")); } - // Ignore errors when forceit is TRUE. + // Ignore errors when forceit is true. if ((some_error || errmsg != NULL) && !forceit) { retval = FAIL; goto fail; @@ -3052,7 +3051,7 @@ nobackup: fenc = (char *)enc_canonize((char_u *)fenc); fenc_tofree = fenc; } else { - fenc = (char *)buf->b_p_fenc; + fenc = buf->b_p_fenc; } // Check if the file needs to be converted. @@ -3089,8 +3088,8 @@ nobackup: if (!write_info.bw_conv_buf) { end = 0; } - write_info.bw_first = TRUE; - } else + write_info.bw_first = true; + } else { #endif /* @@ -3106,6 +3105,11 @@ nobackup: } } } + +#ifdef HAVE_ICONV +} +#endif + if (converted && wb_flags == 0 #ifdef HAVE_ICONV && write_info.bw_iconv_fd == (iconv_t)-1 @@ -3115,7 +3119,7 @@ nobackup: SET_ERRMSG(_("E213: Cannot convert (add ! to write without conversion)")); goto restore_backup; } - notconverted = TRUE; + notconverted = true; } // If conversion is taking place, we may first pretend to write and check @@ -3137,12 +3141,12 @@ nobackup: } else { // Open the file "wfname" for writing. // We may try to open the file twice: If we can't write to the file - // and forceit is TRUE we delete the existing file and try to + // and forceit is true we delete the existing file and try to // create a new one. If this still fails we may have lost the // original file! (this may happen when the user reached his // quotum for number of files). // Appending will fail if the file does not exist and forceit is - // FALSE. + // false. while ((fd = os_open(wfname, O_WRONLY | (append ? @@ -3366,7 +3370,7 @@ restore_backup: // been written to disk and we don't lose it. // For a device do try the fsync() but don't complain if it does not work // (could be a pipe). - // If the 'fsync' option is FALSE, don't fsync(). Useful for laptops. + // If the 'fsync' option is false, don't fsync(). Useful for laptops. int error; if (p_fs && (error = os_fsync(fd)) != 0 && !device // fsync not supported on this storage. @@ -3495,32 +3499,32 @@ restore_backup: c = false; if (write_info.bw_conv_error) { STRCAT(IObuff, _(" CONVERSION ERROR")); - c = TRUE; + c = true; if (write_info.bw_conv_error_lnum != 0) { vim_snprintf_add((char *)IObuff, IOSIZE, _(" in line %" PRId64 ";"), (int64_t)write_info.bw_conv_error_lnum); } } else if (notconverted) { STRCAT(IObuff, _("[NOT converted]")); - c = TRUE; + c = true; } else if (converted) { STRCAT(IObuff, _("[converted]")); - c = TRUE; + c = true; } if (device) { STRCAT(IObuff, _("[Device]")); - c = TRUE; + c = true; } else if (newfile) { STRCAT(IObuff, new_file_message()); c = true; } if (no_eol) { msg_add_eol(); - c = TRUE; + c = true; } // may add [unix/dos/mac] if (msg_add_fileformat(fileformat)) { - c = TRUE; + c = true; } msg_add_lines(c, (long)lnum, nchars); // add line/char count if (!shortmess(SHM_WRITE)) { @@ -3711,23 +3715,23 @@ nofail: if (append) { apply_autocmds_exarg(EVENT_FILEAPPENDPOST, fname, fname, - FALSE, curbuf, eap); + false, curbuf, eap); } else if (filtering) { apply_autocmds_exarg(EVENT_FILTERWRITEPOST, NULL, fname, - FALSE, curbuf, eap); + false, curbuf, eap); } else if (reset_changed && whole) { apply_autocmds_exarg(EVENT_BUFWRITEPOST, fname, fname, - FALSE, curbuf, eap); + false, curbuf, eap); } else { apply_autocmds_exarg(EVENT_FILEWRITEPOST, fname, fname, - FALSE, curbuf, eap); + false, curbuf, eap); } // restore curwin/curbuf and a few other things aucmd_restbuf(&aco); if (aborting()) { // autocmds may abort script processing - retval = FALSE; + retval = false; } } @@ -3994,7 +3998,7 @@ static int buf_write_bytes(struct bw_info *ip) } if (ucs2bytes(c, &p, flags) && !ip->bw_conv_error) { - ip->bw_conv_error = TRUE; + ip->bw_conv_error = true; ip->bw_conv_error_lnum = ip->bw_start_lnum; } if (c == NL) { @@ -4049,7 +4053,7 @@ static int buf_write_bytes(struct bw_info *ip) to = (char *)ip->bw_conv_buf; tolen = save_len; } - ip->bw_first = FALSE; + ip->bw_first = false; } /* @@ -4058,7 +4062,7 @@ static int buf_write_bytes(struct bw_info *ip) if ((iconv(ip->bw_iconv_fd, (void *)&from, &fromlen, &to, &tolen) == (size_t)-1 && ICONV_ERRNO != ICONV_EINVAL) || fromlen > CONV_RESTLEN) { - ip->bw_conv_error = TRUE; + ip->bw_conv_error = true; return FAIL; } @@ -4163,7 +4167,7 @@ static bool need_conversion(const char_u *fenc) int fenc_flags; if (*fenc == NUL || STRCMP(p_enc, fenc) == 0) { - same_encoding = TRUE; + same_encoding = true; fenc_flags = 0; } else { // Ignore difference between "ansi" and "latin1", "ucs-4" and @@ -4296,10 +4300,10 @@ static int make_bom(char_u *buf, char_u *name) /// Shorten filename of a buffer. /// -/// @param force when TRUE: Use full path from now on for files currently being +/// @param force when true: Use full path from now on for files currently being /// edited, both for file name and swap file name. Try to shorten the file /// names a bit, if safe to do so. -/// when FALSE: Only try to shorten absolute file names. +/// when false: Only try to shorten absolute file names. /// /// For buffers that have buftype "nofile" or "scratch": never change the file /// name. @@ -4386,7 +4390,7 @@ char *modname(const char *fname, const char *ext, bool prepend_dot) } add_pathsep(retval); fnamelen = strlen(retval); - prepend_dot = FALSE; // nothing to prepend a dot to + prepend_dot = false; // nothing to prepend a dot to } else { fnamelen = strlen(fname); retval = xmalloc(fnamelen + extlen + 3); @@ -4769,7 +4773,7 @@ int vim_rename(const char_u *from, const char_u *to) return 0; } -static int already_warned = FALSE; +static int already_warned = false; /// Check if any not hidden buffer has been changed. /// Postpone the check if there are characters in the stuff buffer, a global @@ -4778,7 +4782,7 @@ static int already_warned = FALSE; /// /// @param focus called for GUI focus event /// -/// @return TRUE if some message was written (screen should be redrawn and cursor positioned). +/// @return true if some message was written (screen should be redrawn and cursor positioned). int check_timestamps(int focus) { int didit = 0; @@ -4786,15 +4790,15 @@ int check_timestamps(int focus) // Don't check timestamps while system() or another low-level function may // cause us to lose and gain focus. if (no_check_timestamps > 0) { - return FALSE; + return false; } // Avoid doing a check twice. The OK/Reload dialog can cause a focus // event and we would keep on checking if the file is steadily growing. // Do check again after typing something. if (focus && did_check_timestamps) { - need_check_timestamps = TRUE; - return FALSE; + need_check_timestamps = true; + return false; } if (!stuff_empty() || global_busy || !typebuf_typed() @@ -5075,7 +5079,7 @@ int buf_check_timestamp(buf_T *buf) redraw_cmdline = false; } } - already_warned = TRUE; + already_warned = true; } xfree(path); @@ -5606,8 +5610,8 @@ bool match_file_list(char_u *list, char_u *sfname, char_u *ffname) /// Convert the given pattern "pat" which has shell style wildcards in it, into /// a regular expression, and return the result in allocated memory. If there -/// is a directory path separator to be matched, then TRUE is put in -/// allow_dirs, otherwise FALSE is put there -- webb. +/// is a directory path separator to be matched, then true is put in +/// allow_dirs, otherwise false is put there -- webb. /// Handle backslashes before special characters, like "\*" and "\ ". /// /// @param pat_end first char after pattern or NULL @@ -5625,7 +5629,7 @@ char *file_pat_to_reg_pat(const char *pat, const char *pat_end, char *allow_dirs bool add_dollar = true; if (allow_dirs != NULL) { - *allow_dirs = FALSE; + *allow_dirs = false; } if (pat_end == NULL) { pat_end = pat + STRLEN(pat); @@ -5711,7 +5715,7 @@ char *file_pat_to_reg_pat(const char *pat, const char *pat_end, char *allow_dirs reg_pat[i++] = '/'; reg_pat[i++] = ']'; if (allow_dirs != NULL) { - *allow_dirs = TRUE; + *allow_dirs = true; } break; } @@ -5745,7 +5749,7 @@ char *file_pat_to_reg_pat(const char *pat, const char *pat_end, char *allow_dirs && (!no_bslash || *p != '\\') #endif ) { - *allow_dirs = TRUE; + *allow_dirs = true; } reg_pat[i++] = '\\'; reg_pat[i++] = *p; @@ -5758,7 +5762,7 @@ char *file_pat_to_reg_pat(const char *pat, const char *pat_end, char *allow_dirs reg_pat[i++] = '/'; reg_pat[i++] = ']'; if (allow_dirs != NULL) { - *allow_dirs = TRUE; + *allow_dirs = true; } break; #endif diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 9cc17acb37..b4ddb3ec08 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1556,7 +1556,7 @@ static void foldCreateMarkers(win_T *wp, pos_T start, pos_T end) } parseMarker(wp); - foldAddMarker(buf, start, wp->w_p_fmr, foldstartmarkerlen); + foldAddMarker(buf, start, (char_u *)wp->w_p_fmr, foldstartmarkerlen); foldAddMarker(buf, end, foldendmarker, foldendmarkerlen); // Update both changes here, to avoid all folds after the start are @@ -1575,9 +1575,9 @@ static void foldCreateMarkers(win_T *wp, pos_T start, pos_T end) /// Add "marker[markerlen]" in 'commentstring' to position `pos`. static void foldAddMarker(buf_T *buf, pos_T pos, const char_u *marker, size_t markerlen) { - char_u *cms = buf->b_p_cms; + char_u *cms = (char_u *)buf->b_p_cms; char_u *newline; - char_u *p = (char_u *)strstr((char *)buf->b_p_cms, "%s"); + char_u *p = (char_u *)strstr(buf->b_p_cms, "%s"); bool line_is_comment = false; linenr_T lnum = pos.lnum; @@ -1621,7 +1621,7 @@ static void deleteFoldMarkers(win_T *wp, fold_T *fp, int recursive, linenr_T lnu lnum_off + fp->fd_top); } } - foldDelMarker(wp->w_buffer, fp->fd_top + lnum_off, wp->w_p_fmr, + foldDelMarker(wp->w_buffer, fp->fd_top + lnum_off, (char_u *)wp->w_p_fmr, foldstartmarkerlen); foldDelMarker(wp->w_buffer, fp->fd_top + lnum_off + fp->fd_len - 1, foldendmarker, foldendmarkerlen); @@ -1639,7 +1639,7 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char_u *marker, size_t mark return; } - char_u *cms = buf->b_p_cms; + char_u *cms = (char_u *)buf->b_p_cms; char_u *line = ml_get_buf(buf, lnum, false); for (char_u *p = line; *p != NUL; p++) { if (STRNCMP(p, marker, markerlen) != 0) { @@ -1729,7 +1729,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldin emsg_silent++; // handle exceptions, but don't display errors text = - (char_u *)eval_to_string_safe((char *)wp->w_p_fdt, NULL, + (char_u *)eval_to_string_safe(wp->w_p_fdt, NULL, was_set_insecurely(wp, "foldtext", OPT_LOCAL)); emsg_silent--; @@ -1790,7 +1790,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldin static void foldtext_cleanup(char_u *str) { // Ignore leading and trailing white space in 'commentstring'. - char_u *cms_start = (char_u *)skipwhite((char *)curbuf->b_p_cms); + char_u *cms_start = (char_u *)skipwhite(curbuf->b_p_cms); size_t cms_slen = STRLEN(cms_start); while (cms_slen > 0 && ascii_iswhite(cms_start[cms_slen - 1])) { cms_slen--; @@ -2854,7 +2854,7 @@ static void foldlevelIndent(fline_T *flp) // empty line or lines starting with a character in 'foldignore': level // depends on surrounding lines - if (*s == NUL || vim_strchr((char *)flp->wp->w_p_fdi, *s) != NULL) { + if (*s == NUL || vim_strchr(flp->wp->w_p_fdi, *s) != NULL) { // first and last line can't be undefined, use level 0 if (lnum == 1 || lnum == buf->b_ml.ml_line_count) { flp->lvl = 0; @@ -2907,7 +2907,7 @@ static void foldlevelExpr(fline_T *flp) const bool save_keytyped = KeyTyped; int c; - const int n = eval_foldexpr((char *)flp->wp->w_p_fde, &c); + const int n = eval_foldexpr(flp->wp->w_p_fde, &c); KeyTyped = save_keytyped; switch (c) { @@ -2985,8 +2985,8 @@ static void foldlevelExpr(fline_T *flp) /// Relies on the option value to have been checked for correctness already. static void parseMarker(win_T *wp) { - foldendmarker = (char_u *)vim_strchr((char *)wp->w_p_fmr, ','); - foldstartmarkerlen = (size_t)(foldendmarker++ - wp->w_p_fmr); + foldendmarker = (char_u *)vim_strchr(wp->w_p_fmr, ','); + foldstartmarkerlen = (size_t)(foldendmarker++ - (char_u *)wp->w_p_fmr); foldendmarkerlen = STRLEN(foldendmarker); } @@ -3003,7 +3003,7 @@ static void foldlevelMarker(fline_T *flp) int start_lvl = flp->lvl; // cache a few values for speed - char_u *startmarker = flp->wp->w_p_fmr; + char_u *startmarker = (char_u *)flp->wp->w_p_fmr; int cstart = *startmarker; startmarker++; int cend = *foldendmarker; diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 1f4d28bcd3..f5f09f1394 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -81,11 +81,9 @@ static buffheader_T readbuf2 = { { NULL, { NUL } }, NULL, 0, 0 }; static int typeahead_char = 0; // typeahead char that's not flushed -/* - * when block_redo is TRUE redo buffer will not be changed - * used by edit() to repeat insertions and 'V' command for redoing - */ -static int block_redo = FALSE; +// when block_redo is true redo buffer will not be changed +// used by edit() to repeat insertions and 'V' command for redoing +static int block_redo = false; static int KeyNoremap = 0; // remapping flags @@ -162,7 +160,7 @@ static char_u *get_buffcont(buffheader_T *buffer, int dozero) p2 = p; for (const buffblock_T *bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next) { - for (const char_u *str = bp->b_str; *str;) { + for (const char_u *str = (char_u *)bp->b_str; *str;) { *p2++ = *str++; } } @@ -179,7 +177,7 @@ char_u *get_recorded(void) char_u *p; size_t len; - p = get_buffcont(&recordbuff, TRUE); + p = get_buffcont(&recordbuff, true); free_buff(&recordbuff); /* @@ -207,7 +205,7 @@ char_u *get_recorded(void) /// K_SPECIAL in the returned string is escaped. char_u *get_inserted(void) { - return get_buffcont(&redobuff, FALSE); + return get_buffcont(&redobuff, false); } /// Add string after the current block of the given buffer @@ -319,7 +317,7 @@ static void add_char_buff(buffheader_T *buf, int c) /// Get one byte from the read buffers. Use readbuf1 one first, use readbuf2 /// if that one is empty. -/// If advance == TRUE go to the next char. +/// If advance == true go to the next char. /// No translation is done K_SPECIAL is escaped. static int read_readbuffers(int advance) { @@ -341,7 +339,7 @@ static int read_readbuf(buffheader_T *buf, int advance) } buffblock_T *const curr = buf->bh_first.b_next; - c = curr->b_str[buf->bh_index]; + c = (char_u)curr->b_str[buf->bh_index]; if (advance) { if (curr->b_str[++buf->bh_index] == NUL) { @@ -368,19 +366,15 @@ static void start_stuff(void) } } -/* - * Return TRUE if the stuff buffer is empty. - */ +/// Return true if the stuff buffer is empty. int stuff_empty(void) FUNC_ATTR_PURE { return (readbuf1.bh_first.b_next == NULL && readbuf2.bh_first.b_next == NULL); } -/* - * Return TRUE if readbuf1 is empty. There may still be redo characters in - * redbuf2. - */ +/// Return true if readbuf1 is empty. There may still be redo characters in +/// redbuf2. int readbuf1_empty(void) FUNC_ATTR_PURE { @@ -649,7 +643,7 @@ static int read_redo(bool init, bool old_redo) if (bp == NULL) { return FAIL; } - p = bp->b_str; + p = (char_u *)bp->b_str; return OK; } if ((c = *p) == NUL) { @@ -670,7 +664,7 @@ static int read_redo(bool init, bool old_redo) } if (*++p == NUL && bp->b_next != NULL) { bp = bp->b_next; - p = bp->b_str; + p = (char_u *)bp->b_str; } buf[i] = (char_u)c; if (i == n - 1) { // last byte of a character @@ -793,7 +787,7 @@ int start_redo_ins(void) void stop_redo_ins(void) { - block_redo = FALSE; + block_redo = false; } /* @@ -934,7 +928,7 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) } for (i = 0; i < addlen; i++) { typebuf.tb_noremap[typebuf.tb_off + i + offset] = - (char_u)((--nrm >= 0) ? val : RM_YES); + (uint8_t)((--nrm >= 0) ? val : RM_YES); } // tb_maplen and tb_silent only remember the length of mapped and/or @@ -970,7 +964,7 @@ int ins_char_typebuf(int c, int modifiers) return (int)len; } -/// Return TRUE if the typeahead buffer was changed (while waiting for a +/// Return true if the typeahead buffer was changed (while waiting for a /// character to arrive). Happens when a message was received from a client or /// from feedkeys(). /// But check in a more generic way to avoid trouble: When "typebuf.tb_buf" @@ -986,10 +980,8 @@ bool typebuf_changed(int tb_change_cnt) || typebuf_was_filled); } -/* - * Return TRUE if there are no characters in the typeahead buffer that have - * not been typed (result from a mapping or come from ":normal"). - */ +/// Return true if there are no characters in the typeahead buffer that have +/// not been typed (result from a mapping or come from ":normal"). int typebuf_typed(void) FUNC_ATTR_PURE { @@ -1353,9 +1345,7 @@ void close_all_scripts(void) #endif -/* - * Return TRUE when reading keys from a script file. - */ +/// Return true when reading keys from a script file. int using_script(void) FUNC_ATTR_PURE { @@ -1686,7 +1676,7 @@ int vpeekc_any(void) /* * Call vpeekc() without causing anything to be mapped. - * Return TRUE if a character is available, FALSE otherwise. + * Return true if a character is available, false otherwise. */ int char_avail(void) { @@ -2047,12 +2037,11 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) // - Partly match: mlen == typebuf.tb_len keylen = mp->m_keylen; if (mlen == keylen || (mlen == typebuf.tb_len && typebuf.tb_len < keylen)) { - char_u *s; int n; // If only script-local mappings are allowed, check if the // mapping starts with K_SNR. - s = typebuf.tb_noremap + typebuf.tb_off; + uint8_t *s = typebuf.tb_noremap + typebuf.tb_off; if (*s == RM_SCRIPT && (mp->m_keys[0] != K_SPECIAL || mp->m_keys[1] != KS_EXTRA @@ -2248,7 +2237,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) save_m_keys = vim_strsave(mp->m_keys); if (save_m_luaref == LUA_NOREF) { - save_m_str = vim_strsave(mp->m_str); + save_m_str = vim_strsave((char_u *)mp->m_str); } map_str = eval_map_expr(mp, NUL); @@ -2280,7 +2269,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) vgetc_busy = save_vgetc_busy; may_garbage_collect = save_may_garbage_collect; } else { - map_str = mp->m_str; + map_str = (char_u *)mp->m_str; } // Insert the 'to' part in the typebuf.tb_buf. @@ -2364,8 +2353,8 @@ void check_end_reg_executing(bool advance) /// /// if "advance" is true (vgetc()): /// Really get the character. -/// KeyTyped is set to TRUE in the case the user typed the key. -/// KeyStuffed is TRUE if the character comes from the stuff buffer. +/// KeyTyped is set to true in the case the user typed the key. +/// KeyStuffed is true if the character comes from the stuff buffer. /// if "advance" is false (vpeekc()): /// Just look whether there is a character available. /// Return NUL if not. @@ -2452,7 +2441,7 @@ static int vgetorpeek(bool advance) // flush all input c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0L); - // If inchar() returns TRUE (script file was active) or we + // If inchar() returns true (script file was active) or we // are inside a mapping, get out of Insert mode. // Otherwise we behave like having gotten a CTRL-C. // As a result typing CTRL-C in insert mode will @@ -2501,7 +2490,7 @@ static int vgetorpeek(bool advance) // write char to script file(s) gotchars(typebuf.tb_buf + typebuf.tb_off, 1); } - KeyNoremap = typebuf.tb_noremap[typebuf.tb_off]; + KeyNoremap = (unsigned char)typebuf.tb_noremap[typebuf.tb_off]; del_typebuf(1, 0); } break; // got character, break the for loop @@ -2866,7 +2855,7 @@ int inchar(char_u *buf, int maxlen, long wait_time) if (read_size <= 0) { // Did not get a character from script. // If we got an interrupt, skip all previously typed characters and - // return TRUE if quit reading script file. + // return true if quit reading script file. // Stop reading typeahead when a single CTRL-C was read, // fill_input_buf() returns this when not able to read from stdin. // Don't use buf[] here, closescript() may have freed typebuf.tb_buf[] diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 67b113849c..6c83e2f3c3 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -755,7 +755,7 @@ EXTERN int keep_help_flag INIT(= false); // doing :ta from help file // When a string option is NULL (which only happens in out-of-memory // situations), it is set to empty_option, to avoid having to check for NULL // everywhere. -EXTERN char_u *empty_option INIT(= (char_u *)""); +EXTERN char *empty_option INIT(= ""); EXTERN bool redir_off INIT(= false); // no redirection for a moment EXTERN FILE *redir_fd INIT(= NULL); // message redirection file @@ -795,7 +795,6 @@ EXTERN char *last_chdir_reason INIT(= NULL); EXTERN bool km_stopsel INIT(= false); EXTERN bool km_startsel INIT(= false); -EXTERN int cedit_key INIT(= -1); ///< key value of 'cedit' option EXTERN int cmdwin_type INIT(= 0); ///< type of cmdline window or 0 EXTERN int cmdwin_result INIT(= 0); ///< result of cmdline window or 0 EXTERN int cmdwin_level INIT(= 0); ///< cmdline recursion level diff --git a/src/nvim/grid.c b/src/nvim/grid.c index f95ef3e705..c805c238c6 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -475,9 +475,9 @@ static int grid_char_needs_redraw(ScreenGrid *grid, size_t off_from, size_t off_ /// "endcol" gives the columns where valid characters are. /// "clear_width" is the width of the window. It's > 0 if the rest of the line /// needs to be cleared, negative otherwise. -/// "rlflag" is TRUE in a rightleft window: -/// When TRUE and "clear_width" > 0, clear columns 0 to "endcol" -/// When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" +/// "rlflag" is true in a rightleft window: +/// When true and "clear_width" > 0, clear columns 0 to "endcol" +/// When false and "clear_width" > 0, clear columns "endcol" to "clear_width" /// If "wrap" is true, then hint to the UI that "row" contains a line /// which has wrapped into the next row. void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int clear_width, diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 6f45b4a03d..7d261b751c 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -51,20 +51,20 @@ * * int mch_print_begin(prt_settings_T *settings) * Called to start the print job. - * Return FALSE to abort. + * Return false to abort. * * int mch_print_begin_page(char_u *msg) * Called at the start of each page. * "msg" indicates the progress of the print job, can be NULL. - * Return FALSE to abort. + * Return false to abort. * * int mch_print_end_page() * Called at the end of each page. - * Return FALSE to abort. + * Return false to abort. * * int mch_print_blank_page() * Called to generate a blank page for collated, duplex, multiple copy - * document. Return FALSE to abort. + * document. Return false to abort. * * void mch_print_end(prt_settings_T *psettings) * Called at normal end of print job. @@ -87,36 +87,33 @@ * * mch_print_start_line(int margin, int page_line) * Sets the current position at the start of line "page_line". - * If margin is TRUE start in the left margin (for header and line number). + * If margin is true start in the left margin (for header and line number). * * int mch_print_text_out(char_u *p, size_t len); * Output one character of text p[len] at the current position. - * Return TRUE if there is no room for another character in the same line. + * Return true if there is no room for another character in the same line. * * Note that the generic code has no idea of margins. The machine code should * simply make the page look smaller! The header and the line numbers are * printed in the margin. */ -static option_table_T printer_opts[OPT_PRINT_NUM_OPTIONS] - = - { - { "top", TRUE, 0, NULL, 0, FALSE }, - { "bottom", TRUE, 0, NULL, 0, FALSE }, - { "left", TRUE, 0, NULL, 0, FALSE }, - { "right", TRUE, 0, NULL, 0, FALSE }, - { "header", TRUE, 0, NULL, 0, FALSE }, - { "syntax", FALSE, 0, NULL, 0, FALSE }, - { "number", FALSE, 0, NULL, 0, FALSE }, - { "wrap", FALSE, 0, NULL, 0, FALSE }, - { "duplex", FALSE, 0, NULL, 0, FALSE }, - { "portrait", FALSE, 0, NULL, 0, FALSE }, - { "paper", FALSE, 0, NULL, 0, FALSE }, - { "collate", FALSE, 0, NULL, 0, FALSE }, - { "jobsplit", FALSE, 0, NULL, 0, FALSE }, - { "formfeed", FALSE, 0, NULL, 0, FALSE }, - } -; +static option_table_T printer_opts[OPT_PRINT_NUM_OPTIONS] = { + { "top", true, 0, NULL, 0, false }, + { "bottom", true, 0, NULL, 0, false }, + { "left", true, 0, NULL, 0, false }, + { "right", true, 0, NULL, 0, false }, + { "header", true, 0, NULL, 0, false }, + { "syntax", false, 0, NULL, 0, false }, + { "number", false, 0, NULL, 0, false }, + { "wrap", false, 0, NULL, 0, false }, + { "duplex", false, 0, NULL, 0, false }, + { "portrait", false, 0, NULL, 0, false }, + { "paper", false, 0, NULL, 0, false }, + { "collate", false, 0, NULL, 0, false }, + { "jobsplit", false, 0, NULL, 0, false }, + { "formfeed", false, 0, NULL, 0, false }, +}; static const uint32_t cterm_color_8[8] = { 0x000000, 0xff0000, 0x00ff00, 0xffff00, @@ -152,12 +149,12 @@ static int page_count; static option_table_T mbfont_opts[OPT_MBFONT_NUM_OPTIONS] = { - { "c", FALSE, 0, NULL, 0, FALSE }, - { "a", FALSE, 0, NULL, 0, FALSE }, - { "r", FALSE, 0, NULL, 0, FALSE }, - { "b", FALSE, 0, NULL, 0, FALSE }, - { "i", FALSE, 0, NULL, 0, FALSE }, - { "o", FALSE, 0, NULL, 0, FALSE }, + { "c", false, 0, NULL, 0, false }, + { "a", false, 0, NULL, 0, false }, + { "r", false, 0, NULL, 0, false }, + { "b", false, 0, NULL, 0, false }, + { "i", false, 0, NULL, 0, false }, + { "o", false, 0, NULL, 0, false }, }; /* @@ -506,9 +503,7 @@ int prt_header_height(void) return 2; } -/* - * Return TRUE if using a line number for printing. - */ +// Return true if using a line number for printing. int prt_use_number(void) { return printer_opts[OPT_PRINT_NUMBER].present @@ -552,7 +547,7 @@ static void prt_header(prt_settings_T *const psettings, const int pagenum, const if (*p_header != NUL) { linenr_T tmp_lnum, tmp_topline, tmp_botline; - int use_sandbox = FALSE; + int use_sandbox = false; /* * Need to (temporarily) set current line number and first/last line @@ -669,7 +664,7 @@ void ex_hardcopy(exarg_T *eap) settings.modec = 'c'; if (!syntax_present(curwin)) { - settings.do_syntax = FALSE; + settings.do_syntax = false; } else if (printer_opts[OPT_PRINT_SYNTAX].present && TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) != 'a') { settings.do_syntax = @@ -866,7 +861,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T { colnr_T col; char_u *line; - int need_break = FALSE; + int need_break = false; int outputlen; int tab_spaces; int print_pos; @@ -879,7 +874,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T if (!ppos->ff && prt_use_number()) { prt_line_number(psettings, page_line, ppos->file_line); } - ppos->ff = FALSE; + ppos->ff = false; } else { // left over from wrap halfway through a tab print_pos = ppos->print_pos; @@ -942,7 +937,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T && printer_opts[OPT_PRINT_FORMFEED].present && TOLOWER_ASC(printer_opts[OPT_PRINT_FORMFEED].string[0]) == 'y') { - ppos->ff = TRUE; + ppos->ff = true; need_break = 1; } else { need_break = mch_print_text_out(line + col, (size_t)outputlen); @@ -1984,7 +1979,7 @@ void mch_print_cleanup(void) if (prt_do_conv) { convert_setup(&prt_conv, NULL, NULL); - prt_do_conv = FALSE; + prt_do_conv = false; } if (prt_ps_fd != NULL) { fclose(prt_ps_fd); @@ -2116,11 +2111,11 @@ static int prt_match_encoding(char *p_encoding, struct prt_ps_mbfont_S *p_cmap, for (mbenc = 0; mbenc < p_cmap->num_encodings; mbenc++) { if (STRNICMP(p_mbenc->encoding, p_encoding, enc_len) == 0) { *pp_mbenc = p_mbenc; - return TRUE; + return true; } p_mbenc++; } - return FALSE; + return false; } static int prt_match_charset(char *p_charset, struct prt_ps_mbfont_S *p_cmap, @@ -2139,11 +2134,11 @@ static int prt_match_charset(char *p_charset, struct prt_ps_mbfont_S *p_cmap, for (mbchar = 0; mbchar < p_cmap->num_charsets; mbchar++) { if (STRNICMP(p_mbchar->charset, p_charset, char_len) == 0) { *pp_mbchar = p_mbchar; - return TRUE; + return true; } p_mbchar++; } - return FALSE; + return false; } int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) @@ -2277,7 +2272,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) prt_ps_font = &prt_ps_mb_font; } else { - prt_use_courier = FALSE; + prt_use_courier = false; prt_ps_font = &prt_ps_courier_font; } @@ -2379,16 +2374,16 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) * Set up printer duplex and tumble based on Duplex option setting - default * is long sided duplex printing (i.e. no tumble). */ - prt_duplex = TRUE; - prt_tumble = FALSE; + prt_duplex = true; + prt_tumble = false; psettings->duplex = 1; if (printer_opts[OPT_PRINT_DUPLEX].present) { if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "off", 3) == 0) { - prt_duplex = FALSE; + prt_duplex = false; psettings->duplex = 0; } else if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "short", 5) == 0) { - prt_tumble = TRUE; + prt_tumble = true; } } @@ -2941,7 +2936,7 @@ int mch_print_begin_page(char_u *str) int mch_print_blank_page(void) { - return mch_print_begin_page(NULL) ? (mch_print_end_page()) : FALSE; + return mch_print_begin_page(NULL) ? (mch_print_end_page()) : false; } static double prt_pos_x = 0; diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 7a0c7ba395..a63768a8e3 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -690,7 +690,7 @@ static int color_numbers_8[28] = { 0, 4, 2, 6, // Lookup the "cterm" value to be used for color with index "idx" in // color_names[]. -// "boldp" will be set to TRUE or FALSE for a foreground color when using 8 +// "boldp" will be set to kTrue or kFalse for a foreground color when using 8 // colors, otherwise it will be unchanged. int lookup_color(const int idx, const bool foreground, TriState *const boldp) { @@ -1371,7 +1371,7 @@ void restore_cterm_colors(void) /// @param check_link if true also check for an existing link. /// -/// @return TRUE if highlight group "idx" has any settings. +/// @return true if highlight group "idx" has any settings. static int hl_has_settings(int idx, bool check_link) { return hl_table[idx].sg_cleared == 0 @@ -1761,7 +1761,7 @@ int syn_name2attr(const char_u *name) return 0; } -/// Return TRUE if highlight group "name" exists. +/// Return true if highlight group "name" exists. int highlight_exists(const char *name) { return syn_name2id(name) > 0; diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 9d3b2b0455..e32b58fbcb 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -203,19 +203,19 @@ static void do_cscope_general(exarg_T *eap, int make_split) /// Implementation of ":cscope" and ":lcscope" void ex_cscope(exarg_T *eap) { - do_cscope_general(eap, FALSE); + do_cscope_general(eap, false); } /// Implementation of ":scscope". Same as ex_cscope(), but splits window, too. void ex_scscope(exarg_T *eap) { - do_cscope_general(eap, TRUE); + do_cscope_general(eap, true); } /// Implementation of ":cstag" void ex_cstag(exarg_T *eap) { - int ret = FALSE; + int ret = false; if (*eap->arg == NUL) { (void)emsg(_("E562: Usage: cstag <ident>")); @@ -278,7 +278,7 @@ void ex_cstag(exarg_T *eap) /// This simulates a vim_fgets(), but for cscope, returns the next line /// from the cscope output. should only be called from find_tags() /// -/// @return true if eof, FALSE otherwise +/// @return true if eof, false otherwise bool cs_fgets(char_u *buf, int size) FUNC_ATTR_NONNULL_ALL { @@ -839,7 +839,7 @@ err_closing: si.hStdOutput = stdout_wr; si.hStdError = stdout_wr; si.hStdInput = stdin_rd; - created = CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, + created = CreateProcess(NULL, cmd, NULL, NULL, true, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi); xfree(prog); xfree(cmd); @@ -875,7 +875,7 @@ err_closing: /// Query cscope using command line interface. Parse the output and use tselect /// to allow choices. Like Nvi, creates a pipe to send to/from query/cscope. /// -/// @return TRUE if we jump to a tag or abort, FALSE if not. +/// @return true if we jump to a tag or abort, false if not. static int cs_find(exarg_T *eap) { char *opt, *pat; @@ -1106,7 +1106,7 @@ static int cs_help(exarg_T *eap) cmdp++; } - wait_return(TRUE); + wait_return(true); return CSCOPE_SUCCESS; } @@ -1280,7 +1280,7 @@ static void cs_kill_execute(size_t i, char *cname) (void)smsg_attr(HL_ATTR(HLF_R) | MSG_HIST, _("cscope connection %s closed"), cname); } - cs_release_csp(i, TRUE); + cs_release_csp(i, true); } /// Convert the cscope output into a ctags style entry (as might be found @@ -1932,7 +1932,7 @@ static int cs_reset(exarg_T *eap) pplist[i] = csinfo[i].ppath; fllist[i] = csinfo[i].flags; if (csinfo[i].fname != NULL) { - cs_release_csp(i, FALSE); + cs_release_csp(i, false); } } @@ -2035,7 +2035,7 @@ static int cs_show(exarg_T *eap) } } - wait_return(TRUE); + wait_return(true); return CSCOPE_SUCCESS; } diff --git a/src/nvim/indent.c b/src/nvim/indent.c index f18a6d7b32..c44cd06a2f 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -710,7 +710,7 @@ int get_number_indent(linenr_T lnum) if ((State & MODE_INSERT) || has_format_option(FO_Q_COMS)) { lead_len = get_leader_len((char *)ml_get(lnum), NULL, false, true); } - regmatch.regprog = vim_regcomp((char *)curbuf->b_p_flp, RE_MAGIC); + regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC); if (regmatch.regprog != NULL) { regmatch.rm_ic = false; @@ -732,6 +732,47 @@ int get_number_indent(linenr_T lnum) return (int)col; } +/// This is called when 'breakindentopt' is changed and when a window is +/// initialized +bool briopt_check(win_T *wp) +{ + int bri_shift = 0; + int bri_min = 20; + bool bri_sbr = false; + int bri_list = 0; + + char *p = wp->w_p_briopt; + while (*p != NUL) { + if (STRNCMP(p, "shift:", 6) == 0 + && ((p[6] == '-' && ascii_isdigit(p[7])) || ascii_isdigit(p[6]))) { + p += 6; + bri_shift = getdigits_int(&p, true, 0); + } else if (STRNCMP(p, "min:", 4) == 0 && ascii_isdigit(p[4])) { + p += 4; + bri_min = getdigits_int(&p, true, 0); + } else if (STRNCMP(p, "sbr", 3) == 0) { + p += 3; + bri_sbr = true; + } else if (STRNCMP(p, "list:", 5) == 0) { + p += 5; + bri_list = (int)getdigits(&p, false, 0); + } + if (*p != ',' && *p != NUL) { + return false; + } + if (*p == ',') { + p++; + } + } + + wp->w_briopt_shift = bri_shift; + wp->w_briopt_min = bri_min; + wp->w_briopt_sbr = bri_sbr; + wp->w_briopt_list = bri_list; + + return true; +} + // Return appropriate space number for breakindent, taking influencing // parameters into account. Window must be specified, since it is not // necessarily always the current one. @@ -770,7 +811,7 @@ int get_breakindent_win(win_T *wp, char_u *line) // add additional indent for numbered lists if (wp->w_briopt_list != 0) { regmatch_T regmatch = { - .regprog = vim_regcomp((char *)curbuf->b_p_flp, + .regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT), }; @@ -855,7 +896,7 @@ int get_expr_indent(void) // Need to make a copy, the 'indentexpr' option could be changed while // evaluating it. - char_u *inde_copy = vim_strsave(curbuf->b_p_inde); + char_u *inde_copy = vim_strsave((char_u *)curbuf->b_p_inde); indent = (int)eval_to_number((char *)inde_copy); xfree(inde_copy); @@ -1077,7 +1118,7 @@ static int lisp_match(char_u *p) { char_u buf[LSIZE]; int len; - char *word = (char *)(*curbuf->b_p_lw != NUL ? curbuf->b_p_lw : p_lispwords); + char *word = (char *)(*curbuf->b_p_lw != NUL ? (char_u *)curbuf->b_p_lw : p_lispwords); while (*word != NUL) { (void)copy_option_part(&word, (char *)buf, LSIZE, ","); diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index fe8c235cc1..128eea915d 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -223,7 +223,7 @@ bool cin_is_cinword(const char_u *line) char_u *cinw_buf = xmalloc(cinw_len); line = (char_u *)skipwhite((char *)line); - for (char *cinw = (char *)curbuf->b_p_cinw; *cinw;) { + for (char *cinw = curbuf->b_p_cinw; *cinw;) { size_t len = copy_option_part(&cinw, (char *)cinw_buf, cinw_len, ","); if (STRNCMP(line, cinw_buf, len) == 0 && (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1]))) { @@ -275,10 +275,8 @@ static const char_u *cin_skipcomment(const char_u *s) return s; } -/* - * Return TRUE if there is no code at *s. White space and comments are - * not considered code. - */ +/// Return true if there is no code at *s. White space and comments are +/// not considered code. static int cin_nocode(const char_u *s) { return *cin_skipcomment(s) == NUL; @@ -403,7 +401,7 @@ bool cin_islabel(void) // XXX } curwin->w_cursor = cursor_save; - if (cin_isterminated(line, TRUE, FALSE) + if (cin_isterminated(line, true, false) || cin_isscopedecl(line) || cin_iscase(line, true) || (cin_islabel_skip(&line) && cin_nocode(line))) { @@ -455,7 +453,7 @@ static int cin_isinit(void) return true; } - return FALSE; + return false; } /// Recognize a switch label: "case .*:" or "default:". @@ -519,7 +517,7 @@ bool cin_isscopedecl(const char_u *p) bool found = false; - for (char *cinsd = (char *)curbuf->b_p_cinsd; *cinsd;) { + for (char *cinsd = curbuf->b_p_cinsd; *cinsd;) { const size_t len = copy_option_part(&cinsd, (char *)cinsd_buf, cinsd_len, ","); if (STRNCMP(s, cinsd_buf, len) == 0) { const char_u *skip = cin_skipcomment(s + len); @@ -769,10 +767,10 @@ static int cin_ispreproc(const char_u *s) if (*skipwhite((char *)s) == '#') { return true; } - return FALSE; + return false; } -/// Return TRUE if line "*pp" at "*lnump" is a preprocessor statement or a +/// Return true if line "*pp" at "*lnump" is a preprocessor statement or a /// continuation line of a preprocessor statement. Decrease "*lnump" to the /// start and return the line in "*pp". /// Put the amount of indent in "*amount". @@ -789,7 +787,7 @@ static int cin_ispreproc_cont(const char_u **pp, linenr_T *lnump, int *amount) for (;;) { if (cin_ispreproc(line)) { - retval = TRUE; + retval = true; *lnump = lnum; break; } @@ -842,7 +840,7 @@ static char_u cin_isterminated(const char_u *s, int incl_open, int incl_comma) { char_u found_start = 0; unsigned n_open = 0; - int is_else = FALSE; + int is_else = false; s = cin_skipcomment(s); @@ -1095,14 +1093,12 @@ probablyFound: return 0; } -/* - * Return TRUE if we are at the end of a do-while. - * do - * nothing; - * while (foo - * && bar); <-- here - * Adjust the cursor to the line with "while". - */ +/// Return true if we are at the end of a do-while. +/// do +/// nothing; +/// while (foo +/// && bar); <-- here +/// Adjust the cursor to the line with "while". static int cin_iswhileofdo_end(int terminated) { const char_u *line; @@ -1133,7 +1129,7 @@ static int cin_iswhileofdo_end(int terminated) } if (cin_starts_with(s, "while")) { curwin->w_cursor.lnum = trypos->lnum; - return TRUE; + return true; } } @@ -1146,7 +1142,7 @@ static int cin_iswhileofdo_end(int terminated) p++; } } - return FALSE; + return false; } static int cin_isbreak(const char_u *p) @@ -1190,7 +1186,7 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) return false; } - cpp_base_class = lookfor_ctor_init = class_or_struct = FALSE; + cpp_base_class = lookfor_ctor_init = class_or_struct = false; /* Search for a line starting with '#', empty, ending in ';' or containing * '{' or '}' and start below it. This handles the following situations: @@ -1256,7 +1252,7 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) if (s[1] == ':') { /* skip double colon. It can't be a constructor * initialization any more */ - lookfor_ctor_init = FALSE; + lookfor_ctor_init = false; s = cin_skipcomment(s + 2); } else if (lookfor_ctor_init || class_or_struct) { /* we have something found, that looks like the start of @@ -1270,8 +1266,8 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) } } else if ((STRNCMP(s, "class", 5) == 0 && !vim_isIDc(s[5])) || (STRNCMP(s, "struct", 6) == 0 && !vim_isIDc(s[6]))) { - class_or_struct = TRUE; - lookfor_ctor_init = FALSE; + class_or_struct = true; + lookfor_ctor_init = false; if (*s == 'c') { s = cin_skipcomment(s + 5); @@ -1280,12 +1276,12 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) } } else { if (s[0] == '{' || s[0] == '}' || s[0] == ';') { - cpp_base_class = lookfor_ctor_init = class_or_struct = FALSE; + cpp_base_class = lookfor_ctor_init = class_or_struct = false; } else if (s[0] == ')') { /* Constructor-initialization is assumed if we come across * something like "):" */ - class_or_struct = FALSE; - lookfor_ctor_init = TRUE; + class_or_struct = false; + lookfor_ctor_init = true; } else if (s[0] == '?') { // Avoid seeing '() :' after '?' as constructor init. return false; @@ -1345,11 +1341,9 @@ static int get_baseclass_amount(int col) return amount; } -/* - * Return TRUE if string "s" ends with the string "find", possibly followed by - * white space and comments. Skip strings and comments. - * Ignore "ignore" after "find" if it's not NULL. - */ +/// Return true if string "s" ends with the string "find", possibly followed by +/// white space and comments. Skip strings and comments. +/// Ignore "ignore" after "find" if it's not NULL. static int cin_ends_in(const char_u *s, const char_u *find, const char_u *ignore) { const char_u *p = s; @@ -1371,12 +1365,10 @@ static int cin_ends_in(const char_u *s, const char_u *find, const char_u *ignore p++; } } - return FALSE; + return false; } -/* - * Return TRUE when "s" starts with "word" and then a non-ID character. - */ +/// Return true when "s" starts with "word" and then a non-ID character. static int cin_starts_with(const char_u *s, const char *word) { int l = (int)STRLEN(word); @@ -1573,7 +1565,7 @@ static int corr_ind_maxparen(pos_T *startpos) static int find_last_paren(const char_u *l, int start, int end) { int i; - int retval = FALSE; + int retval = false; int open_count = 0; curwin->w_cursor.col = 0; // default is start of line @@ -1588,7 +1580,7 @@ static int find_last_paren(const char_u *l, int start, int end) open_count--; } else { curwin->w_cursor.col = i; - retval = TRUE; + retval = true; } } } @@ -1740,7 +1732,7 @@ void parse_cino(buf_T *buf) // Handle C #pragma directives buf->b_ind_pragma = 0; - for (p = (char *)buf->b_p_cino; *p;) { + for (p = buf->b_p_cino; *p;) { l = p++; if (*p == '-') { p++; @@ -2055,7 +2047,7 @@ int get_c_indent(void) char *p; int start_align = 0; int start_off = 0; - int done = FALSE; + int done = false; // find how indented the line beginning the comment is getvcol(curwin, comment_pos, &col, NULL, NULL); @@ -2063,7 +2055,7 @@ int get_c_indent(void) *lead_start = NUL; *lead_middle = NUL; - p = (char *)curbuf->b_p_com; + p = curbuf->b_p_com; while (*p != NUL) { int align = 0; int off = 0; @@ -2098,7 +2090,7 @@ int get_c_indent(void) * up with the comment opener per the 'comments' option. */ if (STRNCMP(theline, lead_middle, lead_middle_len) == 0 && STRNCMP(theline, lead_end, STRLEN(lead_end)) != 0) { - done = TRUE; + done = true; if (curwin->w_cursor.lnum > 1) { /* If the start comment string matches in the previous * line, use the indent of that line plus offset. If @@ -2562,7 +2554,7 @@ int get_c_indent(void) } } - lookfor_break = FALSE; + lookfor_break = false; if (cin_iscase(theline, false)) { // it's a switch() label lookfor = LOOKFOR_CASE; // find a previous switch() label @@ -2646,7 +2638,7 @@ int get_c_indent(void) continue; } - terminated = cin_isterminated(l, FALSE, TRUE); + terminated = cin_isterminated(l, false, true); /* * If we are at top level and the line looks like a @@ -2660,7 +2652,7 @@ int get_c_indent(void) * don't add extra indent. * TODO: does not work, if a function * declaration is split over multiple lines: - * cin_isfuncdecl returns FALSE then. + * cin_isfuncdecl returns false then. */ if (terminated == ',') { break; @@ -2971,7 +2963,7 @@ int get_c_indent(void) * initialisation (not indented) or a variable declaration * (indented). */ - terminated = cin_isterminated(l, FALSE, TRUE); + terminated = cin_isterminated(l, false, true); if (js_cur_has_key) { js_cur_has_key = false; // only check the first line diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index c92183dc2a..a3b5e3df5c 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -901,7 +901,7 @@ static void ins_compl_longest_match(compl_T *match) had_match = (curwin->w_cursor.col > compl_col); ins_compl_delete(); - ins_bytes(compl_leader + get_compl_len()); + ins_bytes((char *)compl_leader + get_compl_len()); ins_redraw(false); // When the match isn't there (to avoid matching itself) remove it @@ -935,7 +935,7 @@ static void ins_compl_longest_match(compl_T *match) *p = NUL; had_match = (curwin->w_cursor.col > compl_col); ins_compl_delete(); - ins_bytes(compl_leader + get_compl_len()); + ins_bytes((char *)compl_leader + get_compl_len()); ins_redraw(false); // When the match isn't there (to avoid matching itself) remove it @@ -1677,7 +1677,7 @@ static void ins_compl_new_leader(void) { ins_compl_del_pum(); ins_compl_delete(); - ins_bytes(compl_leader + get_compl_len()); + ins_bytes((char *)compl_leader + get_compl_len()); compl_used_match = false; if (compl_started) { @@ -2224,11 +2224,11 @@ static char_u *get_complete_funcname(int type) { switch (type) { case CTRL_X_FUNCTION: - return curbuf->b_p_cfu; + return (char_u *)curbuf->b_p_cfu; case CTRL_X_OMNI: - return curbuf->b_p_ofu; + return (char_u *)curbuf->b_p_ofu; case CTRL_X_THESAURUS: - return *curbuf->b_p_tsrfu == NUL ? p_tsrfu : curbuf->b_p_tsrfu; + return *curbuf->b_p_tsrfu == NUL ? p_tsrfu : (char_u *)curbuf->b_p_tsrfu; default: return (char_u *)""; } @@ -2823,8 +2823,8 @@ static void get_next_dict_tsr_completion(int compl_type, char_u *dict, int dict_ } else { ins_compl_dictionaries(dict != NULL ? dict : (compl_type == CTRL_X_THESAURUS - ? (*curbuf->b_p_tsr == NUL ? p_tsr : curbuf->b_p_tsr) - : (*curbuf->b_p_dict == NUL ? p_dict : curbuf->b_p_dict)), + ? (*curbuf->b_p_tsr == NUL ? p_tsr : (char_u *)curbuf->b_p_tsr) + : (*curbuf->b_p_dict == NUL ? p_dict : (char_u *)curbuf->b_p_dict)), (char_u *)compl_pattern, dict != NULL ? dict_f : 0, compl_type == CTRL_X_THESAURUS); @@ -3174,7 +3174,7 @@ static int ins_compl_get_exp(pos_T *ini) } st.found_all = false; st.ins_buf = curbuf; - st.e_cpt = (compl_cont_status & CONT_LOCAL) ? "." : (char *)curbuf->b_p_cpt; + st.e_cpt = (compl_cont_status & CONT_LOCAL) ? "." : curbuf->b_p_cpt; st.last_match_pos = st.first_match_pos = *ini; } else if (st.ins_buf != curbuf && !buf_valid(st.ins_buf)) { st.ins_buf = curbuf; // In case the buffer was wiped out. @@ -3319,7 +3319,7 @@ void ins_compl_delete(void) /// "in_compl_func" is true when called from complete_check(). void ins_compl_insert(bool in_compl_func) { - ins_bytes(compl_shown_match->cp_str + get_compl_len()); + ins_bytes((char *)compl_shown_match->cp_str + get_compl_len()); compl_used_match = !match_at_original_text(compl_shown_match); dict_T *dict = ins_compl_dict_alloc(compl_shown_match); @@ -3511,13 +3511,13 @@ static int ins_compl_next(bool allow_get_expansion, int count, bool insert_match // Insert the text of the new completion, or the compl_leader. if (compl_no_insert && !started) { - ins_bytes(compl_orig_text + get_compl_len()); + ins_bytes((char *)compl_orig_text + get_compl_len()); compl_used_match = false; } else if (insert_match) { if (!compl_get_longest || compl_used_match) { ins_compl_insert(in_compl_func); } else { - ins_bytes(compl_leader + get_compl_len()); + ins_bytes((char *)compl_leader + get_compl_len()); } } else { compl_used_match = false; @@ -4079,9 +4079,9 @@ static int ins_compl_start(void) edit_submode_pre = (char_u *)_(" Adding"); if (ctrl_x_mode_line_or_eval()) { // Insert a new line, keep indentation but ignore 'comments'. - char_u *old = curbuf->b_p_com; + char *old = curbuf->b_p_com; - curbuf->b_p_com = (char_u *)""; + curbuf->b_p_com = ""; compl_startpos.lnum = curwin->w_cursor.lnum; compl_startpos.col = compl_col; ins_eol('\r'); diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 38bc187f4f..39585ac182 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -990,7 +990,7 @@ int nlua_in_fast_event(lua_State *lstate) static bool viml_func_is_fast(const char *name) { - const EvalFuncDef *const fdef = find_internal_func((const char *)name); + const EvalFuncDef *const fdef = find_internal_func(name); if (fdef) { return fdef->fast; } diff --git a/src/nvim/macros.h b/src/nvim/macros.h index a896a406d1..5601db274b 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -31,7 +31,7 @@ /// @return `s, sizeof(s) - 1` #define S_LEN(s) (s), (sizeof(s) - 1) -/// LINEEMPTY() - return TRUE if the line is empty +/// LINEEMPTY() - return true if the line is empty #define LINEEMPTY(p) (*ml_get(p) == NUL) // toupper() and tolower() that use the current locale. diff --git a/src/nvim/main.c b/src/nvim/main.c index 12c51e8a85..6fc70dec2d 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -508,7 +508,7 @@ int main(int argc, char **argv) // When started with "-q errorfile" jump to first error now. if (params.edit_type == EDIT_QF) { - qf_jump(NULL, 0, 0, FALSE); + qf_jump(NULL, 0, 0, false); TIME_MSG("jump to first error"); } @@ -520,7 +520,7 @@ int main(int argc, char **argv) if (params.diff_mode) { // set options in each window for "nvim -d". FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { - diff_win_options(wp, TRUE); + diff_win_options(wp, true); } } @@ -713,8 +713,8 @@ void getout(int exitval) if (did_emsg) { // give the user a chance to read the (error) message - no_wait_return = FALSE; - wait_return(FALSE); + no_wait_return = false; + wait_return(false); } // Position the cursor again, the autocommands may have moved it @@ -1638,7 +1638,7 @@ static void create_windows(mparm_T *parmp) } curwin = curwin->w_next; } - dorewind = FALSE; + dorewind = false; curbuf = curwin->w_buffer; if (curbuf->b_ml.ml_mfp == NULL) { // Set 'foldlevel' to 'foldlevelstart' if it's not negative.. @@ -1647,15 +1647,15 @@ static void create_windows(mparm_T *parmp) } // When getting the ATTENTION prompt here, use a dialog. swap_exists_action = SEA_DIALOG; - set_buflisted(TRUE); + set_buflisted(true); // create memfile, read file - (void)open_buffer(FALSE, NULL, 0); + (void)open_buffer(false, NULL, 0); if (swap_exists_action == SEA_QUIT) { if (got_int || only_one_window()) { // abort selected or quit and only one window - did_emsg = FALSE; // avoid hit-enter prompt + did_emsg = false; // avoid hit-enter prompt getout(1); } // We can't close the window, it would disturb what @@ -1667,7 +1667,7 @@ static void create_windows(mparm_T *parmp) } else { handle_swap_exists(NULL); } - dorewind = TRUE; // start again + dorewind = true; // start again } os_breakcheck(); if (got_int) { @@ -1760,7 +1760,7 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd) // abort or quit selected if (got_int || only_one_window()) { // abort selected and only one window - did_emsg = FALSE; // avoid hit-enter prompt + did_emsg = false; // avoid hit-enter prompt getout(1); } win_close(curwin, true, false); @@ -1841,7 +1841,7 @@ static void exe_commands(mparm_T *parmp) * pattern on line 1. But don't move the cursor when an autocommand * with g`" was used. */ - msg_scroll = TRUE; + msg_scroll = true; if (parmp->tagname == NULL && curwin->w_cursor.lnum <= 1) { curwin->w_cursor.lnum = 0; } @@ -1861,12 +1861,12 @@ static void exe_commands(mparm_T *parmp) } if (!exmode_active) { - msg_scroll = FALSE; + msg_scroll = false; } // When started with "-q errorfile" jump to first error again. if (parmp->edit_type == EDIT_QF) { - qf_jump(NULL, 0, 0, FALSE); + qf_jump(NULL, 0, 0, false); } TIME_MSG("executing command arguments"); } diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 9da7e9a947..f7f1de13c4 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -150,7 +150,7 @@ static void showmap(mapblock_T *mp, bool local) { size_t len = 1; - if (message_filtered(mp->m_keys) && message_filtered(mp->m_str) + if (message_filtered(mp->m_keys) && message_filtered((char_u *)mp->m_str) && (mp->m_desc == NULL || message_filtered((char_u *)mp->m_desc))) { return; } @@ -203,7 +203,7 @@ static void showmap(mapblock_T *mp, bool local) } else if (mp->m_str[0] == NUL) { msg_puts_attr("<Nop>", HL_ATTR(HLF_8)); } else { - msg_outtrans_special(mp->m_str, false, 0); + msg_outtrans_special((char_u *)mp->m_str, false, 0); } if (mp->m_desc != NULL) { @@ -449,8 +449,8 @@ static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, } mp->m_keys = vim_strsave(keys); - mp->m_str = args->rhs; - mp->m_orig_str = args->orig_rhs; + mp->m_str = (char *)args->rhs; + mp->m_orig_str = (char *)args->orig_rhs; mp->m_luaref = args->rhs_lua; if (!simplified) { args->rhs = NULL; @@ -704,7 +704,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, } else { // do we have a match? if (round) { // second round: Try unmap "rhs" string n = (int)STRLEN(mp->m_str); - p = mp->m_str; + p = (char_u *)mp->m_str; } else { n = mp->m_keylen; p = mp->m_keys; @@ -761,8 +761,8 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, XFREE_CLEAR(mp->m_str); XFREE_CLEAR(mp->m_orig_str); } - mp->m_str = args->rhs; - mp->m_orig_str = args->orig_rhs; + mp->m_str = (char *)args->rhs; + mp->m_orig_str = (char *)args->orig_rhs; mp->m_luaref = args->rhs_lua; if (!keyround1_simplified) { args->rhs = NULL; @@ -1113,7 +1113,7 @@ int map_to_exists_mode(const char *const rhs, const int mode, const bool abbr) mp = maphash[hash]; } for (; mp; mp = mp->m_next) { - if ((mp->m_mode & mode) && strstr((char *)mp->m_str, rhs) != NULL) { + if ((mp->m_mode & mode) && strstr(mp->m_str, rhs) != NULL) { return true; } } @@ -1506,7 +1506,7 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol) if (mp->m_expr) { s = eval_map_expr(mp, c); } else { - s = mp->m_str; + s = (char_u *)mp->m_str; } if (s != NULL) { // insert the to string @@ -1542,7 +1542,7 @@ char_u *eval_map_expr(mapblock_T *mp, int c) // Remove escaping of K_SPECIAL, because "str" is in a format to be used as // typeahead. if (mp->m_luaref == LUA_NOREF) { - expr = vim_strsave(mp->m_str); + expr = vim_strsave((char_u *)mp->m_str); vim_unescape_ks(expr); } @@ -1639,7 +1639,7 @@ int makemap(FILE *fd, buf_T *buf) if (mp->m_luaref != LUA_NOREF) { continue; } - for (p = mp->m_str; *p != NUL; p++) { + for (p = (char_u *)mp->m_str; *p != NUL; p++) { if (p[0] == K_SPECIAL && p[1] == KS_EXTRA && p[2] == KE_SNR) { break; @@ -1785,7 +1785,7 @@ int makemap(FILE *fd, buf_T *buf) if (putc(' ', fd) < 0 || put_escstr(fd, mp->m_keys, 0) == FAIL || putc(' ', fd) < 0 - || put_escstr(fd, mp->m_str, 1) == FAIL + || put_escstr(fd, (char_u *)mp->m_str, 1) == FAIL || put_eol(fd) < 0) { return FAIL; } @@ -1956,7 +1956,7 @@ char_u *check_map(char_u *keys, int mode, int exact, int ign_mod, int abbr, mapb *local_ptr = local; } *rhs_lua = mp->m_luaref; - return mp->m_luaref == LUA_NOREF ? mp->m_str : NULL; + return mp->m_luaref == LUA_NOREF ? (char_u *)mp->m_str : NULL; } } } diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index f9d8422481..ad8718742f 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -1932,11 +1932,11 @@ void utf_find_illegal(void) char_u *tofree = NULL; vimconv.vc_type = CONV_NONE; - if (enc_canon_props(curbuf->b_p_fenc) & ENC_8BIT) { + if (enc_canon_props((char_u *)curbuf->b_p_fenc) & ENC_8BIT) { // 'encoding' is "utf-8" but we are editing a 8-bit encoded file, // possibly a utf-8 file with illegal bytes. Setup for conversion // from utf-8 to 'fileencoding'. - convert_setup(&vimconv, p_enc, curbuf->b_p_fenc); + convert_setup(&vimconv, p_enc, (char_u *)curbuf->b_p_fenc); } curwin->w_cursor.coladd = 0; @@ -1989,8 +1989,7 @@ theend: } /// @return true if string "s" is a valid utf-8 string. -/// When "end" is NULL stop at the first NUL. -/// When "end" is positive stop there. +/// When "end" is NULL stop at the first NUL. Otherwise stop at "end". bool utf_valid_string(const char_u *s, const char_u *end) { const char_u *p = s; diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 980d6908f9..014d9a1d18 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -552,7 +552,7 @@ void check_need_swap(bool newfile) /// Close memline for buffer 'buf'. /// -/// @param del_file if TRUE, delete the swap file +/// @param del_file if true, delete the swap file void ml_close(buf_T *buf, int del_file) { if (buf->b_ml.ml_mfp == NULL) { // not open @@ -590,7 +590,7 @@ void ml_close_notmod(void) { FOR_ALL_BUFFERS(buf) { if (!bufIsChanged(buf)) { - ml_close(buf, TRUE); // close all not-modified buffers + ml_close(buf, true); // close all not-modified buffers } } } @@ -721,7 +721,7 @@ static void add_b0_fenc(ZERO_BL *b0p, buf_T *buf) b0p->b0_flags &= (uint8_t) ~B0_HAS_FENC; } else { memmove((char *)b0p->b0_fname + size - n, - (char *)buf->b_p_fenc, (size_t)n); + buf->b_p_fenc, (size_t)n); *(b0p->b0_fname + size - n - 1) = NUL; b0p->b0_flags |= B0_HAS_FENC; } @@ -764,7 +764,7 @@ void ml_recover(bool checkext) int attr; int orig_file_status = NOTDONE; - recoverymode = TRUE; + recoverymode = true; called_from_main = (curbuf->b_ml.ml_mfp == NULL); attr = HL_ATTR(HLF_E); @@ -785,7 +785,7 @@ void ml_recover(bool checkext) directly = false; // count the number of matching swap files - len = recover_names(fname, FALSE, 0, NULL); + len = recover_names(fname, false, 0, NULL); if (len == 0) { // no swap files found semsg(_("E305: No swap file found for %s"), fname); goto theend; @@ -794,16 +794,16 @@ void ml_recover(bool checkext) i = 1; } else { // several swap files found, choose // list the names of the swap files - (void)recover_names(fname, TRUE, 0, NULL); + (void)recover_names(fname, true, 0, NULL); msg_putchar('\n'); msg_puts(_("Enter number of swap file to use (0 to quit): ")); - i = get_number(FALSE, NULL); + i = get_number(false, NULL); if (i < 1 || i > len) { goto theend; } } // get the swap file name that will be used - (void)recover_names(fname, FALSE, i, &fname_used); + (void)recover_names(fname, false, i, &fname_used); } if (fname_used == NULL) { goto theend; // user chose invalid number. @@ -1201,7 +1201,7 @@ void ml_recover(bool checkext) curbuf->b_flags |= BF_RECOVERED; check_cursor(); - recoverymode = FALSE; + recoverymode = false; if (got_int) { emsg(_("E311: Recovery Interrupted")); } else if (error) { @@ -1226,7 +1226,7 @@ void ml_recover(bool checkext) theend: xfree(fname_used); - recoverymode = FALSE; + recoverymode = false; if (mfp != NULL) { if (hp != NULL) { mf_put(mfp, hp, false, false); @@ -1238,7 +1238,7 @@ theend: xfree(buf); } if (serious_error && called_from_main) { - ml_close(curbuf, TRUE); + ml_close(curbuf, true); } else { apply_autocmds(EVENT_BUFREADPOST, NULL, curbuf->b_fname, false, curbuf); apply_autocmds(EVENT_BUFWINENTER, NULL, curbuf->b_fname, false, curbuf); @@ -1255,7 +1255,7 @@ theend: /// - find the name of the n'th swap file when recovering /// /// @param fname base for swap file name -/// @param list when TRUE, list the swap file names +/// @param list when true, list the swap file names /// @param nr when non-zero, return nr'th swap file name /// @param fname_out result when "nr" > 0 int recover_names(char_u *fname, int list, int nr, char_u **fname_out) @@ -1310,7 +1310,7 @@ int recover_names(char_u *fname, int list, int nr, char_u **fname_out) names[2] = xstrdup(".sw?"); num_names = 3; } else { - num_names = recov_file_names(names, fname_res, TRUE); + num_names = recov_file_names(names, fname_res, true); } } else { // check directory dir_name if (fname == NULL) { @@ -1333,7 +1333,7 @@ int recover_names(char_u *fname, int list, int nr, char_u **fname_out) tail = (char_u *)path_tail((char *)fname_res); tail = (char_u *)concat_fnames((char *)dir_name, (char *)tail, true); } - num_names = recov_file_names(names, tail, FALSE); + num_names = recov_file_names(names, tail, false); xfree(tail); } } @@ -1447,7 +1447,7 @@ char *make_percent_swname(const char *dir, const char *name) *d = '%'; } } - d = concat_fnames(dir, s, TRUE); + d = concat_fnames(dir, s, true); xfree(s); xfree(f); } @@ -1668,8 +1668,8 @@ static int recov_file_names(char **names, char_u *path, int prepend_dot) /// sync all memlines /// -/// @param check_file if TRUE, check if original file exists and was not changed. -/// @param check_char if TRUE, stop syncing when character becomes available, but +/// @param check_file if true, check if original file exists and was not changed. +/// @param check_char if true, stop syncing when character becomes available, but /// /// always sync at least one block. void ml_sync_all(int check_file, int check_char, bool do_fsync) @@ -1714,7 +1714,7 @@ void ml_sync_all(int check_file, int check_char, bool do_fsync) /// Used for the :preserve command and when the original file has been /// changed or deleted. /// -/// @param message if TRUE, the success of preserving is reported. +/// @param message if true, the success of preserving is reported. void ml_preserve(buf_T *buf, int message, bool do_fsync) { bhdr_T *hp; @@ -1908,7 +1908,7 @@ int ml_line_alloced(void) /// "line" does not need to be allocated, but can't be another line in a /// buffer, unlocking may make it invalid. /// -/// newfile: TRUE when starting to edit a new file, meaning that pe_old_lnum +/// newfile: true when starting to edit a new file, meaning that pe_old_lnum /// will be set for recovery /// Check: The caller of this function should probably also call /// appended_lines(). @@ -1922,7 +1922,7 @@ int ml_line_alloced(void) int ml_append(linenr_T lnum, char *line, colnr_T len, bool newfile) { // When starting up, we might still need to create the memfile - if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) { + if (curbuf->b_ml.ml_mfp == NULL && open_buffer(false, NULL, 0) == FAIL) { return FAIL; } @@ -1949,7 +1949,7 @@ int ml_append_buf(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, bool new if (buf->b_ml.ml_line_lnum != 0) { ml_flush_line(buf); } - return ml_append_int(buf, lnum, line, len, newfile, FALSE); + return ml_append_int(buf, lnum, line, len, newfile, false); } /// @param lnum append after this line (can be 0) @@ -3040,7 +3040,7 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action) if (bnum != bnum2) { bnum = bnum2; pp->pb_pointer[idx].pe_bnum = bnum; - dirty = TRUE; + dirty = true; } } @@ -3058,10 +3058,10 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action) } if (action == ML_DELETE) { pp->pb_pointer[idx].pe_line_count--; - dirty = TRUE; + dirty = true; } else if (action == ML_INSERT) { pp->pb_pointer[idx].pe_line_count++; - dirty = TRUE; + dirty = true; } mf_put(mfp, hp, dirty, false); } @@ -3203,7 +3203,7 @@ int resolve_symlink(const char_u *fname, char_u *buf) * be consistent even when opening a relative symlink from different * working directories. */ - return vim_FullName((char *)tmp, (char *)buf, MAXPATHL, TRUE); + return vim_FullName((char *)tmp, (char *)buf, MAXPATHL, true); } #endif @@ -3275,7 +3275,7 @@ char_u *get_file_in_dir(char_u *fname, char_u *dname) retval = vim_strsave(fname); } else if (dname[0] == '.' && vim_ispathsep(dname[1])) { if (tail == fname) { // no path before file name - retval = (char_u *)concat_fnames((char *)dname + 2, (char *)tail, TRUE); + retval = (char_u *)concat_fnames((char *)dname + 2, (char *)tail, true); } else { save_char = *tail; *tail = NUL; @@ -3285,7 +3285,7 @@ char_u *get_file_in_dir(char_u *fname, char_u *dname) xfree(t); } } else { - retval = (char_u *)concat_fnames((char *)dname, (char *)tail, TRUE); + retval = (char_u *)concat_fnames((char *)dname, (char *)tail, true); } return retval; @@ -3455,7 +3455,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ && !buf->b_help && !(buf->b_flags & BF_DUMMY)) { int fd; struct block0 b0; - int differ = FALSE; + int differ = false; // Try to read block 0 from the swap file to get the original // file name (and inode number). @@ -3475,7 +3475,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ expand_env(b0.b0_fname, NameBuff, MAXPATHL); if (fnamecmp_ino((char_u *)buf->b_ffname, NameBuff, char_to_long(b0.b0_ino))) { - differ = TRUE; + differ = true; } } } else { @@ -3484,7 +3484,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ expand_env(b0.b0_fname, NameBuff, MAXPATHL); if (fnamecmp_ino((char_u *)buf->b_ffname, NameBuff, char_to_long(b0.b0_ino))) { - differ = TRUE; + differ = true; } } } @@ -3564,7 +3564,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ if (choice > 0) { switch (choice) { case 1: - buf->b_p_ro = TRUE; + buf->b_p_ro = true; break; case 2: break; @@ -3579,7 +3579,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ break; case 6: swap_exists_action = SEA_QUIT; - got_int = TRUE; + got_int = true; break; } @@ -3667,18 +3667,18 @@ static int b0_magic_wrong(ZERO_BL *b0p) /// /// current file doesn't exist, file for swap file exist, file name(s) not /// available -> probably different -/// == 0 != 0 FAIL X TRUE -/// == 0 != 0 X FAIL TRUE +/// == 0 != 0 FAIL X true +/// == 0 != 0 X FAIL true /// /// current file exists, inode for swap unknown, file name(s) not /// available -> probably different -/// != 0 == 0 FAIL X TRUE -/// != 0 == 0 X FAIL TRUE +/// != 0 == 0 FAIL X true +/// != 0 == 0 X FAIL true /// /// current file doesn't exist, inode for swap unknown, one file name not /// available -> probably different -/// == 0 == 0 FAIL OK TRUE -/// == 0 == 0 OK FAIL TRUE +/// == 0 == 0 FAIL OK true +/// == 0 == 0 OK FAIL true /// /// current file doesn't exist, inode for swap unknown, both file names not /// available -> compare file names @@ -3722,8 +3722,8 @@ static bool fnamecmp_ino(char_u *fname_c, char_u *fname_s, long ino_block0) * One of the inode numbers is unknown, try a forced vim_FullName() and * compare the file names. */ - retval_c = vim_FullName((char *)fname_c, (char *)buf_c, MAXPATHL, TRUE); - retval_s = vim_FullName((char *)fname_s, (char *)buf_s, MAXPATHL, TRUE); + retval_c = vim_FullName((char *)fname_c, (char *)buf_c, MAXPATHL, true); + retval_s = vim_FullName((char *)fname_s, (char *)buf_s, MAXPATHL, true); if (retval_c == OK && retval_s == OK) { return STRCMP(buf_c, buf_s) != 0; } @@ -4163,7 +4163,7 @@ void goto_byte(long cnt) curwin->w_cursor.lnum = lnum; curwin->w_cursor.col = (colnr_T)boff; curwin->w_cursor.coladd = 0; - curwin->w_set_curswant = TRUE; + curwin->w_set_curswant = true; } check_cursor(); diff --git a/src/nvim/menu.c b/src/nvim/menu.c index b7665c2d82..b1d729f71d 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -914,7 +914,7 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth) */ static vimmenu_T *expand_menu = NULL; static int expand_modes = 0x0; -static int expand_emenu; // TRUE for ":emenu" command +static int expand_emenu; // true for ":emenu" command /* * Work out what to complete when doing command line completion of menu names. @@ -1056,7 +1056,7 @@ char *get_menu_name(expand_T *xp, int idx) } else { str = menu->dname; if (menu->en_dname == NULL) { - should_advance = TRUE; + should_advance = true; } } } else { @@ -1163,10 +1163,8 @@ char *menu_name_skip(char *const name) return p; } -/* - * Return TRUE when "name" matches with menu "menu". The name is compared in - * two ways: raw menu name and menu name without '&'. ignore part after a TAB. - */ +/// Return true when "name" matches with menu "menu". The name is compared in +/// two ways: raw menu name and menu name without '&'. ignore part after a TAB. static bool menu_name_equal(const char *const name, const vimmenu_T *const menu) { if (menu->en_name != NULL @@ -1405,10 +1403,8 @@ bool menu_is_toolbar(const char *const name) return STRNCMP(name, "ToolBar", 7) == 0; } -/* - * Return TRUE if the name is a menu separator identifier: Starts and ends - * with '-' - */ +/// Return true if the name is a menu separator identifier: Starts and ends +/// with '-' int menu_is_separator(char *name) { return name[0] == '-' && name[STRLEN(name) - 1] == '-'; diff --git a/src/nvim/message.c b/src/nvim/message.c index e29bacbd17..aa5e556180 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -56,7 +56,7 @@ typedef struct msgchunk_S msgchunk_T; struct msgchunk_S { msgchunk_T *sb_next; msgchunk_T *sb_prev; - char sb_eol; // TRUE when line ends after this text + char sb_eol; // true when line ends after this text int sb_msg_col; // column in which text starts int sb_attr; // text attributes char_u sb_text[1]; // text to be displayed, actually longer @@ -66,7 +66,7 @@ struct msgchunk_S { #define DLG_BUTTON_SEP '\n' #define DLG_HOTKEY_CHAR '&' -static int confirm_msg_used = FALSE; // displaying confirm_msg +static int confirm_msg_used = false; // displaying confirm_msg #ifdef INCLUDE_GENERATED_DECLARATIONS # include "message.c.generated.h" #endif @@ -78,7 +78,7 @@ MessageHistoryEntry *last_msg_hist = NULL; static int msg_hist_len = 0; static FILE *verbose_fd = NULL; -static int verbose_did_open = FALSE; +static int verbose_did_open = false; bool keep_msg_more = false; // keep_msg was set by msgmore() @@ -102,7 +102,7 @@ bool keep_msg_more = false; // keep_msg was set by msgmore() * msg_scrolled How many lines the screen has been scrolled (because of * messages). Used in update_screen() to scroll the screen * back. Incremented each time the screen scrolls a line. - * msg_scrolled_ign TRUE when msg_scrolled is non-zero and msg_puts_attr() + * msg_scrolled_ign true when msg_scrolled is non-zero and msg_puts_attr() * writes something without scrolling should not make * need_wait_return to be set. This is a hack to make ":ts" * work without an extra prompt. @@ -215,7 +215,7 @@ void msg_grid_validate(void) /// Displays the string 's' on the status line /// When terminal not initialized (yet) mch_errmsg(..) is used. /// -/// @return TRUE if wait_return not called +/// @return true if wait_return not called int msg(char *s) { return msg_attr_keep(s, 0, false, false); @@ -319,7 +319,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) * break this loop, limit the recursiveness to 3 levels. */ if (entered >= 3) { - return TRUE; + return true; } entered++; @@ -335,7 +335,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) // Truncate the message if needed. msg_start(); - buf = msg_strtrunc((char_u *)s, FALSE); + buf = msg_strtrunc((char_u *)s, false); if (buf != NULL) { s = (const char *)buf; } @@ -634,7 +634,7 @@ void msg_source(int attr) recursive = false; } -/// @return TRUE if not giving error messages right now: +/// @return true if not giving error messages right now: /// If "emsg_off" is set: no error messages at the moment. /// If "msg" is in 'debug': do error message but without side effects. /// If "emsg_skip" is set: never do error messages. @@ -643,9 +643,9 @@ int emsg_not_now(void) if ((emsg_off > 0 && vim_strchr((char *)p_debug, 'm') == NULL && vim_strchr((char *)p_debug, 't') == NULL) || emsg_skip > 0) { - return TRUE; + return true; } - return FALSE; + return false; } static bool emsg_multiline(const char *s, bool multiline) @@ -1177,12 +1177,12 @@ void wait_return(int redraw) oldState = State; if (quit_more) { c = CAR; // just pretend CR was hit - quit_more = FALSE; - got_int = FALSE; + quit_more = false; + got_int = false; } else if (exmode_active) { msg_puts(" "); // make sure the cursor is on the right line c = CAR; // no need for a return in ex mode - got_int = FALSE; + got_int = false; } else { // Make sure the hit-return prompt is on screen when 'guioptions' was // just changed. @@ -1247,8 +1247,8 @@ void wait_return(int redraw) } if (quit_more) { c = CAR; // just pretend CR was hit - quit_more = FALSE; - got_int = FALSE; + quit_more = false; + got_int = false; } else if (c != K_IGNORE) { c = K_IGNORE; hit_return_msg(); @@ -1653,7 +1653,7 @@ void msg_make(char_u *arg) /// If K_SPECIAL is encountered, then it is taken in conjunction with the /// following character and shown as <F1>, <S-Up> etc. Any other character /// which is not printable shown in <> form. -/// If 'from' is TRUE (lhs of a mapping), a space is shown as <Space>. +/// If 'from' is true (lhs of a mapping), a space is shown as <Space>. /// If a character is displayed in one of these special ways, is also /// highlighted (its highlight name is '8' in the p_hl variable). /// Otherwise characters are not highlighted. @@ -2557,7 +2557,7 @@ static void store_sb_text(char **sb_str, char *s, int attr, int *sb_col, int fin } mp->sb_next = NULL; } else if (finish && last_msgchunk != NULL) { - last_msgchunk->sb_eol = TRUE; + last_msgchunk->sb_eol = true; } *sb_str = s; @@ -2614,7 +2614,7 @@ void sb_text_end_cmdline(void) } /// Clear any text remembered for scrolling back. -/// When "all" is FALSE keep the last line. +/// When "all" is false keep the last line. /// Called when redrawing the screen. void clear_sb_text(int all) { @@ -2649,7 +2649,7 @@ void show_sb_text(void) vim_beep(BO_MESS); } else { do_more_prompt('G'); - wait_return(FALSE); + wait_return(false); } } @@ -2668,7 +2668,7 @@ static msgchunk_T *msg_sb_start(msgchunk_T *mps) void msg_sb_eol(void) { if (last_msgchunk != NULL) { - last_msgchunk->sb_eol = TRUE; + last_msgchunk->sb_eol = true; } } @@ -2687,7 +2687,7 @@ static msgchunk_T *disp_sb_line(int row, msgchunk_T *smp) if (*p == '\n') { // don't display the line break p++; } - msg_puts_display(p, -1, mp->sb_attr, TRUE); + msg_puts_display(p, -1, mp->sb_attr, true); if (mp->sb_eol || mp->sb_next == NULL) { break; } @@ -2718,7 +2718,7 @@ static void t_puts(int *t_col, const char_u *t_s, const char_u *s, int attr) } } -/// @return TRUE when messages should be printed to stdout/stderr: +/// @return true when messages should be printed to stdout/stderr: /// - "batch mode" ("silent mode", -es/-Es) /// - no UI and not embedded int msg_use_printf(void) @@ -2786,14 +2786,14 @@ static void msg_puts_printf(const char *str, const ptrdiff_t maxlen) /// When at hit-enter prompt "typed_char" is the already typed character, /// otherwise it's NUL. /// -/// @return TRUE when jumping ahead to "confirm_msg_tail". +/// @return true when jumping ahead to "confirm_msg_tail". static int do_more_prompt(int typed_char) { static bool entered = false; int used_typed_char = typed_char; int oldState = State; int c; - int retval = FALSE; + int retval = false; int toscroll; bool to_redraw = false; msgchunk_T *mp_last = NULL; @@ -2825,7 +2825,7 @@ static int do_more_prompt(int typed_char) State = MODE_ASKMORE; setmouse(); if (typed_char == NUL) { - msg_moremsg(FALSE); + msg_moremsg(false); } for (;;) { /* @@ -2898,10 +2898,10 @@ static int do_more_prompt(int typed_char) case ESC: if (confirm_msg_used) { // Jump to the choices of the dialog. - retval = TRUE; + retval = true; } else { - got_int = TRUE; - quit_more = TRUE; + got_int = true; + quit_more = true; } // When there is some more output (wrapping line) display that // without another prompt. @@ -2917,7 +2917,7 @@ static int do_more_prompt(int typed_char) break; default: // no valid response - msg_moremsg(TRUE); + msg_moremsg(true); continue; } @@ -3168,7 +3168,7 @@ void msg_clr_cmdline(void) /// end putting a message on the screen /// call wait_return if the message does not fit in the available space /// -/// @return TRUE if wait_return not called. +/// @return true if wait_return not called. int msg_end(void) { /* @@ -3391,7 +3391,7 @@ void verbose_enter_scroll(void) msg_silent++; } else { // always scroll up, don't overwrite - msg_scroll = TRUE; + msg_scroll = true; } } @@ -3414,7 +3414,7 @@ void verbose_stop(void) fclose(verbose_fd); verbose_fd = NULL; } - verbose_did_open = FALSE; + verbose_did_open = false; } /// Open the file 'verbosefile'. @@ -3424,7 +3424,7 @@ int verbose_open(void) { if (verbose_fd == NULL && !verbose_did_open) { // Only give the error message once. - verbose_did_open = TRUE; + verbose_did_open = true; verbose_fd = os_fopen((char *)p_vfile, "a"); if (verbose_fd == NULL) { @@ -3523,7 +3523,7 @@ void msg_advance(int col) /// different letter. /// /// @param textfiel IObuff for inputdialog(), NULL otherwise -/// @param ex_cmd when TRUE pressing : accepts default and starts Ex command +/// @param ex_cmd when true pressing : accepts default and starts Ex command /// @returns 0 if cancelled, otherwise the nth button (1-indexed). int do_dialog(int type, char_u *title, char_u *message, char_u *buttons, int dfltbutton, char_u *textfield, int ex_cmd) @@ -3799,7 +3799,7 @@ int vim_dialog_yesno(int type, char_u *title, char_u *message, int dflt) if (do_dialog(type, title == NULL ? (char_u *)_("Question") : title, message, - (char_u *)_("&Yes\n&No"), dflt, NULL, FALSE) == 1) { + (char_u *)_("&Yes\n&No"), dflt, NULL, false) == 1) { return VIM_YES; } return VIM_NO; @@ -3810,7 +3810,7 @@ int vim_dialog_yesnocancel(int type, char_u *title, char_u *message, int dflt) switch (do_dialog(type, title == NULL ? (char_u *)_("Question") : title, message, - (char_u *)_("&Yes\n&No\n&Cancel"), dflt, NULL, FALSE)) { + (char_u *)_("&Yes\n&No\n&Cancel"), dflt, NULL, false)) { case 1: return VIM_YES; case 2: @@ -3825,7 +3825,7 @@ int vim_dialog_yesnoallcancel(int type, char_u *title, char_u *message, int dflt title == NULL ? (char_u *)"Question" : title, message, (char_u *)_("&Yes\n&No\nSave &All\n&Discard All\n&Cancel"), - dflt, NULL, FALSE)) { + dflt, NULL, false)) { case 1: return VIM_YES; case 2: diff --git a/src/nvim/mouse.h b/src/nvim/mouse.h index 08261e4a30..21ff56bbbc 100644 --- a/src/nvim/mouse.h +++ b/src/nvim/mouse.h @@ -36,7 +36,7 @@ #define MOUSE_X2 0x400 // Mouse-button X2 // Direction for nv_mousescroll() and ins_mousescroll() -#define MSCR_DOWN 0 // DOWN must be FALSE +#define MSCR_DOWN 0 // DOWN must be false #define MSCR_UP 1 #define MSCR_LEFT (-1) #define MSCR_RIGHT (-2) diff --git a/src/nvim/msgpack_rpc/server.c b/src/nvim/msgpack_rpc/server.c index b252f0998e..532e684f93 100644 --- a/src/nvim/msgpack_rpc/server.c +++ b/src/nvim/msgpack_rpc/server.c @@ -216,7 +216,7 @@ bool server_stop(char *endpoint) watchers.ga_len--; // Bump v:servername to the next available server, if any. - if (strequal(addr, (char *)get_vim_var_str(VV_SEND_SERVER))) { + if (strequal(addr, get_vim_var_str(VV_SEND_SERVER))) { set_vservername(&watchers); } diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 75900b735b..1bd780be0f 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -2653,10 +2653,10 @@ void clear_showcmd(void) if (VIsual_mode == Ctrl_V) { char_u *const saved_sbr = p_sbr; - char_u *const saved_w_sbr = curwin->w_p_sbr; + char *const saved_w_sbr = curwin->w_p_sbr; // Make 'sbr' empty for a moment to get the correct size. - p_sbr = empty_option; + p_sbr = (char_u *)empty_option; curwin->w_p_sbr = empty_option; getvcols(curwin, &curwin->w_cursor, &VIsual, &leftcol, &rightcol); p_sbr = saved_sbr; @@ -4275,7 +4275,7 @@ static void nv_ident(cmdarg_T *cap) // Allocate buffer to put the command in. Inserting backslashes can // double the length of the word. p_kp / curbuf->b_p_kp could be added // and some numbers. - char_u *kp = *curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp; // 'keywordprg' + char_u *kp = *curbuf->b_p_kp == NUL ? p_kp : (char_u *)curbuf->b_p_kp; // 'keywordprg' assert(*kp != NUL); // option.c:do_set() should default to ":help" if empty. bool kp_ex = (*kp == ':'); // 'keywordprg' is an ex command bool kp_help = (STRCMP(kp, ":he") == 0 || STRCMP(kp, ":help") == 0); @@ -7075,8 +7075,8 @@ static void nv_object(cmdarg_T *cap) include = true; // "ax" = an object: include white space } // Make sure (), [], {} and <> are in 'matchpairs' - mps_save = curbuf->b_p_mps; - curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; + mps_save = (char_u *)curbuf->b_p_mps; + curbuf->b_p_mps = "(:),{:},[:],<:>"; switch (cap->nchar) { case 'w': // "aw" = a word @@ -7130,7 +7130,7 @@ static void nv_object(cmdarg_T *cap) break; } - curbuf->b_p_mps = mps_save; + curbuf->b_p_mps = (char *)mps_save; if (!flag) { clearopbeep(cap->oap); } diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 1f6b154eed..a1f4149715 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -78,9 +78,9 @@ struct block_def { colnr_T textcol; // index of chars (partially) in block colnr_T start_vcol; // start col of 1st char wholly inside block colnr_T end_vcol; // start col of 1st char wholly after block - int is_short; // TRUE if line is too short to fit in block - int is_MAX; // TRUE if curswant==MAXCOL when starting - int is_oneChar; // TRUE if block within one character + int is_short; // true if line is too short to fit in block + int is_MAX; // true if curswant==MAXCOL when starting + int is_oneChar; // true if block within one character int pre_whitesp; // screen cols of ws before block int pre_whitesp_c; // chars of ws before block colnr_T end_char_vcols; // number of vcols of post-block char @@ -181,13 +181,13 @@ int get_op_type(int char1, int char2) return i; } -/// @return TRUE if operator "op" always works on whole lines. +/// @return true if operator "op" always works on whole lines. int op_on_lines(int op) { return opchars[op][2] & OPF_LINES; } -/// @return TRUE if operator "op" changes text. +/// @return true if operator "op" changes text. int op_is_change(int op) { return opchars[op][2] & OPF_CHANGE; @@ -2090,7 +2090,7 @@ void op_tilde(oparg_T *oap) { pos_T pos; struct block_def bd; - int did_change = FALSE; + int did_change = false; if (u_save((linenr_T)(oap->start.lnum - 1), (linenr_T)(oap->end.lnum + 1)) == FAIL) { @@ -2165,7 +2165,7 @@ void op_tilde(oparg_T *oap) /// @param length is rounded up to include the whole last multi-byte character. /// Also works correctly when the number of bytes changes. /// -/// @return TRUE if some character was changed. +/// @return true if some character was changed. static int swapchars(int op_type, pos_T *pos, int length) FUNC_ATTR_NONNULL_ALL { @@ -2303,7 +2303,7 @@ void op_insert(oparg_T *oap, long count1) if (oap->motion_type == kMTBlockWise && curwin->w_cursor.coladd == 0) { // Move the cursor to the character right of the block. - curwin->w_set_curswant = TRUE; + curwin->w_set_curswant = true; while (*get_cursor_pos_ptr() != NUL && (curwin->w_cursor.col < bd.textcol + bd.textlen)) { curwin->w_cursor.col++; @@ -2463,7 +2463,7 @@ void op_insert(oparg_T *oap, long count1) /// handle a change operation /// -/// @return TRUE if edit() returns because of a CTRL-O command +/// @return true if edit() returns because of a CTRL-O command int op_change(oparg_T *oap) { colnr_T l; @@ -2489,10 +2489,10 @@ int op_change(oparg_T *oap) // save for undo if (curbuf->b_ml.ml_flags & ML_EMPTY) { if (u_save_cursor() == FAIL) { - return FALSE; + return false; } } else if (op_delete(oap) == FAIL) { - return FALSE; + return false; } if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum) @@ -2518,7 +2518,7 @@ int op_change(oparg_T *oap) fix_indent(); } - retval = edit(NUL, FALSE, (linenr_T)1); + retval = edit(NUL, false, (linenr_T)1); /* * In Visual block mode, handle copying the new text to all lines of the @@ -3708,7 +3708,7 @@ error: } msgmore(nr_lines); - curwin->w_set_curswant = TRUE; + curwin->w_set_curswant = true; end: if (cmdmod.cmod_flags & CMOD_LOCKMARKS) { @@ -3722,7 +3722,7 @@ end: xfree(y_array); } - VIsual_active = FALSE; + VIsual_active = false; // If the cursor is past the end of the line put it at the end. adjust_cursor_eol(); @@ -3751,7 +3751,7 @@ void adjust_cursor_eol(void) } } -/// @return TRUE if lines starting with '#' should be left aligned. +/// @return true if lines starting with '#' should be left aligned. int preprocs_left(void) { return ((curbuf->b_p_si && !curbuf->b_p_cin) @@ -4011,8 +4011,8 @@ char_u *skip_comment(char_u *line, bool process, bool include_space, bool *is_co } /// @param count number of lines (minimal 2) to join at cursor position. -/// @param save_undo when TRUE, save lines for undo first. -/// @param use_formatoptions set to FALSE when e.g. processing backspace and comment +/// @param save_undo when true, save lines for undo first. +/// @param use_formatoptions set to false when e.g. processing backspace and comment /// leaders should not be removed. /// @param setmark when true, sets the '[ and '] mark, else, the caller is expected /// to set those marks. @@ -4033,7 +4033,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions colnr_T col = 0; int ret = OK; int *comments = NULL; - int remove_comments = (use_formatoptions == TRUE) + int remove_comments = (use_formatoptions == true) && has_format_option(FO_REMOVE_COMS); bool prev_was_comment = false; assert(count >= 1); @@ -4208,7 +4208,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions check_cursor_col(); curwin->w_cursor.coladd = 0; - curwin->w_set_curswant = TRUE; + curwin->w_set_curswant = true; theend: xfree(spaces); @@ -4218,7 +4218,7 @@ theend: return ret; } -/// @return TRUE if the two comment leaders given are the same. +/// @return true if the two comment leaders given are the same. /// /// @param lnum The first line. White-space is ignored. /// @@ -4248,21 +4248,21 @@ static int same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, in return leader2_len == 0; } if (*p == COM_END) { - return FALSE; + return false; } if (*p == COM_START) { if (*(ml_get(lnum) + leader1_len) == NUL) { - return FALSE; + return false; } if (leader2_flags == NULL || leader2_len == 0) { - return FALSE; + return false; } for (p = leader2_flags; *p && *p != ':'; p++) { if (*p == COM_MIDDLE) { - return TRUE; + return true; } } - return FALSE; + return false; } } } @@ -4385,23 +4385,20 @@ int fex_format(linenr_T lnum, long count, int c) { int use_sandbox = was_set_insecurely(curwin, "formatexpr", OPT_LOCAL); int r; - char_u *fex; - /* - * Set v:lnum to the first line number and v:count to the number of lines. - * Set v:char to the character to be inserted (can be NUL). - */ + // Set v:lnum to the first line number and v:count to the number of lines. + // Set v:char to the character to be inserted (can be NUL). set_vim_var_nr(VV_LNUM, (varnumber_T)lnum); set_vim_var_nr(VV_COUNT, (varnumber_T)count); set_vim_var_char(c); // Make a copy, the option could be changed while calling it. - fex = vim_strsave(curbuf->b_p_fex); + char *fex = xstrdup(curbuf->b_p_fex); // Evaluate the function. if (use_sandbox) { sandbox++; } - r = (int)eval_to_number((char *)fex); + r = (int)eval_to_number(fex); if (use_sandbox) { sandbox--; } @@ -4591,7 +4588,7 @@ void format_lines(linenr_T line_count, int avoid_fex) // do the formatting, without 'showmode' State = MODE_INSERT; // for open_line() smd_save = p_smd; - p_smd = FALSE; + p_smd = false; insertchar(NUL, INSCHAR_FORMAT + (do_comments ? INSCHAR_DO_COM : 0) + (do_comments && do_comments_list @@ -4638,7 +4635,7 @@ void format_lines(linenr_T line_count, int avoid_fex) } } curwin->w_cursor.lnum--; - if (do_join(2, TRUE, FALSE, FALSE, false) == FAIL) { + if (do_join(2, true, false, false, false) == FAIL) { beep_flush(); break; } @@ -4655,22 +4652,22 @@ void format_lines(linenr_T line_count, int avoid_fex) } } -/// @return TRUE if line "lnum" ends in a white character. +/// @return true if line "lnum" ends in a white character. static int ends_in_white(linenr_T lnum) { char_u *s = ml_get(lnum); size_t l; if (*s == NUL) { - return FALSE; + return false; } l = STRLEN(s) - 1; return ascii_iswhite(s[l]); } /// Blank lines, and lines containing only the comment leader, are left -/// untouched by the formatting. The function returns TRUE in this -/// case. It also returns TRUE when a line starts with the end of a comment +/// untouched by the formatting. The function returns true in this +/// case. It also returns true when a line starts with the end of a comment /// ('e' in comment flags), so that this line is skipped, and not joined to the /// previous line. A new paragraph starts after a blank line, or when the /// comment leader changes. @@ -4698,13 +4695,13 @@ static int fmt_check_par(linenr_T lnum, int *leader_len, char_u **leader_flags, return *skipwhite((char *)ptr + *leader_len) == NUL || (*leader_len > 0 && *flags == COM_END) - || startPS(lnum, NUL, FALSE); + || startPS(lnum, NUL, false); } /// Used for auto-formatting. /// -/// @return TRUE when a paragraph starts in line "lnum". -/// FALSE when the previous line is in the same paragraph. +/// @return true when a paragraph starts in line "lnum". +/// false when the previous line is in the same paragraph. int paragraph_start(linenr_T lnum) { char_u *p; @@ -4714,11 +4711,11 @@ int paragraph_start(linenr_T lnum) char_u *next_leader_flags = NULL; // flags for leader of next line if (lnum <= 1) { - return TRUE; // start of the file + return true; // start of the file } p = ml_get(lnum - 1); if (*p == NUL) { - return TRUE; // after empty line + return true; // after empty line } const bool do_comments = has_format_option(FO_Q_COMS); // format comments if (fmt_check_par(lnum - 1, &leader_len, &leader_flags, do_comments)) { @@ -4730,16 +4727,16 @@ int paragraph_start(linenr_T lnum) } if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) { - return TRUE; // missing trailing space in previous line. + return true; // missing trailing space in previous line. } if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) { - return TRUE; // numbered item starts in "lnum". + return true; // numbered item starts in "lnum". } if (!same_leader(lnum - 1, leader_len, leader_flags, next_leader_len, next_leader_flags)) { - return TRUE; // change of comment leader. + return true; // change of comment leader. } - return FALSE; + return false; } /// prepare a few things for block mode yank/delete/tilde @@ -5008,12 +5005,12 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) pos_T endpos; colnr_T save_coladd = 0; - const bool do_hex = vim_strchr((char *)curbuf->b_p_nf, 'x') != NULL; // "heX" - const bool do_oct = vim_strchr((char *)curbuf->b_p_nf, 'o') != NULL; // "Octal" - const bool do_bin = vim_strchr((char *)curbuf->b_p_nf, 'b') != NULL; // "Bin" - const bool do_alpha = vim_strchr((char *)curbuf->b_p_nf, 'p') != NULL; // "alPha" + const bool do_hex = vim_strchr(curbuf->b_p_nf, 'x') != NULL; // "heX" + const bool do_oct = vim_strchr(curbuf->b_p_nf, 'o') != NULL; // "Octal" + const bool do_bin = vim_strchr(curbuf->b_p_nf, 'b') != NULL; // "Bin" + const bool do_alpha = vim_strchr(curbuf->b_p_nf, 'p') != NULL; // "alPha" // "Unsigned" - const bool do_unsigned = vim_strchr((char *)curbuf->b_p_nf, 'u') != NULL; + const bool do_unsigned = vim_strchr(curbuf->b_p_nf, 'u') != NULL; if (virtual_active()) { save_coladd = pos->coladd; @@ -5609,7 +5606,7 @@ void write_reg_contents_ex(int name, const char_u *str, ssize_t len, bool must_a // Special case: '/' search pattern if (name == '/') { - set_last_search_pat(str, RE_SEARCH, TRUE, TRUE); + set_last_search_pat(str, RE_SEARCH, true, true); return; } @@ -5886,10 +5883,10 @@ void cursor_pos_info(dict_T *dict) if (l_VIsual_mode == Ctrl_V) { char_u *const saved_sbr = p_sbr; - char_u *const saved_w_sbr = curwin->w_p_sbr; + char *const saved_w_sbr = curwin->w_p_sbr; // Make 'sbr' empty for a moment to get the correct size. - p_sbr = empty_option; + p_sbr = (char_u *)empty_option; curwin->w_p_sbr = empty_option; oparg.is_VIsual = true; oparg.motion_type = kMTBlockWise; diff --git a/src/nvim/option.c b/src/nvim/option.c index b1d5be8cb7..3f7c200928 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -30,6 +30,7 @@ #include "nvim/arglist.h" #include "nvim/ascii.h" #include "nvim/buffer.h" +#include "nvim/change.h" #include "nvim/charset.h" #include "nvim/cursor_shape.h" #include "nvim/decoration_provider.h" @@ -71,6 +72,7 @@ #include "nvim/popupmenu.h" #include "nvim/regexp.h" #include "nvim/screen.h" +#include "nvim/search.h" #include "nvim/spell.h" #include "nvim/spellfile.h" #include "nvim/spellsuggest.h" @@ -464,7 +466,7 @@ static void set_option_default(int opt_idx, int opt_flags) (char *)options[opt_idx].def_val, opt_flags, 0); } else { if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) { - free_string_option(*(char_u **)(varp)); + free_string_option(*(char **)(varp)); } *(char_u **)varp = options[opt_idx].def_val; options[opt_idx].flags &= ~P_ALLOCED; @@ -603,14 +605,14 @@ void free_all_options(void) if (options[i].indir == PV_NONE) { // global option: free value and default value. if ((options[i].flags & P_ALLOCED) && options[i].var != NULL) { - free_string_option(*(char_u **)options[i].var); + free_string_option(*(char **)options[i].var); } if (options[i].flags & P_DEF_ALLOCED) { - free_string_option(options[i].def_val); + free_string_option((char *)options[i].def_val); } } else if (options[i].var != VAR_WIN && (options[i].flags & P_STRING)) { // buffer-local option: free global value - clear_string_option((char_u **)options[i].var); + clear_string_option((char **)options[i].var); } } free_operatorfunc_option(); @@ -730,7 +732,7 @@ void set_helplang_default(const char *lang) int idx = findoption("hlg"); if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) { if (options[idx].flags & P_ALLOCED) { - free_string_option(p_hlg); + free_string_option((char *)p_hlg); } p_hlg = (char_u *)xmemdupz(lang, lang_len); // zh_CN becomes "cn", zh_TW becomes "tw". @@ -1185,7 +1187,7 @@ int do_set(char *arg, int opt_flags) // A global-local string option might have an empty // option as value to indicate that the global // value should be used. - if (((int)options[opt_idx].indir & PV_BOTH) && origval_l == empty_option) { + if (((int)options[opt_idx].indir & PV_BOTH) && origval_l == (char_u *)empty_option) { origval_l = origval_g; } } @@ -1205,7 +1207,7 @@ int do_set(char *arg, int opt_flags) // required when an environment variable was set // later if (newval == NULL) { - newval = empty_option; + newval = (char_u *)empty_option; } else if (!(options[opt_idx].flags & P_NO_DEF_EXP)) { s = option_expand(opt_idx, newval); if (s == NULL) { @@ -1233,7 +1235,7 @@ int do_set(char *arg, int opt_flags) i = getdigits_int((char **)varp, true, 0); switch (i) { case 0: - *(char_u **)varp = empty_option; + *(char **)varp = empty_option; break; case 1: *(char_u **)varp = vim_strsave((char_u *)"indent,eol"); @@ -1600,7 +1602,7 @@ void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked /// Convert a key name or string into a key value. /// Used for 'wildchar' and 'cedit' options. -static int string_to_key(char_u *arg) +int string_to_key(char_u *arg) { if (*arg == '<') { return find_key_option(arg + 1, true); @@ -1611,24 +1613,6 @@ static int string_to_key(char_u *arg) return *arg; } -/// Check value of 'cedit' and set cedit_key. -/// Returns NULL if value is OK, error message otherwise. -char *check_cedit(void) -{ - int n; - - if (*p_cedit == NUL) { - cedit_key = -1; - } else { - n = string_to_key(p_cedit); - if (vim_isprintc(n)) { - return e_invarg; - } - cedit_key = n; - } - return NULL; -} - // When changing 'title', 'titlestring', 'icon' or 'iconstring', call // maketitle() to create and display it. // When switching the title or icon off, call ui_set_{icon,title}(NULL) to get @@ -1797,17 +1781,17 @@ static void didset_options2(void) highlight_changed(); // Parse default for 'fillchars'. - (void)set_chars_option(curwin, &curwin->w_p_fcs, true); + (void)set_chars_option(curwin, (char_u **)&curwin->w_p_fcs, true); // Parse default for 'listchars'. - (void)set_chars_option(curwin, &curwin->w_p_lcs, true); + (void)set_chars_option(curwin, (char_u **)&curwin->w_p_lcs, true); // Parse default for 'wildmode'. check_opt_wim(); xfree(curbuf->b_p_vsts_array); - (void)tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array); + (void)tabstop_set((char_u *)curbuf->b_p_vsts, &curbuf->b_p_vsts_array); xfree(curbuf->b_p_vts_array); - (void)tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array); + (void)tabstop_set((char_u *)curbuf->b_p_vts, &curbuf->b_p_vts_array); } /// Check for string options that are NULL (normally only termcap options). @@ -1817,7 +1801,7 @@ void check_options(void) for (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_u **)get_varp(&(options[opt_idx]))); + check_string_option((char **)get_varp(&(options[opt_idx]))); } } } @@ -3597,12 +3581,12 @@ int makeset(FILE *fd, int opt_flags, int local_only) /// 'sessionoptions' or 'viewoptions' contains "folds" but not "options". int makefoldset(FILE *fd) { - if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL - || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0) + if (put_setstring(fd, "setlocal", "fdm", (char_u **)&curwin->w_p_fdm, 0) == FAIL + || put_setstring(fd, "setlocal", "fde", (char_u **)&curwin->w_p_fde, 0) == FAIL - || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0) + || put_setstring(fd, "setlocal", "fmr", (char_u **)&curwin->w_p_fmr, 0) == FAIL - || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0) + || put_setstring(fd, "setlocal", "fdi", (char_u **)&curwin->w_p_fdi, 0) == FAIL || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL @@ -3803,7 +3787,7 @@ void unset_global_local_option(char *name, void *from) clear_string_option(&((win_T *)from)->w_p_stl); break; case PV_WBR: - clear_string_option((char_u **)&((win_T *)from)->w_p_wbr); + clear_string_option(&((win_T *)from)->w_p_wbr); break; case PV_UL: buf->b_p_ul = NO_LOCAL_UNDOLEVEL; @@ -3816,12 +3800,12 @@ void unset_global_local_option(char *name, void *from) break; case PV_LCS: clear_string_option(&((win_T *)from)->w_p_lcs); - set_chars_option((win_T *)from, &((win_T *)from)->w_p_lcs, true); + set_chars_option((win_T *)from, (char_u **)&((win_T *)from)->w_p_lcs, true); redraw_later((win_T *)from, UPD_NOT_VALID); break; case PV_FCS: clear_string_option(&((win_T *)from)->w_p_fcs); - set_chars_option((win_T *)from, &((win_T *)from)->w_p_fcs, true); + set_chars_option((win_T *)from, (char_u **)&((win_T *)from)->w_p_fcs, true); redraw_later((win_T *)from, UPD_NOT_VALID); break; case PV_VE: @@ -4238,7 +4222,7 @@ char_u *get_equalprg(void) if (*curbuf->b_p_ep == NUL) { return p_ep; } - return curbuf->b_p_ep; + return (char_u *)curbuf->b_p_ep; } /// Copy options from one window to another. @@ -4250,6 +4234,14 @@ void win_copy_options(win_T *wp_from, win_T *wp_to) didset_window_options(wp_to, true); } +static char *copy_option_val(const char *val) +{ + if (val == empty_option) { + return empty_option; // no need to allocate memory + } + return xstrdup(val); +} + /// Copy the options from one winopt_T to another. /// Doesn't free the old option values in "to", use clear_winopt() for that. /// The 'scroll' option is not copied, because it depends on the window height. @@ -4258,21 +4250,23 @@ void copy_winopt(winopt_T *from, winopt_T *to) { to->wo_arab = from->wo_arab; to->wo_list = from->wo_list; + to->wo_lcs = copy_option_val(from->wo_lcs); + to->wo_fcs = copy_option_val(from->wo_fcs); to->wo_nu = from->wo_nu; to->wo_rnu = from->wo_rnu; - to->wo_ve = vim_strsave(from->wo_ve); + to->wo_ve = copy_option_val(from->wo_ve); to->wo_ve_flags = from->wo_ve_flags; to->wo_nuw = from->wo_nuw; to->wo_rl = from->wo_rl; - to->wo_rlc = vim_strsave(from->wo_rlc); - to->wo_sbr = vim_strsave(from->wo_sbr); - to->wo_stl = vim_strsave(from->wo_stl); - to->wo_wbr = xstrdup(from->wo_wbr); + to->wo_rlc = copy_option_val(from->wo_rlc); + to->wo_sbr = copy_option_val(from->wo_sbr); + to->wo_stl = copy_option_val(from->wo_stl); + to->wo_wbr = copy_option_val(from->wo_wbr); to->wo_wrap = from->wo_wrap; to->wo_wrap_save = from->wo_wrap_save; to->wo_lbr = from->wo_lbr; to->wo_bri = from->wo_bri; - to->wo_briopt = vim_strsave(from->wo_briopt); + to->wo_briopt = copy_option_val(from->wo_briopt); to->wo_scb = from->wo_scb; to->wo_scb_save = from->wo_scb_save; to->wo_crb = from->wo_crb; @@ -4280,32 +4274,28 @@ void copy_winopt(winopt_T *from, winopt_T *to) to->wo_spell = from->wo_spell; to->wo_cuc = from->wo_cuc; to->wo_cul = from->wo_cul; - to->wo_culopt = vim_strsave(from->wo_culopt); - to->wo_cc = vim_strsave(from->wo_cc); + to->wo_culopt = copy_option_val(from->wo_culopt); + to->wo_cc = copy_option_val(from->wo_cc); to->wo_diff = from->wo_diff; to->wo_diff_saved = from->wo_diff_saved; - to->wo_cocu = vim_strsave(from->wo_cocu); + to->wo_cocu = copy_option_val(from->wo_cocu); to->wo_cole = from->wo_cole; - to->wo_fdc = vim_strsave(from->wo_fdc); - to->wo_fdc_save = from->wo_diff_saved - ? vim_strsave(from->wo_fdc_save) : empty_option; + to->wo_fdc = copy_option_val(from->wo_fdc); + to->wo_fdc_save = from->wo_diff_saved ? xstrdup(from->wo_fdc_save) : empty_option; to->wo_fen = from->wo_fen; to->wo_fen_save = from->wo_fen_save; - to->wo_fdi = vim_strsave(from->wo_fdi); + to->wo_fdi = copy_option_val(from->wo_fdi); to->wo_fml = from->wo_fml; to->wo_fdl = from->wo_fdl; to->wo_fdl_save = from->wo_fdl_save; - to->wo_fdm = vim_strsave(from->wo_fdm); - to->wo_fdm_save = from->wo_diff_saved - ? vim_strsave(from->wo_fdm_save) : empty_option; + to->wo_fdm = copy_option_val(from->wo_fdm); + to->wo_fdm_save = from->wo_diff_saved ? xstrdup(from->wo_fdm_save) : empty_option; to->wo_fdn = from->wo_fdn; - to->wo_fde = vim_strsave(from->wo_fde); - to->wo_fdt = vim_strsave(from->wo_fdt); - to->wo_fmr = vim_strsave(from->wo_fmr); - to->wo_scl = vim_strsave(from->wo_scl); - to->wo_winhl = vim_strsave(from->wo_winhl); - to->wo_fcs = vim_strsave(from->wo_fcs); - to->wo_lcs = vim_strsave(from->wo_lcs); + to->wo_fde = copy_option_val(from->wo_fde); + to->wo_fdt = copy_option_val(from->wo_fdt); + to->wo_fmr = copy_option_val(from->wo_fmr); + to->wo_scl = copy_option_val(from->wo_scl); + to->wo_winhl = copy_option_val(from->wo_winhl); to->wo_winbl = from->wo_winbl; // Copy the script context so that we know were the value was last set. @@ -4340,10 +4330,10 @@ static void check_winopt(winopt_T *wop) check_string_option(&wop->wo_cocu); check_string_option(&wop->wo_briopt); check_string_option(&wop->wo_winhl); - check_string_option(&wop->wo_fcs); check_string_option(&wop->wo_lcs); + check_string_option(&wop->wo_fcs); check_string_option(&wop->wo_ve); - check_string_option((char_u **)&wop->wo_wbr); + check_string_option(&wop->wo_wbr); } /// Free the allocated memory inside a winopt_T. @@ -4366,10 +4356,10 @@ void clear_winopt(winopt_T *wop) clear_string_option(&wop->wo_cocu); clear_string_option(&wop->wo_briopt); clear_string_option(&wop->wo_winhl); - clear_string_option(&wop->wo_fcs); clear_string_option(&wop->wo_lcs); + clear_string_option(&wop->wo_fcs); clear_string_option(&wop->wo_ve); - clear_string_option((char_u **)&wop->wo_wbr); + clear_string_option(&wop->wo_wbr); } void didset_window_options(win_T *wp, bool valid_cursor) @@ -4377,8 +4367,8 @@ void didset_window_options(win_T *wp, bool valid_cursor) check_colorcolumn(wp); briopt_check(wp); fill_culopt_flags(NULL, wp); - set_chars_option(wp, &wp->w_p_fcs, true); - set_chars_option(wp, &wp->w_p_lcs, true); + set_chars_option(wp, (char_u **)&wp->w_p_fcs, true); + set_chars_option(wp, (char_u **)&wp->w_p_lcs, true); parse_winhl_opt(wp); // sets w_hl_needs_update also for w_p_winbl check_blending(wp); set_winbar_win(wp, false, valid_cursor); @@ -4451,7 +4441,7 @@ void buf_copy_options(buf_T *buf, int flags) // (jumping back to a help file with CTRL-T or CTRL-O) dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) || buf->b_p_initialized; if (dont_do_help) { // don't free b_p_isk - save_p_isk = buf->b_p_isk; + save_p_isk = (char_u *)buf->b_p_isk; buf->b_p_isk = NULL; } // Always free the allocated strings. If not already initialized, @@ -4459,19 +4449,19 @@ void buf_copy_options(buf_T *buf, int flags) if (!buf->b_p_initialized) { free_buf_options(buf, true); buf->b_p_ro = false; // don't copy readonly - buf->b_p_fenc = vim_strsave(p_fenc); + buf->b_p_fenc = (char *)vim_strsave(p_fenc); switch (*p_ffs) { case 'm': - buf->b_p_ff = vim_strsave((char_u *)FF_MAC); + buf->b_p_ff = xstrdup(FF_MAC); break; case 'd': - buf->b_p_ff = vim_strsave((char_u *)FF_DOS); + buf->b_p_ff = xstrdup(FF_DOS); break; case 'u': - buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); + buf->b_p_ff = xstrdup(FF_UNIX); break; default: - buf->b_p_ff = vim_strsave(p_ff); + buf->b_p_ff = (char *)vim_strsave(p_ff); break; } buf->b_p_bh = empty_option; @@ -4516,42 +4506,42 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_swf = p_swf; COPY_OPT_SCTX(buf, BV_SWF); } - buf->b_p_cpt = vim_strsave(p_cpt); + buf->b_p_cpt = (char *)vim_strsave(p_cpt); COPY_OPT_SCTX(buf, BV_CPT); #ifdef BACKSLASH_IN_FILENAME buf->b_p_csl = vim_strsave(p_csl); COPY_OPT_SCTX(buf, BV_CSL); #endif - buf->b_p_cfu = vim_strsave(p_cfu); + buf->b_p_cfu = (char *)vim_strsave(p_cfu); COPY_OPT_SCTX(buf, BV_CFU); - buf->b_p_ofu = vim_strsave(p_ofu); + buf->b_p_ofu = (char *)vim_strsave(p_ofu); COPY_OPT_SCTX(buf, BV_OFU); - buf->b_p_tfu = vim_strsave(p_tfu); + buf->b_p_tfu = (char *)vim_strsave(p_tfu); COPY_OPT_SCTX(buf, BV_TFU); buf->b_p_sts = p_sts; COPY_OPT_SCTX(buf, BV_STS); buf->b_p_sts_nopaste = p_sts_nopaste; - buf->b_p_vsts = vim_strsave(p_vsts); + buf->b_p_vsts = (char *)vim_strsave(p_vsts); COPY_OPT_SCTX(buf, BV_VSTS); - if (p_vsts && p_vsts != empty_option) { + if (p_vsts && p_vsts != (char_u *)empty_option) { (void)tabstop_set(p_vsts, &buf->b_p_vsts_array); } else { buf->b_p_vsts_array = NULL; } buf->b_p_vsts_nopaste = p_vsts_nopaste - ? vim_strsave(p_vsts_nopaste) + ? (char *)vim_strsave(p_vsts_nopaste) : NULL; - buf->b_p_com = vim_strsave(p_com); + buf->b_p_com = (char *)vim_strsave(p_com); COPY_OPT_SCTX(buf, BV_COM); - buf->b_p_cms = vim_strsave(p_cms); + buf->b_p_cms = (char *)vim_strsave(p_cms); COPY_OPT_SCTX(buf, BV_CMS); - buf->b_p_fo = vim_strsave(p_fo); + buf->b_p_fo = (char *)vim_strsave(p_fo); COPY_OPT_SCTX(buf, BV_FO); - buf->b_p_flp = vim_strsave(p_flp); + buf->b_p_flp = (char *)vim_strsave(p_flp); COPY_OPT_SCTX(buf, BV_FLP); - buf->b_p_nf = vim_strsave(p_nf); + buf->b_p_nf = (char *)vim_strsave(p_nf); COPY_OPT_SCTX(buf, BV_NF); - buf->b_p_mps = vim_strsave(p_mps); + buf->b_p_mps = (char *)vim_strsave(p_mps); COPY_OPT_SCTX(buf, BV_MPS); buf->b_p_si = p_si; COPY_OPT_SCTX(buf, BV_SI); @@ -4561,18 +4551,18 @@ void buf_copy_options(buf_T *buf, int flags) COPY_OPT_SCTX(buf, BV_CI); buf->b_p_cin = p_cin; COPY_OPT_SCTX(buf, BV_CIN); - buf->b_p_cink = vim_strsave(p_cink); + buf->b_p_cink = (char *)vim_strsave(p_cink); COPY_OPT_SCTX(buf, BV_CINK); - buf->b_p_cino = vim_strsave(p_cino); + buf->b_p_cino = (char *)vim_strsave(p_cino); COPY_OPT_SCTX(buf, BV_CINO); - buf->b_p_cinsd = vim_strsave(p_cinsd); + buf->b_p_cinsd = (char *)vim_strsave(p_cinsd); COPY_OPT_SCTX(buf, BV_CINSD); // Don't copy 'filetype', it must be detected buf->b_p_ft = empty_option; buf->b_p_pi = p_pi; COPY_OPT_SCTX(buf, BV_PI); - buf->b_p_cinw = vim_strsave(p_cinw); + buf->b_p_cinw = (char *)vim_strsave(p_cinw); COPY_OPT_SCTX(buf, BV_CINW); buf->b_p_lisp = p_lisp; COPY_OPT_SCTX(buf, BV_LISP); @@ -4581,25 +4571,25 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_smc = p_smc; COPY_OPT_SCTX(buf, BV_SMC); buf->b_s.b_syn_isk = empty_option; - buf->b_s.b_p_spc = vim_strsave(p_spc); + buf->b_s.b_p_spc = (char *)vim_strsave(p_spc); COPY_OPT_SCTX(buf, BV_SPC); (void)compile_cap_prog(&buf->b_s); - buf->b_s.b_p_spf = vim_strsave(p_spf); + buf->b_s.b_p_spf = (char *)vim_strsave(p_spf); COPY_OPT_SCTX(buf, BV_SPF); - buf->b_s.b_p_spl = vim_strsave(p_spl); + buf->b_s.b_p_spl = (char *)vim_strsave(p_spl); COPY_OPT_SCTX(buf, BV_SPL); - buf->b_s.b_p_spo = vim_strsave(p_spo); + buf->b_s.b_p_spo = (char *)vim_strsave(p_spo); COPY_OPT_SCTX(buf, BV_SPO); - buf->b_p_inde = vim_strsave(p_inde); + buf->b_p_inde = (char *)vim_strsave(p_inde); COPY_OPT_SCTX(buf, BV_INDE); - buf->b_p_indk = vim_strsave(p_indk); + buf->b_p_indk = (char *)vim_strsave(p_indk); COPY_OPT_SCTX(buf, BV_INDK); buf->b_p_fp = empty_option; - buf->b_p_fex = vim_strsave(p_fex); + buf->b_p_fex = (char *)vim_strsave(p_fex); COPY_OPT_SCTX(buf, BV_FEX); - buf->b_p_sua = vim_strsave(p_sua); + buf->b_p_sua = (char *)vim_strsave(p_sua); COPY_OPT_SCTX(buf, BV_SUA); - buf->b_p_keymap = vim_strsave(p_keymap); + buf->b_p_keymap = (char *)vim_strsave(p_keymap); COPY_OPT_SCTX(buf, BV_KMAP); buf->b_kmap_state |= KEYMAP_INIT; // This isn't really an option, but copying the langmap and IME @@ -4626,12 +4616,12 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_tc_flags = 0; buf->b_p_def = empty_option; buf->b_p_inc = empty_option; - buf->b_p_inex = vim_strsave(p_inex); + buf->b_p_inex = (char *)vim_strsave(p_inex); COPY_OPT_SCTX(buf, BV_INEX); buf->b_p_dict = empty_option; buf->b_p_tsr = empty_option; buf->b_p_tsrfu = empty_option; - buf->b_p_qe = vim_strsave(p_qe); + buf->b_p_qe = (char *)vim_strsave(p_qe); COPY_OPT_SCTX(buf, BV_QE); buf->b_p_udf = p_udf; COPY_OPT_SCTX(buf, BV_UDF); @@ -4645,21 +4635,21 @@ void buf_copy_options(buf_T *buf, int flags) * or to a help buffer. */ if (dont_do_help) { - buf->b_p_isk = save_p_isk; - if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) { + buf->b_p_isk = (char *)save_p_isk; + if (p_vts && p_vts != (char_u *)empty_option && !buf->b_p_vts_array) { (void)tabstop_set(p_vts, &buf->b_p_vts_array); } else { buf->b_p_vts_array = NULL; } } else { - buf->b_p_isk = vim_strsave(p_isk); + buf->b_p_isk = (char *)vim_strsave(p_isk); COPY_OPT_SCTX(buf, BV_ISK); did_isk = true; buf->b_p_ts = p_ts; COPY_OPT_SCTX(buf, BV_TS); - buf->b_p_vts = vim_strsave(p_vts); + buf->b_p_vts = (char *)vim_strsave(p_vts); COPY_OPT_SCTX(buf, BV_VTS); - if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) { + if (p_vts && p_vts != (char_u *)empty_option && !buf->b_p_vts_array) { (void)tabstop_set(p_vts, &buf->b_p_vts_array); } else { buf->b_p_vts_array = NULL; @@ -5065,7 +5055,7 @@ bool has_format_option(int x) if (p_paste) { return false; } - return vim_strchr((char *)curbuf->b_p_fo, x) != NULL; + return vim_strchr(curbuf->b_p_fo, x) != NULL; } /// @returns true if "x" is present in 'shortmess' option, or @@ -5105,7 +5095,7 @@ static void paste_option_changed(void) xfree(buf->b_p_vsts_nopaste); } buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option - ? vim_strsave(buf->b_p_vsts) + ? xstrdup(buf->b_p_vsts) : NULL; } @@ -5124,7 +5114,7 @@ static void paste_option_changed(void) if (p_vsts_nopaste) { xfree(p_vsts_nopaste); } - p_vsts_nopaste = p_vsts && p_vsts != empty_option + p_vsts_nopaste = p_vsts && p_vsts != (char_u *)empty_option ? vim_strsave(p_vsts) : NULL; } @@ -5160,9 +5150,9 @@ static void paste_option_changed(void) p_sts = 0; p_ai = 0; if (p_vsts) { - free_string_option(p_vsts); + free_string_option((char *)p_vsts); } - p_vsts = empty_option; + p_vsts = (char_u *)empty_option; } else if (old_p_paste) { // Paste switched from on to off: Restore saved values. @@ -5176,12 +5166,10 @@ static void paste_option_changed(void) if (buf->b_p_vsts) { free_string_option(buf->b_p_vsts); } - buf->b_p_vsts = buf->b_p_vsts_nopaste - ? vim_strsave(buf->b_p_vsts_nopaste) - : empty_option; + buf->b_p_vsts = buf->b_p_vsts_nopaste ? xstrdup(buf->b_p_vsts_nopaste) : empty_option; xfree(buf->b_p_vsts_array); if (buf->b_p_vsts && buf->b_p_vsts != empty_option) { - (void)tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array); + (void)tabstop_set((char_u *)buf->b_p_vsts, &buf->b_p_vsts_array); } else { buf->b_p_vsts_array = NULL; } @@ -5203,9 +5191,9 @@ static void paste_option_changed(void) p_tw = p_tw_nopaste; p_wm = p_wm_nopaste; if (p_vsts) { - free_string_option(p_vsts); + free_string_option((char *)p_vsts); } - p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option; + p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : (char_u *)empty_option; } old_p_paste = p_paste; @@ -5286,7 +5274,7 @@ int fill_culopt_flags(char_u *val, win_T *wp) char_u culopt_flags_new = 0; if (val == NULL) { - p = wp->w_p_culopt; + p = (char_u *)wp->w_p_culopt; } else { p = val; } @@ -5360,59 +5348,6 @@ int option_set_callback_func(char_u *optval, Callback *optcb) return OK; } -/// Read the 'wildmode' option, fill wim_flags[]. -int check_opt_wim(void) -{ - char_u new_wim_flags[4]; - char_u *p; - int i; - int idx = 0; - - for (i = 0; i < 4; i++) { - new_wim_flags[i] = 0; - } - - for (p = p_wim; *p; p++) { - for (i = 0; ASCII_ISALPHA(p[i]); i++) {} - if (p[i] != NUL && p[i] != ',' && p[i] != ':') { - return FAIL; - } - if (i == 7 && STRNCMP(p, "longest", 7) == 0) { - new_wim_flags[idx] |= WIM_LONGEST; - } else if (i == 4 && STRNCMP(p, "full", 4) == 0) { - new_wim_flags[idx] |= WIM_FULL; - } else if (i == 4 && STRNCMP(p, "list", 4) == 0) { - new_wim_flags[idx] |= WIM_LIST; - } else if (i == 8 && STRNCMP(p, "lastused", 8) == 0) { - new_wim_flags[idx] |= WIM_BUFLASTUSED; - } else { - return FAIL; - } - p += i; - if (*p == NUL) { - break; - } - if (*p == ',') { - if (idx == 3) { - return FAIL; - } - idx++; - } - } - - // fill remaining entries with last flag - while (idx < 3) { - new_wim_flags[idx + 1] = new_wim_flags[idx]; - idx++; - } - - // only when there are no errors, wim_flags[] is changed - for (i = 0; i < 4; i++) { - wim_flags[i] = new_wim_flags[i]; - } - return OK; -} - /// Check if backspacing over something is allowed. /// @param what BS_INDENT, BS_EOL, BS_START, or BS_NOSTOP bool can_bs(int what) @@ -5433,98 +5368,6 @@ bool can_bs(int what) return vim_strchr((char *)p_bs, what) != NULL; } -/// Save the current values of 'fileformat' and 'fileencoding', so that we know -/// the file must be considered changed when the value is different. -void save_file_ff(buf_T *buf) -{ - buf->b_start_ffc = *buf->b_p_ff; - buf->b_start_eol = buf->b_p_eol; - buf->b_start_bomb = buf->b_p_bomb; - - // Only use free/alloc when necessary, they take time. - if (buf->b_start_fenc == NULL - || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) { - xfree(buf->b_start_fenc); - buf->b_start_fenc = (char *)vim_strsave(buf->b_p_fenc); - } -} - -/// Return true if 'fileformat' and/or 'fileencoding' has a different value -/// from when editing started (save_file_ff() called). -/// Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was -/// changed and 'binary' is not set. -/// Also when 'endofline' was changed and 'fixeol' is not set. -/// When "ignore_empty" is true don't consider a new, empty buffer to be -/// changed. -bool file_ff_differs(buf_T *buf, bool ignore_empty) - FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT -{ - // In a buffer that was never loaded the options are not valid. - if (buf->b_flags & BF_NEVERLOADED) { - return false; - } - if (ignore_empty - && (buf->b_flags & BF_NEW) - && buf->b_ml.ml_line_count == 1 - && *ml_get_buf(buf, (linenr_T)1, false) == NUL) { - return false; - } - if (buf->b_start_ffc != *buf->b_p_ff) { - return true; - } - if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol) { - return true; - } - if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb) { - return true; - } - if (buf->b_start_fenc == NULL) { - return *buf->b_p_fenc != NUL; - } - return STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0; -} - -/// This is called when 'breakindentopt' is changed and when a window is -/// initialized -bool briopt_check(win_T *wp) -{ - int bri_shift = 0; - int bri_min = 20; - bool bri_sbr = false; - int bri_list = 0; - - char *p = (char *)wp->w_p_briopt; - while (*p != NUL) { - if (STRNCMP(p, "shift:", 6) == 0 - && ((p[6] == '-' && ascii_isdigit(p[7])) || ascii_isdigit(p[6]))) { - p += 6; - bri_shift = getdigits_int(&p, true, 0); - } else if (STRNCMP(p, "min:", 4) == 0 && ascii_isdigit(p[4])) { - p += 4; - bri_min = getdigits_int(&p, true, 0); - } else if (STRNCMP(p, "sbr", 3) == 0) { - p += 3; - bri_sbr = true; - } else if (STRNCMP(p, "list:", 5) == 0) { - p += 5; - bri_list = (int)getdigits(&p, false, 0); - } - if (*p != ',' && *p != NUL) { - return false; - } - if (*p == ',') { - p++; - } - } - - wp->w_briopt_shift = bri_shift; - wp->w_briopt_min = bri_min; - wp->w_briopt_sbr = bri_sbr; - wp->w_briopt_list = bri_list; - - return true; -} - /// Get the local or global value of 'backupcopy'. /// /// @param buf The buffer. @@ -5550,16 +5393,16 @@ char_u *get_showbreak_value(win_T *const win) return p_sbr; } if (STRCMP(win->w_p_sbr, "NONE") == 0) { - return empty_option; + return (char_u *)empty_option; } - return win->w_p_sbr; + return (char_u *)win->w_p_sbr; } /// Return the current end-of-line type: EOL_DOS, EOL_UNIX or EOL_MAC. int get_fileformat(const buf_T *buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - int c = *buf->b_p_ff; + int c = (unsigned char)(*buf->b_p_ff); if (buf->b_p_bin || c == 'u') { return EOL_UNIX; @@ -5586,7 +5429,7 @@ int get_fileformat_force(const buf_T *buf, const exarg_T *eap) ? (eap->force_bin == FORCE_BIN) : buf->b_p_bin) { return EOL_UNIX; } - c = *buf->b_p_ff; + c = (unsigned char)(*buf->b_p_ff); } if (c == 'u') { return EOL_UNIX; diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index ad8092add2..f9848cb792 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -972,8 +972,8 @@ enum { WV_WRAP, WV_SCL, WV_WINHL, - WV_FCS, WV_LCS, + WV_FCS, WV_WINBL, WV_WBR, WV_COUNT, // must be the last one diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 78ae7e41ab..e4cdf883fe 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -18,6 +18,7 @@ #include "nvim/drawscreen.h" #include "nvim/eval.h" #include "nvim/eval/vars.h" +#include "nvim/ex_getln.h" #include "nvim/hardcopy.h" #include "nvim/highlight_group.h" #include "nvim/indent.h" @@ -254,14 +255,14 @@ void check_buf_options(buf_T *buf) /// memory, vim_strsave() returned NULL, which was replaced by empty_option by /// check_options(). /// Does NOT check for P_ALLOCED flag! -void free_string_option(char_u *p) +void free_string_option(char *p) { if (p != empty_option) { xfree(p); } } -void clear_string_option(char_u **pp) +void clear_string_option(char **pp) { if (*pp != empty_option) { xfree(*pp); @@ -269,7 +270,7 @@ void clear_string_option(char_u **pp) *pp = empty_option; } -void check_string_option(char_u **pp) +void check_string_option(char **pp) { if (*pp == NULL) { *pp = empty_option; @@ -292,7 +293,7 @@ static void set_string_option_global(int opt_idx, char_u **varp) } if (!is_global_option(opt_idx) && p != varp) { s = vim_strsave(*varp); - free_string_option(*p); + free_string_option((char *)(*p)); *p = s; } } @@ -332,7 +333,7 @@ void set_string_option_direct(const char *name, int opt_idx, const char *val, in { varp = (char **)get_option_varp_scope(idx, both ? OPT_LOCAL : opt_flags); if ((opt_flags & OPT_FREE) && (get_option_flags(idx) & P_ALLOCED)) { - free_string_option((char_u *)(*varp)); + free_string_option(*varp); } *varp = s; @@ -346,8 +347,8 @@ void set_string_option_direct(const char *name, int opt_idx, const char *val, in // When setting both values of a global option with a local value, // make the local value empty, so that the global value is used. if (is_global_local_option(idx) && both) { - free_string_option((char_u *)(*varp)); - *varp = (char *)empty_option; + free_string_option(*varp); + *varp = empty_option; } if (set_sid != SID_NONE) { sctx_T script_ctx; @@ -662,7 +663,7 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er unsigned int *flags = &bkc_flags; if (opt_flags & OPT_LOCAL) { - bkc = curbuf->b_p_bkc; + bkc = (char_u *)curbuf->b_p_bkc; flags = &curbuf->b_bkc_flags; } @@ -687,12 +688,12 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er *p_pm == '.' ? p_pm + 1 : p_pm) == 0) { errmsg = e_backupext_and_patchmode_are_equal; } - } else if (varp == &curwin->w_p_briopt) { // 'breakindentopt' + } else if (varp == (char_u **)&curwin->w_p_briopt) { // 'breakindentopt' if (briopt_check(curwin) == FAIL) { errmsg = e_invarg; } } else if (varp == &p_isi - || varp == &(curbuf->b_p_isk) + || varp == (char_u **)&(curbuf->b_p_isk) || varp == &p_isp || varp == &p_isf) { // 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[] @@ -712,12 +713,12 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er } } else if (varp == &p_rtp || varp == &p_pp) { // 'runtimepath' 'packpath' runtime_search_path_invalidate(); - } else if (varp == &curwin->w_p_culopt - || gvarp == &curwin->w_allbuf_opt.wo_culopt) { // 'cursorlineopt' + } else if (varp == (char_u **)&curwin->w_p_culopt + || gvarp == (char_u **)&curwin->w_allbuf_opt.wo_culopt) { // 'cursorlineopt' if (**varp == NUL || fill_culopt_flags(*varp, curwin) != OK) { errmsg = e_invarg; } - } else if (varp == &curwin->w_p_cc) { // 'colorcolumn' + } else if (varp == (char_u **)&curwin->w_p_cc) { // 'colorcolumn' errmsg = check_colorcolumn(curwin); } else if (varp == &p_hlg) { // 'helplang' // Check for "", "ab", "ab,cd", etc. @@ -780,9 +781,9 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er // value, that's not what we want here. Disable the color // scheme and set the colors again. do_unlet(S_LEN("g:colors_name"), true); - free_string_option(p_bg); + free_string_option((char *)p_bg); p_bg = vim_strsave((char_u *)(dark ? "dark" : "light")); - check_string_option(&p_bg); + check_string_option((char **)&p_bg); init_highlight(false, false); } } else { @@ -841,7 +842,7 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er p = (char *)enc_canonize(p_penc); xfree(p_penc); p_penc = (char_u *)p; - } else if (varp == &curbuf->b_p_keymap) { + } else if (varp == (char_u **)&curbuf->b_p_keymap) { if (!valid_filetype(*varp)) { errmsg = e_invarg; } else { @@ -949,39 +950,31 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er } s = (char *)skip_to_option_part((char_u *)s); } - } else if (varp == &p_lcs) { // global 'listchars' - errmsg = set_chars_option(curwin, varp, false); + } else if (varp == &p_lcs || varp == &p_fcs) { // global 'listchars' or 'fillchars' + char **local_ptr = varp == &p_lcs ? &curwin->w_p_lcs : &curwin->w_p_fcs; + // only apply the global value to "curwin" when it does not have a local value + errmsg = set_chars_option(curwin, varp, **local_ptr == NUL || !(opt_flags & OPT_GLOBAL)); if (errmsg == NULL) { - // The current window is set to use the global 'listchars' value. - // So clear the window-local value. + // If the current window is set to use the global + // 'listchars'/'fillchars' value, clear the window-local value. if (!(opt_flags & OPT_GLOBAL)) { - clear_string_option(&curwin->w_p_lcs); + clear_string_option(local_ptr); } FOR_ALL_TAB_WINDOWS(tp, wp) { + // If the current window has a local value need to apply it + // again, it was changed when setting the global value. // If no error was returned above, we don't expect an error // here, so ignore the return value. - (void)set_chars_option(wp, &wp->w_p_lcs, true); + local_ptr = varp == &p_lcs ? &wp->w_p_lcs : &wp->w_p_fcs; + if (**local_ptr == NUL) { + (void)set_chars_option(wp, (char_u **)local_ptr, true); + } } redraw_all_later(UPD_NOT_VALID); } - } else if (varp == &curwin->w_p_lcs) { // local 'listchars' + } else if (varp == (char_u **)&curwin->w_p_lcs) { // local 'listchars' errmsg = set_chars_option(curwin, varp, true); - } else if (varp == &p_fcs) { // global 'fillchars' - errmsg = set_chars_option(curwin, varp, false); - if (errmsg == NULL) { - // The current window is set to use the global 'fillchars' value. - // So clear the window-local value. - if (!(opt_flags & OPT_GLOBAL)) { - clear_string_option(&curwin->w_p_fcs); - } - FOR_ALL_TAB_WINDOWS(tp, wp) { - // If no error was returned above, we don't expect an error - // here, so ignore the return value. - (void)set_chars_option(wp, &wp->w_p_fcs, true); - } - redraw_all_later(UPD_NOT_VALID); - } - } else if (varp == &curwin->w_p_fcs) { // local 'fillchars' + } else if (varp == (char_u **)&curwin->w_p_fcs) { // local 'fillchars' errmsg = set_chars_option(curwin, varp, true); } else if (varp == &p_cedit) { // 'cedit' errmsg = check_cedit(); @@ -1117,11 +1110,11 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er if (opt_strings_flags(p_cb, p_cb_values, &cb_flags, true) != OK) { errmsg = e_invarg; } - } else if (varp == &(curwin->w_s->b_p_spl) // 'spell' - || varp == &(curwin->w_s->b_p_spf)) { + } else if (varp == (char_u **)&(curwin->w_s->b_p_spl) // 'spell' + || varp == (char_u **)&(curwin->w_s->b_p_spf)) { // When 'spelllang' or 'spellfile' is set and there is a window for this // buffer in which 'spell' is set load the wordlists. - const bool is_spellfile = varp == &(curwin->w_s->b_p_spf); + const bool is_spellfile = varp == (char_u **)&(curwin->w_s->b_p_spf); if ((is_spellfile && !valid_spellfile(*varp)) || (!is_spellfile && !valid_spelllang(*varp))) { @@ -1129,10 +1122,10 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er } else { errmsg = did_set_spell_option(is_spellfile); } - } else if (varp == &(curwin->w_s->b_p_spc)) { + } else if (varp == (char_u **)&(curwin->w_s->b_p_spc)) { // When 'spellcapcheck' is set compile the regexp program. errmsg = compile_cap_prog(curwin->w_s); - } else if (varp == &(curwin->w_s->b_p_spo)) { // 'spelloptions' + } else if (varp == (char_u **)&(curwin->w_s->b_p_spo)) { // 'spelloptions' if (**varp != NUL && STRCMP("camel", *varp) != 0) { errmsg = e_invarg; } @@ -1146,14 +1139,14 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er } } else if (gvarp == &p_bh) { // When 'bufhidden' is set, check for valid value. - if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, false) != OK) { + if (check_opt_strings((char_u *)curbuf->b_p_bh, p_bufhidden_values, false) != OK) { errmsg = e_invarg; } } else if (gvarp == &p_bt) { // When 'buftype' is set, check for valid value. if ((curbuf->terminal && curbuf->b_p_bt[0] != 't') || (!curbuf->terminal && curbuf->b_p_bt[0] == 't') - || check_opt_strings(curbuf->b_p_bt, p_buftype_values, false) != OK) { + || check_opt_strings((char_u *)curbuf->b_p_bt, p_buftype_values, false) != OK) { errmsg = e_invarg; } else { if (curwin->w_status_height || global_stl_height()) { @@ -1241,7 +1234,7 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er errmsg = e_invarg; } #endif - } else if (varp == &curwin->w_p_scl) { // 'signcolumn' + } else if (varp == (char_u **)&curwin->w_p_scl) { // 'signcolumn' if (check_signcolumn(*varp) != OK) { errmsg = e_invarg; } @@ -1252,7 +1245,8 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er && (curwin->w_p_nu || curwin->w_p_rnu)) { curwin->w_nrwidth_line_count = 0; } - } else if (varp == &curwin->w_p_fdc || varp == &curwin->w_allbuf_opt.wo_fdc) { + } else if (varp == (char_u **)&curwin->w_p_fdc + || varp == (char_u **)&curwin->w_allbuf_opt.wo_fdc) { // 'foldcolumn' if (**varp == NUL || check_opt_strings(*varp, p_fdc_values, false) != OK) { errmsg = e_invarg; @@ -1266,7 +1260,7 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er &p, REPTERM_FROM_PART | REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS); if (p != NULL) { - free_string_option(p_pt); + free_string_option((char *)p_pt); p_pt = (char_u *)p; } } @@ -1286,7 +1280,7 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er unsigned int *flags; if (opt_flags & OPT_LOCAL) { - p = (char *)curbuf->b_p_tc; + p = curbuf->b_p_tc; flags = &curbuf->b_tc_flags; } else { p = (char *)p_tc; @@ -1308,7 +1302,7 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er if (diffopt_changed() == FAIL) { errmsg = e_invarg; } - } else if (gvarp == &curwin->w_allbuf_opt.wo_fdm) { // 'foldmethod' + } else if (gvarp == (char_u **)&curwin->w_allbuf_opt.wo_fdm) { // 'foldmethod' if (check_opt_strings(*varp, p_fdm_values, false) != OK || *curwin->w_p_fdm == NUL) { errmsg = e_invarg; @@ -1318,11 +1312,11 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er newFoldLevel(); } } - } else if (varp == &curwin->w_p_fde) { // 'foldexpr' + } else if (varp == (char_u **)&curwin->w_p_fde) { // 'foldexpr' if (foldmethodIsExpr(curwin)) { foldUpdateAll(curwin); } - } else if (gvarp == &curwin->w_allbuf_opt.wo_fmr) { // 'foldmarker' + } else if (gvarp == (char_u **)&curwin->w_allbuf_opt.wo_fmr) { // 'foldmarker' p = vim_strchr((char *)(*varp), ','); if (p == NULL) { errmsg = N_("E536: comma required"); @@ -1343,7 +1337,7 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er if (check_opt_strings(p_fcl, p_fcl_values, true) != OK) { errmsg = e_invarg; } - } else if (gvarp == &curwin->w_allbuf_opt.wo_fdi) { // 'foldignore' + } else if (gvarp == (char_u **)&curwin->w_allbuf_opt.wo_fdi) { // 'foldignore' if (foldmethodIsIndent(curwin)) { foldUpdateAll(curwin); } @@ -1352,7 +1346,7 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er unsigned int *flags = &ve_flags; if (opt_flags & OPT_LOCAL) { - ve = curwin->w_p_ve; + ve = (char_u *)curwin->w_p_ve; flags = &curwin->w_ve_flags; } @@ -1413,7 +1407,7 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er // even when the value comes from a modeline. *value_checked = true; } - } else if (varp == &curwin->w_p_winhl) { + } else if (varp == (char_u **)&curwin->w_p_winhl) { if (!parse_winhl_opt(curwin)) { errmsg = e_invarg; } @@ -1421,7 +1415,7 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er if (opt_strings_flags(p_tpf, p_tpf_values, &tpf_flags, true) != OK) { errmsg = e_invarg; } - } else if (varp == &(curbuf->b_p_vsts)) { // 'varsofttabstop' + } else if (varp == (char_u **)&(curbuf->b_p_vsts)) { // 'varsofttabstop' char_u *cp; if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) { @@ -1446,7 +1440,7 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er } } } - } else if (varp == &(curbuf->b_p_vts)) { // 'vartabstop' + } else if (varp == (char_u **)&(curbuf->b_p_vts)) { // 'vartabstop' char_u *cp; if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) { @@ -1492,9 +1486,9 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er p = (char *)SHM_ALL; } else if (varp == (char_u **)&(p_cpo)) { // 'cpoptions' p = CPO_VI; - } else if (varp == &(curbuf->b_p_fo)) { // 'formatoptions' + } else if (varp == (char_u **)&(curbuf->b_p_fo)) { // 'formatoptions' p = FO_ALL; - } else if (varp == &curwin->w_p_cocu) { // 'concealcursor' + } else if (varp == (char_u **)&curwin->w_p_cocu) { // 'concealcursor' p = COCU_ALL; } else if (varp == &p_mouse) { // 'mouse' p = MOUSE_ALL; @@ -1511,7 +1505,7 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er // If error detected, restore the previous value. if (errmsg != NULL) { - free_string_option(*varp); + free_string_option((char *)(*varp)); *varp = oldval; // When resetting some values, need to act on it. if (did_chartab) { @@ -1524,7 +1518,7 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er // Use "free_oldval", because recursiveness may change the flags under // our fingers (esp. init_highlight()). if (free_oldval) { - free_string_option(oldval); + free_string_option((char *)oldval); } set_option_flag(opt_idx, P_ALLOCED); @@ -1533,8 +1527,8 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er // global option with local value set to use global value; free // the local value and make it empty p = (char *)get_option_varp_scope(opt_idx, OPT_LOCAL); - free_string_option(*(char_u **)p); - *(char_u **)p = empty_option; + free_string_option(*(char **)p); + *(char **)p = empty_option; } else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL) { // May set global value for local option. set_string_option_global(opt_idx, varp); @@ -1542,17 +1536,17 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er // Trigger the autocommand only after setting the flags. // When 'syntax' is set, load the syntax of that name - if (varp == &(curbuf->b_p_syn)) { + if (varp == (char_u **)&(curbuf->b_p_syn)) { static int syn_recursive = 0; syn_recursive++; // Only pass true for "force" when the value changed or not used // recursively, to avoid endless recurrence. - apply_autocmds(EVENT_SYNTAX, (char *)curbuf->b_p_syn, curbuf->b_fname, + apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname, value_changed || syn_recursive == 1, curbuf); curbuf->b_flags |= BF_SYN_SET; syn_recursive--; - } else if (varp == &(curbuf->b_p_ft)) { + } else if (varp == (char_u **)&(curbuf->b_p_ft)) { // 'filetype' is set, trigger the FileType autocommand // Skip this when called from a modeline and the filetype was // already set to this value. @@ -1568,19 +1562,19 @@ char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *er did_filetype = true; // Only pass true for "force" when the value changed or not // used recursively, to avoid endless recurrence. - apply_autocmds(EVENT_FILETYPE, (char *)curbuf->b_p_ft, curbuf->b_fname, + apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname, value_changed || ft_recursive == 1, curbuf); ft_recursive--; // Just in case the old "curbuf" is now invalid - if (varp != &(curbuf->b_p_ft)) { + if (varp != (char_u **)&(curbuf->b_p_ft)) { varp = NULL; } secure = secure_save; } } - if (varp == &(curwin->w_s->b_p_spl)) { + if (varp == (char_u **)&(curwin->w_s->b_p_spl)) { char_u fname[200]; - char_u *q = curwin->w_s->b_p_spl; + char_u *q = (char_u *)curwin->w_s->b_p_spl; // Skip the first name if it is "cjk". if (STRNCMP(q, "cjk,", 4) == 0) { diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index b793b8f9c6..574543b1a5 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -74,7 +74,7 @@ static bool have_wildcard(int num, char **file) static bool have_dollars(int num, char **file) { for (int i = 0; i < num; i++) { - if (vim_strchr((char *)file[i], '$') != NULL) { + if (vim_strchr(file[i], '$') != NULL) { return true; } } diff --git a/src/nvim/path.c b/src/nvim/path.c index 3b3156bc73..8d3c556c7d 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -233,10 +233,8 @@ char_u *get_past_head(const char_u *path) return (char_u *)retval; } -/* - * Return TRUE if 'c' is a path separator. - * Note that for MS-Windows this includes the colon. - */ +/// Return true if 'c' is a path separator. +/// Note that for MS-Windows this includes the colon. int vim_ispathsep(int c) { #ifdef UNIX @@ -262,9 +260,7 @@ int vim_ispathsep_nocolon(int c) ; } -/* - * return TRUE if 'c' is a path list separator. - */ +/// return true if 'c' is a path list separator. int vim_ispathlistsep(int c) { #ifdef UNIX @@ -319,11 +315,9 @@ void shorten_dir(char_u *str) shorten_dir_len(str, 1); } -/* - * Return TRUE if the directory of "fname" exists, FALSE otherwise. - * Also returns TRUE if there is no directory name. - * "fname" must be writable!. - */ +/// Return true if the directory of "fname" exists, false otherwise. +/// Also returns true if there is no directory name. +/// "fname" must be writable!. bool dir_of_file_exists(char_u *fname) { char *p = path_tail_with_sep((char *)fname); @@ -376,16 +370,16 @@ int path_fnamencmp(const char *const fname1, const char *const fname2, size_t le const char *p1 = fname1; const char *p2 = fname2; while (len > 0) { - c1 = utf_ptr2char((const char_u *)p1); - c2 = utf_ptr2char((const char_u *)p2); + c1 = utf_ptr2char(p1); + c2 = utf_ptr2char(p2); if ((c1 == NUL || c2 == NUL || (!((c1 == '/' || c1 == '\\') && (c2 == '\\' || c2 == '/')))) && (p_fic ? (c1 != c2 && CH_FOLD(c1) != CH_FOLD(c2)) : c1 != c2)) { break; } - len -= (size_t)utfc_ptr2len((const char_u *)p1); - p1 += utfc_ptr2len((const char_u *)p1); - p2 += utfc_ptr2len((const char_u *)p2); + len -= (size_t)utfc_ptr2len(p1); + p1 += utfc_ptr2len(p1); + p2 += utfc_ptr2len(p2); } return p_fic ? CH_FOLD(c1) - CH_FOLD(c2) : c1 - c2; #else @@ -806,10 +800,8 @@ static int find_previous_pathsep(char_u *path, char_u **psep) return FAIL; } -/* - * Returns TRUE if "maybe_unique" is unique wrt other_paths in "gap". - * "maybe_unique" is the end portion of "((char_u **)gap->ga_data)[i]". - */ +/// Returns true if "maybe_unique" is unique wrt other_paths in "gap". +/// "maybe_unique" is the end portion of "((char_u **)gap->ga_data)[i]". static bool is_unique(char_u *maybe_unique, garray_T *gap, int i) { char_u **other_paths = (char_u **)gap->ga_data; @@ -843,7 +835,7 @@ static bool is_unique(char_u *maybe_unique, garray_T *gap, int i) */ static void expand_path_option(char_u *curdir, garray_T *gap) { - char_u *path_option = *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path; + char_u *path_option = *curbuf->b_p_path == NUL ? p_path : (char_u *)curbuf->b_p_path; char_u *buf = xmalloc(MAXPATHL); while (*path_option != NUL) { @@ -1149,10 +1141,8 @@ static int expand_in_path(garray_T *const gap, char_u *const pattern, const int return gap->ga_len; } -/* - * Return TRUE if "p" contains what looks like an environment variable. - * Allowing for escaping. - */ +/// Return true if "p" contains what looks like an environment variable. +/// Allowing for escaping. static bool has_env_var(char_u *p) { for (; *p; MB_PTR_ADV(p)) { @@ -1167,7 +1157,7 @@ static bool has_env_var(char_u *p) #ifdef SPECIAL_WILDCHAR -// Return TRUE if "p" contains a special wildcard character, one that Vim +// Return true if "p" contains a special wildcard character, one that Vim // cannot expand, requires using a shell. static bool has_special_wildchar(char_u *p) { @@ -1365,9 +1355,7 @@ void FreeWild(int count, char **files) xfree(files); } -/* - * Return TRUE if we can expand this backtick thing here. - */ +/// Return true if we can expand this backtick thing here. static int vim_backtick(char_u *p) { return *p == '`' && *(p + 1) != NUL && *(p + STRLEN(p) - 1) == '`'; @@ -1684,7 +1672,7 @@ void simplify_filename(char_u *filename) static char *eval_includeexpr(const char *const ptr, const size_t len) { set_vim_var_string(VV_FNAME, ptr, (ptrdiff_t)len); - char *res = eval_to_string_safe((char *)curbuf->b_p_inex, NULL, + char *res = eval_to_string_safe(curbuf->b_p_inex, NULL, was_set_insecurely(curwin, "includeexpr", OPT_LOCAL)); set_vim_var_string(VV_FNAME, NULL, 0); return res; @@ -1726,7 +1714,7 @@ char_u *find_file_name_in_path(char_u *ptr, size_t len, int options, long count, ptr = tofree; len = STRLEN(ptr); file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, - TRUE, rel_fname); + true, rel_fname); } } if (file_name == NULL && (options & FNAME_MESS)) { @@ -1740,7 +1728,7 @@ char_u *find_file_name_in_path(char_u *ptr, size_t len, int options, long count, * appears several times in the path. */ while (file_name != NULL && --count > 0) { xfree(file_name); - file_name = find_file_in_path(ptr, len, options, FALSE, rel_fname); + file_name = find_file_in_path(ptr, len, options, false, rel_fname); } } else { file_name = vim_strnsave(ptr, len); @@ -1820,9 +1808,7 @@ bool path_with_extension(const char *path, const char *extension) return strcmp(last_dot + 1, extension) == 0; } -/* - * Return TRUE if "name" is a full (absolute) path name or URL. - */ +/// Return true if "name" is a full (absolute) path name or URL. bool vim_isAbsName(char_u *name) { return path_with_url((char *)name) != 0 || path_is_absolute(name); @@ -1959,21 +1945,17 @@ void path_fix_case(char *name) os_closedir(&dir); } -/* - * Return TRUE if "p" points to just after a path separator. - * Takes care of multi-byte characters. - * "b" must point to the start of the file name - */ +/// Return true if "p" points to just after a path separator. +/// Takes care of multi-byte characters. +/// "b" must point to the start of the file name int after_pathsep(const char *b, const char *p) { return p > b && vim_ispathsep(p[-1]) && utf_head_off((char_u *)b, (char_u *)p - 1) == 0; } -/* - * Return TRUE if file names "f1" and "f2" are in the same directory. - * "f1" may be a short name, "f2" must be a full path. - */ +/// Return true if file names "f1" and "f2" are in the same directory. +/// "f1" may be a short name, "f2" must be a full path. bool same_directory(char_u *f1, char_u *f2) { char ffname[MAXPATHL]; @@ -1985,7 +1967,7 @@ bool same_directory(char_u *f1, char_u *f2) return false; } - (void)vim_FullName((char *)f1, (char *)ffname, MAXPATHL, FALSE); + (void)vim_FullName((char *)f1, (char *)ffname, MAXPATHL, false); t1 = path_tail_with_sep(ffname); t2 = path_tail_with_sep((char *)f2); return t1 - ffname == (char_u *)t2 - f2 @@ -2252,9 +2234,7 @@ int expand_wildcards(int num_pat, char **pat, int *num_files, char ***files, int return retval; } -/* - * Return TRUE if "fname" matches with an entry in 'suffixes'. - */ +/// Return true if "fname" matches with an entry in 'suffixes'. int match_suffix(char_u *fname) { #define MAXSUFLEN 30 // maximum length of a file suffix @@ -2417,7 +2397,7 @@ static int path_to_absolute(const char_u *fname, char_u *buf, size_t len, int fo /// Check if file `fname` is a full (absolute) path. /// -/// @return `TRUE` if "fname" is absolute. +/// @return `true` if "fname" is absolute. int path_is_absolute(const char_u *fname) { #ifdef WIN32 diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 6ce2b4d878..7c914b0276 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -67,9 +67,9 @@ struct qfline_S { char *qf_module; ///< module name for this error char *qf_pattern; ///< search pattern for the error char *qf_text; ///< description of the error - char qf_viscol; ///< set to TRUE if qf_col and qf_end_col is + char qf_viscol; ///< set to true if qf_col and qf_end_col is // screen column - char qf_cleared; ///< set to TRUE if line has been deleted + char qf_cleared; ///< set to true if line has been deleted char qf_type; ///< type of the error (mostly 'E'); 1 for :helpgrep char qf_valid; ///< valid error message detected }; @@ -100,7 +100,7 @@ typedef struct qf_list_S { qfline_T *qf_ptr; ///< pointer to the current error int qf_count; ///< number of errors (0 means empty list) int qf_index; ///< current index in the error list - int qf_nonevalid; ///< TRUE if not a single valid entry found + int qf_nonevalid; ///< true if not a single valid entry found char *qf_title; ///< title derived from the command that created ///< the error list or set by setqflist typval_T *qf_ctx; ///< context set by setqflist/setloclist @@ -1091,7 +1091,7 @@ static int qf_init_ext(qf_info_T *qi, int qf_idx, const char *restrict efile, bu // Use the local value of 'errorformat' if it's set. if (errorformat == p_efm && tv == NULL && buf && *buf->b_p_efm != NUL) { - efm = (char *)buf->b_p_efm; + efm = buf->b_p_efm; } else { efm = errorformat; } @@ -1891,7 +1891,7 @@ static qf_info_T *ll_get_or_alloc_list(win_T *wp) /// Get the quickfix/location list stack to use for the specified Ex command. /// For a location list command, returns the stack for the current window. If /// the location list is not found, then returns NULL and prints an error -/// message if 'print_emsg' is TRUE. +/// message if 'print_emsg' is true. static qf_info_T *qf_cmd_get_stack(exarg_T *eap, int print_emsg) { qf_info_T *qi = &ql_info; @@ -2511,7 +2511,7 @@ static win_T *qf_find_win_with_normal_buf(void) } // Go to a window in any tabpage containing the specified file. Returns true -// if successfully jumped to the window. Otherwise returns FALSE. +// if successfully jumped to the window. Otherwise returns false. static bool qf_goto_tabwin_with_file(int fnum) { FOR_ALL_TAB_WINDOWS(tp, wp) { @@ -2534,7 +2534,7 @@ static int qf_open_new_file_win(qf_info_T *ll_ref) if (win_split(0, flags) == FAIL) { return FAIL; // not enough room for window } - p_swb = empty_option; // don't split again + p_swb = (char_u *)empty_option; // don't split again swb_flags = 0; RESET_BINDING(curwin); if (ll_ref != NULL) { @@ -2994,7 +2994,7 @@ theend: qfl->qf_ptr = qf_ptr; qfl->qf_index = qf_index; } - if (p_swb != (char_u *)old_swb && p_swb == empty_option) { + if (p_swb != (char_u *)old_swb && p_swb == (char_u *)empty_option) { // Restore old 'switchbuf' value, but not when an autocommand or // modeline has changed the value. p_swb = (char_u *)old_swb; @@ -3393,7 +3393,7 @@ bool qf_mark_adjust(win_T *wp, linenr_T line1, linenr_T line2, linenr_T amount, found_one = true; if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2) { if (amount == MAXLNUM) { - qfp->qf_cleared = TRUE; + qfp->qf_cleared = true; } else { qfp->qf_lnum += amount; } @@ -3747,7 +3747,7 @@ linenr_T qf_current_entry(win_T *wp) } /// Update the cursor position in the quickfix window to the current error. -/// Return TRUE if there is a quickfix window. +/// Return true if there is a quickfix window. /// /// @param old_qf_index previous qf_index or zero static bool qf_win_pos_update(qf_info_T *qi, int old_qf_index) @@ -4175,7 +4175,7 @@ static void qf_jump_first(qf_info_T *qi, unsigned save_qfid, int forceit) } } -// Return TRUE when using ":vimgrep" for ":grep". +// Return true when using ":vimgrep" for ":grep". int grep_internal(cmdidx_T cmdidx) { return (cmdidx == CMD_grep @@ -4183,7 +4183,7 @@ int grep_internal(cmdidx_T cmdidx) || cmdidx == CMD_grepadd || cmdidx == CMD_lgrepadd) && STRCMP("internal", - *curbuf->b_p_gp == NUL ? p_gp : curbuf->b_p_gp) == 0; + *curbuf->b_p_gp == NUL ? p_gp : (char_u *)curbuf->b_p_gp) == 0; } // Return the make/grep autocmd name. @@ -4241,7 +4241,7 @@ static char *make_get_fullcmd(const char *makecmd, const char *fname) // Used for ":make", ":lmake", ":grep", ":lgrep", ":grepadd", and ":lgrepadd" void ex_make(exarg_T *eap) { - char *enc = (*curbuf->b_p_menc != NUL) ? (char *)curbuf->b_p_menc : (char *)p_menc; + char *enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : (char *)p_menc; // Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". if (grep_internal(eap->cmdidx)) { @@ -4832,7 +4832,7 @@ static void qf_get_nth_below_entry(qfline_T *entry_arg, linenr_T n, bool linewis } /// Get the nth quickfix entry above the specified entry. Searches backwards in -/// the list. If linewise is TRUE, then treat multiple entries on a single line +/// the list. If linewise is true, then treat multiple entries on a single line /// as one. static void qf_get_nth_above_entry(qfline_T *entry, linenr_T n, bool linewise, int *errornr) FUNC_ATTR_NONNULL_ALL @@ -4981,7 +4981,7 @@ void ex_cfile(exarg_T *eap) set_string_option_direct("ef", -1, eap->arg, OPT_FREE, 0); } - char *enc = (*curbuf->b_p_menc != NUL) ? (char *)curbuf->b_p_menc : (char *)p_menc; + char *enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : (char *)p_menc; if (is_loclist_cmd(eap->cmdidx)) { wp = curwin; @@ -5305,7 +5305,7 @@ static int vgr_process_args(exarg_T *eap, vgr_args_T *args) } // Parse the list of arguments, wildcards have already been expanded. - if (get_arglist_exp((char_u *)p, &args->fcount, &args->fnames, true) == FAIL) { + if (get_arglist_exp(p, &args->fcount, &args->fnames, true) == FAIL) { return FAIL; } if (args->fcount == 0) { @@ -5429,7 +5429,7 @@ static int vgr_process_files(win_T *wp, qf_info_T *qi, vgr_args_T *cmd_args, boo // options! aco_save_T aco; aucmd_prepbuf(&aco, buf); - apply_autocmds(EVENT_FILETYPE, (char *)buf->b_p_ft, buf->b_fname, true, buf); + apply_autocmds(EVENT_FILETYPE, buf->b_p_ft, buf->b_fname, true, buf); do_modelines(OPT_NOWIN); aucmd_restbuf(&aco); } @@ -5609,7 +5609,7 @@ static buf_T *load_dummy_buffer(char *fname, char *dirname_start, char *resultin if (readfile_result == OK && !got_int && !(curbuf->b_flags & BF_NEW)) { - failed = FALSE; + failed = false; if (curbuf != newbuf) { // Bloody autocommands changed the buffer! Can happen when // using netrw and editing a remote file. Use the current @@ -5677,7 +5677,7 @@ static void wipe_dummy_buffer(buf_T *buf, char *dirname_start) cleanup_T cs; // Reset the error/interrupt/exception state here so that aborting() - // returns FALSE when wiping out the buffer. Otherwise it doesn't + // returns false when wiping out the buffer. Otherwise it doesn't // work when got_int is set. enter_cleanup(&cs); @@ -7065,7 +7065,7 @@ void ex_helpgrep(exarg_T *eap) bool updated = false; // Make 'cpoptions' empty, the 'l' flag should not be used here. char *const save_cpo = p_cpo; - p_cpo = (char *)empty_option; + p_cpo = empty_option; bool new_qi = false; if (is_loclist_cmd(eap->cmdidx)) { @@ -7096,7 +7096,7 @@ void ex_helpgrep(exarg_T *eap) updated = true; } - if ((char_u *)p_cpo == empty_option) { + if (p_cpo == empty_option) { p_cpo = save_cpo; } else { // Darn, some plugin changed the value. If it's still empty it was @@ -7104,7 +7104,7 @@ void ex_helpgrep(exarg_T *eap) if (*p_cpo == NUL) { set_option_value_give_err("cpo", 0L, save_cpo, 0); } - free_string_option((char_u *)save_cpo); + free_string_option(save_cpo); } if (updated) { diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 58e195b745..43c85bedb5 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -69,7 +69,7 @@ bool conceal_cursor_line(const win_T *wp) } else { return false; } - return vim_strchr((char *)wp->w_p_cocu, c) != NULL; + return vim_strchr(wp->w_p_cocu, c) != NULL; } /// Whether cursorline is drawn in a special way @@ -535,7 +535,7 @@ bool get_keymap_str(win_T *wp, char *fmt, char *buf, int len) curwin = old_curwin; if (p == NULL || *p == NUL) { if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) { - p = (char *)wp->w_buffer->b_p_keymap; + p = wp->w_buffer->b_p_keymap; } else { p = "lang"; } @@ -1262,17 +1262,15 @@ int number_width(win_T *wp) /// Calls mb_cptr2char_adv(p) and returns the character. /// If "p" starts with "\x", "\u" or "\U" the hex or unicode value is used. /// Returns 0 for invalid hex or invalid UTF-8 byte. -static int get_encoded_char_adv(char_u **p) +static int get_encoded_char_adv(const char_u **p) { - char_u *s = *p; + const char_u *s = *p; if (s[0] == '\\' && (s[1] == 'x' || s[1] == 'u' || s[1] == 'U')) { int64_t num = 0; - int bytes; - int n; - for (bytes = s[1] == 'x' ? 1 : s[1] == 'u' ? 2 : 4; bytes > 0; bytes--) { + for (int bytes = s[1] == 'x' ? 1 : s[1] == 'u' ? 2 : 4; bytes > 0; bytes--) { *p += 2; - n = hexhex2nr(*p); + int n = hexhex2nr(*p); if (n < 0) { return 0; } @@ -1283,8 +1281,8 @@ static int get_encoded_char_adv(char_u **p) } // TODO(bfredl): use schar_T representation and utfc_ptr2len - int clen = utf_ptr2len((char *)s); - int c = mb_cptr2char_adv((const char_u **)p); + int clen = utf_ptr2len((const char *)s); + int c = mb_cptr2char_adv(p); if (clen == 1 && c > 127) { // Invalid UTF-8 byte return 0; } @@ -1294,26 +1292,22 @@ static int get_encoded_char_adv(char_u **p) /// Handle setting 'listchars' or 'fillchars'. /// Assume monocell characters /// -/// @param varp either &curwin->w_p_lcs or &curwin->w_p_fcs +/// @param varp either the global or the window-local value. +/// @param apply if false, do not store the flags, only check for errors. /// @return error message, NULL if it's OK. -char *set_chars_option(win_T *wp, char_u **varp, bool set) +char *set_chars_option(win_T *wp, char_u **varp, bool apply) { - int round, i, len, len2, entries; - char_u *p, *s; - int c1; - int c2 = 0; - int c3 = 0; - char_u *last_multispace = NULL; // Last occurrence of "multispace:" - char_u *last_lmultispace = NULL; // Last occurrence of "leadmultispace:" + const char_u *last_multispace = NULL; // Last occurrence of "multispace:" + const char_u *last_lmultispace = NULL; // Last occurrence of "leadmultispace:" int multispace_len = 0; // Length of lcs-multispace string int lead_multispace_len = 0; // Length of lcs-leadmultispace string + const bool is_listchars = (varp == &p_lcs || varp == (char_u **)&wp->w_p_lcs); struct chars_tab { - int *cp; ///< char value + int *cp; ///< char value char *name; ///< char id - int def; ///< default value + int def; ///< default value }; - struct chars_tab *tab; // XXX: Characters taking 2 columns is forbidden (TUI limitation?). Set old defaults in this case. struct chars_tab fcs_tab[] = { @@ -1335,6 +1329,7 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) { &wp->w_p_fcs_chars.msgsep, "msgsep", ' ' }, { &wp->w_p_fcs_chars.eob, "eob", '~' }, }; + struct chars_tab lcs_tab[] = { { &wp->w_p_lcs_chars.eol, "eol", NUL }, { &wp->w_p_lcs_chars.ext, "extends", NUL }, @@ -1347,30 +1342,33 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) { &wp->w_p_lcs_chars.conceal, "conceal", NUL }, }; - if (varp == &p_lcs || varp == &wp->w_p_lcs) { + struct chars_tab *tab; + int entries; + const char_u *value = *varp; + if (is_listchars) { tab = lcs_tab; entries = ARRAY_SIZE(lcs_tab); - if (varp == &wp->w_p_lcs && wp->w_p_lcs[0] == NUL) { - varp = &p_lcs; + if (varp == (char_u **)&wp->w_p_lcs && wp->w_p_lcs[0] == NUL) { + value = p_lcs; // local value is empty, use the global value } } else { tab = fcs_tab; entries = ARRAY_SIZE(fcs_tab); - if (varp == &wp->w_p_fcs && wp->w_p_fcs[0] == NUL) { - varp = &p_fcs; + if (varp == (char_u **)&wp->w_p_fcs && wp->w_p_fcs[0] == NUL) { + value = p_fcs; // local value is empty, use the global value } } // first round: check for valid value, second round: assign values - for (round = 0; round <= (set ? 1 : 0); round++) { + for (int round = 0; round <= (apply ? 1 : 0); round++) { if (round > 0) { // After checking that the value is valid: set defaults - for (i = 0; i < entries; i++) { + for (int i = 0; i < entries; i++) { if (tab[i].cp != NULL) { *(tab[i].cp) = tab[i].def; } } - if (varp == &p_lcs || varp == &wp->w_p_lcs) { + if (is_listchars) { wp->w_p_lcs_chars.tab1 = NUL; wp->w_p_lcs_chars.tab3 = NUL; @@ -1392,19 +1390,20 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) } } } - p = *varp; + const char_u *p = value; while (*p) { + int i; for (i = 0; i < entries; i++) { - len = (int)STRLEN(tab[i].name); + const size_t len = STRLEN(tab[i].name); if (STRNCMP(p, tab[i].name, len) == 0 && p[len] == ':' && p[len + 1] != NUL) { - c2 = c3 = 0; - s = p + len + 1; - c1 = get_encoded_char_adv(&s); + const char_u *s = p + len + 1; + int c1 = get_encoded_char_adv(&s); if (c1 == 0 || char2cells(c1) > 1) { return e_invarg; } + int c2 = 0, c3 = 0; if (tab[i].cp == &wp->w_p_lcs_chars.tab2) { if (*s == NUL) { return e_invarg; @@ -1437,19 +1436,19 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) } if (i == entries) { - len = (int)STRLEN("multispace"); - len2 = (int)STRLEN("leadmultispace"); - if ((varp == &p_lcs || varp == &wp->w_p_lcs) + const size_t len = STRLEN("multispace"); + const size_t len2 = STRLEN("leadmultispace"); + if (is_listchars && STRNCMP(p, "multispace", len) == 0 && p[len] == ':' && p[len + 1] != NUL) { - s = p + len + 1; + const char_u *s = p + len + 1; if (round == 0) { // Get length of lcs-multispace string in the first round last_multispace = p; multispace_len = 0; while (*s != NUL && *s != ',') { - c1 = get_encoded_char_adv(&s); + int c1 = get_encoded_char_adv(&s); if (c1 == 0 || char2cells(c1) > 1) { return e_invarg; } @@ -1463,24 +1462,24 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) } else { int multispace_pos = 0; while (*s != NUL && *s != ',') { - c1 = get_encoded_char_adv(&s); + int c1 = get_encoded_char_adv(&s); if (p == last_multispace) { wp->w_p_lcs_chars.multispace[multispace_pos++] = c1; } } p = s; } - } else if ((varp == &p_lcs || varp == &wp->w_p_lcs) + } else if (is_listchars && STRNCMP(p, "leadmultispace", len2) == 0 && p[len2] == ':' && p[len2 + 1] != NUL) { - s = p + len2 + 1; + const char_u *s = p + len2 + 1; if (round == 0) { // get length of lcs-leadmultispace string in first round last_lmultispace = p; lead_multispace_len = 0; while (*s != NUL && *s != ',') { - c1 = get_encoded_char_adv(&s); + int c1 = get_encoded_char_adv(&s); if (c1 == 0 || char2cells(c1) > 1) { return e_invarg; } @@ -1494,7 +1493,7 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) } else { int multispace_pos = 0; while (*s != NUL && *s != ',') { - c1 = get_encoded_char_adv(&s); + int c1 = get_encoded_char_adv(&s); if (p == last_lmultispace) { wp->w_p_lcs_chars.leadmultispace[multispace_pos++] = c1; } @@ -1505,6 +1504,7 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) return e_invarg; } } + if (*p == ',') { p++; } @@ -1527,10 +1527,10 @@ char *check_chars_options(void) return e_conflicts_with_value_of_fillchars; } FOR_ALL_TAB_WINDOWS(tp, wp) { - if (set_chars_option(wp, &wp->w_p_lcs, true) != NULL) { + if (set_chars_option(wp, (char_u **)&wp->w_p_lcs, true) != NULL) { return e_conflicts_with_value_of_listchars; } - if (set_chars_option(wp, &wp->w_p_fcs, true) != NULL) { + if (set_chars_option(wp, (char_u **)&wp->w_p_fcs, true) != NULL) { return e_conflicts_with_value_of_fillchars; } } diff --git a/src/nvim/search.c b/src/nvim/search.c index 6e5e12dd17..3b6bcbeeb3 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -354,10 +354,8 @@ char_u *last_search_pattern(void) return spats[RE_SEARCH].pat; } -/* - * Return TRUE when case should be ignored for search pattern "pat". - * Uses the 'ignorecase' and 'smartcase' options. - */ +/// Return true when case should be ignored for search pattern "pat". +/// Uses the 'ignorecase' and 'smartcase' options. int ignorecase(char_u *pat) { return ignorecase_opt(pat, p_ic, p_scs); @@ -423,7 +421,7 @@ int last_csearch_forward(void) int last_csearch_until(void) { - return last_t_cmd == TRUE; + return last_t_cmd == true; } void set_last_csearch(int c, char_u *s, int len) @@ -480,8 +478,8 @@ void set_last_search_pat(const char_u *s, int idx, int magic, int setlast) spats[idx].no_scs = false; spats[idx].off.dir = '/'; set_vv_searchforward(); - spats[idx].off.line = FALSE; - spats[idx].off.end = FALSE; + spats[idx].off.line = false; + spats[idx].off.end = false; spats[idx].off.off = 0; if (setlast) { last_idx = idx; @@ -610,11 +608,11 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir, start_pos = *pos; // remember start pos for detecting no match found = 0; // default: not found - at_first_line = TRUE; // default: start in first line + at_first_line = true; // default: start in first line if (pos->lnum == 0) { // correct lnum for when starting in line 0 pos->lnum = 1; pos->col = 0; - at_first_line = FALSE; // not in first line now + at_first_line = false; // not in first line now } /* @@ -627,14 +625,14 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir, if (dir == BACKWARD && start_pos.col == 0 && (options & SEARCH_START) == 0) { lnum = pos->lnum - 1; - at_first_line = FALSE; + at_first_line = false; } else { lnum = pos->lnum; } for (loop = 0; loop <= 1; loop++) { // loop twice if 'wrapscan' set for (; lnum > 0 && lnum <= buf->b_ml.ml_line_count; - lnum += dir, at_first_line = FALSE) { + lnum += dir, at_first_line = false) { // Stop after checking "stop_lnum", if it's set. if (stop_lnum != 0 && (dir == FORWARD ? lnum > stop_lnum : lnum < stop_lnum)) { @@ -901,7 +899,7 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir, break; // if second loop, stop where started } } - at_first_line = FALSE; + at_first_line = false; // vim_regexec_multi() may clear "regprog" if (regmatch.regprog == NULL) { @@ -1006,22 +1004,22 @@ static int first_submatch(regmmatch_T *rp) /// Highest level string search function. /// Search for the 'count'th occurrence of pattern 'pat' in direction 'dirc' /// -/// Careful: If spats[0].off.line == TRUE and spats[0].off.off == 0 this +/// Careful: If spats[0].off.line == true and spats[0].off.off == 0 this /// makes the movement linewise without moving the match position. /// /// @param dirc if 0: use previous dir. /// @param pat NULL or empty : use previous string. -/// @param options if TRUE and -/// SEARCH_REV == TRUE : go in reverse of previous dir. -/// SEARCH_ECHO == TRUE : echo the search command and handle options -/// SEARCH_MSG == TRUE : may give error message -/// SEARCH_OPT == TRUE : interpret optional flags -/// SEARCH_HIS == TRUE : put search pattern in history -/// SEARCH_NOOF == TRUE : don't add offset to position -/// SEARCH_MARK == TRUE : set previous context mark -/// SEARCH_KEEP == TRUE : keep previous search pattern -/// SEARCH_START == TRUE : accept match at curpos itself -/// SEARCH_PEEK == TRUE : check for typed char, cancel search +/// @param options if true and +/// SEARCH_REV == true : go in reverse of previous dir. +/// SEARCH_ECHO == true : echo the search command and handle options +/// SEARCH_MSG == true : may give error message +/// SEARCH_OPT == true : interpret optional flags +/// SEARCH_HIS == true : put search pattern in history +/// SEARCH_NOOF == true : don't add offset to position +/// SEARCH_MARK == true : set previous context mark +/// SEARCH_KEEP == true : keep previous search pattern +/// SEARCH_START == true : accept match at curpos itself +/// SEARCH_PEEK == true : check for typed char, cancel search /// @param oap can be NULL /// @param dirc '/' or '?' /// @param search_delim delimiter for search, e.g. '%' in s%regex%replacement @@ -1137,8 +1135,8 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, dircp = p; // remember where we put the NUL *p++ = NUL; } - spats[0].off.line = FALSE; - spats[0].off.end = FALSE; + spats[0].off.line = false; + spats[0].off.end = false; spats[0].off.off = 0; // Check for a line offset or a character offset. // For get_address (echo off) we don't check for a character @@ -1435,7 +1433,7 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, setpcmark(); } curwin->w_cursor = pos; - curwin->w_set_curswant = TRUE; + curwin->w_set_curswant = true; end_do_search: if ((options & SEARCH_KEEP) || (cmdmod.cmod_flags & CMOD_KEEPPATTERNS)) { @@ -1519,12 +1517,10 @@ int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char_u *pat) * Character Searches */ -/* - * Search for a character in a line. If "t_cmd" is FALSE, move to the - * position of the character, otherwise move to just before the char. - * Do this "cap->count1" times. - * Return FAIL or OK. - */ +/// Search for a character in a line. If "t_cmd" is false, move to the +/// position of the character, otherwise move to just before the char. +/// Do this "cap->count1" times. +/// Return FAIL or OK. int searchc(cmdarg_T *cap, int t_cmd) FUNC_ATTR_NONNULL_ALL { @@ -1696,34 +1692,34 @@ static bool find_rawstring_end(char_u *linep, pos_T *startpos, pos_T *endpos) static void find_mps_values(int *initc, int *findc, bool *backwards, bool switchit) FUNC_ATTR_NONNULL_ALL { - char_u *ptr = curbuf->b_p_mps; + char *ptr = curbuf->b_p_mps; while (*ptr != NUL) { - if (utf_ptr2char((char *)ptr) == *initc) { + if (utf_ptr2char(ptr) == *initc) { if (switchit) { *findc = *initc; - *initc = utf_ptr2char((char *)ptr + utfc_ptr2len((char *)ptr) + 1); + *initc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1); *backwards = true; } else { - *findc = utf_ptr2char((char *)ptr + utfc_ptr2len((char *)ptr) + 1); + *findc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1); *backwards = false; } return; } - char_u *prev = ptr; - ptr += utfc_ptr2len((char *)ptr) + 1; - if (utf_ptr2char((char *)ptr) == *initc) { + char *prev = ptr; + ptr += utfc_ptr2len(ptr) + 1; + if (utf_ptr2char(ptr) == *initc) { if (switchit) { *findc = *initc; - *initc = utf_ptr2char((char *)prev); + *initc = utf_ptr2char(prev); *backwards = false; } else { - *findc = utf_ptr2char((char *)prev); + *findc = utf_ptr2char(prev); *backwards = true; } return; } - ptr += utfc_ptr2len((char *)ptr); + ptr += utfc_ptr2len(ptr); if (*ptr == ',') { ptr++; } @@ -2376,7 +2372,7 @@ void showmatch(int c) * Only show match for chars in the 'matchpairs' option. */ // 'matchpairs' is "x:y,x:y" - for (p = curbuf->b_p_mps; *p != NUL; p++) { + for (p = (char_u *)curbuf->b_p_mps; *p != NUL; p++) { if (utf_ptr2char((char *)p) == c && (curwin->w_p_rl ^ p_ri)) { break; } @@ -2520,7 +2516,7 @@ int findsent(Direction dir, long count) for (;;) { // find end of sentence c = gchar_pos(&pos); - if (c == NUL || (pos.col == 0 && startPS(pos.lnum, NUL, FALSE))) { + if (c == NUL || (pos.col == 0 && startPS(pos.lnum, NUL, false))) { if (dir == BACKWARD && pos.lnum != startlnum) { pos.lnum++; } @@ -2581,11 +2577,11 @@ found: /// Paragraphs are currently supposed to be separated by empty lines. /// If 'what' is NUL we go to the next paragraph. /// If 'what' is '{' or '}' we go to the next section. -/// If 'both' is TRUE also stop at '}'. +/// If 'both' is true also stop at '}'. /// /// @param pincl Return: true if last char is to be included /// -/// @return TRUE if the next paragraph or section was found. +/// @return true if the next paragraph or section was found. bool findpar(bool *pincl, int dir, long count, int what, int both) { linenr_T curr; @@ -2676,11 +2672,9 @@ static int inmacro(char_u *opt, char_u *s) return macro[0] != NUL; } -/* - * startPS: return TRUE if line 'lnum' is the start of a section or paragraph. - * If 'para' is '{' or '}' only check for sections. - * If 'both' is TRUE also stop at '}' - */ +/// startPS: return true if line 'lnum' is the start of a section or paragraph. +/// If 'para' is '{' or '}' only check for sections. +/// If 'both' is true also stop at '}' int startPS(linenr_T lnum, int para, int both) { char_u *s; @@ -2712,12 +2706,12 @@ int startPS(linenr_T lnum, int para, int both) * 2 or higher - keyword characters (letters, digits and underscore) */ -static int cls_bigword; // TRUE for "W", "B" or "E" +static int cls_bigword; // true for "W", "B" or "E" /* * cls() - returns the class of character at curwin->w_cursor * - * If a 'W', 'B', or 'E' motion is being done (cls_bigword == TRUE), chars + * If a 'W', 'B', or 'E' motion is being done (cls_bigword == true), chars * from class 2 and higher are reported as class 1 since only white space * boundaries are of interest. */ @@ -2732,7 +2726,7 @@ static int cls(void) c = utf_class(c); - // If cls_bigword is TRUE, report all non-blanks as class 1. + // If cls_bigword is true, report all non-blanks as class 1. if (c != 0 && cls_bigword) { return 1; } @@ -2742,7 +2736,7 @@ static int cls(void) /// fwd_word(count, type, eol) - move forward one word /// /// @return FAIL if the cursor was already at the end of the file. -/// If eol is TRUE, last word stops at end of line (for operators). +/// If eol is true, last word stops at end of line (for operators). /// /// @param bigword "W", "E" or "B" int fwd_word(long count, int bigword, int eol) @@ -2809,7 +2803,7 @@ int fwd_word(long count, int bigword, int eol) /* * bck_word() - move backward 'count' words * - * If stop is TRUE and we are already on the start of a word, move one less. + * If stop is true and we are already on the start of a word, move one less. * * Returns FAIL if top of the file was reached. */ @@ -2855,7 +2849,7 @@ int bck_word(long count, int bigword, int stop) inc_cursor(); // overshot - forward one finished: - stop = FALSE; + stop = false; } return OK; } @@ -2872,8 +2866,8 @@ finished: * * Returns FAIL if end of the file was reached. * - * If stop is TRUE and we are already on the end of a word, move one less. - * If empty is TRUE stop on an empty line. + * If stop is true and we are already on the end of a word, move one less. + * If empty is true stop on an empty line. */ int end_word(long count, int bigword, int stop, int empty) { @@ -2906,7 +2900,7 @@ int end_word(long count, int bigword, int stop, int empty) } else if (!stop || sclass == 0) { /* * We were at the end of a word. Go to the end of the next word. - * First skip white space, if 'empty' is TRUE, stop at empty line. + * First skip white space, if 'empty' is true, stop at empty line. */ while (cls() == 0) { if (empty && curwin->w_cursor.col == 0 @@ -2927,14 +2921,14 @@ int end_word(long count, int bigword, int stop, int empty) } dec_cursor(); // overshot - one char backward finished: - stop = FALSE; // we move only one word less + stop = false; // we move only one word less } return OK; } /// Move back to the end of the word. /// -/// @param bigword TRUE for "B" +/// @param bigword true for "B" /// @param eol if true, then stop at end of line. /// /// @return FAIL if start of the file was reached. @@ -3046,14 +3040,14 @@ static void findsent_forward(long count, bool at_start_sent) /// Find word under cursor, cursor at end. /// Used while an operator is pending, and in Visual mode. /// -/// @param include TRUE: include word and white space -/// @param bigword FALSE == word, TRUE == WORD +/// @param include true: include word and white space +/// @param bigword false == word, true == WORD int current_word(oparg_T *oap, long count, int include, int bigword) { pos_T start_pos; pos_T pos; bool inclusive = true; - int include_white = FALSE; + int include_white = false; cls_bigword = bigword; clearpos(&start_pos); @@ -3080,7 +3074,7 @@ int current_word(oparg_T *oap, long count, int include, int bigword) * not be included ("word"), find end of word. */ if ((cls() == 0) == include) { - if (end_word(1L, bigword, TRUE, TRUE) == FAIL) { + if (end_word(1L, bigword, true, true) == FAIL) { return FAIL; } } else { @@ -3091,7 +3085,7 @@ int current_word(oparg_T *oap, long count, int include, int bigword) * If we end up in the first column of the next line (single char * word) back up to end of the line. */ - fwd_word(1L, bigword, TRUE); + fwd_word(1L, bigword, true); if (curwin->w_cursor.col == 0) { decl(&curwin->w_cursor); } else { @@ -3099,7 +3093,7 @@ int current_word(oparg_T *oap, long count, int include, int bigword) } if (include) { - include_white = TRUE; + include_white = true; } } @@ -3127,7 +3121,7 @@ int current_word(oparg_T *oap, long count, int include, int bigword) return FAIL; } if (include != (cls() != 0)) { - if (bck_word(1L, bigword, TRUE) == FAIL) { + if (bck_word(1L, bigword, true) == FAIL) { return FAIL; } } else { @@ -3144,7 +3138,7 @@ int current_word(oparg_T *oap, long count, int include, int bigword) return FAIL; } if (include != (cls() == 0)) { - if (fwd_word(1L, bigword, TRUE) == FAIL && count > 1) { + if (fwd_word(1L, bigword, true) == FAIL && count > 1) { return FAIL; } /* @@ -3156,7 +3150,7 @@ int current_word(oparg_T *oap, long count, int include, int bigword) inclusive = false; } } else { - if (end_word(1L, bigword, TRUE, TRUE) == FAIL) { + if (end_word(1L, bigword, true, true) == FAIL) { return FAIL; } } @@ -3378,7 +3372,7 @@ extend: /// Find block under the cursor, cursor at end. /// "what" and "other" are two matching parenthesis/brace/etc. /// -/// @param include TRUE == include white space +/// @param include true == include white space /// @param what '(', '{', etc. /// @param other ')', '}', etc. int current_block(oparg_T *oap, long count, int include, int what, int other) @@ -3453,7 +3447,7 @@ int current_block(oparg_T *oap, long count, int include, int what, int other) } curwin->w_cursor = *end_pos; - // Try to exclude the '(', '{', ')', '}', etc. when "include" is FALSE. + // Try to exclude the '(', '{', ')', '}', etc. when "include" is false. // If the ending '}', ')' or ']' is only preceded by indent, skip that // indent. But only if the resulting area is not smaller than what we // started with. @@ -3764,7 +3758,7 @@ theend: return retval; } -/// @param include TRUE == include white space +/// @param include true == include white space /// @param type 'p' for paragraph, 'S' for section int current_par(oparg_T *oap, long count, int include, int type) { @@ -3775,7 +3769,7 @@ int current_par(oparg_T *oap, long count, int include, int type) int start_is_white; int prev_start_is_white; int retval = OK; - int do_white = FALSE; + int do_white = false; int t; int i; @@ -4090,8 +4084,7 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar) if (col_start < 0) { goto abort_search; } - col_end = find_next_quote(line, col_start + 1, quotechar, - curbuf->b_p_qe); + col_end = find_next_quote(line, col_start + 1, quotechar, (char_u *)curbuf->b_p_qe); if (col_end < 0) { // We were on a starting quote perhaps? col_end = col_start; @@ -4102,8 +4095,7 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar) if (line[col_end] != quotechar) { goto abort_search; } - col_start = find_prev_quote(line, col_end, quotechar, - curbuf->b_p_qe); + col_start = find_prev_quote(line, col_end, quotechar, (char_u *)curbuf->b_p_qe); if (line[col_start] != quotechar) { // We were on an ending quote perhaps? col_start = col_end; @@ -4132,8 +4124,7 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar) goto abort_search; } // Find close quote character. - col_end = find_next_quote(line, col_start + 1, quotechar, - curbuf->b_p_qe); + col_end = find_next_quote(line, col_start + 1, quotechar, (char_u *)curbuf->b_p_qe); if (col_end < 0) { goto abort_search; } @@ -4146,7 +4137,7 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar) } } else { // Search backward for a starting quote. - col_start = find_prev_quote(line, col_start, quotechar, curbuf->b_p_qe); + col_start = find_prev_quote(line, col_start, quotechar, (char_u *)curbuf->b_p_qe); if (line[col_start] != quotechar) { // No quote before the cursor, look after the cursor. col_start = find_next_quote(line, col_start, quotechar, NULL); @@ -4156,8 +4147,7 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar) } // Find close quote character. - col_end = find_next_quote(line, col_start + 1, quotechar, - curbuf->b_p_qe); + col_end = find_next_quote(line, col_start + 1, quotechar, (char_u *)curbuf->b_p_qe); if (col_end < 0) { goto abort_search; } @@ -4398,7 +4388,7 @@ int current_search(long count, bool forward) /// If move is true, check from the beginning of the buffer, /// else from position "cur". /// "direction" is FORWARD or BACKWARD. -/// Returns TRUE, FALSE or -1 for failure. +/// Returns true, false or -1 for failure. static int is_zero_width(char_u *pattern, int move, pos_T *cur, Direction direction) { regmmatch_T regmatch; @@ -4455,9 +4445,7 @@ static int is_zero_width(char_u *pattern, int move, pos_T *cur, Direction direct return result; } -/* - * return TRUE if line 'lnum' is empty or has white chars only. - */ +/// return true if line 'lnum' is empty or has white chars only. int linewhite(linenr_T lnum) { char_u *p; @@ -5375,22 +5363,22 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo goto fpip_end; } } - inc_opt = (*curbuf->b_p_inc == NUL) ? p_inc : curbuf->b_p_inc; + inc_opt = (*curbuf->b_p_inc == NUL) ? p_inc : (char_u *)curbuf->b_p_inc; if (*inc_opt != NUL) { incl_regmatch.regprog = vim_regcomp((char *)inc_opt, p_magic ? RE_MAGIC : 0); if (incl_regmatch.regprog == NULL) { goto fpip_end; } - incl_regmatch.rm_ic = FALSE; // don't ignore case in incl. pat. + incl_regmatch.rm_ic = false; // don't ignore case in incl. pat. } if (type == FIND_DEFINE && (*curbuf->b_p_def != NUL || *p_def != NUL)) { def_regmatch.regprog = vim_regcomp(*curbuf->b_p_def == NUL - ? (char *)p_def : (char *)curbuf->b_p_def, + ? (char *)p_def : curbuf->b_p_def, p_magic ? RE_MAGIC : 0); if (def_regmatch.regprog == NULL) { goto fpip_end; } - def_regmatch.rm_ic = FALSE; // don't ignore case in define pat. + def_regmatch.rm_ic = false; // don't ignore case in define pat. } files = xcalloc((size_t)max_path_depth, sizeof(SearchedFile)); old_files = max_path_depth; @@ -5423,7 +5411,7 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo new_fname = file_name_in_line(incl_regmatch.endp[0], 0, FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname, NULL); } - already_searched = FALSE; + already_searched = false; if (new_fname != NULL) { // Check whether we have already searched in this file for (i = 0;; i++) { @@ -5543,7 +5531,7 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo bigger[i].fp = NULL; bigger[i].name = NULL; bigger[i].lnum = 0; - bigger[i].matched = FALSE; + bigger[i].matched = false; } for (i = old_files; i < max_path_depth; i++) { bigger[i + max_path_depth] = files[i]; @@ -5564,7 +5552,7 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo } files[depth].name = curr_fname = new_fname; files[depth].lnum = 0; - files[depth].matched = FALSE; + files[depth].matched = false; if (action == ACTION_EXPAND) { msg_hist_off = true; // reset in msg_trunc_attr() vim_snprintf((char *)IObuff, IOSIZE, @@ -5818,7 +5806,7 @@ search_line: } if (action != ACTION_SHOW) { curwin->w_cursor.col = (colnr_T)(startp - line); - curwin->w_set_curswant = TRUE; + curwin->w_set_curswant = true; } if (l_g_do_tagpreview != 0 @@ -5961,7 +5949,7 @@ static void show_pat_in_path(char_u *line, int type, bool did_show, int action, msg_puts_attr((const char *)IObuff, HL_ATTR(HLF_N)); msg_puts(" "); } - msg_prt_line(line, FALSE); + msg_prt_line(line, false); ui_flush(); // show one line at a time // Definition continues until line that doesn't end with '\' diff --git a/src/nvim/spell.c b/src/nvim/spell.c index ecb97afd02..439fcff8a0 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1837,7 +1837,7 @@ char *did_set_spelllang(win_T *wp) // Make a copy of 'spelllang', the SpellFileMissing autocommands may change // it under our fingers. - spl_copy = vim_strsave(wp->w_s->b_p_spl); + spl_copy = vim_strsave((char_u *)wp->w_s->b_p_spl); wp->w_s->b_cjk = 0; @@ -1966,7 +1966,7 @@ char *did_set_spelllang(win_T *wp) // round 1: load first name in 'spellfile'. // round 2: load second name in 'spellfile. // etc. - spf = (char *)curwin->w_s->b_p_spf; + spf = curwin->w_s->b_p_spf; for (round = 0; round == 0 || *spf != NUL; round++) { if (round == 0) { // Internal wordlist, if there is one. @@ -2120,13 +2120,13 @@ static void use_midword(slang_T *lp, win_T *wp) wp->w_s->b_spell_ismw[c] = true; } else if (wp->w_s->b_spell_ismw_mb == NULL) { // First multi-byte char in "b_spell_ismw_mb". - wp->w_s->b_spell_ismw_mb = vim_strnsave(p, (size_t)l); + wp->w_s->b_spell_ismw_mb = (char *)vim_strnsave(p, (size_t)l); } else { // Append multi-byte chars to "b_spell_ismw_mb". const int n = (int)STRLEN(wp->w_s->b_spell_ismw_mb); - char_u *bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, (size_t)n + (size_t)l); + char_u *bp = vim_strnsave((char_u *)wp->w_s->b_spell_ismw_mb, (size_t)n + (size_t)l); xfree(wp->w_s->b_spell_ismw_mb); - wp->w_s->b_spell_ismw_mb = bp; + wp->w_s->b_spell_ismw_mb = (char *)bp; STRLCPY(bp + n, p, l + 1); } p += l; @@ -2359,7 +2359,7 @@ bool spell_iswordp(const char_u *p, const win_T *wp) if (c < 256 ? wp->w_s->b_spell_ismw[c] : (wp->w_s->b_spell_ismw_mb != NULL - && vim_strchr((char *)wp->w_s->b_spell_ismw_mb, c) != NULL)) { + && vim_strchr(wp->w_s->b_spell_ismw_mb, c) != NULL)) { s = p + l; } } @@ -2405,7 +2405,7 @@ static bool spell_iswordp_w(const int *p, const win_T *wp) if (*p < 256 ? wp->w_s->b_spell_ismw[*p] : (wp->w_s->b_spell_ismw_mb != NULL - && vim_strchr((char *)wp->w_s->b_spell_ismw_mb, + && vim_strchr(wp->w_s->b_spell_ismw_mb, *p) != NULL)) { s = p + 1; } else { @@ -3599,7 +3599,7 @@ char *compile_cap_prog(synblock_T *synblock) synblock->b_cap_prog = NULL; } else { // Prepend a ^ so that we only match at one column - char_u *re = concat_str((char_u *)"^", synblock->b_p_spc); + char_u *re = concat_str((char_u *)"^", (char_u *)synblock->b_p_spc); synblock->b_cap_prog = vim_regcomp((char *)re, RE_MAGIC); xfree(re); if (synblock->b_cap_prog == NULL) { diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 676eff9f4a..46249470d1 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -440,7 +440,7 @@ typedef struct spellinfo_S { sblock_T *si_blocks; // memory blocks used long si_blocks_cnt; // memory blocks allocated - int si_did_emsg; // TRUE when ran out of memory + int si_did_emsg; // true when ran out of memory long si_compress_cnt; // words to add before lowering // compression limit @@ -454,7 +454,7 @@ typedef struct spellinfo_S { int si_ascii; // handling only ASCII words int si_add; // addition file - int si_clear_chartab; // when TRUE clear char tables + int si_clear_chartab; // when true clear char tables int si_region; // region mask vimconv_T si_conv; // for conversion to 'encoding' int si_memtot; // runtime memory used @@ -1924,7 +1924,7 @@ static void spell_clear_flags(wordnode_T *node) wordnode_T *np; for (np = node; np != NULL; np = np->wn_sibling) { - np->wn_u1.index = FALSE; + np->wn_u1.index = false; spell_clear_flags(np->wn_child); } } @@ -1940,7 +1940,7 @@ static void spell_print_node(wordnode_T *node, int depth) msg((char_u *)line2); msg((char_u *)line3); } else { - node->wn_u1.index = TRUE; + node->wn_u1.index = true; if (node->wn_byte != NUL) { if (node->wn_child != NULL) { @@ -4877,12 +4877,12 @@ void ex_mkspell(exarg_T *eap) { int fcount; char **fnames; - char_u *arg = (char_u *)eap->arg; + char *arg = eap->arg; bool ascii = false; if (STRNCMP(arg, "-ascii", 6) == 0) { ascii = true; - arg = (char_u *)skipwhite((char *)arg + 6); + arg = skipwhite(arg + 6); } // Expand all the remaining arguments (e.g., $VIMRUNTIME). @@ -5552,7 +5552,7 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo } fnamebuf = xmalloc(MAXPATHL); - for (spf = curwin->w_s->b_p_spf, i = 1; *spf != NUL; i++) { + for (spf = (char_u *)curwin->w_s->b_p_spf, i = 1; *spf != NUL; i++) { copy_option_part((char **)&spf, (char *)fnamebuf, MAXPATHL, ","); if (i == idx) { break; @@ -5680,14 +5680,14 @@ static void init_spellfile(void) char_u *rtp; char_u *lend; bool aspath = false; - char_u *lstart = curbuf->b_s.b_p_spl; + char_u *lstart = (char_u *)curbuf->b_s.b_p_spl; if (*curwin->w_s->b_p_spl != NUL && !GA_EMPTY(&curwin->w_s->b_langp)) { buf = xmalloc(MAXPATHL); // Find the end of the language name. Exclude the region. If there // is a path separator remember the start of the tail. - for (lend = curwin->w_s->b_p_spl; *lend != NUL + for (lend = (char_u *)curwin->w_s->b_p_spl; *lend != NUL && vim_strchr(",._", *lend) == NULL; lend++) { if (vim_ispathsep(*lend)) { aspath = true; @@ -5702,8 +5702,7 @@ static void init_spellfile(void) if (aspath) { // Use directory of an entry with path, e.g., for // "/dir/lg.utf-8.spl" use "/dir". - STRLCPY(buf, curbuf->b_s.b_p_spl, - lstart - curbuf->b_s.b_p_spl); + STRLCPY(buf, curbuf->b_s.b_p_spl, lstart - (char_u *)curbuf->b_s.b_p_spl); } else { // Copy the path from 'runtimepath' to buf[]. copy_option_part((char **)&rtp, (char *)buf, MAXPATHL, ","); @@ -5712,8 +5711,7 @@ static void init_spellfile(void) // Use the first language name from 'spelllang' and the // encoding used in the first loaded .spl file. if (aspath) { - STRLCPY(buf, curbuf->b_s.b_p_spl, - lend - curbuf->b_s.b_p_spl + 1); + STRLCPY(buf, curbuf->b_s.b_p_spl, lend - (char_u *)curbuf->b_s.b_p_spl + 1); } else { // Create the "spell" directory if it doesn't exist yet. l = (int)STRLEN(buf); diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index e868a79b9a..d7277b38ae 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -522,7 +522,7 @@ void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler) use_sandbox = was_set_insecurely(wp, "rulerformat", 0); } else { if (*wp->w_p_stl != NUL) { - stl = wp->w_p_stl; + stl = (char_u *)wp->w_p_stl; } else { stl = p_stl; } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 7794499582..e9383e1bb3 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -812,9 +812,7 @@ static void restore_chartab(char_u *chartab) } } -/* - * Return TRUE if the line-continuation pattern matches in line "lnum". - */ +/// Return true if the line-continuation pattern matches in line "lnum". static int syn_match_linecont(linenr_T lnum) { if (syn_block->b_syn_linecont_prog != NULL) { @@ -832,7 +830,7 @@ static int syn_match_linecont(linenr_T lnum) restore_chartab(buf_chartab); return r; } - return FALSE; + return false; } /* @@ -878,7 +876,7 @@ static void syn_update_ends(bool startofline) cur_si->si_m_endpos.lnum = 0; cur_si->si_m_endpos.col = 0; cur_si->si_h_endpos = cur_si->si_m_endpos; - cur_si->si_ends = TRUE; + cur_si->si_ends = true; } } } @@ -1345,7 +1343,7 @@ static void load_current_state(synstate_T *from) if (keepend_level < 0 && (CUR_STATE(i).si_flags & HL_KEEPEND)) { keepend_level = i; } - CUR_STATE(i).si_ends = FALSE; + CUR_STATE(i).si_ends = false; CUR_STATE(i).si_m_lnum = 0; if (CUR_STATE(i).si_idx >= 0) { CUR_STATE(i).si_next_list = @@ -1551,7 +1549,7 @@ static bool syn_finish_line(const bool syncing) /// "col" is normally 0 for the first use in a line, and increments by one each /// time. It's allowed to skip characters and to stop before the end of the /// line. But only a "col" after a previously used column is allowed. -/// When "can_spell" is not NULL set it to TRUE when spell-checking should be +/// When "can_spell" is not NULL set it to true when spell-checking should be /// done. /// /// @param keep_state keep state of char at "col" @@ -1732,7 +1730,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con cur_si->si_m_endpos.col = endcol; cur_si->si_h_endpos.lnum = current_lnum; cur_si->si_h_endpos.col = endcol; - cur_si->si_ends = TRUE; + cur_si->si_ends = true; cur_si->si_end_idx = 0; cur_si->si_flags = flags; cur_si->si_seqnr = next_seqnr++; @@ -2046,10 +2044,8 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con if (can_spell != NULL) { struct sp_syn sps; - /* - * set "can_spell" to TRUE if spell checking is supposed to be - * done in the current item. - */ + // set "can_spell" to true if spell checking is supposed to be + // done in the current item. if (syn_block->b_spell_cluster_id == 0) { // There is no @Spell cluster: Do spelling for items without // @NoSpell cluster. @@ -2192,7 +2188,7 @@ static stateitem_T *push_next_match(void) } else { cur_si->si_m_endpos = next_match_m_endpos; cur_si->si_h_endpos = next_match_h_endpos; - cur_si->si_ends = TRUE; + cur_si->si_ends = true; cur_si->si_flags |= next_match_flags; cur_si->si_eoe_pos = next_match_eoe_pos; cur_si->si_end_idx = next_match_end_idx; @@ -2216,7 +2212,7 @@ static stateitem_T *push_next_match(void) cur_si->si_m_lnum = current_lnum; cur_si->si_m_endpos = next_match_eos_pos; cur_si->si_h_endpos = next_match_eos_pos; - cur_si->si_ends = TRUE; + cur_si->si_ends = true; cur_si->si_end_idx = 0; cur_si->si_flags = HL_MATCH; cur_si->si_seqnr = next_seqnr++; @@ -2422,7 +2418,7 @@ static void check_keepend(void) limit_pos_zero(&sip->si_m_endpos, &maxpos); limit_pos_zero(&sip->si_h_endpos, &maxpos_h); limit_pos_zero(&sip->si_eoe_pos, &maxpos); - sip->si_ends = TRUE; + sip->si_ends = true; } if (sip->si_ends && (sip->si_flags & HL_KEEPEND)) { if (maxpos.lnum == 0 @@ -2482,12 +2478,12 @@ static void update_si_end(stateitem_T *sip, int startcol, bool force) // No end pattern matched. if (SYN_ITEMS(syn_block)[sip->si_idx].sp_flags & HL_ONELINE) { // a "oneline" never continues in the next line - sip->si_ends = TRUE; + sip->si_ends = true; sip->si_m_endpos.lnum = current_lnum; sip->si_m_endpos.col = (colnr_T)STRLEN(syn_getcurline()); } else { // continues in the next line - sip->si_ends = FALSE; + sip->si_ends = false; sip->si_m_endpos.lnum = 0; } sip->si_h_endpos = sip->si_m_endpos; @@ -2496,7 +2492,7 @@ static void update_si_end(stateitem_T *sip, int startcol, bool force) sip->si_m_endpos = endpos; sip->si_h_endpos = hl_endpos; sip->si_eoe_pos = end_endpos; - sip->si_ends = TRUE; + sip->si_ends = true; sip->si_end_idx = end_idx; } } @@ -2888,7 +2884,7 @@ static char_u *syn_getcurline(void) /* * Call vim_regexec() to find a match with "rmp" in "syn_buf". - * Returns TRUE when there is a match. + * Returns true when there is a match. */ static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T *st) { @@ -2929,9 +2925,9 @@ static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T if (r > 0) { rmp->startpos[0].lnum += lnum; rmp->endpos[0].lnum += lnum; - return TRUE; + return true; } - return FALSE; + return false; } /// Check one position in a line for a matching keyword. @@ -3162,7 +3158,7 @@ static void syn_cmd_iskeyword(exarg_T *eap, int syncing) msg_puts("\n"); if (curwin->w_s->b_syn_isk != empty_option) { msg_puts("syntax iskeyword "); - msg_outtrans((char *)curwin->w_s->b_syn_isk); + msg_outtrans(curwin->w_s->b_syn_isk); } else { msg_outtrans(_("syntax iskeyword not set")); } @@ -3172,15 +3168,15 @@ static void syn_cmd_iskeyword(exarg_T *eap, int syncing) clear_string_option(&curwin->w_s->b_syn_isk); } else { memmove(save_chartab, curbuf->b_chartab, (size_t)32); - save_isk = curbuf->b_p_isk; - curbuf->b_p_isk = vim_strsave(arg); + save_isk = (char_u *)curbuf->b_p_isk; + curbuf->b_p_isk = (char *)vim_strsave(arg); buf_init_chartab(curbuf, false); memmove(curwin->w_s->b_syn_chartab, curbuf->b_chartab, (size_t)32); memmove(curbuf->b_chartab, save_chartab, (size_t)32); clear_string_option(&curwin->w_s->b_syn_isk); curwin->w_s->b_syn_isk = curbuf->b_p_isk; - curbuf->b_p_isk = save_isk; + curbuf->b_p_isk = (char *)save_isk; } } redraw_later(curwin, UPD_NOT_VALID); @@ -3471,7 +3467,7 @@ void syn_maybe_enable(void) /// Handle ":syntax [list]" command: list current syntax words. /// -/// @param syncing when TRUE: list syncing items +/// @param syncing when true: list syncing items static void syn_cmd_list(exarg_T *eap, int syncing) { char_u *arg = (char_u *)eap->arg; @@ -4006,7 +4002,7 @@ static void add_keyword(char_u *const name, const int id, const int flags, kp->k_char = conceal_char; kp->k_syn.cont_in_list = copy_id_list(cont_in_list); if (cont_in_list != NULL) { - curwin->w_s->b_syn_containedin = TRUE; + curwin->w_s->b_syn_containedin = true; } kp->next_list = copy_id_list(next_list); @@ -4063,7 +4059,7 @@ static char_u *get_group_name(char_u *arg, char_u **name_end) /// /// @param arg next argument to be checked /// @param opt various things -/// @param skip TRUE if skipping over command +/// @param skip true if skipping over command /// /// @return a pointer to the next argument (which isn't an option). /// Return NULL for any error; @@ -4428,7 +4424,7 @@ error: /// /// Also ":syntax sync match {name} [[grouphere | groupthere] {group-name}] .." /// -/// @param syncing TRUE for ":syntax sync match .. " +/// @param syncing true for ":syntax sync match .. " static void syn_cmd_match(exarg_T *eap, int syncing) { char_u *arg = (char_u *)eap->arg; @@ -4490,7 +4486,7 @@ static void syn_cmd_match(exarg_T *eap, int syncing) spp->sp_syn.cont_in_list = syn_opt_arg.cont_in_list; spp->sp_cchar = conceal_char; if (syn_opt_arg.cont_in_list != NULL) { - curwin->w_s->b_syn_containedin = TRUE; + curwin->w_s->b_syn_containedin = true; } spp->sp_next_list = syn_opt_arg.next_list; @@ -4526,7 +4522,7 @@ static void syn_cmd_match(exarg_T *eap, int syncing) /// Handle ":syntax region {group-name} [matchgroup={group-name}] /// start {start} .. [skip {skip}] end {end} .. [{options}]". /// -/// @param syncing TRUE for ":syntax sync region .." +/// @param syncing true for ":syntax sync region .." static void syn_cmd_region(exarg_T *eap, int syncing) { char_u *arg = (char_u *)eap->arg; @@ -4705,7 +4701,7 @@ static void syn_cmd_region(exarg_T *eap, int syncing) SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = syn_opt_arg.cont_in_list; if (syn_opt_arg.cont_in_list != NULL) { - curwin->w_s->b_syn_containedin = TRUE; + curwin->w_s->b_syn_containedin = true; } SYN_ITEMS(curwin->w_s)[idx].sp_next_list = syn_opt_arg.next_list; @@ -5070,7 +5066,7 @@ static char_u *get_syn_pattern(char_u *arg, synpat_T *ci) // Make 'cpoptions' empty, to avoid the 'l' flag cpo_save = p_cpo; - p_cpo = (char *)empty_option; + p_cpo = empty_option; ci->sp_prog = vim_regcomp((char *)ci->sp_pattern, RE_MAGIC); p_cpo = cpo_save; @@ -5154,7 +5150,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) char *cpo_save; if (ends_excmd(*arg_start)) { - syn_cmd_list(eap, TRUE); + syn_cmd_list(eap, true); return; } @@ -5189,7 +5185,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) arg_end = (char *)key + 9; } if (arg_end[-1] != '=' || !ascii_isdigit(*arg_end)) { - illegal = TRUE; + illegal = true; break; } linenr_T n = getdigits_int32(&arg_end, false, 0); @@ -5214,7 +5210,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) } if (curwin->w_s->b_syn_linecont_pat != NULL) { emsg(_("E403: syntax sync: line continuations pattern specified twice")); - finished = TRUE; + finished = true; break; } arg_end = (char *)skip_regexp(next_arg + 1, *next_arg, true, NULL); @@ -5226,14 +5222,14 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) if (!eap->skip) { // store the pattern and compiled regexp program curwin->w_s->b_syn_linecont_pat = - vim_strnsave(next_arg + 1, (size_t)(arg_end - (char *)next_arg) - 1); + (char *)vim_strnsave(next_arg + 1, (size_t)(arg_end - (char *)next_arg) - 1); curwin->w_s->b_syn_linecont_ic = curwin->w_s->b_syn_ic; // Make 'cpoptions' empty, to avoid the 'l' flag cpo_save = p_cpo; - p_cpo = (char *)empty_option; + p_cpo = empty_option; curwin->w_s->b_syn_linecont_prog = - vim_regcomp((char *)curwin->w_s->b_syn_linecont_pat, RE_MAGIC); + vim_regcomp(curwin->w_s->b_syn_linecont_pat, RE_MAGIC); p_cpo = cpo_save; syn_clear_time(&curwin->w_s->b_syn_linecont_time); @@ -5247,15 +5243,15 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) } else { eap->arg = (char *)next_arg; if (STRCMP(key, "MATCH") == 0) { - syn_cmd_match(eap, TRUE); + syn_cmd_match(eap, true); } else if (STRCMP(key, "REGION") == 0) { - syn_cmd_region(eap, TRUE); + syn_cmd_region(eap, true); } else if (STRCMP(key, "CLEAR") == 0) { - syn_cmd_clear(eap, TRUE); + syn_cmd_clear(eap, true); } else { - illegal = TRUE; + illegal = true; } - finished = TRUE; + finished = true; break; } arg_start = next_arg; @@ -5364,7 +5360,7 @@ static int get_id_list(char_u **const arg, const int keylen, int16_t **const lis break; } - regmatch.rm_ic = TRUE; + regmatch.rm_ic = true; id = 0; for (int i = highlight_num_groups(); --i >= 0;) { if (vim_regexec(®match, (char *)highlight_group_name(i), (colnr_T)0)) { @@ -5472,7 +5468,7 @@ static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, in static int depth = 0; int r; - // If ssp has a "containedin" list and "cur_si" is in it, return TRUE. + // If ssp has a "containedin" list and "cur_si" is in it, return true. if (cur_si != NULL && ssp->cont_in_list != NULL && !(cur_si->si_flags & HL_MATCH)) { // Ignore transparent items without a contains argument. Double check @@ -5486,12 +5482,12 @@ static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, in &(SYN_ITEMS(syn_block)[cur_si->si_idx].sp_syn), SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags & HL_CONTAINED)) { - return TRUE; + return true; } } if (list == NULL) { - return FALSE; + return false; } /* @@ -5502,33 +5498,31 @@ static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, in return !contained; } - /* - * If the first item is "ALLBUT", return TRUE if "id" is NOT in the - * contains list. We also require that "id" is at the same ":syn include" - * level as the list. - */ + // If the first item is "ALLBUT", return true if "id" is NOT in the + // contains list. We also require that "id" is at the same ":syn include" + // level as the list. item = *list; if (item >= SYNID_ALLBUT && item < SYNID_CLUSTER) { if (item < SYNID_TOP) { // ALL or ALLBUT: accept all groups in the same file if (item - SYNID_ALLBUT != ssp->inc_tag) { - return FALSE; + return false; } } else if (item < SYNID_CONTAINED) { // TOP: accept all not-contained groups in the same file if (item - SYNID_TOP != ssp->inc_tag || contained) { - return FALSE; + return false; } } else { // CONTAINED: accept all contained groups in the same file if (item - SYNID_CONTAINED != ssp->inc_tag || !contained) { - return FALSE; + return false; } } item = *++list; - retval = FALSE; + retval = false; } else { - retval = TRUE; + retval = true; } /* @@ -5832,7 +5826,7 @@ int syn_get_stack_item(int i) { if (i >= current_state.ga_len) { // Need to invalidate the state, because we didn't properly finish it - // for the last character, "keep_state" was TRUE. + // for the last character, "keep_state" was true. invalidate_current_state(); current_col = MAXCOL; return -1; diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 7401e73e84..7d3d0f7905 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -202,7 +202,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) } prev_num_matches = num_matches; - free_string_option(nofile_fname); + free_string_option((char *)nofile_fname); nofile_fname = NULL; clearpos(&saved_fmark.mark); // shutup gcc 4.0 @@ -215,7 +215,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) new_tag = true; if (g_do_tagpreview != 0) { tagstack_clear_entry(&ptag_entry); - ptag_entry.tagname = vim_strsave(tag); + ptag_entry.tagname = (char *)vim_strsave(tag); } } else { if (g_do_tagpreview != 0) { @@ -239,7 +239,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) cur_fnum = ptag_entry.cur_fnum; } else { tagstack_clear_entry(&ptag_entry); - ptag_entry.tagname = vim_strsave(tag); + ptag_entry.tagname = (char *)vim_strsave(tag); } } else { /* @@ -261,7 +261,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) } // put the tag name in the tag stack - tagstack[tagstackidx].tagname = vim_strsave(tag); + tagstack[tagstackidx].tagname = (char *)vim_strsave(tag); curwin->w_tagstacklen = tagstacklen; @@ -440,9 +440,9 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) // When desired match not found yet, try to find it (and others). if (use_tagstack) { - name = tagstack[tagstackidx].tagname; + name = (char_u *)tagstack[tagstackidx].tagname; } else if (g_do_tagpreview != 0) { - name = ptag_entry.tagname; + name = (char_u *)ptag_entry.tagname; } else { name = tag; } @@ -587,9 +587,9 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose) if (use_tfu && parse_match((char_u *)matches[cur_match], &tagp2) == OK && tagp2.user_data) { XFREE_CLEAR(tagstack[tagstackidx].user_data); - tagstack[tagstackidx].user_data = vim_strnsave(tagp2.user_data, - (size_t)(tagp2.user_data_end - - tagp2.user_data)); + tagstack[tagstackidx].user_data = (char *)vim_strnsave(tagp2.user_data, + (size_t)(tagp2.user_data_end - + tagp2.user_data)); } tagstackidx++; @@ -1184,7 +1184,7 @@ static int find_tagfunc_tags(char_u *pat, garray_T *ga, int *match_count, int fl flags & TAG_REGEXP ? "r": ""); save_pos = curwin->w_cursor; - result = call_vim_function((char *)curbuf->b_p_tfu, 3, args, &rettv); + result = call_vim_function(curbuf->b_p_tfu, 3, args, &rettv); curwin->w_cursor = save_pos; // restore the cursor position d->dv_refcount--; @@ -1409,7 +1409,7 @@ int find_tags(char_u *pat, int *num_matches, char ***matchesp, int flags, int mi int cmplen; int match; // matches - int match_no_ic = 0; // matches with rm_ic == FALSE + int match_no_ic = 0; // matches with rm_ic == false int match_re; // match with regexp int matchoff = 0; int save_emsg_off; @@ -1441,7 +1441,7 @@ int find_tags(char_u *pat, int *num_matches, char ***matchesp, int flags, int mi int help_only = (flags & TAG_HELP); int name_only = (flags & TAG_NAMES); int noic = (flags & TAG_NOIC); - int get_it_again = FALSE; + int get_it_again = false; int use_cscope = (flags & TAG_CSCOPE); int verbose = (flags & TAG_VERBOSE); int use_tfu = ((flags & TAG_NO_TAGFUNC) == 0); @@ -1514,7 +1514,7 @@ int find_tags(char_u *pat, int *num_matches, char ***matchesp, int flags, int mi } save_emsg_off = emsg_off; - emsg_off = TRUE; // don't want error for invalid RE here + emsg_off = true; // don't want error for invalid RE here prepare_pats(&orgpat, has_re); emsg_off = save_emsg_off; if (has_re && orgpat.regmatch.regprog == NULL) { @@ -2009,7 +2009,7 @@ parse_line: } // if tag length does not match, don't try comparing if (orgpat.len != cmplen) { - match = FALSE; + match = false; } else { if (orgpat.regmatch.rm_ic) { assert(cmplen >= 0); @@ -2026,7 +2026,7 @@ parse_line: /* * Has a regexp: Also find tags matching regexp. */ - match_re = FALSE; + match_re = false; if (!match && orgpat.regmatch.regprog != NULL) { int cc; @@ -2236,7 +2236,7 @@ parse_line: if (use_cscope) { break; } - orgpat.regmatch.rm_ic = TRUE; // try another time while ignoring case + orgpat.regmatch.rm_ic = true; // try another time while ignoring case } if (!stop_searching) { @@ -2334,7 +2334,7 @@ void free_tag_stuff(void) /// For help files, use "tags" file only. /// /// @param tnp holds status info -/// @param first TRUE when first file name is wanted +/// @param first true when first file name is wanted /// @param buf pointer to buffer of MAXPATHL chars /// /// @return FAIL if no more tag file names, OK otherwise. @@ -2388,15 +2388,15 @@ int get_tagfname(tagname_T *tnp, int first, char_u *buf) if (first) { // Init. We make a copy of 'tags', because autocommands may change // the value without notifying us. - tnp->tn_tags = vim_strsave((*curbuf->b_p_tags != NUL) ? curbuf->b_p_tags : p_tags); + tnp->tn_tags = vim_strsave((*curbuf->b_p_tags != NUL) ? (char_u *)curbuf->b_p_tags : p_tags); tnp->tn_np = (char *)tnp->tn_tags; } /* * Loop until we have found a file name that can be used. * There are two states: - * tnp->tn_did_filefind_init == FALSE: setup for next part in 'tags'. - * tnp->tn_did_filefind_init == TRUE: find next file in this part. + * tnp->tn_did_filefind_init == false: setup for next part in 'tags'. + * tnp->tn_did_filefind_init == true: find next file in this part. */ for (;;) { if (tnp->tn_did_filefind_init) { @@ -2405,7 +2405,7 @@ int get_tagfname(tagname_T *tnp, int first, char_u *buf) break; } - tnp->tn_did_filefind_init = FALSE; + tnp->tn_did_filefind_init = false; } else { char_u *filename = NULL; @@ -2431,11 +2431,11 @@ int get_tagfname(tagname_T *tnp, int first, char_u *buf) tnp->tn_search_ctx = vim_findfile_init(buf, filename, r_ptr, 100, - FALSE, // don't free visited list + false, // don't free visited list FINDFILE_FILE, // we search for a file tnp->tn_search_ctx, true, (char_u *)curbuf->b_ffname); if (tnp->tn_search_ctx != NULL) { - tnp->tn_did_filefind_init = TRUE; + tnp->tn_did_filefind_init = true; } } } @@ -2459,7 +2459,7 @@ void tagname_free(tagname_T *tnp) /// Parse one line from the tags file. Find start/end of tag name, start/end of /// file name and start of search pattern. /// -/// If is_etag is TRUE, tagp->fname and tagp->fname_end are not set. +/// If is_etag is true, tagp->fname and tagp->fname_end are not set. /// /// @param lbuf line to be parsed /// @@ -2510,8 +2510,8 @@ static int parse_tag_line(char_u *lbuf, tagptrs_T *tagp) * Static tags produced by the new ctags program have the format: * 'tag file /pattern/;"<Tab>file:' " * - * Return TRUE if it is a static tag and adjust *tagname to the real tag. - * Return FALSE if it is not a static tag. + * Return true if it is a static tag and adjust *tagname to the real tag. + * Return false if it is not a static tag. */ static bool test_for_static(tagptrs_T *tagp) { @@ -2522,11 +2522,11 @@ static bool test_for_static(tagptrs_T *tagp) while ((p = (char_u *)vim_strchr((char *)p, '\t')) != NULL) { p++; if (STRNCMP(p, "file:", 5) == 0) { - return TRUE; + return true; } } - return FALSE; + return false; } // Returns the length of a matching tag line. @@ -2640,7 +2640,7 @@ static char_u *tag_full_fname(tagptrs_T *tagp) /// /// @param lbuf_arg line from the tags file for this tag /// @param forceit :ta with ! -/// @param keep_help keep help flag (FALSE for cscope) +/// @param keep_help keep help flag (false for cscope) /// /// @return OK for success, NOTAGFILE when file not found, FAIL otherwise. static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) @@ -2732,7 +2732,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) * into a fullpath */ if (!curwin->w_p_pvw) { - full_fname = (char_u *)FullName_save((char *)fname, FALSE); + full_fname = (char_u *)FullName_save((char *)fname, false); fname = full_fname; /* @@ -2825,15 +2825,15 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) */ str = pbuf; if (pbuf[0] == '/' || pbuf[0] == '?') { - str = skip_regexp(pbuf + 1, pbuf[0], FALSE, NULL) + 1; + str = skip_regexp(pbuf + 1, pbuf[0], false, NULL) + 1; } if (str > pbuf_end - 1) { // search command with nothing following save_p_ws = p_ws; save_p_ic = p_ic; save_p_scs = p_scs; p_ws = true; // need 'wrapscan' for backward searches - p_ic = FALSE; // don't ignore case now - p_scs = FALSE; + p_ic = false; // don't ignore case now + p_scs = false; save_lnum = curwin->w_cursor.lnum; if (tagp.tagline > 0) { // start search before line from "line:" field @@ -3014,13 +3014,13 @@ static char_u *expand_tag_fname(char_u *fname, char_u *const tag_fname, const bo /* * Check if we have a tag for the buffer with name "buf_ffname". * This is a bit slow, because of the full path compare in path_full_compare(). - * Return TRUE if tag for file "fname" if tag file "tag_fname" is for current + * Return true if tag for file "fname" if tag file "tag_fname" is for current * file. */ static int test_for_current(char_u *fname, char_u *fname_end, char_u *tag_fname, char_u *buf_ffname) { int c; - int retval = FALSE; + int retval = false; char_u *fullname; if (buf_ffname != NULL) { // if the buffer has a name @@ -3365,7 +3365,7 @@ static void tagstack_push_item(win_T *wp, char_u *tagname, int cur_fnum, int cur } wp->w_tagstacklen++; - tagstack[idx].tagname = tagname; + tagstack[idx].tagname = (char *)tagname; tagstack[idx].cur_fnum = cur_fnum; tagstack[idx].cur_match = cur_match; if (tagstack[idx].cur_match < 0) { @@ -3373,7 +3373,7 @@ static void tagstack_push_item(win_T *wp, char_u *tagname, int cur_fnum, int cur } tagstack[idx].fmark.mark = mark; tagstack[idx].fmark.fnum = fnum; - tagstack[idx].user_data = user_data; + tagstack[idx].user_data = (char *)user_data; } // Add a list of items to the tag stack in the specified window diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 1b4ac12aa6..90966bcfad 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -418,7 +418,7 @@ bool terminal_enter(void) // placed at end of buffer to "follow" output. #11072 handle_T save_curwin = curwin->handle; bool save_w_p_cul = curwin->w_p_cul; - char_u *save_w_p_culopt = NULL; + char *save_w_p_culopt = NULL; char_u save_w_p_culopt_flags = curwin->w_p_culopt_flags; int save_w_p_cuc = curwin->w_p_cuc; long save_w_p_so = curwin->w_p_so; @@ -426,7 +426,7 @@ bool terminal_enter(void) if (curwin->w_p_cul && curwin->w_p_culopt_flags & CULOPT_NBR) { if (STRCMP(curwin->w_p_culopt, "number")) { save_w_p_culopt = curwin->w_p_culopt; - curwin->w_p_culopt = (char_u *)xstrdup("number"); + curwin->w_p_culopt = xstrdup("number"); } curwin->w_p_culopt_flags = CULOPT_NBR; } else { diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 206f335751..ce23141c7a 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -425,7 +425,7 @@ for s:test in sort(s:tests) set belloff=all let prev_error = '' let total_errors = [] - let run_nr = 1 + let g:run_nr = 1 " A test can set g:test_is_flaky to retry running the test. let g:test_is_flaky = 0 @@ -444,10 +444,10 @@ for s:test in sort(s:tests) call add(s:messages, 'Found errors in ' . s:test . ':') call extend(s:messages, v:errors) - call add(total_errors, 'Run ' . run_nr . ':') + call add(total_errors, 'Run ' . g:run_nr . ':') call extend(total_errors, v:errors) - if run_nr == 5 || prev_error == v:errors[0] + if g:run_nr >= 5 || prev_error == v:errors[0] call add(total_errors, 'Flaky test failed too often, giving up') let v:errors = total_errors break @@ -462,7 +462,7 @@ for s:test in sort(s:tests) let prev_error = v:errors[0] let v:errors = [] - let run_nr += 1 + let g:run_nr += 1 call RunTheTest(s:test) diff --git a/src/nvim/testdir/setup.vim b/src/nvim/testdir/setup.vim index 6bc3607b69..472ed4ca14 100644 --- a/src/nvim/testdir/setup.vim +++ b/src/nvim/testdir/setup.vim @@ -5,7 +5,7 @@ if exists('s:did_load') set directory& set directory^=. set display= - set fillchars=vert:\|,fold:- + set fillchars=vert:\|,foldsep:\|,fold:- set formatoptions=tcq set fsync set laststatus=1 diff --git a/src/nvim/testdir/test_display.vim b/src/nvim/testdir/test_display.vim index 6938abbc28..217bb5d781 100644 --- a/src/nvim/testdir/test_display.vim +++ b/src/nvim/testdir/test_display.vim @@ -309,6 +309,88 @@ func Test_eob_fillchars() close endfunc +" Test for 'foldopen', 'foldclose' and 'foldsep' in 'fillchars' +func Test_fold_fillchars() + new + set fdc=2 foldenable foldmethod=manual + call setline(1, ['one', 'two', 'three', 'four', 'five']) + 2,4fold + " First check for the default setting for a closed fold + let lines = ScreenLines([1, 3], 8) + let expected = [ + \ ' one ', + \ '+ +-- 3', + \ ' five ' + \ ] + call assert_equal(expected, lines) + normal 2Gzo + " check the characters for an open fold + let lines = ScreenLines([1, 5], 8) + let expected = [ + \ ' one ', + \ '- two ', + \ '| three ', + \ '| four ', + \ ' five ' + \ ] + call assert_equal(expected, lines) + + " change the setting + set fillchars=vert:\|,fold:-,eob:~,foldopen:[,foldclose:],foldsep:- + + " check the characters for an open fold + let lines = ScreenLines([1, 5], 8) + let expected = [ + \ ' one ', + \ '[ two ', + \ '- three ', + \ '- four ', + \ ' five ' + \ ] + call assert_equal(expected, lines) + + " check the characters for a closed fold + normal 2Gzc + let lines = ScreenLines([1, 3], 8) + let expected = [ + \ ' one ', + \ '] +-- 3', + \ ' five ' + \ ] + call assert_equal(expected, lines) + + %bw! + set fillchars& fdc& foldmethod& foldenable& +endfunc + +func Test_local_fillchars() + CheckScreendump + + let lines =<< trim END + call setline(1, ['window 1']->repeat(3)) + setlocal fillchars=stl:1,stlnc:a,vert:=,eob:x + vnew + call setline(1, ['window 2']->repeat(3)) + setlocal fillchars=stl:2,stlnc:b,vert:+,eob:y + new + wincmd J + call setline(1, ['window 3']->repeat(3)) + setlocal fillchars=stl:3,stlnc:c,vert:<,eob:z + vnew + call setline(1, ['window 4']->repeat(3)) + setlocal fillchars=stl:4,stlnc:d,vert:>,eob:o + END + call writefile(lines, 'Xdisplayfillchars') + let buf = RunVimInTerminal('-S Xdisplayfillchars', #{rows: 12}) + call VerifyScreenDump(buf, 'Test_display_fillchars_1', {}) + + call term_sendkeys(buf, ":wincmd k\r") + call VerifyScreenDump(buf, 'Test_display_fillchars_2', {}) + + call StopVimInTerminal(buf) + call delete('Xdisplayfillchars') +endfunc + func Test_display_linebreak_breakat() new vert resize 25 diff --git a/src/nvim/testing.c b/src/nvim/testing.c index e3ffe1c7d1..4a252dca3e 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -457,7 +457,7 @@ void f_assert_exception(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) ga_clear(&ga); rettv->vval.v_number = 1; } else if (error != NULL - && strstr((char *)get_vim_var_str(VV_EXCEPTION), error) == NULL) { + && strstr(get_vim_var_str(VV_EXCEPTION), error) == NULL) { prepare_assert_error(&ga); fill_assert_error(&ga, &argvars[1], NULL, &argvars[0], get_vim_var_tv(VV_EXCEPTION), ASSERT_OTHER); @@ -493,7 +493,7 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) const char *const error = tv_get_string_buf_chk(&argvars[1], buf); if (error == NULL - || strstr((char *)get_vim_var_str(VV_ERRMSG), error) == NULL) { + || strstr(get_vim_var_str(VV_ERRMSG), error) == NULL) { prepare_assert_error(&ga); fill_assert_error(&ga, &argvars[2], NULL, &argvars[1], get_vim_var_tv(VV_ERRMSG), ASSERT_OTHER); diff --git a/src/nvim/undo.c b/src/nvim/undo.c index e2e0bb38a2..ac52bce2f9 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -773,7 +773,7 @@ static bool serialize_header(bufinfo_T *bi, char_u *hash) undo_write_bytes(bi, (uintmax_t)buf->b_ml.ml_line_count, 4); size_t len = buf->b_u_line_ptr ? STRLEN(buf->b_u_line_ptr) : 0; undo_write_bytes(bi, len, 4); - if (len > 0 && !undo_write(bi, buf->b_u_line_ptr, len)) { + if (len > 0 && !undo_write(bi, (char_u *)buf->b_u_line_ptr, len)) { return false; } undo_write_bytes(bi, (uintmax_t)buf->b_u_line_lnum, 4); @@ -1593,7 +1593,7 @@ void u_read_undo(char *name, const char_u *hash, const char_u *orig_name FUNC_AT curbuf->b_u_oldhead = old_idx < 0 ? NULL : uhp_table[old_idx]; curbuf->b_u_newhead = new_idx < 0 ? NULL : uhp_table[new_idx]; curbuf->b_u_curhead = cur_idx < 0 ? NULL : uhp_table[cur_idx]; - curbuf->b_u_line_ptr = line_ptr; + curbuf->b_u_line_ptr = (char *)line_ptr; curbuf->b_u_line_lnum = line_lnum; curbuf->b_u_line_colnr = line_colnr; curbuf->b_u_numhead = num_head; @@ -2960,7 +2960,7 @@ void u_saveline(linenr_T lnum) } else { curbuf->b_u_line_colnr = 0; } - curbuf->b_u_line_ptr = u_save_line(lnum); + curbuf->b_u_line_ptr = (char *)u_save_line(lnum); } /// clear the line saved for the "U" command @@ -2992,12 +2992,12 @@ void u_undoline(void) } char_u *oldp = u_save_line(curbuf->b_u_line_lnum); - ml_replace(curbuf->b_u_line_lnum, (char *)curbuf->b_u_line_ptr, true); + ml_replace(curbuf->b_u_line_lnum, curbuf->b_u_line_ptr, true); changed_bytes(curbuf->b_u_line_lnum, 0); extmark_splice_cols(curbuf, (int)curbuf->b_u_line_lnum - 1, 0, (colnr_T)STRLEN(oldp), (colnr_T)STRLEN(curbuf->b_u_line_ptr), kExtmarkUndo); xfree(curbuf->b_u_line_ptr); - curbuf->b_u_line_ptr = oldp; + curbuf->b_u_line_ptr = (char *)oldp; colnr_T t = curbuf->b_u_line_colnr; if (curwin->w_cursor.lnum == curbuf->b_u_line_lnum) { diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index e130db69f2..834aad2872 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -106,7 +106,7 @@ static struct { /// Return NULL if there is no matching command. /// /// @param *p end of the command (possibly including count) -/// @param full set to TRUE for a full match +/// @param full set to true for a full match /// @param xp used for completion, NULL otherwise /// @param complp completion flags or NULL char *find_ucmd(exarg_T *eap, char *p, int *full, expand_T *xp, int *complp) diff --git a/src/nvim/version.c b/src/nvim/version.c index 34ded3460f..ac55066c7f 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -2016,7 +2016,7 @@ void ex_version(exarg_T *eap) /// Output a string for the version message. If it's going to wrap, output a /// newline, unless the message is too long to fit on the screen anyway. -/// When "wrap" is TRUE wrap the string in []. +/// When "wrap" is true wrap the string in []. /// @param s /// @param wrap static void version_msg_wrap(char *s, int wrap) @@ -2072,7 +2072,7 @@ void list_in_columns(char **items, int size, int current) // Find the length of the longest item, use that + 1 as the column width. int i; for (i = 0; size < 0 ? items[i] != NULL : i < size; i++) { - int l = vim_strsize((char *)items[i]) + (i == current ? 2 : 0); + int l = vim_strsize(items[i]) + (i == current ? 2 : 0); if (l > width) { width = l; @@ -2084,7 +2084,7 @@ void list_in_columns(char **items, int size, int current) if (Columns < width) { // Not enough screen columns - show one per line for (i = 0; i < item_count; i++) { - version_msg_wrap((char *)items[i], i == current); + version_msg_wrap(items[i], i == current); if (msg_col > 0 && i < item_count - 1) { msg_putchar('\n'); } @@ -2106,7 +2106,7 @@ void list_in_columns(char **items, int size, int current) if (idx == current) { msg_putchar('['); } - msg_puts((char *)items[idx]); + msg_puts(items[idx]); if (idx == current) { msg_putchar(']'); } @@ -2209,7 +2209,7 @@ void maybe_intro_message(void) /// Only used when starting Vim on an empty file, without a file name. /// Or with the ":intro" command (for Sven :-). /// -/// @param colon TRUE for ":intro" +/// @param colon true for ":intro" void intro_message(int colon) { int i; @@ -2326,6 +2326,6 @@ static void do_intro_line(long row, char_u *mesg, int attr) void ex_intro(exarg_T *eap) { screenclear(); - intro_message(TRUE); - wait_return(TRUE); + intro_message(true); + wait_return(true); } diff --git a/src/nvim/vim.h b/src/nvim/vim.h index 09b949bb20..3e12d8b0b4 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -167,15 +167,6 @@ enum { #define MIN_SWAP_PAGE_SIZE 1048 #define MAX_SWAP_PAGE_SIZE 50000 -// Boolean constants - -#ifndef TRUE -# define FALSE 0 // note: this is an int, not a long! -# define TRUE 1 -#endif - -#define MAYBE 2 // sometimes used for a variant on TRUE - #define STATUS_HEIGHT 1 // height of a status line under a window #define QF_WINHEIGHT 10 // default height for quickfix window diff --git a/src/nvim/window.c b/src/nvim/window.c index 2a944e7d1d..ffbb0fa27f 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -727,38 +727,38 @@ void win_set_minimal_style(win_T *wp) // Hide EOB region: use " " fillchar and cleared highlighting if (wp->w_p_fcs_chars.eob != ' ') { - char_u *old = wp->w_p_fcs; + char_u *old = (char_u *)wp->w_p_fcs; wp->w_p_fcs = ((*old == NUL) - ? (char_u *)xstrdup("eob: ") - : concat_str(old, (char_u *)",eob: ")); - free_string_option(old); + ? xstrdup("eob: ") + : (char *)concat_str(old, (char_u *)",eob: ")); + free_string_option((char *)old); } // TODO(bfredl): this could use a highlight namespace directly, // and avoid pecularities around window options - char_u *old = wp->w_p_winhl; + char_u *old = (char_u *)wp->w_p_winhl; wp->w_p_winhl = ((*old == NUL) - ? (char_u *)xstrdup("EndOfBuffer:") - : concat_str(old, (char_u *)",EndOfBuffer:")); - free_string_option(old); + ? xstrdup("EndOfBuffer:") + : (char *)concat_str(old, (char_u *)",EndOfBuffer:")); + free_string_option((char *)old); parse_winhl_opt(wp); // signcolumn: use 'auto' if (wp->w_p_scl[0] != 'a' || STRLEN(wp->w_p_scl) >= 8) { free_string_option(wp->w_p_scl); - wp->w_p_scl = (char_u *)xstrdup("auto"); + wp->w_p_scl = xstrdup("auto"); } // foldcolumn: use '0' if (wp->w_p_fdc[0] != '0') { free_string_option(wp->w_p_fdc); - wp->w_p_fdc = (char_u *)xstrdup("0"); + wp->w_p_fdc = xstrdup("0"); } // colorcolumn: cleared if (wp->w_p_cc != NULL && *wp->w_p_cc != NUL) { free_string_option(wp->w_p_cc); - wp->w_p_cc = (char_u *)xstrdup(""); + wp->w_p_cc = xstrdup(""); } } @@ -1299,9 +1299,9 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) } else { curfrp = oldwin->w_frame; if (flags & WSP_BELOW) { - before = FALSE; + before = false; } else if (flags & WSP_ABOVE) { - before = TRUE; + before = true; } else if (flags & WSP_VERT) { before = !p_spr; } else { @@ -1570,10 +1570,10 @@ static void win_init(win_T *newp, win_T *oldp, int flags) taggy_T *tag = &newp->w_tagstack[i]; *tag = oldp->w_tagstack[i]; if (tag->tagname != NULL) { - tag->tagname = vim_strsave(tag->tagname); + tag->tagname = xstrdup(tag->tagname); } if (tag->user_data != NULL) { - tag->user_data = vim_strsave(tag->user_data); + tag->user_data = xstrdup(tag->user_data); } } newp->w_tagstackidx = oldp->w_tagstackidx; @@ -3096,7 +3096,7 @@ void win_free_all(void) cmdwin_type = 0; while (first_tabpage->tp_next != NULL) { - tabpage_close(TRUE); + tabpage_close(true); } while (lastwin != NULL && lastwin->w_floating) { @@ -4025,7 +4025,7 @@ static tabpage_T *alloc_tabpage(void) // Init t: variables. tp->tp_vars = tv_dict_alloc(); init_var_dict(tp->tp_vars, &tp->tp_winvar, VAR_SCOPE); - tp->tp_diff_invalid = TRUE; + tp->tp_diff_invalid = true; tp->tp_ch_used = p_ch; return tp; @@ -4836,7 +4836,7 @@ static void win_enter_ext(win_T *const wp, const int flags) } if (!curwin_invalid) { prevwin = curwin; // remember for CTRL-W p - curwin->w_redr_status = TRUE; + curwin->w_redr_status = true; } curwin = wp; curbuf = wp->w_buffer; @@ -7291,7 +7291,7 @@ char *check_colorcolumn(win_T *wp) return NULL; // buffer was closed } - for (s = (char *)wp->w_p_cc; *s != NUL && count < 255;) { + for (s = wp->w_p_cc; *s != NUL && count < 255;) { if (*s == '-' || *s == '+') { // -N and +N: add to 'textwidth' col = (*s == '-') ? -1 : 1; |