diff options
45 files changed, 356 insertions, 313 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index b7f9292de1..aef7df95dc 100755 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -157,7 +157,6 @@ list(REMOVE_ITEM NVIM_SOURCES ${to_remove}) # Legacy files that do not yet pass -Wconversion. set(CONV_SOURCES - diff.c edit.c eval.c eval/funcs.c diff --git a/src/nvim/ascii.h b/src/nvim/ascii.h index 2cabaa43ef..692db40c0d 100644 --- a/src/nvim/ascii.h +++ b/src/nvim/ascii.h @@ -9,11 +9,11 @@ // Definitions of various common control characters. -#define CharOrd(x) ((uint8_t)(x) < 'a' \ - ? (uint8_t)(x) - 'A' \ - : (uint8_t)(x) - 'a') -#define CharOrdLow(x) ((uint8_t)(x) - 'a') -#define CharOrdUp(x) ((uint8_t)(x) - 'A') +#define CHAR_ORD(x) ((uint8_t)(x) < 'a' \ + ? (uint8_t)(x) - 'A' \ + : (uint8_t)(x) - 'a') +#define CHAR_ORD_LOW(x) ((uint8_t)(x) - 'a') +#define CHAR_ORD_UP(x) ((uint8_t)(x) - 'A') #define ROT13(c, a) (((((c) - (a)) + 13) % 26) + (a)) #define NUL '\000' @@ -35,8 +35,8 @@ #define POUND 0xA3 -#define Ctrl_chr(x) (TOUPPER_ASC(x) ^ 0x40) // '?' -> DEL, '@' -> ^@, etc. -#define Meta(x) ((x) | 0x80) +#define CTRL_CHR(x) (TOUPPER_ASC(x) ^ 0x40) // '?' -> DEL, '@' -> ^@, etc. +#define META(x) ((x) | 0x80) #define CTRL_F_STR "\006" #define CTRL_H_STR "\010" diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 173f8e17af..3dc3d3d7a9 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -2359,7 +2359,7 @@ bool au_exists(const char *const arg) FUNC_ATTR_WARN_UNUSED_RESULT } // if pattern is "<buffer>", special handling is needed which uses curbuf - // for pattern "<buffer=N>, fnamecmp() will work fine + // for pattern "<buffer=N>, FNAMECMP() will work fine if (pattern != NULL && STRICMP(pattern, "<buffer>") == 0) { buflocal_buf = curbuf; } @@ -2367,12 +2367,12 @@ bool au_exists(const char *const arg) FUNC_ATTR_WARN_UNUSED_RESULT // Check if there is an autocommand with the given pattern. for (; ap != NULL; ap = ap->next) { // only use a pattern when it has not been removed and has commands. - // For buffer-local autocommands, fnamecmp() works fine. + // For buffer-local autocommands, FNAMECMP() works fine. if (ap->pat != NULL && ap->cmds != NULL && (group == AUGROUP_ALL || ap->group == group) && (pattern == NULL || (buflocal_buf == NULL - ? fnamecmp(ap->pat, (char_u *)pattern) == 0 + ? FNAMECMP(ap->pat, (char_u *)pattern) == 0 : ap->buflocal_nr == buflocal_buf->b_fnum))) { retval = true; break; diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 30bd37fe7f..5d2d1cebde 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -357,6 +357,7 @@ void set_bufref(bufref_T *bufref, buf_T *buf) /// /// @param bufref Buffer reference to check for. bool bufref_valid(bufref_T *bufref) + FUNC_ATTR_PURE { return bufref->br_buf_free_count == buf_free_count ? true @@ -2100,6 +2101,7 @@ buf_T *buflist_findname(char_u *ffname) /// /// @return buffer or NULL if not found static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id, bool file_id_valid) + FUNC_ATTR_PURE { // Start at the last buffer, expect to find a match sooner. FOR_ALL_BUFFERS_BACKWARDS(buf) { @@ -2531,7 +2533,7 @@ static bool wininfo_other_tab_diff(wininfo_T *wip) /// /// @return NULL when there isn't any info. static wininfo_T *find_wininfo(buf_T *buf, bool need_options, bool skip_diff_buffer) - FUNC_ATTR_NONNULL_ALL + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE { wininfo_T *wip; @@ -2609,6 +2611,7 @@ void get_winopts(buf_T *buf) /// /// @return a pointer to no_position if no position is found. pos_T *buflist_findfpos(buf_T *buf) + FUNC_ATTR_PURE { static pos_T no_position = { 1, 0, 0 }; @@ -2618,6 +2621,7 @@ pos_T *buflist_findfpos(buf_T *buf) /// Find the lnum for the buffer 'buf' for the current window. linenr_T buflist_findlnum(buf_T *buf) + FUNC_ATTR_PURE { return buflist_findfpos(buf)->lnum; } @@ -2951,7 +2955,7 @@ static bool otherfile_buf(buf_T *buf, char_u *ffname, FileID *file_id_p, bool fi if (ffname == NULL || *ffname == NUL || buf->b_ffname == NULL) { return true; } - if (fnamecmp(ffname, buf->b_ffname) == 0) { + if (FNAMECMP(ffname, buf->b_ffname) == 0) { return false; } { @@ -4928,6 +4932,7 @@ void do_arg_all(int count, int forceit, int keep_tabs) /// @return true if "buf" is a prompt buffer. bool bt_prompt(buf_T *buf) + FUNC_ATTR_PURE { return buf != NULL && buf->b_p_bt[0] == 'p'; } @@ -5339,6 +5344,7 @@ bool bt_dontwrite_msg(const buf_T *const buf) /// @return true if the buffer should be hidden, according to 'hidden', ":hide" /// and 'bufhidden'. bool buf_hide(const buf_T *const buf) + FUNC_ATTR_PURE { // 'bufhidden' overrules 'hidden' and ":hide", check it first switch (buf->b_p_bh[0]) { diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 0a1c92a9a4..d6d5ecc907 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -178,7 +178,7 @@ typedef struct { #define w_p_fdi w_onebuf_opt.wo_fdi // 'foldignore' long wo_fdl; #define w_p_fdl w_onebuf_opt.wo_fdl // 'foldlevel' - int wo_fdl_save; + 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; @@ -1151,15 +1151,15 @@ typedef struct VimMenu vimmenu_T; struct VimMenu { int modes; ///< Which modes is this menu visible for int enabled; ///< for which modes the menu is enabled - char_u *name; ///< Name of menu, possibly translated - char_u *dname; ///< Displayed Name ("name" without '&') - char_u *en_name; ///< "name" untranslated, NULL when + char *name; ///< Name of menu, possibly translated + char *dname; ///< Displayed Name ("name" without '&') + char *en_name; ///< "name" untranslated, NULL when ///< was not translated - char_u *en_dname; ///< NULL when "dname" untranslated + char *en_dname; ///< NULL when "dname" untranslated int mnemonic; ///< mnemonic key (after '&') - char_u *actext; ///< accelerator text (after TAB) + char *actext; ///< accelerator text (after TAB) long priority; ///< Menu order priority - char_u *strings[MENU_MODES]; ///< Mapped string for each mode + char *strings[MENU_MODES]; ///< Mapped string for each mode int noremap[MENU_MODES]; ///< A \ref REMAP_VALUES flag for each mode bool silent[MENU_MODES]; ///< A silent flag for each mode vimmenu_T *children; ///< Children of sub-menu diff --git a/src/nvim/charset.c b/src/nvim/charset.c index ec1866e9cc..31c61a1398 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -654,6 +654,7 @@ static inline unsigned nr2hex(unsigned n) /// /// @reeturn Number of display cells. int byte2cells(int b) + FUNC_ATTR_PURE { if (b >= 0x80) { return 0; @@ -1176,6 +1177,7 @@ intptr_t getwhitecols_curline(void) } intptr_t getwhitecols(const char_u *p) + FUNC_ATTR_PURE { return skipwhite(p) - p; } @@ -1222,6 +1224,7 @@ const char *skipbin(const char *q) /// @return Pointer to the character after the skipped digits and hex /// characters. char_u *skiphex(char_u *q) + FUNC_ATTR_PURE { char_u *p = q; while (ascii_isxdigit(*p)) { @@ -1237,6 +1240,7 @@ char_u *skiphex(char_u *q) /// /// @return Pointer to the digit or (NUL after the string). char_u *skiptodigit(char_u *q) + FUNC_ATTR_PURE { char_u *p = q; while (*p != NUL && !ascii_isdigit(*p)) { @@ -1270,6 +1274,7 @@ const char *skiptobin(const char *q) /// /// @return Pointer to the hex character or (NUL after the string). char_u *skiptohex(char_u *q) + FUNC_ATTR_PURE { char_u *p = q; while (*p != NUL && !ascii_isxdigit(*p)) { @@ -1285,7 +1290,7 @@ char_u *skiptohex(char_u *q) /// /// @return Pointer to the next whitespace or NUL character. char_u *skiptowhite(const char_u *p) - FUNC_ATTR_NONNULL_ALL + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE { while (*p != ' ' && *p != '\t' && *p != NUL) { p++; @@ -1299,6 +1304,7 @@ char_u *skiptowhite(const char_u *p) /// /// @return Pointer to the next whitespace character. char_u *skiptowhite_esc(char_u *p) + FUNC_ATTR_PURE { while (*p != ' ' && *p != '\t' && *p != NUL) { if (((*p == '\\') || (*p == Ctrl_V)) && (*(p + 1) != NUL)) { @@ -1392,6 +1398,7 @@ long getdigits_long(char_u **pp, bool strict, long def) /// /// @param lbuf line buffer to check bool vim_isblankline(char_u *lbuf) + FUNC_ATTR_PURE { char_u *p = skipwhite(lbuf); return *p == NUL || *p == '\r' || *p == '\n'; @@ -1618,6 +1625,7 @@ vim_str2nr_proceed: /// /// @return The value of the hex character. int hex2nr(int c) + FUNC_ATTR_CONST { if ((c >= 'a') && (c <= 'f')) { return c - 'a' + 10; @@ -1632,6 +1640,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) + FUNC_ATTR_PURE { if (!ascii_isxdigit(p[0]) || !ascii_isxdigit(p[1])) { return -1; diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 9e8fa2e62d..2fa96e4fc2 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -284,8 +284,8 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T tp->tp_diff_update = true; } - int inserted; - int deleted; + long inserted; + long deleted; if (line2 == MAXLNUM) { // mark_adjust(99, MAXLNUM, 9, 0): insert lines inserted = amount; @@ -304,8 +304,8 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T diff_T *dp = tp->tp_first_diff; linenr_T lnum_deleted = line1; // lnum of remaining deletion - int n; - int off; + linenr_T n; + linenr_T off; for (;;) { // If the change is after the previous diff block and before the next // diff block, thus not touching an existing change, create a new diff @@ -556,8 +556,8 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp) } // First check lines at the top, then at the bottom. - int off_org = 0; - int off_new = 0; + linenr_T off_org = 0; + linenr_T off_new = 0; int dir = FORWARD; for (;;) { // Repeat until a line is found which is different or the number of @@ -722,7 +722,7 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din) for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { len += (long)STRLEN(ml_get_buf(buf, lnum, false)) + 1; } - char_u *ptr = try_malloc(len); + char_u *ptr = try_malloc((size_t)len); if (ptr == NULL) { // Allocating memory failed. This can happen, because we try to read // the whole buffer text into memory. Set the failed flag, the diff @@ -756,9 +756,9 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din) const int orig_len = utfc_ptr2len(s); if (utf_char2bytes(c, cbuf) != orig_len) { // TODO(Bram): handle byte length difference - memmove(ptr + len, s, orig_len); + memmove(ptr + len, s, (size_t)orig_len); } else { - memmove(ptr + len, cbuf, orig_len); + memmove(ptr + len, cbuf, (size_t)orig_len); } s += orig_len; @@ -1072,7 +1072,7 @@ static int diff_file_internal(diffio_T *diffio) memset(&emit_cfg, 0, sizeof(emit_cfg)); memset(&emit_cb, 0, sizeof(emit_cb)); - param.flags = diff_algorithm; + param.flags = (unsigned long)diff_algorithm; if (diff_flags & DIFF_IWHITE) { param.flags |= XDF_IGNORE_WHITESPACE_CHANGE; @@ -1891,13 +1891,13 @@ int diff_check(win_T *wp, linenr_T lnum) // Insert filler lines above the line just below the change. Will return // 0 when this buf had the max count. - int maxcount = 0; + linenr_T maxcount = 0; for (int i = 0; i < DB_COUNT; i++) { if ((curtab->tp_diffbuf[i] != NULL) && (dp->df_count[i] > maxcount)) { maxcount = dp->df_count[i]; } } - return maxcount - dp->df_count[idx]; + return (int)(maxcount - dp->df_count[idx]); } /// Compare two entries in diff "dp" and return true if they are equal. @@ -2062,7 +2062,7 @@ void diff_set_topline(win_T *fromwin, win_T *towin) if (lnum >= dp->df_lnum[fromidx]) { // Inside a change: compute filler lines. With three or more // buffers we need to know the largest count. - int max_count = 0; + linenr_T max_count = 0; for (int i = 0; i < DB_COUNT; i++) { if ((curtab->tp_diffbuf[i] != NULL) && (max_count < dp->df_count[i])) { @@ -2099,7 +2099,7 @@ void diff_set_topline(win_T *fromwin, win_T *towin) towin->w_topfill = fromwin->w_topfill; } else { // fromwin has some diff lines - towin->w_topfill = dp->df_lnum[fromidx] + max_count - lnum; + towin->w_topfill = (int)(dp->df_lnum[fromidx] + max_count - lnum); } } } @@ -2312,7 +2312,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) return false; } - int off = lnum - dp->df_lnum[idx]; + linenr_T off = lnum - dp->df_lnum[idx]; int i; for (i = 0; i < DB_COUNT; i++) { if ((curtab->tp_diffbuf[i] != NULL) && (i != idx)) { @@ -2493,7 +2493,7 @@ void nv_diffgetput(bool put, size_t count) void ex_diffgetput(exarg_T *eap) { linenr_T lnum; - int count; + linenr_T count; linenr_T off = 0; diff_T *dp; diff_T *dfree; @@ -2502,8 +2502,9 @@ void ex_diffgetput(exarg_T *eap) char_u *p; aco_save_T aco; buf_T *buf; - int start_skip, end_skip; - int new_count; + linenr_T start_skip; + linenr_T end_skip; + linenr_T new_count; int buf_empty; int found_not_ma = false; int idx_other; @@ -2562,7 +2563,7 @@ void ex_diffgetput(exarg_T *eap) if (eap->arg + i == p) { // digits only - i = atol((char *)eap->arg); + i = (int)atol((char *)eap->arg); } else { i = buflist_findpat(eap->arg, p, false, true, false); @@ -2671,7 +2672,7 @@ void ex_diffgetput(exarg_T *eap) // range ends above end of current/from diff block if (idx_cur == idx_from) { // :diffput - i = dp->df_count[idx_cur] - start_skip - end_skip; + i = (int)(dp->df_count[idx_cur] - start_skip - end_skip); if (count > i) { count = i; @@ -2914,7 +2915,7 @@ int diff_move_to(int dir, long count) /// "buf1" in diff mode. static linenr_T diff_get_corresponding_line_int(buf_T *buf1, linenr_T lnum1) { - int baseline = 0; + linenr_T baseline = 0; int idx1 = diff_buf_idx(buf1); int idx2 = diff_buf_idx(curbuf); diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 47d491033b..48436f1115 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -846,6 +846,7 @@ static int insert_execute(VimState *state, int key) /// Don't do this when still processing a command or a mapping. /// Don't do this when inside a ":normal" command. bool goto_im(void) + FUNC_ATTR_PURE { return p_im && stuff_empty() && typebuf_typed(); } @@ -1654,7 +1655,7 @@ void edit_putchar(int c, bool highlight) /// Return the effective prompt for the specified buffer. char_u *buf_prompt_text(const buf_T *const buf) - FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE { if (buf->b_prompt_text == NULL) { return (char_u *)"% "; @@ -1663,7 +1664,8 @@ char_u *buf_prompt_text(const buf_T *const buf) } // Return the effective prompt for the current buffer. -char_u *prompt_text(void) FUNC_ATTR_WARN_UNUSED_RESULT +char_u *prompt_text(void) + FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE { return buf_prompt_text(curbuf); } @@ -1711,6 +1713,7 @@ static void init_prompt(int cmdchar_todo) /// @return true if the cursor is in the editable position of the prompt line. bool prompt_curpos_editable(void) + FUNC_ATTR_PURE { return curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count && curwin->w_cursor.col >= (int)STRLEN(prompt_text()); @@ -2101,6 +2104,7 @@ static void ins_ctrl_x(void) // Whether other than default completion has been selected. bool ctrl_x_mode_not_default(void) + FUNC_ATTR_PURE { return ctrl_x_mode != CTRL_X_NORMAL; } @@ -2108,6 +2112,7 @@ bool ctrl_x_mode_not_default(void) // Whether CTRL-X was typed without a following character, // not including when in CTRL-X CTRL-V mode. bool ctrl_x_mode_not_defined_yet(void) + FUNC_ATTR_PURE { return ctrl_x_mode == CTRL_X_NOT_DEFINED_YET; } @@ -3140,6 +3145,7 @@ static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, * Returns a pointer to the first char of the word. Also stops at a NUL. */ char_u *find_word_start(char_u *ptr) + FUNC_ATTR_PURE { while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1) { ptr += utfc_ptr2len(ptr); @@ -3152,6 +3158,7 @@ char_u *find_word_start(char_u *ptr) * Returns a pointer to just after the word. */ char_u *find_word_end(char_u *ptr) + FUNC_ATTR_PURE { const int start_class = mb_get_class(ptr); if (start_class > 1) { @@ -7144,6 +7151,7 @@ int stuff_inserted(int c, long count, int no_esc) } char_u *get_last_insert(void) + FUNC_ATTR_PURE { if (last_insert == NULL) { return NULL; @@ -7521,7 +7529,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) // Does it look like a control character? if (*look == '^' && look[1] >= '?' && look[1] <= '_') { - if (try_match && keytyped == Ctrl_chr(look[1])) { + if (try_match && keytyped == CTRL_CHR(look[1])) { return true; } look += 2; @@ -7690,6 +7698,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) * Map Hebrew keyboard when in hkmap mode. */ int hkmap(int c) + FUNC_ATTR_PURE { if (p_hkmapp) { // phonetic mapping, by Ilya Dogolazky enum { @@ -7727,7 +7736,7 @@ int hkmap(int c) }; if (c == 'N' || c == 'M' || c == 'P' || c == 'C' || c == 'Z') { - return (int)(map[CharOrd(c)] - 1 + p_aleph); + return (int)(map[CHAR_ORD(c)] - 1 + p_aleph); } else if (c == 'x') { // '-1'='sofit' return 'X'; } else if (c == 'q') { @@ -7743,7 +7752,7 @@ int hkmap(int c) // do this the same was as 5.7 and previous, so it works correctly on // all systems. Specifically, the e.g. Delete and Arrow keys are // munged and won't work if e.g. searching for Hebrew text. - return (int)(map[CharOrdLow(c)] + p_aleph); + return (int)(map[CHAR_ORD_LOW(c)] + p_aleph); } else { return c; } @@ -7773,12 +7782,12 @@ int hkmap(int c) if (c < 'a' || c > 'z') { return c; } - c = str[CharOrdLow(c)]; + c = str[CHAR_ORD_LOW(c)]; break; } } - return (int)(CharOrdLow(c) + p_aleph); + return (int)(CHAR_ORD_LOW(c) + p_aleph); } } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 0c45f05640..e192a6de6b 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2720,7 +2720,7 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) if (cmdidx == CMD_let || cmdidx == CMD_const) { xp->xp_context = EXPAND_USER_VARS; - if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL) { + if (strpbrk((char *)arg, "\"'+-*/%.=!?~|&$([<>,#") == NULL) { // ":let var1 var2 ...": find last space. for (p = arg + STRLEN(arg); p >= arg;) { xp->xp_pattern = p; @@ -2735,8 +2735,7 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS : EXPAND_EXPRESSION; } - while ((xp->xp_pattern = vim_strpbrk(arg, - (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL) { + while ((xp->xp_pattern = (char_u *)strpbrk((char *)arg, "\"'+-*/%.=!?~|&$([<>,#")) != NULL) { c = *xp->xp_pattern; if (c == '&') { c = xp->xp_pattern[1]; @@ -5050,6 +5049,7 @@ static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate) /// @return the function name of the partial. char_u *partial_name(partial_T *pt) + FUNC_ATTR_PURE { if (pt->pt_name != NULL) { return pt->pt_name; @@ -8525,6 +8525,7 @@ static void check_vars(const char *name, size_t len) /// check if special v:lua value for calling lua functions bool is_luafunc(partial_T *partial) + FUNC_ATTR_PURE { return partial == vvlua_partial; } @@ -9922,6 +9923,7 @@ void func_line_end(void *cookie) } static var_flavour_T var_flavour(char_u *varname) + FUNC_ATTR_PURE { char_u *p = varname; @@ -10199,7 +10201,7 @@ repeat: // Do not call shorten_fname() here since it removes the prefix // even though the path does not have a prefix. - if (fnamencmp(p, dirname, namelen) == 0) { + if (FNAMENCMP(p, dirname, namelen) == 0) { p += namelen; if (vim_ispathsep(*p)) { while (*p && vim_ispathsep(*p)) { diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index 6f4357421b..b04e3c04d6 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -29,8 +29,6 @@ #include "nvim/message.h" #include "nvim/vim.h" // For _() -#define utf_char2len(b) ((size_t)utf_char2len(b)) - const char *const encode_bool_var_names[] = { [kBoolVarTrue] = "true", [kBoolVarFalse] = "false", @@ -653,7 +651,7 @@ static inline int convert_to_json_string(garray_T *const gap, const char *const ga_grow(gap, (int)str_len); for (size_t i = 0; i < utf_len;) { const int ch = utf_ptr2char((char_u *)utf_buf + i); - const size_t shift = (ch == 0? 1: utf_char2len(ch)); + const size_t shift = (ch == 0 ? 1 : ((size_t)utf_char2len(ch))); assert(shift > 0); // Is false on invalid unicode, but this should already be handled. assert(ch == 0 || shift == ((size_t)utf_ptr2len((char_u *)utf_buf + i))); diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 609db3990b..5d192eb4b3 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2182,7 +2182,7 @@ static void f_menu_get(typval_T *argvars, typval_T *rettv, FunPtr fptr) const char *const strmodes = tv_get_string(&argvars[1]); modes = get_menu_cmd_modes(strmodes, false, NULL, NULL); } - menu_get((char_u *)tv_get_string(&argvars[0]), modes, rettv->vval.v_list); + menu_get((char *)tv_get_string(&argvars[0]), modes, rettv->vval.v_list); } /// "expandcmd()" function @@ -3256,7 +3256,7 @@ static void f_getcompletion(typval_T *argvars, typval_T *rettv, FunPtr fptr) } if (xpc.xp_context == EXPAND_MENUS) { - set_context_in_menu_cmd(&xpc, "menu", xpc.xp_pattern, false); + set_context_in_menu_cmd(&xpc, "menu", (char *)xpc.xp_pattern, false); xpc.xp_pattern_len = STRLEN(xpc.xp_pattern); } diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 0fadc0d220..340b731312 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -2503,7 +2503,7 @@ void ex_function(exarg_T *eap) p = vim_strchr(scriptname, '/'); plen = (int)STRLEN(p); slen = (int)STRLEN(sourcing_name); - if (slen > plen && fnamecmp(p, + if (slen > plen && FNAMECMP(p, sourcing_name + slen - plen) == 0) { j = OK; } diff --git a/src/nvim/event/loop.h b/src/nvim/event/loop.h index acd1d1a334..b3cd60f53d 100644 --- a/src/nvim/event/loop.h +++ b/src/nvim/event/loop.h @@ -10,8 +10,8 @@ typedef void *WatcherPtr; -#define _noop(x) -KLIST_INIT(WatcherPtr, WatcherPtr, _noop) +#define _NOOP(x) +KLIST_INIT(WatcherPtr, WatcherPtr, _NOOP) typedef struct loop { uv_loop_t uv; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index e16537c192..d4c21bb33f 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4969,6 +4969,7 @@ char_u *check_help_lang(char_u *arg) /// /// @return a heuristic indicating how well the given string matches. int help_heuristic(char_u *matched_string, int offset, int wrong_case) + FUNC_ATTR_PURE { int num_letters; char_u *p; @@ -5342,8 +5343,8 @@ void fix_help_buffer(void) * files. This uses the very first line in the help file. */ char_u *const fname = path_tail(curbuf->b_fname); - if (fnamecmp(fname, "help.txt") == 0 - || (fnamencmp(fname, "help.", 5) == 0 + if (FNAMECMP(fname, "help.txt") == 0 + || (FNAMENCMP(fname, "help.", 5) == 0 && ASCII_ISALPHA(fname[5]) && ASCII_ISALPHA(fname[6]) && TOLOWER_ASC(fname[7]) == 'x' @@ -5401,18 +5402,18 @@ void fix_help_buffer(void) if (e1 == NULL || e2 == NULL) { continue; } - if (fnamecmp(e1, ".txt") != 0 - && fnamecmp(e1, fname + 4) != 0) { + if (FNAMECMP(e1, ".txt") != 0 + && FNAMECMP(e1, fname + 4) != 0) { // Not .txt and not .abx, remove it. XFREE_CLEAR(fnames[i1]); continue; } if (e1 - f1 != e2 - f2 - || fnamencmp(f1, f2, e1 - f1) != 0) { + || FNAMENCMP(f1, f2, e1 - f1) != 0) { continue; } - if (fnamecmp(e1, ".txt") == 0 - && fnamecmp(e2, fname + 4) == 0) { + if (FNAMECMP(e1, ".txt") == 0 + && FNAMECMP(e2, fname + 4) == 0) { // use .abx instead of .txt XFREE_CLEAR(fnames[i1]); } diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index ac1d760bce..5af202c191 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -201,6 +201,7 @@ static char *pexpand_cmds[] = { /// Function given to ExpandGeneric() to obtain the profile command /// specific expansion. char_u *get_profile_name(expand_T *xp, int idx) + FUNC_ATTR_PURE { switch (pexpand_what) { case PEXP_SUBCMD: @@ -439,6 +440,7 @@ static void script_dump_profile(FILE *fd) /// @return true when a function defined in the current script should be /// profiled. bool prof_def_func(void) + FUNC_ATTR_PURE { if (current_sctx.sc_sid > 0) { return SCRIPT_ITEM(current_sctx.sc_sid).sn_pr_force; @@ -1732,6 +1734,7 @@ int *source_dbg_tick(void *cookie) /// @return the nesting level for a source cookie. int source_level(void *cookie) + FUNC_ATTR_PURE { return ((struct source_cookie *)cookie)->level; } @@ -2176,7 +2179,7 @@ scriptitem_T *get_current_script_id(char_u *fname, sctx_T *ret_sctx) bool file_id_equal = file_id_ok && si->file_id_valid && os_fileid_equal(&(si->file_id), &file_id); if (si->sn_name != NULL - && (file_id_equal || fnamecmp(si->sn_name, fname) == 0)) { + && (file_id_equal || FNAMECMP(si->sn_name, fname) == 0)) { break; } } @@ -2288,6 +2291,7 @@ void free_scriptnames(void) #endif linenr_T get_sourced_lnum(LineGetter fgetline, void *cookie) + FUNC_ATTR_PURE { return fgetline == getsourceline ? ((struct source_cookie *)cookie)->sourcing_lnum diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index b67754ffe5..2311e80de4 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -44,8 +44,8 @@ #include "nvim/keymap.h" #include "nvim/lua/executor.h" #include "nvim/main.h" -#include "nvim/match.h" #include "nvim/mark.h" +#include "nvim/match.h" #include "nvim/mbyte.h" #include "nvim/memline.h" #include "nvim/memory.h" @@ -2663,9 +2663,9 @@ static char_u *find_command(exarg_T *eap, int *full) // Use a precomputed index for fast look-up in cmdnames[] // taking into account the first 2 letters of eap->cmd. - eap->cmdidx = cmdidxs1[CharOrdLow(c1)]; + eap->cmdidx = cmdidxs1[CHAR_ORD_LOW(c1)]; if (ASCII_ISLOWER(c2)) { - eap->cmdidx += cmdidxs2[CharOrdLow(c1)][CharOrdLow(c2)]; + eap->cmdidx += cmdidxs2[CHAR_ORD_LOW(c1)][CHAR_ORD_LOW(c2)]; } } else { eap->cmdidx = CMD_bang; @@ -3616,8 +3616,7 @@ const char *set_one_cmd_context(expand_T *xp, const char *buff) // EX_XFILE: file names are handled above. if (!(ea.argt & EX_XFILE)) { if (context == EXPAND_MENUS) { - return (const char *)set_context_in_menu_cmd(xp, cmd, - (char_u *)arg, forceit); + return (const char *)set_context_in_menu_cmd(xp, cmd, (char *)arg, forceit); } else if (context == EXPAND_COMMANDS) { return arg; } else if (context == EXPAND_MAPPINGS) { @@ -3723,7 +3722,7 @@ const char *set_one_cmd_context(expand_T *xp, const char *buff) case CMD_tunmenu: case CMD_popup: case CMD_emenu: - return (const char *)set_context_in_menu_cmd(xp, cmd, (char_u *)arg, forceit); + return (const char *)set_context_in_menu_cmd(xp, cmd, (char *)arg, forceit); case CMD_colorscheme: xp->xp_context = EXPAND_COLORS; @@ -4520,7 +4519,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp) if ((eap->usefilter || eap->cmdidx == CMD_bang || eap->cmdidx == CMD_terminal) - && vim_strpbrk(repl, (char_u *)"!") != NULL) { + && strpbrk((char *)repl, "!") != NULL) { char_u *l; l = vim_strsave_escaped(repl, (char_u *)"!"); diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index f4aaab5c43..102d817694 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -75,7 +75,10 @@ || (cstack->cs_idx > 0 \ && !(cstack->cs_flags[cstack->cs_idx - 1] & CSF_ACTIVE))) -#define discard_pending_return(p) tv_free((typval_T *)(p)) +static void discard_pending_return(typval_T *p) +{ + tv_free(p); +} /* * When several errors appear in a row, setting "force_abort" is delayed until @@ -129,6 +132,7 @@ int should_abort(int retcode) /// to find finally clauses to be executed, and that some errors in skipped /// commands are still reported. int aborted_in_try(void) + FUNC_ATTR_PURE { // This function is only called after an error. In this case, "force_abort" // determines whether searching for finally clauses is necessary. @@ -388,12 +392,12 @@ char *get_exception_string(void *value, except_type_T type, char_u *cmdname, int mesg = ((struct msglist *)value)->throw_msg; if (cmdname != NULL && *cmdname != NUL) { size_t cmdlen = STRLEN(cmdname); - ret = (char *)vim_strnsave((char_u *)"Vim(", 4 + cmdlen + 2 + STRLEN(mesg)); + ret = xstrnsave("Vim(", 4 + cmdlen + 2 + STRLEN(mesg)); STRCPY(&ret[4], cmdname); STRCPY(&ret[4 + cmdlen], "):"); val = ret + 4 + cmdlen + 2; } else { - ret = (char *)vim_strnsave((char_u *)"Vim:", 4 + STRLEN(mesg)); + ret = xstrnsave("Vim:", 4 + STRLEN(mesg)); val = ret + 4; } diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 15f1d3d065..8a09c10908 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -924,8 +924,8 @@ char_u *vim_findfile(void *search_ctx_arg) */ if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0) { for (int i = stackp->ffs_filearray_cur; - i < stackp->ffs_filearray_size; ++i) { - if (fnamecmp(stackp->ffs_filearray[i], + i < stackp->ffs_filearray_size; i++) { + if (FNAMECMP(stackp->ffs_filearray[i], stackp->ffs_fix_path) == 0) { continue; // don't repush same directory } @@ -1050,7 +1050,7 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, if (*list_headp != NULL) { retptr = *list_headp; while (retptr != NULL) { - if (fnamecmp(filename, retptr->ffvl_filename) == 0) { + if (FNAMECMP(filename, retptr->ffvl_filename) == 0) { #ifdef FF_VERBOSE if (p_verbose >= 5) { verbose_enter_scroll(); @@ -1151,7 +1151,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * // check against list of already visited files for (vp = *visited_list; vp != NULL; vp = vp->ffv_next) { - if ((url && fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0) + if ((url && FNAMECMP(vp->ffv_fname, ff_expand_buffer) == 0) || (!url && vp->file_id_valid && os_fileid_equal(&(vp->file_id), &file_id))) { // are the wildcard parts equal @@ -1317,13 +1317,13 @@ static int ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v) * '/home/rks'. Check for PATHSEP in stopdirs_v[i], else * '/home/r' would also match '/home/rks' */ - if (fnamencmp(stopdirs_v[i], path, path_len) == 0 + if (FNAMENCMP(stopdirs_v[i], path, path_len) == 0 && vim_ispathsep(stopdirs_v[i][path_len])) { return TRUE; } } else { - if (fnamecmp(stopdirs_v[i], path) == 0) { - return TRUE; + if (FNAMECMP(stopdirs_v[i], path) == 0) { + return true; } } } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index be66a6ce80..282e25e10e 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2321,8 +2321,8 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_ fname = sfname; #endif - if (buf->b_ffname != NULL && fnamecmp(ffname, buf->b_ffname) == 0) { - overwriting = TRUE; + if (buf->b_ffname != NULL && FNAMECMP(ffname, buf->b_ffname) == 0) { + overwriting = true; } else { overwriting = FALSE; } @@ -4647,7 +4647,7 @@ int vim_rename(const char_u *from, const char_u *to) * to the same file (ignoring case and slash/backslash differences) but * the file name differs we need to go through a temp file. */ - if (fnamecmp(from, to) == 0) { + if (FNAMECMP(from, to) == 0) { if (p_fic && (STRCMP(path_tail((char_u *)from), path_tail((char_u *)to)) != 0)) { use_tmp_file = true; diff --git a/src/nvim/garray.c b/src/nvim/garray.c index 7a3cc4a944..0c76e1a919 100644 --- a/src/nvim/garray.c +++ b/src/nvim/garray.c @@ -123,7 +123,7 @@ void ga_remove_duplicate_strings(garray_T *gap) // loop over the growing array in reverse for (int i = gap->ga_len - 1; i > 0; i--) { - if (fnamecmp(fnames[i - 1], fnames[i]) == 0) { + if (FNAMECMP(fnames[i - 1], fnames[i]) == 0) { xfree(fnames[i]); // close the gap (move all strings one slot lower) diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 85479b220a..f2df7b49fd 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -397,6 +397,7 @@ static void start_stuff(void) * 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); } @@ -406,6 +407,7 @@ int stuff_empty(void) * redbuf2. */ int readbuf1_empty(void) + FUNC_ATTR_PURE { return (readbuf1.bh_first.b_next == NULL); } @@ -1025,10 +1027,10 @@ int ins_char_typebuf(int c, int modifier) /// /// @param tb_change_cnt old value of typebuf.tb_change_cnt bool typebuf_changed(int tb_change_cnt) + FUNC_ATTR_PURE { return tb_change_cnt != 0 && (typebuf.tb_change_cnt != tb_change_cnt - || typebuf_was_filled - ); + || typebuf_was_filled); } /* @@ -1036,6 +1038,7 @@ bool typebuf_changed(int tb_change_cnt) * not been typed (result from a mapping or come from ":normal"). */ int typebuf_typed(void) + FUNC_ATTR_PURE { return typebuf.tb_maplen == 0; } @@ -1044,6 +1047,7 @@ int typebuf_typed(void) * Return the number of characters that are mapped (or not typed). */ int typebuf_maplen(void) + FUNC_ATTR_PURE { return typebuf.tb_maplen; } @@ -1403,6 +1407,7 @@ void close_all_scripts(void) * Return TRUE when reading keys from a script file. */ int using_script(void) + FUNC_ATTR_PURE { return scriptin[curscript] != NULL; } diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 575b239f5a..8e03a8827c 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -1869,8 +1869,6 @@ static void prt_dsc_text(char *comment, char *text) prt_write_file(prt_line_buffer); } -#define prt_dsc_atend(c) prt_dsc_text((c), "atend") - static void prt_dsc_ints(char *comment, int count, int *ints) { int i; @@ -2534,7 +2532,7 @@ bool mch_print_begin(prt_settings_T *psettings) prt_dsc_textline("CreationDate", p_time); prt_dsc_textline("DocumentData", "Clean8Bit"); prt_dsc_textline("Orientation", "Portrait"); - prt_dsc_atend("Pages"); + prt_dsc_text(("Pages"), "atend"); prt_dsc_textline("PageOrder", "Ascend"); // The bbox does not change with orientation - it is always in the default // user coordinate system! We have to recalculate right and bottom diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 9ca01137cf..093ca238f1 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -433,7 +433,7 @@ static int cs_add_common(char *arg1, char *arg2, char *flags) if (fname == NULL) { goto add_err; } - fname = (char *)vim_strnsave((char_u *)fname, len); + fname = xstrnsave(fname, len); xfree(fbuf); FileInfo file_info; bool file_info_ok = os_fileinfo(fname, &file_info); diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c index 1e305528ba..3fdc140ebd 100644 --- a/src/nvim/keymap.c +++ b/src/nvim/keymap.c @@ -775,7 +775,7 @@ static int extract_modifiers(int key, int *modp) } if ((modifiers & MOD_MASK_CTRL) && ((key >= '?' && key <= '_') || ASCII_ISALPHA(key))) { key = TOUPPER_ASC(key); - int new_key = Ctrl_chr(key); + int new_key = CTRL_CHR(key); if (new_key != TAB && new_key != CAR && new_key != ESC) { key = new_key; modifiers &= ~MOD_MASK_CTRL; diff --git a/src/nvim/macros.h b/src/nvim/macros.h index be1ab935c0..0af7483154 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -83,11 +83,11 @@ // mch_open_rw(): invoke os_open() with third argument for user R/W. #if defined(UNIX) // open in rw------- mode -# define mch_open_rw(n, f) os_open((n), (f), (mode_t)0600) +# define MCH_OPEN_RW(n, f) os_open((n), (f), (mode_t)0600) #elif defined(WIN32) -# define mch_open_rw(n, f) os_open((n), (f), S_IREAD | S_IWRITE) +# define MCH_OPEN_RW(n, f) os_open((n), (f), S_IREAD | S_IWRITE) #else -# define mch_open_rw(n, f) os_open((n), (f), 0) +# define MCH_OPEN_RW(n, f) os_open((n), (f), 0) #endif #define REPLACE_NORMAL(s) (((s) & REPLACE_FLAG) && !((s) & VREPLACE_FLAG)) diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 6790bf8240..0dbfb0c49f 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -551,7 +551,7 @@ static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf) { if (fm->fmark.fnum == 0 && fm->fname != NULL - && fnamecmp(name, fm->fname) == 0) { + && FNAMECMP(name, fm->fname) == 0) { fm->fmark.fnum = buf->b_fnum; XFREE_CLEAR(fm->fname); } @@ -923,7 +923,7 @@ void ex_changes(exarg_T *eap) } } -#define one_adjust(add) \ +#define ONE_ADJUST(add) \ { \ lp = add; \ if (*lp >= line1 && *lp <= line2) \ @@ -938,7 +938,7 @@ void ex_changes(exarg_T *eap) } // don't delete the line, just put at first deleted line -#define one_adjust_nodel(add) \ +#define ONE_ADJUST_NODEL(add) \ { \ lp = add; \ if (*lp >= line1 && *lp <= line2) \ @@ -994,37 +994,37 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, lo if (!cmdmod.lockmarks) { // named marks, lower case and upper case for (i = 0; i < NMARKS; i++) { - one_adjust(&(curbuf->b_namedm[i].mark.lnum)); + ONE_ADJUST(&(curbuf->b_namedm[i].mark.lnum)); if (namedfm[i].fmark.fnum == fnum) { - one_adjust_nodel(&(namedfm[i].fmark.mark.lnum)); + ONE_ADJUST_NODEL(&(namedfm[i].fmark.mark.lnum)); } } for (i = NMARKS; i < NGLOBALMARKS; i++) { if (namedfm[i].fmark.fnum == fnum) { - one_adjust_nodel(&(namedfm[i].fmark.mark.lnum)); + ONE_ADJUST_NODEL(&(namedfm[i].fmark.mark.lnum)); } } // last Insert position - one_adjust(&(curbuf->b_last_insert.mark.lnum)); + ONE_ADJUST(&(curbuf->b_last_insert.mark.lnum)); // last change position - one_adjust(&(curbuf->b_last_change.mark.lnum)); + ONE_ADJUST(&(curbuf->b_last_change.mark.lnum)); // last cursor position, if it was set if (!equalpos(curbuf->b_last_cursor.mark, initpos)) { - one_adjust(&(curbuf->b_last_cursor.mark.lnum)); + ONE_ADJUST(&(curbuf->b_last_cursor.mark.lnum)); } // list of change positions - for (i = 0; i < curbuf->b_changelistlen; ++i) { - one_adjust_nodel(&(curbuf->b_changelist[i].mark.lnum)); + for (i = 0; i < curbuf->b_changelistlen; i++) { + ONE_ADJUST_NODEL(&(curbuf->b_changelist[i].mark.lnum)); } // Visual area - one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum)); - one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum)); + ONE_ADJUST_NODEL(&(curbuf->b_visual.vi_start.lnum)); + ONE_ADJUST_NODEL(&(curbuf->b_visual.vi_end.lnum)); // quickfix marks if (!qf_mark_adjust(NULL, line1, line2, amount, amount_after)) { @@ -1047,14 +1047,14 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, lo } // previous context mark - one_adjust(&(curwin->w_pcmark.lnum)); + ONE_ADJUST(&(curwin->w_pcmark.lnum)); // previous pcmark - one_adjust(&(curwin->w_prev_pcmark.lnum)); + ONE_ADJUST(&(curwin->w_prev_pcmark.lnum)); // saved cursor for formatting if (saved_cursor.lnum != 0) { - one_adjust_nodel(&(saved_cursor.lnum)); + ONE_ADJUST_NODEL(&(saved_cursor.lnum)); } /* @@ -1066,7 +1066,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, lo // duplicate marks in the jumplist, they will be removed later. for (i = 0; i < win->w_jumplistlen; i++) { if (win->w_jumplist[i].fmark.fnum == fnum) { - one_adjust_nodel(&(win->w_jumplist[i].fmark.mark.lnum)); + ONE_ADJUST_NODEL(&(win->w_jumplist[i].fmark.mark.lnum)); } } } @@ -1076,15 +1076,15 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, lo // marks in the tag stack for (i = 0; i < win->w_tagstacklen; i++) { if (win->w_tagstack[i].fmark.fnum == fnum) { - one_adjust_nodel(&(win->w_tagstack[i].fmark.mark.lnum)); + ONE_ADJUST_NODEL(&(win->w_tagstack[i].fmark.mark.lnum)); } } } // the displayed Visual area if (win->w_old_cursor_lnum != 0) { - one_adjust_nodel(&(win->w_old_cursor_lnum)); - one_adjust_nodel(&(win->w_old_visual_lnum)); + ONE_ADJUST_NODEL(&(win->w_old_cursor_lnum)); + ONE_ADJUST_NODEL(&(win->w_old_visual_lnum)); } // topline and cursor position for windows with the same buffer @@ -1132,7 +1132,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, lo } // This code is used often, needs to be fast. -#define col_adjust(pp) \ +#define COL_ADJUST(pp) \ { \ posp = pp; \ if (posp->lnum == lnum && posp->col >= mincol) \ @@ -1166,40 +1166,40 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, long lnum_amount, long col_a } // named marks, lower case and upper case for (i = 0; i < NMARKS; i++) { - col_adjust(&(curbuf->b_namedm[i].mark)); + COL_ADJUST(&(curbuf->b_namedm[i].mark)); if (namedfm[i].fmark.fnum == fnum) { - col_adjust(&(namedfm[i].fmark.mark)); + COL_ADJUST(&(namedfm[i].fmark.mark)); } } for (i = NMARKS; i < NGLOBALMARKS; i++) { if (namedfm[i].fmark.fnum == fnum) { - col_adjust(&(namedfm[i].fmark.mark)); + COL_ADJUST(&(namedfm[i].fmark.mark)); } } // last Insert position - col_adjust(&(curbuf->b_last_insert.mark)); + COL_ADJUST(&(curbuf->b_last_insert.mark)); // last change position - col_adjust(&(curbuf->b_last_change.mark)); + COL_ADJUST(&(curbuf->b_last_change.mark)); // list of change positions - for (i = 0; i < curbuf->b_changelistlen; ++i) { - col_adjust(&(curbuf->b_changelist[i].mark)); + for (i = 0; i < curbuf->b_changelistlen; i++) { + COL_ADJUST(&(curbuf->b_changelist[i].mark)); } // Visual area - col_adjust(&(curbuf->b_visual.vi_start)); - col_adjust(&(curbuf->b_visual.vi_end)); + COL_ADJUST(&(curbuf->b_visual.vi_start)); + COL_ADJUST(&(curbuf->b_visual.vi_end)); // previous context mark - col_adjust(&(curwin->w_pcmark)); + COL_ADJUST(&(curwin->w_pcmark)); // previous pcmark - col_adjust(&(curwin->w_prev_pcmark)); + COL_ADJUST(&(curwin->w_prev_pcmark)); // saved cursor for formatting - col_adjust(&saved_cursor); + COL_ADJUST(&saved_cursor); /* * Adjust items in all windows related to the current buffer. @@ -1208,7 +1208,7 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, long lnum_amount, long col_a // marks in the jumplist for (i = 0; i < win->w_jumplistlen; ++i) { if (win->w_jumplist[i].fmark.fnum == fnum) { - col_adjust(&(win->w_jumplist[i].fmark.mark)); + COL_ADJUST(&(win->w_jumplist[i].fmark.mark)); } } @@ -1216,13 +1216,13 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, long lnum_amount, long col_a // marks in the tag stack for (i = 0; i < win->w_tagstacklen; i++) { if (win->w_tagstack[i].fmark.fnum == fnum) { - col_adjust(&(win->w_tagstack[i].fmark.mark)); + COL_ADJUST(&(win->w_tagstack[i].fmark.mark)); } } // cursor position for other windows with the same buffer if (win != curwin) { - col_adjust(&win->w_cursor); + COL_ADJUST(&win->w_cursor); } } } diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index f634c7dda8..6e3c5322e7 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -334,10 +334,9 @@ enc_alias_table[] = * Returns -1 if not found. */ static int enc_canon_search(const char_u *name) + FUNC_ATTR_PURE { - int i; - - for (i = 0; i < IDX_COUNT; ++i) { + for (int i = 0; i < IDX_COUNT; i++) { if (STRCMP(name, enc_canon_table[i].name) == 0) { return i; } @@ -351,10 +350,9 @@ static int enc_canon_search(const char_u *name) * Returns 0 if not found. */ int enc_canon_props(const char_u *name) + FUNC_ATTR_PURE { - int i; - - i = enc_canon_search(name); + int i = enc_canon_search(name); if (i >= 0) { return enc_canon_table[i].prop; } else if (STRNCMP(name, "2byte-", 6) == 0) { @@ -373,6 +371,7 @@ int enc_canon_props(const char_u *name) * 3 - UTF-8 BOM */ int bomb_size(void) + FUNC_ATTR_PURE { int n = 0; @@ -414,11 +413,13 @@ void remove_bom(char_u *s) * >2 for other word characters */ int mb_get_class(const char_u *p) + FUNC_ATTR_PURE { return mb_get_class_tab(p, curbuf->b_chartab); } int mb_get_class_tab(const char_u *p, const uint64_t *const chartab) + FUNC_ATTR_PURE { if (MB_BYTE2LEN(p[0]) == 1) { if (p[0] == NUL || ascii_iswhite(p[0])) { @@ -436,6 +437,7 @@ int mb_get_class_tab(const char_u *p, const uint64_t *const chartab) * Return true if "c" is in "table". */ static bool intable(const struct interval *table, size_t n_items, int c) + FUNC_ATTR_PURE { int mid, bot, top; @@ -1087,6 +1089,7 @@ int utf_class(const int c) } int utf_class_tab(const int c, const uint64_t *const chartab) + FUNC_ATTR_PURE { // sorted list of non-overlapping intervals static struct clinterval { diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 2a72d1e6a0..28337803ac 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -795,7 +795,7 @@ static bool mf_do_open(memfile_T *mfp, char_u *fname, int flags) emsg(_("E300: Swap file already exists (symlink attack?)")); } else { // try to open the file - mfp->mf_fd = mch_open_rw((char *)mfp->mf_fname, flags | O_NOFOLLOW); + mfp->mf_fd = MCH_OPEN_RW((char *)mfp->mf_fname, flags | O_NOFOLLOW); } // If the file cannot be opened, use memory only diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 55480ab384..5646b2db15 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -418,7 +418,7 @@ void ml_setname(buf_T *buf) } // if the file name is the same we don't have to do anything - if (fnamecmp(fname, mfp->mf_fname) == 0) { + if (FNAMECMP(fname, mfp->mf_fname) == 0) { xfree(fname); success = true; break; @@ -3459,7 +3459,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ } // A file name equal to old_fname is OK to use. - if (old_fname != NULL && fnamecmp(fname, old_fname) == 0) { + if (old_fname != NULL && FNAMECMP(fname, old_fname) == 0) { break; } @@ -3484,7 +3484,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ // buffer don't compare the directory names, they can // have a different mountpoint. if (b0.b0_flags & B0_SAME_DIR) { - if (fnamecmp(path_tail(buf->b_ffname), + if (FNAMECMP(path_tail(buf->b_ffname), path_tail(b0.b0_fname)) != 0 || !same_directory((char_u *)fname, buf->b_ffname)) { // Symlinks may point to the same file even diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 0db9d69a7e..f648a06284 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -38,20 +38,20 @@ /// The character for each menu mode -static char_u menu_mode_chars[] = { 'n', 'v', 's', 'o', 'i', 'c', 't' }; +static char menu_mode_chars[] = { 'n', 'v', 's', 'o', 'i', 'c', 't' }; -static char_u e_notsubmenu[] = N_("E327: Part of menu-item path is not sub-menu"); -static char_u e_othermode[] = N_("E328: Menu only exists in another mode"); -static char_u e_nomenu[] = N_("E329: No menu \"%s\""); +static char e_notsubmenu[] = N_("E327: Part of menu-item path is not sub-menu"); +static char e_othermode[] = N_("E328: Menu only exists in another mode"); +static char e_nomenu[] = N_("E329: No menu \"%s\""); // Return true if "name" is a window toolbar menu name. -static bool menu_is_winbar(const char_u *const name) +static bool menu_is_winbar(const char *const name) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { return (STRNCMP(name, "WinBar", 6) == 0); } -static vimmenu_T **get_root_menu(const char_u *const name) +static vimmenu_T **get_root_menu(const char *const name) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { return &root_menu; @@ -63,13 +63,13 @@ void ex_menu(exarg_T *eap) { char *menu_path; int modes; - char_u *map_to; // command mapped to the menu entry + char *map_to; // command mapped to the menu entry int noremap; bool silent = false; int unmenu; - char_u *map_buf; - char_u *arg; - char_u *p; + char *map_buf; + char *arg; + char *p; int i; long pri_tab[MENUDEPTH + 1]; TriState enable = kNone; // kTrue for "menu enable", @@ -77,22 +77,22 @@ void ex_menu(exarg_T *eap) vimmenu_T menuarg; modes = get_menu_cmd_modes((char *)eap->cmd, eap->forceit, &noremap, &unmenu); - arg = eap->arg; + arg = (char *)eap->arg; for (;;) { if (STRNCMP(arg, "<script>", 8) == 0) { noremap = REMAP_SCRIPT; - arg = skipwhite(arg + 8); + arg = (char *)skipwhite((char_u *)arg + 8); continue; } if (STRNCMP(arg, "<silent>", 8) == 0) { silent = true; - arg = skipwhite(arg + 8); + arg = (char *)skipwhite((char_u *)arg + 8); continue; } if (STRNCMP(arg, "<special>", 9) == 0) { // Ignore obsolete "<special>" modifier. - arg = skipwhite(arg + 9); + arg = (char *)skipwhite((char_u *)arg + 9); continue; } break; @@ -111,7 +111,7 @@ void ex_menu(exarg_T *eap) } if (*arg != NUL) { *arg++ = NUL; - arg = skipwhite(arg); + arg = (char *)skipwhite((char_u *)arg); } } @@ -123,7 +123,7 @@ void ex_menu(exarg_T *eap) } if (ascii_iswhite(*p)) { for (i = 0; i < MENUDEPTH && !ascii_iswhite(*arg); i++) { - pri_tab[i] = getdigits_long(&arg, false, 0); + pri_tab[i] = getdigits_long((char_u **)&arg, false, 0); if (pri_tab[i] == 0) { pri_tab[i] = 500; } @@ -131,7 +131,7 @@ void ex_menu(exarg_T *eap) arg++; } } - arg = skipwhite(arg); + arg = (char *)skipwhite((char_u *)arg); } else if (eap->addr_count && eap->line2 != 0) { pri_tab[0] = eap->line2; i = 1; @@ -148,10 +148,10 @@ void ex_menu(exarg_T *eap) */ if (STRNCMP(arg, "enable", 6) == 0 && ascii_iswhite(arg[6])) { enable = kTrue; - arg = skipwhite(arg + 6); + arg = (char *)skipwhite((char_u *)arg + 6); } else if (STRNCMP(arg, "disable", 7) == 0 && ascii_iswhite(arg[7])) { enable = kFalse; - arg = skipwhite(arg + 7); + arg = (char *)skipwhite((char_u *)arg + 7); } /* @@ -163,7 +163,7 @@ void ex_menu(exarg_T *eap) } - menu_path = (char *)arg; + menu_path = arg; if (*menu_path == '.') { semsg(_(e_invarg2), menu_path); goto theend; @@ -175,14 +175,14 @@ void ex_menu(exarg_T *eap) * If there is only a menu name, display menus with that name. */ if (*map_to == NUL && !unmenu && enable == kNone) { - show_menus((char_u *)menu_path, modes); + show_menus(menu_path, modes); goto theend; } else if (*map_to != NUL && (unmenu || enable != kNone)) { emsg(_(e_trailing)); goto theend; } - vimmenu_T **root_menu_ptr = get_root_menu((char_u *)menu_path); + vimmenu_T **root_menu_ptr = get_root_menu(menu_path); if (enable != kNone) { // Change sensitivity of the menu. @@ -201,7 +201,7 @@ void ex_menu(exarg_T *eap) } } } - menu_enable_recurse(*root_menu_ptr, (char_u *)menu_path, modes, enable); + menu_enable_recurse(*root_menu_ptr, menu_path, modes, enable); } else if (unmenu) { /* * Delete menu(s). @@ -224,25 +224,25 @@ void ex_menu(exarg_T *eap) } // Careful: remove_menu() changes menu_path - remove_menu(root_menu_ptr, (char_u *)menu_path, modes, false); + remove_menu(root_menu_ptr, menu_path, modes, false); } else { /* * Add menu(s). * Replace special key codes. */ if (STRICMP(map_to, "<nop>") == 0) { // "<Nop>" means nothing - map_to = (char_u *)""; + map_to = ""; map_buf = NULL; } else if (modes & MENU_TIP_MODE) { map_buf = NULL; // Menu tips are plain text. } else { - map_to = replace_termcodes(map_to, STRLEN(map_to), &map_buf, false, true, - true, CPO_TO_CPO_FLAGS); + map_to = (char *)replace_termcodes((char_u *)map_to, STRLEN(map_to), + (char_u **)&map_buf, false, true, true, CPO_TO_CPO_FLAGS); } menuarg.modes = modes; menuarg.noremap[0] = noremap; menuarg.silent[0] = silent; - add_menu_path((char_u *)menu_path, &menuarg, pri_tab, map_to); + add_menu_path(menu_path, &menuarg, pri_tab, map_to); /* * For the PopUp menu, add a menu for each mode separately. @@ -274,29 +274,29 @@ theend: /// @param[out] menuarg menu entry /// @param[] pri_tab priority table /// @param[in] call_data Right hand side command -static int add_menu_path(const char_u *const menu_path, vimmenu_T *menuarg, - const long *const pri_tab, const char_u *const call_data) +static int add_menu_path(const char *const menu_path, vimmenu_T *menuarg, const long *const pri_tab, + const char *const call_data) { - char_u *path_name; + char *path_name; int modes = menuarg->modes; vimmenu_T *menu = NULL; vimmenu_T *parent; vimmenu_T **lower_pri; - char_u *p; - char_u *name; - char_u *dname; - char_u *next_name; - char_u c; - char_u d; + char *p; + char *name; + char *dname; + char *next_name; + char c; + char d; int i; int pri_idx = 0; int old_modes = 0; int amenu; - char_u *en_name; - char_u *map_to = NULL; + char *en_name; + char *map_to = NULL; // Make a copy so we can stuff around with it, since it could be const - path_name = vim_strsave(menu_path); + path_name = xstrdup(menu_path); vimmenu_T **root_menu_ptr = get_root_menu(menu_path); vimmenu_T **menup = root_menu_ptr; parent = NULL; @@ -366,11 +366,11 @@ static int add_menu_path(const char_u *const menu_path, vimmenu_T *menuarg, menu->modes = modes; menu->enabled = MENU_ALL_MODES; - menu->name = vim_strsave(name); + menu->name = xstrdup(name); // separate mnemonic and accelerator text from actual menu name menu->dname = menu_text(name, &menu->mnemonic, &menu->actext); if (en_name != NULL) { - menu->en_name = vim_strsave(en_name); + menu->en_name = xstrdup(en_name); menu->en_dname = menu_text(en_name, NULL, NULL); } else { menu->en_name = NULL; @@ -420,7 +420,7 @@ static int add_menu_path(const char_u *const menu_path, vimmenu_T *menuarg, } if (menu != NULL && modes) { - p = (call_data == NULL) ? NULL : vim_strsave(call_data); + p = (call_data == NULL) ? NULL : xstrdup(call_data); // loop over all modes, may add more than one for (i = 0; i < MENU_MODES; ++i) { @@ -501,9 +501,9 @@ erret: * Set the (sub)menu with the given name to enabled or disabled. * Called recursively. */ -static int menu_enable_recurse(vimmenu_T *menu, char_u *name, int modes, int enable) +static int menu_enable_recurse(vimmenu_T *menu, char *name, int modes, int enable) { - char_u *p; + char *p; if (menu == NULL) { return OK; // Got to bottom of hierarchy @@ -552,11 +552,11 @@ static int menu_enable_recurse(vimmenu_T *menu, char_u *name, int modes, int ena /// Called recursively. /// /// @param silent don't give error messages -static int remove_menu(vimmenu_T **menup, char_u *name, int modes, bool silent) +static int remove_menu(vimmenu_T **menup, char *name, int modes, bool silent) { vimmenu_T *menu; vimmenu_T *child; - char_u *p; + char *p; if (*menup == NULL) { return OK; // Got to bottom of hierarchy @@ -696,7 +696,7 @@ static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes) } dict = tv_dict_alloc(); - tv_dict_add_str(dict, S_LEN("name"), (char *)menu->dname); + tv_dict_add_str(dict, S_LEN("name"), menu->dname); tv_dict_add_nr(dict, S_LEN("priority"), (int)menu->priority); tv_dict_add_nr(dict, S_LEN("hidden"), menu_is_hidden(menu->dname)); @@ -707,12 +707,12 @@ static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes) } if (menu->actext) { - tv_dict_add_str(dict, S_LEN("actext"), (char *)menu->actext); + tv_dict_add_str(dict, S_LEN("actext"), menu->actext); } if (menu->modes & MENU_TIP_MODE && menu->strings[MENU_INDEX_TIP]) { tv_dict_add_str(dict, S_LEN("tooltip"), - (char *)menu->strings[MENU_INDEX_TIP]); + menu->strings[MENU_INDEX_TIP]); } if (!menu->children) { @@ -724,7 +724,7 @@ static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes) if ((menu->modes & modes & (1 << bit)) != 0) { dict_T *impl = tv_dict_alloc(); tv_dict_add_allocated_str(impl, S_LEN("rhs"), - str2special_save((char *)menu->strings[bit], + str2special_save(menu->strings[bit], false, false)); tv_dict_add_nr(impl, S_LEN("silent"), menu->silent[bit]); tv_dict_add_nr(impl, S_LEN("enabled"), @@ -733,7 +733,7 @@ static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes) (menu->noremap[bit] & REMAP_NONE) ? 1 : 0); tv_dict_add_nr(impl, S_LEN("sid"), (menu->noremap[bit] & REMAP_SCRIPT) ? 1 : 0); - tv_dict_add_dict(commands, (char *)&menu_mode_chars[bit], 1, impl); + tv_dict_add_dict(commands, &menu_mode_chars[bit], 1, impl); } } } else { @@ -757,7 +757,7 @@ static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes) /// @param modes supported modes, see \ref MENU_MODES /// @param[in,out] list must be allocated /// @return false if could not find path_name -bool menu_get(char_u *const path_name, int modes, list_T *list) +bool menu_get(char *const path_name, int modes, list_T *list) { vimmenu_T *menu = find_menu(*get_root_menu(path_name), path_name, modes); if (!menu) { @@ -783,9 +783,9 @@ bool menu_get(char_u *const path_name, int modes, list_T *list) /// @param menu top menu to start looking from /// @param name path towards the menu /// @return menu if \p name is null, found menu or NULL -static vimmenu_T *find_menu(vimmenu_T *menu, char_u *name, int modes) +static vimmenu_T *find_menu(vimmenu_T *menu, char *name, int modes) { - char_u *p; + char *p; while (*name) { // find the end of one dot-separated name and put a NUL at the dot @@ -819,7 +819,7 @@ static vimmenu_T *find_menu(vimmenu_T *menu, char_u *name, int modes) } /// Show the mapping associated with a menu item or hierarchy in a sub-menu. -static int show_menus(char_u *const path_name, int modes) +static int show_menus(char *const path_name, int modes) { // First, find the (sub)menu with the given name vimmenu_T *menu = find_menu(*get_root_menu(path_name), path_name, modes); @@ -858,7 +858,7 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth) msg_puts(" "); } // Same highlighting as for directories!? - msg_outtrans_attr(menu->name, HL_ATTR(HLF_D)); + msg_outtrans_attr((char_u *)menu->name, HL_ATTR(HLF_D)); } if (menu != NULL && menu->children == NULL) { @@ -893,7 +893,7 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth) if (*menu->strings[bit] == NUL) { msg_puts_attr("<Nop>", HL_ATTR(HLF_8)); } else { - msg_outtrans_special(menu->strings[bit], false, 0); + msg_outtrans_special((char_u *)menu->strings[bit], false, 0); } } } @@ -925,13 +925,13 @@ static int expand_emenu; // TRUE for ":emenu" command /* * Work out what to complete when doing command line completion of menu names. */ -char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg, bool forceit) +char *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char *arg, bool forceit) FUNC_ATTR_NONNULL_ALL { - char_u *after_dot; - char_u *p; - char_u *path_name = NULL; - char_u *name; + char *after_dot; + char *p; + char *path_name = NULL; + char *name; int unmenu; vimmenu_T *menu; int expand_menus; @@ -1023,7 +1023,7 @@ char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg, bool xfree(path_name); xp->xp_context = expand_menus ? EXPAND_MENUNAMES : EXPAND_MENUS; - xp->xp_pattern = after_dot; + xp->xp_pattern = (char_u *)after_dot; expand_menu = menu; } else { // We're in the mapping part xp->xp_context = EXPAND_NOTHING; @@ -1038,8 +1038,8 @@ char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg, bool char_u *get_menu_name(expand_T *xp, int idx) { static vimmenu_T *menu = NULL; - char_u *str; - static int should_advance = FALSE; + char *str; + static int should_advance = false; if (idx == 0) { // first call: start at first item menu = expand_menu; @@ -1067,7 +1067,7 @@ char_u *get_menu_name(expand_T *xp, int idx) } } } else { - str = (char_u *)""; + str = ""; } if (should_advance) { @@ -1077,7 +1077,7 @@ char_u *get_menu_name(expand_T *xp, int idx) should_advance = !should_advance; - return str; + return (char_u *)str; } /* @@ -1088,8 +1088,8 @@ char_u *get_menu_names(expand_T *xp, int idx) { static vimmenu_T *menu = NULL; #define TBUFFER_LEN 256 - static char_u tbuffer[TBUFFER_LEN]; //hack - char_u *str; + static char tbuffer[TBUFFER_LEN]; // hack + char *str; static bool should_advance = false; if (idx == 0) { // first call: start at first item @@ -1134,7 +1134,7 @@ char_u *get_menu_names(expand_T *xp, int idx) } } } else { - str = (char_u *)""; + str = ""; } if (should_advance) { @@ -1144,7 +1144,7 @@ char_u *get_menu_names(expand_T *xp, int idx) should_advance = !should_advance; - return str; + return (char_u *)str; } @@ -1153,9 +1153,9 @@ char_u *get_menu_names(expand_T *xp, int idx) /// /// @param name may be modified. /// @return start of the next element -char_u *menu_name_skip(char_u *const name) +char *menu_name_skip(char *const name) { - char_u *p; + char *p; for (p = name; *p && *p != '.'; MB_PTR_ADV(p)) { if (*p == '\\' || *p == Ctrl_V) { @@ -1175,7 +1175,7 @@ char_u *menu_name_skip(char_u *const name) * 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_u *const name, vimmenu_T *const menu) +static bool menu_name_equal(const char *const name, vimmenu_T *const menu) { if (menu->en_name != NULL && (menu_namecmp(name, menu->en_name) @@ -1185,7 +1185,7 @@ static bool menu_name_equal(const char_u *const name, vimmenu_T *const menu) return menu_namecmp(name, menu->name) || menu_namecmp(name, menu->dname); } -static bool menu_namecmp(const char_u *const name, const char_u *const mname) +static bool menu_namecmp(const char *const name, const char *const mname) { int i; @@ -1270,12 +1270,12 @@ int get_menu_cmd_modes(const char *cmd, bool forceit, int *noremap, int *unmenu) * Modify a menu name starting with "PopUp" to include the mode character. * Returns the name in allocated memory. */ -static char_u *popup_mode_name(char *name, int idx) +static char *popup_mode_name(char *name, int idx) { size_t len = STRLEN(name); assert(len >= 4); - char_u *p = vim_strnsave((char_u *)name, len + 1); + char *p = xstrnsave(name, len + 1); memmove(p + 6, p + 5, len - 4); p[5] = menu_mode_chars[idx]; @@ -1294,34 +1294,34 @@ static char_u *popup_mode_name(char *name, int idx) /// allocated. /// /// @return a pointer to allocated memory. -static char_u *menu_text(const char_u *str, int *mnemonic, char_u **actext) +static char *menu_text(const char *str, int *mnemonic, char **actext) FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1) { - char_u *p; - char_u *text; + char *p; + char *text; // Locate accelerator text, after the first TAB - p = vim_strchr(str, TAB); + p = (char *)vim_strchr((char_u *)str, TAB); if (p != NULL) { if (actext != NULL) { - *actext = vim_strsave(p + 1); + *actext = xstrdup(p + 1); } assert(p >= str); - text = vim_strnsave(str, (size_t)(p - str)); + text = xstrnsave(str, (size_t)(p - str)); } else { - text = vim_strsave(str); + text = xstrdup(str); } // Find mnemonic characters "&a" and reduce "&&" to "&". for (p = text; p != NULL;) { - p = vim_strchr(p, '&'); + p = (char *)vim_strchr((char_u *)p, '&'); if (p != NULL) { if (p[1] == NUL) { // trailing "&" break; } if (mnemonic != NULL && p[1] != '&') { - *mnemonic = p[1]; + *mnemonic = (char_u)p[1]; } STRMOVE(p, p + 1); p = p + 1; @@ -1331,7 +1331,7 @@ static char_u *menu_text(const char_u *str, int *mnemonic, char_u **actext) } // Return true if "name" can be a menu in the MenuBar. -bool menu_is_menubar(const char_u *const name) +bool menu_is_menubar(const char *const name) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { return !menu_is_popup((char *)name) @@ -1349,7 +1349,7 @@ bool menu_is_popup(const char *const name) // Return true if "name" is a toolbar menu name. -bool menu_is_toolbar(const char_u *const name) +bool menu_is_toolbar(const char *const name) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { return STRNCMP(name, "ToolBar", 7) == 0; @@ -1359,7 +1359,7 @@ bool menu_is_toolbar(const char_u *const name) * Return TRUE if the name is a menu separator identifier: Starts and ends * with '-' */ -int menu_is_separator(char_u *name) +int menu_is_separator(char *name) { return name[0] == '-' && name[STRLEN(name) - 1] == '-'; } @@ -1368,10 +1368,10 @@ int menu_is_separator(char_u *name) /// True if a popup menu or starts with \ref MNU_HIDDEN_CHAR /// /// @return true if the menu is hidden -static int menu_is_hidden(char_u *name) +static int menu_is_hidden(char *name) { return (name[0] == MNU_HIDDEN_CHAR) - || (menu_is_popup((char *)name) && name[5] != NUL); + || (menu_is_popup(name) && name[5] != NUL); } // Execute "menu". Use by ":emenu" and the window toolbar. @@ -1453,13 +1453,13 @@ static void execute_menu(const exarg_T *eap, vimmenu_T *menu) ex_normal_busy++; if (save_current_state(&save_state)) { - exec_normal_cmd(menu->strings[idx], menu->noremap[idx], + exec_normal_cmd((char_u *)menu->strings[idx], menu->noremap[idx], menu->silent[idx]); } restore_current_state(&save_state); ex_normal_busy--; } else { - ins_typebuf(menu->strings[idx], menu->noremap[idx], 0, true, + ins_typebuf((char_u *)menu->strings[idx], menu->noremap[idx], 0, true, menu->silent[idx]); } } else if (eap != NULL) { @@ -1471,12 +1471,12 @@ static void execute_menu(const exarg_T *eap, vimmenu_T *menu) // execute it. void ex_emenu(exarg_T *eap) { - char_u *saved_name = vim_strsave(eap->arg); + char *saved_name = xstrdup((char *)eap->arg); vimmenu_T *menu = *get_root_menu(saved_name); - char_u *name = saved_name; + char *name = saved_name; while (*name) { // Find in the menu hierarchy - char_u *p = menu_name_skip(name); + char *p = menu_name_skip(name); while (menu != NULL) { if (menu_name_equal(name, menu)) { @@ -1512,9 +1512,9 @@ void ex_emenu(exarg_T *eap) */ typedef struct { - char_u *from; // English name - char_u *from_noamp; // same, without '&' - char_u *to; // translated name + char *from; // English name + char *from_noamp; // same, without '&' + char *to; // translated name } menutrans_T; static garray_T menutrans_ga = GA_EMPTY_INIT_VALUE; @@ -1532,8 +1532,8 @@ static garray_T menutrans_ga = GA_EMPTY_INIT_VALUE; */ void ex_menutranslate(exarg_T *eap) { - char_u *arg = eap->arg; - char_u *from, *from_noamp, *to; + char *arg = (char *)eap->arg; + char *from, *from_noamp, *to; if (menutrans_ga.ga_itemsize == 0) { ga_init(&menutrans_ga, (int)sizeof(menutrans_T), 5); @@ -1542,7 +1542,7 @@ void ex_menutranslate(exarg_T *eap) /* * ":menutrans clear": clear all translations. */ - if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd(*skipwhite(arg + 5))) { + if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd(*skipwhite((char_u *)arg + 5))) { GA_DEEP_CLEAR(&menutrans_ga, menutrans_T, FREE_MENUTRANS); // Delete all "menutrans_" global variables. @@ -1551,16 +1551,16 @@ void ex_menutranslate(exarg_T *eap) // ":menutrans from to": add translation from = arg; arg = menu_skip_part(arg); - to = skipwhite(arg); + to = (char *)skipwhite((char_u *)arg); *arg = NUL; arg = menu_skip_part(to); if (arg == to) { emsg(_(e_invarg)); } else { - from = vim_strsave(from); + from = xstrdup(from); from_noamp = menu_text(from, NULL, NULL); assert(arg >= to); - to = vim_strnsave(to, (size_t)(arg - to)); + to = xstrnsave(to, (size_t)(arg - to)); menu_translate_tab_and_shift(from); menu_translate_tab_and_shift(to); menu_unescape_name(from); @@ -1576,7 +1576,7 @@ void ex_menutranslate(exarg_T *eap) /* * Find the character just after one part of a menu name. */ -static char_u *menu_skip_part(char_u *p) +static char *menu_skip_part(char *p) { while (*p != NUL && *p != '.' && !ascii_iswhite(*p)) { if ((*p == '\\' || *p == Ctrl_V) && p[1] != NUL) { @@ -1591,10 +1591,10 @@ static char_u *menu_skip_part(char_u *p) * Lookup part of a menu name in the translations. * Return a pointer to the translation or NULL if not found. */ -static char_u *menutrans_lookup(char_u *name, int len) +static char *menutrans_lookup(char *name, int len) { menutrans_T *tp = (menutrans_T *)menutrans_ga.ga_data; - char_u *dname; + char *dname; for (int i = 0; i < menutrans_ga.ga_len; i++) { if (STRNICMP(name, tp[i].from, len) == 0 && tp[i].from[len] == NUL) { @@ -1603,7 +1603,7 @@ static char_u *menutrans_lookup(char_u *name, int len) } // Now try again while ignoring '&' characters. - char_u c = name[len]; + char c = name[len]; name[len] = NUL; dname = menu_text(name, NULL, NULL); name[len] = c; @@ -1621,9 +1621,9 @@ static char_u *menutrans_lookup(char_u *name, int len) /* * Unescape the name in the translate dictionary table. */ -static void menu_unescape_name(char_u *name) +static void menu_unescape_name(char *name) { - char_u *p; + char *p; for (p = name; *p && *p != '.'; MB_PTR_ADV(p)) { if (*p == '\\') { @@ -1636,9 +1636,9 @@ static void menu_unescape_name(char_u *name) * Isolate the menu name. * Skip the menu name, and translate <Tab> into a real TAB. */ -static char_u *menu_translate_tab_and_shift(char_u *arg_start) +static char *menu_translate_tab_and_shift(char *arg_start) { - char_u *arg = arg_start; + char *arg = arg_start; while (*arg && !ascii_iswhite(*arg)) { if ((*arg == '\\' || *arg == Ctrl_V) && arg[1] != NUL) { @@ -1652,7 +1652,7 @@ static char_u *menu_translate_tab_and_shift(char_u *arg_start) if (*arg != NUL) { *arg++ = NUL; } - arg = skipwhite(arg); + arg = (char *)skipwhite((char_u *)arg); return arg; } diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 36c2513810..d6550f38fa 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5146,7 +5146,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) if (do_alpha && ASCII_ISALPHA(firstdigit)) { // decrement or increment alphabetic character if (op_type == OP_NR_SUB) { - if (CharOrd(firstdigit) < Prenum1) { + if (CHAR_ORD(firstdigit) < Prenum1) { if (isupper(firstdigit)) { firstdigit = 'A'; } else { @@ -5156,7 +5156,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) firstdigit -= (int)Prenum1; } } else { - if (26 - CharOrd(firstdigit) - 1 < Prenum1) { + if (26 - CHAR_ORD(firstdigit) - 1 < Prenum1) { if (isupper(firstdigit)) { firstdigit = 'Z'; } else { diff --git a/src/nvim/ops.h b/src/nvim/ops.h index efde7290cf..8133dc0b1f 100644 --- a/src/nvim/ops.h +++ b/src/nvim/ops.h @@ -108,9 +108,9 @@ static inline int op_reg_index(const int regname) if (ascii_isdigit(regname)) { return regname - '0'; } else if (ASCII_ISLOWER(regname)) { - return CharOrdLow(regname) + 10; + return CHAR_ORD_LOW(regname) + 10; } else if (ASCII_ISUPPER(regname)) { - return CharOrdUp(regname) + 10; + return CHAR_ORD_UP(regname) + 10; } else if (regname == '-') { return DELETION_REGISTER; } else if (regname == '*') { diff --git a/src/nvim/option.c b/src/nvim/option.c index 37594340de..49c76d2452 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -832,8 +832,8 @@ void set_init_3(void) // Default for p_sp is "| tee", for p_srr is ">". // For known shells it is changed here to include stderr. // - if (fnamecmp(p, "csh") == 0 - || fnamecmp(p, "tcsh") == 0) { + if (FNAMECMP(p, "csh") == 0 + || FNAMECMP(p, "tcsh") == 0) { if (do_sp) { p_sp = (char_u *)"|& tee"; options[idx_sp].def_val = p_sp; @@ -842,16 +842,16 @@ void set_init_3(void) p_srr = (char_u *)">&"; options[idx_srr].def_val = p_srr; } - } else if (fnamecmp(p, "sh") == 0 - || fnamecmp(p, "ksh") == 0 - || fnamecmp(p, "mksh") == 0 - || fnamecmp(p, "pdksh") == 0 - || fnamecmp(p, "zsh") == 0 - || fnamecmp(p, "zsh-beta") == 0 - || fnamecmp(p, "bash") == 0 - || fnamecmp(p, "fish") == 0 - || fnamecmp(p, "ash") == 0 - || fnamecmp(p, "dash") == 0) { + } else if (FNAMECMP(p, "sh") == 0 + || FNAMECMP(p, "ksh") == 0 + || FNAMECMP(p, "mksh") == 0 + || FNAMECMP(p, "pdksh") == 0 + || FNAMECMP(p, "zsh") == 0 + || FNAMECMP(p, "zsh-beta") == 0 + || FNAMECMP(p, "bash") == 0 + || FNAMECMP(p, "fish") == 0 + || FNAMECMP(p, "ash") == 0 + || FNAMECMP(p, "dash") == 0) { // Always use POSIX shell style redirection if we reach this if (do_sp) { p_sp = (char_u *)"2>&1| tee"; @@ -1799,7 +1799,7 @@ static int string_to_key(char_u *arg) return find_key_option(arg + 1, true); } if (*arg == '^') { - return Ctrl_chr(arg[1]); + return CTRL_CHR(arg[1]); } return *arg; } @@ -2392,10 +2392,10 @@ static char *did_set_string_option(int opt_idx, char_u **varp, bool new_value_al && (options[opt_idx].flags & P_SECURE)) { errmsg = e_secure; } else if (((options[opt_idx].flags & P_NFNAME) - && vim_strpbrk(*varp, (char_u *)(secure ? "/\\*?[|;&<>\r\n" - : "/\\*?[<>\r\n")) != NULL) + && strpbrk((char *)(*varp), + (secure ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL) || ((options[opt_idx].flags & P_NDNAME) - && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL)) { + && strpbrk((char *)(*varp), "*?[|;&<>\r\n") != NULL)) { // Check for a "normal" directory or file name in some options. Disallow a // path separator (slash and/or backslash), wildcards and characters that // are often illegal in a file name. Be more permissive if "secure" is off. @@ -4799,7 +4799,7 @@ int findoption_len(const char *const arg, const size_t len) if (s[0] == 't' && s[1] == '_') { quick_tab[26] = i; } else { - quick_tab[CharOrdLow(s[0])] = i; + quick_tab[CHAR_ORD_LOW(s[0])] = i; } } p = s; @@ -4816,7 +4816,7 @@ int findoption_len(const char *const arg, const size_t len) if (is_term_opt) { opt_idx = quick_tab[26]; } else { - opt_idx = quick_tab[CharOrdLow(arg[0])]; + opt_idx = quick_tab[CHAR_ORD_LOW(arg[0])]; } // Match full name for (; (s = options[opt_idx].fullname) != NULL; opt_idx++) { @@ -4825,7 +4825,7 @@ int findoption_len(const char *const arg, const size_t len) } } if (s == NULL && !is_term_opt) { - opt_idx = quick_tab[CharOrdLow(arg[0])]; + opt_idx = quick_tab[CHAR_ORD_LOW(arg[0])]; // Match short name for (; options[opt_idx].fullname != NULL; opt_idx++) { s = options[opt_idx].shortname; diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index e958a39ad2..bf9e455c38 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -698,7 +698,7 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo // If "var" contains white space, escape it with a backslash. // Required for ":e ~/tt" when $HOME includes a space. - if (esc && var != NULL && vim_strpbrk(var, (char_u *)" \t") != NULL) { + if (esc && var != NULL && strpbrk((char *)var, " \t") != NULL) { char_u *p = vim_strsave_escaped(var, (char_u *)" \t"); if (mustfree) { @@ -805,7 +805,7 @@ static char *remove_tail(char *path, char *pend, char *dirname) char *new_tail = pend - len - 1; if (new_tail >= path - && fnamencmp((char_u *)new_tail, (char_u *)dirname, len) == 0 + && FNAMENCMP((char_u *)new_tail, (char_u *)dirname, len) == 0 && (new_tail == path || after_pathsep(path, new_tail))) { return new_tail; } @@ -1102,7 +1102,7 @@ size_t home_replace(const buf_T *const buf, const char_u *src, char_u *const dst size_t len = dirlen; for (;;) { if (len - && fnamencmp(src, (char_u *)p, len) == 0 + && FNAMENCMP(src, (char_u *)p, len) == 0 && (vim_ispathsep(src[len]) || (!one && (src[len] == ',' || src[len] == ' ')) || src[len] == NUL)) { diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index daf974ee74..5fcae79a67 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -1293,7 +1293,7 @@ shortcut_end: return rfname; } -# define is_path_sep(c) ((c) == L'\\' || (c) == L'/') +# define IS_PATH_SEP(c) ((c) == L'\\' || (c) == L'/') /// Returns true if the path contains a reparse point (junction or symbolic /// link). Otherwise false in returned. bool os_is_reparse_point_include(const char *path) @@ -1310,9 +1310,9 @@ bool os_is_reparse_point_include(const char *path) } p = utf16_path; - if (isalpha(p[0]) && p[1] == L':' && is_path_sep(p[2])) { + if (isalpha(p[0]) && p[1] == L':' && IS_PATH_SEP(p[2])) { p += 3; - } else if (is_path_sep(p[0]) && is_path_sep(p[1])) { + } else if (IS_PATH_SEP(p[0]) && IS_PATH_SEP(p[1])) { p += 2; } diff --git a/src/nvim/path.c b/src/nvim/path.c index 75624778e3..66cfb3b31a 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -71,9 +71,9 @@ FileComparison path_full_compare(char_u *const s1, char_u *const s2, const bool if (!id_ok_1 && !id_ok_2) { // If os_fileid() doesn't work, may compare the names. if (checkname) { - vim_FullName((char *)exp1, (char *)full1, MAXPATHL, FALSE); - vim_FullName((char *)s2, (char *)full2, MAXPATHL, FALSE); - if (fnamecmp(full1, full2) == 0) { + vim_FullName((char *)exp1, (char *)full1, MAXPATHL, false); + vim_FullName((char *)s2, (char *)full2, MAXPATHL, false); + if (FNAMECMP(full1, full2) == 0) { return kEqualFileNames; } } @@ -728,7 +728,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, && (name[1] != '.' || name[2] != NUL))) // -V557 && ((regmatch.regprog != NULL && vim_regexec(®match, name, 0)) || ((flags & EW_NOTWILD) - && fnamencmp(path + (s - buf), name, e - s) == 0))) { + && FNAMENCMP(path + (s - buf), name, e - s) == 0))) { STRCPY(s, name); len = STRLEN(buf); @@ -817,7 +817,7 @@ static bool is_unique(char_u *maybe_unique, garray_T *gap, int i) continue; // it's different when it's shorter } char_u *rival = other_paths[j] + other_path_len - candidate_len; - if (fnamecmp(maybe_unique, rival) == 0 + if (FNAMECMP(maybe_unique, rival) == 0 && (rival == other_paths[j] || vim_ispathsep(*(rival - 1)))) { return false; // match } @@ -976,7 +976,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) char_u *path_cutoff; len = STRLEN(path); - is_in_curdir = fnamencmp(curdir, path, dir_end - path) == 0 + is_in_curdir = FNAMENCMP(curdir, path, dir_end - path) == 0 && curdir[dir_end - path] == NUL; if (is_in_curdir) { in_curdir[i] = vim_strsave(path); @@ -1473,7 +1473,7 @@ void addfile(garray_T *gap, char_u *f, int flags) #ifdef FNAME_ILLEGAL // if the file/dir contains illegal characters, don't add it - if (vim_strpbrk(f, (char_u *)FNAME_ILLEGAL) != NULL) { + if (strpbrk((char *)f, FNAME_ILLEGAL) != NULL) { return; } #endif @@ -2090,7 +2090,7 @@ char_u *path_shorten_fname(char_u *full_path, char_u *dir_name) // If full_path and dir_name do not match, it's impossible to make one // relative to the other. - if (fnamencmp(dir_name, full_path, len) != 0) { + if (FNAMENCMP(dir_name, full_path, len) != 0) { return NULL; } @@ -2254,7 +2254,7 @@ int match_suffix(char_u *fname) } } else { if (fnamelen >= setsuflen - && fnamencmp(suf_buf, fname + fnamelen - setsuflen, setsuflen) == 0) { + && FNAMENCMP(suf_buf, fname + fnamelen - setsuflen, setsuflen) == 0) { break; } setsuflen = 0; diff --git a/src/nvim/screen.c b/src/nvim/screen.c index c6fd9e5dff..807503fd00 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -4900,7 +4900,7 @@ static int status_match_len(expand_T *xp, char_u *s) || xp->xp_context == EXPAND_MENUNAMES); // Check for menu separators - replace with '|'. - if (emenu && menu_is_separator(s)) { + if (emenu && menu_is_separator((char *)s)) { return 1; } @@ -5036,7 +5036,7 @@ void win_redr_status_matches(expand_T *xp, int num_matches, char_u **matches, in // Check for menu separators - replace with '|' emenu = (xp->xp_context == EXPAND_MENUS || xp->xp_context == EXPAND_MENUNAMES); - if (emenu && menu_is_separator(s)) { + if (emenu && menu_is_separator((char *)s)) { STRCPY(buf + len, transchar('|')); l = (int)STRLEN(buf + len); len += l; diff --git a/src/nvim/search.c b/src/nvim/search.c index d3c11573ee..4fc5ac93aa 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -2324,7 +2324,7 @@ int check_linecomment(const char_u *line) if (vim_strchr(p, ';') != NULL) { // there may be comments bool in_str = false; // inside of string - while ((p = vim_strpbrk(p, (char_u *)"\";")) != NULL) { + while ((p = (char_u *)strpbrk((char *)p, "\";")) != NULL) { if (*p == '"') { if (in_str) { if (*(p - 1) != '\\') { // skip escaped quote diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 6c0add87d3..76bf81ffbf 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1053,7 +1053,7 @@ static buf_T *find_buffer(khash_t(fnamebufs) *const fname_bufs, const char *cons kh_key(fname_bufs, k) = xstrdup(fname); FOR_ALL_BUFFERS(buf) { if (buf->b_ffname != NULL) { - if (fnamecmp(fname, buf->b_ffname) == 0) { + if (FNAMECMP(fname, buf->b_ffname) == 0) { kh_val(fname_bufs, k) = buf; return buf; } diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 9fa594bc96..20e1fefbb4 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2101,7 +2101,7 @@ char *did_set_spelllang(win_T *wp) // If the name ends in ".spl" use it as the name of the spell file. // If there is a region name let "region" point to it and remove it // from the name. - if (len > 4 && fnamecmp(lang + len - 4, ".spl") == 0) { + if (len > 4 && FNAMECMP(lang + len - 4, ".spl") == 0) { filename = true; // Locate a region and remove it from the file name. diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 3d3e6e728c..0933e6d467 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -893,7 +893,7 @@ void suggest_load_files(void) slang->sl_sugloaded = true; dotp = STRRCHR(slang->sl_fname, '.'); - if (dotp == NULL || fnamecmp(dotp, ".spl") != 0) { + if (dotp == NULL || FNAMECMP(dotp, ".spl") != 0) { continue; } STRCPY(dotp, ".sug"); diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 9d4c64e4b1..848044ee7c 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -67,6 +67,13 @@ char_u *vim_strnsave(const char_u *string, size_t len) return (char_u *)strncpy(xmallocz(len), (char *)string, len); } +/// A clone of vim_strnsave() that uses char* instead of char_u* +char *xstrnsave(const char *string, size_t len) + FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL +{ + return strncpy(xmallocz(len), string, len); // NOLINT(runtime/printf) +} + /* * Same as vim_strsave(), but any characters found in esc_chars are preceded * by a backslash. diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 0ceb66f438..76bb5a0186 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -5376,7 +5376,7 @@ static int get_id_list(char_u **const arg, const int keylen, int16_t **const lis /* * Handle full group name. */ - if (vim_strpbrk(name + 1, (char_u *)"\\.*^$~[") == NULL) { + if (strpbrk((char *)name + 1, "\\.*^$~[") == NULL) { id = syn_check_group((char *)(name + 1), (int)(end - p)); } else { // Handle match of regexp with group names. diff --git a/src/nvim/vim.h b/src/nvim/vim.h index 64333e9c3d..3c8a865fb1 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -253,8 +253,6 @@ enum { FOLD_TEXT_LEN = 51, }; //!< buffer size for get_foldtext() #define STRNCAT(d, s, n) strncat((char *)(d), (char *)(s), (size_t)(n)) #define STRLCAT(d, s, n) xstrlcat((char *)(d), (char *)(s), (size_t)(n)) -#define vim_strpbrk(s, cs) (char_u *)strpbrk((char *)(s), (char *)(cs)) - // Character used as separated in autoload function/variable names. #define AUTOLOAD_CHAR '#' @@ -280,8 +278,8 @@ enum { FOLD_TEXT_LEN = 51, }; //!< buffer size for get_foldtext() /// @param[in] y Second file name to compare. /// /// @return 0 for equal file names, non-zero otherwise. -#define fnamecmp(x, y) path_fnamecmp((const char *)(x), (const char *)(y)) -#define fnamencmp(x, y, n) path_fnamencmp((const char *)(x), \ +#define FNAMECMP(x, y) path_fnamecmp((const char *)(x), (const char *)(y)) +#define FNAMENCMP(x, y, n) path_fnamencmp((const char *)(x), \ (const char *)(y), \ (size_t)(n)) diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 9d1318724e..b8b0a38f44 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -66,7 +66,7 @@ #include "nvim/viml/parser/expressions.h" #include "nvim/viml/parser/parser.h" -#define vim_str2nr(s, ...) vim_str2nr((const char_u *)(s), __VA_ARGS__) +#define VIM_STR2NR(s, ...) vim_str2nr((const char_u *)(s), __VA_ARGS__) typedef kvec_withinit_t(ExprASTNode **, 16) ExprASTStack; @@ -371,7 +371,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags) significand_part = significand_part * 10 + (pline.data[i] - '0'); } if (exp_start) { - vim_str2nr(pline.data + exp_start, NULL, NULL, 0, NULL, &exp_part, + VIM_STR2NR(pline.data + exp_start, NULL, NULL, 0, NULL, &exp_part, (int)(ret.len - exp_start), false); } if (exp_negative) { @@ -389,7 +389,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags) } else { int len; int prep; - vim_str2nr(pline.data, &prep, &len, STR2NR_ALL, NULL, + VIM_STR2NR(pline.data, &prep, &len, STR2NR_ALL, NULL, &ret.data.num.val.integer, (int)pline.size, false); ret.len = (size_t)len; const uint8_t bases[] = { |