From 40855b0143a864739a6037921e15699445dcf8a7 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Sun, 31 Jul 2022 16:20:57 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 6238d85b3a..ff58810ff0 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -149,7 +149,7 @@ int buf_init_chartab(buf_T *buf, int global) p = p_isf; } else { // i == 3 // fourth round: 'iskeyword' - p = buf->b_p_isk; + p = (char_u *)buf->b_p_isk; } while (*p) { -- cgit From db28c2ca2b6561bc65dd064ca5f45b0a9f3b4790 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 26 Aug 2022 09:04:51 +0800 Subject: refactor: set_chars_option() Rename "set" to "apply" and tidy up variable scopes. --- src/nvim/charset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index ff58810ff0..d48cadf356 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1655,7 +1655,7 @@ int hex2nr(int c) /// Convert two hex characters to a byte. /// Return -1 if one of the characters is not hex. -int hexhex2nr(char_u *p) +int hexhex2nr(const char_u *p) FUNC_ATTR_PURE { if (!ascii_isxdigit(p[0]) || !ascii_isxdigit(p[1])) { -- cgit From 395277036014189c03b8969fc0a5cd2bdc5c8631 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 10:36:35 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index d48cadf356..dc62b85716 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -140,13 +140,13 @@ int buf_init_chartab(buf_T *buf, int global) const char_u *p; if (i == 0) { // first round: 'isident' - p = p_isi; + p = (char_u *)p_isi; } else if (i == 1) { // second round: 'isprint' - p = p_isp; + p = (char_u *)p_isp; } else if (i == 2) { // third round: 'isfname' - p = p_isf; + p = (char_u *)p_isf; } else { // i == 3 // fourth round: 'iskeyword' p = (char_u *)buf->b_p_isk; -- cgit From 691f4715c0cf4bc11ea2280db8777e6dd174a8ac Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index dc62b85716..df951854e0 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -246,7 +246,7 @@ int buf_init_chartab(buf_T *buf, int global) } c = *p; - p = skip_to_option_part(p); + p = (char_u *)skip_to_option_part((char *)p); if ((c == ',') && (*p == NUL)) { // Trailing comma is not allowed. -- cgit From ea4e9c71ccaf406fe7aa6b47d461cdab2d6c01e9 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 27 Aug 2022 11:28:11 +0200 Subject: refactor(plines): use a struct for chartabsize state This is a refactor extracted from vim-patch 9.0.0067: cannot show virtual text The logic for inline virtual text is going to be different in nvim than text property based text in vim, but this refactor is still useful, as calculation of displayed linesize is going to be stateful in a similar way. --- src/nvim/charset.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index dc62b85716..3632c3d70b 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -930,14 +930,18 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en posptr -= utf_head_off(line, posptr); } + chartabsize_T cts; + init_chartabsize_arg(&cts, wp, pos->lnum, 0, line, line); + // This function is used very often, do some speed optimizations. // When 'list', 'linebreak', 'showbreak' and 'breakindent' are not set - // use a simple loop. + // and there are no virtual text use a simple loop. // Also use this when 'list' is set but tabs take their normal size. if ((!wp->w_p_list || (wp->w_p_lcs_chars.tab1 != NUL)) && !wp->w_p_lbr && *get_showbreak_value(wp) == NUL - && !wp->w_p_bri) { + && !wp->w_p_bri + && !cts.cts_has_virt_text) { for (;;) { head = 0; int c = *ptr; @@ -984,25 +988,29 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en } else { for (;;) { // A tab gets expanded, depending on the current column + // Other things also take up space. head = 0; - incr = win_lbr_chartabsize(wp, line, ptr, vcol, &head); + incr = win_lbr_chartabsize(&cts, &head); // make sure we don't go past the end of the line - if (*ptr == NUL) { + if (*cts.cts_ptr == NUL) { // NUL at end of line only takes one column incr = 1; break; } - if ((posptr != NULL) && (ptr >= posptr)) { + if ((posptr != NULL) && ((char_u *)cts.cts_ptr >= posptr)) { // character at pos->col break; } - vcol += incr; - MB_PTR_ADV(ptr); + cts.cts_vcol += incr; + MB_PTR_ADV(cts.cts_ptr); } + vcol = cts.cts_vcol; + ptr = (char_u *)cts.cts_ptr; } + clear_chartabsize_arg(&cts); if (start != NULL) { *start = vcol + head; @@ -1013,6 +1021,8 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en } if (cursor != NULL) { + // cursor is after inserted text + vcol += cts.cts_cur_text_width; if ((*ptr == TAB) && (State & MODE_NORMAL) && !wp->w_p_list -- cgit From 58f30a326f34319801e7921f32c83e8320d85f6c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index e0f798121a..2632279565 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -313,7 +313,7 @@ size_t transstr_len(const char *const s, bool untab) const size_t l = (size_t)utfc_ptr2len(p); if (l > 1) { int pcc[MAX_MCO + 1]; - pcc[0] = utfc_ptr2char((const char_u *)p, &pcc[1]); + pcc[0] = utfc_ptr2char(p, &pcc[1]); if (vim_isprintc(pcc[0])) { len += l; @@ -359,7 +359,7 @@ size_t transstr_buf(const char *const s, char *const buf, const size_t len, bool break; // Exceeded `buf` size. } int pcc[MAX_MCO + 1]; - pcc[0] = utfc_ptr2char((const char_u *)p, &pcc[1]); + pcc[0] = utfc_ptr2char(p, &pcc[1]); if (vim_isprintc(pcc[0])) { memmove(buf_p, p, l); @@ -709,7 +709,7 @@ int ptr2cells(const char *p_in) /// @return number of character cells. int vim_strsize(char *s) { - return vim_strnsize((char_u *)s, MAXCOL); + return vim_strnsize(s, MAXCOL); } /// Return the number of character cells string "s[len]" will take on the @@ -721,13 +721,13 @@ int vim_strsize(char *s) /// @param len /// /// @return Number of character cells. -int vim_strnsize(char_u *s, int len) +int vim_strnsize(char *s, int len) { assert(s != NULL); int size = 0; while (*s != NUL && --len >= 0) { - int l = utfc_ptr2len((char *)s); - size += ptr2cells((char *)s); + int l = utfc_ptr2len(s); + size += ptr2cells(s); s += l; len -= l - 1; } @@ -1687,12 +1687,12 @@ int hexhex2nr(const char_u *p) /// characters. /// /// @param str file path string to check -bool rem_backslash(const char_u *str) +bool rem_backslash(const char *str) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { #ifdef BACKSLASH_IN_FILENAME return str[0] == '\\' - && str[1] < 0x80 + && (uint8_t)str[1] < 0x80 && (str[1] == ' ' || (str[1] != NUL && str[1] != '*' @@ -1710,7 +1710,7 @@ bool rem_backslash(const char_u *str) void backslash_halve(char_u *p) { for (; *p; p++) { - if (rem_backslash(p)) { + if (rem_backslash((char *)p)) { STRMOVE(p, p + 1); } } -- cgit From 2828aae7b49921380f229ebf4d7432f39c6c2c2b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 30 Aug 2022 14:52:09 +0200 Subject: refactor: replace char_u with char 4 (#19987) * refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 2632279565..4efd8a4ad1 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1157,7 +1157,7 @@ char *skipwhite(const char *const p) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { - return (char *)skipwhite_len((char_u *)p, STRLEN(p)); + return skipwhite_len(p, STRLEN(p)); } /// Like `skipwhite`, but skip up to `len` characters. @@ -1168,27 +1168,27 @@ char *skipwhite(const char *const p) /// /// @return Pointer to character after the skipped whitespace, or the `len`-th /// character in the string. -char_u *skipwhite_len(const char_u *p, size_t len) +char *skipwhite_len(const char *p, size_t len) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { for (; len > 0 && ascii_iswhite(*p); len--) { p++; } - return (char_u *)p; + return (char *)p; } // getwhitecols: return the number of whitespace // columns (bytes) at the start of a given line intptr_t getwhitecols_curline(void) { - return getwhitecols(get_cursor_line_ptr()); + return getwhitecols((char *)get_cursor_line_ptr()); } -intptr_t getwhitecols(const char_u *p) +intptr_t getwhitecols(const char *p) FUNC_ATTR_PURE { - return (char_u *)skipwhite((char *)p) - p; + return skipwhite(p) - p; } /// Skip over digits @@ -1232,10 +1232,10 @@ const char *skipbin(const char *q) /// /// @return Pointer to the character after the skipped digits and hex /// characters. -char_u *skiphex(char_u *q) +char *skiphex(char *q) FUNC_ATTR_PURE { - char_u *p = q; + char *p = q; while (ascii_isxdigit(*p)) { // skip to next non-digit p++; @@ -1248,10 +1248,10 @@ char_u *skiphex(char_u *q) /// @param q /// /// @return Pointer to the digit or (NUL after the string). -char_u *skiptodigit(char_u *q) +char *skiptodigit(char *q) FUNC_ATTR_PURE { - char_u *p = q; + char *p = q; while (*p != NUL && !ascii_isdigit(*p)) { // skip to next digit p++; @@ -1282,10 +1282,10 @@ const char *skiptobin(const char *q) /// @param q /// /// @return Pointer to the hex character or (NUL after the string). -char_u *skiptohex(char_u *q) +char *skiptohex(char *q) FUNC_ATTR_PURE { - char_u *p = q; + char *p = q; while (*p != NUL && !ascii_isxdigit(*p)) { // skip to next digit p++; @@ -1298,13 +1298,13 @@ char_u *skiptohex(char_u *q) /// @param[in] p Text to skip over. /// /// @return Pointer to the next whitespace or NUL character. -char_u *skiptowhite(const char_u *p) +char *skiptowhite(const char *p) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE { while (*p != ' ' && *p != '\t' && *p != NUL) { p++; } - return (char_u *)p; + return (char *)p; } /// skiptowhite_esc: Like skiptowhite(), but also skip escaped chars @@ -1329,11 +1329,11 @@ char *skiptowhite_esc(char *p) /// @param[in] p Text to skip over. /// /// @return Pointer to the next '\n' or NUL character. -char_u *skip_to_newline(const char_u *const p) +char *skip_to_newline(const char *const p) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { - return (char_u *)xstrchrnul((const char *)p, NL); + return xstrchrnul(p, NL); } /// Gets a number from a string and skips over it, signalling overflow. @@ -1422,10 +1422,10 @@ int32_t getdigits_int32(char **pp, bool strict, long def) /// Check that "lbuf" is empty or only contains blanks. /// /// @param lbuf line buffer to check -bool vim_isblankline(char_u *lbuf) +bool vim_isblankline(char *lbuf) FUNC_ATTR_PURE { - char_u *p = (char_u *)skipwhite((char *)lbuf); + char *p = skipwhite(lbuf); return *p == NUL || *p == '\r' || *p == '\n'; } @@ -1664,8 +1664,9 @@ int hex2nr(int c) } /// Convert two hex characters to a byte. -/// Return -1 if one of the characters is not hex. -int hexhex2nr(const char_u *p) +/// +/// @return -1 if one of the characters is not hex. +int hexhex2nr(const char *p) FUNC_ATTR_PURE { if (!ascii_isxdigit(p[0]) || !ascii_isxdigit(p[1])) { @@ -1707,10 +1708,10 @@ bool rem_backslash(const char *str) /// Halve the number of backslashes in a file name argument. /// /// @param p -void backslash_halve(char_u *p) +void backslash_halve(char *p) { for (; *p; p++) { - if (rem_backslash((char *)p)) { + if (rem_backslash(p)) { STRMOVE(p, p + 1); } } @@ -1721,11 +1722,11 @@ void backslash_halve(char_u *p) /// @param p /// /// @return String with the number of backslashes halved. -char_u *backslash_halve_save(const char_u *p) +char *backslash_halve_save(const char *p) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { // TODO(philix): simplify and improve backslash_halve_save algorithm - char_u *res = vim_strsave(p); + char *res = xstrdup(p); backslash_halve(res); return res; } -- cgit From fb1edb2f5728d74ae811c6ab32395598cea5609b Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 4efd8a4ad1..4604bf7716 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -927,11 +927,11 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en } } posptr = ptr + pos->col; - posptr -= utf_head_off(line, posptr); + posptr -= utf_head_off((char *)line, (char *)posptr); } chartabsize_T cts; - init_chartabsize_arg(&cts, wp, pos->lnum, 0, line, line); + init_chartabsize_arg(&cts, wp, pos->lnum, 0, (char *)line, (char *)line); // This function is used very often, do some speed optimizations. // When 'list', 'linebreak', 'showbreak' and 'breakindent' are not set -- cgit From 49e893f296bca9eef5ff45a3d746c261d055bf10 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 4604bf7716..3396e2de41 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -789,7 +789,7 @@ bool vim_iswordc_buf(const int c, buf_T *const buf) bool vim_iswordp(const char_u *const p) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return vim_iswordp_buf(p, curbuf); + return vim_iswordp_buf((char *)p, curbuf); } /// Just like vim_iswordc_buf() but uses a pointer to the (multi-byte) @@ -799,13 +799,13 @@ bool vim_iswordp(const char_u *const p) /// @param buf buffer whose keywords to use /// /// @return true if "p" points to a keyword character. -bool vim_iswordp_buf(const char_u *const p, buf_T *const buf) +bool vim_iswordp_buf(const char *const p, buf_T *const buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - int c = *p; + int c = (uint8_t)(*p); if (MB_BYTE2LEN(c) > 1) { - c = utf_ptr2char((char *)p); + c = utf_ptr2char(p); } return vim_iswordc_buf(c, buf); } @@ -829,8 +829,8 @@ bool vim_isfilec(int c) bool vim_isfilec_or_wc(int c) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - char_u buf[2]; - buf[0] = (char_u)c; + char buf[2]; + buf[0] = (char)c; buf[1] = NUL; return vim_isfilec(c) || c == ']' || path_has_wildcard(buf); } @@ -905,15 +905,15 @@ bool in_win_border(win_T *wp, colnr_T vcol) /// @param end void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end) { - char_u *ptr; // points to current char - char_u *posptr; // points to char at pos->col + char *ptr; // points to current char + char *posptr; // points to char at pos->col int incr; int head; long *vts = wp->w_buffer->b_p_vts_array; int ts = (int)wp->w_buffer->b_p_ts; colnr_T vcol = 0; - char_u *line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); // start of the line + char *line = ptr = (char *)ml_get_buf(wp->w_buffer, pos->lnum, false); // start of the line if (pos->col == MAXCOL) { // continue until the NUL @@ -927,11 +927,11 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en } } posptr = ptr + pos->col; - posptr -= utf_head_off((char *)line, (char *)posptr); + posptr -= utf_head_off(line, posptr); } chartabsize_T cts; - init_chartabsize_arg(&cts, wp, pos->lnum, 0, (char *)line, (char *)line); + init_chartabsize_arg(&cts, wp, pos->lnum, 0, line, line); // This function is used very often, do some speed optimizations. // When 'list', 'linebreak', 'showbreak' and 'breakindent' are not set @@ -944,7 +944,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en && !cts.cts_has_virt_text) { for (;;) { head = 0; - int c = *ptr; + int c = (uint8_t)(*ptr); // make sure we don't go past the end of the line if (c == NUL) { @@ -960,7 +960,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en // For utf-8, if the byte is >= 0x80, need to look at // further bytes to find the cell width. if (c >= 0x80) { - incr = utf_ptr2cells((char *)ptr); + incr = utf_ptr2cells(ptr); } else { incr = g_chartab[c] & CT_CELL_MASK; } @@ -970,7 +970,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en // cells wide. if ((incr == 2) && wp->w_p_wrap - && (MB_BYTE2LEN(*ptr) > 1) + && (MB_BYTE2LEN((uint8_t)(*ptr)) > 1) && in_win_border(wp, vcol)) { incr++; head = 1; @@ -999,7 +999,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en break; } - if ((posptr != NULL) && ((char_u *)cts.cts_ptr >= posptr)) { + if ((posptr != NULL) && (cts.cts_ptr >= posptr)) { // character at pos->col break; } @@ -1008,7 +1008,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en MB_PTR_ADV(cts.cts_ptr); } vcol = cts.cts_vcol; - ptr = (char_u *)cts.cts_ptr; + ptr = cts.cts_ptr; } clear_chartabsize_arg(&cts); @@ -1076,10 +1076,10 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *e colnr_T endadd = 0; // Cannot put the cursor on part of a wide character. - char_u *ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); + char *ptr = (char *)ml_get_buf(wp->w_buffer, pos->lnum, false); if (pos->col < (colnr_T)STRLEN(ptr)) { - int c = utf_ptr2char((char *)ptr + pos->col); + int c = utf_ptr2char(ptr + pos->col); if ((c != TAB) && vim_isprintc(c)) { endadd = (colnr_T)(char2cells(c) - 1); if (coladd > endadd) { @@ -1182,7 +1182,7 @@ char *skipwhite_len(const char *p, size_t len) // columns (bytes) at the start of a given line intptr_t getwhitecols_curline(void) { - return getwhitecols((char *)get_cursor_line_ptr()); + return getwhitecols(get_cursor_line_ptr()); } intptr_t getwhitecols(const char *p) @@ -1338,7 +1338,7 @@ char *skip_to_newline(const char *const p) /// Gets a number from a string and skips over it, signalling overflow. /// -/// @param[out] pp A pointer to a pointer to char_u. +/// @param[out] pp A pointer to a pointer to char. /// It will be advanced past the read number. /// @param[out] nr Number read from the string. /// @@ -1355,7 +1355,7 @@ bool try_getdigits(char **pp, intmax_t *nr) /// Gets a number from a string and skips over it. /// -/// @param[out] pp Pointer to a pointer to char_u. +/// @param[out] pp Pointer to a pointer to char. /// It will be advanced past the read number. /// @param strict Abort on overflow. /// @param def Default value, if parsing fails or overflow occurs. @@ -1463,14 +1463,14 @@ bool vim_isblankline(char *lbuf) /// @param strict If true, fail if the number has unexpected trailing /// alphanumeric chars: *len is set to 0 and nothing else is /// returned. -void vim_str2nr(const char_u *const start, int *const prep, int *const len, const int what, +void vim_str2nr(const char *const start, int *const prep, int *const len, const int what, varnumber_T *const nptr, uvarnumber_T *const unptr, const int maxlen, const bool strict) FUNC_ATTR_NONNULL_ARG(1) { - const char *ptr = (const char *)start; + const char *ptr = start; #define STRING_ENDED(ptr) \ - (!(maxlen == 0 || (int)((ptr) - (const char *)start) < maxlen)) + (!(maxlen == 0 || (int)((ptr) - start) < maxlen)) int pre = 0; // default is decimal const bool negative = (ptr[0] == '-'); uvarnumber_T un = 0; @@ -1522,7 +1522,7 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len, cons } else if ((what & (STR2NR_HEX | STR2NR_OCT | STR2NR_OOCT | STR2NR_BIN)) && !STRING_ENDED(ptr + 1) && ptr[0] == '0' && ptr[1] != '8' && ptr[1] != '9') { - pre = (char_u)ptr[1]; + pre = (uint8_t)ptr[1]; // Detect hexadecimal: 0x or 0X followed by hex digit. if ((what & STR2NR_HEX) && !STRING_ENDED(ptr + 2) @@ -1610,7 +1610,7 @@ vim_str2nr_hex: vim_str2nr_proceed: // Check for an alphanumeric character immediately following, that is // most likely a typo. - if (strict && ptr - (const char *)start != maxlen && ASCII_ISALNUM(*ptr)) { + if (strict && ptr - start != maxlen && ASCII_ISALNUM(*ptr)) { return; } @@ -1619,7 +1619,7 @@ vim_str2nr_proceed: } if (len != NULL) { - *len = (int)(ptr - (const char *)start); + *len = (int)(ptr - start); } if (nptr != NULL) { -- cgit From 73207cae611a1efb8cd17139e8228772daeb9866 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 3396e2de41..693ff90179 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -913,7 +913,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en int ts = (int)wp->w_buffer->b_p_ts; colnr_T vcol = 0; - char *line = ptr = (char *)ml_get_buf(wp->w_buffer, pos->lnum, false); // start of the line + char *line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); // start of the line if (pos->col == MAXCOL) { // continue until the NUL @@ -1076,7 +1076,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *e colnr_T endadd = 0; // Cannot put the cursor on part of a wide character. - char *ptr = (char *)ml_get_buf(wp->w_buffer, pos->lnum, false); + char *ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); if (pos->col < (colnr_T)STRLEN(ptr)) { int c = utf_ptr2char(ptr + pos->col); -- cgit From 3ff46544c9872b4161fd098569c30b55fe3abd36 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 693ff90179..0cc2189948 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -268,7 +268,7 @@ int buf_init_chartab(buf_T *buf, int global) void trans_characters(char *buf, int bufsize) { char_u *trs; // translated character - int len = (int)STRLEN(buf); // length of string needing translation + int len = (int)strlen(buf); // length of string needing translation int room = bufsize - len; // room in buffer after string while (*buf != 0) { @@ -1078,7 +1078,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *e // Cannot put the cursor on part of a wide character. char *ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); - if (pos->col < (colnr_T)STRLEN(ptr)) { + if (pos->col < (colnr_T)strlen(ptr)) { int c = utf_ptr2char(ptr + pos->col); if ((c != TAB) && vim_isprintc(c)) { endadd = (colnr_T)(char2cells(c) - 1); @@ -1157,7 +1157,7 @@ char *skipwhite(const char *const p) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { - return skipwhite_len(p, STRLEN(p)); + return skipwhite_len(p, strlen(p)); } /// Like `skipwhite`, but skip up to `len` characters. -- cgit From df646572c53f55268a5dbb61628d7c3b302d5663 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 30 Sep 2022 09:53:52 +0200 Subject: docs: fix typos (#20394) Co-authored-by: Raphael Co-authored-by: smjonas Co-authored-by: zeertzjq --- src/nvim/charset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 0cc2189948..f5db03b0b4 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -650,7 +650,7 @@ static inline unsigned nr2hex(unsigned n) /// /// @param b /// -/// @reeturn Number of display cells. +/// @return Number of display cells. int byte2cells(int b) FUNC_ATTR_PURE { -- cgit From 66360675cf4d091b7460e4a8e1435c13216c1929 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 11 Sep 2022 17:12:44 +0200 Subject: build: allow IWYU to fix includes for all .c files Allow Include What You Use to remove unnecessary includes and only include what is necessary. This helps with reducing compilation times and makes it easier to visualise which dependencies are actually required. Work on https://github.com/neovim/neovim/issues/549, but doesn't close it since this only works fully for .c files and not headers. --- src/nvim/charset.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index f5db03b0b4..82a4698058 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -6,28 +6,35 @@ /// Code related to character sets. #include +#include #include +#include +#include #include -#include +#include "auto/config.h" #include "nvim/ascii.h" +#include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/cursor.h" -#include "nvim/func_attr.h" +#include "nvim/eval/typval.h" +#include "nvim/eval/typval_defs.h" #include "nvim/garray.h" +#include "nvim/globals.h" +#include "nvim/grid_defs.h" #include "nvim/indent.h" -#include "nvim/main.h" +#include "nvim/keycodes.h" +#include "nvim/macros.h" #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/move.h" #include "nvim/option.h" -#include "nvim/os_unix.h" #include "nvim/path.h" #include "nvim/plines.h" +#include "nvim/pos.h" #include "nvim/state.h" -#include "nvim/strings.h" #include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -- cgit From 40f3f75867bf03abfd90e0389a38197a00d37af1 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 82a4698058..1f9b8f9a65 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -274,7 +274,7 @@ int buf_init_chartab(buf_T *buf, int global) /// @param bufsize void trans_characters(char *buf, int bufsize) { - char_u *trs; // translated character + char *trs; // translated character int len = (int)strlen(buf); // length of string needing translation int room = bufsize - len; // room in buffer after string @@ -284,8 +284,8 @@ void trans_characters(char *buf, int bufsize) if ((trs_len = utfc_ptr2len(buf)) > 1) { len -= trs_len; } else { - trs = transchar_byte((uint8_t)(*buf)); - trs_len = (int)STRLEN(trs); + trs = (char *)transchar_byte((uint8_t)(*buf)); + trs_len = (int)strlen(trs); if (trs_len > 1) { room -= trs_len - 1; -- cgit From bd22585061b66d7f71d4832b4a81e950b3c9d19d Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 1f9b8f9a65..a8abee42be 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -423,7 +423,7 @@ char *transstr(const char *const s, bool untab) /// /// When "buf" is NULL, return an allocated string. /// Otherwise, put the result in buf, limited by buflen, and return buf. -char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen) +char_u *str_foldcase(char_u *str, int orglen, char *buf, int buflen) FUNC_ATTR_NONNULL_RET { garray_T ga; @@ -431,7 +431,7 @@ char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen) int len = orglen; #define GA_CHAR(i) ((char *)ga.ga_data)[i] -#define GA_PTR(i) ((char_u *)ga.ga_data + (i)) +#define GA_PTR(i) ((char *)ga.ga_data + (i)) #define STR_CHAR(i) (buf == NULL ? GA_CHAR(i) : buf[i]) #define STR_PTR(i) (buf == NULL ? GA_PTR(i) : buf + (i)) @@ -459,8 +459,8 @@ char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen) // Make each character lower case. i = 0; while (STR_CHAR(i) != NUL) { - int c = utf_ptr2char((char *)STR_PTR(i)); - int olen = utf_ptr2len((char *)STR_PTR(i)); + int c = utf_ptr2char(STR_PTR(i)); + int olen = utf_ptr2len(STR_PTR(i)); int lc = mb_tolower(c); // Only replace the character when it is not an invalid @@ -494,17 +494,17 @@ char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen) } } } - (void)utf_char2bytes(lc, (char *)STR_PTR(i)); + (void)utf_char2bytes(lc, STR_PTR(i)); } // skip to next multi-byte char - i += utfc_ptr2len((char *)STR_PTR(i)); + i += utfc_ptr2len(STR_PTR(i)); } if (buf == NULL) { return (char_u *)ga.ga_data; } - return buf; + return (char_u *)buf; } // Catch 22: g_chartab[] can't be initialized before the options are -- cgit From b42d8a43b9f1b3316e73108ebefc4850b1a2c65b Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 16 Dec 2022 13:50:12 +0100 Subject: refactor(tui): use nvim_echo() for verbose terminfo This is needed for #18375 for the obvious reasons. note: verbose_terminfo_event is only temporarily needed until the full TUI process refactor is merged. --- src/nvim/charset.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index a8abee42be..51eddd5850 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -418,6 +418,22 @@ char *transstr(const char *const s, bool untab) return buf; } +size_t kv_transstr(StringBuilder *str, const char *const s, bool untab) + FUNC_ATTR_NONNULL_ARG(1) +{ + if (!s) { + return 0; + } + + // Compute the length of the result, taking account of unprintable + // multi-byte characters. + const size_t len = transstr_len(s, untab); + kv_ensure_space(*str, len + 1); + transstr_buf(s, str->items + str->size, len + 1, untab); + str->size += len; // do not include NUL byte + return len; +} + /// Convert the string "str[orglen]" to do ignore-case comparing. /// Use the current locale. /// -- cgit From 08c2c7480619ccdf0c92fe6ce76da5b73b0e395b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 26 Nov 2022 18:57:46 +0100 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 51eddd5850..51ea7f3205 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1721,7 +1721,7 @@ bool rem_backslash(const char *str) || (str[1] != NUL && str[1] != '*' && str[1] != '?' - && !vim_isfilec(str[1]))); + && !vim_isfilec((uint8_t)str[1]))); #else // ifdef BACKSLASH_IN_FILENAME return str[0] == '\\' && str[1] != NUL; -- cgit From 50f03773f4b9f4638489ccfd0503dc9e39e5de78 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:37:34 +0100 Subject: refactor: replace char_u with char 18 (#21237) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 51ea7f3205..4115743e1c 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -439,7 +439,7 @@ size_t kv_transstr(StringBuilder *str, const char *const s, bool untab) /// /// When "buf" is NULL, return an allocated string. /// Otherwise, put the result in buf, limited by buflen, and return buf. -char_u *str_foldcase(char_u *str, int orglen, char *buf, int buflen) +char *str_foldcase(char *str, int orglen, char *buf, int buflen) FUNC_ATTR_NONNULL_RET { garray_T ga; @@ -518,9 +518,9 @@ char_u *str_foldcase(char_u *str, int orglen, char *buf, int buflen) } if (buf == NULL) { - return (char_u *)ga.ga_data; + return ga.ga_data; } - return (char_u *)buf; + return buf; } // Catch 22: g_chartab[] can't be initialized before the options are @@ -809,10 +809,10 @@ bool vim_iswordc_buf(const int c, buf_T *const buf) /// @param p pointer to the multi-byte character /// /// @return true if "p" points to a keyword character. -bool vim_iswordp(const char_u *const p) +bool vim_iswordp(const char *const p) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return vim_iswordp_buf((char *)p, curbuf); + return vim_iswordp_buf(p, curbuf); } /// Just like vim_iswordc_buf() but uses a pointer to the (multi-byte) -- cgit From 3269902a13df3bccf8705db73488c0a47f495514 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 15 Jan 2023 14:16:33 +0100 Subject: refactor: fix IWYU mapping file and use IWYU (#21802) Also add the EXITFREE definition to main_lib rather than the nvim target, as the header generation needs the EXITFREE flag to work properly. --- src/nvim/charset.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 4115743e1c..aa2d845728 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -13,6 +13,7 @@ #include #include "auto/config.h" +#include "klib/kvec.h" #include "nvim/ascii.h" #include "nvim/buffer_defs.h" #include "nvim/charset.h" @@ -35,6 +36,7 @@ #include "nvim/plines.h" #include "nvim/pos.h" #include "nvim/state.h" +#include "nvim/strings.h" #include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -- cgit From 0344bfad0fc87d2e256ea2b80de7abd069ba1dd2 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 17 Jan 2023 14:17:40 +0100 Subject: refactor: replace char_u with char 22 (#21786) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/charset.c') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index aa2d845728..fa9aa27774 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -146,19 +146,19 @@ int buf_init_chartab(buf_T *buf, int global) // options Each option is a list of characters, character numbers or // ranges, separated by commas, e.g.: "200-210,x,#-178,-" for (i = global ? 0 : 3; i <= 3; i++) { - const char_u *p; + const char *p; if (i == 0) { // first round: 'isident' - p = (char_u *)p_isi; + p = p_isi; } else if (i == 1) { // second round: 'isprint' - p = (char_u *)p_isp; + p = p_isp; } else if (i == 2) { // third round: 'isfname' - p = (char_u *)p_isf; + p = p_isf; } else { // i == 3 // fourth round: 'iskeyword' - p = (char_u *)buf->b_p_isk; + p = buf->b_p_isk; } while (*p) { @@ -254,8 +254,8 @@ int buf_init_chartab(buf_T *buf, int global) c++; } - c = *p; - p = (char_u *)skip_to_option_part((char *)p); + c = (uint8_t)(*p); + p = skip_to_option_part(p); if ((c == ',') && (*p == NUL)) { // Trailing comma is not allowed. -- cgit From 8a4285d5637c146a0ae606918a8e77063c6a5f0d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 18 Jan 2023 14:17:11 +0100 Subject: refactor: replace char_u with char 24 (#21823) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/charset.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/charset.c') 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 -- cgit