diff options
81 files changed, 1122 insertions, 1085 deletions
diff --git a/cmake/GenerateVersion.cmake b/cmake/GenerateVersion.cmake index 8cea39e4de..34993d9552 100644 --- a/cmake/GenerateVersion.cmake +++ b/cmake/GenerateVersion.cmake @@ -33,4 +33,7 @@ endif() if(NOT "${NVIM_VERSION_HASH}" STREQUAL "${CURRENT_VERSION_HASH}") message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}") file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}") + if(WIN32) + configure_file("${OUTPUT}" "${OUTPUT}" NEWLINE_STYLE UNIX) + endif() endif() diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index ca4518d1cc..dbaf706b19 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -173,6 +173,7 @@ getbufline({buf}, {lnum} [, {end}]) getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf} getbufvar({buf}, {varname} [, {def}]) any variable {varname} in buffer {buf} +getcellwidths() List get character cell width overrides getchangelist([{buf}]) List list of change list items getchar([expr]) Number or String get one character from the user @@ -2745,6 +2746,13 @@ getbufvar({buf}, {varname} [, {def}]) *getbufvar()* < Can also be used as a |method|: > GetBufnr()->getbufvar(varname) < +getcellwidths() *getcellwidths()* + Returns a |List| of cell widths of character ranges overridden + by |setcellwidths()|. The format is equal to the argument of + |setcellwidths()|. If no character ranges have their cell + widths overridden, an empty List is returned. + + getchangelist([{buf}]) *getchangelist()* Returns the |changelist| for the buffer {buf}. For the use of {buf}, see |bufname()| above. If buffer {buf} doesn't diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt index 226bd029a3..910aebae70 100644 --- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -624,6 +624,7 @@ String manipulation: *string-functions* strwidth() size of string when displayed strdisplaywidth() size of string when displayed, deals with tabs setcellwidths() set character cell width overrides + getcellwidths() get character cell width overrides substitute() substitute a pattern match with a string submatch() get a specific match in ":s" and substitute() strpart() get part of a string using byte index diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index 44e7ed3986..ab3b3485e4 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -698,7 +698,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer } if (opts->sign_text.type == kObjectTypeString) { - if (!init_sign_text((char **)&decor.sign_text, + if (!init_sign_text(&decor.sign_text, opts->sign_text.data.string.data)) { api_set_error(err, kErrorTypeValidation, "sign_text is not a valid value"); goto error; diff --git a/src/nvim/api/private/converter.c b/src/nvim/api/private/converter.c index 7770ba39d8..58ff552ab7 100644 --- a/src/nvim/api/private/converter.c +++ b/src/nvim/api/private/converter.c @@ -358,7 +358,7 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err) } case kObjectTypeLuaRef: { - char *name = (char *)register_luafunc(api_new_luaref(obj.data.luaref)); + char *name = register_luafunc(api_new_luaref(obj.data.luaref)); tv->v_type = VAR_FUNC; tv->vval.v_string = xstrdup(name); break; diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 13c8e162b6..a53b30dd8a 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2271,7 +2271,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * if (sp->userhl == 0) { grpname = get_default_stl_hl(wp, use_winbar); } else if (sp->userhl < 0) { - grpname = (char *)syn_id2name(-sp->userhl); + grpname = syn_id2name(-sp->userhl); } else { snprintf(user_group, sizeof(user_group), "User%d", sp->userhl); grpname = user_group; diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index f81d26b486..0ffeac1bff 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -278,7 +278,7 @@ Dictionary nvim_win_get_config(Window window, Error *err) String s = cstrn_to_string((const char *)config->border_chars[i], sizeof(schar_T)); int hi_id = config->border_hl_ids[i]; - char *hi_name = (char *)syn_id2name(hi_id); + char *hi_name = syn_id2name(hi_id); if (hi_name[0]) { ADD(tuple, STRING_OBJ(s)); ADD(tuple, STRING_OBJ(cstr_to_string((const char *)hi_name))); diff --git a/src/nvim/change.c b/src/nvim/change.c index e8c4af9879..06696610b0 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -418,14 +418,7 @@ void appended_lines(linenr_T lnum, linenr_T count) /// Like appended_lines(), but adjust marks first. void appended_lines_mark(linenr_T lnum, long count) { - // Skip mark_adjust when adding a line after the last one, there can't - // be marks there. But it's still needed in diff mode. - if (lnum + count < curbuf->b_ml.ml_line_count || curwin->w_p_diff) { - mark_adjust(lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0L, kExtmarkUndo); - } else { - extmark_adjust(curbuf, lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0L, - kExtmarkUndo); - } + mark_adjust(lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0L, kExtmarkUndo); changed_lines(lnum + 1, 0, lnum + 1, (linenr_T)count, true); } @@ -1694,13 +1687,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } // Postpone calling changed_lines(), because it would mess up folding // with markers. - // Skip mark_adjust when adding a line after the last one, there can't - // be marks there. But still needed in diff mode. - if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count - || curwin->w_p_diff) { - mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L, - kExtmarkNOOP); - } + mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L, kExtmarkNOOP); did_append = true; } else { // In MODE_VREPLACE state we are starting to replace the next line. diff --git a/src/nvim/charset.c b/src/nvim/charset.c index fa9aa27774..5aec9ccf9d 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -540,9 +540,9 @@ static char_u transchar_charbuf[11]; /// @param[in] c Character to translate. /// /// @return translated character into a static buffer. -char_u *transchar(int c) +char *transchar(int c) { - return transchar_buf(curbuf, c); + return (char *)transchar_buf(curbuf, c); } char_u *transchar_buf(const buf_T *buf, int c) @@ -584,7 +584,7 @@ char_u *transchar_byte(const int c) transchar_nonprint(curbuf, transchar_charbuf, c); return transchar_charbuf; } - return transchar(c); + return (char_u *)transchar(c); } /// Convert non-printable characters to 2..4 printable ones diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 59891e9899..c1059c40f0 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -979,7 +979,7 @@ static void showmatches_oneline(expand_T *xp, char **matches, int numMatches, in // Expansion was done before and special characters // were escaped, need to halve backslashes. Also // $HOME has been replaced with ~/. - char *exp_path = (char *)expand_env_save_opt(matches[j], true); + char *exp_path = expand_env_save_opt(matches[j], true); char *path = exp_path != NULL ? exp_path : matches[j]; char *halved_slash = backslash_halve_save(path); isdir = os_isdir(halved_slash); @@ -2349,7 +2349,7 @@ void set_cmd_context(expand_T *xp, char *str, int len, int col, int use_ccline) } else if (use_ccline && ccline->input_fn) { xp->xp_context = ccline->xp_context; xp->xp_pattern = ccline->cmdbuff; - xp->xp_arg = (char *)ccline->xp_arg; + xp->xp_arg = ccline->xp_arg; } else { while (nextcomm != NULL) { nextcomm = set_one_cmd_context(xp, nextcomm); @@ -2914,14 +2914,14 @@ static void expand_shellcmd_onedir(char *buf, char *s, size_t l, char *pat, char if (strlen(name) > l) { // Check if this name was already found. - hash_T hash = hash_hash((char_u *)name + l); + hash_T hash = hash_hash(name + l); hashitem_T *hi = hash_lookup(ht, (const char *)(name + l), strlen(name + l), hash); if (HASHITEM_EMPTY(hi)) { // Remove the path that was prepended. STRMOVE(name, name + l); ((char **)gap->ga_data)[gap->ga_len++] = name; - hash_add_item(ht, hi, (char_u *)name, hash); + hash_add_item(ht, hi, name, hash); name = NULL; } } diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c index 3dfbcd1f81..ad615969ba 100644 --- a/src/nvim/debugger.c +++ b/src/nvim/debugger.c @@ -802,7 +802,7 @@ static linenr_T debuggy_find(bool file, char *fname, linenr_T after, garray_T *g // while matching should abort it. prev_got_int = got_int; got_int = false; - if (vim_regexec_prog(&bp->dbg_prog, false, (char_u *)name, (colnr_T)0)) { + if (vim_regexec_prog(&bp->dbg_prog, false, name, (colnr_T)0)) { lnum = bp->dbg_lnum; if (fp != NULL) { *fp = bp->dbg_forceit; diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c index 037eb9f0d9..9274138cb6 100644 --- a/src/nvim/decoration.c +++ b/src/nvim/decoration.c @@ -407,7 +407,7 @@ void decor_redraw_signs(buf_T *buf, int row, int *num_signs, SignTextAttrs sattr } if (j < SIGN_SHOW_MAX) { sattrs[j] = (SignTextAttrs) { - .text = (char *)decor->sign_text, + .text = decor->sign_text, .hl_attr_id = decor->sign_hl_id == 0 ? 0 : syn_id2attr(decor->sign_hl_id), .priority = decor->priority }; diff --git a/src/nvim/decoration.h b/src/nvim/decoration.h index cee1eb2f94..c9ec8ede7f 100644 --- a/src/nvim/decoration.h +++ b/src/nvim/decoration.h @@ -58,7 +58,7 @@ struct Decoration { DecorPriority priority; int col; // fixed col value, like win_col int virt_text_width; // width of virt_text - char_u *sign_text; + char *sign_text; int sign_hl_id; int number_hl_id; int line_hl_id; diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 40be6b1abc..7fbde4f45b 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -2293,7 +2293,7 @@ static bool diff_equal_char(const char *const p1, const char *const p2, int *con static int diff_cmp(char *s1, char *s2) { if ((diff_flags & DIFF_IBLANK) - && (*(char_u *)skipwhite(s1) == NUL || *skipwhite(s2) == NUL)) { + && (*skipwhite(s1) == NUL || *skipwhite(s2) == NUL)) { return 0; } diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 144817fe2b..a057978a5e 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1489,7 +1489,7 @@ int do_digraph(int c) /// Find a digraph for "val". If found return the string to display it. /// If not found return NULL. -char_u *get_digraph_for_char(int val_arg) +char *get_digraph_for_char(int val_arg) { const int val = val_arg; const digr_T *dp; @@ -1506,7 +1506,7 @@ char_u *get_digraph_for_char(int val_arg) r[0] = dp->char1; r[1] = dp->char2; r[2] = NUL; - return r; + return (char *)r; } dp++; } @@ -1749,16 +1749,16 @@ static void digraph_getlist_appendpair(const digr_T *dp, list_T *l) list_T *l2 = tv_list_alloc(2); tv_list_append_list(l, l2); - char_u buf[30]; - buf[0] = dp->char1; - buf[1] = dp->char2; + char buf[30]; + buf[0] = (char)dp->char1; + buf[1] = (char)dp->char2; buf[2] = NUL; - tv_list_append_string(l2, (char *)buf, -1); + tv_list_append_string(l2, buf, -1); - char_u *p = buf; - p += utf_char2bytes(dp->result, (char *)p); + char *p = buf; + p += utf_char2bytes(dp->result, p); *p = NUL; - tv_list_append_string(l2, (char *)buf, -1); + tv_list_append_string(l2, buf, -1); } void digraph_getlist_common(bool list_all, typval_T *rettv) @@ -1824,7 +1824,7 @@ struct dg_header_entry { static void printdigraph(const digr_T *dp, result_T *previous) FUNC_ATTR_NONNULL_ARG(1) { - char_u buf[30]; + char buf[30]; int list_width = 13; if (dp->result == 0) { @@ -1854,29 +1854,29 @@ static void printdigraph(const digr_T *dp, result_T *previous) } } - char_u *p = &buf[0]; - *p++ = dp->char1; - *p++ = dp->char2; + char *p = &buf[0]; + *p++ = (char)dp->char1; + *p++ = (char)dp->char2; *p++ = ' '; *p = NUL; - msg_outtrans((char *)buf); + msg_outtrans(buf); p = buf; // add a space to draw a composing char on if (utf_iscomposing(dp->result)) { *p++ = ' '; } - p += utf_char2bytes(dp->result, (char *)p); + p += utf_char2bytes(dp->result, p); *p = NUL; - msg_outtrans_attr((char *)buf, HL_ATTR(HLF_8)); + msg_outtrans_attr(buf, HL_ATTR(HLF_8)); p = buf; if (char2cells(dp->result) == 1) { *p++ = ' '; } assert(p >= buf); - vim_snprintf((char *)p, sizeof(buf) - (size_t)(p - buf), " %3d", dp->result); - msg_outtrans((char *)buf); + vim_snprintf(p, sizeof(buf) - (size_t)(p - buf), " %3d", dp->result); + msg_outtrans(buf); } /// Get the two digraph characters from a typval. diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 9287fdb460..e7efb14559 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -1432,7 +1432,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, } char_attr = win_hl_attr(wp, HLF_DED); } - char *const sbr = (char *)get_showbreak_value(wp); + char *const sbr = get_showbreak_value(wp); if (*sbr != NUL && need_showbreak) { // Draw 'showbreak' at the start of each broken line. p_extra = sbr; @@ -1824,7 +1824,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, syntax_attr = get_syntax_attr((colnr_T)v - 1, has_spell ? &can_spell : NULL, false); - if (did_emsg) { + if (did_emsg) { // -V547 wp->w_s->b_syn_error = true; has_syntax = false; } else { @@ -1979,7 +1979,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, // We have just drawn the showbreak value, no need to add // space for it again. if (vcol == vcol_sbr) { - n_extra -= mb_charlen((char *)get_showbreak_value(wp)); + n_extra -= mb_charlen(get_showbreak_value(wp)); if (n_extra < 0) { n_extra = 0; } @@ -2075,7 +2075,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, if (c == TAB && (!wp->w_p_list || wp->w_p_lcs_chars.tab1)) { int tab_len = 0; long vcol_adjusted = vcol; // removed showbreak length - char *const sbr = (char *)get_showbreak_value(wp); + char *const sbr = get_showbreak_value(wp); // Only adjust the tab_len, when at the first column after the // showbreak value was drawn. diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 9b82d50012..bf4563caa1 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -107,10 +107,9 @@ static colnr_T Insstart_textlen; // length of line when insert started static colnr_T Insstart_blank_vcol; // vcol for first inserted blank static bool update_Insstart_orig = true; // set Insstart_orig to Insstart -static char_u *last_insert = NULL; // the text of the previous insert, - // K_SPECIAL is escaped -static int last_insert_skip; // nr of chars in front of previous insert -static int new_insert_skip; // nr of chars in front of current insert +static char *last_insert = NULL; // the text of the previous insert, K_SPECIAL is escaped +static int last_insert_skip; // nr of chars in front of previous insert +static int new_insert_skip; // nr of chars in front of current insert static int did_restart_edit; // "restart_edit" when calling edit() static bool can_cindent; // may do cindenting on this line @@ -558,12 +557,12 @@ static int insert_execute(VimState *state, int key) // completion: Add to "compl_leader". if (ins_compl_accept_char(s->c)) { // Trigger InsertCharPre. - char_u *str = do_insert_char_pre(s->c); - char_u *p; + char *str = do_insert_char_pre(s->c); + char *p; if (str != NULL) { for (p = str; *p != NUL; MB_PTR_ADV(p)) { - ins_compl_addleader(utf_ptr2char((char *)p)); + ins_compl_addleader(utf_ptr2char(p)); } xfree(str); } else { @@ -1122,7 +1121,7 @@ normalchar: if (!p_paste) { // Trigger InsertCharPre. - char *str = (char *)do_insert_char_pre(s->c); + char *str = do_insert_char_pre(s->c); char *p; if (str != NULL) { @@ -1544,8 +1543,8 @@ void display_dollar(colnr_T col) curwin->w_cursor.col = col; // If on the last byte of a multi-byte move to the first byte. - char_u *p = (char_u *)get_cursor_line_ptr(); - curwin->w_cursor.col -= utf_head_off((char *)p, (char *)p + col); + char *p = get_cursor_line_ptr(); + curwin->w_cursor.col -= utf_head_off(p, p + col); curs_columns(curwin, false); // Recompute w_wrow and w_wcol if (curwin->w_wcol < curwin->w_grid.cols) { edit_putchar('$', false); @@ -1579,7 +1578,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang int last_vcol; int insstart_less; // reduction for Insstart.col int new_cursor_col; - char_u *ptr; + char *ptr; int save_p_list; int start_col; colnr_T vc; @@ -1658,9 +1657,9 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang // Advance the cursor until we reach the right screen column. last_vcol = 0; - ptr = (char_u *)get_cursor_line_ptr(); + ptr = get_cursor_line_ptr(); chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, 0, 0, (char *)ptr, (char *)ptr); + init_chartabsize_arg(&cts, curwin, 0, 0, ptr, ptr); while (cts.cts_vcol <= (int)curwin->w_virtcol) { last_vcol = cts.cts_vcol; if (cts.cts_vcol > 0) { @@ -1683,7 +1682,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang ptr = xmallocz(i); memset(ptr, ' ', i); new_cursor_col += (int)i; - ins_str((char *)ptr); + ins_str(ptr); xfree(ptr); } @@ -2062,8 +2061,8 @@ void insertchar(int c, int flags, int second_indent) // Need to remove existing (middle) comment leader and insert end // comment leader. First, check what comment leader we can find. - char_u *line = (char_u *)get_cursor_line_ptr(); - int i = get_leader_len((char *)line, &p, false, true); + char *line = get_cursor_line_ptr(); + int i = get_leader_len(line, &p, false, true); if (i > 0 && vim_strchr(p, COM_MIDDLE) != NULL) { // Just checking // Skip middle-comment string while (*p && p[-1] != ':') { // find end of middle flags @@ -2308,7 +2307,7 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove) if (did_restart_edit == 0 || (ptr != NULL && (int)strlen(ptr) > new_insert_skip)) { xfree(last_insert); - last_insert = (char_u *)ptr; + last_insert = ptr; last_insert_skip = new_insert_skip; } else { xfree(ptr); @@ -2414,7 +2413,7 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove) // Used for the replace command. void set_last_insert(int c) { - char_u *s; + char *s; xfree(last_insert); last_insert = xmalloc(MB_MAXBYTES * 3 + 5); @@ -2423,7 +2422,7 @@ void set_last_insert(int c) if (c < ' ' || c == DEL) { *s++ = Ctrl_V; } - s = add_char2buf(c, s); + s = (char *)add_char2buf(c, (char_u *)s); *s++ = ESC; *s++ = NUL; last_insert_skip = 0; @@ -2738,12 +2737,12 @@ char_u *get_last_insert(void) if (last_insert == NULL) { return NULL; } - return last_insert + last_insert_skip; + return (char_u *)last_insert + last_insert_skip; } // Get last inserted string, and remove trailing <Esc>. // Returns pointer to allocated memory (must be freed) or NULL. -char_u *get_last_insert_save(void) +char *get_last_insert_save(void) { char *s; int len; @@ -2751,13 +2750,13 @@ char_u *get_last_insert_save(void) if (last_insert == NULL) { return NULL; } - s = xstrdup((char *)last_insert + last_insert_skip); + s = xstrdup(last_insert + last_insert_skip); len = (int)strlen(s); if (len > 0 && s[len - 1] == ESC) { // remove trailing ESC s[len - 1] = NUL; } - return (char_u *)s; + return s; } /// Check the word in front of the cursor for an abbreviation. @@ -4502,7 +4501,7 @@ static bool ins_tab(void) if (!curbuf->b_p_et && (tabstop_count(curbuf->b_p_vsts_array) > 0 || get_sts_value() > 0 || (p_sta && ind))) { - char_u *ptr; + char *ptr; char *saved_line = NULL; // init for GCC pos_T pos; pos_T fpos; @@ -4517,9 +4516,9 @@ static bool ins_tab(void) pos = curwin->w_cursor; cursor = &pos; saved_line = xstrdup(get_cursor_line_ptr()); - ptr = (char_u *)saved_line + pos.col; + ptr = saved_line + pos.col; } else { - ptr = (char_u *)get_cursor_pos_ptr(); + ptr = get_cursor_pos_ptr(); cursor = &curwin->w_cursor; } @@ -4547,9 +4546,9 @@ static bool ins_tab(void) getvcol(curwin, &fpos, &vcol, NULL, NULL); getvcol(curwin, cursor, &want_vcol, NULL, NULL); - char_u *tab = (char_u *)"\t"; + char *tab = "\t"; chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, 0, vcol, (char *)tab, (char *)tab); + init_chartabsize_arg(&cts, curwin, 0, vcol, tab, tab); // Use as many TABs as possible. Beware of 'breakindent', 'showbreak' // and 'linebreak' adding extra virtual columns. @@ -4578,13 +4577,13 @@ static bool ins_tab(void) if (change_col >= 0) { int repl_off = 0; // Skip over the spaces we need. - init_chartabsize_arg(&cts, curwin, 0, vcol, (char *)ptr, (char *)ptr); + init_chartabsize_arg(&cts, curwin, 0, vcol, ptr, ptr); while (cts.cts_vcol < want_vcol && *cts.cts_ptr == ' ') { cts.cts_vcol += lbr_chartabsize(&cts); cts.cts_ptr++; repl_off++; } - ptr = (char_u *)cts.cts_ptr; + ptr = cts.cts_ptr; vcol = cts.cts_vcol; clear_chartabsize_arg(&cts); @@ -4761,8 +4760,8 @@ static int ins_digraph(void) int ins_copychar(linenr_T lnum) { int c; - char_u *ptr, *prev_ptr; - char_u *line; + char *ptr, *prev_ptr; + char *line; if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) { vim_beep(BO_COPY); @@ -4770,25 +4769,25 @@ int ins_copychar(linenr_T lnum) } // try to advance to the cursor column - line = (char_u *)ml_get(lnum); + line = ml_get(lnum); prev_ptr = line; validate_virtcol(); chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, lnum, 0, (char *)line, (char *)line); + init_chartabsize_arg(&cts, curwin, lnum, 0, line, line); while (cts.cts_vcol < curwin->w_virtcol && *cts.cts_ptr != NUL) { - prev_ptr = (char_u *)cts.cts_ptr; + prev_ptr = cts.cts_ptr; cts.cts_vcol += lbr_chartabsize_adv(&cts); } if (cts.cts_vcol > curwin->w_virtcol) { ptr = prev_ptr; } else { - ptr = (char_u *)cts.cts_ptr; + ptr = cts.cts_ptr; } clear_chartabsize_arg(&cts); - c = utf_ptr2char((char *)ptr); + c = utf_ptr2char(ptr); if (c == NUL) { vim_beep(BO_COPY); } @@ -4837,7 +4836,7 @@ static int ins_ctrl_ey(int tc) static void ins_try_si(int c) { pos_T *pos, old_pos; - char_u *ptr; + char *ptr; int i; bool temp; @@ -4851,7 +4850,7 @@ static void ins_try_si(int c) // containing the matching '(' if there is one. This handles the // case where an "if (..\n..) {" statement continues over multiple // lines -- webb - ptr = (char_u *)ml_get(pos->lnum); + ptr = ml_get(pos->lnum); i = pos->col; if (i > 0) { // skip blanks before '{' while (--i > 0 && ascii_iswhite(ptr[i])) {} @@ -4876,7 +4875,7 @@ static void ins_try_si(int c) old_pos = curwin->w_cursor; i = get_indent(); while (curwin->w_cursor.lnum > 1) { - ptr = (char_u *)skipwhite(ml_get(--(curwin->w_cursor.lnum))); + ptr = skipwhite(ml_get(--(curwin->w_cursor.lnum))); // ignore empty lines and lines starting with '#'. if (*ptr != '#' && *ptr != NUL) { @@ -4927,7 +4926,7 @@ colnr_T get_nolist_virtcol(void) // "c" is the character that was typed. // Return a pointer to allocated memory with the replacement string. // Return NULL to continue inserting "c". -static char_u *do_insert_char_pre(int c) +static char *do_insert_char_pre(int c) { char buf[MB_MAXBYTES + 1]; const int save_State = State; @@ -4958,7 +4957,7 @@ static char_u *do_insert_char_pre(int c) // Restore the State, it may have been changed. State = save_State; - return (char_u *)res; + return res; } bool get_can_cindent(void) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index b0805aecff..f58fb3f371 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -3828,7 +3828,7 @@ static int get_string_tv(char **arg, typval_T *rettv, int evaluate) if (p[1] != '*') { flags |= FSK_SIMPLIFY; } - extra = trans_special((const char **)&p, strlen(p), (char_u *)name, flags, false, NULL); + extra = trans_special((const char **)&p, strlen(p), name, flags, false, NULL); if (extra != 0) { name += extra; if (name >= rettv->vval.v_string + len) { @@ -3924,7 +3924,7 @@ static void partial_free(partial_T *pt) xfree(pt->pt_argv); tv_dict_unref(pt->pt_dict); if (pt->pt_name != NULL) { - func_unref((char_u *)pt->pt_name); + func_unref(pt->pt_name); xfree(pt->pt_name); } else { func_ptr_unref(pt->pt_func); @@ -4490,7 +4490,7 @@ bool set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack // A partial does not have a copyID, because it cannot contain itself. if (pt != NULL) { - abort = set_ref_in_func((char_u *)pt->pt_name, pt->pt_func, copyID); + abort = set_ref_in_func(pt->pt_name, pt->pt_func, copyID); if (pt->pt_dict != NULL) { typval_T dtv; @@ -4507,7 +4507,7 @@ bool set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack break; } case VAR_FUNC: - abort = set_ref_in_func((char_u *)tv->vval.v_string, NULL, copyID); + abort = set_ref_in_func(tv->vval.v_string, NULL, copyID); break; case VAR_UNKNOWN: case VAR_BOOL: @@ -5104,7 +5104,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref) xfree(name); } else { pt->pt_name = name; - func_ref((char_u *)name); + func_ref(name); } rettv->v_type = VAR_PARTIAL; @@ -5113,7 +5113,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref) // result is a VAR_FUNC rettv->v_type = VAR_FUNC; rettv->vval.v_string = name; - func_ref((char_u *)name); + func_ref(name); } } theend: @@ -5529,7 +5529,7 @@ bool callback_from_typval(Callback *const callback, const typval_T *const arg) if (callback->data.funcref == NULL) { callback->data.funcref = xstrdup(name); } - func_ref((char_u *)callback->data.funcref); + func_ref(callback->data.funcref); callback->type = kCallbackFuncref; } } else if (nlua_is_table_from_lua(arg)) { @@ -7408,7 +7408,7 @@ void ex_echo(exarg_T *eap) /// ":echohl {name}". void ex_echohl(exarg_T *eap) { - echo_attr = syn_name2attr((char_u *)eap->arg); + echo_attr = syn_name2attr(eap->arg); } /// ":execute expr1 ..." execute the result of an expression. @@ -8100,7 +8100,7 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, const char // - The text up to where the match is. // - The substituted text. // - The text after the match. - sublen = vim_regsub(®match, (char_u *)sub, expr, (char_u *)tail, 0, REGSUB_MAGIC); + sublen = vim_regsub(®match, sub, expr, tail, 0, REGSUB_MAGIC); ga_grow(&ga, (int)((end - tail) + sublen - (regmatch.endp[0] - regmatch.startp[0]))); @@ -8108,8 +8108,8 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, const char int i = (int)(regmatch.startp[0] - tail); memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); // add the substituted text - (void)vim_regsub(®match, (char_u *)sub, expr, - (char_u *)ga.ga_data + ga.ga_len + i, sublen, + (void)vim_regsub(®match, sub, expr, + (char *)ga.ga_data + ga.ga_len + i, sublen, REGSUB_COPY | REGSUB_MAGIC); ga.ga_len += i + sublen - 1; tail = regmatch.endp[0]; diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 14be6aba73..c17a44b990 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -148,6 +148,7 @@ return { getbufline={args={2, 3}, base=1}, getbufoneline={args=2, base=1}, getbufvar={args={2, 3}, base=1}, + getcellwidths={}, getchangelist={args={0, 1}, base=1}, getchar={args={0, 1}}, getcharmod={}, diff --git a/src/nvim/eval/buffer.c b/src/nvim/eval/buffer.c index e8eca3f854..2f37d1ba2e 100644 --- a/src/nvim/eval/buffer.c +++ b/src/nvim/eval/buffer.c @@ -278,9 +278,9 @@ void f_appendbufline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "bufadd(expr)" function void f_bufadd(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - char_u *name = (char_u *)tv_get_string(&argvars[0]); + char *name = (char *)tv_get_string(&argvars[0]); - rettv->vval.v_number = buflist_add(*name == NUL ? NULL : (char *)name, 0); + rettv->vval.v_number = buflist_add(*name == NUL ? NULL : name, 0); } /// "bufexists(expr)" function diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 25e026706c..6a677dd675 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -244,11 +244,11 @@ int call_internal_func(const char *const fname, const int argcount, typval_T *co } /// Invoke a method for base->method(). -int call_internal_method(const char_u *const fname, const int argcount, typval_T *const argvars, +int call_internal_method(const char *const fname, const int argcount, typval_T *const argvars, typval_T *const rettv, typval_T *const basetv) FUNC_ATTR_NONNULL_ALL { - const EvalFuncDef *const fdef = find_internal_func((const char *)fname); + const EvalFuncDef *const fdef = find_internal_func(fname); if (fdef == NULL) { return FCERR_UNKNOWN; } else if (fdef->base_arg == BASE_NONE) { @@ -572,16 +572,16 @@ static void f_call(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (argvars[2].v_type != VAR_DICT) { emsg(_(e_dictreq)); if (owned) { - func_unref((char_u *)func); + func_unref(func); } return; } selfdict = argvars[2].vval.v_dict; } - func_call((char_u *)func, &argvars[1], partial, selfdict, rettv); + func_call(func, &argvars[1], partial, selfdict, rettv); if (owned) { - func_unref((char_u *)func); + func_unref(func); } } @@ -2248,7 +2248,7 @@ static void f_get(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) rettv->v_type = (*what == 'f' ? VAR_FUNC : VAR_STRING); assert(name != NULL); if (rettv->v_type == VAR_FUNC) { - func_ref((char_u *)name); + func_ref((char *)name); } if (*what == 'n' && pt->pt_name == NULL && pt->pt_func != NULL) { // use <SNR> instead of the byte code @@ -2982,7 +2982,7 @@ static void f_globpath(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) const char *const file = tv_get_string_buf_chk(&argvars[1], buf1); if (file != NULL && !error) { garray_T ga; - ga_init(&ga, (int)sizeof(char_u *), 10); + ga_init(&ga, (int)sizeof(char *), 10); globpath((char *)tv_get_string(&argvars[0]), (char *)file, &ga, flags); if (rettv->v_type == VAR_STRING) { @@ -6468,7 +6468,7 @@ static void f_rpcstart(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) // Allocate extra memory for the argument vector and the NULL pointer int argvl = argsl + 2; - char **argv = xmalloc(sizeof(char_u *) * (size_t)argvl); + char **argv = xmalloc(sizeof(char *) * (size_t)argvl); // Copy program name argv[0] = xstrdup(argvars[0].vval.v_string); @@ -6644,7 +6644,7 @@ static void f_searchdecl(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } } if (!error && name != NULL) { - rettv->vval.v_number = find_decl((char_u *)name, strlen(name), locally, + rettv->vval.v_number = find_decl((char *)name, strlen(name), locally, thisblock, SEARCH_KEEP) == FAIL; } } @@ -7069,11 +7069,11 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv, EvalFuncData fpt return; } - char_u *const csearch = (char_u *)tv_dict_get_string(d, "char", false); + char *const csearch = tv_dict_get_string(d, "char", false); if (csearch != NULL) { int pcc[MAX_MCO]; - const int c = utfc_ptr2char((char *)csearch, pcc); - set_last_csearch(c, (char *)csearch, utfc_ptr2len((char *)csearch)); + const int c = utfc_ptr2char(csearch, pcc); + set_last_csearch(c, csearch, utfc_ptr2len(csearch)); } dictitem_T *di = tv_dict_find(d, S_LEN("forward")); @@ -7612,7 +7612,7 @@ static void f_spellsuggest(typval_T *argvars, typval_T *rettv, EvalFuncData fptr maxcount = 25; } - spell_suggest_list(&ga, (char_u *)str, maxcount, need_capital, false); + spell_suggest_list(&ga, (char *)str, maxcount, need_capital, false); f_spellsuggest_return: tv_list_alloc_ret(rettv, (ptrdiff_t)ga.ga_len); diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 7c61a2f990..5a356813f0 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1599,7 +1599,7 @@ void callback_free(Callback *callback) { switch (callback->type) { case kCallbackFuncref: - func_unref((char_u *)callback->data.funcref); + func_unref(callback->data.funcref); xfree(callback->data.funcref); break; case kCallbackPartial: @@ -1628,7 +1628,7 @@ void callback_put(Callback *cb, typval_T *tv) case kCallbackFuncref: tv->v_type = VAR_FUNC; tv->vval.v_string = xstrdup(cb->data.funcref); - func_ref((char_u *)cb->data.funcref); + func_ref(cb->data.funcref); break; case kCallbackLua: // TODO(tjdevries): Unified Callback. @@ -1654,7 +1654,7 @@ void callback_copy(Callback *dest, Callback *src) break; case kCallbackFuncref: dest->data.funcref = xstrdup(src->data.funcref); - func_ref((char_u *)src->data.funcref); + func_ref(src->data.funcref); break; case kCallbackLua: dest->data.luaref = api_new_luaref(src->data.luaref); @@ -3019,7 +3019,7 @@ static inline int _nothing_conv_func_start(typval_T *const tv, char_u *const fun return OK; } } else { - func_unref(fun); + func_unref((char *)fun); if ((const char *)fun != tv_empty_string) { xfree(fun); } @@ -3235,7 +3235,7 @@ void tv_free(typval_T *tv) partial_unref(tv->vval.v_partial); break; case VAR_FUNC: - func_unref((char_u *)tv->vval.v_string); + func_unref(tv->vval.v_string); FALLTHROUGH; case VAR_STRING: xfree(tv->vval.v_string); @@ -3288,7 +3288,7 @@ void tv_copy(const typval_T *const from, typval_T *const to) if (from->vval.v_string != NULL) { to->vval.v_string = xstrdup(from->vval.v_string); if (from->v_type == VAR_FUNC) { - func_ref((char_u *)to->vval.v_string); + func_ref(to->vval.v_string); } } break; diff --git a/src/nvim/eval/typval_defs.h b/src/nvim/eval/typval_defs.h index 939e5d0810..4615198441 100644 --- a/src/nvim/eval/typval_defs.h +++ b/src/nvim/eval/typval_defs.h @@ -337,7 +337,7 @@ struct ufunc { ///< used for s: variables int uf_refcount; ///< reference count, see func_name_refcount() funccall_T *uf_scoped; ///< l: local variables for closure - char_u *uf_name_exp; ///< if "uf_name[]" starts with SNR the name with + char *uf_name_exp; ///< if "uf_name[]" starts with SNR the name with ///< "<SNR>" as a string, otherwise NULL char uf_name[]; ///< Name of function (actual size equals name); ///< can start with <SNR>123_ diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 5d3b70b414..1d27826e7a 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -84,7 +84,7 @@ hashtab_T *func_tbl_get(void) } /// Get function arguments. -static int get_function_args(char **argp, char_u endchar, garray_T *newargs, int *varargs, +static int get_function_args(char **argp, char endchar, garray_T *newargs, int *varargs, garray_T *default_args, bool skip) { bool mustend = false; @@ -106,7 +106,7 @@ static int get_function_args(char **argp, char_u endchar, garray_T *newargs, int // Isolate the arguments: "arg1, arg2, ...)" bool any_default = false; - while (*p != (char)endchar) { + while (*p != endchar) { if (p[0] == '.' && p[1] == '.' && p[2] == '.') { if (varargs != NULL) { *varargs = true; @@ -188,14 +188,14 @@ static int get_function_args(char **argp, char_u endchar, garray_T *newargs, int } } p = skipwhite(p); - if (mustend && *p != (char)endchar) { + if (mustend && *p != endchar) { if (!skip) { semsg(_(e_invarg2), *argp); } break; } } - if (*p != (char)endchar) { + if (*p != endchar) { goto err_ret; } p++; // skip "endchar" @@ -229,12 +229,12 @@ static void register_closure(ufunc_T *fp) } /// @return a name for a lambda. Returned in static memory. -char_u *get_lambda_name(void) +char *get_lambda_name(void) { - static char_u name[30]; + static char name[30]; static int lambda_no = 0; - snprintf((char *)name, sizeof(name), "<lambda>%d", ++lambda_no); + snprintf(name, sizeof(name), "<lambda>%d", ++lambda_no); return name; } @@ -308,7 +308,7 @@ int get_lambda_tv(char **arg, typval_T *rettv, bool evaluate) char *p; garray_T newlines; - char *name = (char *)get_lambda_name(); + char *name = get_lambda_name(); fp = xcalloc(1, offsetof(ufunc_T, uf_name) + strlen(name) + 1); pt = xcalloc(1, sizeof(partial_T)); @@ -1226,7 +1226,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett /// For the first we only count the name stored in func_hashtab as a reference, /// using function() does not count as a reference, because the function is /// looked up by name. -static bool func_name_refcount(const char_u *name) +static bool func_name_refcount(const char *name) { return isdigit((uint8_t)(*name)) || *name == '<'; } @@ -1319,7 +1319,7 @@ void free_all_functions(void) // Only free functions that are not refcounted, those are // supposed to be freed when no longer referenced. fp = HI2UF(hi); - if (func_name_refcount((char_u *)fp->uf_name)) { + if (func_name_refcount(fp->uf_name)) { skipped++; } else { changed = func_hashtab.ht_changed; @@ -1345,7 +1345,7 @@ void free_all_functions(void) // Only free functions that are not refcounted, those are // supposed to be freed when no longer referenced. fp = HI2UF(hi); - if (func_name_refcount((char_u *)fp->uf_name)) { + if (func_name_refcount(fp->uf_name)) { skipped++; } else { func_free(fp); @@ -1382,7 +1382,7 @@ static bool builtin_function(const char *name, int len) return p == NULL; } -int func_call(char_u *name, typval_T *args, partial_T *partial, dict_T *selfdict, typval_T *rettv) +int func_call(char *name, typval_T *args, partial_T *partial, dict_T *selfdict, typval_T *rettv) { typval_T argv[MAX_FUNC_ARGS + 1]; int argc = 0; @@ -1404,7 +1404,7 @@ int func_call(char_u *name, typval_T *args, partial_T *partial, dict_T *selfdict funcexe.fe_evaluate = true; funcexe.fe_partial = partial; funcexe.fe_selfdict = selfdict; - r = call_func((char *)name, -1, rettv, argc, argv, &funcexe); + r = call_func(name, -1, rettv, argc, argv, &funcexe); func_call_skip_call: // Free the arguments. @@ -1435,30 +1435,30 @@ varnumber_T callback_call_retnr(Callback *callback, int argcount, typval_T *argv /// Give an error message for the result of a function. /// Nothing if "error" is FCERR_NONE. -static void user_func_error(int error, const char_u *name) +static void user_func_error(int error, const char *name) FUNC_ATTR_NONNULL_ALL { switch (error) { case FCERR_UNKNOWN: - emsg_funcname(N_("E117: Unknown function: %s"), (char *)name); + emsg_funcname(N_("E117: Unknown function: %s"), name); break; case FCERR_NOTMETHOD: - emsg_funcname(N_("E276: Cannot use function as a method: %s"), (char *)name); + emsg_funcname(N_("E276: Cannot use function as a method: %s"), name); break; case FCERR_DELETED: - emsg_funcname(N_("E933: Function was deleted: %s"), (char *)name); + emsg_funcname(N_("E933: Function was deleted: %s"), name); break; case FCERR_TOOMANY: - emsg_funcname(_(e_toomanyarg), (char *)name); + emsg_funcname(_(e_toomanyarg), name); break; case FCERR_TOOFEW: - emsg_funcname(N_("E119: Not enough arguments for function: %s"), (char *)name); + emsg_funcname(N_("E119: Not enough arguments for function: %s"), name); break; case FCERR_SCRIPT: - emsg_funcname(N_("E120: Using <SID> not in a script context: %s"), (char *)name); + emsg_funcname(N_("E120: Using <SID> not in a script context: %s"), name); break; case FCERR_DICT: - emsg_funcname(N_("E725: Calling dict function without Dictionary: %s"), (char *)name); + emsg_funcname(N_("E725: Calling dict function without Dictionary: %s"), name); break; } } @@ -1612,7 +1612,7 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t } else if (funcexe->fe_basetv != NULL) { // expr->method(): Find the method name in the table, call its // implementation with the base as one of the arguments. - error = call_internal_method((char_u *)fname, argcount, argvars, rettv, + error = call_internal_method(fname, argcount, argvars, rettv, funcexe->fe_basetv); } else { // Find the function name in the table, call its implementation. @@ -1636,7 +1636,7 @@ theend: // Report an error unless the argument evaluation or function call has been // cancelled due to an aborting error, an interrupt, or an exception. if (!aborting()) { - user_func_error(error, (name != NULL) ? (char_u *)name : (char_u *)funcname); + user_func_error(error, (name != NULL) ? name : funcname); } // clear the copies made from the partial @@ -1652,7 +1652,7 @@ theend: char *printable_func_name(ufunc_T *fp) { - return fp->uf_name_exp != NULL ? (char *)fp->uf_name_exp : fp->uf_name; + return fp->uf_name_exp != NULL ? fp->uf_name_exp : fp->uf_name; } /// List the head of the function: "name(arg1, arg2)". @@ -1724,7 +1724,7 @@ static void list_func_head(ufunc_T *fp, int indent, bool force) /// @param partial return: partial of a FuncRef /// /// @return the function name in allocated memory, or NULL for failure. -char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, partial_T **partial) +char *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, partial_T **partial) FUNC_ATTR_NONNULL_ARG(1) { char *name = NULL; @@ -1745,7 +1745,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa && (*pp)[2] == KE_SNR) { *pp += 3; len = get_id_len((const char **)pp) + 3; - return (char_u *)xmemdupz(start, (size_t)len); + return xmemdupz(start, (size_t)len); } // A name starting with "<SID>" or "<SNR>" is local to a script. But @@ -1924,7 +1924,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa theend: clear_lval(&lv); - return (char_u *)name; + return name; } /// If the "funcname" starts with "s:" or "<SID>", then expands it to the @@ -1976,7 +1976,7 @@ char *save_function_name(char **name, bool skip, int flags, funcdict_T *fudi) CLEAR_POINTER(fudi); } } else { - saved = (char *)trans_function_name(&p, skip, flags, fudi, NULL); + saved = trans_function_name(&p, skip, flags, fudi, NULL); } *name = p; return saved; @@ -2001,7 +2001,7 @@ static void list_functions(regmatch_T *regmatch) if ((fp->uf_flags & FC_DEAD) == 0 && (regmatch == NULL ? (!message_filtered((char *)fp->uf_name) - && !func_name_refcount((char_u *)fp->uf_name)) + && !func_name_refcount(fp->uf_name)) : (!isdigit((uint8_t)(*fp->uf_name)) && vim_regexec(regmatch, (char *)fp->uf_name, 0)))) { list_func_head(fp, false, false); @@ -2296,7 +2296,7 @@ void ex_function(exarg_T *eap) } else { xfree(line_to_free); if (eap->getline == NULL) { - theline = (char *)getcmdline(':', 0L, indent, do_concat); + theline = getcmdline(':', 0L, indent, do_concat); } else { theline = eap->getline(':', eap->cookie, indent, do_concat); } @@ -2532,7 +2532,7 @@ void ex_function(exarg_T *eap) fp = NULL; overwrite = true; } else { - char_u *exp_name = fp->uf_name_exp; + char *exp_name = fp->uf_name_exp; // redefine existing function, keep the expanded name XFREE_CLEAR(name); fp->uf_name_exp = NULL; @@ -2708,7 +2708,7 @@ bool function_exists(const char *const name, bool no_deref) if (no_deref) { flag |= TFN_NO_DEREF; } - char *const p = (char *)trans_function_name((char **)&nm, false, flag, NULL, NULL); + char *const p = trans_function_name((char **)&nm, false, flag, NULL, NULL); nm = skipwhite(nm); // Only accept "funcname", "funcname ", "funcname (..." and @@ -2770,7 +2770,7 @@ void ex_delfunction(exarg_T *eap) { ufunc_T *fp = NULL; char *p; - char_u *name; + char *name; funcdict_T fudi; p = eap->arg; @@ -2800,7 +2800,7 @@ void ex_delfunction(exarg_T *eap) return; } if (!eap->skip) { - fp = find_func(name); + fp = find_func((char_u *)name); } xfree(name); @@ -2833,7 +2833,7 @@ void ex_delfunction(exarg_T *eap) // it and the refcount is more than one, it should be kept. // A numbered function or lambda should be kept if the refcount is // one or more. - if (fp->uf_refcount > (func_name_refcount((char_u *)fp->uf_name) ? 0 : 1)) { + if (fp->uf_refcount > (func_name_refcount(fp->uf_name) ? 0 : 1)) { // Function is still referenced somewhere. Don't free it but // do remove it from the hashtable. if (func_remove(fp)) { @@ -2849,7 +2849,7 @@ void ex_delfunction(exarg_T *eap) /// Unreference a Function: decrement the reference count and free it when it /// becomes zero. -void func_unref(char_u *name) +void func_unref(char *name) { ufunc_T *fp = NULL; @@ -2857,7 +2857,7 @@ void func_unref(char_u *name) return; } - fp = find_func(name); + fp = find_func((char_u *)name); if (fp == NULL && isdigit((uint8_t)(*name))) { #ifdef EXITFREE if (!entered_free_all_mem) { @@ -2891,14 +2891,14 @@ void func_ptr_unref(ufunc_T *fp) } /// Count a reference to a Function. -void func_ref(char_u *name) +void func_ref(char *name) { ufunc_T *fp; if (name == NULL || !func_name_refcount(name)) { return; } - fp = find_func(name); + fp = find_func((char_u *)name); if (fp != NULL) { (fp->uf_refcount)++; } else if (isdigit((uint8_t)(*name))) { @@ -3018,7 +3018,7 @@ void ex_call(exarg_T *eap) return; } - tofree = (char *)trans_function_name(&arg, false, TFN_INT, &fudi, &partial); + tofree = trans_function_name(&arg, false, TFN_INT, &fudi, &partial); if (fudi.fd_newkey != NULL) { // Still need to give an error message for missing key. semsg(_(e_dictkey), fudi.fd_newkey); @@ -3328,7 +3328,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) // be referenced elsewhere. if (ret_pt->pt_name != NULL) { pt->pt_name = xstrdup(ret_pt->pt_name); - func_ref((char_u *)pt->pt_name); + func_ref(pt->pt_name); } else { pt->pt_func = ret_pt->pt_func; func_ptr_ref(pt->pt_func); @@ -3349,9 +3349,9 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) } /// @return the name of the executed function. -char_u *func_name(void *cookie) +char *func_name(void *cookie) { - return (char_u *)((funccall_T *)cookie)->func->uf_name; + return ((funccall_T *)cookie)->func->uf_name; } /// @return the address holding the next breakpoint line for a funccall cookie. @@ -3610,7 +3610,7 @@ bool set_ref_in_functions(int copyID) if (!HASHITEM_EMPTY(hi)) { todo--; fp = HI2UF(hi); - if (!func_name_refcount((char_u *)fp->uf_name) + if (!func_name_refcount(fp->uf_name) && set_ref_in_func(NULL, fp, copyID)) { return true; } @@ -3636,7 +3636,7 @@ bool set_ref_in_func_args(int copyID) /// "ht_stack" is used to add hashtabs to be marked. Can be NULL. /// /// @return true if setting references failed somehow. -bool set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID) +bool set_ref_in_func(char *name, ufunc_T *fp_in, int copyID) { ufunc_T *fp = fp_in; funccall_T *fc; @@ -3650,7 +3650,7 @@ bool set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID) } if (fp_in == NULL) { - fname = fname_trans_sid((char *)name, fname_buf, &tofree, &error); + fname = fname_trans_sid(name, fname_buf, &tofree, &error); fp = find_func((char_u *)fname); } if (fp != NULL) { @@ -3663,9 +3663,9 @@ bool set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID) } /// Registers a luaref as a lambda. -char_u *register_luafunc(LuaRef ref) +char *register_luafunc(LuaRef ref) { - char *name = (char *)get_lambda_name(); + char *name = get_lambda_name(); ufunc_T *fp = xcalloc(1, offsetof(ufunc_T, uf_name) + strlen(name) + 1); fp->uf_refcount = 1; @@ -3679,5 +3679,5 @@ char_u *register_luafunc(LuaRef ref) hash_add(&func_hashtab, UF2HIKEY(fp)); // coverity[leaked_storage] - return (char_u *)fp->uf_name; + return fp->uf_name; } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 4ea11dd32a..6e888d9dcf 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -158,7 +158,7 @@ void do_ascii(const exarg_T *const eap) char buf2[20]; buf2[0] = NUL; - dig = (char *)get_digraph_for_char(cval); + dig = get_digraph_for_char(cval); if (dig != NULL) { iobuff_len += (size_t)vim_snprintf(IObuff + iobuff_len, sizeof(IObuff) - iobuff_len, @@ -206,7 +206,7 @@ void do_ascii(const exarg_T *const eap) } iobuff_len += (size_t)utf_char2bytes(c, IObuff + iobuff_len); - dig = (char *)get_digraph_for_char(c); + dig = get_digraph_for_char(c); if (dig != NULL) { iobuff_len += (size_t)vim_snprintf(IObuff + iobuff_len, sizeof(IObuff) - iobuff_len, @@ -3895,7 +3895,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // When it fails sublen is zero. sublen = vim_regsub_multi(®match, sub_firstlnum - regmatch.startpos[0].lnum, - (char_u *)sub, (char_u *)sub_firstline, 0, + sub, sub_firstline, 0, REGSUB_BACKSLASH | (magic_isset() ? REGSUB_MAGIC : 0)); textlock--; @@ -3938,7 +3938,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T textlock++; (void)vim_regsub_multi(®match, sub_firstlnum - regmatch.startpos[0].lnum, - (char_u *)sub, (char_u *)new_end, sublen, + sub, new_end, sublen, REGSUB_COPY | REGSUB_BACKSLASH | (magic_isset() ? REGSUB_MAGIC : 0)); textlock--; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 896130debf..08d4065e98 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -369,7 +369,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) // Get the function or script name and the address where the next breakpoint // line and the debug tick for a function or script are stored. if (getline_is_func) { - fname = (char *)func_name(real_cookie); + fname = func_name(real_cookie); breakpoint = func_breakpoint(real_cookie); dbg_tick = func_dbg_tick(real_cookie); } else if (getline_equal(fgetline, cookie, getsourceline)) { @@ -919,7 +919,7 @@ static char *get_loop_line(int c, void *cookie, int indent, bool do_concat) char *line; // First time inside the ":while"/":for": get line normally. if (cp->getline == NULL) { - line = (char *)getcmdline(c, 0L, indent, do_concat); + line = getcmdline(c, 0L, indent, do_concat); } else { line = cp->getline(c, cp->cookie, indent, do_concat); } @@ -2852,7 +2852,7 @@ bool checkforcmd(char **pp, const char *cmd, int len) break; } } - if (i >= len && !isalpha((uint8_t)(*pp)[i])) { + if (i >= len && !ASCII_ISALPHA((*pp)[i])) { *pp = skipwhite(*pp + i); return true; } @@ -3812,8 +3812,8 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp) #endif for (l = repl; *l; l++) { - if (vim_strchr((char *)ESCAPE_CHARS, (uint8_t)(*l)) != NULL) { - l = vim_strsave_escaped(repl, (char *)ESCAPE_CHARS); + if (vim_strchr(ESCAPE_CHARS, (uint8_t)(*l)) != NULL) { + l = vim_strsave_escaped(repl, ESCAPE_CHARS); xfree(repl); repl = l; break; @@ -4976,8 +4976,8 @@ void ex_splitview(exarg_T *eap) } if (eap->cmdidx == CMD_sfind || eap->cmdidx == CMD_tabfind) { - fname = (char *)find_file_in_path(eap->arg, strlen(eap->arg), - FNAME_MESS, true, curbuf->b_ffname); + fname = find_file_in_path(eap->arg, strlen(eap->arg), + FNAME_MESS, true, curbuf->b_ffname); if (fname == NULL) { goto theend; } @@ -4987,7 +4987,7 @@ void ex_splitview(exarg_T *eap) // Either open new tab page or split the window. if (use_tab) { if (win_new_tabpage(cmdmod.cmod_tab != 0 ? cmdmod.cmod_tab : eap->addr_count == 0 - ? 0 : (int)eap->line2 + 1, (char_u *)eap->arg) != FAIL) { + ? 0 : (int)eap->line2 + 1, eap->arg) != FAIL) { do_exedit(eap, old_curwin); apply_autocmds(EVENT_TABNEWENTERED, NULL, NULL, false, curbuf); @@ -5169,15 +5169,15 @@ static void ex_resize(exarg_T *eap) /// ":find [+command] <file>" command. static void ex_find(exarg_T *eap) { - char *fname = (char *)find_file_in_path(eap->arg, strlen(eap->arg), - FNAME_MESS, true, curbuf->b_ffname); + char *fname = find_file_in_path(eap->arg, strlen(eap->arg), + FNAME_MESS, true, curbuf->b_ffname); if (eap->addr_count > 0) { // Repeat finding the file "count" times. This matters when it // appears several times in the path. linenr_T count = eap->line2; while (fname != NULL && --count > 0) { xfree(fname); - fname = (char *)find_file_in_path(NULL, 0, FNAME_MESS, false, curbuf->b_ffname); + fname = find_file_in_path(NULL, 0, FNAME_MESS, false, curbuf->b_ffname); } } @@ -6845,7 +6845,7 @@ char_u *eval_vars(char *src, const char_u *srcstart, size_t *usedlen, linenr_T * break; case SPEC_CFILE: // file name under cursor - result = (char *)file_name_at_cursor(FNAME_MESS|FNAME_HYP, 1L, NULL); + result = file_name_at_cursor(FNAME_MESS|FNAME_HYP, 1L, NULL); if (result == NULL) { *errormsg = ""; return NULL; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 0a1d6b2857..c62142310d 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -381,7 +381,7 @@ static void may_do_incsearch_highlighting(int firstc, long count, incsearch_stat proftime_T tm; int skiplen, patlen; char next_char; - char_u use_last_pat; + bool use_last_pat; int search_delim; // Parsing range may already set the last search pattern. @@ -725,7 +725,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool clea if (ccline.input_fn) { s->xpc.xp_context = ccline.xp_context; s->xpc.xp_pattern = ccline.cmdbuff; - s->xpc.xp_arg = (char *)ccline.xp_arg; + s->xpc.xp_arg = ccline.xp_arg; } // Avoid scrolling when called by a recursive do_cmdline(), e.g. when @@ -908,7 +908,7 @@ theend: xfree(ccline.last_colors.cmdbuff); kv_destroy(ccline.last_colors.colors); - char_u *p = (char_u *)ccline.cmdbuff; + char *p = ccline.cmdbuff; if (ui_has(kUICmdline)) { ui_call_cmdline_hide(ccline.level); @@ -923,7 +923,7 @@ theend: ccline.cmdbuff = NULL; } - return p; + return (uint8_t *)p; } static int command_line_check(VimState *state) @@ -1474,7 +1474,7 @@ static int command_line_erase_chars(CommandLineState *s) } if (s->c == K_DEL) { - ccline.cmdpos += mb_off_next((char_u *)ccline.cmdbuff, + ccline.cmdpos += mb_off_next(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos); } @@ -2625,9 +2625,9 @@ static void abandon_cmdline(void) /// /// @param count only used for incremental search /// @param indent indent for inside conditionals -char_u *getcmdline(int firstc, long count, int indent, bool do_concat FUNC_ATTR_UNUSED) +char *getcmdline(int firstc, long count, int indent, bool do_concat FUNC_ATTR_UNUSED) { - return command_line_enter(firstc, count, indent, true); + return (char *)command_line_enter(firstc, count, indent, true); } /// Get a command line with a prompt @@ -2660,10 +2660,10 @@ char *getcmdline_prompt(const int firstc, const char *const prompt, const int at CLEAR_FIELD(ccline); } ccline.prompt_id = last_prompt_id++; - ccline.cmdprompt = (char_u *)prompt; + ccline.cmdprompt = (char *)prompt; ccline.cmdattr = attr; ccline.xp_context = xp_context; - ccline.xp_arg = (char_u *)xp_arg; + ccline.xp_arg = (char *)xp_arg; ccline.input_fn = (firstc == '@'); ccline.highlight_callback = highlight_callback; @@ -2687,12 +2687,6 @@ char *getcmdline_prompt(const int firstc, const char *const prompt, const int at return ret; } -// Return current cmdline prompt -char_u *get_cmdprompt(void) -{ - return ccline.cmdprompt; -} - /// Read the 'wildmode' option, fill wim_flags[]. int check_opt_wim(void) { @@ -2872,7 +2866,7 @@ char *getexline(int c, void *cookie, int indent, bool do_concat) (void)vgetc(); } - return (char *)getcmdline(c, 1L, indent, do_concat); + return getcmdline(c, 1L, indent, do_concat); } bool cmdline_overstrike(void) @@ -2910,7 +2904,7 @@ void realloc_cmdbuff(int len) return; // no need to resize } - char_u *p = (char_u *)ccline.cmdbuff; + char *p = ccline.cmdbuff; alloc_cmdbuff(len); // will get some more // There isn't always a NUL after the command, but it may need to be // there, thus copy up to the NUL and add a NUL. @@ -2922,7 +2916,7 @@ void realloc_cmdbuff(int len) && ccline.xpc->xp_pattern != NULL && ccline.xpc->xp_context != EXPAND_NOTHING && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) { - int i = (int)((char_u *)ccline.xpc->xp_pattern - p); + int i = (int)(ccline.xpc->xp_pattern - p); // If xp_pattern points inside the old cmdbuff it needs to be adjusted // to point into the newly allocated memory. @@ -3257,10 +3251,10 @@ static void draw_cmdline(int start, int len) bool do_arabicshape = false; int mb_l; for (int i = start; i < start + len; i += mb_l) { - char_u *p = (char_u *)ccline.cmdbuff + i; + char *p = ccline.cmdbuff + i; int u8cc[MAX_MCO]; - int u8c = utfc_ptr2char_len((char *)p, u8cc, start + len - i); - mb_l = utfc_ptr2len_len((char *)p, start + len - i); + int u8c = utfc_ptr2char_len(p, u8cc, start + len - i); + mb_l = utfc_ptr2len_len(p, start + len - i); if (ARABIC_CHAR(u8c)) { do_arabicshape = true; break; @@ -3293,10 +3287,10 @@ static void draw_cmdline(int start, int len) int prev_c = 0; int prev_c1 = 0; for (int i = start; i < start + len; i += mb_l) { - char_u *p = (char_u *)ccline.cmdbuff + i; + char *p = ccline.cmdbuff + i; int u8cc[MAX_MCO]; - int u8c = utfc_ptr2char_len((char *)p, u8cc, start + len - i); - mb_l = utfc_ptr2len_len((char *)p, start + len - i); + int u8c = utfc_ptr2char_len(p, u8cc, start + len - i); + mb_l = utfc_ptr2len_len(p, start + len - i); if (ARABIC_CHAR(u8c)) { int pc; int pc1 = 0; @@ -3310,7 +3304,7 @@ static void draw_cmdline(int start, int len) if (i + mb_l >= start + len) { nc = NUL; } else { - nc = utf_ptr2char((char *)p + mb_l); + nc = utf_ptr2char(p + mb_l); } } else { // Displaying from left to right. @@ -3319,7 +3313,7 @@ static void draw_cmdline(int start, int len) } else { int pcc[MAX_MCO]; - pc = utfc_ptr2char_len((char *)p + mb_l, pcc, start + len - i - mb_l); + pc = utfc_ptr2char_len(p + mb_l, pcc, start + len - i - mb_l); pc1 = pcc[0]; } nc = prev_c; @@ -3369,7 +3363,7 @@ static void ui_ext_cmdline_show(CmdlineInfo *line) if (cmdline_star) { content = arena_array(&arena, 1); size_t len = 0; - for (char_u *p = (char_u *)ccline.cmdbuff; *p; MB_PTR_ADV(p)) { + for (char *p = ccline.cmdbuff; *p; MB_PTR_ADV(p)) { len++; } char *buf = arena_alloc(&arena, len, false); @@ -3400,7 +3394,7 @@ static void ui_ext_cmdline_show(CmdlineInfo *line) char charbuf[2] = { (char)line->cmdfirstc, 0 }; ui_call_cmdline_show(content, line->cmdpos, cstr_as_string(charbuf), - cstr_as_string((char *)(line->cmdprompt)), + cstr_as_string((line->cmdprompt)), line->cmdindent, line->level); if (line->special_char) { @@ -3682,7 +3676,7 @@ static void restore_cmdline(CmdlineInfo *ccp) static bool cmdline_paste(int regname, bool literally, bool remcr) { char *arg; - char_u *p; + char *p; bool allocated; // check for valid regname; also accept special characters for CTRL-R in @@ -3714,7 +3708,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) // When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate // part of the word. - p = (char_u *)arg; + p = arg; if (p_is && regname == Ctrl_W) { char *w; int len; @@ -3733,7 +3727,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) } } - cmdline_paste_str((char *)p, literally); + cmdline_paste_str(p, literally); if (allocated) { xfree(arg); } @@ -3800,7 +3794,7 @@ static void redrawcmdprompt(void) msg_putchar(ccline.cmdfirstc); } if (ccline.cmdprompt != NULL) { - msg_puts_attr((const char *)ccline.cmdprompt, ccline.cmdattr); + msg_puts_attr(ccline.cmdprompt, ccline.cmdattr); ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; // do the reverse of cmd_startcol() if (ccline.cmdfirstc != NUL) { @@ -3975,8 +3969,8 @@ char *vim_strsave_fnameescape(const char *const fname, const int what) { #ifdef BACKSLASH_IN_FILENAME # define PATH_ESC_CHARS " \t\n*?[{`%#'\"|!<" -# define BUFFER_ESC_CHARS ((char_u *)" \t\n*?[`%#'\"|!<") - char_u buf[sizeof(PATH_ESC_CHARS)]; +# define BUFFER_ESC_CHARS (" \t\n*?[`%#'\"|!<") + char buf[sizeof(PATH_ESC_CHARS)]; int j = 0; // Don't escape '[', '{' and '!' if they are in 'isfname' and for the @@ -3988,8 +3982,7 @@ char *vim_strsave_fnameescape(const char *const fname, const int what) } } buf[j] = NUL; - char *p = (char *)vim_strsave_escaped((const char_u *)fname, - (const char_u *)buf); + char *p = vim_strsave_escaped(fname, buf); #else # define PATH_ESC_CHARS " \t\n*?[{`$\\%#'\"|!<" # define SHELL_ESC_CHARS " \t\n*?[{`$\\%#'\"|!<>();&" @@ -4018,11 +4011,11 @@ char *vim_strsave_fnameescape(const char *const fname, const int what) /// Put a backslash before the file name in "pp", which is in allocated memory. void escape_fname(char **pp) { - char_u *p = xmalloc(strlen(*pp) + 2); + char *p = xmalloc(strlen(*pp) + 2); p[0] = '\\'; STRCPY(p + 1, *pp); xfree(*pp); - *pp = (char *)p; + *pp = p; } /// For each file name in files[num_files]: @@ -4296,7 +4289,7 @@ char *check_cedit(void) if (*p_cedit == NUL) { cedit_key = -1; } else { - n = string_to_key((char_u *)p_cedit); + n = string_to_key(p_cedit); if (vim_isprintc(n)) { return e_invarg; } diff --git a/src/nvim/ex_getln.h b/src/nvim/ex_getln.h index 916b695a35..61ac4b69c5 100644 --- a/src/nvim/ex_getln.h +++ b/src/nvim/ex_getln.h @@ -54,14 +54,14 @@ struct cmdline_info { int cmdspos; ///< cursor column on screen int cmdfirstc; ///< ':', '/', '?', '=', '>' or NUL int cmdindent; ///< number of spaces before cmdline - char_u *cmdprompt; ///< message in front of cmdline + char *cmdprompt; ///< message in front of cmdline int cmdattr; ///< attributes for prompt int overstrike; ///< Typing mode on the command line. Shared by ///< getcmdline() and put_on_cmdline(). expand_T *xpc; ///< struct being used for expansion, xp_pattern ///< may point into cmdbuff int xp_context; ///< type of expansion - char_u *xp_arg; ///< user-defined expansion arg + char *xp_arg; ///< user-defined expansion arg int input_fn; ///< when true Invoked for input() function unsigned prompt_id; ///< Prompt number, used to disable coloring on errors. Callback highlight_callback; ///< Callback used for coloring user input. diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index d0280b3571..02a33f8fd3 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -551,7 +551,7 @@ void vim_findfile_cleanup(void *ctx) /// /// @return a pointer to an allocated file name or, /// NULL if nothing found. -char_u *vim_findfile(void *search_ctx_arg) +char *vim_findfile(void *search_ctx_arg) { char *file_path; char *rest_of_wildcards; @@ -829,7 +829,7 @@ char_u *vim_findfile(void *search_ctx_arg) verbose_leave_scroll(); } #endif - return (char_u *)file_path; + return file_path; } // Not found or found already, try next suffix. @@ -1287,13 +1287,13 @@ static int ff_path_in_stoplist(char *path, int path_len, char **stopdirs_v) /// @param rel_fname file name searching relative to /// /// @return an allocated string for the file name. NULL for error. -char_u *find_file_in_path(char *ptr, size_t len, int options, int first, char *rel_fname) +char *find_file_in_path(char *ptr, size_t len, int options, int first, char *rel_fname) { - return (char_u *)find_file_in_path_option(ptr, len, options, first, - (*curbuf->b_p_path == NUL - ? (char *)p_path - : curbuf->b_p_path), - FINDFILE_BOTH, rel_fname, curbuf->b_p_sua); + return find_file_in_path_option(ptr, len, options, first, + (*curbuf->b_p_path == NUL + ? (char *)p_path + : curbuf->b_p_path), + FINDFILE_BOTH, rel_fname, curbuf->b_p_sua); } static char *ff_file_to_find = NULL; @@ -1322,10 +1322,10 @@ void free_findfile(void) /// @param rel_fname file name searching relative to /// /// @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) +char *find_directory_in_path(char *ptr, size_t len, int options, char *rel_fname) { - return (char_u *)find_file_in_path_option((char *)ptr, len, options, true, (char *)p_cdpath, - FINDFILE_DIR, (char *)rel_fname, ""); + return find_file_in_path_option(ptr, len, options, true, (char *)p_cdpath, + FINDFILE_DIR, rel_fname, ""); } /// @param ptr file name @@ -1446,7 +1446,7 @@ char *find_file_in_path_option(char *ptr, size_t len, int options, int first, ch for (;;) { if (did_findfile_init) { - file_name = (char *)vim_findfile(fdip_search_ctx); + file_name = vim_findfile(fdip_search_ctx); if (file_name != NULL) { break; } @@ -1610,8 +1610,8 @@ int vim_chdirfile(char *fname, CdCause cause) /// Change directory to "new_dir". Search 'cdpath' for relative directory names. int vim_chdir(char *new_dir) { - char *dir_name = (char *)find_directory_in_path((char_u *)new_dir, strlen(new_dir), - FNAME_MESS, (char_u *)curbuf->b_ffname); + char *dir_name = find_directory_in_path(new_dir, strlen(new_dir), + FNAME_MESS, curbuf->b_ffname); if (dir_name == NULL) { return -1; } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 3a7db22d2f..78fe8a3ab3 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -105,7 +105,7 @@ enum { // Structure to pass arguments from buf_write() to buf_write_bytes(). struct bw_info { int bw_fd; // file descriptor - char_u *bw_buf; // buffer with data to be written + char *bw_buf; // buffer with data to be written int bw_len; // length of data #ifdef HAS_BW_FLAGS int bw_flags; // FIO_ flags @@ -113,7 +113,7 @@ struct bw_info { char_u bw_rest[CONV_RESTLEN]; // not converted bytes int bw_restlen; // nr of bytes in bw_rest[] int bw_first; // first write call - char_u *bw_conv_buf; // buffer for writing converted chars + char *bw_conv_buf; // buffer for writing converted chars size_t bw_conv_buflen; // size of bw_conv_buf int bw_conv_error; // set for conversion error linenr_T bw_conv_error_lnum; // first line with error or zero @@ -835,14 +835,14 @@ retry: // appears not to handle this correctly. This works just like // conversion to UTF-8 except how the resulting character is put in // the buffer. - fio_flags = get_fio_flags((char_u *)fenc); + fio_flags = get_fio_flags(fenc); } #ifdef HAVE_ICONV // Try using iconv() if we can't convert internally. if (fio_flags == 0 && !did_iconv) { - iconv_fd = (iconv_t)my_iconv_open((char_u *)"utf-8", (char_u *)fenc); + iconv_fd = (iconv_t)my_iconv_open("utf-8", fenc); } #endif @@ -1107,7 +1107,7 @@ retry: || (!curbuf->b_p_bomb && tmpname == NULL && (*fenc == 'u' || *fenc == NUL)))) { - char_u *ccname; + char *ccname; int blen = 0; // no BOM detection in a short file or in binary mode @@ -1115,7 +1115,7 @@ retry: ccname = NULL; } else { ccname = check_for_bom((char_u *)ptr, size, &blen, - fio_flags == FIO_UCSBOM ? FIO_ALL : get_fio_flags((char_u *)fenc)); + fio_flags == FIO_UCSBOM ? FIO_ALL : get_fio_flags(fenc)); } if (ccname != NULL) { // Remove BOM from the text @@ -1137,7 +1137,7 @@ retry: if (fenc_alloced) { xfree(fenc); } - fenc = (char *)ccname; + fenc = ccname; fenc_alloced = false; } // retry reading without getting new bytes or rewinding @@ -1193,7 +1193,7 @@ retry: if (from_size > 0) { // Some remaining characters, keep them for the next // round. - memmove(conv_rest, (char_u *)fromp, from_size); + memmove(conv_rest, fromp, from_size); conv_restlen = (int)from_size; } @@ -1394,7 +1394,7 @@ retry: // an incomplete character at the end though, the next // read() will get the next bytes, we'll check it // then. - l = utf_ptr2len_len(p, todo); + l = utf_ptr2len_len((char *)p, todo); if (l > todo && !incomplete_tail) { // Avoid retrying with a different encoding when // a truncated file is more likely, or attempting @@ -2566,7 +2566,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en #ifdef HAVE_ACL // For systems that support ACL: get the ACL from the original file. if (!newfile) { - acl = os_get_acl((char_u *)fname); + acl = os_get_acl(fname); } #endif @@ -2806,7 +2806,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en (double)file_info_old.stat.st_mtim.tv_sec); #endif #ifdef HAVE_ACL - os_set_acl((char_u *)backup, acl); + os_set_acl(backup, acl); #endif SET_ERRMSG(NULL); break; @@ -2980,7 +2980,7 @@ nobackup: // Latin1 to Unicode conversion. This is handled in buf_write_bytes(). // Prepare the flags for it and allocate bw_conv_buf when needed. if (converted) { - wb_flags = get_fio_flags((char_u *)fenc); + wb_flags = get_fio_flags(fenc); if (wb_flags & (FIO_UCS2 | FIO_UCS4 | FIO_UTF16 | FIO_UTF8)) { // Need to allocate a buffer to translate into. if (wb_flags & (FIO_UCS2 | FIO_UTF16 | FIO_UTF8)) { @@ -2999,7 +2999,7 @@ nobackup: #ifdef HAVE_ICONV // Use iconv() conversion when conversion is needed and it's not done // internally. - write_info.bw_iconv_fd = (iconv_t)my_iconv_open((char_u *)fenc, (char_u *)"utf-8"); + write_info.bw_iconv_fd = (iconv_t)my_iconv_open(fenc, "utf-8"); if (write_info.bw_iconv_fd != (iconv_t)-1) { // We're going to use iconv(), allocate a buffer to convert in. write_info.bw_conv_buflen = (size_t)bufsize * ICONV_MULT; @@ -3151,7 +3151,7 @@ restore_backup: } SET_ERRMSG(NULL); - write_info.bw_buf = (char_u *)buffer; + write_info.bw_buf = buffer; nchars = 0; // use "++bin", "++nobin" or 'binary' @@ -3164,7 +3164,7 @@ restore_backup: // Skip the BOM when appending and the file already existed, the BOM // only makes sense at the start of the file. if (buf->b_p_bomb && !write_bin && (!append || perm < 0)) { - write_info.bw_len = make_bom((char_u *)buffer, (char_u *)fenc); + write_info.bw_len = make_bom((char_u *)buffer, fenc); if (write_info.bw_len > 0) { // don't convert write_info.bw_flags = FIO_NOCONVERT | wb_flags; @@ -3342,7 +3342,7 @@ restore_backup: // Probably need to set the ACL before changing the user (can't set the // ACL on a file the user doesn't own). if (!backup_copy) { - os_set_acl((char_u *)wfname, acl); + os_set_acl(wfname, acl); } #endif @@ -3812,7 +3812,7 @@ static bool time_differs(const FileInfo *file_info, long mtime, long mtime_ns) F static int buf_write_bytes(struct bw_info *ip) { int wlen; - char_u *buf = ip->bw_buf; // data to write + char *buf = ip->bw_buf; // data to write int len = ip->bw_len; // length of data #ifdef HAS_BW_FLAGS int flags = ip->bw_flags; // extra flags @@ -3820,7 +3820,7 @@ static int buf_write_bytes(struct bw_info *ip) // Skip conversion when writing the BOM. if (!(flags & FIO_NOCONVERT)) { - char_u *p; + char *p; unsigned c; int n; @@ -3828,7 +3828,7 @@ static int buf_write_bytes(struct bw_info *ip) // Convert latin1 in the buffer to UTF-8 in the file. p = ip->bw_conv_buf; // translate to buffer for (wlen = 0; wlen < len; wlen++) { - p += utf_char2bytes(buf[wlen], (char *)p); + p += utf_char2bytes((uint8_t)buf[wlen], p); } buf = ip->bw_conv_buf; len = (int)(p - ip->bw_conv_buf); @@ -3852,7 +3852,7 @@ static int buf_write_bytes(struct bw_info *ip) l = len; } memmove(ip->bw_rest + ip->bw_restlen, buf, (size_t)l); - n = utf_ptr2len_len(ip->bw_rest, ip->bw_restlen + l); + n = utf_ptr2len_len((char *)ip->bw_rest, ip->bw_restlen + l); if (n > ip->bw_restlen + len) { // We have an incomplete byte sequence at the end to // be written. We can't convert it without the @@ -3892,9 +3892,9 @@ static int buf_write_bytes(struct bw_info *ip) break; } if (n > 1) { - c = (unsigned)utf_ptr2char((char *)buf + wlen); + c = (unsigned)utf_ptr2char(buf + wlen); } else { - c = buf[wlen]; + c = (uint8_t)buf[wlen]; } } @@ -3929,17 +3929,17 @@ static int buf_write_bytes(struct bw_info *ip) // the bytes of the current call. Use the end of the // conversion buffer for this. fromlen = (size_t)len + (size_t)ip->bw_restlen; - fp = (char *)ip->bw_conv_buf + ip->bw_conv_buflen - fromlen; + fp = ip->bw_conv_buf + ip->bw_conv_buflen - fromlen; memmove(fp, ip->bw_rest, (size_t)ip->bw_restlen); memmove(fp + ip->bw_restlen, buf, (size_t)len); from = fp; tolen = ip->bw_conv_buflen - fromlen; } else { - from = (const char *)buf; + from = buf; fromlen = (size_t)len; tolen = ip->bw_conv_buflen; } - to = (char *)ip->bw_conv_buf; + to = ip->bw_conv_buf; if (ip->bw_first) { size_t save_len = tolen; @@ -3950,7 +3950,7 @@ static int buf_write_bytes(struct bw_info *ip) // There is a bug in iconv() on Linux (which appears to be // wide-spread) which sets "to" to NULL and messes up "tolen". if (to == NULL) { - to = (char *)ip->bw_conv_buf; + to = ip->bw_conv_buf; tolen = save_len; } ip->bw_first = false; @@ -3971,7 +3971,7 @@ static int buf_write_bytes(struct bw_info *ip) ip->bw_restlen = (int)fromlen; buf = ip->bw_conv_buf; - len = (int)((char_u *)to - ip->bw_conv_buf); + len = (int)(to - ip->bw_conv_buf); } #endif } @@ -3991,9 +3991,9 @@ static int buf_write_bytes(struct bw_info *ip) /// @param flags FIO_ flags that specify which encoding to use /// /// @return true for an error, false when it's OK. -static bool ucs2bytes(unsigned c, char_u **pp, int flags) FUNC_ATTR_NONNULL_ALL +static bool ucs2bytes(unsigned c, char **pp, int flags) FUNC_ATTR_NONNULL_ALL { - char_u *p = *pp; + char_u *p = (char_u *)(*pp); bool error = false; int cc; @@ -4047,7 +4047,7 @@ static bool ucs2bytes(unsigned c, char_u **pp, int flags) FUNC_ATTR_NONNULL_ALL } } - *pp = p; + *pp = (char *)p; return error; } @@ -4070,8 +4070,8 @@ static bool need_conversion(const char *fenc) } else { // Ignore difference between "ansi" and "latin1", "ucs-4" and // "ucs-4be", etc. - enc_flags = get_fio_flags((char_u *)p_enc); - fenc_flags = get_fio_flags((char_u *)fenc); + enc_flags = get_fio_flags(p_enc); + fenc_flags = get_fio_flags(fenc); same_encoding = (enc_flags != 0 && fenc_flags == enc_flags); } if (same_encoding) { @@ -4089,14 +4089,14 @@ static bool need_conversion(const char *fenc) /// use 'encoding'. /// /// @param name string to check for encoding -static int get_fio_flags(const char_u *name) +static int get_fio_flags(const char *name) { int prop; if (*name == NUL) { - name = (char_u *)p_enc; + name = p_enc; } - prop = enc_canon_props((char *)name); + prop = enc_canon_props(name); if (prop & ENC_UNICODE) { if (prop & ENC_2BYTE) { if (prop & ENC_ENDIAN_L) { @@ -4130,7 +4130,7 @@ static int get_fio_flags(const char_u *name) /// /// @return the name of the encoding and set "*lenp" to the length or, /// NULL when no BOM found. -static char_u *check_for_bom(const char_u *p, long size, int *lenp, int flags) +static char *check_for_bom(const char_u *p, long size, int *lenp, int flags) { char *name = NULL; int len = 2; @@ -4167,16 +4167,16 @@ static char_u *check_for_bom(const char_u *p, long size, int *lenp, int flags) } *lenp = len; - return (char_u *)name; + return name; } /// Generate a BOM in "buf[4]" for encoding "name". /// /// @return the length of the BOM (zero when no BOM). -static int make_bom(char_u *buf, char_u *name) +static int make_bom(char_u *buf, char *name) { int flags; - char_u *p; + char *p; flags = get_fio_flags(name); @@ -4191,9 +4191,9 @@ static int make_bom(char_u *buf, char_u *name) buf[2] = 0xbf; return 3; } - p = buf; + p = (char *)buf; (void)ucs2bytes(0xfeff, &p, flags); - return (int)(p - buf); + return (int)((char_u *)p - buf); } /// Shorten filename of a buffer. @@ -4232,9 +4232,9 @@ void shorten_buf_fname(buf_T *buf, char *dirname, int force) /// Shorten filenames for all buffers. void shorten_fnames(int force) { - char_u dirname[MAXPATHL]; + char dirname[MAXPATHL]; - os_dirname((char *)dirname, MAXPATHL); + os_dirname(dirname, MAXPATHL); FOR_ALL_BUFFERS(buf) { shorten_buf_fname(buf, (char *)dirname, force); @@ -4597,7 +4597,7 @@ int vim_rename(const char *from, const char *to) perm = os_getperm(from); #ifdef HAVE_ACL // For systems that support ACL: get the ACL from the original file. - acl = os_get_acl((char_u *)from); + acl = os_get_acl(from); #endif fd_in = os_open((char *)from, O_RDONLY, 0); if (fd_in < 0) { @@ -4650,7 +4650,7 @@ int vim_rename(const char *from, const char *to) os_setperm((const char *)to, perm); #endif #ifdef HAVE_ACL - os_set_acl((char_u *)to, acl); + os_set_acl(to, acl); os_free_acl(acl); #endif if (errmsg != NULL) { diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 43b1d780be..7da8d12f4b 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -774,7 +774,7 @@ EXTERN bool g_tag_at_cursor INIT(= false); // whether the tag command comes EXTERN int replace_offset INIT(= 0); // offset for replace_push() -EXTERN char_u *escape_chars INIT(= (char_u *)" \t\\\"|"); // need backslash in cmd line +EXTERN char *escape_chars INIT(= " \t\\\"|"); // need backslash in cmd line EXTERN int keep_help_flag INIT(= false); // doing :ta from help file @@ -825,7 +825,7 @@ 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 -EXTERN char_u no_lines_msg[] INIT(= N_("--No lines in buffer--")); +EXTERN char no_lines_msg[] INIT(= N_("--No lines in buffer--")); // When ":global" is used to number of substitutions and changed lines is // accumulated until it's finished. diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index f805d99d4b..851e70caca 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -88,7 +88,7 @@ void hash_clear_all(hashtab_T *ht, unsigned int off) /// is changed in any way. hashitem_T *hash_find(const hashtab_T *const ht, const char *const key) { - return hash_lookup(ht, key, strlen(key), hash_hash((char_u *)key)); + return hash_lookup(ht, key, strlen(key), hash_hash(key)); } /// Like hash_find, but key is not NUL-terminated @@ -204,13 +204,13 @@ void hash_debug_results(void) /// FAIL if key already present int hash_add(hashtab_T *ht, char *key) { - hash_T hash = hash_hash((char_u *)key); + hash_T hash = hash_hash(key); hashitem_T *hi = hash_lookup(ht, key, strlen(key), hash); if (!HASHITEM_EMPTY(hi)) { internal_error("hash_add()"); return FAIL; } - hash_add_item(ht, hi, (char_u *)key, hash); + hash_add_item(ht, hi, key, hash); return OK; } @@ -221,14 +221,14 @@ int hash_add(hashtab_T *ht, char *key) /// @param key Pointer to the key for the new item. The key has to be contained /// in the new item (@see hashitem_T). Must not be NULL. /// @param hash The precomputed hash value for the key. -void hash_add_item(hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash) +void hash_add_item(hashtab_T *ht, hashitem_T *hi, char *key, hash_T hash) { ht->ht_used++; ht->ht_changed++; if (hi->hi_key == NULL) { ht->ht_filled++; } - hi->hi_key = (char *)key; + hi->hi_key = key; hi->hi_hash = hash; // When the space gets low may resize the array. @@ -406,9 +406,9 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems) /// run a script that uses hashtables a lot. Vim will then print statistics /// when exiting. Try that with the current hash algorithm and yours. The /// lower the percentage the better. -hash_T hash_hash(const char_u *key) +hash_T hash_hash(const char *key) { - hash_T hash = *key; + hash_T hash = (uint8_t)(*key); if (hash == 0) { return (hash_T)0; @@ -416,7 +416,7 @@ hash_T hash_hash(const char_u *key) // A simplistic algorithm that appears to do very well. // Suggested by George Reilly. - const uint8_t *p = key + 1; + const uint8_t *p = (uint8_t *)key + 1; while (*p != NUL) { HASH_CYCLE_BODY(hash, p); } diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 2a81b4deb0..5f7e41e6e0 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -77,22 +77,20 @@ static int hl_attr_table[] = /// The ID of a highlight group is also called group ID. It is the index in /// the highlight_ga array PLUS ONE. typedef struct { - char_u *sg_name; ///< highlight group name - char *sg_name_u; ///< uppercase of sg_name + char *sg_name; ///< highlight group name + char *sg_name_u; ///< uppercase of sg_name bool sg_cleared; ///< "hi clear" was used int sg_attr; ///< Screen attr @see ATTR_ENTRY int sg_link; ///< link to this highlight group ID int sg_deflink; ///< default link; restored in highlight_clear() int sg_set; ///< combination of flags in \ref SG_SET sctx_T sg_deflink_sctx; ///< script where the default link was set - sctx_T sg_script_ctx; ///< script in which the group was last set - // for terminal UIs + sctx_T sg_script_ctx; ///< script in which the group was last set for terminal UIs int sg_cterm; ///< "cterm=" highlighting attr ///< (combination of \ref HlAttrFlags) int sg_cterm_fg; ///< terminal fg color number + 1 int sg_cterm_bg; ///< terminal bg color number + 1 - bool sg_cterm_bold; ///< bold attr was set for light color - // for RGB UIs + bool sg_cterm_bold; ///< bold attr was set for light color for RGB UIs int sg_gui; ///< "gui=" highlighting attributes ///< (combination of \ref HlAttrFlags) RgbValue sg_rgb_fg; ///< RGB foreground color @@ -571,7 +569,7 @@ int highlight_num_groups(void) } /// Returns the name of a highlight group. -char_u *highlight_group_name(int id) +char *highlight_group_name(int id) { return hl_table[id].sg_name; } @@ -658,7 +656,7 @@ void init_highlight(bool both, bool reset) /// @return OK for success, FAIL for failure. int load_colors(char *name) { - char_u *buf; + char *buf; int retval = FAIL; static bool recursive = false; @@ -673,11 +671,11 @@ int load_colors(char *name) size_t buflen = strlen(name) + 12; buf = xmalloc(buflen); apply_autocmds(EVENT_COLORSCHEMEPRE, name, curbuf->b_fname, false, curbuf); - snprintf((char *)buf, buflen, "colors/%s.vim", name); - retval = source_runtime((char *)buf, DIP_START + DIP_OPT); + snprintf(buf, buflen, "colors/%s.vim", name); + retval = source_runtime(buf, DIP_START + DIP_OPT); if (retval == FAIL) { - snprintf((char *)buf, buflen, "colors/%s.lua", name); - retval = source_runtime((char *)buf, DIP_START + DIP_OPT); + snprintf(buf, buflen, "colors/%s.lua", name); + retval = source_runtime(buf, DIP_START + DIP_OPT); } xfree(buf); if (retval == OK) { @@ -1471,7 +1469,7 @@ static void highlight_list_one(const int id) const HlGroup *sgp = &hl_table[id - 1]; // index is ID minus one bool didh = false; - if (message_filtered((char *)sgp->sg_name)) { + if (message_filtered(sgp->sg_name)) { return; } @@ -1505,7 +1503,7 @@ static void highlight_list_one(const int id) didh = true; msg_puts_attr("links to", HL_ATTR(HLF_D)); msg_putchar(' '); - msg_outtrans((char *)hl_table[hl_table[id - 1].sg_link - 1].sg_name); + msg_outtrans(hl_table[hl_table[id - 1].sg_link - 1].sg_name); } if (!didh) { @@ -1527,7 +1525,7 @@ Dictionary get_global_hl_defs(Arena *arena) hlattrs2dict(&attrs, syn_attr2entry(h->sg_attr), true); } else if (h->sg_link > 0) { attrs = arena_dict(arena, 1); - char *link = (char *)hl_table[h->sg_link - 1].sg_name; + char *link = hl_table[h->sg_link - 1].sg_name; PUT_C(attrs, "link", STRING_OBJ(cstr_as_string(link))); } PUT_C(rv, (char *)h->sg_name, DICTIONARY_OBJ(attrs)); @@ -1702,7 +1700,7 @@ bool syn_list_header(const bool did_header, const int outlen, const int id, bool if (got_int) { return true; } - msg_outtrans((char *)hl_table[id - 1].sg_name); + msg_outtrans(hl_table[id - 1].sg_name); name_col = msg_col; endcol = 15; } else if ((ui_has(kUIMessages) || msg_silent) && !force_newline) { @@ -1804,10 +1802,10 @@ int syn_name2id_len(const char *name, size_t len) /// Lookup a highlight group name and return its attributes. /// Return zero if not found. -int syn_name2attr(const char_u *name) +int syn_name2attr(const char *name) FUNC_ATTR_NONNULL_ALL { - int id = syn_name2id((char *)name); + int id = syn_name2id(name); if (id != 0) { return syn_id2attr(id); @@ -1823,10 +1821,10 @@ int highlight_exists(const char *name) /// Return the name of highlight group "id". /// When not a valid ID return an empty string. -char_u *syn_id2name(int id) +char *syn_id2name(int id) { if (id <= 0 || id > highlight_ga.ga_len) { - return (char_u *)""; + return ""; } return hl_table[id - 1].sg_name; } @@ -1896,7 +1894,7 @@ static int syn_add_group(const char *name, size_t len) // Append another syntax_highlight entry. HlGroup *hlgp = GA_APPEND_VIA_PTR(HlGroup, &highlight_ga); CLEAR_POINTER(hlgp); - hlgp->sg_name = (char_u *)arena_memdupz(&highlight_arena, name, len); + hlgp->sg_name = arena_memdupz(&highlight_arena, name, len); hlgp->sg_rgb_bg = -1; hlgp->sg_rgb_fg = -1; hlgp->sg_rgb_sp = -1; diff --git a/src/nvim/indent.c b/src/nvim/indent.c index ed4005d139..2d1b5efb0a 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -388,7 +388,7 @@ int get_indent_buf(buf_T *buf, linenr_T lnum) /// Count the size (in window cells) of the indent in line "ptr", with /// 'tabstop' at "ts". /// If @param list is true, count only screen size for tabs. -int get_indent_str(const char_u *ptr, int ts, bool list) +int get_indent_str(const char *ptr, int ts, bool list) FUNC_ATTR_NONNULL_ALL { int count = 0; @@ -402,7 +402,7 @@ int get_indent_str(const char_u *ptr, int ts, bool list) } else { // In list mode, when tab is not set, count screen char width // for Tab, displays: ^I - count += ptr2cells((char *)ptr); + count += ptr2cells(ptr); } } else if (*ptr == ' ') { // Count a space for one. @@ -805,7 +805,7 @@ int get_breakindent_win(win_T *wp, char *line) { static int prev_indent = 0; // Cached indent value. static long prev_ts = 0L; // Cached tabstop value. - static const char_u *prev_line = NULL; // cached pointer to line. + static const char *prev_line = NULL; // cached pointer to line. static varnumber_T prev_tick = 0; // Changedtick of cached value. static long *prev_vts = NULL; // Cached vartabs values. static int prev_list = 0; // cached list value @@ -822,12 +822,12 @@ int get_breakindent_win(win_T *wp, char *line) // - 'tabstop' changed // - 'briopt_list changed' changed or // - 'formatlistpattern' changed - if (prev_line != (char_u *)line || prev_ts != wp->w_buffer->b_p_ts + if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts || prev_tick != buf_get_changedtick(wp->w_buffer) || prev_listopt != wp->w_briopt_list || (prev_flp == NULL || (strcmp(prev_flp, get_flp_value(wp->w_buffer)) != 0)) || prev_vts != wp->w_buffer->b_p_vts_array) { - prev_line = (char_u *)line; + prev_line = line; prev_ts = wp->w_buffer->b_p_ts; prev_tick = buf_get_changedtick(wp->w_buffer); prev_vts = wp->w_buffer->b_p_vts_array; @@ -881,7 +881,7 @@ int get_breakindent_win(win_T *wp, char *line) // indent minus the length of the showbreak string if (wp->w_briopt_sbr) { - bri -= vim_strsize((char *)get_showbreak_value(wp)); + bri -= vim_strsize(get_showbreak_value(wp)); } // never indent past left window margin @@ -903,10 +903,10 @@ int get_breakindent_win(win_T *wp, char *line) // the line. int inindent(int extra) { - char_u *ptr; + char *ptr; colnr_T col; - for (col = 0, ptr = (char_u *)get_cursor_line_ptr(); ascii_iswhite(*ptr); col++) { + for (col = 0, ptr = get_cursor_line_ptr(); ascii_iswhite(*ptr); col++) { ptr++; } @@ -1189,7 +1189,7 @@ int get_lisp_indent(void) { pos_T *pos, realpos, paren; int amount; - char_u *that; + char *that; colnr_T col; colnr_T firsttry; int parencount; @@ -1224,7 +1224,7 @@ int get_lisp_indent(void) continue; } - for (that = (char_u *)get_cursor_line_ptr(); *that != NUL; that++) { + for (that = get_cursor_line_ptr(); *that != NUL; that++) { if (*that == ';') { while (*(that + 1) != NUL) { that++; @@ -1274,20 +1274,20 @@ int get_lisp_indent(void) curwin->w_cursor.col = pos->col; col = pos->col; - that = (char_u *)get_cursor_line_ptr(); + that = get_cursor_line_ptr(); if (vi_lisp && (get_indent() == 0)) { amount = 2; } else { - char_u *line = that; + char *line = that; chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, pos->lnum, 0, (char *)line, (char *)line); + init_chartabsize_arg(&cts, curwin, pos->lnum, 0, line, line); while (*cts.cts_ptr != NUL && col > 0) { cts.cts_vcol += lbr_chartabsize_adv(&cts); col--; } amount = cts.cts_vcol; - that = (char_u *)cts.cts_ptr; + that = cts.cts_ptr; clear_chartabsize_arg(&cts); // Some keywords require "body" indenting rules (the @@ -1295,7 +1295,7 @@ int get_lisp_indent(void) // (let ((a 1)) instead (let ((a 1)) // (...)) of (...)) if (!vi_lisp && ((*that == '(') || (*that == '[')) - && lisp_match((char *)that + 1)) { + && lisp_match(that + 1)) { amount += 2; } else { if (*that != NUL) { @@ -1305,12 +1305,12 @@ int get_lisp_indent(void) firsttry = amount; init_chartabsize_arg(&cts, curwin, (colnr_T)(that - line), - amount, (char *)line, (char *)that); + amount, line, that); while (ascii_iswhite(*cts.cts_ptr)) { cts.cts_vcol += lbr_chartabsize(&cts); cts.cts_ptr++; } - that = (char_u *)cts.cts_ptr; + that = cts.cts_ptr; amount = cts.cts_vcol; clear_chartabsize_arg(&cts); @@ -1326,9 +1326,10 @@ int get_lisp_indent(void) quotecount = 0; init_chartabsize_arg(&cts, curwin, - (colnr_T)(that - line), amount, (char *)line, (char *)that); + (colnr_T)(that - line), amount, line, that); if (vi_lisp || ((*that != '"') && (*that != '\'') - && (*that != '#') && ((*that < '0') || (*that > '9')))) { + && (*that != '#') + && (((uint8_t)(*that) < '0') || ((uint8_t)(*that) > '9')))) { while (*cts.cts_ptr && (!ascii_iswhite(*cts.cts_ptr) || quotecount || parencount) && (!((*cts.cts_ptr == '(' || *cts.cts_ptr == '[') @@ -1354,7 +1355,7 @@ int get_lisp_indent(void) cts.cts_vcol += lbr_chartabsize(&cts); cts.cts_ptr++; } - that = (char_u *)cts.cts_ptr; + that = cts.cts_ptr; amount = cts.cts_vcol; clear_chartabsize_arg(&cts); @@ -1377,7 +1378,7 @@ static int lisp_match(char *p) { char buf[LSIZE]; int len; - char *word = (char *)(*curbuf->b_p_lw != NUL ? (char_u *)curbuf->b_p_lw : p_lispwords); + char *word = *curbuf->b_p_lw != NUL ? curbuf->b_p_lw : p_lispwords; while (*word != NUL) { (void)copy_option_part(&word, buf, LSIZE, ","); diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 38fb7a2873..a8af8ec966 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2997,7 +2997,7 @@ static void get_next_filename_completion(void) #ifdef BACKSLASH_IN_FILENAME if (curbuf->b_p_csl[0] != NUL) { for (int i = 0; i < num_matches; i++) { - char_u *ptr = matches[i]; + char *ptr = matches[i]; while (*ptr != NUL) { if (curbuf->b_p_csl[0] == 's' && *ptr == '\\') { *ptr = '/'; diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index a4228fcc7e..552dec6bf8 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -541,7 +541,7 @@ char_u *get_special_key_name(int c, int modifiers) } else if (vim_isprintc(c)) { string[idx++] = (char_u)c; } else { - s = transchar(c); + s = (char_u *)transchar(c); while (*s) { string[idx++] = *s++; } @@ -572,7 +572,7 @@ char_u *get_special_key_name(int c, int modifiers) /// @param[out] did_simplify found <C-H>, etc. /// /// @return Number of characters added to dst, zero for no match. -unsigned int trans_special(const char **const srcp, const size_t src_len, char_u *const dst, +unsigned int trans_special(const char **const srcp, const size_t src_len, char *const dst, const int flags, const bool escape_ks, bool *const did_simplify) FUNC_ATTR_NONNULL_ARG(1, 3) FUNC_ATTR_WARN_UNUSED_RESULT { @@ -582,7 +582,7 @@ unsigned int trans_special(const char **const srcp, const size_t src_len, char_u return 0; } - return special_to_buf(key, modifiers, escape_ks, dst); + return special_to_buf(key, modifiers, escape_ks, (char_u *)dst); } /// Put the character sequence for "key" with "modifiers" into "dst" and return @@ -944,7 +944,7 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co } } - slen = trans_special(&src, (size_t)(end - src) + 1, (char_u *)result + dlen, + slen = trans_special(&src, (size_t)(end - src) + 1, result + dlen, FSK_KEYCODE | ((flags & REPTERM_NO_SIMPLIFY) ? 0 : FSK_SIMPLIFY), true, did_simplify); if (slen) { @@ -1059,8 +1059,8 @@ char *vim_strsave_escape_ks(char *p) // Need a buffer to hold up to three times as much. Four in case of an // illegal utf-8 byte: // 0xc0 -> 0xc3 - 0x80 -> 0xc3 K_SPECIAL KS_SPECIAL KE_FILLER - char_u *res = xmalloc(strlen(p) * 4 + 1); - char_u *d = res; + char *res = xmalloc(strlen(p) * 4 + 1); + char_u *d = (char_u *)res; for (char_u *s = (char_u *)p; *s != NUL;) { if (s[0] == K_SPECIAL && s[1] != NUL && s[2] != NUL) { // Copy special key unmodified. @@ -1076,7 +1076,7 @@ char *vim_strsave_escape_ks(char *p) } *d = NUL; - return (char *)res; + return res; } /// Remove escaping from K_SPECIAL characters. Reverse of diff --git a/src/nvim/locale.c b/src/nvim/locale.c index 6322271073..c3cfd3bedb 100644 --- a/src/nvim/locale.c +++ b/src/nvim/locale.c @@ -294,7 +294,7 @@ static char **find_locales(void) if (locale_a == NULL) { return NULL; } - ga_init(&locales_ga, sizeof(char_u *), 20); + ga_init(&locales_ga, sizeof(char *), 20); // Transform locale_a string where each locale is separated by "\n" // into an array of locale strings. @@ -308,7 +308,7 @@ static char **find_locales(void) xfree(locale_a); // Guarantee that .ga_data is NULL terminated ga_grow(&locales_ga, 1); - ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; + ((char **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; return locales_ga.ga_data; } # endif diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c index 3c129fe7ce..6160b84485 100644 --- a/src/nvim/lua/converter.c +++ b/src/nvim/lua/converter.c @@ -391,7 +391,7 @@ nlua_pop_typval_table_processing_end: case LUA_TFUNCTION: { LuaRef func = nlua_ref_global(lstate, -1); - char *name = (char *)register_luafunc(func); + char *name = register_luafunc(func); cur.tv->v_type = VAR_FUNC; cur.tv->vval.v_string = xstrdup(name); diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index f23310304f..7006c1dc4e 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1950,7 +1950,7 @@ char_u *nlua_register_table_as_callable(const typval_T *const arg) LuaRef func = nlua_ref_global(lstate, -1); - char_u *name = register_luafunc(func); + char_u *name = (char_u *)register_luafunc(func); lua_pop(lstate, 1); // [] assert(top == lua_gettop(lstate)); diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index dac96790d7..8b74418753 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -40,17 +40,17 @@ # include "lua/stdlib.c.generated.h" #endif -static int regex_match(lua_State *lstate, regprog_T **prog, char_u *str) +static int regex_match(lua_State *lstate, regprog_T **prog, char *str) { regmatch_T rm; rm.regprog = *prog; rm.rm_ic = false; - bool match = vim_regexec(&rm, (char *)str, 0); + bool match = vim_regexec(&rm, str, 0); *prog = rm.regprog; if (match) { - lua_pushinteger(lstate, (lua_Integer)(rm.startp[0] - (char *)str)); - lua_pushinteger(lstate, (lua_Integer)(rm.endp[0] - (char *)str)); + lua_pushinteger(lstate, (lua_Integer)(rm.startp[0] - str)); + lua_pushinteger(lstate, (lua_Integer)(rm.endp[0] - str)); return 2; } return 0; @@ -60,7 +60,7 @@ static int regex_match_str(lua_State *lstate) { regprog_T **prog = regex_check(lstate); const char *str = luaL_checkstring(lstate, 2); - int nret = regex_match(lstate, prog, (char_u *)str); + int nret = regex_match(lstate, prog, (char *)str); if (!*prog) { return luaL_error(lstate, "regex: internal error"); @@ -116,7 +116,7 @@ static int regex_match_line(lua_State *lstate) line[end] = NUL; } - int nret = regex_match(lstate, prog, (char_u *)line + start); + int nret = regex_match(lstate, prog, line + start); if (end >= 0) { line[end] = save; @@ -198,7 +198,7 @@ static int nlua_str_utf_pos(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL size_t idx = 1; size_t clen; for (size_t i = 0; i < s1_len && s1[i] != NUL; i += clen) { - clen = (size_t)utf_ptr2len_len((const char_u *)(s1) + i, (int)(s1_len - i)); + clen = (size_t)utf_ptr2len_len(s1 + i, (int)(s1_len - i)); lua_pushinteger(lstate, (long)i + 1); lua_rawseti(lstate, -2, (int)idx); idx++; @@ -266,8 +266,7 @@ int nlua_str_byteindex(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL use_utf16 = lua_toboolean(lstate, 3); } - ssize_t byteidx = mb_utf_index_to_bytes((const char_u *)s1, s1_len, - (size_t)idx, use_utf16); + ssize_t byteidx = mb_utf_index_to_bytes(s1, s1_len, (size_t)idx, use_utf16); if (byteidx == -1) { return luaL_error(lstate, "index out of range"); } @@ -503,14 +502,14 @@ static int nlua_iconv(lua_State *lstate) size_t str_len = 0; const char *str = lua_tolstring(lstate, 1, &str_len); - char_u *from = (char_u *)enc_canonize(enc_skip((char *)lua_tolstring(lstate, 2, NULL))); - char_u *to = (char_u *)enc_canonize(enc_skip((char *)lua_tolstring(lstate, 3, NULL))); + char *from = enc_canonize(enc_skip((char *)lua_tolstring(lstate, 2, NULL))); + char *to = enc_canonize(enc_skip((char *)lua_tolstring(lstate, 3, NULL))); vimconv_T vimconv; vimconv.vc_type = CONV_NONE; - convert_setup_ext(&vimconv, (char *)from, false, (char *)to, false); + convert_setup_ext(&vimconv, from, false, to, false); - char_u *ret = (char_u *)string_convert(&vimconv, (char *)str, &str_len); + char *ret = string_convert(&vimconv, (char *)str, &str_len); convert_setup(&vimconv, NULL, NULL); @@ -520,7 +519,7 @@ static int nlua_iconv(lua_State *lstate) if (ret == NULL) { lua_pushnil(lstate); } else { - lua_pushlstring(lstate, (char *)ret, str_len); + lua_pushlstring(lstate, ret, str_len); xfree(ret); } diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 29c6bb6723..2a943db5d5 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1851,9 +1851,9 @@ int makemap(FILE *fd, buf_T *buf) } if (putc(' ', fd) < 0 - || put_escstr(fd, (char_u *)mp->m_keys, 0) == FAIL + || put_escstr(fd, mp->m_keys, 0) == FAIL || putc(' ', fd) < 0 - || put_escstr(fd, (char_u *)mp->m_str, 1) == FAIL + || put_escstr(fd, mp->m_str, 1) == FAIL || put_eol(fd) < 0) { return FAIL; } @@ -1879,9 +1879,9 @@ int makemap(FILE *fd, buf_T *buf) // "what": 0 for :map lhs, 1 for :map rhs, 2 for :set // // return FAIL for failure, OK otherwise -int put_escstr(FILE *fd, char_u *strstart, int what) +int put_escstr(FILE *fd, char *strstart, int what) { - char_u *str = strstart; + char_u *str = (char_u *)strstart; int c; // :map xx <Nop> @@ -1958,7 +1958,7 @@ int put_escstr(FILE *fd, char_u *strstart, int what) } } else if (c < ' ' || c > '~' || c == '|' || (what == 0 && c == ' ') - || (what == 1 && str == strstart && c == ' ') + || (what == 1 && str == (char_u *)strstart && c == ' ') || (what != 2 && c == '<')) { if (putc(Ctrl_V, fd) < 0) { return FAIL; diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index b5274b9695..eafbf0b17a 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -540,7 +540,7 @@ int utf_ptr2cells_len(const char *p, int size) // Need to convert to a wide character. if (size > 0 && (uint8_t)(*p) >= 0x80) { - if (utf_ptr2len_len((char_u *)p, size) < utf8len_tab[(uint8_t)(*p)]) { + if (utf_ptr2len_len(p, size) < utf8len_tab[(uint8_t)(*p)]) { return 1; // truncated } c = utf_ptr2char((char *)p); @@ -584,9 +584,9 @@ size_t mb_string2cells_len(const char *str, size_t size) { size_t clen = 0; - for (const char_u *p = (char_u *)str; *p != NUL && p < (char_u *)str + size; - p += utfc_ptr2len_len((char *)p, (int)size + (int)(p - (char_u *)str))) { - clen += (size_t)utf_ptr2cells((char *)p); + for (const char *p = str; *p != NUL && p < str + size; + p += utfc_ptr2len_len(p, (int)size + (int)(p - str))) { + clen += (size_t)utf_ptr2cells(p); } return clen; @@ -785,7 +785,7 @@ int utfc_ptr2char_len(const char *p, int *pcc, int maxlen) int i = 0; - int len = utf_ptr2len_len((char_u *)p, maxlen); + int len = utf_ptr2len_len(p, maxlen); // Is it safe to use utf_ptr2char()? bool safe = len > 1 && len <= maxlen; int c = safe ? utf_ptr2char(p) : (uint8_t)(*p); @@ -793,7 +793,7 @@ int utfc_ptr2char_len(const char *p, int *pcc, int maxlen) // Only accept a composing char when the first char isn't illegal. if ((safe || c < 0x80) && len < maxlen && (uint8_t)p[len] >= 0x80) { for (; i < MAX_MCO; i++) { - int len_cc = utf_ptr2len_len((char_u *)p + len, maxlen - len); + int len_cc = utf_ptr2len_len(p + len, maxlen - len); safe = len_cc > 1 && len_cc <= maxlen - len; if (!safe || (pcc[i] = utf_ptr2char(p + len)) < 0x80 || !(i == 0 ? utf_composinglike(p, p + len) : utf_iscomposing(pcc[i]))) { @@ -848,13 +848,13 @@ int utf_byte2len(int b) // Returns 1 for an illegal byte sequence (also in incomplete byte seq.). // Returns number > "size" for an incomplete byte sequence. // Never returns zero. -int utf_ptr2len_len(const char_u *p, int size) +int utf_ptr2len_len(const char *p, int size) { int len; int i; int m; - len = utf8len_tab[*p]; + len = utf8len_tab[(uint8_t)(*p)]; if (len == 1) { return 1; // NUL, ascii or illegal lead byte } @@ -925,7 +925,7 @@ int utfc_ptr2len_len(const char *p, int size) } // Skip over first UTF-8 char, stopping at a NUL byte. - len = utf_ptr2len_len((char_u *)p, size); + len = utf_ptr2len_len(p, size); // Check for illegal byte and incomplete byte sequence. if ((len == 1 && (uint8_t)p[0] >= 0x80) || len > size) { @@ -944,7 +944,7 @@ int utfc_ptr2len_len(const char *p, int size) // Next character length should not go beyond size to ensure that // utf_composinglike(...) does not read beyond size. - len_next_char = utf_ptr2len_len((char_u *)p + len, size - len); + len_next_char = utf_ptr2len_len(p + len, size - len); if (len_next_char > size - len) { break; } @@ -1462,7 +1462,7 @@ void mb_utflen(const char *s, size_t len, size_t *codepoints, size_t *codeunits) size_t count = 0, extra = 0; size_t clen; for (size_t i = 0; i < len; i += clen) { - clen = (size_t)utf_ptr2len_len((char_u *)s + i, (int)(len - i)); + clen = (size_t)utf_ptr2len_len(s + i, (int)(len - i)); // NB: gets the byte value of invalid sequence bytes. // we only care whether the char fits in the BMP or not int c = (clen > 1) ? utf_ptr2char(s + i) : (uint8_t)s[i]; @@ -1475,7 +1475,7 @@ void mb_utflen(const char *s, size_t len, size_t *codepoints, size_t *codeunits) *codeunits += count + extra; } -ssize_t mb_utf_index_to_bytes(const char_u *s, size_t len, size_t index, bool use_utf16_units) +ssize_t mb_utf_index_to_bytes(const char *s, size_t len, size_t index, bool use_utf16_units) FUNC_ATTR_NONNULL_ALL { size_t count = 0; @@ -1487,7 +1487,7 @@ ssize_t mb_utf_index_to_bytes(const char_u *s, size_t len, size_t index, bool us clen = (size_t)utf_ptr2len_len(s + i, (int)(len - i)); // NB: gets the byte value of invalid sequence bytes. // we only care whether the char fits in the BMP or not - int c = (clen > 1) ? utf_ptr2char((char *)s + i) : s[i]; + int c = (clen > 1) ? utf_ptr2char(s + i) : (uint8_t)s[i]; count++; if (use_utf16_units && c > 0xFFFF) { count++; @@ -1787,7 +1787,7 @@ void mb_copy_char(const char **const fp, char **const tp) /// Return the offset from "p_in" to the first byte of a character. When "p_in" is /// at the start of a character 0 is returned, otherwise the offset to the next /// character. Can start anywhere in a stream of bytes. -int mb_off_next(const char_u *base, const char *p_in) +int mb_off_next(const char *base, const char *p_in) { const uint8_t *p = (uint8_t *)p_in; int i; @@ -1801,7 +1801,7 @@ int mb_off_next(const char_u *base, const char *p_in) for (i = 0; (p[i] & 0xc0) == 0x80; i++) {} if (i > 0) { // Check for illegal sequence. - for (j = 0; p - j > base; j++) { + for (j = 0; p - j > (uint8_t *)base; j++) { if ((p[-j] & 0xc0) != 0x80) { break; } @@ -2265,7 +2265,7 @@ enc_locale_copy_enc: // versions). // Returns (void *)-1 if failed. // (should return iconv_t, but that causes problems with prototypes). -void *my_iconv_open(char_u *to, char_u *from) +void *my_iconv_open(char *to, char *from) { iconv_t fd; # define ICONV_TESTLEN 400 @@ -2277,7 +2277,7 @@ void *my_iconv_open(char_u *to, char_u *from) if (iconv_working == kBroken) { return (void *)-1; // detected a broken iconv() previously } - fd = iconv_open(enc_skip((char *)to), enc_skip((char *)from)); + fd = iconv_open(enc_skip(to), enc_skip(from)); if (fd != (iconv_t)-1 && iconv_working == kUnknown) { // Do a dummy iconv() call to check if it actually works. There is a @@ -2452,8 +2452,8 @@ int convert_setup_ext(vimconv_T *vcp, char *from, bool from_unicode_is_utf8, cha #ifdef HAVE_ICONV else { // NOLINT(readability/braces) // Use iconv() for conversion. - vcp->vc_fd = (iconv_t)my_iconv_open(to_is_utf8 ? (char_u *)"utf-8" : (char_u *)to, - from_is_utf8 ? (char_u *)"utf-8" : (char_u *)from); + vcp->vc_fd = (iconv_t)my_iconv_open(to_is_utf8 ? "utf-8" : to, + from_is_utf8 ? "utf-8" : from); if (vcp->vc_fd != (iconv_t)-1) { vcp->vc_type = CONV_ICONV; vcp->vc_factor = 4; // could be longer too... @@ -2553,7 +2553,7 @@ char_u *string_convert_ext(const vimconv_T *const vcp, char_u *ptr, size_t *lenp retval = xmalloc(len + 1); d = retval; for (size_t i = 0; i < len; i++) { - l = utf_ptr2len_len(ptr + i, (int)(len - i)); + l = utf_ptr2len_len((char *)ptr + i, (int)(len - i)); if (l == 0) { *d++ = NUL; } else if (l == 1) { @@ -2795,6 +2795,21 @@ void f_setcellwidths(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) redraw_all_later(UPD_NOT_VALID); } +/// "getcellwidths()" function +void f_getcellwidths(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) +{ + tv_list_alloc_ret(rettv, (ptrdiff_t)cw_table_size); + + for (size_t i = 0; i < cw_table_size; i++) { + list_T *entry = tv_list_alloc(3); + tv_list_append_number(entry, (varnumber_T)cw_table[i].first); + tv_list_append_number(entry, (varnumber_T)cw_table[i].last); + tv_list_append_number(entry, (varnumber_T)cw_table[i].width); + + tv_list_append_list(rettv->vval.v_list, entry); + } +} + void f_charclass(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { if (tv_check_for_string_arg(argvars, 0) == FAIL diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 759920c4ec..10a8195e7a 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -757,7 +757,7 @@ void ml_recover(bool checkext) directly = false; // count the number of matching swap files - len = recover_names((char_u *)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; @@ -767,7 +767,7 @@ void ml_recover(bool checkext) i = 1; } else { // several swap files found, choose // list the names of the swap files - (void)recover_names((char_u *)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); @@ -776,7 +776,7 @@ void ml_recover(bool checkext) } } // get the swap file name that will be used - (void)recover_names((char_u *)fname, false, i, &fname_used); + (void)recover_names(fname, false, i, &fname_used); } if (fname_used == NULL) { goto theend; // user chose invalid number. @@ -1201,24 +1201,24 @@ theend: /// @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 **fname_out) +int recover_names(char *fname, int list, int nr, char **fname_out) { int num_names; char *(names[6]); - char_u *tail; + char *tail; char *p; int file_count = 0; char **files; - char_u *fname_res = NULL; + char *fname_res = NULL; #ifdef HAVE_READLINK - char_u fname_buf[MAXPATHL]; + char fname_buf[MAXPATHL]; #endif if (fname != NULL) { #ifdef HAVE_READLINK // Expand symlink in the file name, because the swap file is created // with the actual file instead of with the symlink. - if (resolve_symlink((char *)fname, (char *)fname_buf) == OK) { + if (resolve_symlink(fname, fname_buf) == OK) { fname_res = fname_buf; } else #endif @@ -1250,7 +1250,7 @@ int recover_names(char_u *fname, int list, int nr, char **fname_out) names[2] = xstrdup(".sw?"); num_names = 3; } else { - num_names = recov_file_names(names, (char *)fname_res, true); + num_names = recov_file_names(names, fname_res, true); } } else { // check directory dir_name if (fname == NULL) { @@ -1267,13 +1267,12 @@ int recover_names(char_u *fname, int list, int nr, char **fname_out) && len > 1 && p[-1] == p[-2]) { // Ends with '//', Use Full path for swap name - tail = (char_u *)make_percent_swname(dir_name, - (char *)fname_res); + tail = make_percent_swname(dir_name, fname_res); } else { - tail = (char_u *)path_tail((char *)fname_res); - tail = (char_u *)concat_fnames(dir_name, (char *)tail, true); + tail = path_tail(fname_res); + tail = concat_fnames(dir_name, tail, true); } - num_names = recov_file_names(names, (char *)tail, false); + num_names = recov_file_names(names, tail, false); xfree(tail); } } @@ -1290,11 +1289,11 @@ int recover_names(char_u *fname, int list, int nr, char **fname_out) // not able to execute the shell). // Try finding a swap file by simply adding ".swp" to the file name. if (*dirp == NUL && file_count + num_files == 0 && fname != NULL) { - char_u *swapname = (char_u *)modname((char *)fname_res, ".swp", true); + char *swapname = modname(fname_res, ".swp", true); if (swapname != NULL) { - if (os_path_exists((char *)swapname)) { - files = xmalloc(sizeof(char_u *)); - files[0] = (char *)swapname; + if (os_path_exists(swapname)) { + files = xmalloc(sizeof(char *)); + files[0] = swapname; swapname = NULL; num_files = 1; } @@ -1877,7 +1876,7 @@ int ml_append(linenr_T lnum, char *line, colnr_T len, bool newfile) /// @param line text of the new line /// @param len length of new line, including NUL, or 0 /// @param newfile flag, see above -int ml_append_buf(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, bool newfile) +int ml_append_buf(buf_T *buf, linenr_T lnum, char *line, colnr_T len, bool newfile) FUNC_ATTR_NONNULL_ARG(1) { if (buf->b_ml.ml_mfp == NULL) { @@ -1887,7 +1886,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, (char *)line, len, newfile, false); + return ml_append_int(buf, lnum, line, len, newfile, false); } /// @param lnum append after this line (can be 0) diff --git a/src/nvim/move.c b/src/nvim/move.c index ee9edb3dc4..3af26b910e 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -760,7 +760,7 @@ void curs_columns(win_T *wp, int may_scroll) // When cursor wraps to first char of next line in Insert // mode, the 'showbreak' string isn't shown, backup to first // column - char *const sbr = (char *)get_showbreak_value(wp); + char *const sbr = get_showbreak_value(wp); if (*sbr && *get_cursor_pos_ptr() == NUL && wp->w_wcol == vim_strsize(sbr)) { wp->w_wcol = 0; diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 6fb00ca6b5..798ea4f990 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1526,8 +1526,7 @@ void restore_visual_mode(void) /// @param dir the direction of searching, is either FORWARD or BACKWARD /// @param *colp is in/decremented if "ptr[-dir]" should also be included. /// @param bnp points to a counter for square brackets. -static bool find_is_eval_item(const char_u *const ptr, int *const colp, int *const bnp, - const int dir) +static bool find_is_eval_item(const char *const ptr, int *const colp, int *const bnp, const int dir) { // Accept everything inside []. if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) { @@ -1635,7 +1634,7 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, char **text || (find_type & FIND_IDENT)) && (!(find_type & FIND_EVAL) || prevcol == 0 - || !find_is_eval_item((char_u *)ptr + prevcol, &prevcol, &bn, BACKWARD))) { + || !find_is_eval_item(ptr + prevcol, &prevcol, &bn, BACKWARD))) { break; } col = prevcol; @@ -1678,7 +1677,7 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, char **text : mb_get_class(ptr + col) != 0) || ((find_type & FIND_EVAL) && col <= (int)startcol - && find_is_eval_item((char_u *)ptr + col, &col, &bn, FORWARD)))) { + && find_is_eval_item(ptr + col, &col, &bn, FORWARD)))) { col += utfc_ptr2len(ptr + col); } @@ -1927,7 +1926,7 @@ bool add_to_showcmd(int c) } } - char *p = (char *)transchar(c); + char *p = transchar(c); if (*p == ' ') { STRCPY(p, "<20>"); } @@ -2236,7 +2235,7 @@ static void nv_gd(oparg_T *oap, int nchar, int thisblock) size_t len; char *ptr; if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0 - || !find_decl((char_u *)ptr, len, nchar == 'd', thisblock, SEARCH_START)) { + || !find_decl(ptr, len, nchar == 'd', thisblock, SEARCH_START)) { clearopbeep(oap); return; } @@ -2252,7 +2251,7 @@ static void nv_gd(oparg_T *oap, int nchar, int thisblock) /// @return true if line[offset] is not inside a C-style comment or string, /// false otherwise. -static bool is_ident(const char_u *line, int offset) +static bool is_ident(const char *line, int offset) { bool incomment = false; int instring = 0; @@ -2260,11 +2259,11 @@ static bool is_ident(const char_u *line, int offset) for (int i = 0; i < offset && line[i] != NUL; i++) { if (instring != 0) { - if (prev != '\\' && line[i] == instring) { + if (prev != '\\' && (uint8_t)line[i] == instring) { instring = 0; } } else if ((line[i] == '"' || line[i] == '\'') && !incomment) { - instring = line[i]; + instring = (uint8_t)line[i]; } else { if (incomment) { if (prev == '*' && line[i] == '/') { @@ -2277,7 +2276,7 @@ static bool is_ident(const char_u *line, int offset) } } - prev = line[i]; + prev = (uint8_t)line[i]; } return incomment == false && instring == 0; @@ -2291,7 +2290,7 @@ static bool is_ident(const char_u *line, int offset) /// @param flags_arg flags passed to searchit() /// /// @return fail when not found. -bool find_decl(char_u *ptr, size_t len, bool locally, bool thisblock, int flags_arg) +bool find_decl(char *ptr, size_t len, bool locally, bool thisblock, int flags_arg) { char *pat; pos_T old_pos; @@ -2309,7 +2308,7 @@ bool find_decl(char_u *ptr, size_t len, bool locally, bool thisblock, int flags_ // Put "\V" before the pattern to avoid that the special meaning of "." // and "~" causes trouble. assert(len <= INT_MAX); - sprintf(pat, vim_iswordp((char *)ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", // NOLINT(runtime/printf) + sprintf(pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", // NOLINT(runtime/printf) (int)len, ptr); old_pos = curwin->w_cursor; save_p_ws = p_ws; @@ -2370,7 +2369,7 @@ bool find_decl(char_u *ptr, size_t len, bool locally, bool thisblock, int flags_ curwin->w_cursor.col = 0; continue; } - bool valid = is_ident((char_u *)get_cursor_line_ptr(), curwin->w_cursor.col); + bool valid = is_ident(get_cursor_line_ptr(), curwin->w_cursor.col); // If the current position is not a valid identifier and a previous match is // present, favor that one instead. @@ -2551,7 +2550,7 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist) validate_virtcol(); colnr_T virtcol = curwin->w_virtcol; if (virtcol > (colnr_T)width1 && *get_showbreak_value(curwin) != NUL) { - virtcol -= vim_strsize((char *)get_showbreak_value(curwin)); + virtcol -= vim_strsize(get_showbreak_value(curwin)); } int c = utf_ptr2char(get_cursor_pos_ptr()); @@ -3929,7 +3928,7 @@ static void nv_gotofile(cmdarg_T *cap) return; } - ptr = (char *)grab_file_name(cap->count1, &lnum); + ptr = grab_file_name(cap->count1, &lnum); if (ptr != NULL) { // do autowrite if necessary @@ -3998,7 +3997,7 @@ static void nv_search(cmdarg_T *cap) // When using 'incsearch' the cursor may be moved to set a different search // start position. - cap->searchbuf = (char *)getcmdline(cap->cmdchar, cap->count1, 0, true); + cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0, true); if (cap->searchbuf == NULL) { clearop(oap); diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 42ff2b15ed..c87aa596c3 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -723,7 +723,7 @@ int get_expr_register(void) { char *new_line; - new_line = (char *)getcmdline('=', 0L, 0, true); + new_line = getcmdline('=', 0L, 0, true); if (new_line == NULL) { return NUL; } @@ -1131,7 +1131,7 @@ int do_execreg(int regname, int colon, int addcr, int silent) retval = put_in_typebuf(p, true, colon, silent); xfree(p); } else if (regname == '.') { // use last inserted text - p = (char *)get_last_insert_save(); + p = get_last_insert_save(); if (p == NULL) { emsg(_(e_noinstext)); return FAIL; @@ -1351,7 +1351,7 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg) return true; case '.': // last inserted text - *argp = (char *)get_last_insert_save(); + *argp = get_last_insert_save(); *allocated = true; if (*argp == NULL && errmsg) { emsg(_(e_noinstext)); @@ -1363,9 +1363,8 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg) if (!errmsg) { return false; } - *argp - = (char *)file_name_at_cursor(FNAME_MESS | FNAME_HYP | (regname == Ctrl_P ? FNAME_EXP : 0), - 1L, NULL); + *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP | (regname == Ctrl_P ? FNAME_EXP : 0), + 1L, NULL); *allocated = true; return true; @@ -3148,7 +3147,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (y_size == 0 || y_array == NULL) { semsg(_("E353: Nothing in register %s"), - regname == 0 ? (char_u *)"\"" : transchar(regname)); + regname == 0 ? "\"" : transchar(regname)); goto end; } @@ -5178,7 +5177,7 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, // Count the number of lines within the string if (str_list) { - for (char_u **ss = (char_u **)str; *ss != NULL; ss++) { + for (char **ss = (char **)str; *ss != NULL; ss++) { newlines++; } } else { diff --git a/src/nvim/option.c b/src/nvim/option.c index 0c2a2f7060..2bd3dcfe2d 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1106,7 +1106,7 @@ int do_set(char *arg, int opt_flags) char *errmsg = NULL; char *startarg = arg; // remember for error message - if (strncmp(arg, "all", 3) == 0 && !isalpha((uint8_t)arg[3]) + if (strncmp(arg, "all", 3) == 0 && !ASCII_ISALPHA(arg[3]) && !(opt_flags & OPT_MODELINE)) { // ":set all" show all options. // ":set all&" set all options to their default value. @@ -1390,7 +1390,7 @@ int do_set(char *arg, int opt_flags) || *arg == '^' || (*arg != NUL && (!arg[1] || ascii_iswhite(arg[1])) && !ascii_isdigit(*arg)))) { - value = string_to_key((char_u *)arg); + value = string_to_key(arg); if (value == 0 && (long *)varp != &p_wcm) { errmsg = e_invarg; goto skip; @@ -1520,15 +1520,15 @@ 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. -int string_to_key(char_u *arg) +int string_to_key(char *arg) { if (*arg == '<') { - return find_key_option((char *)arg + 1, true); + return find_key_option(arg + 1, true); } if (*arg == '^') { - return CTRL_CHR(arg[1]); + return CTRL_CHR((uint8_t)arg[1]); } - return *arg; + return (uint8_t)(*arg); } // When changing 'title', 'titlestring', 'icon' or 'iconstring', call @@ -1601,9 +1601,9 @@ void set_options_bin(int oldval, int newval, int opt_flags) /// number, return -1. int get_shada_parameter(int type) { - char_u *p = find_shada_parameter(type); + char *p = find_shada_parameter(type); if (p != NULL && ascii_isdigit(*p)) { - return atoi((char *)p); + return atoi(p); } return -1; } @@ -1611,11 +1611,11 @@ int get_shada_parameter(int type) /// Find the parameter represented by the given character (eg ''', ':', '"', or /// '/') in the 'shada' option and return a pointer to the string after it. /// Return NULL if the parameter is not specified in the string. -char_u *find_shada_parameter(int type) +char *find_shada_parameter(int type) { for (char *p = p_shada; *p; p++) { if (*p == type) { - return (char_u *)p + 1; + return p + 1; } if (*p == 'n') { // 'n' is always the last one break; @@ -1773,7 +1773,7 @@ void redraw_titles(void) bool valid_name(const char *val, const char *allowed) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - for (const char_u *s = (char_u *)val; *s != NUL; s++) { + for (const char *s = val; *s != NUL; s++) { if (!ASCII_ISALNUM(*s) && vim_strchr(allowed, (uint8_t)(*s)) == NULL) { return false; @@ -3090,10 +3090,10 @@ bool is_string_option(const char *name) // Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number. // When "has_lt" is true there is a '<' before "*arg_arg". // Returns 0 when the key is not recognized. -int find_key_option_len(const char_u *arg_arg, size_t len, bool has_lt) +int find_key_option_len(const char *arg_arg, size_t len, bool has_lt) { int key = 0; - const char *arg = (char *)arg_arg; + const char *arg = arg_arg; // Don't use get_special_key_code() for t_xx, we don't want it to call // add_termcap_entry(). @@ -3113,7 +3113,7 @@ int find_key_option_len(const char_u *arg_arg, size_t len, bool has_lt) static int find_key_option(const char *arg, bool has_lt) { - return find_key_option_len((char_u *)arg, strlen(arg), has_lt); + return find_key_option_len(arg, strlen(arg), has_lt); } /// if 'all' == 0: show changed options @@ -3431,7 +3431,7 @@ int makefoldset(FILE *fd) static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_t flags) { - char_u *buf = NULL; + char *buf = NULL; char_u *part = NULL; if (fprintf(fd, "%s %s=", cmd, name) < 0) { @@ -3444,7 +3444,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ if (valuep == &p_pt) { char_u *s = (char_u *)(*valuep); while (*s != NUL) { - if (put_escstr(fd, (char_u *)str2special((const char **)&s, false, false), 2) == FAIL) { + if (put_escstr(fd, (char *)str2special((const char **)&s, false, false), 2) == FAIL) { return FAIL; } } @@ -3453,7 +3453,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ // replace home directory in the whole option value into "buf" buf = xmalloc(size); - home_replace(NULL, *valuep, (char *)buf, size, false); + home_replace(NULL, *valuep, buf, size, false); // If the option value is longer than MAXPATHL, we need to append // each comma separated part of the option separately, so that it @@ -3466,7 +3466,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ if (put_eol(fd) == FAIL) { goto fail; } - char *p = (char *)buf; + char *p = buf; while (*p != NUL) { // for each comma separated option part, append value to // the option, :set rtp+=value @@ -3474,7 +3474,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ goto fail; } (void)copy_option_part(&p, (char *)part, size, ","); - if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL) { + if (put_escstr(fd, (char *)part, 2) == FAIL || put_eol(fd) == FAIL) { goto fail; } } @@ -3487,7 +3487,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ return FAIL; } xfree(buf); - } else if (put_escstr(fd, (char_u *)(*valuep), 2) == FAIL) { + } else if (put_escstr(fd, *valuep, 2) == FAIL) { return FAIL; } } @@ -4843,7 +4843,7 @@ void ExpandOldSetting(int *num_file, char ***file) // A backslash is required before some characters. This is the reverse of // what happens in do_set(). - char_u *buf = (char_u *)vim_strsave_escaped(var, (char *)escape_chars); + char_u *buf = (char_u *)vim_strsave_escaped(var, escape_chars); #ifdef BACKSLASH_IN_FILENAME // For MS-Windows et al. we don't double backslashes at the start and @@ -4877,7 +4877,7 @@ static void option_value2string(vimoption_T *opp, int scope) if (wc_use_keyname((char_u *)varp, &wc)) { xstrlcpy(NameBuff, (char *)get_special_key_name((int)wc, 0), sizeof(NameBuff)); } else if (wc != 0) { - xstrlcpy(NameBuff, (char *)transchar((int)wc), sizeof(NameBuff)); + xstrlcpy(NameBuff, transchar((int)wc), sizeof(NameBuff)); } else { snprintf(NameBuff, sizeof(NameBuff), @@ -5260,16 +5260,16 @@ unsigned int get_ve_flags(void) /// /// @param win If not NULL, the window to get the local option from; global /// otherwise. -char_u *get_showbreak_value(win_T *const win) +char *get_showbreak_value(win_T *const win) FUNC_ATTR_WARN_UNUSED_RESULT { if (win->w_p_sbr == NULL || *win->w_p_sbr == NUL) { - return (char_u *)p_sbr; + return p_sbr; } if (strcmp(win->w_p_sbr, "NONE") == 0) { - return (char_u *)empty_option; + return empty_option; } - return (char_u *)win->w_p_sbr; + return win->w_p_sbr; } /// Return the current end-of-line type: EOL_DOS, EOL_UNIX or EOL_MAC. diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 6385d968dd..e33e57424b 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -578,7 +578,7 @@ EXTERN long p_lines; // 'lines' EXTERN long p_linespace; // 'linespace' EXTERN int p_lisp; ///< 'lisp' EXTERN char *p_lop; ///< 'lispoptions' -EXTERN char_u *p_lispwords; // 'lispwords' +EXTERN char *p_lispwords; // 'lispwords' EXTERN long p_ls; // 'laststatus' EXTERN long p_stal; // 'showtabline' EXTERN char *p_lcs; // 'listchars' diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index ab58888482..efb1ff2ab6 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -206,7 +206,7 @@ static char *illegal_char(char *errbuf, size_t errbuflen, int c) return ""; } vim_snprintf(errbuf, errbuflen, _("E539: Illegal character <%s>"), - (char *)transchar(c)); + transchar(c)); return errbuf; } diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index ae34a79365..7e4710a2f7 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -543,7 +543,7 @@ void free_homedir(void) /// @see {expand_env} char *expand_env_save(char *src) { - return (char *)expand_env_save_opt(src, false); + return expand_env_save_opt(src, false); } /// Similar to expand_env_save() but when "one" is `true` handle the string as @@ -551,10 +551,10 @@ char *expand_env_save(char *src) /// @param src String containing environment variables to expand /// @param one Should treat as only one file name /// @see {expand_env} -char_u *expand_env_save_opt(char *src, bool one) +char *expand_env_save_opt(char *src, bool one) { - char_u *p = xmalloc(MAXPATHL); - expand_env_esc(src, (char *)p, MAXPATHL, false, one, NULL); + char *p = xmalloc(MAXPATHL); + expand_env_esc(src, p, MAXPATHL, false, one, NULL); return p; } diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index ce1b2d1cf5..302faa8140 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -330,11 +330,11 @@ static bool is_executable_ext(const char *name, char **abspath) const char *ext_end = ext; size_t ext_len = - copy_option_part(&ext_end, (char_u *)buf_end, + copy_option_part((char **)&ext_end, buf_end, sizeof(os_buf) - (size_t)(buf_end - os_buf), ENV_SEPSTR); if (ext_len != 0) { bool in_pathext = nameext_len == ext_len - && 0 == mb_strnicmp((char_u *)nameext, (char_u *)ext, ext_len); + && 0 == mb_strnicmp(nameext, ext, ext_len); if (((in_pathext || is_unix_shell) && is_executable(name, abspath)) || is_executable(os_buf, abspath)) { @@ -791,14 +791,14 @@ int os_setperm(const char *const name, int perm) // Return a pointer to the ACL of file "fname" in allocated memory. // Return NULL if the ACL is not available for whatever reason. -vim_acl_T os_get_acl(const char_u *fname) +vim_acl_T os_get_acl(const char *fname) { vim_acl_T ret = NULL; return ret; } // Set the ACL of file "fname" to "acl" (unless it's NULL). -void os_set_acl(const char_u *fname, vim_acl_T aclent) +void os_set_acl(const char *fname, vim_acl_T aclent) { if (aclent == NULL) { return; diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 51cabfbcbf..759b3cf83c 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -254,7 +254,8 @@ size_t input_enqueue(String keys) uint8_t buf[19] = { 0 }; // Do not simplify the keys here. Simplification will be done later. unsigned int new_size - = trans_special((const char **)&ptr, (size_t)(end - ptr), buf, FSK_KEYCODE, true, NULL); + = trans_special((const char **)&ptr, (size_t)(end - ptr), (char *)buf, FSK_KEYCODE, true, + NULL); if (new_size) { new_size = handle_mouse_event(&ptr, buf, new_size); diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index a99a8d25ce..6b07b6ef70 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -121,7 +121,7 @@ char *get_xdg_home(const XDGVarType idx) #endif #ifdef BACKSLASH_IN_FILENAME - slash_adjust((char_u *)dir); + slash_adjust(dir); #endif } return dir; diff --git a/src/nvim/path.c b/src/nvim/path.c index afc0563498..12087d52bd 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1260,7 +1260,7 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i } else { // First expand environment variables, "~/" and "~user/". if ((has_env_var(p) && !(flags & EW_NOTENV)) || *p == '~') { - p = (char *)expand_env_save_opt(p, true); + p = expand_env_save_opt(p, true); if (p == NULL) { p = pat[i]; } else { @@ -1414,9 +1414,9 @@ static int expand_backtick(garray_T *gap, char *pat, int flags) /// backslash twice. /// When 'shellslash' set do it the other way around. /// When the path looks like a URL leave it unmodified. -void slash_adjust(char_u *p) +void slash_adjust(char *p) { - if (path_with_url((const char *)p)) { + if (path_with_url(p)) { return; } @@ -1429,8 +1429,8 @@ void slash_adjust(char_u *p) } while (*p) { - if (*p == (char_u)psepcN) { - *p = (char_u)psepc; + if (*p == psepcN) { + *p = psepc; } MB_PTR_ADV(p); } @@ -1690,8 +1690,8 @@ char *find_file_name_in_path(char *ptr, size_t len, int options, long count, cha } if (options & FNAME_EXP) { - file_name = (char *)find_file_in_path(ptr, len, options & ~FNAME_MESS, true, - rel_fname); + file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, true, + rel_fname); // If the file could not be found in a normal way, try applying // 'includeexpr' (unless done already). @@ -1701,8 +1701,8 @@ char *find_file_name_in_path(char *ptr, size_t len, int options, long count, cha if (tofree != NULL) { ptr = tofree; len = strlen(ptr); - file_name = (char *)find_file_in_path(ptr, len, options & ~FNAME_MESS, - true, rel_fname); + file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, + true, rel_fname); } } if (file_name == NULL && (options & FNAME_MESS)) { @@ -1717,7 +1717,7 @@ char *find_file_name_in_path(char *ptr, size_t len, int options, long count, cha while (file_name != NULL && --count > 0) { xfree(file_name); file_name = - (char *)find_file_in_path(ptr, len, options, false, rel_fname); + find_file_in_path(ptr, len, options, false, rel_fname); } } else { file_name = xstrnsave(ptr, len); @@ -1768,7 +1768,7 @@ int path_with_url(const char *fname) // non-URL text. // first character must be alpha - if (!isalpha((uint8_t)(*fname))) { + if (!ASCII_ISALPHA(*fname)) { return 0; } @@ -1777,7 +1777,7 @@ int path_with_url(const char *fname) } // check body: alpha or dash - for (p = fname + 1; (isalpha((uint8_t)(*p)) || (*p == '-')); p++) {} + for (p = fname + 1; (ASCII_ISALPHA(*p) || (*p == '-')); p++) {} // check last char is not a dash if (p[-1] == '-') { diff --git a/src/nvim/plines.c b/src/nvim/plines.c index 38ca91a6ac..6393c8dea5 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -440,7 +440,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) // Set *headp to the size of what we add. // Do not use 'showbreak' at the NUL after the text. added = 0; - char *const sbr = c == NUL ? empty_option : (char *)get_showbreak_value(wp); + char *const sbr = c == NUL ? empty_option : get_showbreak_value(wp); if ((*sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && vcol != 0) { colnr_T sbrlen = 0; int numberwidth = win_col_off(wp); diff --git a/src/nvim/profile.c b/src/nvim/profile.c index acbaf09a6e..8402817710 100644 --- a/src/nvim/profile.c +++ b/src/nvim/profile.c @@ -299,7 +299,7 @@ void ex_profile(exarg_T *eap) if (len == 5 && strncmp(eap->arg, "start", 5) == 0 && *e != NUL) { xfree(profile_fname); - profile_fname = (char *)expand_env_save_opt(e, true); + profile_fname = expand_env_save_opt(e, true); do_profiling = PROF_YES; profile_set_wait(profile_zero()); set_vim_var_nr(VV_PROFILING, 1L); diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 32ae0fc276..f0c1011844 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3168,15 +3168,15 @@ void qf_list(exarg_T *eap) // Get the attributes for the different quickfix highlight items. Note // that this depends on syntax items defined in the qf.vim syntax file - qfFileAttr = syn_name2attr((char_u *)"qfFileName"); + qfFileAttr = syn_name2attr("qfFileName"); if (qfFileAttr == 0) { qfFileAttr = HL_ATTR(HLF_D); } - qfSepAttr = syn_name2attr((char_u *)"qfSeparator"); + qfSepAttr = syn_name2attr("qfSeparator"); if (qfSepAttr == 0) { qfSepAttr = HL_ATTR(HLF_D); } - qfLineAttr = syn_name2attr((char_u *)"qfLineNr"); + qfLineAttr = syn_name2attr("qfLineNr"); if (qfLineAttr == 0) { qfLineAttr = HL_ATTR(HLF_N); } @@ -3997,7 +3997,7 @@ static int qf_buf_add_line(qf_list_T *qfl, buf_T *buf, linenr_T lnum, const qfli IObuff + len, IOSIZE - len); } - if (ml_append_buf(buf, lnum, (char_u *)IObuff, + if (ml_append_buf(buf, lnum, IObuff, (colnr_T)strlen(IObuff) + 1, false) == FAIL) { return FAIL; } diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 54461bfa07..ab8e974b29 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -361,7 +361,7 @@ static int nextchr; // used for ungetchr() #define REG_NPAREN 3 // \%(\) typedef struct { - char_u *regparse; + char *regparse; int prevchr_len; int curchr; int prevchr; @@ -393,12 +393,12 @@ static int get_equi_class(char **pp) { int c; int l = 1; - char_u *p = (char_u *)(*pp); + char *p = *pp; if (p[1] == '=' && p[2] != NUL) { - l = utfc_ptr2len((char *)p + 2); + l = utfc_ptr2len(p + 2); if (p[l + 2] == '=' && p[l + 3] == ']') { - c = utf_ptr2char((char *)p + 2); + c = utf_ptr2char(p + 2); *pp += l + 4; return c; } @@ -414,12 +414,12 @@ static int get_coll_element(char **pp) { int c; int l = 1; - char_u *p = (char_u *)(*pp); + char *p = *pp; if (p[0] != NUL && p[1] == '.' && p[2] != NUL) { - l = utfc_ptr2len((char *)p + 2); + l = utfc_ptr2len(p + 2); if (p[l + 2] == '.' && p[l + 3] == ']') { - c = utf_ptr2char((char *)p + 2); + c = utf_ptr2char(p + 2); *pp += l + 4; return c; } @@ -437,7 +437,7 @@ static void get_cpo_flags(void) /// Skip over a "[]" range. /// "p" must point to the character after the '['. /// The returned pointer is on the matching ']', or the terminating NUL. -static char_u *skip_anyof(char *p) +static char *skip_anyof(char *p) { int l; @@ -472,7 +472,7 @@ static char_u *skip_anyof(char *p) } } - return (char_u *)p; + return p; } /// Skip past regular expression. @@ -522,7 +522,7 @@ char *skip_regexp_ex(char *startp, int dirc, int magic, char **newp, int *droppe } if ((p[0] == '[' && mymagic >= MAGIC_ON) || (p[0] == '\\' && p[1] == '[' && mymagic <= MAGIC_OFF)) { - p = (char *)skip_anyof(p + 1); + p = skip_anyof(p + 1); if (p[0] == NUL) { break; } @@ -559,9 +559,9 @@ static int at_start; // True when on the first character static int prev_at_start; // True when on the second character // Start parsing at "str". -static void initchr(char_u *str) +static void initchr(char *str) { - regparse = (char *)str; + regparse = str; prevchr_len = 0; curchr = prevprevchr = prevchr = nextchr = -1; at_start = true; @@ -572,7 +572,7 @@ static void initchr(char_u *str) // starts in the same state again. static void save_parse_state(parse_state_T *ps) { - ps->regparse = (char_u *)regparse; + ps->regparse = regparse; ps->prevchr_len = prevchr_len; ps->curchr = curchr; ps->prevchr = prevchr; @@ -586,7 +586,7 @@ static void save_parse_state(parse_state_T *ps) // Restore a previously saved parse state. static void restore_parse_state(parse_state_T *ps) { - regparse = (char *)ps->regparse; + regparse = ps->regparse; prevchr_len = ps->prevchr_len; curchr = ps->curchr; prevchr = ps->prevchr; @@ -892,7 +892,7 @@ static int64_t getoctchrs(void) static int read_limits(long *minval, long *maxval) { int reverse = false; - char_u *first_char; + char *first_char; long tmp; if (*regparse == '-') { @@ -900,7 +900,7 @@ static int read_limits(long *minval, long *maxval) regparse++; reverse = true; } - first_char = (char_u *)regparse; + first_char = regparse; *minval = getdigits_long(®parse, false, 0); if (*regparse == ',') { // There is a comma. if (ascii_isdigit(*++regparse)) { @@ -1019,7 +1019,7 @@ static bool reg_iswordc(int c) } // Get pointer to the line "lnum", which is relative to "reg_firstlnum". -static char_u *reg_getline(linenr_T lnum) +static char *reg_getline(linenr_T lnum) { // when looking behind for a match/no-match lnum is negative. But we // can't go before line 1 @@ -1028,9 +1028,9 @@ static char_u *reg_getline(linenr_T lnum) } if (lnum > rex.reg_maxline) { // Must have matched the "\n" in the last line. - return (char_u *)""; + return ""; } - return (char_u *)ml_get_buf(rex.reg_buf, rex.reg_firstlnum + lnum, false); + return ml_get_buf(rex.reg_buf, rex.reg_firstlnum + lnum, false); } static char_u *reg_startzp[NSUBEXP]; // Workspace to mark beginning @@ -1147,7 +1147,7 @@ static bool reg_match_visual(void) } // getvvcol() flushes rex.line, need to get it again - rex.line = reg_getline(rex.lnum); + rex.line = (char_u *)reg_getline(rex.lnum); rex.input = rex.line + col; unsigned int cols_u = win_linetabsize(wp, rex.reg_firstlnum + rex.lnum, (char *)rex.line, col); @@ -1190,8 +1190,8 @@ static void cleanup_subexpr(void) memset(rex.reg_startpos, 0xff, sizeof(lpos_T) * NSUBEXP); memset(rex.reg_endpos, 0xff, sizeof(lpos_T) * NSUBEXP); } else { - memset(rex.reg_startp, 0, sizeof(char_u *) * NSUBEXP); - memset(rex.reg_endp, 0, sizeof(char_u *) * NSUBEXP); + memset(rex.reg_startp, 0, sizeof(char *) * NSUBEXP); + memset(rex.reg_endp, 0, sizeof(char *) * NSUBEXP); } rex.need_clear_subexpr = false; } @@ -1205,8 +1205,8 @@ static void cleanup_zsubexpr(void) memset(reg_startzpos, 0xff, sizeof(lpos_T) * NSUBEXP); memset(reg_endzpos, 0xff, sizeof(lpos_T) * NSUBEXP); } else { - memset(reg_startzp, 0, sizeof(char_u *) * NSUBEXP); - memset(reg_endzp, 0, sizeof(char_u *) * NSUBEXP); + memset(reg_startzp, 0, sizeof(char *) * NSUBEXP); + memset(reg_endzp, 0, sizeof(char *) * NSUBEXP); } rex.need_clear_zsubexpr = false; } @@ -1215,7 +1215,7 @@ static void cleanup_zsubexpr(void) // Advance rex.lnum, rex.line and rex.input to the next line. static void reg_nextline(void) { - rex.line = reg_getline(++rex.lnum); + rex.line = (char_u *)reg_getline(++rex.lnum); rex.input = rex.line; fast_breakcheck(); } @@ -1252,7 +1252,7 @@ static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T e } // Get the line to compare with. - p = (char *)reg_getline(clnum); + p = reg_getline(clnum); assert(p); if (clnum == end_lnum) { @@ -1434,21 +1434,21 @@ static int cstrncmp(char *s1, char *s2, int *n) /// @param c character to find in @a s /// /// @return NULL if no match, otherwise pointer to the position in @a s -static inline char_u *cstrchr(const char_u *const s, const int c) +static inline char *cstrchr(const char *const s, const int c) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_ALWAYS_INLINE { if (!rex.reg_ic) { - return (char_u *)vim_strchr((char *)s, c); + return vim_strchr(s, c); } // Use folded case for UTF-8, slow! For ASCII use libc strpbrk which is // expected to be highly optimized. if (c > 0x80) { const int folded_c = utf_fold(c); - for (const char_u *p = s; *p != NUL; p += utfc_ptr2len((char *)p)) { - if (utf_fold(utf_ptr2char((char *)p)) == folded_c) { - return (char_u *)p; + for (const char *p = s; *p != NUL; p += utfc_ptr2len(p)) { + if (utf_fold(utf_ptr2char(p)) == folded_c) { + return (char *)p; } } return NULL; @@ -1460,11 +1460,11 @@ static inline char_u *cstrchr(const char_u *const s, const int c) } else if (ASCII_ISLOWER(c)) { cc = TOUPPER_ASC(c); } else { - return (char_u *)vim_strchr((char *)s, c); + return vim_strchr(s, c); } char tofind[] = { (char)c, (char)cc, NUL }; - return (char_u *)strpbrk((const char *)s, tofind); + return strpbrk(s, tofind); } //////////////////////////////////////////////////////////////// @@ -1636,8 +1636,7 @@ static void clear_submatch_list(staticList10_T *sl) /// references invalid! /// /// Returns the size of the replacement, including terminating NUL. -int vim_regsub(regmatch_T *rmp, char_u *source, typval_T *expr, char_u *dest, int destlen, - int flags) +int vim_regsub(regmatch_T *rmp, char *source, typval_T *expr, char *dest, int destlen, int flags) { regexec_T rex_save; bool rex_in_use_save = rex_in_use; @@ -1653,7 +1652,7 @@ int vim_regsub(regmatch_T *rmp, char_u *source, typval_T *expr, char_u *dest, in rex.reg_maxline = 0; rex.reg_buf = curbuf; rex.reg_line_lbr = true; - int result = vim_regsub_both((char *)source, expr, (char *)dest, destlen, flags); + int result = vim_regsub_both(source, expr, dest, destlen, flags); rex_in_use = rex_in_use_save; if (rex_in_use) { @@ -1663,7 +1662,7 @@ int vim_regsub(regmatch_T *rmp, char_u *source, typval_T *expr, char_u *dest, in return result; } -int vim_regsub_multi(regmmatch_T *rmp, linenr_T lnum, char_u *source, char_u *dest, int destlen, +int vim_regsub_multi(regmmatch_T *rmp, linenr_T lnum, char *source, char *dest, int destlen, int flags) { regexec_T rex_save; @@ -1681,7 +1680,7 @@ int vim_regsub_multi(regmmatch_T *rmp, linenr_T lnum, char_u *source, char_u *de rex.reg_firstlnum = lnum; rex.reg_maxline = curbuf->b_ml.ml_line_count - lnum; rex.reg_line_lbr = false; - int result = vim_regsub_both((char *)source, NULL, (char *)dest, destlen, flags); + int result = vim_regsub_both(source, NULL, dest, destlen, flags); rex_in_use = rex_in_use_save; if (rex_in_use) { @@ -1974,7 +1973,7 @@ static int vim_regsub_both(char *source, typval_T *expr, char *dest, int destlen if (clnum < 0 || rex.reg_mmatch->endpos[no].lnum < 0) { s = NULL; } else { - s = (char *)reg_getline(clnum) + rex.reg_mmatch->startpos[no].col; + s = reg_getline(clnum) + rex.reg_mmatch->startpos[no].col; if (rex.reg_mmatch->endpos[no].lnum == clnum) { len = rex.reg_mmatch->endpos[no].col - rex.reg_mmatch->startpos[no].col; @@ -2005,7 +2004,7 @@ static int vim_regsub_both(char *source, typval_T *expr, char *dest, int destlen *dst = CAR; } dst++; - s = (char *)reg_getline(++clnum); + s = reg_getline(++clnum); if (rex.reg_mmatch->endpos[no].lnum == clnum) { len = rex.reg_mmatch->endpos[no].col; } else { @@ -2099,7 +2098,7 @@ static char *reg_getline_submatch(linenr_T lnum) rex.reg_firstlnum = rsm.sm_firstlnum; rex.reg_maxline = rsm.sm_maxline; - s = (char *)reg_getline(lnum); + s = reg_getline(lnum); rex.reg_firstlnum = save_first; rex.reg_maxline = save_max; @@ -2366,7 +2365,7 @@ regprog_T *vim_regcomp(char *expr_arg, int re_flags) // But don't try if an error message was given. if (regexp_engine == AUTOMATIC_ENGINE && called_emsg == called_emsg_before) { regexp_engine = BACKTRACKING_ENGINE; - report_re_switch((char_u *)expr); + report_re_switch(expr); prog = bt_regengine.regcomp((char_u *)expr, re_flags); } } @@ -2400,12 +2399,12 @@ void free_regexp_stuff(void) #endif -static void report_re_switch(char_u *pat) +static void report_re_switch(char *pat) { if (p_verbose > 0) { verbose_enter(); msg_puts(_("Switching to backtracking RE engine for pattern: ")); - msg_puts((char *)pat); + msg_puts(pat); verbose_leave(); } } @@ -2422,7 +2421,7 @@ static void report_re_switch(char_u *pat) /// @param nl /// /// @return true if there is a match, false if not. -static bool vim_regexec_string(regmatch_T *rmp, char_u *line, colnr_T col, bool nl) +static bool vim_regexec_string(regmatch_T *rmp, char *line, colnr_T col, bool nl) { regexec_T rex_save; bool rex_in_use_save = rex_in_use; @@ -2445,7 +2444,7 @@ static bool vim_regexec_string(regmatch_T *rmp, char_u *line, colnr_T col, bool rex.reg_startpos = NULL; rex.reg_endpos = NULL; - int result = rmp->regprog->engine->regexec_nl(rmp, line, col, nl); + int result = rmp->regprog->engine->regexec_nl(rmp, (char_u *)line, col, nl); rmp->regprog->re_in_use = false; // NFA engine aborted because it's very slow, use backtracking engine instead. @@ -2457,11 +2456,11 @@ static bool vim_regexec_string(regmatch_T *rmp, char_u *line, colnr_T col, bool p_re = BACKTRACKING_ENGINE; vim_regfree(rmp->regprog); - report_re_switch((char_u *)pat); + report_re_switch(pat); rmp->regprog = vim_regcomp(pat, re_flags); if (rmp->regprog != NULL) { rmp->regprog->re_in_use = true; - result = rmp->regprog->engine->regexec_nl(rmp, line, col, nl); + result = rmp->regprog->engine->regexec_nl(rmp, (char_u *)line, col, nl); rmp->regprog->re_in_use = false; } @@ -2479,7 +2478,7 @@ static bool vim_regexec_string(regmatch_T *rmp, char_u *line, colnr_T col, bool // Note: "*prog" may be freed and changed. // Return true if there is a match, false if not. -bool vim_regexec_prog(regprog_T **prog, bool ignore_case, char_u *line, colnr_T col) +bool vim_regexec_prog(regprog_T **prog, bool ignore_case, char *line, colnr_T col) { regmatch_T regmatch = { .regprog = *prog, .rm_ic = ignore_case }; bool r = vim_regexec_string(®match, line, col, false); @@ -2491,7 +2490,7 @@ bool vim_regexec_prog(regprog_T **prog, bool ignore_case, char_u *line, colnr_T // Return true if there is a match, false if not. bool vim_regexec(regmatch_T *rmp, char *line, colnr_T col) { - return vim_regexec_string(rmp, (char_u *)line, col, false); + return vim_regexec_string(rmp, line, col, false); } // Like vim_regexec(), but consider a "\n" in "line" to be a line break. @@ -2499,7 +2498,7 @@ bool vim_regexec(regmatch_T *rmp, char *line, colnr_T col) // Return true if there is a match, false if not. bool vim_regexec_nl(regmatch_T *rmp, char *line, colnr_T col) { - return vim_regexec_string(rmp, (char_u *)line, col, true); + return vim_regexec_string(rmp, line, col, true); } /// Match a regexp against multiple lines. @@ -2549,7 +2548,7 @@ long vim_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, p_re = BACKTRACKING_ENGINE; regprog_T *prev_prog = rmp->regprog; - report_re_switch((char_u *)pat); + report_re_switch(pat); // checking for \z misuse was already done when compiling for NFA, // allow all here reg_do_extmatch = REX_ALL; diff --git a/src/nvim/regexp_bt.c b/src/nvim/regexp_bt.c index a047c51145..611d24c091 100644 --- a/src/nvim/regexp_bt.c +++ b/src/nvim/regexp_bt.c @@ -430,7 +430,7 @@ static int regnarrate = 0; // Setup to parse the regexp. Used once to get the length and once to do it. static void regcomp_start(char_u *expr, int re_flags) // see vim_regcomp() { - initchr(expr); + initchr((char *)expr); if (re_flags & RE_MAGIC) { reg_magic = MAGIC_ON; } else { @@ -2128,7 +2128,7 @@ collection: // If there is no matching ']', we assume the '[' is a normal // character. This makes 'incsearch' and ":help [" work. - lp = skip_anyof(regparse); + lp = (char_u *)skip_anyof(regparse); if (*lp == ']') { // there is a matching ']' int startc = -1; // > 0 when next '-' is a range int endc; @@ -3014,7 +3014,7 @@ static void reg_restore(regsave_T *save, garray_T *gap) // only call reg_getline() when the line number changed to save // a bit of time rex.lnum = save->rs_u.pos.lnum; - rex.line = reg_getline(rex.lnum); + rex.line = (char_u *)reg_getline(rex.lnum); } rex.input = rex.line + save->rs_u.pos.col; } else { @@ -3385,12 +3385,12 @@ do_class: } else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) { scan++; } else if ((len = utfc_ptr2len((char *)scan)) > 1) { - if ((cstrchr(opnd, utf_ptr2char((char *)scan)) == NULL) == testval) { + if ((cstrchr((char *)opnd, utf_ptr2char((char *)scan)) == NULL) == testval) { break; } scan += len; } else { - if ((cstrchr(opnd, *scan) == NULL) == testval) { + if ((cstrchr((char *)opnd, *scan) == NULL) == testval) { break; } scan++; @@ -3647,7 +3647,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) // Line may have been freed, get it again. if (REG_MULTI) { - rex.line = reg_getline(rex.lnum); + rex.line = (char_u *)reg_getline(rex.lnum); rex.input = rex.line + col; } @@ -4003,7 +4003,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) case ANYBUT: if (c == NUL) { status = RA_NOMATCH; - } else if ((cstrchr(OPERAND(scan), c) == NULL) == (op == ANYOF)) { + } else if ((cstrchr((char *)OPERAND(scan), c) == NULL) == (op == ANYOF)) { status = RA_NOMATCH; } else { ADVANCE_REGINPUT(); @@ -4700,7 +4700,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) } } else { const char_u *const line = - reg_getline(rp->rs_un.regsave.rs_u.pos.lnum); + (char_u *)reg_getline(rp->rs_un.regsave.rs_u.pos.lnum); rp->rs_un.regsave.rs_u.pos.col -= utf_head_off((char *)line, @@ -4782,7 +4782,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) break; } rex.lnum--; - rex.line = reg_getline(rex.lnum); + rex.line = (char_u *)reg_getline(rex.lnum); // Just in case regrepeat() didn't count right. if (rex.line == NULL) { break; @@ -4962,7 +4962,7 @@ static long bt_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm, int if (REG_MULTI) { prog = (bt_regprog_T *)rex.reg_mmatch->regprog; - line = reg_getline((linenr_T)0); + line = (char_u *)reg_getline((linenr_T)0); rex.reg_startpos = rex.reg_mmatch->startpos; rex.reg_endpos = rex.reg_mmatch->endpos; } else { @@ -5014,7 +5014,7 @@ static long bt_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm, int MB_PTR_ADV(s); } } else { - while ((s = cstrchr(s, c)) != NULL) { + while ((s = (char_u *)cstrchr((char *)s, c)) != NULL) { if (cstrncmp((char *)s, (char *)prog->regmust, &prog->regmlen) == 0) { break; // Found it. } @@ -5049,7 +5049,7 @@ static long bt_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm, int while (!got_int) { if (prog->regstart != NUL) { // Skip until the char we know it must start with. - s = cstrchr(rex.line + col, prog->regstart); + s = (char_u *)cstrchr((char *)rex.line + col, prog->regstart); if (s == NULL) { retval = 0; break; @@ -5071,7 +5071,7 @@ static long bt_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm, int // if not currently on the first line, get it again if (rex.lnum != 0) { rex.lnum = 0; - rex.line = reg_getline((linenr_T)0); + rex.line = (char_u *)reg_getline((linenr_T)0); } if (rex.line[col] == NUL) { break; diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 66a31f0184..aaa8073240 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -2218,7 +2218,7 @@ collection: // - ranges, two characters followed by NFA_RANGE. p = (char_u *)regparse; - endp = skip_anyof((char *)p); + endp = (char_u *)skip_anyof((char *)p); if (*endp == ']') { // Try to reverse engineer character classes. For example, // recognize that [0-9] stands for \d and [A-Za-z_] for \h, @@ -5522,10 +5522,10 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T // bytes if possible. if (state->val <= 0) { if (REG_MULTI) { - rex.line = reg_getline(--rex.lnum); + rex.line = (char_u *)reg_getline(--rex.lnum); if (rex.line == NULL) { // can't go before the first line - rex.line = reg_getline(++rex.lnum); + rex.line = (char_u *)reg_getline(++rex.lnum); } } rex.input = rex.line; @@ -5533,10 +5533,10 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T if (REG_MULTI && (int)(rex.input - rex.line) < state->val) { // Not enough bytes in this line, go to end of // previous line. - rex.line = reg_getline(--rex.lnum); + rex.line = (char_u *)reg_getline(--rex.lnum); if (rex.line == NULL) { // can't go before the first line - rex.line = reg_getline(++rex.lnum); + rex.line = (char_u *)reg_getline(++rex.lnum); rex.input = rex.line; } else { rex.input = rex.line + strlen((char *)rex.line); @@ -5595,7 +5595,7 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T // restore position in input text rex.lnum = save_reglnum; if (REG_MULTI) { - rex.line = reg_getline(rex.lnum); + rex.line = (char_u *)reg_getline(rex.lnum); } rex.input = rex.line + save_reginput_col; if (result != NFA_TOO_EXPENSIVE) { @@ -5772,7 +5772,7 @@ static int failure_chance(nfa_state_T *state, int depth) // Skip until the char "c" we know a match must start with. static int skip_to_start(int c, colnr_T *colp) { - const char_u *const s = cstrchr(rex.line + *colp, c); + const char_u *const s = (char_u *)cstrchr((char *)rex.line + *colp, c); if (s == NULL) { return FAIL; } @@ -6860,7 +6860,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm // Line may have been freed, get it again. if (REG_MULTI) { - rex.line = reg_getline(rex.lnum); + rex.line = (char_u *)reg_getline(rex.lnum); rex.input = rex.line + col; } @@ -7333,7 +7333,7 @@ static long nfa_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm, int if (REG_MULTI) { prog = (nfa_regprog_T *)rex.reg_mmatch->regprog; - line = reg_getline((linenr_T)0); // relative to the cursor + line = (char_u *)reg_getline((linenr_T)0); // relative to the cursor rex.reg_startpos = rex.reg_mmatch->startpos; rex.reg_endpos = rex.reg_mmatch->endpos; } else { diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 321023bce2..fd32209310 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -104,7 +104,7 @@ estack_T *estack_push(etype_T type, char *name, linenr_T lnum) void estack_push_ufunc(ufunc_T *ufunc, linenr_T lnum) { estack_T *entry = estack_push(ETYPE_UFUNC, - ufunc->uf_name_exp != NULL ? (char *)ufunc->uf_name_exp : ufunc->uf_name, + ufunc->uf_name_exp != NULL ? ufunc->uf_name_exp : ufunc->uf_name, lnum); if (entry != NULL) { entry->es_info.ufunc = ufunc; diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 92d47fbf49..95151936c1 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1482,7 +1482,7 @@ static char *shada_filename(const char *file) if (p_shadafile != NULL && *p_shadafile != NUL) { file = p_shadafile; } else { - if ((file = (char *)find_shada_parameter('n')) == NULL || *file == NUL) { + if ((file = find_shada_parameter('n')) == NULL || *file == NUL) { file = shada_get_default_file(); } // XXX It used to be one level lower, so that whatever is in diff --git a/src/nvim/sign.c b/src/nvim/sign.c index e211b0069e..753c814110 100644 --- a/src/nvim/sign.c +++ b/src/nvim/sign.c @@ -99,7 +99,7 @@ static signgroup_T *sign_group_ref(const char *groupname) hashitem_T *hi; signgroup_T *group; - hash = hash_hash((char_u *)groupname); + hash = hash_hash(groupname); hi = hash_lookup(&sg_table, (char *)groupname, strlen(groupname), hash); if (HASHITEM_EMPTY(hi)) { // new group @@ -108,7 +108,7 @@ static signgroup_T *sign_group_ref(const char *groupname) STRCPY(group->sg_name, groupname); group->sg_refcount = 1; group->sg_next_sign_id = 1; - hash_add_item(&sg_table, hi, (char_u *)group->sg_name, hash); + hash_add_item(&sg_table, hi, group->sg_name, hash); } else { // existing group group = HI2SG(hi); diff --git a/src/nvim/spell.c b/src/nvim/spell.c index c17fafd3d7..e4c5779a08 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -123,7 +123,7 @@ enum { slang_T *first_lang = NULL; // file used for "zG" and "zW" -char_u *int_wordlist = NULL; +char *int_wordlist = NULL; // Structure to store info for word matching. typedef struct matchinf_S { @@ -131,9 +131,9 @@ typedef struct matchinf_S { // pointers to original text to be checked char *mi_word; // start of word being checked - char_u *mi_end; // end of matching word so far - char_u *mi_fend; // next char to be added to mi_fword - char_u *mi_cend; // char after what was used for + char *mi_end; // end of matching word so far + char *mi_fend; // next char to be added to mi_fword + char *mi_cend; // char after what was used for // mi_capflags // case-folded text @@ -161,12 +161,12 @@ typedef struct matchinf_S { // for NOBREAK int mi_result2; // "mi_result" without following word - char_u *mi_end2; // "mi_end" without following word + char *mi_end2; // "mi_end" without following word } matchinf_T; // Structure used for the cookie argument of do_in_runtimepath(). typedef struct spelload_S { - char_u sl_lang[MAXWLEN + 1]; // language name + char sl_lang[MAXWLEN + 1]; // language name slang_T *sl_slang; // resulting slang_T struct int sl_nobreak; // NOBREAK language found } spelload_T; @@ -242,23 +242,23 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount // julifeest". if (*ptr >= '0' && *ptr <= '9') { if (*ptr == '0' && (ptr[1] == 'b' || ptr[1] == 'B')) { - mi.mi_end = (char_u *)skipbin(ptr + 2); + mi.mi_end = (char *)skipbin(ptr + 2); } else if (*ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X')) { - mi.mi_end = (char_u *)skiphex(ptr + 2); + mi.mi_end = skiphex(ptr + 2); } else { - mi.mi_end = (char_u *)skipdigits(ptr); + mi.mi_end = skipdigits(ptr); } - nrlen = (size_t)(mi.mi_end - (char_u *)ptr); + nrlen = (size_t)(mi.mi_end - ptr); } // Find the normal end of the word (until the next non-word character). mi.mi_word = ptr; - mi.mi_fend = (char_u *)ptr; + mi.mi_fend = ptr; if (spell_iswordp(mi.mi_fend, wp)) { bool this_upper = false; // init for gcc if (use_camel_case) { - int c = utf_ptr2char((char *)mi.mi_fend); + int c = utf_ptr2char(mi.mi_fend); this_upper = SPELL_ISUPPER(c); } @@ -266,7 +266,7 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount MB_PTR_ADV(mi.mi_fend); if (use_camel_case) { const bool prev_upper = this_upper; - int c = utf_ptr2char((char *)mi.mi_fend); + int c = utf_ptr2char(mi.mi_fend); this_upper = SPELL_ISUPPER(c); camel_case = !prev_upper && this_upper; } @@ -277,7 +277,7 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount // Check word starting with capital letter. int c = utf_ptr2char(ptr); if (!SPELL_ISUPPER(c)) { - wrongcaplen = (size_t)(mi.mi_fend - (char_u *)ptr); + wrongcaplen = (size_t)(mi.mi_fend - ptr); } } } @@ -300,7 +300,7 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount MB_PTR_ADV(mi.mi_fend); } - (void)spell_casefold(wp, (char_u *)ptr, (int)(mi.mi_fend - (char_u *)ptr), (char_u *)mi.mi_fword, + (void)spell_casefold(wp, ptr, (int)(mi.mi_fend - ptr), mi.mi_fword, MAXWLEN + 1); mi.mi_fwordlen = (int)strlen(mi.mi_fword); @@ -345,7 +345,7 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount // Count the word in the first language where it's found to be OK. if (count_word && mi.mi_result == SP_OK) { count_common_word(mi.mi_lp->lp_slang, ptr, - (int)(mi.mi_end - (char_u *)ptr), 1); + (int)(mi.mi_end - ptr), 1); count_word = false; } } @@ -357,7 +357,7 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) { return nrlen; } - } else if (!spell_iswordp_nmw((char_u *)ptr, wp)) { + } else if (!spell_iswordp_nmw(ptr, wp)) { // When we are at a non-word character there is no error, just // skip over the character (try looking for a word after it). if (capcol != NULL && wp->w_s->b_cap_prog != NULL) { @@ -374,28 +374,28 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount } return (size_t)(utfc_ptr2len(ptr)); - } else if (mi.mi_end == (char_u *)ptr) { + } else if (mi.mi_end == ptr) { // Always include at least one character. Required for when there // is a mixup in "midword". MB_PTR_ADV(mi.mi_end); } else if (mi.mi_result == SP_BAD && LANGP_ENTRY(wp->w_s->b_langp, 0)->lp_slang->sl_nobreak) { - char_u *p, *fp; + char *p, *fp; int save_result = mi.mi_result; // First language in 'spelllang' is NOBREAK. Find first position // at which any word would be valid. mi.mi_lp = LANGP_ENTRY(wp->w_s->b_langp, 0); if (mi.mi_lp->lp_slang->sl_fidxs != NULL) { - p = (char_u *)mi.mi_word; - fp = (char_u *)mi.mi_fword; + p = mi.mi_word; + fp = mi.mi_fword; for (;;) { MB_PTR_ADV(p); MB_PTR_ADV(fp); if (p >= mi.mi_end) { break; } - mi.mi_compoff = (int)(fp - (char_u *)mi.mi_fword); + mi.mi_compoff = (int)(fp - mi.mi_fword); find_word(&mi, FIND_COMPOUND); if (mi.mi_result != SP_BAD) { mi.mi_end = p; @@ -421,7 +421,7 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount return wrongcaplen; } - return (size_t)(mi.mi_end - (char_u *)ptr); + return (size_t)(mi.mi_end - ptr); } // Check if the word at "mip->mi_word" is in the tree. @@ -444,7 +444,7 @@ static void find_word(matchinf_T *mip, int mode) // Check for word with matching case in keep-case tree. ptr = mip->mi_word; flen = 9999; // no case folding, always enough bytes - byts = slang->sl_kbyts; + byts = (char_u *)slang->sl_kbyts; idxs = slang->sl_kidxs; if (mode == FIND_KEEPCOMPOUND) { @@ -455,7 +455,7 @@ static void find_word(matchinf_T *mip, int mode) // Check for case-folded in case-folded tree. ptr = mip->mi_fword; flen = mip->mi_fwordlen; // available case-folded bytes - byts = slang->sl_fbyts; + byts = (char_u *)slang->sl_fbyts; idxs = slang->sl_fidxs; if (mode == FIND_PREFIX) { @@ -575,7 +575,7 @@ static void find_word(matchinf_T *mip, int mode) if (utf_head_off(ptr, ptr + wlen) > 0) { continue; // not at first byte of character } - if (spell_iswordp((char_u *)ptr + wlen, mip->mi_win)) { + if (spell_iswordp(ptr + wlen, mip->mi_win)) { if (slang->sl_compprog == NULL && !slang->sl_nobreak) { continue; // next char is a word character } @@ -612,11 +612,11 @@ static void find_word(matchinf_T *mip, int mode) // For keep-case tree the case is always right. For prefixes we // don't bother to check. if (mode == FIND_FOLDWORD) { - if (mip->mi_cend != (char_u *)mip->mi_word + wlen) { + if (mip->mi_cend != mip->mi_word + wlen) { // mi_capflags was set for a different word length, need // to do it again. - mip->mi_cend = (char_u *)mip->mi_word + wlen; - mip->mi_capflags = captype((char_u *)mip->mi_word, mip->mi_cend); + mip->mi_cend = mip->mi_word + wlen; + mip->mi_capflags = captype(mip->mi_word, mip->mi_cend); } if (mip->mi_capflags == WF_KEEPCAP @@ -629,7 +629,7 @@ static void find_word(matchinf_T *mip, int mode) // mip->mi_prefarridx that find_prefix() filled. c = valid_word_prefix(mip->mi_prefcnt, mip->mi_prefarridx, (int)flags, - (char_u *)mip->mi_word + mip->mi_cprefixlen, slang, + mip->mi_word + mip->mi_cprefixlen, slang, false); if (c == 0) { continue; @@ -687,7 +687,8 @@ static void find_word(matchinf_T *mip, int mode) } // Quickly check if compounding is possible with this flag. - if (!byte_in_str(mip->mi_complen == 0 ? slang->sl_compstartflags : slang->sl_compallflags, + if (!byte_in_str(mip->mi_complen == + 0 ? slang->sl_compstartflags : slang->sl_compallflags, (int)((unsigned)flags >> 24))) { continue; } @@ -712,7 +713,7 @@ static void find_word(matchinf_T *mip, int mode) } else { p = mip->mi_word + mip->mi_compoff; } - capflags = captype((char_u *)p, (char_u *)mip->mi_word + wlen); + capflags = captype(p, mip->mi_word + wlen); if (capflags == WF_KEEPCAP || (capflags == WF_ALLCAP && (flags & WF_FIXCAP) != 0)) { continue; @@ -724,7 +725,7 @@ static void find_word(matchinf_T *mip, int mode) // accept a no-caps word, even when the dictionary // word specifies ONECAP. MB_PTR_BACK(mip->mi_word, p); - if (spell_iswordp_nmw((char_u *)p, mip->mi_win) + if (spell_iswordp_nmw(p, mip->mi_win) ? capflags == WF_ONECAP : (flags & WF_ONECAP) != 0 && capflags != WF_ONECAP) { @@ -744,12 +745,12 @@ static void find_word(matchinf_T *mip, int mode) if (slang->sl_compsylmax < MAXWLEN) { // "fword" is only needed for checking syllables. if (ptr == mip->mi_word) { - (void)spell_casefold(mip->mi_win, (char_u *)ptr, wlen, (char_u *)fword, MAXWLEN); + (void)spell_casefold(mip->mi_win, ptr, wlen, fword, MAXWLEN); } else { xstrlcpy(fword, ptr, (size_t)endlen[endidxcnt] + 1); } } - if (!can_compound(slang, (char *)fword, mip->mi_compflags)) { + if (!can_compound(slang, fword, mip->mi_compflags)) { continue; } } else if (slang->sl_comprules != NULL @@ -767,7 +768,7 @@ static void find_word(matchinf_T *mip, int mode) if (!word_ends) { int save_result = mip->mi_result; - char_u *save_end = mip->mi_end; + char *save_end = mip->mi_end; langp_T *save_lp = mip->mi_lp; // Check that a valid word follows. If there is one and we @@ -878,16 +879,16 @@ static void find_word(matchinf_T *mip, int mode) if (nobreak_result == SP_BAD) { if (mip->mi_result2 > res) { mip->mi_result2 = res; - mip->mi_end2 = (char_u *)mip->mi_word + wlen; + mip->mi_end2 = mip->mi_word + wlen; } else if (mip->mi_result2 == res - && mip->mi_end2 < (char_u *)mip->mi_word + wlen) { - mip->mi_end2 = (char_u *)mip->mi_word + wlen; + && mip->mi_end2 < mip->mi_word + wlen) { + mip->mi_end2 = mip->mi_word + wlen; } } else if (mip->mi_result > res) { mip->mi_result = res; - mip->mi_end = (char_u *)mip->mi_word + wlen; - } else if (mip->mi_result == res && mip->mi_end < (char_u *)mip->mi_word + wlen) { - mip->mi_end = (char_u *)mip->mi_word + wlen; + mip->mi_end = mip->mi_word + wlen; + } else if (mip->mi_result == res && mip->mi_end < mip->mi_word + wlen) { + mip->mi_end = mip->mi_word + wlen; } if (mip->mi_result == SP_OK) { @@ -930,15 +931,15 @@ bool match_checkcompoundpattern(char *ptr, int wlen, garray_T *gap) bool can_compound(slang_T *slang, const char *word, const uint8_t *flags) FUNC_ATTR_NONNULL_ALL { - char_u uflags[MAXWLEN * 2] = { 0 }; + char uflags[MAXWLEN * 2] = { 0 }; if (slang->sl_compprog == NULL) { return false; } // Need to convert the single byte flags to utf8 characters. - char_u *p = uflags; + char *p = uflags; for (int i = 0; flags[i] != NUL; i++) { - p += utf_char2bytes(flags[i], (char *)p); + p += utf_char2bytes(flags[i], p); } *p = NUL; p = uflags; @@ -950,7 +951,7 @@ bool can_compound(slang_T *slang, const char *word, const uint8_t *flags) // are too many syllables AND the number of compound words is above // COMPOUNDWORDMAX then compounding is not allowed. if (slang->sl_compsylmax < MAXWLEN - && count_syllables(slang, (char_u *)word) > slang->sl_compsylmax) { + && count_syllables(slang, word) > slang->sl_compsylmax) { return (int)strlen((char *)flags) < slang->sl_compmax; } return true; @@ -963,7 +964,7 @@ bool can_compound(slang_T *slang, const char *word, const uint8_t *flags) bool match_compoundrule(slang_T *slang, const char_u *compflags) { // loop over all the COMPOUNDRULE entries - for (char_u *p = slang->sl_comprules; *p != NUL; p++) { + for (char_u *p = (char_u *)slang->sl_comprules; *p != NUL; p++) { // loop over the flags in the compound word we have made, match // them against the current rule entry for (int i = 0;; i++) { @@ -1013,7 +1014,7 @@ bool match_compoundrule(slang_T *slang, const char_u *compflags) /// @param totprefcnt nr of prefix IDs /// @param arridx idx in sl_pidxs[] /// @param cond_req only use prefixes with a condition -int valid_word_prefix(int totprefcnt, int arridx, int flags, char_u *word, slang_T *slang, +int valid_word_prefix(int totprefcnt, int arridx, int flags, char *word, slang_T *slang, bool cond_req) { int prefid = (int)((unsigned)flags >> 24); @@ -1061,7 +1062,7 @@ static void find_prefix(matchinf_T *mip, int mode) int wlen = 0; slang_T *slang = mip->mi_lp->lp_slang; - char_u *byts = slang->sl_pbyts; + char_u *byts = (char_u *)slang->sl_pbyts; if (byts == NULL) { return; // array is empty } @@ -1110,8 +1111,8 @@ static void find_prefix(matchinf_T *mip, int mode) } // Case-folded length may differ from original length. - mip->mi_cprefixlen = nofold_len((char_u *)mip->mi_fword, mip->mi_prefixlen, - (char_u *)mip->mi_word); + mip->mi_cprefixlen = nofold_len(mip->mi_fword, mip->mi_prefixlen, + mip->mi_word); find_word(mip, FIND_PREFIX); if (len == 0) { @@ -1157,7 +1158,7 @@ static void find_prefix(matchinf_T *mip, int mode) // Return the length of the folded chars in bytes. static int fold_more(matchinf_T *mip) { - char_u *p = mip->mi_fend; + char *p = mip->mi_fend; do { MB_PTR_ADV(mip->mi_fend); } while (*mip->mi_fend != NUL && spell_iswordp(mip->mi_fend, mip->mi_win)); @@ -1168,7 +1169,7 @@ static int fold_more(matchinf_T *mip) } (void)spell_casefold(mip->mi_win, p, (int)(mip->mi_fend - p), - (char_u *)mip->mi_fword + mip->mi_fwordlen, + mip->mi_fword + mip->mi_fwordlen, MAXWLEN - mip->mi_fwordlen); int flen = (int)strlen(mip->mi_fword + mip->mi_fwordlen); mip->mi_fwordlen += flen; @@ -1500,7 +1501,7 @@ void spell_cat_line(char *buf, char *line, int maxlen) // Load word list(s) for "lang" from Vim spell file(s). // "lang" must be the language without the region: e.g., "en". -static void spell_load_lang(char_u *lang) +static void spell_load_lang(char *lang) { char fname_enc[85]; int r; @@ -1520,18 +1521,18 @@ static void spell_load_lang(char_u *lang) // autocommand may load it then. for (int round = 1; round <= 2; round++) { // Find the first spell file for "lang" in 'runtimepath' and load it. - vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5, + vim_snprintf(fname_enc, sizeof(fname_enc) - 5, "spell/%s.%s.spl", lang, spell_enc()); - r = do_in_runtimepath((char *)fname_enc, 0, spell_load_cb, &sl); + r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl); if (r == FAIL && *sl.sl_lang != NUL) { // Try loading the ASCII version. - vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5, + vim_snprintf(fname_enc, sizeof(fname_enc) - 5, "spell/%s.ascii.spl", lang); - r = do_in_runtimepath((char *)fname_enc, 0, spell_load_cb, &sl); + r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl); if (r == FAIL && *sl.sl_lang != NUL && round == 1 - && apply_autocmds(EVENT_SPELLFILEMISSING, (char *)lang, + && apply_autocmds(EVENT_SPELLFILEMISSING, lang, curbuf->b_fname, false, curbuf)) { continue; } @@ -1556,7 +1557,7 @@ static void spell_load_lang(char_u *lang) } else if (sl.sl_slang != NULL) { // At least one file was loaded, now load ALL the additions. STRCPY(fname_enc + strlen(fname_enc) - 3, "add.spl"); - do_in_runtimepath((char *)fname_enc, DIP_ALL, spell_load_cb, &sl); + do_in_runtimepath(fname_enc, DIP_ALL, spell_load_cb, &sl); } curbuf->b_locked--; @@ -1564,19 +1565,19 @@ static void spell_load_lang(char_u *lang) // Return the encoding used for spell checking: Use 'encoding', except that we // use "latin1" for "latin9". And limit to 60 characters (just in case). -char_u *spell_enc(void) +char *spell_enc(void) { if (strlen(p_enc) < 60 && strcmp(p_enc, "iso-8859-15") != 0) { - return (char_u *)p_enc; + return p_enc; } - return (char_u *)"latin1"; + return "latin1"; } // Get the name of the .spl file for the internal wordlist into // "fname[MAXPATHL]". -static void int_wordlist_spl(char_u *fname) +static void int_wordlist_spl(char *fname) { - vim_snprintf((char *)fname, MAXPATHL, SPL_FNAME_TMPL, + vim_snprintf(fname, MAXPATHL, SPL_FNAME_TMPL, int_wordlist, spell_enc()); } @@ -1700,7 +1701,7 @@ void slang_clear_sug(slang_T *lp) static void spell_load_cb(char *fname, void *cookie) { spelload_T *slp = (spelload_T *)cookie; - slang_T *slang = spell_load_file(fname, (char *)slp->sl_lang, NULL, false); + slang_T *slang = spell_load_file(fname, slp->sl_lang, NULL, false); if (slang != NULL) { // When a previously loaded file has NOBREAK also use it for the // ".add" files. @@ -1736,14 +1737,14 @@ void count_common_word(slang_T *lp, char *word, int len, uint8_t count) } wordcount_T *wc; - hash_T hash = hash_hash((char_u *)p); + hash_T hash = hash_hash(p); const size_t p_len = strlen(p); hashitem_T *hi = hash_lookup(&lp->sl_wordcount, (const char *)p, p_len, hash); if (HASHITEM_EMPTY(hi)) { wc = xmalloc(sizeof(wordcount_T) + p_len); memcpy(wc->wc_word, p, p_len + 1); wc->wc_count = count; - hash_add_item(&lp->sl_wordcount, hi, wc->wc_word, hash); + hash_add_item(&lp->sl_wordcount, hi, (char *)wc->wc_word, hash); } else { wc = HI2WC(hi); wc->wc_count = (uint16_t)(wc->wc_count + count); @@ -1755,9 +1756,9 @@ void count_common_word(slang_T *lp, char *word, int len, uint8_t count) // Returns true if byte "n" appears in "str". // Like strchr() but independent of locale. -bool byte_in_str(char_u *str, int n) +bool byte_in_str(uint8_t *str, int n) { - for (char_u *p = str; *p != NUL; p++) { + for (uint8_t *p = str; *p != NUL; p++) { if (*p == n) { return true; } @@ -1798,7 +1799,7 @@ int init_syl_tab(slang_T *slang) // Count the number of syllables in "word". // When "word" contains spaces the syllables after the last space are counted. // Returns zero if syllables are not defines. -static int count_syllables(slang_T *slang, const char_u *word) +static int count_syllables(slang_T *slang, const char *word) FUNC_ATTR_NONNULL_ALL { int cnt = 0; @@ -1809,7 +1810,7 @@ static int count_syllables(slang_T *slang, const char_u *word) return 0; } - for (const char *p = (char *)word; *p != NUL; p += len) { + for (const char *p = word; *p != NUL; p += len) { // When running into a space reset counter. if (*p == ' ') { len = 1; @@ -1893,11 +1894,11 @@ char *did_set_spelllang(win_T *wp) // Loop over comma separated language names. for (splp = spl_copy; *splp != NUL;) { // Get one language name. - copy_option_part(&splp, (char *)lang, MAXWLEN, ","); + copy_option_part(&splp, lang, MAXWLEN, ","); region = NULL; len = (int)strlen(lang); - if (!valid_spelllang((char *)lang)) { + if (!valid_spelllang(lang)) { continue; } @@ -1913,7 +1914,7 @@ char *did_set_spelllang(win_T *wp) filename = true; // Locate a region and remove it from the file name. - p = vim_strchr(path_tail((char *)lang), '_'); + p = vim_strchr(path_tail(lang), '_'); if (p != NULL && ASCII_ISALPHA(p[1]) && ASCII_ISALPHA(p[2]) && !ASCII_ISALPHA(p[3])) { xstrlcpy(region_cp, p + 1, 3); @@ -1925,7 +1926,7 @@ char *did_set_spelllang(win_T *wp) // Check if we loaded this language before. for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (path_full_compare((char *)lang, slang->sl_fname, false, true) + if (path_full_compare(lang, slang->sl_fname, false, true) == kEqualFiles) { break; } @@ -1959,9 +1960,9 @@ char *did_set_spelllang(win_T *wp) // If not found try loading the language now. if (slang == NULL) { if (filename) { - (void)spell_load_file((char *)lang, (char *)lang, NULL, false); + (void)spell_load_file(lang, lang, NULL, false); } else { - spell_load_lang((char_u *)lang); + spell_load_lang(lang); // SpellFileMissing autocommands may do anything, including // destroying the buffer we are using or closing the window. if (!bufref_valid(&bufref) || !win_valid_any_tab(wp)) { @@ -1974,12 +1975,12 @@ char *did_set_spelllang(win_T *wp) // Loop over the languages, there can be several files for "lang". for (slang = first_lang; slang != NULL; slang = slang->sl_next) { if (filename - ? path_full_compare((char *)lang, slang->sl_fname, false, true) == kEqualFiles + ? path_full_compare(lang, slang->sl_fname, false, true) == kEqualFiles : STRICMP(lang, slang->sl_name) == 0) { region_mask = REGION_ALL; if (!filename && region != NULL) { // find region in sl_regions - c = find_region(slang->sl_regions, (char_u *)region); + c = find_region(slang->sl_regions, region); if (c == REGION_ALL) { if (slang->sl_add) { if (*slang->sl_regions != NUL) { @@ -2022,17 +2023,17 @@ char *did_set_spelllang(win_T *wp) if (int_wordlist == NULL) { continue; } - int_wordlist_spl((char_u *)spf_name); + int_wordlist_spl(spf_name); } else { // One entry in 'spellfile'. - copy_option_part(&spf, (char *)spf_name, MAXPATHL - 5, ","); + copy_option_part(&spf, spf_name, MAXPATHL - 5, ","); STRCAT(spf_name, ".spl"); // If it was already found above then skip it. for (c = 0; c < ga.ga_len; c++) { p = LANGP_ENTRY(ga, c)->lp_slang->sl_fname; if (p != NULL - && path_full_compare((char *)spf_name, p, false, true) == kEqualFiles) { + && path_full_compare(spf_name, p, false, true) == kEqualFiles) { break; } } @@ -2043,7 +2044,7 @@ char *did_set_spelllang(win_T *wp) // Check if it was loaded already. for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (path_full_compare((char *)spf_name, slang->sl_fname, false, true) + if (path_full_compare(spf_name, slang->sl_fname, false, true) == kEqualFiles) { break; } @@ -2055,13 +2056,13 @@ char *did_set_spelllang(win_T *wp) if (round == 0) { STRCPY(lang, "internal wordlist"); } else { - xstrlcpy(lang, path_tail((char *)spf_name), MAXWLEN + 1); - p = vim_strchr((char *)lang, '.'); + xstrlcpy(lang, path_tail(spf_name), MAXWLEN + 1); + p = vim_strchr(lang, '.'); if (p != NULL) { *p = NUL; // truncate at ".encoding.add" } } - slang = spell_load_file((char *)spf_name, (char *)lang, NULL, true); + slang = spell_load_file(spf_name, lang, NULL, true); // If one of the languages has NOBREAK we assume the addition // files also have this. @@ -2073,7 +2074,7 @@ char *did_set_spelllang(win_T *wp) region_mask = REGION_ALL; if (use_region != NULL && !dont_use_region) { // find region in sl_regions - c = find_region(slang->sl_regions, (char_u *)use_region); + c = find_region(slang->sl_regions, use_region); if (c != REGION_ALL) { region_mask = 1 << c; } else if (*slang->sl_regions != NUL) { @@ -2185,7 +2186,7 @@ static void use_midword(slang_T *lp, win_T *wp) // Find the region "region[2]" in "rp" (points to "sl_regions"). // Each region is simply stored as the two characters of its name. // Returns the index if found (first is 0), REGION_ALL if not found. -static int find_region(const char_u *rp, const char_u *region) +static int find_region(const char *rp, const char *region) { int i; @@ -2210,14 +2211,14 @@ static int find_region(const char_u *rp, const char_u *region) /// @param[in] end End of word or NULL for NUL delimited string /// /// @returns Case type of word -int captype(char_u *word, const char_u *end) +int captype(char *word, const char *end) FUNC_ATTR_NONNULL_ARG(1) { char *p; // find first letter - for (p = (char *)word; !spell_iswordp_nmw((char_u *)p, curwin); MB_PTR_ADV(p)) { - if (end == NULL ? *p == NUL : (char_u *)p >= end) { + for (p = word; !spell_iswordp_nmw(p, curwin); MB_PTR_ADV(p)) { + if (end == NULL ? *p == NUL : p >= end) { return 0; // only non-word characters, illegal word } } @@ -2228,8 +2229,8 @@ int captype(char_u *word, const char_u *end) // Need to check all letters to find a word with mixed upper/lower. // But a word with an upper char only at start is a ONECAP. - for (; end == NULL ? *p != NUL : (char_u *)p < end; MB_PTR_ADV(p)) { - if (spell_iswordp_nmw((char_u *)p, curwin)) { + for (; end == NULL ? *p != NUL : p < end; MB_PTR_ADV(p)) { + if (spell_iswordp_nmw(p, curwin)) { c = utf_ptr2char(p); if (!SPELL_ISUPPER(c)) { // UUl -> KEEPCAP @@ -2258,10 +2259,10 @@ int captype(char_u *word, const char_u *end) void spell_delete_wordlist(void) { if (int_wordlist != NULL) { - char_u fname[MAXPATHL] = { 0 }; - os_remove((char *)int_wordlist); + char fname[MAXPATHL] = { 0 }; + os_remove(int_wordlist); int_wordlist_spl(fname); - os_remove((char *)fname); + os_remove(fname); XFREE_CLEAR(int_wordlist); } } @@ -2393,18 +2394,18 @@ void init_spell_chartab(void) /// Thus this only works properly when past the first character of the word. /// /// @param wp Buffer used. -bool spell_iswordp(const char_u *p, const win_T *wp) +bool spell_iswordp(const char *p, const win_T *wp) FUNC_ATTR_NONNULL_ALL { - const int l = utfc_ptr2len((char *)p); - const char_u *s = p; + const int l = utfc_ptr2len(p); + const char *s = p; if (l == 1) { // be quick for ASCII - if (wp->w_s->b_spell_ismw[*p]) { + if (wp->w_s->b_spell_ismw[(uint8_t)(*p)]) { s = p + 1; // skip a mid-word character } } else { - int c = utf_ptr2char((char *)p); + int c = utf_ptr2char(p); if (c < 256 ? wp->w_s->b_spell_ismw[c] : (wp->w_s->b_spell_ismw_mb != NULL @@ -2413,20 +2414,20 @@ bool spell_iswordp(const char_u *p, const win_T *wp) } } - int c = utf_ptr2char((char *)s); + int c = utf_ptr2char(s); if (c > 255) { - return spell_mb_isword_class(mb_get_class((char *)s), wp); + return spell_mb_isword_class(mb_get_class(s), wp); } return spelltab.st_isw[c]; } // Returns true if "p" points to a word character. // Unlike spell_iswordp() this doesn't check for "midword" characters. -bool spell_iswordp_nmw(const char_u *p, win_T *wp) +bool spell_iswordp_nmw(const char *p, win_T *wp) { - int c = utf_ptr2char((char *)p); + int c = utf_ptr2char(p); if (c > 255) { - return spell_mb_isword_class(mb_get_class((char *)p), wp); + return spell_mb_isword_class(mb_get_class(p), wp); } return spelltab.st_isw[c]; } @@ -2471,7 +2472,7 @@ static bool spell_iswordp_w(const int *p, const win_T *wp) // Uses the character definitions from the .spl file. // When using a multi-byte 'encoding' the length may change! // Returns FAIL when something wrong. -int spell_casefold(const win_T *wp, char_u *str, int len, char_u *buf, int buflen) +int spell_casefold(const win_T *wp, char *str, int len, char *buf, int buflen) FUNC_ATTR_NONNULL_ALL { if (len >= buflen) { @@ -2482,7 +2483,7 @@ int spell_casefold(const win_T *wp, char_u *str, int len, char_u *buf, int bufle int outi = 0; // Fold one character at a time. - for (char *p = (char *)str; (char_u *)p < str + len;) { + for (char *p = str; p < str + len;) { if (outi + MB_MAXBYTES > buflen) { buf[outi] = NUL; return FAIL; @@ -2493,7 +2494,7 @@ int spell_casefold(const win_T *wp, char_u *str, int len, char_u *buf, int bufle // when it is the last character in a word, then it folds to // 0x03C2. if (c == 0x03a3 || c == 0x03c2) { - if (p == (char *)str + len || !spell_iswordp((char_u *)p, wp)) { + if (p == str + len || !spell_iswordp(p, wp)) { c = 0x03c2; } else { c = 0x03c3; @@ -2502,7 +2503,7 @@ int spell_casefold(const win_T *wp, char_u *str, int len, char_u *buf, int bufle c = SPELL_TOFOLD(c); } - outi += utf_char2bytes(c, (char *)buf + outi); + outi += utf_char2bytes(c, buf + outi); } buf[outi] = NUL; @@ -2551,7 +2552,7 @@ bool check_need_cap(linenr_T lnum, colnr_T col) char *p = line + endcol; for (;;) { MB_PTR_BACK(line, p); - if (p == line || spell_iswordp_nmw((char_u *)p, curwin)) { + if (p == line || spell_iswordp_nmw(p, curwin)) { break; } if (vim_regexec(®match, p, 0) @@ -2582,15 +2583,15 @@ void ex_spellrepall(exarg_T *eap) int addlen = (int)(strlen(repl_to) - strlen(repl_from)); size_t frompatlen = strlen(repl_from) + 7; - char_u *frompat = xmalloc(frompatlen); - snprintf((char *)frompat, frompatlen, "\\V\\<%s\\>", repl_from); + char *frompat = xmalloc(frompatlen); + snprintf(frompat, frompatlen, "\\V\\<%s\\>", repl_from); p_ws = false; sub_nsubs = 0; sub_nlines = 0; curwin->w_cursor.lnum = 0; while (!got_int) { - if (do_search(NULL, '/', '/', (char *)frompat, 1L, SEARCH_KEEP, NULL) == 0 + if (do_search(NULL, '/', '/', frompat, 1L, SEARCH_KEEP, NULL) == 0 || u_save_cursor() == FAIL) { break; } @@ -2600,11 +2601,11 @@ void ex_spellrepall(exarg_T *eap) char *line = get_cursor_line_ptr(); if (addlen <= 0 || strncmp(line + curwin->w_cursor.col, repl_to, strlen(repl_to)) != 0) { - char_u *p = xmalloc(strlen(line) + (size_t)addlen + 1); + char *p = xmalloc(strlen(line) + (size_t)addlen + 1); memmove(p, line, (size_t)curwin->w_cursor.col); STRCPY(p + curwin->w_cursor.col, repl_to); STRCAT(p, line + curwin->w_cursor.col + strlen(repl_from)); - ml_replace(curwin->w_cursor.lnum, (char *)p, false); + ml_replace(curwin->w_cursor.lnum, p, false); changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); if (curwin->w_cursor.lnum != prev_lnum) { @@ -2634,9 +2635,9 @@ void ex_spellrepall(exarg_T *eap) /// @param[in] word source string to copy /// @param[in,out] wcopy copied string, with case of first letter changed /// @param[in] upper True to upper case, otherwise lower case -void onecap_copy(char_u *word, char *wcopy, bool upper) +void onecap_copy(char *word, char *wcopy, bool upper) { - char *p = (char *)word; + char *p = word; int c = mb_cptr2char_adv((const char **)&p); if (upper) { c = SPELL_TOUPPER(c); @@ -2649,15 +2650,15 @@ void onecap_copy(char_u *word, char *wcopy, bool upper) // Make a copy of "word" with all the letters upper cased into // "wcopy[MAXWLEN]". The result is NUL terminated. -void allcap_copy(char_u *word, char_u *wcopy) +void allcap_copy(char *word, char *wcopy) { - char_u *d = wcopy; - for (char *s = (char *)word; *s != NUL;) { + char_u *d = (char_u *)wcopy; + for (char *s = word; *s != NUL;) { int c = mb_cptr2char_adv((const char **)&s); if (c == 0xdf) { c = 'S'; - if (d - wcopy >= MAXWLEN - 1) { + if (d - (char_u *)wcopy >= MAXWLEN - 1) { break; } *d++ = (char_u)c; @@ -2665,7 +2666,7 @@ void allcap_copy(char_u *word, char_u *wcopy) c = SPELL_TOUPPER(c); } - if (d - wcopy >= MAXWLEN - MB_MAXBYTES) { + if (d - (char_u *)wcopy >= MAXWLEN - MB_MAXBYTES) { break; } d += utf_char2bytes(c, (char *)d); @@ -2675,9 +2676,9 @@ void allcap_copy(char_u *word, char_u *wcopy) // Case-folding may change the number of bytes: Count nr of chars in // fword[flen] and return the byte length of that many chars in "word". -int nofold_len(char_u *fword, int flen, char_u *word) +int nofold_len(char *fword, int flen, char *word) { - char_u *p; + char *p; int i = 0; for (p = fword; p < fword + flen; MB_PTR_ADV(p)) { @@ -2690,14 +2691,14 @@ int nofold_len(char_u *fword, int flen, char_u *word) } // Copy "fword" to "cword", fixing case according to "flags". -void make_case_word(char_u *fword, char_u *cword, int flags) +void make_case_word(char *fword, char *cword, int flags) { if (flags & WF_ALLCAP) { // Make it all upper-case allcap_copy(fword, cword); } else if (flags & WF_ONECAP) { // Make the first letter upper-case - onecap_copy(fword, (char *)cword, true); + onecap_copy(fword, cword, true); } else { // Use goodword as-is. STRCPY(cword, fword); @@ -2720,9 +2721,9 @@ char *eval_soundfold(const char *const word) langp_T *const lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); if (!GA_EMPTY(&lp->lp_slang->sl_sal)) { // soundfold the word - char_u sound[MAXWLEN]; - spell_soundfold(lp->lp_slang, (char *)word, false, (char *)sound); - return xstrdup((const char *)sound); + char sound[MAXWLEN]; + spell_soundfold(lp->lp_slang, (char *)word, false, sound); + return xstrdup(sound); } } } @@ -2750,7 +2751,7 @@ void spell_soundfold(slang_T *slang, char *inword, bool folded, char *res) { if (slang->sl_sofo) { // SOFOFROM and SOFOTO used - spell_soundfold_sofo(slang, (char_u *)inword, (char_u *)res); + spell_soundfold_sofo(slang, inword, res); } else { char fword[MAXWLEN]; char *word; @@ -2758,17 +2759,17 @@ void spell_soundfold(slang_T *slang, char *inword, bool folded, char *res) if (folded) { word = inword; } else { - (void)spell_casefold(curwin, (char_u *)inword, (int)strlen(inword), (char_u *)fword, MAXWLEN); + (void)spell_casefold(curwin, inword, (int)strlen(inword), fword, MAXWLEN); word = fword; } - spell_soundfold_wsal(slang, (char_u *)word, (char_u *)res); + spell_soundfold_wsal(slang, word, res); } } // Perform sound folding of "inword" into "res" according to SOFOFROM and // SOFOTO lines. -static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) +static void spell_soundfold_sofo(slang_T *slang, char *inword, char *res) { int ri = 0; @@ -2776,7 +2777,7 @@ static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) // The sl_sal_first[] table contains the translation for chars up to // 255, sl_sal the rest. - for (char *s = (char *)inword; *s != NUL;) { + for (char *s = inword; *s != NUL;) { int c = mb_cptr2char_adv((const char **)&s); if (utf_class(c) == 0) { c = ' '; @@ -2802,7 +2803,7 @@ static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) } if (c != NUL && c != prevc) { - ri += utf_char2bytes(c, (char *)res + ri); + ri += utf_char2bytes(c, res + ri); if (ri + MB_MAXBYTES > MAXWLEN) { break; } @@ -2815,7 +2816,7 @@ static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) // Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]". // Multi-byte version of spell_soundfold(). -static void spell_soundfold_wsal(slang_T *slang, const char_u *inword, char_u *res) +static void spell_soundfold_wsal(slang_T *slang, const char *inword, char *res) { salitem_T *smp = (salitem_T *)slang->sl_sal.ga_data; int word[MAXWLEN] = { 0 }; @@ -2849,7 +2850,7 @@ static void spell_soundfold_wsal(slang_T *slang, const char_u *inword, char_u *r did_white = true; } else { did_white = false; - if (!spell_iswordp_nmw(t, curwin)) { + if (!spell_iswordp_nmw((char *)t, curwin)) { continue; } } @@ -2906,7 +2907,7 @@ static void spell_soundfold_wsal(slang_T *slang, const char_u *inword, char_u *r } k++; } - char_u *s = smp[n].sm_rules; + char_u *s = (char_u *)smp[n].sm_rules; pri = 5; // default priority p0 = *s; @@ -2983,7 +2984,7 @@ static void spell_soundfold_wsal(slang_T *slang, const char_u *inword, char_u *r } p0 = 5; - s = smp[n0].sm_rules; + s = (char_u *)smp[n0].sm_rules; while (*s == '-') { // "k0" gets NOT reduced because // "if (k0 == k)" @@ -3024,7 +3025,7 @@ static void spell_soundfold_wsal(slang_T *slang, const char_u *inword, char_u *r // replace string ws = smp[n].sm_to_w; - s = smp[n].sm_rules; + s = (char_u *)smp[n].sm_rules; p0 = (vim_strchr((char *)s, '<') != NULL) ? 1 : 0; if (p0 == 1 && z == 0) { // rule with '<' is used @@ -3102,7 +3103,7 @@ static void spell_soundfold_wsal(slang_T *slang, const char_u *inword, char_u *r // Convert wide characters in "wres" to a multi-byte string in "res". int l = 0; for (int n = 0; n < reslen; n++) { - l += utf_char2bytes(wres[n], (char *)res + l); + l += utf_char2bytes(wres[n], res + l); if (l + MB_MAXBYTES > MAXWLEN) { break; } @@ -3204,7 +3205,7 @@ void spell_dump_compl(char *pat, int ic, Direction *dir, int dumpflags_arg) if (ic) { dumpflags |= DUMPFLAG_ICASE; } else { - n = captype((char_u *)pat, NULL); + n = captype(pat, NULL); if (n == WF_ONECAP) { dumpflags |= DUMPFLAG_ONECAP; } else if (n == WF_ALLCAP @@ -3218,7 +3219,7 @@ void spell_dump_compl(char *pat, int ic, Direction *dir, int dumpflags_arg) // regions or none at all. for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) { lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); - p = (char *)lp->lp_slang->sl_regions; + p = lp->lp_slang->sl_regions; if (p[0] != 0) { if (region_names == NULL) { // first language with regions region_names = p; @@ -3264,11 +3265,11 @@ void spell_dump_compl(char *pat, int ic, Direction *dir, int dumpflags_arg) for (int round = 1; round <= 2; round++) { if (round == 1) { dumpflags &= ~DUMPFLAG_KEEPCASE; - byts = (char *)slang->sl_fbyts; + byts = slang->sl_fbyts; idxs = slang->sl_fidxs; } else { dumpflags |= DUMPFLAG_KEEPCASE; - byts = (char *)slang->sl_kbyts; + byts = slang->sl_kbyts; idxs = slang->sl_kidxs; } if (byts == NULL) { @@ -3319,7 +3320,7 @@ void spell_dump_compl(char *pat, int ic, Direction *dir, int dumpflags_arg) // Apply the prefix, if there is one. if (c != 0) { - lnum = dump_prefixes(slang, word, (char_u *)pat, dir, + lnum = dump_prefixes(slang, word, pat, dir, dumpflags, flags, lnum); } } @@ -3337,7 +3338,7 @@ void spell_dump_compl(char *pat, int ic, Direction *dir, int dumpflags_arg) // ignore case... assert(depth >= 0); if (depth <= patlen - && mb_strnicmp((char *)word, pat, (size_t)depth) != 0) { + && mb_strnicmp(word, pat, (size_t)depth) != 0) { depth--; } } @@ -3367,12 +3368,12 @@ static void dump_word(slang_T *slang, char *word, char *pat, Direction *dir, int if ((dumpflags & DUMPFLAG_KEEPCASE) == 0 && (flags & WF_CAPMASK) != 0) { // Need to fix case according to "flags". - make_case_word((char_u *)word, (char_u *)cword, flags); + make_case_word(word, cword, flags); p = cword; } else { p = word; if ((dumpflags & DUMPFLAG_KEEPCASE) - && ((captype((char_u *)word, NULL) & WF_KEEPCAP) == 0 + && ((captype(word, NULL) & WF_KEEPCAP) == 0 || (flags & WF_FIXCAP) != 0)) { keepcap = true; } @@ -3436,8 +3437,8 @@ static void dump_word(slang_T *slang, char *word, char *pat, Direction *dir, int /// @param flags flags with prefix ID /// /// @return the updated line number. -static linenr_T dump_prefixes(slang_T *slang, char *word, char_u *pat, Direction *dir, - int dumpflags, int flags, linenr_T startlnum) +static linenr_T dump_prefixes(slang_T *slang, char *word, char *pat, Direction *dir, int dumpflags, + int flags, linenr_T startlnum) { idx_T arridx[MAXWLEN]; int curi[MAXWLEN]; @@ -3450,11 +3451,11 @@ static linenr_T dump_prefixes(slang_T *slang, char *word, char_u *pat, Direction // upper-case letter in word_up[]. int c = utf_ptr2char(word); if (SPELL_TOUPPER(c) != c) { - onecap_copy((char_u *)word, (char *)word_up, true); + onecap_copy(word, word_up, true); has_word_up = true; } - char_u *byts = slang->sl_pbyts; + char_u *byts = (char_u *)slang->sl_pbyts; idx_T *idxs = slang->sl_pidxs; if (byts != NULL) { // array not is empty // Loop over all prefixes, building them byte-by-byte in prefix[]. @@ -3484,10 +3485,10 @@ static linenr_T dump_prefixes(slang_T *slang, char *word, char_u *pat, Direction } curi[depth] += i - 1; - c = valid_word_prefix(i, n, flags, (char_u *)word, slang, false); + c = valid_word_prefix(i, n, flags, word, slang, false); if (c != 0) { xstrlcpy(prefix + depth, word, (size_t)(MAXWLEN - depth)); - dump_word(slang, (char *)prefix, (char *)pat, dir, dumpflags, + dump_word(slang, prefix, pat, dir, dumpflags, (c & WF_RAREPFX) ? (flags | WF_RARE) : flags, lnum); if (lnum != 0) { lnum++; @@ -3498,11 +3499,10 @@ static linenr_T dump_prefixes(slang_T *slang, char *word, char_u *pat, Direction // first letter is upper-case, but only if the prefix has // a condition. if (has_word_up) { - c = valid_word_prefix(i, n, flags, (char_u *)word_up, slang, - true); + c = valid_word_prefix(i, n, flags, word_up, slang, true); if (c != 0) { xstrlcpy(prefix + depth, word_up, (size_t)(MAXWLEN - depth)); - dump_word(slang, (char *)prefix, (char *)pat, dir, dumpflags, + dump_word(slang, prefix, pat, dir, dumpflags, (c & WF_RAREPFX) ? (flags | WF_RARE) : flags, lnum); if (lnum != 0) { lnum++; @@ -3528,7 +3528,7 @@ char *spell_to_word_end(char *start, win_T *win) { char *p = start; - while (*p != NUL && spell_iswordp((char_u *)p, win)) { + while (*p != NUL && spell_iswordp(p, win)) { MB_PTR_ADV(p); } return p; @@ -3545,8 +3545,8 @@ int spell_word_start(int startcol) return startcol; } - char_u *line = (char_u *)get_cursor_line_ptr(); - char_u *p; + char *line = get_cursor_line_ptr(); + char *p; // Find a word character before "startcol". for (p = line + startcol; p > line;) { @@ -3588,7 +3588,7 @@ int expand_spelling(linenr_T lnum, char *pat, char ***matchp) { garray_T ga; - spell_suggest_list(&ga, (char_u *)pat, 100, spell_expand_need_cap, true); + spell_suggest_list(&ga, pat, 100, spell_expand_need_cap, true); *matchp = ga.ga_data; return ga.ga_len; } diff --git a/src/nvim/spell_defs.h b/src/nvim/spell_defs.h index 4d146a1706..726af7d698 100644 --- a/src/nvim/spell_defs.h +++ b/src/nvim/spell_defs.h @@ -80,11 +80,11 @@ typedef struct fromto_S { // The info is split for quick processing by spell_soundfold(). // Note that "sm_oneof" and "sm_rules" point into sm_lead. typedef struct salitem_S { - char_u *sm_lead; // leading letters - int sm_leadlen; // length of "sm_lead" - char_u *sm_oneof; // letters from () or NULL - char_u *sm_rules; // rules like ^, $, priority - char_u *sm_to; // replacement. + char *sm_lead; // leading letters + int sm_leadlen; // length of "sm_lead" + char_u *sm_oneof; // letters from () or NULL + char *sm_rules; // rules like ^, $, priority + char *sm_to; // replacement. int *sm_lead_w; // wide character copy of "sm_lead" int *sm_oneof_w; // wide character copy of "sm_oneof" int *sm_to_w; // wide character copy of "sm_to" @@ -119,17 +119,17 @@ struct slang_S { char *sl_fname; // name of .spl file bool sl_add; // true if it's a .add file. - char_u *sl_fbyts; // case-folded word bytes + char *sl_fbyts; // case-folded word bytes long sl_fbyts_len; // length of sl_fbyts idx_T *sl_fidxs; // case-folded word indexes - char_u *sl_kbyts; // keep-case word bytes + char *sl_kbyts; // keep-case word bytes idx_T *sl_kidxs; // keep-case word indexes - char_u *sl_pbyts; // prefix tree word bytes + char *sl_pbyts; // prefix tree word bytes idx_T *sl_pidxs; // prefix tree word indexes char_u *sl_info; // infotext string or NULL - char_u sl_regions[MAXREGIONS * 2 + 1]; + char sl_regions[MAXREGIONS * 2 + 1]; // table with up to 8 region names plus NUL char_u *sl_midword; // MIDWORD string or NULL @@ -143,9 +143,9 @@ struct slang_S { garray_T sl_comppat; // CHECKCOMPOUNDPATTERN items regprog_T *sl_compprog; // COMPOUNDRULE turned into a regexp progrm // (NULL when no compounding) - char_u *sl_comprules; // all COMPOUNDRULE concatenated (or NULL) - char_u *sl_compstartflags; // flags for first compound word - char_u *sl_compallflags; // all flags for compound words + uint8_t *sl_comprules; // all COMPOUNDRULE concatenated (or NULL) + uint8_t *sl_compstartflags; // flags for first compound word + uint8_t *sl_compallflags; // all flags for compound words bool sl_nobreak; // When true: no spaces between words char_u *sl_syllable; // SYLLABLE repeatable chars or NULL garray_T sl_syl_items; // syllable items @@ -172,7 +172,7 @@ struct slang_S { // Info from the .sug file. Loaded on demand. time_t sl_sugtime; // timestamp for .sug file - char_u *sl_sbyts; // soundfolded word bytes + char *sl_sbyts; // soundfolded word bytes idx_T *sl_sidxs; // soundfolded word indexes buf_T *sl_sugbuf; // buffer with word number table bool sl_sugloaded; // true when .sug file was loaded or failed to @@ -227,7 +227,7 @@ typedef struct { extern slang_T *first_lang; // file used for "zG" and "zW" -extern char_u *int_wordlist; +extern char *int_wordlist; extern spelltab_T spelltab; extern int did_set_spelltab; diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 6f5bd836b1..4725c9aea6 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -336,7 +336,7 @@ static char *msg_compressing = N_("Compressing word tree..."); // and .dic file. // Main structure to store the contents of a ".aff" file. typedef struct afffile_S { - char_u *af_enc; // "SET", normalized, alloc'ed string or NULL + char *af_enc; // "SET", normalized, alloc'ed string or NULL int af_flagtype; // AFT_CHAR, AFT_LONG, AFT_NUM or AFT_CAPLONG unsigned af_rare; // RARE ID for rare word unsigned af_keepcase; // KEEPCASE ID for keep-case word @@ -364,12 +364,12 @@ typedef struct afffile_S { typedef struct affentry_S affentry_T; // Affix entry from ".aff" file. Used for prefixes and suffixes. struct affentry_S { - affentry_T *ae_next; // next affix with same name/number - char *ae_chop; // text to chop off basic word (can be NULL) - char *ae_add; // text to add to basic word (can be NULL) - char_u *ae_flags; // flags on the affix (can be NULL) - char_u *ae_cond; // condition (NULL for ".") - regprog_T *ae_prog; // regexp program for ae_cond or NULL + affentry_T *ae_next; // next affix with same name/number + char *ae_chop; // text to chop off basic word (can be NULL) + char *ae_add; // text to add to basic word (can be NULL) + char *ae_flags; // flags on the affix (can be NULL) + char *ae_cond; // condition (NULL for ".") + regprog_T *ae_prog; // regexp program for ae_cond or NULL char ae_compforbid; // COMPOUNDFORBIDFLAG found char ae_comppermit; // COMPOUNDPERMITFLAG found }; @@ -724,7 +724,7 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent) if (p == NULL) { goto endFAIL; } - set_map_str(lp, (char_u *)p); + set_map_str(lp, p); xfree(p); break; @@ -1004,8 +1004,8 @@ someerror: // Need to put word counts in the word tries, so that we can find // a word by its number. - tree_count_words(slang->sl_fbyts, slang->sl_fidxs); - tree_count_words(slang->sl_sbyts, slang->sl_sidxs); + tree_count_words((char_u *)slang->sl_fbyts, slang->sl_fidxs); + tree_count_words((char_u *)slang->sl_sbyts, slang->sl_sidxs); nextone: if (fd != NULL) { @@ -1054,7 +1054,7 @@ static int read_region_section(FILE *fd, slang_T *lp, int len) if (len > MAXREGIONS * 2) { return SP_FORMERROR; } - SPELL_READ_NONNUL_BYTES((char *)lp->sl_regions, (size_t)len, fd,; ); // NOLINT(whitespace/parens) + SPELL_READ_NONNUL_BYTES(lp->sl_regions, (size_t)len, fd,; ); // NOLINT(whitespace/parens) lp->sl_regions[len] = NUL; return 0; } @@ -1083,7 +1083,7 @@ static int read_charflags_section(FILE *fd) // Set the word-char flags and fill SPELL_ISUPPER() table. if (flags != NULL && fol != NULL) { - set_spell_charflags((char_u *)flags, flagslen, fol); + set_spell_charflags((char_u *)flags, flagslen, (char *)fol); } xfree(flags); @@ -1219,7 +1219,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) return SP_TRUNCERROR; } p = xmalloc((size_t)ccnt + 2); - smp->sm_lead = p; + smp->sm_lead = (char *)p; // Read up to the first special char into sm_lead. int i = 0; @@ -1230,7 +1230,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) } *p++ = (char_u)c; } - smp->sm_leadlen = (int)(p - smp->sm_lead); + smp->sm_leadlen = (int)(p - (char_u *)smp->sm_lead); *p++ = NUL; // Put (abc) chars in sm_oneof, if any. @@ -1252,7 +1252,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) } // Any following chars go in sm_rules. - smp->sm_rules = p; + smp->sm_rules = (char *)p; if (i < ccnt) { // store the char we got while checking for end of sm_lead *p++ = (char_u)c; @@ -1267,7 +1267,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) *p++ = NUL; // <saltolen> <salto> - smp->sm_to = read_cnt_string(fd, 1, &ccnt); + smp->sm_to = (char *)read_cnt_string(fd, 1, &ccnt); if (ccnt < 0) { xfree(smp->sm_lead); return ccnt; @@ -1275,11 +1275,11 @@ static int read_sal_section(FILE *fd, slang_T *slang) // convert the multi-byte strings to wide char strings smp->sm_lead_w = mb_str2wide(smp->sm_lead); - smp->sm_leadlen = mb_charlen((char *)smp->sm_lead); + smp->sm_leadlen = mb_charlen(smp->sm_lead); if (smp->sm_oneof == NULL) { smp->sm_oneof_w = NULL; } else { - smp->sm_oneof_w = mb_str2wide(smp->sm_oneof); + smp->sm_oneof_w = mb_str2wide((char *)smp->sm_oneof); } if (smp->sm_to == NULL) { smp->sm_to_w = NULL; @@ -1294,12 +1294,12 @@ static int read_sal_section(FILE *fd, slang_T *slang) smp = &((salitem_T *)gap->ga_data)[gap->ga_len]; p = xmalloc(1); p[0] = NUL; - smp->sm_lead = p; + smp->sm_lead = (char *)p; smp->sm_lead_w = mb_str2wide(smp->sm_lead); smp->sm_leadlen = 0; smp->sm_oneof = NULL; smp->sm_oneof_w = NULL; - smp->sm_rules = p; + smp->sm_rules = (char *)p; smp->sm_to = NULL; smp->sm_to_w = NULL; gap->ga_len++; @@ -1348,19 +1348,19 @@ static int read_words_section(FILE *fd, slang_T *lp, int len) static int read_sofo_section(FILE *fd, slang_T *slang) { int cnt; - char_u *from, *to; + char *from, *to; int res; slang->sl_sofo = true; // <sofofromlen> <sofofrom> - from = read_cnt_string(fd, 2, &cnt); + from = (char *)read_cnt_string(fd, 2, &cnt); if (cnt < 0) { return cnt; } // <sofotolen> <sofoto> - to = read_cnt_string(fd, 2, &cnt); + to = (char *)read_cnt_string(fd, 2, &cnt); if (cnt < 0) { xfree(from); return cnt; @@ -1451,25 +1451,25 @@ static int read_compound(FILE *fd, slang_T *slang, int len) // Conversion to utf-8 may double the size. c = todo * 2 + 7; c += todo * 2; - char_u *pat = xmalloc((size_t)c); + char *pat = xmalloc((size_t)c); // We also need a list of all flags that can appear at the start and one // for all flags. - char_u *cp = xmalloc((size_t)todo + 1); + uint8_t *cp = xmalloc((size_t)todo + 1); slang->sl_compstartflags = cp; *cp = NUL; - char_u *ap = xmalloc((size_t)todo + 1); + uint8_t *ap = xmalloc((size_t)todo + 1); slang->sl_compallflags = ap; *ap = NUL; // And a list of all patterns in their original form, for checking whether // compounding may work in match_compoundrule(). This is freed when we // encounter a wildcard, the check doesn't work then. - char_u *crp = xmalloc((size_t)todo + 1); + uint8_t *crp = xmalloc((size_t)todo + 1); slang->sl_comprules = crp; - char_u *pp = pat; + char_u *pp = (char_u *)pat; *pp++ = '^'; *pp++ = '\\'; *pp++ = '('; @@ -1538,7 +1538,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) *crp = NUL; } - slang->sl_compprog = vim_regcomp((char *)pat, RE_MAGIC + RE_STRING + RE_STRICT); + slang->sl_compprog = vim_regcomp(pat, RE_MAGIC + RE_STRING + RE_STRICT); xfree(pat); if (slang->sl_compprog == NULL) { return SP_FORMERROR; @@ -1549,7 +1549,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) // Set the SOFOFROM and SOFOTO items in language "lp". // Returns SP_*ERROR flags when there is something wrong. -static int set_sofo(slang_T *lp, char_u *from, char_u *to) +static int set_sofo(slang_T *lp, char *from, char *to) { char *s; char *p; @@ -1566,7 +1566,7 @@ static int set_sofo(slang_T *lp, char_u *from, char_u *to) // First count the number of items for each list. Temporarily use // sl_sal_first[] for this. - for (p = (char *)from, s = (char *)to; *p != NUL && *s != NUL;) { + for (p = from, s = to; *p != NUL && *s != NUL;) { const int c = mb_cptr2char_adv((const char **)&p); MB_CPTR_ADV(s); if (c >= 256) { @@ -1589,7 +1589,7 @@ static int set_sofo(slang_T *lp, char_u *from, char_u *to) // Put the characters up to 255 in sl_sal_first[] the rest in a sl_sal // list. memset(lp->sl_sal_first, 0, sizeof(salfirst_T) * 256); - for (p = (char *)from, s = (char *)to; *p != NUL && *s != NUL;) { + for (p = from, s = to; *p != NUL && *s != NUL;) { const int c = mb_cptr2char_adv((const char **)&p); const int i = mb_cptr2char_adv((const char **)&s); if (c >= 256) { @@ -1660,12 +1660,12 @@ static void set_sal_first(slang_T *lp) // Turn a multi-byte string into a wide character string. // Return it in allocated memory. -static int *mb_str2wide(char_u *s) +static int *mb_str2wide(char *s) { int i = 0; - int *res = xmalloc(((size_t)mb_charlen((char *)s) + 1) * sizeof(int)); - for (char *p = (char *)s; *p != NUL;) { + int *res = xmalloc(((size_t)mb_charlen(s) + 1) * sizeof(int)); + for (char *p = s; *p != NUL;) { res[i++] = mb_ptr2char_adv((const char **)&p); } res[i] = NUL; @@ -1681,12 +1681,12 @@ static int *mb_str2wide(char_u *s) /// @param prefixcnt when "prefixtree" is true: prefix count /// /// @return zero when OK, SP_ value for an error. -static int spell_read_tree(FILE *fd, char_u **bytsp, long *bytsp_len, idx_T **idxsp, - bool prefixtree, int prefixcnt) +static int spell_read_tree(FILE *fd, char **bytsp, long *bytsp_len, idx_T **idxsp, bool prefixtree, + int prefixcnt) FUNC_ATTR_NONNULL_ARG(1, 2, 4) { int idx; - char_u *bp; + char *bp; idx_T *ip; // The tree size was computed when writing the file, so that we can @@ -1712,7 +1712,7 @@ static int spell_read_tree(FILE *fd, char_u **bytsp, long *bytsp_len, idx_T **id *idxsp = ip; // Recursively read the tree and store it in the array. - idx = read_tree_node(fd, bp, ip, (int)len, 0, prefixtree, prefixcnt); + idx = read_tree_node(fd, (char_u *)bp, ip, (int)len, 0, prefixtree, prefixcnt); if (idx < 0) { return idx; } @@ -1839,15 +1839,15 @@ static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx /// Reload the spell file "fname" if it's loaded. /// /// @param added_word invoked through "zg" -static void spell_reload_one(char_u *fname, bool added_word) +static void spell_reload_one(char *fname, bool added_word) { slang_T *slang; bool didit = false; for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (path_full_compare((char *)fname, slang->sl_fname, false, true) == kEqualFiles) { + if (path_full_compare(fname, slang->sl_fname, false, true) == kEqualFiles) { slang_clear(slang); - if (spell_load_file((char *)fname, NULL, slang, false) == NULL) { + if (spell_load_file(fname, NULL, slang, false) == NULL) { // reloading failed, clear the language slang_clear(slang); } @@ -2021,12 +2021,12 @@ static void spell_print_tree(wordnode_T *root) // Reads the affix file "fname". // Returns an afffile_T, NULL for complete failure. -static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) +static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) { FILE *fd; - char_u rline[MAXLINELEN]; - char_u *line; - char_u *pc = NULL; + char rline[MAXLINELEN]; + char *line; + char *pc = NULL; #define MAXITEMCNT 30 char *(items[MAXITEMCNT]); int itemcnt; @@ -2052,13 +2052,13 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) int compmax = 0; // COMPOUNDWORDMAX value char *compflags = NULL; // COMPOUNDFLAG and COMPOUNDRULE // concatenated - char_u *midword = NULL; // MIDWORD value - char_u *syllable = NULL; // SYLLABLE value - char_u *sofofrom = NULL; // SOFOFROM value - char_u *sofoto = NULL; // SOFOTO value + char *midword = NULL; // MIDWORD value + char *syllable = NULL; // SYLLABLE value + char *sofofrom = NULL; // SOFOFROM value + char *sofoto = NULL; // SOFOTO value // Open the file. - fd = os_fopen((char *)fname, "r"); + fd = os_fopen(fname, "r"); if (fd == NULL) { semsg(_(e_notopen), fname); return NULL; @@ -2086,7 +2086,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) hash_init(&aff->af_comp); // Read all the lines in the file one by one. - while (!vim_fgets((char *)rline, MAXLINELEN, fd) && !got_int) { + while (!vim_fgets(rline, MAXLINELEN, fd) && !got_int) { line_breakcheck(); lnum++; @@ -2098,7 +2098,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // Convert from "SET" to 'encoding' when needed. xfree(pc); if (spin->si_conv.vc_type != CONV_NONE) { - pc = (char_u *)string_convert(&spin->si_conv, (char *)rline, NULL); + pc = string_convert(&spin->si_conv, rline, NULL); if (pc == NULL) { smsg(_("Conversion failure for word in %s line %d: %s"), fname, lnum, rline); @@ -2113,7 +2113,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // Split the line up in white separated items. Put a NUL after each // item. itemcnt = 0; - for (p = (char *)line;;) { + for (p = line;;) { while (*p != NUL && (uint8_t)(*p) <= ' ') { // skip white space and CR/NL p++; } @@ -2144,9 +2144,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) if (itemcnt > 0) { if (is_aff_rule(items, itemcnt, "SET", 2) && aff->af_enc == NULL) { // Setup for conversion from "ENC" to 'encoding'. - aff->af_enc = (char_u *)enc_canonize((char *)items[1]); + aff->af_enc = enc_canonize((char *)items[1]); if (!spin->si_ascii - && convert_setup(&spin->si_conv, (char *)aff->af_enc, p_enc) == FAIL) { + && convert_setup(&spin->si_conv, aff->af_enc, p_enc) == FAIL) { smsg(_("Conversion in %s not supported: from %s to %s"), fname, aff->af_enc, p_enc); } @@ -2191,57 +2191,47 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) STRCAT(p, items[1]); spin->si_info = p; } else if (is_aff_rule(items, itemcnt, "MIDWORD", 2) && midword == NULL) { - midword = (char_u *)getroom_save(spin, items[1]); + midword = getroom_save(spin, items[1]); } else if (is_aff_rule(items, itemcnt, "TRY", 2)) { // ignored, we look in the tree for what chars may appear } else if ((is_aff_rule(items, itemcnt, "RAR", 2) // TODO(vim): remove "RAR" later || is_aff_rule(items, itemcnt, "RARE", 2)) && aff->af_rare == 0) { - aff->af_rare = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_rare = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if ((is_aff_rule(items, itemcnt, "KEP", 2) // TODO(vim): remove "KEP" later || is_aff_rule(items, itemcnt, "KEEPCASE", 2)) && aff->af_keepcase == 0) { - aff->af_keepcase = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_keepcase = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if ((is_aff_rule(items, itemcnt, "BAD", 2) || is_aff_rule(items, itemcnt, "FORBIDDENWORD", 2)) && aff->af_bad == 0) { - aff->af_bad = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_bad = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if (is_aff_rule(items, itemcnt, "NEEDAFFIX", 2) && aff->af_needaffix == 0) { - aff->af_needaffix = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_needaffix = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if (is_aff_rule(items, itemcnt, "CIRCUMFIX", 2) && aff->af_circumfix == 0) { - aff->af_circumfix = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_circumfix = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if (is_aff_rule(items, itemcnt, "NOSUGGEST", 2) && aff->af_nosuggest == 0) { - aff->af_nosuggest = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_nosuggest = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if ((is_aff_rule(items, itemcnt, "NEEDCOMPOUND", 2) || is_aff_rule(items, itemcnt, "ONLYINCOMPOUND", 2)) && aff->af_needcomp == 0) { - aff->af_needcomp = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_needcomp = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if (is_aff_rule(items, itemcnt, "COMPOUNDROOT", 2) && aff->af_comproot == 0) { - aff->af_comproot = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_comproot = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if (is_aff_rule(items, itemcnt, "COMPOUNDFORBIDFLAG", 2) && aff->af_compforbid == 0) { - aff->af_compforbid = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_compforbid = affitem2flag(aff->af_flagtype, items[1], fname, lnum); if (aff->af_pref.ht_used > 0) { smsg(_("Defining COMPOUNDFORBIDFLAG after PFX item may give wrong results in %s line %d"), fname, lnum); } } else if (is_aff_rule(items, itemcnt, "COMPOUNDPERMITFLAG", 2) && aff->af_comppermit == 0) { - aff->af_comppermit = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_comppermit = affitem2flag(aff->af_flagtype, items[1], fname, lnum); if (aff->af_pref.ht_used > 0) { smsg(_("Defining COMPOUNDPERMITFLAG after PFX item may give wrong results in %s line %d"), fname, lnum); @@ -2330,7 +2320,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } } else if (is_aff_rule(items, itemcnt, "SYLLABLE", 2) && syllable == NULL) { - syllable = (char_u *)getroom_save(spin, items[1]); + syllable = getroom_save(spin, items[1]); } else if (is_aff_rule(items, itemcnt, "NOBREAK", 1)) { spin->si_nobreak = true; } else if (is_aff_rule(items, itemcnt, "NOSPLITSUGS", 1)) { @@ -2375,8 +2365,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } else { // New affix letter. cur_aff = getroom(spin, sizeof(*cur_aff), true); - cur_aff->ah_flag = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + cur_aff->ah_flag = affitem2flag(aff->af_flagtype, items[1], fname, lnum); if (cur_aff->ah_flag == 0 || strlen(items[1]) >= AH_KEY_LEN) { break; } @@ -2469,7 +2458,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) aff_entry->ae_add = getroom_save(spin, items[3]); // Recognize flags on the affix: abcd/XYZ - aff_entry->ae_flags = (char_u *)vim_strchr(aff_entry->ae_add, '/'); + aff_entry->ae_flags = vim_strchr(aff_entry->ae_add, '/'); if (aff_entry->ae_flags != NULL) { *aff_entry->ae_flags++ = NUL; aff_process_flags(aff, aff_entry); @@ -2484,15 +2473,15 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) cur_aff->ah_first = aff_entry; if (strcmp(items[4], ".") != 0) { - char_u buf[MAXLINELEN]; + char buf[MAXLINELEN]; - aff_entry->ae_cond = (char_u *)getroom_save(spin, items[4]); + aff_entry->ae_cond = getroom_save(spin, items[4]); if (*items[0] == 'P') { - sprintf((char *)buf, "^%s", items[4]); // NOLINT(runtime/printf) + sprintf(buf, "^%s", items[4]); // NOLINT(runtime/printf) } else { - sprintf((char *)buf, "%s$", items[4]); // NOLINT(runtime/printf) + sprintf(buf, "%s$", items[4]); // NOLINT(runtime/printf) } - aff_entry->ae_prog = vim_regcomp((char *)buf, RE_MAGIC + RE_STRING + RE_STRICT); + aff_entry->ae_prog = vim_regcomp(buf, RE_MAGIC + RE_STRING + RE_STRICT); if (aff_entry->ae_prog == NULL) { smsg(_("Broken condition in %s line %d: %s"), fname, lnum, items[4]); @@ -2520,7 +2509,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) c_up = SPELL_TOUPPER(c); if (c_up != c && (aff_entry->ae_cond == NULL - || utf_ptr2char((char *)aff_entry->ae_cond) == c)) { + || utf_ptr2char(aff_entry->ae_cond) == c)) { p = aff_entry->ae_add + strlen(aff_entry->ae_add); MB_PTR_BACK(aff_entry->ae_add, p); if (utf_ptr2char(p) == c_up) { @@ -2532,13 +2521,13 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // actual word, thus must check for the // upper-case letter. if (aff_entry->ae_cond != NULL) { - char_u buf[MAXLINELEN]; - onecap_copy((char_u *)items[4], (char *)buf, true); - aff_entry->ae_cond = (char_u *)getroom_save(spin, (char *)buf); + char buf[MAXLINELEN]; + onecap_copy(items[4], buf, true); + aff_entry->ae_cond = getroom_save(spin, buf); if (aff_entry->ae_cond != NULL) { - sprintf((char *)buf, "^%s", aff_entry->ae_cond); // NOLINT(runtime/printf) + sprintf(buf, "^%s", aff_entry->ae_cond); // NOLINT(runtime/printf) vim_regfree(aff_entry->ae_prog); - aff_entry->ae_prog = vim_regcomp((char *)buf, RE_MAGIC + RE_STRING); + aff_entry->ae_prog = vim_regcomp(buf, RE_MAGIC + RE_STRING); } } } @@ -2553,7 +2542,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // Find a previously used condition. for (idx = spin->si_prefcond.ga_len - 1; idx >= 0; idx--) { p = ((char **)spin->si_prefcond.ga_data)[idx]; - if (str_equal(p, (char *)aff_entry->ae_cond)) { + if (str_equal(p, aff_entry->ae_cond)) { break; } } @@ -2562,7 +2551,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) idx = spin->si_prefcond.ga_len; pp = GA_APPEND_VIA_PTR(char_u *, &spin->si_prefcond); *pp = (aff_entry->ae_cond == NULL) ? - NULL : (char_u *)getroom_save(spin, (char *)aff_entry->ae_cond); + NULL : (char_u *)getroom_save(spin, aff_entry->ae_cond); } // Add the prefix to the prefix tree. @@ -2688,10 +2677,10 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } } else if (is_aff_rule(items, itemcnt, "SOFOFROM", 2) && sofofrom == NULL) { - sofofrom = (char_u *)getroom_save(spin, items[1]); + sofofrom = getroom_save(spin, items[1]); } else if (is_aff_rule(items, itemcnt, "SOFOTO", 2) && sofoto == NULL) { - sofoto = (char_u *)getroom_save(spin, items[1]); + sofoto = getroom_save(spin, items[1]); } else if (strcmp(items[0], "COMMON") == 0) { int i; @@ -2761,8 +2750,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } if (syllable != NULL) { - aff_check_string(spin->si_syllable, (char *)syllable, "SYLLABLE"); - spin->si_syllable = (char *)syllable; + aff_check_string(spin->si_syllable, syllable, "SYLLABLE"); + spin->si_syllable = syllable; } if (sofofrom != NULL || sofoto != NULL) { @@ -2772,16 +2761,16 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } else if (!GA_EMPTY(&spin->si_sal)) { smsg(_("Both SAL and SOFO lines in %s"), fname); } else { - aff_check_string(spin->si_sofofr, (char *)sofofrom, "SOFOFROM"); - aff_check_string(spin->si_sofoto, (char *)sofoto, "SOFOTO"); - spin->si_sofofr = (char *)sofofrom; - spin->si_sofoto = (char *)sofoto; + aff_check_string(spin->si_sofofr, sofofrom, "SOFOFROM"); + aff_check_string(spin->si_sofoto, sofoto, "SOFOTO"); + spin->si_sofofr = sofofrom; + spin->si_sofoto = sofoto; } } if (midword != NULL) { - aff_check_string(spin->si_midword, (char *)midword, "MIDWORD"); - spin->si_midword = (char *)midword; + aff_check_string(spin->si_midword, midword, "MIDWORD"); + spin->si_midword = midword; } xfree(pc); @@ -2808,7 +2797,7 @@ static void aff_process_flags(afffile_T *affile, affentry_T *entry) if (entry->ae_flags != NULL && (affile->af_compforbid != 0 || affile->af_comppermit != 0)) { - for (p = (char *)entry->ae_flags; *p != NUL;) { + for (p = entry->ae_flags; *p != NUL;) { prevp = (char_u *)p; flag = get_affitem(affile->af_flagtype, &p); if (flag == affile->af_comppermit || flag == affile->af_compforbid) { @@ -2843,10 +2832,10 @@ static bool spell_info_item(char *s) // Turn an affix flag name into a number, according to the FLAG type. // returns zero for failure. -static unsigned affitem2flag(int flagtype, char_u *item, char_u *fname, int lnum) +static unsigned affitem2flag(int flagtype, char *item, char *fname, int lnum) { unsigned res; - char *p = (char *)item; + char *p = item; res = get_affitem(flagtype, &p); if (res == 0) { @@ -2978,18 +2967,18 @@ static void check_renumber(spellinfo_T *spin) } // Returns true if flag "flag" appears in affix list "afflist". -static bool flag_in_afflist(int flagtype, char_u *afflist, unsigned flag) +static bool flag_in_afflist(int flagtype, char *afflist, unsigned flag) { char *p; unsigned n; switch (flagtype) { case AFT_CHAR: - return vim_strchr((char *)afflist, (int)flag) != NULL; + return vim_strchr(afflist, (int)flag) != NULL; case AFT_CAPLONG: case AFT_LONG: - for (p = (char *)afflist; *p != NUL;) { + for (p = afflist; *p != NUL;) { n = (unsigned)mb_ptr2char_adv((const char **)&p); if ((flagtype == AFT_LONG || (n >= 'A' && n <= 'Z')) && *p != NUL) { @@ -3002,7 +2991,7 @@ static bool flag_in_afflist(int flagtype, char_u *afflist, unsigned flag) break; case AFT_NUM: - for (p = (char *)afflist; *p != NUL;) { + for (p = afflist; *p != NUL;) { int digits = getdigits_int(&p, true, 0); assert(digits >= 0); n = (unsigned int)digits; @@ -3053,13 +3042,13 @@ static bool str_equal(char *s1, char *s2) /// They are stored case-folded. static void add_fromto(spellinfo_T *spin, garray_T *gap, char *from, char *to) { - char_u word[MAXWLEN]; + char word[MAXWLEN]; fromto_T *ftp = GA_APPEND_VIA_PTR(fromto_T, gap); - (void)spell_casefold(curwin, (char_u *)from, (int)strlen(from), word, MAXWLEN); - ftp->ft_from = getroom_save(spin, (char *)word); - (void)spell_casefold(curwin, (char_u *)to, (int)strlen(to), word, MAXWLEN); - ftp->ft_to = getroom_save(spin, (char *)word); + (void)spell_casefold(curwin, from, (int)strlen(from), word, MAXWLEN); + ftp->ft_from = getroom_save(spin, word); + (void)spell_casefold(curwin, to, (int)strlen(to), word, MAXWLEN); + ftp->ft_to = getroom_save(spin, word); } /// Converts a boolean argument in a SAL line to true or false; @@ -3103,7 +3092,7 @@ static void spell_free_aff(afffile_T *aff) // Read dictionary file "fname". // Returns OK or FAIL; -static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) +static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) { hashtab_T ht; char line[MAXLINELEN]; @@ -3128,7 +3117,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) Timestamp last_msg_time = 0; // Open the file. - fd = os_fopen((char *)fname, "r"); + fd = os_fopen(fname, "r"); if (fd == NULL) { semsg(_(e_notopen), fname); return FAIL; @@ -3229,7 +3218,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) break; } - hash = hash_hash((char_u *)dw); + hash = hash_hash(dw); hi = hash_lookup(&ht, (const char *)dw, strlen(dw), hash); if (!HASHITEM_EMPTY(hi)) { if (p_verbose > 0) { @@ -3241,7 +3230,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) } duplicate++; } else { - hash_add_item(&ht, hi, (char_u *)dw, hash); + hash_add_item(&ht, hi, dw, hash); } flags = 0; @@ -3250,17 +3239,17 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) need_affix = false; if (afflist != NULL) { // Extract flags from the affix list. - flags |= get_affix_flags(affile, afflist); + flags |= get_affix_flags(affile, (char *)afflist); if (affile->af_needaffix != 0 - && flag_in_afflist(affile->af_flagtype, afflist, + && flag_in_afflist(affile->af_flagtype, (char *)afflist, affile->af_needaffix)) { need_affix = true; } if (affile->af_pfxpostpone) { // Need to store the list of prefix IDs with the word. - pfxlen = get_pfxlist(affile, afflist, store_afflist); + pfxlen = get_pfxlist(affile, (char *)afflist, store_afflist); } if (spin->si_compflags != NULL) { @@ -3272,21 +3261,21 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) // Add the word to the word tree(s). if (store_word(spin, dw, flags, spin->si_region, - store_afflist, need_affix) == FAIL) { + (char *)store_afflist, need_affix) == FAIL) { retval = FAIL; } if (afflist != NULL) { // Find all matching suffixes and add the resulting words. // Additionally do matching prefixes that combine. - if (store_aff_word(spin, dw, afflist, affile, + if (store_aff_word(spin, dw, (char *)afflist, affile, &affile->af_suff, &affile->af_pref, CONDIT_SUF, flags, (char *)store_afflist, pfxlen) == FAIL) { retval = FAIL; } // Find all matching prefixes and add the resulting words. - if (store_aff_word(spin, dw, afflist, affile, + if (store_aff_word(spin, dw, (char *)afflist, affile, &affile->af_pref, NULL, CONDIT_SUF, flags, (char *)store_afflist, pfxlen) == FAIL) { retval = FAIL; @@ -3311,7 +3300,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) // Check for affix flags in "afflist" that are turned into word flags. // Return WF_ flags. -static int get_affix_flags(afffile_T *affile, char_u *afflist) +static int get_affix_flags(afffile_T *affile, char *afflist) { int flags = 0; @@ -3350,7 +3339,7 @@ static int get_affix_flags(afffile_T *affile, char_u *afflist) // Used for PFXPOSTPONE. // Put the resulting flags in "store_afflist[MAXWLEN]" with a terminating NUL // and return the number of affixes. -static int get_pfxlist(afffile_T *affile, char_u *afflist, char_u *store_afflist) +static int get_pfxlist(afffile_T *affile, char *afflist, char_u *store_afflist) { char *p; char *prevp; @@ -3359,7 +3348,7 @@ static int get_pfxlist(afffile_T *affile, char_u *afflist, char_u *store_afflist char key[AH_KEY_LEN]; hashitem_T *hi; - for (p = (char *)afflist; *p != NUL;) { + for (p = afflist; *p != NUL;) { prevp = p; if (get_affitem(affile->af_flagtype, &p) != 0) { // A flag is a postponed prefix flag if it appears in "af_pref" @@ -3426,7 +3415,7 @@ static void get_compflags(afffile_T *affile, char *afflist, char_u *store_afflis /// @param pfxlen nr of flags in "pfxlist" for prefixes, rest is compound flags /// /// @return FAIL when out of memory. -static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffile_T *affile, +static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_T *affile, hashtab_T *ht, hashtab_T *xht, int condit, int flags, char *pfxlist, int pfxlen) { @@ -3476,7 +3465,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffil && (ae->ae_chop == NULL || strlen(ae->ae_chop) < wordlen) && (ae->ae_prog == NULL - || vim_regexec_prog(&ae->ae_prog, false, (char_u *)word, (colnr_T)0)) + || vim_regexec_prog(&ae->ae_prog, false, word, (colnr_T)0)) && (((condit & CONDIT_CFIX) == 0) == ((condit & CONDIT_AFF) == 0 || ae->ae_flags == NULL @@ -3525,16 +3514,18 @@ static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffil // Extract flags from the affix list. use_flags |= get_affix_flags(affile, ae->ae_flags); - if (affile->af_needaffix != 0 && flag_in_afflist(affile->af_flagtype, ae->ae_flags, - affile->af_needaffix)) { + if (affile->af_needaffix != 0 + && flag_in_afflist(affile->af_flagtype, ae->ae_flags, + affile->af_needaffix)) { need_affix = true; } // When there is a CIRCUMFIX flag the other affix // must also have it and we don't add the word // with one affix. - if (affile->af_circumfix != 0 && flag_in_afflist(affile->af_flagtype, ae->ae_flags, - affile->af_circumfix)) { + if (affile->af_circumfix != 0 + && flag_in_afflist(affile->af_flagtype, ae->ae_flags, + affile->af_circumfix)) { use_condit |= CONDIT_CFIX; if ((condit & CONDIT_CFIX) == 0) { need_affix = true; @@ -3545,8 +3536,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffil || spin->si_compflags != NULL) { if (affile->af_pfxpostpone) { // Get prefix IDS from the affix list. - use_pfxlen = get_pfxlist(affile, - ae->ae_flags, store_afflist); + use_pfxlen = get_pfxlist(affile, ae->ae_flags, store_afflist); } else { use_pfxlen = 0; } @@ -3567,7 +3557,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffil if (spin->si_compflags != NULL) { // Get compound IDS from the affix list. - get_compflags(affile, (char *)ae->ae_flags, + get_compflags(affile, ae->ae_flags, (char_u *)use_pfxlist + use_pfxlen); } else { use_pfxlist[use_pfxlen] = NUL; @@ -3624,7 +3614,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffil // Store the modified word. if (store_word(spin, newword, use_flags, - spin->si_region, (char_u *)use_pfxlist, + spin->si_region, use_pfxlist, need_affix) == FAIL) { retval = FAIL; } @@ -3669,7 +3659,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char_u *afflist, afffil } // Read a file with a list of words. -static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) +static int spell_read_wordfile(spellinfo_T *spin, char *fname) { FILE *fd; long lnum = 0; @@ -3685,7 +3675,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) int regionmask; // Open the file. - fd = os_fopen((char *)fname, "r"); + fd = os_fopen(fname, "r"); if (fd == NULL) { semsg(_(e_notopen), fname); return FAIL; @@ -3695,7 +3685,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) spell_message(spin, IObuff); // Read all the lines in the file one by one. - while (!vim_fgets((char *)rline, MAXLINELEN, fd) && !got_int) { + while (!vim_fgets(rline, MAXLINELEN, fd) && !got_int) { line_breakcheck(); lnum++; @@ -3935,11 +3925,11 @@ static bool valid_spell_word(const char *word, const char *end) /// @param region supported region(s) /// @param pfxlist list of prefix ids or null /// @param need_affix only store word with affix id -static int store_word(spellinfo_T *spin, char *word, int flags, int region, const char_u *pfxlist, +static int store_word(spellinfo_T *spin, char *word, int flags, int region, const char *pfxlist, bool need_affix) { int len = (int)strlen(word); - int ct = captype((char_u *)word, (char_u *)word + len); + int ct = captype(word, word + len); char_u foldword[MAXWLEN]; int res = OK; @@ -3948,8 +3938,8 @@ static int store_word(spellinfo_T *spin, char *word, int flags, int region, cons return FAIL; } - (void)spell_casefold(curwin, (char_u *)word, len, foldword, MAXWLEN); - for (const char_u *p = pfxlist; res == OK; p++) { + (void)spell_casefold(curwin, word, len, (char *)foldword, MAXWLEN); + for (const char_u *p = (char_u *)pfxlist; res == OK; p++) { if (!need_affix || (p != NULL && *p != NUL)) { res = tree_add_word(spin, foldword, spin->si_foldroot, ct | flags, region, p == NULL ? 0 : *p); @@ -3961,7 +3951,7 @@ static int store_word(spellinfo_T *spin, char *word, int flags, int region, cons spin->si_foldwcount++; if (res == OK && (ct == WF_KEEPCAP || (flags & WF_KEEPCAP))) { - for (const char_u *p = pfxlist; res == OK; p++) { + for (const char_u *p = (char_u *)pfxlist; res == OK; p++) { if (!need_affix || (p != NULL && *p != NUL)) { res = tree_add_word(spin, (char_u *)word, spin->si_keeproot, flags, region, p == NULL ? 0 : *p); @@ -4265,7 +4255,7 @@ static long node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, lo compressed += node_compress(spin, child, ht, tot); // Try to find an identical child. - hash = hash_hash(child->wn_u1.hashkey); + hash = hash_hash((char *)child->wn_u1.hashkey); hi = hash_lookup(ht, (const char *)child->wn_u1.hashkey, strlen((char *)child->wn_u1.hashkey), hash); if (!HASHITEM_EMPTY(hi)) { @@ -4294,7 +4284,7 @@ static long node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, lo } else { // No other child has this hash value, add it to the // hashtable. - hash_add_item(ht, hi, child->wn_u1.hashkey, hash); + hash_add_item(ht, hi, (char *)child->wn_u1.hashkey, hash); } } } @@ -4974,7 +4964,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char *wfname) len = (int)strlen(fname); fname[len - 2] = 'u'; fname[len - 1] = 'g'; - sug_write(spin, (char_u *)fname); + sug_write(spin, fname); theend: xfree(fname); @@ -5008,7 +4998,7 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang) // Go through the whole case-folded tree, soundfold each word and put it // in the trie. - byts = slang->sl_fbyts; + byts = (char_u *)slang->sl_fbyts; idxs = slang->sl_fidxs; arridx[0] = 0; @@ -5199,10 +5189,10 @@ static int offset2bytes(int nr, char_u *buf) } // Write the .sug file in "fname". -static void sug_write(spellinfo_T *spin, char_u *fname) +static void sug_write(spellinfo_T *spin, char *fname) { // Create the file. Note that an existing file is silently overwritten! - FILE *fd = os_fopen((char *)fname, "w"); + FILE *fd = os_fopen(fname, "w"); if (fd == NULL) { semsg(_(e_notopen), fname); return; @@ -5284,7 +5274,7 @@ theend: /// @param added_word invoked through "zg" static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool added_word) { - char_u *fname = NULL; + char *fname = NULL; char **innames; int incount; afffile_T *(afile[MAXREGIONS]); @@ -5301,9 +5291,9 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool ga_init(&spin.si_rep, (int)sizeof(fromto_T), 20); ga_init(&spin.si_repsal, (int)sizeof(fromto_T), 20); ga_init(&spin.si_sal, (int)sizeof(fromto_T), 20); - ga_init(&spin.si_map, (int)sizeof(char_u), 100); - ga_init(&spin.si_comppat, (int)sizeof(char_u *), 20); - ga_init(&spin.si_prefcond, (int)sizeof(char_u *), 50); + ga_init(&spin.si_map, (int)sizeof(char), 100); + ga_init(&spin.si_comppat, (int)sizeof(char *), 20); + ga_init(&spin.si_prefcond, (int)sizeof(char *), 50); hash_init(&spin.si_commonwords); spin.si_newcompID = 127; // start compound ID at first maximum @@ -5325,14 +5315,14 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool // For ":mkspell path/vim" output file is "path/vim.latin1.spl". incount = 1; vim_snprintf(wfname, MAXPATHL, SPL_FNAME_TMPL, - fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc()); + fnames[0], spin.si_ascii ? "ascii" : spell_enc()); } else if (len > 4 && strcmp(fnames[0] + len - 4, ".spl") == 0) { // Name ends in ".spl", use as the file name. xstrlcpy(wfname, fnames[0], MAXPATHL); } else { // Name should be language, make the file name from it. vim_snprintf(wfname, MAXPATHL, SPL_FNAME_TMPL, - fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc()); + fnames[0], spin.si_ascii ? "ascii" : spell_enc()); } // Check for .ascii.spl. @@ -5404,8 +5394,8 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool spin.si_conv.vc_type = CONV_NONE; spin.si_region = 1 << i; - vim_snprintf((char *)fname, MAXPATHL, "%s.aff", innames[i]); - if (os_path_exists((char *)fname)) { + vim_snprintf(fname, MAXPATHL, "%s.aff", innames[i]); + if (os_path_exists(fname)) { // Read the .aff file. Will init "spin->si_conv" based on the // "SET" line. afile[i] = spell_read_aff(&spin, fname); @@ -5413,8 +5403,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool error = true; } else { // Read the .dic file and store the words in the trees. - vim_snprintf((char *)fname, MAXPATHL, "%s.dic", - innames[i]); + vim_snprintf(fname, MAXPATHL, "%s.dic", innames[i]); if (spell_read_dic(&spin, fname, afile[i]) == FAIL) { error = true; } @@ -5422,7 +5411,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool } else { // No .aff file, try reading the file as a word list. Store // the words in the trees. - if (spell_read_wordfile(&spin, (char_u *)innames[i]) == FAIL) { + if (spell_read_wordfile(&spin, innames[i]) == FAIL) { error = true; } } @@ -5458,7 +5447,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool // If the file is loaded need to reload it. if (!error) { - spell_reload_one((char_u *)wfname, added_word); + spell_reload_one(wfname, added_word); } } @@ -5534,11 +5523,11 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) buf_T *buf = NULL; bool new_spf = false; char *fname; - char_u *fnamebuf = NULL; + char *fnamebuf = NULL; char line[MAXWLEN * 2]; long fpos, fpos_next = 0; int i; - char_u *spf; + char *spf; if (!valid_spell_word(word, word + len)) { emsg(_(e_illegal_character_in_word)); @@ -5547,12 +5536,12 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) if (idx == 0) { // use internal wordlist if (int_wordlist == NULL) { - int_wordlist = (char_u *)vim_tempname(); + int_wordlist = vim_tempname(); if (int_wordlist == NULL) { return; } } - fname = (char *)int_wordlist; + fname = int_wordlist; } else { // If 'spellfile' isn't set figure out a good default value. if (*curwin->w_s->b_p_spf == NUL) { @@ -5566,8 +5555,8 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) } fnamebuf = xmalloc(MAXPATHL); - for (spf = (char_u *)curwin->w_s->b_p_spf, i = 1; *spf != NUL; i++) { - copy_option_part((char **)&spf, (char *)fnamebuf, MAXPATHL, ","); + for (spf = curwin->w_s->b_p_spf, i = 1; *spf != NUL; i++) { + copy_option_part(&spf, fnamebuf, MAXPATHL, ","); if (i == idx) { break; } @@ -5579,7 +5568,7 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) } // Check that the user isn't editing the .add file somewhere. - buf = buflist_findname_exp((char *)fnamebuf); + buf = buflist_findname_exp(fnamebuf); if (buf != NULL && buf->b_ml.ml_mfp == NULL) { buf = NULL; } @@ -5589,7 +5578,7 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) return; } - fname = (char *)fnamebuf; + fname = fnamebuf; } if (what == SPELL_ADD_BAD || undo) { @@ -5690,18 +5679,18 @@ static void init_spellfile(void) { char *buf; int l; - char_u *fname; - char_u *rtp; - char_u *lend; + char *fname; + char *rtp; + char *lend; bool aspath = false; - char_u *lstart = (char_u *)curbuf->b_s.b_p_spl; + char *lstart = 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 = (char_u *)curwin->w_s->b_p_spl; *lend != NUL + for (lend = curwin->w_s->b_p_spl; *lend != NUL && vim_strchr(",._", (uint8_t)(*lend)) == NULL; lend++) { if (vim_ispathsep(*lend)) { aspath = true; @@ -5711,21 +5700,21 @@ static void init_spellfile(void) // Loop over all entries in 'runtimepath'. Use the first one where we // are allowed to write. - rtp = (char_u *)p_rtp; + rtp = p_rtp; while (*rtp != NUL) { if (aspath) { // Use directory of an entry with path, e.g., for // "/dir/lg.utf-8.spl" use "/dir". - xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lstart - (char_u *)curbuf->b_s.b_p_spl)); + xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lstart - curbuf->b_s.b_p_spl)); } else { // Copy the path from 'runtimepath' to buf[]. - copy_option_part((char **)&rtp, buf, MAXPATHL, ","); + copy_option_part(&rtp, buf, MAXPATHL, ","); } if (os_file_is_writable(buf) == 2) { // Use the first language name from 'spelllang' and the // encoding used in the first loaded .spl file. if (aspath) { - xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lend - (char_u *)curbuf->b_s.b_p_spl + 1)); + xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lend - curbuf->b_s.b_p_spl + 1)); } else { // Create the "spell" directory if it doesn't exist yet. l = (int)strlen(buf); @@ -5739,14 +5728,14 @@ static void init_spellfile(void) "/%.*s", (int)(lend - lstart), lstart); } l = (int)strlen(buf); - fname = (char_u *)LANGP_ENTRY(curwin->w_s->b_langp, 0) + fname = LANGP_ENTRY(curwin->w_s->b_langp, 0) ->lp_slang->sl_fname; vim_snprintf(buf + l, MAXPATHL - (size_t)l, ".%s.add", ((fname != NULL - && strstr(path_tail((char *)fname), ".ascii.") != NULL) + && strstr(path_tail(fname), ".ascii.") != NULL) ? "ascii" : (const char *)spell_enc())); - set_option_value_give_err("spellfile", 0L, (const char *)buf, OPT_LOCAL); + set_option_value_give_err("spellfile", 0L, buf, OPT_LOCAL); break; } aspath = false; @@ -5759,13 +5748,13 @@ static void init_spellfile(void) /// Set the spell character tables from strings in the .spl file. /// /// @param cnt length of "flags" -static void set_spell_charflags(const char_u *flags, int cnt, char_u *fol) +static void set_spell_charflags(const char_u *flags, int cnt, char *fol) { // We build the new tables here first, so that we can compare with the // previous one. spelltab_T new_st; int i; - char *p = (char *)fol; + char *p = fol; int c; clear_spell_chartab(&new_st); @@ -5843,7 +5832,7 @@ static int write_spell_prefcond(FILE *fd, garray_T *gap, size_t *fwv) } // Use map string "map" for languages "lp". -static void set_map_str(slang_T *lp, char_u *map) +static void set_map_str(slang_T *lp, char *map) { char *p; int headc = 0; @@ -5865,7 +5854,7 @@ static void set_map_str(slang_T *lp, char_u *map) // The similar characters are stored separated with slashes: // "aaa/bbb/ccc/". Fill sl_map_array[c] with the character before c and // before the same slash. For characters above 255 sl_map_hash is used. - for (p = (char *)map; *p != NUL;) { + for (p = map; *p != NUL;) { c = mb_cptr2char_adv((const char **)&p); if (c == '/') { headc = 0; @@ -5888,10 +5877,10 @@ static void set_map_str(slang_T *lp, char_u *map) b[cl] = NUL; utf_char2bytes(headc, b + cl + 1); b[cl + 1 + headcl] = NUL; - hash = hash_hash((char_u *)b); + hash = hash_hash(b); hi = hash_lookup(&lp->sl_map_hash, (const char *)b, strlen(b), hash); if (HASHITEM_EMPTY(hi)) { - hash_add_item(&lp->sl_map_hash, hi, (char_u *)b, hash); + hash_add_item(&lp->sl_map_hash, hi, b, hash); } else { // This should have been checked when generating the .spl // file. diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index c2888b3945..7823a411f3 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -304,7 +304,7 @@ static int score_wordcount_adj(slang_T *slang, int score, char_u *word, bool spl static int badword_captype(char_u *word, char_u *end) FUNC_ATTR_NONNULL_ALL { - int flags = captype(word, end); + int flags = captype((char *)word, (char *)end); int c; int l, u; bool first; @@ -497,15 +497,15 @@ void spell_suggest(int count) line = get_cursor_line_ptr(); p = (char_u *)line + curwin->w_cursor.col; // Backup to before start of word. - while (p > (char_u *)line && spell_iswordp_nmw(p, curwin)) { + while (p > (char_u *)line && spell_iswordp_nmw((char *)p, curwin)) { MB_PTR_BACK(line, p); } // Forward to start of word. - while (*p != NUL && !spell_iswordp_nmw(p, curwin)) { + while (*p != NUL && !spell_iswordp_nmw((char *)p, curwin)) { MB_PTR_ADV(p); } - if (!spell_iswordp_nmw(p, curwin)) { // No word found. + if (!spell_iswordp_nmw((char *)p, curwin)) { // No word found. beep_flush(); return; } @@ -678,13 +678,13 @@ void spell_suggest(int count) /// /// @param maxcount maximum nr of suggestions /// @param need_cap 'spellcapcheck' matched -void spell_suggest_list(garray_T *gap, char_u *word, int maxcount, bool need_cap, bool interactive) +void spell_suggest_list(garray_T *gap, char *word, int maxcount, bool need_cap, bool interactive) { suginfo_T sug; suggest_T *stp; char_u *wcopy; - spell_find_suggest(word, 0, &sug, maxcount, false, need_cap, interactive); + spell_find_suggest((char_u *)word, 0, &sug, maxcount, false, need_cap, interactive); // Make room in "gap". ga_init(gap, sizeof(char_u *), sug.su_ga.ga_len + 1); @@ -749,7 +749,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma su->su_badlen = MAXWLEN - 1; // just in case } xstrlcpy((char *)su->su_badword, su->su_badptr, (size_t)su->su_badlen + 1); - (void)spell_casefold(curwin, (char_u *)su->su_badptr, su->su_badlen, (char_u *)su->su_fbadword, + (void)spell_casefold(curwin, su->su_badptr, su->su_badlen, su->su_fbadword, MAXWLEN); // TODO(vim): make this work if the case-folded text is longer than the @@ -788,7 +788,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma // for that. c = utf_ptr2char(su->su_badptr); if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) { - make_case_word((char_u *)su->su_badword, (char_u *)buf, WF_ONECAP); + make_case_word((char *)su->su_badword, buf, WF_ONECAP); add_suggestion(su, &su->su_ga, (char *)buf, su->su_badlen, SCORE_ICASE, 0, true, su->su_sallang, false); } @@ -900,8 +900,8 @@ static void spell_suggest_file(suginfo_T *su, char_u *fname) // If the suggestion doesn't have specific case duplicate the case // of the bad word. - if (captype(p, NULL) == 0) { - make_case_word(p, cword, su->su_badflags); + if (captype((char *)p, NULL) == 0) { + make_case_word((char *)p, (char *)cword, su->su_badflags); p = cword; } @@ -1021,7 +1021,7 @@ static void suggest_try_special(suginfo_T *su) // use that for the goodword too: "The the" -> "The". c = su->su_fbadword[len]; su->su_fbadword[len] = NUL; - make_case_word((char_u *)su->su_fbadword, word, su->su_badflags); + make_case_word(su->su_fbadword, (char *)word, su->su_badflags); su->su_fbadword[len] = c; // Give a soundalike score of 0, compute the score as if deleting one @@ -1090,7 +1090,7 @@ static void suggest_try_change(suginfo_T *su) STRCPY(fword, su->su_fbadword); n = (int)strlen(fword); p = su->su_badptr + su->su_badlen; - (void)spell_casefold(curwin, (char_u *)p, (int)strlen(p), (char_u *)fword + n, MAXWLEN - n); + (void)spell_casefold(curwin, p, (int)strlen(p), fword + n, MAXWLEN - n); // Make sure the resulting text is not longer than the original text. n = (int)strlen(su->su_badptr); @@ -1198,7 +1198,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun if (soundfold) { // Going through the soundfold tree. - byts = fbyts = slang->sl_sbyts; + byts = fbyts = (char_u *)slang->sl_sbyts; idxs = fidxs = slang->sl_sidxs; pbyts = NULL; pidxs = NULL; @@ -1207,9 +1207,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun } else { // When there are postponed prefixes we need to use these first. At // the end of the prefix we continue in the case-fold tree. - fbyts = slang->sl_fbyts; + fbyts = (char_u *)slang->sl_fbyts; fidxs = slang->sl_fidxs; - pbyts = slang->sl_pbyts; + pbyts = (char_u *)slang->sl_pbyts; pidxs = slang->sl_pidxs; if (pbyts != NULL) { byts = pbyts; @@ -1263,7 +1263,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun if (depth < MAXWLEN - 1 && (byts[arridx] == 0 || n == STATE_NOPREFIX)) { // Set su->su_badflags to the caps type at this position. // Use the caps type until here for the prefix itself. - n = nofold_len((char_u *)fword, sp->ts_fidx, (char_u *)su->su_badptr); + n = nofold_len(fword, sp->ts_fidx, su->su_badptr); flags = badword_captype((char_u *)su->su_badptr, (char_u *)su->su_badptr + n); su->su_badflags = badword_captype((char_u *)su->su_badptr + n, (char_u *)su->su_badptr + su->su_badlen); @@ -1281,8 +1281,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // Move the prefix to preword[] with the right case // and make find_keepcap_word() works. tword[sp->ts_twordlen] = NUL; - make_case_word((char_u *)tword + sp->ts_splitoff, - (char_u *)preword + sp->ts_prewordlen, flags); + make_case_word(tword + sp->ts_splitoff, + preword + sp->ts_prewordlen, flags); sp->ts_prewordlen = (char_u)strlen(preword); sp->ts_splitoff = sp->ts_twordlen; } @@ -1310,7 +1310,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun fword_ends = (fword[sp->ts_fidx] == NUL || (soundfold ? ascii_iswhite(fword[sp->ts_fidx]) - : !spell_iswordp((char_u *)fword + sp->ts_fidx, curwin))); + : !spell_iswordp(fword + sp->ts_fidx, curwin))); tword[sp->ts_twordlen] = NUL; if (sp->ts_prefixdepth <= PFD_NOTSPECIAL @@ -1325,7 +1325,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun for (c = 0; c < len && pbyts[n + c] == 0; c++) {} if (c > 0) { c = valid_word_prefix(c, n, flags, - (char_u *)tword + sp->ts_splitoff, slang, false); + tword + sp->ts_splitoff, slang, false); if (c == 0) { break; } @@ -1446,11 +1446,11 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // When appending a compound word after a word character don't // use Onecap. - if (p != NULL && spell_iswordp_nmw((char_u *)p, curwin)) { + if (p != NULL && spell_iswordp_nmw(p, curwin)) { c &= ~WF_ONECAP; } - make_case_word((char_u *)tword + sp->ts_splitoff, - (char_u *)preword + sp->ts_prewordlen, c); + make_case_word(tword + sp->ts_splitoff, + preword + sp->ts_prewordlen, c); } if (!soundfold) { @@ -1482,7 +1482,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun } if (!spell_valid_case(su->su_badflags, - captype((char_u *)preword + sp->ts_prewordlen, NULL))) { + captype(preword + sp->ts_prewordlen, NULL))) { newscore += SCORE_ICASE; } } @@ -1513,10 +1513,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // char, e.g., "thes," -> "these". p = fword + sp->ts_fidx; MB_PTR_BACK(fword, p); - if (!spell_iswordp((char_u *)p, curwin) && *preword != NUL) { + if (!spell_iswordp(p, curwin) && *preword != NUL) { p = preword + strlen(preword); MB_PTR_BACK(preword, p); - if (spell_iswordp((char_u *)p, curwin)) { + if (spell_iswordp(p, curwin)) { newscore += SCORE_NONWORD; } } @@ -1536,10 +1536,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun if (su->su_badflags & WF_MIXCAP) { // We really don't know if the word should be // upper or lower case, add both. - c = captype((char_u *)preword, NULL); + c = captype(preword, NULL); if (c == 0 || c == WF_ALLCAP) { - make_case_word((char_u *)tword + sp->ts_splitoff, - (char_u *)preword + sp->ts_prewordlen, + make_case_word(tword + sp->ts_splitoff, + preword + sp->ts_prewordlen, c == 0 ? WF_ALLCAP : 0); add_suggestion(su, &su->su_ga, (char *)preword, @@ -1678,7 +1678,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // non-word character with a space. Always skip a // character when the word ends. But only when the // good word can end. - if (((!try_compound && !spell_iswordp_nmw((char_u *)fword + if (((!try_compound && !spell_iswordp_nmw(fword + sp->ts_fidx, curwin)) || fword_ends) @@ -1710,7 +1710,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // set su->su_badflags to the caps type at this // position - n = nofold_len((char_u *)fword, sp->ts_fidx, (char_u *)su->su_badptr); + n = nofold_len(fword, sp->ts_fidx, su->su_badptr); su->su_badflags = badword_captype((char_u *)su->su_badptr + n, (char_u *)su->su_badptr + su->su_badlen); @@ -2034,7 +2034,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // Don't swap if the first character is not a word character. // SWAP3 etc. also don't make sense then. - if (!soundfold && !spell_iswordp((char_u *)p, curwin)) { + if (!soundfold && !spell_iswordp(p, curwin)) { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; break; @@ -2044,7 +2044,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun c = utf_ptr2char(p); if (p[n] == NUL) { c2 = NUL; - } else if (!soundfold && !spell_iswordp((char_u *)p + n, curwin)) { + } else if (!soundfold && !spell_iswordp(p + n, curwin)) { c2 = c; // don't swap non-word char } else { c2 = utf_ptr2char(p + n); @@ -2104,7 +2104,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun c = utf_ptr2char(p); fl = utf_ptr2len(p + n); c2 = utf_ptr2char(p + n); - if (!soundfold && !spell_iswordp((char_u *)p + n + fl, curwin)) { + if (!soundfold && !spell_iswordp(p + n + fl, curwin)) { c3 = c; // don't swap non-word char } else { c3 = utf_ptr2char(p + n + fl); @@ -2155,7 +2155,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun utf_char2bytes(c2, p + tl); p = p + tl; - if (!soundfold && !spell_iswordp((char_u *)p, curwin)) { + if (!soundfold && !spell_iswordp(p, curwin)) { // Middle char is not a word char, skip the rotate. First and // third char were already checked at swap and swap3. PROF_STORE(sp->ts_state) @@ -2399,7 +2399,7 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword) int c; idx_T lo, hi, m; char_u *p; - char_u *byts = slang->sl_kbyts; // array with bytes of the words + char_u *byts = (char_u *)slang->sl_kbyts; // array with bytes of the words idx_T *idxs = slang->sl_kidxs; // array with indexes if (byts == NULL) { @@ -2409,7 +2409,7 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword) } // Make an all-cap version of "fword". - allcap_copy((char_u *)fword, (char_u *)uword); + allcap_copy(fword, uword); // Each character needs to be tried both case-folded and upper-case. // All this gets very complicated if we keep in mind that changing case @@ -2666,7 +2666,7 @@ static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u * pbad = badsound; } else { // soundfold the bad word with more characters following - (void)spell_casefold(curwin, (char_u *)su->su_badptr, stp->st_orglen, fword, MAXWLEN); + (void)spell_casefold(curwin, su->su_badptr, stp->st_orglen, (char *)fword, MAXWLEN); // When joining two words the sound often changes a lot. E.g., "t he" // sounds like "t h" while "the" sounds like "@". Avoid that by @@ -2819,7 +2819,7 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T // times with different scores. Since the following is quite slow only do // the words that have a better score than before. Use a hashtable to // remember the words that have been done. - hash = hash_hash((char_u *)goodword); + hash = hash_hash(goodword); const size_t goodword_len = strlen(goodword); hi = hash_lookup(&slang->sl_sounddone, (const char *)goodword, goodword_len, hash); @@ -2827,7 +2827,7 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T sft = xmalloc(sizeof(sftword_T) + goodword_len); sft->sft_score = (int16_t)score; memcpy(sft->sft_word, goodword, goodword_len + 1); - hash_add_item(&slang->sl_sounddone, hi, sft->sft_word, hash); + hash_add_item(&slang->sl_sounddone, hi, (char *)sft->sft_word, hash); } else { sft = HI2SFT(hi); if (score >= sft->sft_score) { @@ -2851,7 +2851,7 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T // previous wordnr. orgnr += bytes2offset(&nrline); - byts = slang->sl_fbyts; + byts = (char_u *)slang->sl_fbyts; idxs = slang->sl_fidxs; // Lookup the word "orgnr" one of the two tries. @@ -2909,7 +2909,7 @@ badword: flags |= su->su_badflags; if ((flags & WF_CAPMASK) != 0) { // Need to fix case according to "flags". - make_case_word(theword, cword, flags); + make_case_word((char *)theword, (char *)cword, flags); p = cword; } else { p = theword; @@ -2989,7 +2989,7 @@ static int soundfold_find(slang_T *slang, char_u *word) idx_T *idxs; int wordnr = 0; - byts = slang->sl_sbyts; + byts = (char_u *)slang->sl_sbyts; idxs = slang->sl_sidxs; for (;;) { @@ -3244,12 +3244,12 @@ static void add_banned(suginfo_T *su, char *word) hash_T hash; hashitem_T *hi; - hash = hash_hash((char_u *)word); + hash = hash_hash(word); const size_t word_len = strlen(word); hi = hash_lookup(&su->su_banned, word, word_len, hash); if (HASHITEM_EMPTY(hi)) { s = xmemdupz(word, word_len); - hash_add_item(&su->su_banned, hi, s, hash); + hash_add_item(&su->su_banned, hi, (char *)s, hash); } } diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index 46cd600d81..0639615b8b 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -715,7 +715,7 @@ void draw_tabline(void) int len; int attr_nosel = HL_ATTR(HLF_TP); int attr_fill = HL_ATTR(HLF_TPF); - char_u *p; + char *p; int room; int use_sep_chars = (t_colors < 8); @@ -815,16 +815,16 @@ void draw_tabline(void) get_trans_bufname(cwp->w_buffer); shorten_dir(NameBuff); len = vim_strsize(NameBuff); - p = (char_u *)NameBuff; + p = NameBuff; while (len > room) { - len -= ptr2cells((char *)p); + len -= ptr2cells(p); MB_PTR_ADV(p); } if (len > Columns - col - 1) { len = Columns - col - 1; } - grid_puts_len(&default_grid, (char *)p, (int)strlen((char *)p), 0, col, attr); + grid_puts_len(&default_grid, p, (int)strlen(p), 0, col, attr); col += len; } grid_putchar(&default_grid, ' ', 0, col++, attr); @@ -894,13 +894,10 @@ int build_statuscol_str(win_T *wp, linenr_T lnum, long relnum, int maxwidth, int fillchar, maxwidth, hlrec, &clickrec, stcp); xfree(stc); - // Allocate and fill click def array if width has changed - if (wp->w_status_click_defs_size != (size_t)width) { - stl_clear_click_defs(wp->w_statuscol_click_defs, wp->w_statuscol_click_defs_size); - wp->w_statuscol_click_defs = stl_alloc_click_defs(wp->w_statuscol_click_defs, width, - &wp->w_statuscol_click_defs_size); - stl_fill_click_defs(wp->w_statuscol_click_defs, clickrec, buf, width, false); - } + stl_clear_click_defs(wp->w_statuscol_click_defs, wp->w_statuscol_click_defs_size); + wp->w_statuscol_click_defs = stl_alloc_click_defs(wp->w_statuscol_click_defs, width, + &wp->w_statuscol_click_defs_size); + stl_fill_click_defs(wp->w_statuscol_click_defs, clickrec, buf, width, false); return width; } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index f18f445867..46cd6245a7 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -92,7 +92,7 @@ typedef struct syn_pattern { } synpat_T; typedef struct syn_cluster_S { - char_u *scl_name; // syntax cluster name + char *scl_name; // syntax cluster name char *scl_name_u; // uppercase of scl_name int16_t *scl_list; // IDs in this syntax cluster } syn_cluster_T; @@ -3416,8 +3416,8 @@ static void syn_list_one(const int id, const bool syncing, const bool link_only) } msg_putchar(' '); if (spp->sp_sync_idx >= 0) { - msg_outtrans((char *)highlight_group_name(SYN_ITEMS(curwin->w_s) - [spp->sp_sync_idx].sp_syn.id - 1)); + msg_outtrans(highlight_group_name(SYN_ITEMS(curwin->w_s) + [spp->sp_sync_idx].sp_syn.id - 1)); } else { msg_puts("NONE"); } @@ -3430,7 +3430,7 @@ static void syn_list_one(const int id, const bool syncing, const bool link_only) (void)syn_list_header(did_header, 0, id, true); msg_puts_attr("links to", attr); msg_putchar(' '); - msg_outtrans((char *)highlight_group_name(highlight_link_id(id - 1) - 1)); + msg_outtrans(highlight_group_name(highlight_link_id(id - 1) - 1)); } } @@ -3453,7 +3453,7 @@ static void syn_list_cluster(int id) // slight hack: roughly duplicate the guts of syn_list_header() msg_putchar('\n'); - msg_outtrans((char *)SYN_CLSTR(curwin->w_s)[id].scl_name); + msg_outtrans(SYN_CLSTR(curwin->w_s)[id].scl_name); if (msg_col >= endcol) { // output at least one space endcol = msg_col + 1; @@ -3490,9 +3490,9 @@ static void put_id_list(const char *const name, const int16_t *const list, const int scl_id = *p - SYNID_CLUSTER; msg_putchar('@'); - msg_outtrans((char *)SYN_CLSTR(curwin->w_s)[scl_id].scl_name); + msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name); } else { - msg_outtrans((char *)highlight_group_name(*p - 1)); + msg_outtrans(highlight_group_name(*p - 1)); } if (p[1]) { msg_putchar(','); @@ -3514,7 +3514,7 @@ static void put_pattern(const char *const s, const int c, const synpat_T *const if (last_matchgroup == 0) { msg_outtrans("NONE"); } else { - msg_outtrans((char *)highlight_group_name(last_matchgroup - 1)); + msg_outtrans(highlight_group_name(last_matchgroup - 1)); } msg_putchar(' '); } @@ -3743,7 +3743,7 @@ static void add_keyword(char *const name, const int id, const int flags, } kp->next_list = copy_id_list(next_list); - const hash_T hash = hash_hash((char_u *)kp->keyword); + const hash_T hash = hash_hash(kp->keyword); hashtab_T *const ht = (curwin->w_s->b_syn_ic) ? &curwin->w_s->b_keywtab_ic : &curwin->w_s->b_keywtab; @@ -3757,7 +3757,7 @@ static void add_keyword(char *const name, const int id, const int flags, if (HASHITEM_EMPTY(hi)) { // new keyword, add to hashtable kp->ke_next = NULL; - hash_add_item(ht, hi, (char_u *)kp->keyword, hash); + hash_add_item(ht, hi, kp->keyword, hash); } else { // keyword already exists, prepend to list kp->ke_next = HI2KE(hi); @@ -4634,7 +4634,7 @@ static int syn_add_cluster(char *name) syn_cluster_T *scp = GA_APPEND_VIA_PTR(syn_cluster_T, &curwin->w_s->b_syn_clusters); CLEAR_POINTER(scp); - scp->scl_name = (char_u *)name; + scp->scl_name = name; scp->scl_name_u = vim_strsave_up(name); scp->scl_list = NULL; @@ -5042,7 +5042,7 @@ static int get_id_list(char **const arg, const int keylen, int16_t **const list, 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)) { + if (vim_regexec(®match, highlight_group_name(i), (colnr_T)0)) { if (round == 2) { // Got more items than expected; can happen // when adding items that match: @@ -5677,7 +5677,7 @@ static void syntime_report(void) msg_puts(profile_msg(p->average)); msg_puts(" "); msg_advance(50); - msg_outtrans((char *)highlight_group_name(p->id - 1)); + msg_outtrans(highlight_group_name(p->id - 1)); msg_puts(" "); msg_advance(69); diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 75a2849fbd..0d52f73ce7 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -2078,10 +2078,10 @@ static void findtags_add_match(findtags_state_T *st, tagptrs_T *tagpp, findtags_ // the part that matters for comparing, more bytes may // follow after it. E.g. help tags store the priority // after the NUL. - *hash = hash_hash((char_u *)mfp); + *hash = hash_hash(mfp); hi = hash_lookup(&st->ht_match[mtt], (const char *)mfp, strlen(mfp), *hash); if (HASHITEM_EMPTY(hi)) { - hash_add_item(&st->ht_match[mtt], hi, (char_u *)mfp, *hash); + hash_add_item(&st->ht_match[mtt], hi, mfp, *hash); GA_APPEND(char *, &st->ga_match[mtt], mfp); st->match_count++; } else { @@ -2573,7 +2573,7 @@ int get_tagfname(tagname_T *tnp, int first, char *buf) // tnp->tn_did_filefind_init == true: find next file in this part. for (;;) { if (tnp->tn_did_filefind_init) { - fname = (char *)vim_findfile(tnp->tn_search_ctx); + fname = vim_findfile(tnp->tn_search_ctx); if (fname != NULL) { break; } diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 106e92d43c..a52a34cd66 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -435,7 +435,7 @@ bool terminal_enter(void) handle_T save_curwin = curwin->handle; bool save_w_p_cul = curwin->w_p_cul; char *save_w_p_culopt = NULL; - char_u save_w_p_culopt_flags = curwin->w_p_culopt_flags; + uint8_t 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; long save_w_p_siso = curwin->w_p_siso; @@ -718,7 +718,7 @@ void terminal_paste(long count, char **y_array, size_t y_size) } vterm_keyboard_start_paste(curbuf->terminal->vt); size_t buff_len = strlen(y_array[0]); - char_u *buff = xmalloc(buff_len); + char *buff = xmalloc(buff_len); for (int i = 0; i < count; i++) { // -V756 // feed the lines to the terminal for (size_t j = 0; j < y_size; j++) { @@ -731,18 +731,18 @@ void terminal_paste(long count, char **y_array, size_t y_size) buff = xrealloc(buff, len); buff_len = len; } - char_u *dst = buff; - char_u *src = (char_u *)y_array[j]; + char *dst = buff; + char *src = y_array[j]; while (*src != '\0') { - len = (size_t)utf_ptr2len((char *)src); - int c = utf_ptr2char((char *)src); + len = (size_t)utf_ptr2len(src); + int c = utf_ptr2char(src); if (!is_filter_char(c)) { memcpy(dst, src, len); dst += len; } src += len; } - terminal_send(curbuf->terminal, (char *)buff, (size_t)(dst - buff)); + terminal_send(curbuf->terminal, buff, (size_t)(dst - buff)); } } xfree(buff); diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 704ff6ec55..df3123c21a 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -629,6 +629,7 @@ func Test_WinScrolled_diff() \ }, event) call StopVimInTerminal(buf) + call delete('XscrollEvent') endfunc func Test_WinClosed() diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index ebcbc8177e..980b8c5b38 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -2704,17 +2704,18 @@ endfunc " buffer name fuzzy completion func Test_fuzzy_completion_bufname() set wildoptions& - edit SomeFile.txt + " Use a long name to reduce the risk of matching a random directory name + edit SomeRandomFileWithLetters.txt enew - call feedkeys(":b SF\<Tab>\<C-B>\"\<CR>", 'tx') - call assert_equal('"b SF', @:) - call feedkeys(":b S*File.txt\<Tab>\<C-B>\"\<CR>", 'tx') - call assert_equal('"b SomeFile.txt', @:) + call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"b SRFWL', @:) + call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"b SomeRandomFileWithLetters.txt', @:) set wildoptions=fuzzy - call feedkeys(":b SF\<Tab>\<C-B>\"\<CR>", 'tx') - call assert_equal('"b SomeFile.txt', @:) - call feedkeys(":b S*File.txt\<Tab>\<C-B>\"\<CR>", 'tx') - call assert_equal('"b S*File.txt', @:) + call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"b SomeRandomFileWithLetters.txt', @:) + call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"b S*FileWithLetters.txt', @:) %bw! set wildoptions& endfunc diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim index 130ad9c7e1..19415286ad 100644 --- a/src/nvim/testdir/test_fold.vim +++ b/src/nvim/testdir/test_fold.vim @@ -1483,4 +1483,17 @@ func Test_indent_with_L_command() bwipe! endfunc +" Make sure that when there is a fold at the bottom of the buffer and a newline +" character is appended to the line, the fold gets expanded (instead of the new +" line not being part of the fold). +func Test_expand_fold_at_bottom_of_buffer() + new + " create a fold on the only line + fold + execute "normal A\<CR>" + call assert_equal([1, 1], range(1, 2)->map('foldlevel(v:val)')) + + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_utf8.vim b/src/nvim/testdir/test_utf8.vim index 9146cf7ab3..255f179fc9 100644 --- a/src/nvim/testdir/test_utf8.vim +++ b/src/nvim/testdir/test_utf8.vim @@ -199,6 +199,26 @@ func Test_setcellwidths() call setcellwidths([]) endfunc +func Test_getcellwidths() + call setcellwidths([]) + call assert_equal([], getcellwidths()) + + let widthlist = [ + \ [0x1330, 0x1330, 2], + \ [9999, 10000, 1], + \ [0x1337, 0x1339, 2], + \] + let widthlistsorted = [ + \ [0x1330, 0x1330, 2], + \ [0x1337, 0x1339, 2], + \ [9999, 10000, 1], + \] + call setcellwidths(widthlist) + call assert_equal(widthlistsorted, getcellwidths()) + + call setcellwidths([]) +endfunc + func Test_setcellwidths_dump() CheckRunVimInTerminal diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index 4af629d091..f2705057ef 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -127,13 +127,13 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on // Don't break until after the comment leader if (do_comments) { - char_u *line = (char_u *)get_cursor_line_ptr(); - leader_len = get_leader_len((char *)line, NULL, false, true); + char *line = get_cursor_line_ptr(); + leader_len = get_leader_len(line, NULL, false, true); if (leader_len == 0 && curbuf->b_p_cin) { // Check for a line comment after code. - int comment_start = check_linecomment((char *)line); + int comment_start = check_linecomment(line); if (comment_start != MAXCOL) { - leader_len = get_leader_len((char *)line + comment_start, NULL, false, true); + leader_len = get_leader_len(line + comment_start, NULL, false, true); if (leader_len != 0) { leader_len += comment_start; } @@ -477,25 +477,25 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on /// comment leader changes. static int fmt_check_par(linenr_T lnum, int *leader_len, char **leader_flags, bool do_comments) { - char_u *flags = NULL; // init for GCC - char_u *ptr; + char *flags = NULL; // init for GCC + char *ptr; - ptr = (char_u *)ml_get(lnum); + ptr = ml_get(lnum); if (do_comments) { - *leader_len = get_leader_len((char *)ptr, leader_flags, false, true); + *leader_len = get_leader_len(ptr, leader_flags, false, true); } else { *leader_len = 0; } if (*leader_len > 0) { // Search for 'e' flag in comment leader flags. - flags = (char_u *)(*leader_flags); + flags = *leader_flags; while (*flags && *flags != ':' && *flags != COM_END) { flags++; } } - return *skipwhite((char *)ptr + *leader_len) == NUL + return *skipwhite(ptr + *leader_len) == NUL || (*leader_len > 0 && *flags == COM_END) || startPS(lnum, NUL, false); } @@ -587,7 +587,7 @@ static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int /// false when the previous line is in the same paragraph. static bool paragraph_start(linenr_T lnum) { - char_u *p; + char *p; int leader_len = 0; // leader len of current line char *leader_flags = NULL; // flags for leader of current line int next_leader_len = 0; // leader len of next line @@ -596,7 +596,7 @@ static bool paragraph_start(linenr_T lnum) if (lnum <= 1) { return true; // start of the file } - p = (char_u *)ml_get(lnum - 1); + p = ml_get(lnum - 1); if (*p == NUL) { return true; // after empty line } diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 3e4aae62c9..ad16a6eda2 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -1074,9 +1074,9 @@ static u_entry_T *unserialize_uep(bufinfo_T *bi, bool *error, const char *file_n char_u **array = NULL; if (uep->ue_size > 0) { - if ((size_t)uep->ue_size < SIZE_MAX / sizeof(char_u *)) { // -V547 - array = xmalloc(sizeof(char_u *) * (size_t)uep->ue_size); - memset(array, 0, sizeof(char_u *) * (size_t)uep->ue_size); + if ((size_t)uep->ue_size < SIZE_MAX / sizeof(char *)) { // -V547 + array = xmalloc(sizeof(char *) * (size_t)uep->ue_size); + memset(array, 0, sizeof(char *) * (size_t)uep->ue_size); } } uep->ue_array = (char **)array; @@ -1209,7 +1209,7 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf, } goto theend; } else { - char_u mbuf[UF_START_MAGIC_LEN]; + char mbuf[UF_START_MAGIC_LEN]; ssize_t len = read_eintr(fd, mbuf, UF_START_MAGIC_LEN); close(fd); if (len < UF_START_MAGIC_LEN @@ -1342,8 +1342,8 @@ write_error: #ifdef HAVE_ACL if (buf->b_ffname != NULL) { // For systems that support ACL: get the ACL from the original file. - vim_acl_T acl = os_get_acl((char_u *)buf->b_ffname); - os_set_acl((char_u *)file_name, acl); + vim_acl_T acl = os_get_acl(buf->b_ffname); + os_set_acl(file_name, acl); os_free_acl(acl); } #endif @@ -1363,7 +1363,7 @@ void u_read_undo(char *name, const char_u *hash, const char *orig_name FUNC_ATTR FUNC_ATTR_NONNULL_ARG(2) { u_header_T **uhp_table = NULL; - char_u *line_ptr = NULL; + char *line_ptr = NULL; char *file_name; if (name == NULL) { @@ -1414,7 +1414,7 @@ void u_read_undo(char *name, const char_u *hash, const char *orig_name FUNC_ATTR }; // Read the undo file header. - char_u magic_buf[UF_START_MAGIC_LEN]; + char magic_buf[UF_START_MAGIC_LEN]; if (fread(magic_buf, UF_START_MAGIC_LEN, 1, fp) != 1 || memcmp(magic_buf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0) { semsg(_("E823: Not an undo file: %s"), file_name); @@ -1426,8 +1426,8 @@ void u_read_undo(char *name, const char_u *hash, const char *orig_name FUNC_ATTR goto error; } - char_u read_hash[UNDO_HASH_SIZE]; - if (!undo_read(&bi, read_hash, UNDO_HASH_SIZE)) { + char read_hash[UNDO_HASH_SIZE]; + if (!undo_read(&bi, (char_u *)read_hash, UNDO_HASH_SIZE)) { corruption_error("hash", file_name); goto error; } @@ -1453,7 +1453,7 @@ void u_read_undo(char *name, const char_u *hash, const char *orig_name FUNC_ATTR } if (str_len > 0) { - line_ptr = undo_read_string(&bi, (size_t)str_len); + line_ptr = (char *)undo_read_string(&bi, (size_t)str_len); } linenr_T line_lnum = (linenr_T)undo_read_4c(&bi); colnr_T line_colnr = (colnr_T)undo_read_4c(&bi); @@ -1608,7 +1608,7 @@ void u_read_undo(char *name, const char_u *hash, const char *orig_name FUNC_ATTR 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 = (char *)line_ptr; + curbuf->b_u_line_ptr = line_ptr; curbuf->b_u_line_lnum = line_lnum; curbuf->b_u_line_colnr = line_colnr; curbuf->b_u_numhead = num_head; @@ -2238,7 +2238,7 @@ target_zero: /// @param do_buf_event If `true`, send buffer updates. static void u_undoredo(int undo, bool do_buf_event) { - char_u **newarray = NULL; + char **newarray = NULL; linenr_T newlnum = MAXLNUM; u_entry_T *nuep; u_entry_T *newlist = NULL; @@ -2316,13 +2316,13 @@ static void u_undoredo(int undo, bool do_buf_event) // delete the lines between top and bot and save them in newarray if (oldsize > 0) { - newarray = xmalloc(sizeof(char_u *) * (size_t)oldsize); + newarray = xmalloc(sizeof(char *) * (size_t)oldsize); // delete backwards, it goes faster in most cases long i; linenr_T lnum; for (lnum = bot - 1, i = oldsize; --i >= 0; lnum--) { // what can we do when we run out of memory? - newarray[i] = (char_u *)u_save_line(lnum); + newarray[i] = u_save_line(lnum); // remember we deleted the last line in the buffer, and a // dummy empty line will be inserted if (curbuf->b_ml.ml_line_count == 1) { @@ -2348,7 +2348,7 @@ static void u_undoredo(int undo, bool do_buf_event) } xfree(uep->ue_array[i]); } - xfree((char_u *)uep->ue_array); + xfree(uep->ue_array); } // Adjust marks @@ -2378,7 +2378,7 @@ static void u_undoredo(int undo, bool do_buf_event) u_newcount += newsize; u_oldcount += oldsize; uep->ue_size = oldsize; - uep->ue_array = (char **)newarray; + uep->ue_array = newarray; uep->ue_bot = top + newsize + 1; // insert this entry in front of the new entry list @@ -2565,11 +2565,11 @@ static void u_undo_end(bool did_undo, bool absolute, bool quiet) uhp = curbuf->b_u_newhead; } - char_u msgbuf[80]; + char msgbuf[80]; if (uhp == NULL) { *msgbuf = NUL; } else { - undo_fmt_time((char *)msgbuf, sizeof(msgbuf), uhp->uh_time); + undo_fmt_time(msgbuf, sizeof(msgbuf), uhp->uh_time); } { @@ -2935,7 +2935,7 @@ static void u_freeentries(buf_T *buf, u_header_T *uhp, u_header_T **uhpp) #ifdef U_DEBUG uhp->uh_magic = 0; #endif - xfree((char_u *)uhp); + xfree(uhp); buf->b_u_numhead--; } @@ -2945,11 +2945,11 @@ static void u_freeentry(u_entry_T *uep, long n) while (n > 0) { xfree(uep->ue_array[--n]); } - xfree((char_u *)uep->ue_array); + xfree(uep->ue_array); #ifdef U_DEBUG uep->ue_magic = 0; #endif - xfree((char_u *)uep); + xfree(uep); } /// invalidate the undo buffer; called when storage has already been released diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index a8e4603aa2..31cb1e8936 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -1432,7 +1432,7 @@ static size_t uc_check_code(char *code, size_t len, char *buf, ucmd_T *cmd, exar l++; if (l <= 1) { - type = ct_NONE; + // type = ct_NONE; } else if (STRNICMP(p, "args>", l) == 0) { type = ct_ARGS; } else if (STRNICMP(p, "bang>", l) == 0) { diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 0b19526fa0..e839ff87c8 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -1826,7 +1826,7 @@ static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const no flags |= FSK_SIMPLIFY; } const size_t special_len = trans_special(&p, (size_t)(e - p), - (char_u *)v_p, flags, false, NULL); + v_p, flags, false, NULL); if (special_len != 0) { v_p += special_len; } else { diff --git a/src/nvim/window.c b/src/nvim/window.c index f16e9b8436..fdaaeb812e 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -508,7 +508,7 @@ wingotofile: CHECK_CMDWIN; linenr_T lnum = -1; - char *ptr = (char *)grab_file_name(Prenum1, &lnum); + char *ptr = grab_file_name(Prenum1, &lnum); if (ptr != NULL) { tabpage_T *oldtab = curtab; win_T *oldwin = curwin; @@ -756,20 +756,20 @@ 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 = (char_u *)wp->w_p_fcs; + char *old = wp->w_p_fcs; wp->w_p_fcs = ((*old == NUL) ? xstrdup("eob: ") - : concat_str((char *)old, ",eob: ")); - free_string_option((char *)old); + : concat_str(old, ",eob: ")); + free_string_option(old); } // TODO(bfredl): this could use a highlight namespace directly, // and avoid peculiarities around window options - char_u *old = (char_u *)wp->w_p_winhl; + char *old = wp->w_p_winhl; wp->w_p_winhl = ((*old == NUL) ? xstrdup("EndOfBuffer:") - : concat_str((char *)old, ",EndOfBuffer:")); - free_string_option((char *)old); + : concat_str(old, ",EndOfBuffer:")); + free_string_option(old); parse_winhl_opt(wp); // signcolumn: use 'auto' @@ -2617,8 +2617,8 @@ static bool close_last_window_tabpage(win_T *win, bool free_buf, tabpage_T *prev goto_tabpage_tp(alt_tabpage(), false, true); // save index for tabclosed event - char_u prev_idx[NUMBUFLEN]; - snprintf((char *)prev_idx, NUMBUFLEN, "%i", tabpage_index(prev_curtab)); + char prev_idx[NUMBUFLEN]; + snprintf(prev_idx, NUMBUFLEN, "%i", tabpage_index(prev_curtab)); // Safety check: Autocommands may have closed the window when jumping // to the other tab page. @@ -4064,7 +4064,7 @@ void free_tabpage(tabpage_T *tp) /// tabpage in case of 0. /// @param filename Will be passed to apply_autocmds(). /// @return Was the new tabpage created successfully? FAIL or OK. -int win_new_tabpage(int after, char_u *filename) +int win_new_tabpage(int after, char *filename) { tabpage_T *old_curtab = curtab; @@ -4127,7 +4127,7 @@ int win_new_tabpage(int after, char_u *filename) apply_autocmds(EVENT_WINNEW, NULL, NULL, false, curbuf); apply_autocmds(EVENT_WINENTER, NULL, NULL, false, curbuf); - apply_autocmds(EVENT_TABNEW, (char *)filename, (char *)filename, false, curbuf); + apply_autocmds(EVENT_TABNEW, filename, filename, false, curbuf); apply_autocmds(EVENT_TABENTER, NULL, NULL, false, curbuf); return OK; @@ -6757,7 +6757,7 @@ static void frame_add_height(frame_T *frp, int n) // Get the file name at the cursor. // If Visual mode is active, use the selected text if it's in one line. // Returns the name in allocated memory, NULL for failure. -char_u *grab_file_name(long count, linenr_T *file_lnum) +char *grab_file_name(long count, linenr_T *file_lnum) { int options = FNAME_MESS | FNAME_EXP | FNAME_REL | FNAME_UNESC; if (VIsual_active) { @@ -6772,7 +6772,7 @@ char_u *grab_file_name(long count, linenr_T *file_lnum) *file_lnum = (linenr_T)getdigits_long(&p, false, 0); } - return (char_u *)find_file_name_in_path(ptr, len, options, count, curbuf->b_ffname); + return find_file_name_in_path(ptr, len, options, count, curbuf->b_ffname); } return file_name_at_cursor(options | FNAME_HYP, count, file_lnum); } @@ -6788,11 +6788,11 @@ char_u *grab_file_name(long count, linenr_T *file_lnum) // FNAME_EXP expand to path // FNAME_HYP check for hypertext link // FNAME_INCL apply "includeexpr" -char_u *file_name_at_cursor(int options, long count, linenr_T *file_lnum) +char *file_name_at_cursor(int options, long count, linenr_T *file_lnum) { - return file_name_in_line(get_cursor_line_ptr(), - curwin->w_cursor.col, options, count, curbuf->b_ffname, - file_lnum); + return (char *)file_name_in_line(get_cursor_line_ptr(), + curwin->w_cursor.col, options, count, curbuf->b_ffname, + file_lnum); } /// @param rel_fname file we are searching relative to diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua index 32ed856872..3da630ddcc 100644 --- a/test/functional/ui/statuscolumn_spec.lua +++ b/test/functional/ui/statuscolumn_spec.lua @@ -5,6 +5,7 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval local exec_lua = helpers.exec_lua +local feed = helpers.feed local meths = helpers.meths local pcall_err = helpers.pcall_err @@ -413,6 +414,19 @@ describe('statuscolumn', function() eq('', eval("g:testvar")) end) + it('click labels do not leak memory', function() + command([[ + set laststatus=2 + setlocal statuscolumn=%0@MyClickFunc@abcd%T + 4vsplit + setlocal statusline=abcd + redrawstatus + setlocal statusline= + only + redraw + ]]) + end) + it('works with foldcolumn', function() -- Fits maximum multibyte foldcolumn #21759 command([[set stc=%C%=%l\ fdc=9 fillchars=foldsep:ð’€€]]) @@ -425,7 +439,7 @@ describe('statuscolumn', function() vim.api.nvim_buf_set_extmark(0, ns, 7, 0, { virt_lines_leftcol = true, virt_lines = {{{"virt", ""}}} }) ]]) - helpers.feed('lh') -- force update wcol/row + feed('lh') -- force update wcol/row screen:expect([[ 4 aaaaa | 5 aaaaa | |