refactor: remove char_u (#22829)

Closes https://github.com/neovim/neovim/issues/459
This commit is contained in:
dundargoc
2023-04-02 10:11:42 +02:00
committed by GitHub
parent 9084948893
commit d510bfbc8e
40 changed files with 340 additions and 1965 deletions

View File

@@ -55,7 +55,7 @@ static bool chartab_initialized = false;
((chartab)[(unsigned)(c) >> 6] & (1ull << ((c) & 0x3f))) ((chartab)[(unsigned)(c) >> 6] & (1ull << ((c) & 0x3f)))
// Table used below, see init_chartab() for an explanation // Table used below, see init_chartab() for an explanation
static char_u g_chartab[256]; static uint8_t g_chartab[256];
// Flags for g_chartab[]. // Flags for g_chartab[].
#define CT_CELL_MASK 0x07 ///< mask: nr of display cells (1, 2 or 4) #define CT_CELL_MASK 0x07 ///< mask: nr of display cells (1, 2 or 4)
@@ -286,7 +286,7 @@ void trans_characters(char *buf, int bufsize)
if ((trs_len = utfc_ptr2len(buf)) > 1) { if ((trs_len = utfc_ptr2len(buf)) > 1) {
len -= trs_len; len -= trs_len;
} else { } else {
trs = (char *)transchar_byte((uint8_t)(*buf)); trs = transchar_byte((uint8_t)(*buf));
trs_len = (int)strlen(trs); trs_len = (int)strlen(trs);
if (trs_len > 1) { if (trs_len > 1) {
@@ -532,7 +532,7 @@ char *str_foldcase(char *str, int orglen, char *buf, int buflen)
// Does NOT work for multi-byte characters, c must be <= 255. // Does NOT work for multi-byte characters, c must be <= 255.
// Also doesn't work for the first byte of a multi-byte, "c" must be a // Also doesn't work for the first byte of a multi-byte, "c" must be a
// character! // character!
static char_u transchar_charbuf[11]; static uint8_t transchar_charbuf[11];
/// Translate a character into a printable one, leaving printable ASCII intact /// Translate a character into a printable one, leaving printable ASCII intact
/// ///
@@ -543,10 +543,10 @@ static char_u transchar_charbuf[11];
/// @return translated character into a static buffer. /// @return translated character into a static buffer.
char *transchar(int c) char *transchar(int c)
{ {
return (char *)transchar_buf(curbuf, c); return transchar_buf(curbuf, c);
} }
char_u *transchar_buf(const buf_T *buf, int c) char *transchar_buf(const buf_T *buf, int c)
{ {
int i = 0; int i = 0;
if (IS_SPECIAL(c)) { if (IS_SPECIAL(c)) {
@@ -560,14 +560,14 @@ char_u *transchar_buf(const buf_T *buf, int c)
if ((!chartab_initialized && (c >= ' ' && c <= '~')) if ((!chartab_initialized && (c >= ' ' && c <= '~'))
|| ((c <= 0xFF) && vim_isprintc_strict(c))) { || ((c <= 0xFF) && vim_isprintc_strict(c))) {
// printable character // printable character
transchar_charbuf[i] = (char_u)c; transchar_charbuf[i] = (uint8_t)c;
transchar_charbuf[i + 1] = NUL; transchar_charbuf[i + 1] = NUL;
} else if (c <= 0xFF) { } else if (c <= 0xFF) {
transchar_nonprint(buf, transchar_charbuf + i, c); transchar_nonprint(buf, (char *)transchar_charbuf + i, c);
} else { } else {
transchar_hex((char *)transchar_charbuf + i, c); transchar_hex((char *)transchar_charbuf + i, c);
} }
return transchar_charbuf; return (char *)transchar_charbuf;
} }
/// Like transchar(), but called with a byte instead of a character. /// Like transchar(), but called with a byte instead of a character.
@@ -577,7 +577,7 @@ char_u *transchar_buf(const buf_T *buf, int c)
/// @param[in] c Byte to translate. /// @param[in] c Byte to translate.
/// ///
/// @return pointer to translated character in transchar_charbuf. /// @return pointer to translated character in transchar_charbuf.
char_u *transchar_byte(const int c) char *transchar_byte(const int c)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_WARN_UNUSED_RESULT
{ {
return transchar_byte_buf(curbuf, c); return transchar_byte_buf(curbuf, c);
@@ -590,12 +590,12 @@ char_u *transchar_byte(const int c)
/// @param[in] c Byte to translate. /// @param[in] c Byte to translate.
/// ///
/// @return pointer to translated character in transchar_charbuf. /// @return pointer to translated character in transchar_charbuf.
char_u *transchar_byte_buf(const buf_T *buf, const int c) char *transchar_byte_buf(const buf_T *buf, const int c)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_WARN_UNUSED_RESULT
{ {
if (c >= 0x80) { if (c >= 0x80) {
transchar_nonprint(buf, transchar_charbuf, c); transchar_nonprint(buf, (char *)transchar_charbuf, c);
return transchar_charbuf; return (char *)transchar_charbuf;
} }
return transchar_buf(buf, c); return transchar_buf(buf, c);
} }
@@ -609,7 +609,7 @@ char_u *transchar_byte_buf(const buf_T *buf, const int c)
/// at least 5 bytes (conversion result + NUL). /// at least 5 bytes (conversion result + NUL).
/// @param[in] c Character to convert. NUL is assumed to be NL according to /// @param[in] c Character to convert. NUL is assumed to be NL according to
/// `:h NL-used-for-NUL`. /// `:h NL-used-for-NUL`.
void transchar_nonprint(const buf_T *buf, char_u *charbuf, int c) void transchar_nonprint(const buf_T *buf, char *charbuf, int c)
{ {
if (c == NL) { if (c == NL) {
// we use newline in place of a NUL // we use newline in place of a NUL
@@ -622,12 +622,12 @@ void transchar_nonprint(const buf_T *buf, char_u *charbuf, int c)
if (dy_flags & DY_UHEX || c > 0x7f) { if (dy_flags & DY_UHEX || c > 0x7f) {
// 'display' has "uhex" // 'display' has "uhex"
transchar_hex((char *)charbuf, c); transchar_hex(charbuf, c);
} else { } else {
// 0x00 - 0x1f and 0x7f // 0x00 - 0x1f and 0x7f
charbuf[0] = '^'; charbuf[0] = '^';
// DEL displayed as ^? // DEL displayed as ^?
charbuf[1] = (char_u)(c ^ 0x40); charbuf[1] = (char)(uint8_t)(c ^ 0x40);
charbuf[2] = NUL; charbuf[2] = NUL;
} }

View File

@@ -54,6 +54,6 @@ static inline bool vim_isbreak(int c)
/// Used very often if 'linebreak' is set /// Used very often if 'linebreak' is set
static inline bool vim_isbreak(int c) static inline bool vim_isbreak(int c)
{ {
return breakat_flags[(char_u)c]; return breakat_flags[(uint8_t)c];
} }
#endif // NVIM_CHARSET_H #endif // NVIM_CHARSET_H

View File

@@ -2371,7 +2371,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
mb_c = c; mb_c = c;
mb_utf8 = check_mb_utf8(&c, u8cc); mb_utf8 = check_mb_utf8(&c, u8cc);
} else if (c != NUL) { } else if (c != NUL) {
wlv.p_extra = (char *)transchar_buf(wp->w_buffer, c); wlv.p_extra = transchar_buf(wp->w_buffer, c);
if (wlv.n_extra == 0) { if (wlv.n_extra == 0) {
wlv.n_extra = byte2cells(c) - 1; wlv.n_extra = byte2cells(c) - 1;
} }

View File

@@ -1955,7 +1955,7 @@ static void insert_special(int c, int allow_modmask, int ctrlv)
allow_modmask = true; allow_modmask = true;
} }
if (IS_SPECIAL(c) || (mod_mask && allow_modmask)) { if (IS_SPECIAL(c) || (mod_mask && allow_modmask)) {
char *p = (char *)get_special_key_name(c, mod_mask); char *p = get_special_key_name(c, mod_mask);
int len = (int)strlen(p); int len = (int)strlen(p);
c = (uint8_t)p[len - 1]; c = (uint8_t)p[len - 1];
if (len > 2) { if (len > 2) {

View File

@@ -6197,7 +6197,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
} }
# else # else
char *v = os_realpath(fname, NULL); char *v = os_realpath(fname, NULL);
rettv->vval.v_string = (char_u *)(v == NULL ? xstrdup(fname) : v); rettv->vval.v_string = v == NULL ? xstrdup(fname) : v;
# endif # endif
#endif #endif

View File

@@ -206,7 +206,7 @@ typedef struct {
struct { \ struct { \
typval_T di_tv; /* Structure that holds scope dictionary itself. */ \ typval_T di_tv; /* Structure that holds scope dictionary itself. */ \
uint8_t di_flags; /* Flags. */ \ uint8_t di_flags; /* Flags. */ \
char_u di_key[__VA_ARGS__]; /* Key value. */ /* NOLINT(runtime/arrays)*/ \ char di_key[__VA_ARGS__]; /* Key value. */ /* NOLINT(runtime/arrays)*/ \
} }
/// Structure to hold a scope dictionary /// Structure to hold a scope dictionary

View File

@@ -90,7 +90,7 @@ static int get_function_args(char **argp, char endchar, garray_T *newargs, int *
bool mustend = false; bool mustend = false;
char *arg = *argp; char *arg = *argp;
char *p = arg; char *p = arg;
char_u c; uint8_t c;
int i; int i;
if (newargs != NULL) { if (newargs != NULL) {
@@ -128,7 +128,7 @@ static int get_function_args(char **argp, char endchar, garray_T *newargs, int *
} }
if (newargs != NULL) { if (newargs != NULL) {
ga_grow(newargs, 1); ga_grow(newargs, 1);
c = (char_u)(*p); c = (uint8_t)(*p);
*p = NUL; *p = NUL;
arg = xstrdup(arg); arg = xstrdup(arg);
@@ -159,7 +159,7 @@ static int get_function_args(char **argp, char endchar, garray_T *newargs, int *
while (p > expr && ascii_iswhite(p[-1])) { while (p > expr && ascii_iswhite(p[-1])) {
p--; p--;
} }
c = (char_u)(*p); c = (uint8_t)(*p);
*p = NUL; *p = NUL;
expr = xstrdup(expr); expr = xstrdup(expr);
((char **)(default_args->ga_data))[default_args->ga_len] = expr; ((char **)(default_args->ga_data))[default_args->ga_len] = expr;

View File

@@ -149,7 +149,7 @@ void do_ascii(const exarg_T *const eap)
char buf1[20]; char buf1[20];
if (vim_isprintc_strict(c) && (c < ' ' || c > '~')) { if (vim_isprintc_strict(c) && (c < ' ' || c > '~')) {
char buf3[7]; char buf3[7];
transchar_nonprint(curbuf, (char_u *)buf3, c); transchar_nonprint(curbuf, buf3, c);
vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3); vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3);
} else { } else {
buf1[0] = NUL; buf1[0] = NUL;

View File

@@ -2117,7 +2117,7 @@ static int command_line_handle_key(CommandLineState *s)
// put the character in the command line // put the character in the command line
if (IS_SPECIAL(s->c) || mod_mask != 0) { if (IS_SPECIAL(s->c) || mod_mask != 0) {
put_on_cmdline((char *)get_special_key_name(s->c, mod_mask), -1, true); put_on_cmdline(get_special_key_name(s->c, mod_mask), -1, true);
} else { } else {
int j = utf_char2bytes(s->c, IObuff); int j = utf_char2bytes(s->c, IObuff);
IObuff[j] = NUL; // exclude composing chars IObuff[j] = NUL; // exclude composing chars

View File

@@ -794,7 +794,7 @@ char *vim_findfile(void *search_ctx_arg)
) { ) {
#ifdef FF_VERBOSE #ifdef FF_VERBOSE
if (ff_check_visited(&search_ctx->ffsc_visited_list->ffvl_visited_list, if (ff_check_visited(&search_ctx->ffsc_visited_list->ffvl_visited_list,
file_path, (char_u *)"") == FAIL) { file_path, "") == FAIL) {
if (p_verbose >= 5) { if (p_verbose >= 5) {
verbose_enter_scroll(); verbose_enter_scroll();
smsg("Already: %s", file_path); smsg("Already: %s", file_path);

View File

@@ -41,7 +41,7 @@ static const uint16_t cmdidxs1[%u] = {
-- Values in cmdidxs2[c1][c2] are relative to cmdidxs1[c1] so that they -- Values in cmdidxs2[c1][c2] are relative to cmdidxs1[c1] so that they
-- fit in a byte. -- fit in a byte.
local cmdidxs2_out = string.format([[ local cmdidxs2_out = string.format([[
static const char_u cmdidxs2[%u][%u] = { static const uint8_t cmdidxs2[%u][%u] = {
/* a b c d e f g h i j k l m n o p q r s t u v w x y z */ /* a b c d e f g h i j k l m n o p q r s t u v w x y z */
]], a_to_z, a_to_z) ]], a_to_z, a_to_z)

View File

@@ -139,7 +139,7 @@ local dump_option = function(i, o)
w(get_cond(o.enable_if)) w(get_cond(o.enable_if))
end end
if o.varname then if o.varname then
w(' .var=(char_u *)&' .. o.varname) w(' .var=(char *)&' .. o.varname)
elseif #o.scope == 1 and o.scope[1] == 'window' then elseif #o.scope == 1 and o.scope[1] == 'window' then
w(' .var=VAR_WIN') w(' .var=VAR_WIN')
end end

View File

@@ -34,18 +34,18 @@
static const struct modmasktable { static const struct modmasktable {
uint16_t mod_mask; ///< Bit-mask for particular key modifier. uint16_t mod_mask; ///< Bit-mask for particular key modifier.
uint16_t mod_flag; ///< Bit(s) for particular key modifier. uint16_t mod_flag; ///< Bit(s) for particular key modifier.
char_u name; ///< Single letter name of modifier. char name; ///< Single letter name of modifier.
} mod_mask_table[] = { } mod_mask_table[] = {
{ MOD_MASK_ALT, MOD_MASK_ALT, (char_u)'M' }, { MOD_MASK_ALT, MOD_MASK_ALT, 'M' },
{ MOD_MASK_META, MOD_MASK_META, (char_u)'T' }, { MOD_MASK_META, MOD_MASK_META, 'T' },
{ MOD_MASK_CTRL, MOD_MASK_CTRL, (char_u)'C' }, { MOD_MASK_CTRL, MOD_MASK_CTRL, 'C' },
{ MOD_MASK_SHIFT, MOD_MASK_SHIFT, (char_u)'S' }, { MOD_MASK_SHIFT, MOD_MASK_SHIFT, 'S' },
{ MOD_MASK_MULTI_CLICK, MOD_MASK_2CLICK, (char_u)'2' }, { MOD_MASK_MULTI_CLICK, MOD_MASK_2CLICK, '2' },
{ MOD_MASK_MULTI_CLICK, MOD_MASK_3CLICK, (char_u)'3' }, { MOD_MASK_MULTI_CLICK, MOD_MASK_3CLICK, '3' },
{ MOD_MASK_MULTI_CLICK, MOD_MASK_4CLICK, (char_u)'4' }, { MOD_MASK_MULTI_CLICK, MOD_MASK_4CLICK, '4' },
{ MOD_MASK_CMD, MOD_MASK_CMD, (char_u)'D' }, { MOD_MASK_CMD, MOD_MASK_CMD, 'D' },
// 'A' must be the last one // 'A' must be the last one
{ MOD_MASK_ALT, MOD_MASK_ALT, (char_u)'A' }, { MOD_MASK_ALT, MOD_MASK_ALT, 'A' },
{ 0, 0, NUL } { 0, 0, NUL }
// NOTE: when adding an entry, update MAX_KEY_NAME_LEN! // NOTE: when adding an entry, update MAX_KEY_NAME_LEN!
}; };
@@ -386,7 +386,7 @@ int name_to_mod_mask(int c)
{ {
c = TOUPPER_ASC(c); c = TOUPPER_ASC(c);
for (size_t i = 0; mod_mask_table[i].mod_mask != 0; i++) { for (size_t i = 0; mod_mask_table[i].mod_mask != 0; i++) {
if (c == mod_mask_table[i].name) { if (c == (uint8_t)mod_mask_table[i].name) {
return mod_mask_table[i].mod_flag; return mod_mask_table[i].mod_flag;
} }
} }
@@ -468,9 +468,9 @@ int handle_x_keys(const int key)
} }
/// @return a string which contains the name of the given key when the given modifiers are down. /// @return a string which contains the name of the given key when the given modifiers are down.
char_u *get_special_key_name(int c, int modifiers) char *get_special_key_name(int c, int modifiers)
{ {
static char_u string[MAX_KEY_NAME_LEN + 1]; static char string[MAX_KEY_NAME_LEN + 1];
int i, idx; int i, idx;
int table_idx; int table_idx;
@@ -524,7 +524,7 @@ char_u *get_special_key_name(int c, int modifiers)
if ((modifiers & mod_mask_table[i].mod_mask) if ((modifiers & mod_mask_table[i].mod_mask)
== mod_mask_table[i].mod_flag) { == mod_mask_table[i].mod_flag) {
string[idx++] = mod_mask_table[i].name; string[idx++] = mod_mask_table[i].name;
string[idx++] = (char_u)'-'; string[idx++] = '-';
} }
} }
@@ -532,18 +532,18 @@ char_u *get_special_key_name(int c, int modifiers)
if (IS_SPECIAL(c)) { if (IS_SPECIAL(c)) {
string[idx++] = 't'; string[idx++] = 't';
string[idx++] = '_'; string[idx++] = '_';
string[idx++] = (char_u)KEY2TERMCAP0(c); string[idx++] = (char)(uint8_t)KEY2TERMCAP0(c);
string[idx++] = KEY2TERMCAP1(c); string[idx++] = (char)(uint8_t)KEY2TERMCAP1(c);
} else { } else {
// Not a special key, only modifiers, output directly. // Not a special key, only modifiers, output directly.
if (utf_char2len(c) > 1) { if (utf_char2len(c) > 1) {
idx += utf_char2bytes(c, (char *)string + idx); idx += utf_char2bytes(c, string + idx);
} else if (vim_isprintc(c)) { } else if (vim_isprintc(c)) {
string[idx++] = (char_u)c; string[idx++] = (char)(uint8_t)c;
} else { } else {
s = transchar(c); s = transchar(c);
while (*s) { while (*s) {
string[idx++] = (uint8_t)(*s++); string[idx++] = *s++;
} }
} }
} }
@@ -1083,7 +1083,7 @@ char *vim_strsave_escape_ks(char *p)
/// vim_strsave_escape_ks(). Works in-place. /// vim_strsave_escape_ks(). Works in-place.
void vim_unescape_ks(char *p) void vim_unescape_ks(char *p)
{ {
char_u *s = (char_u *)p, *d = (char_u *)p; uint8_t *s = (uint8_t *)p, *d = (uint8_t *)p;
while (*s != NUL) { while (*s != NUL) {
if (s[0] == K_SPECIAL && s[1] == KS_SPECIAL && s[2] == KE_FILLER) { if (s[0] == K_SPECIAL && s[1] == KS_SPECIAL && s[2] == KE_FILLER) {

View File

@@ -1189,7 +1189,7 @@ static char *translate_mapping(char *str_in, int cpo_flags)
str += 2; str += 2;
} }
if (IS_SPECIAL(c) || modifiers) { // special key if (IS_SPECIAL(c) || modifiers) { // special key
ga_concat(&ga, (char *)get_special_key_name(c, modifiers)); ga_concat(&ga, get_special_key_name(c, modifiers));
continue; // for (str) continue; // for (str)
} }
} }
@@ -1436,7 +1436,7 @@ int ExpandMappings(char *pat, regmatch_T *regmatch, int *numMatches, char ***mat
bool check_abbr(int c, char *ptr, int col, int mincol) bool check_abbr(int c, char *ptr, int col, int mincol)
{ {
int scol; // starting column of the abbr. int scol; // starting column of the abbr.
char_u tb[MB_MAXBYTES + 4]; uint8_t tb[MB_MAXBYTES + 4];
mapblock_T *mp; mapblock_T *mp;
mapblock_T *mp2; mapblock_T *mp2;
int clen = 0; // length in characters int clen = 0; // length in characters
@@ -1535,8 +1535,8 @@ bool check_abbr(int c, char *ptr, int col, int mincol)
// special key code, split up // special key code, split up
if (IS_SPECIAL(c) || c == K_SPECIAL) { if (IS_SPECIAL(c) || c == K_SPECIAL) {
tb[j++] = K_SPECIAL; tb[j++] = K_SPECIAL;
tb[j++] = (char_u)K_SECOND(c); tb[j++] = (uint8_t)K_SECOND(c);
tb[j++] = (char_u)K_THIRD(c); tb[j++] = (uint8_t)K_THIRD(c);
} else { } else {
if (c < ABBR_OFF && (c < ' ' || c > '~')) { if (c < ABBR_OFF && (c < ' ' || c > '~')) {
tb[j++] = Ctrl_V; // special char needs CTRL-V tb[j++] = Ctrl_V; // special char needs CTRL-V
@@ -1918,7 +1918,7 @@ int put_escstr(FILE *fd, char *strstart, int what)
str += 2; str += 2;
} }
if (IS_SPECIAL(c) || modifiers) { // special key if (IS_SPECIAL(c) || modifiers) { // special key
if (fputs((char *)get_special_key_name(c, modifiers), fd) < 0) { if (fputs(get_special_key_name(c, modifiers), fd) < 0) {
return FAIL; return FAIL;
} }
continue; continue;

View File

@@ -653,32 +653,32 @@ int utf_ptr2char(const char *const p_in)
// //
// If byte sequence is illegal or incomplete, returns -1 and does not advance // If byte sequence is illegal or incomplete, returns -1 and does not advance
// "s". // "s".
static int utf_safe_read_char_adv(const char_u **s, size_t *n) static int utf_safe_read_char_adv(const char **s, size_t *n)
{ {
if (*n == 0) { // end of buffer if (*n == 0) { // end of buffer
return 0; return 0;
} }
uint8_t k = utf8len_tab_zero[**s]; uint8_t k = utf8len_tab_zero[(uint8_t)(**s)];
if (k == 1) { if (k == 1) {
// ASCII character or NUL // ASCII character or NUL
(*n)--; (*n)--;
return *(*s)++; return (uint8_t)(*(*s)++);
} }
if (k <= *n) { if (k <= *n) {
// We have a multibyte sequence and it isn't truncated by buffer // We have a multibyte sequence and it isn't truncated by buffer
// limits so utf_ptr2char() is safe to use. Or the first byte is // limits so utf_ptr2char() is safe to use. Or the first byte is
// illegal (k=0), and it's also safe to use utf_ptr2char(). // illegal (k=0), and it's also safe to use utf_ptr2char().
int c = utf_ptr2char((char *)(*s)); int c = utf_ptr2char(*s);
// On failure, utf_ptr2char() returns the first byte, so here we // On failure, utf_ptr2char() returns the first byte, so here we
// check equality with the first byte. The only non-ASCII character // check equality with the first byte. The only non-ASCII character
// which equals the first byte of its own UTF-8 representation is // which equals the first byte of its own UTF-8 representation is
// U+00C3 (UTF-8: 0xC3 0x83), so need to check that special case too. // U+00C3 (UTF-8: 0xC3 0x83), so need to check that special case too.
// It's safe even if n=1, else we would have k=2 > n. // It's safe even if n=1, else we would have k=2 > n.
if (c != (int)(**s) || (c == 0xC3 && (*s)[1] == 0x83)) { if (c != (int)((uint8_t)(**s)) || (c == 0xC3 && (uint8_t)(*s)[1] == 0x83)) {
// byte sequence was successfully decoded // byte sequence was successfully decoded
*s += k; *s += k;
*n -= k; *n -= k;
@@ -1271,7 +1271,7 @@ bool mb_isalpha(int a)
return mb_islower(a) || mb_isupper(a); return mb_islower(a) || mb_isupper(a);
} }
static int utf_strnicmp(const char_u *s1, const char_u *s2, size_t n1, size_t n2) static int utf_strnicmp(const char *s1, const char *s2, size_t n1, size_t n2)
{ {
int c1, c2, cdiff; int c1, c2, cdiff;
char buffer[6]; char buffer[6];
@@ -1313,14 +1313,14 @@ static int utf_strnicmp(const char_u *s1, const char_u *s2, size_t n1, size_t n2
if (c1 != -1 && c2 == -1) { if (c1 != -1 && c2 == -1) {
n1 = (size_t)utf_char2bytes(utf_fold(c1), (char *)buffer); n1 = (size_t)utf_char2bytes(utf_fold(c1), (char *)buffer);
s1 = (char_u *)buffer; s1 = buffer;
} else if (c2 != -1 && c1 == -1) { } else if (c2 != -1 && c1 == -1) {
n2 = (size_t)utf_char2bytes(utf_fold(c2), (char *)buffer); n2 = (size_t)utf_char2bytes(utf_fold(c2), (char *)buffer);
s2 = (char_u *)buffer; s2 = buffer;
} }
while (n1 > 0 && n2 > 0 && *s1 != NUL && *s2 != NUL) { while (n1 > 0 && n2 > 0 && *s1 != NUL && *s2 != NUL) {
cdiff = (int)(*s1) - (int)(*s2); cdiff = (int)((uint8_t)(*s1)) - (int)((uint8_t)(*s2));
if (cdiff != 0) { if (cdiff != 0) {
return cdiff; return cdiff;
} }
@@ -1498,7 +1498,7 @@ ssize_t mb_utf_index_to_bytes(const char *s, size_t len, size_t index, bool use_
/// two characters otherwise. /// two characters otherwise.
int mb_strnicmp(const char *s1, const char *s2, const size_t nn) int mb_strnicmp(const char *s1, const char *s2, const size_t nn)
{ {
return utf_strnicmp((char_u *)s1, (char_u *)s2, nn, nn); return utf_strnicmp(s1, s2, nn, nn);
} }
/// Compare strings case-insensitively /// Compare strings case-insensitively

View File

@@ -351,7 +351,7 @@ int ml_open(buf_T *buf)
dp->db_index[0] = --dp->db_txt_start; // at end of block dp->db_index[0] = --dp->db_txt_start; // at end of block
dp->db_free -= 1 + (unsigned)INDEX_SIZE; dp->db_free -= 1 + (unsigned)INDEX_SIZE;
dp->db_line_count = 1; dp->db_line_count = 1;
*((char_u *)dp + dp->db_txt_start) = NUL; // empty line *((char *)dp + dp->db_txt_start) = NUL; // empty line
return OK; return OK;
@@ -1065,7 +1065,7 @@ void ml_recover(bool checkext)
} }
// make sure there is a NUL at the end of the block // make sure there is a NUL at the end of the block
*((char_u *)dp + dp->db_txt_end - 1) = NUL; *((char *)dp + dp->db_txt_end - 1) = NUL;
// check number of lines in block // check number of lines in block
// if wrong, use count in data block // if wrong, use count in data block

View File

@@ -1589,7 +1589,7 @@ int msg_outtrans_len_attr(const char *msgstr, int len, int attr)
len -= mb_l - 1; len -= mb_l - 1;
str += mb_l; str += mb_l;
} else { } else {
s = (char *)transchar_byte_buf(NULL, (uint8_t)(*str)); s = transchar_byte_buf(NULL, (uint8_t)(*str));
if (s[1] != NUL) { if (s[1] != NUL) {
// Unprintable char: print the printable chars so far and the // Unprintable char: print the printable chars so far and the
// translation of the unprintable char. // translation of the unprintable char.
@@ -1671,7 +1671,7 @@ int msg_outtrans_special(const char *strstart, bool from, int maxlen)
} }
if (text[0] != NUL && text[1] == NUL) { if (text[0] != NUL && text[1] == NUL) {
// single-byte character or illegal byte // single-byte character or illegal byte
text = (char *)transchar_byte_buf(NULL, (uint8_t)text[0]); text = transchar_byte_buf(NULL, (uint8_t)text[0]);
} }
const int len = vim_strsize(text); const int len = vim_strsize(text);
if (maxlen > 0 && retval + len >= maxlen) { if (maxlen > 0 && retval + len >= maxlen) {
@@ -1917,7 +1917,7 @@ void msg_prt_line(char *s, int list)
s--; s--;
} else if (c != NUL && (n = byte2cells(c)) > 1) { } else if (c != NUL && (n = byte2cells(c)) > 1) {
n_extra = n - 1; n_extra = n - 1;
p_extra = (char *)transchar_byte_buf(NULL, c); p_extra = transchar_byte_buf(NULL, c);
c_extra = NUL; c_extra = NUL;
c_final = NUL; c_final = NUL;
c = (unsigned char)(*p_extra++); c = (unsigned char)(*p_extra++);

View File

@@ -5162,7 +5162,7 @@ void write_reg_contents_ex(int name, const char *str, ssize_t len, bool must_app
/// @param str string or list of strings to put in register /// @param str string or list of strings to put in register
/// @param len length of the string (Ignored when str_list=true.) /// @param len length of the string (Ignored when str_list=true.)
/// @param blocklen width of visual block, or -1 for "I don't know." /// @param blocklen width of visual block, or -1 for "I don't know."
/// @param str_list True if str is `char_u **`. /// @param str_list True if str is `char **`.
static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, size_t len, static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, size_t len,
colnr_T blocklen, bool str_list) colnr_T blocklen, bool str_list)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL

View File

@@ -421,7 +421,7 @@ static void set_option_default(const int opt_idx, int opt_flags)
// pointer to variable for current option // pointer to variable for current option
vimoption_T *opt = &options[opt_idx]; vimoption_T *opt = &options[opt_idx];
char_u *varp = (char_u *)get_varp_scope(opt, both ? OPT_LOCAL : opt_flags); char *varp = get_varp_scope(opt, both ? OPT_LOCAL : opt_flags);
uint32_t flags = opt->flags; uint32_t flags = opt->flags;
if (varp != NULL) { // skip hidden option, nothing to do for it if (varp != NULL) { // skip hidden option, nothing to do for it
if (flags & P_STRING) { if (flags & P_STRING) {
@@ -833,7 +833,7 @@ static void do_set_num(int opt_idx, int opt_flags, char **argp, int nextchar, co
if (op == OP_REMOVING) { if (op == OP_REMOVING) {
value = *(long *)varp - value; value = *(long *)varp - value;
} }
*errmsg = set_num_option(opt_idx, (char_u *)varp, (long)value, *errmsg = set_num_option(opt_idx, (char *)varp, (long)value,
errbuf, errbuflen, opt_flags); errbuf, errbuflen, opt_flags);
} }
@@ -847,7 +847,7 @@ static void munge_string_opt_val(char **varp, char **oldval, char **const origva
if (varp == &p_kp && (**argp == NUL || **argp == ' ')) { if (varp == &p_kp && (**argp == NUL || **argp == ' ')) {
*save_argp = *argp; *save_argp = *argp;
*argp = ":help"; *argp = ":help";
} else if (varp == &p_bs && ascii_isdigit(**(char_u **)varp)) { } else if (varp == &p_bs && ascii_isdigit((uint8_t)(**varp))) {
// Convert 'backspace' number to string, for // Convert 'backspace' number to string, for
// adding, prepending and removing string. // adding, prepending and removing string.
const int i = getdigits_int(varp, true, 0); const int i = getdigits_int(varp, true, 0);
@@ -927,7 +927,7 @@ static void do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar,
// reset, use the global value here. // reset, use the global value here.
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
&& ((int)options[opt_idx].indir & PV_BOTH)) { && ((int)options[opt_idx].indir & PV_BOTH)) {
varp = (char *)options[opt_idx].var; varp = options[opt_idx].var;
} }
// The old value is kept until we are sure that the new value is valid. // The old value is kept until we are sure that the new value is valid.
@@ -1439,7 +1439,7 @@ static void do_set_option(int opt_flags, char **argp, bool *did_show, char *errb
showoneopt(&options[opt_idx], opt_flags); showoneopt(&options[opt_idx], opt_flags);
if (p_verbose > 0) { if (p_verbose > 0) {
// Mention where the option was last set. // Mention where the option was last set.
if (varp == (char *)options[opt_idx].var) { if (varp == options[opt_idx].var) {
option_last_set_msg(options[opt_idx].last_set); option_last_set_msg(options[opt_idx].last_set);
} else if ((int)options[opt_idx].indir & PV_WIN) { } else if ((int)options[opt_idx].indir & PV_WIN) {
option_last_set_msg(curwin->w_p_script_ctx[(int)options[opt_idx].indir & PV_MASK]); option_last_set_msg(curwin->w_p_script_ctx[(int)options[opt_idx].indir & PV_MASK]);
@@ -1735,7 +1735,7 @@ static char *option_expand(int opt_idx, char *val)
// For 'spellsuggest' expand after "file:". // For 'spellsuggest' expand after "file:".
expand_env_esc(val, NameBuff, MAXPATHL, expand_env_esc(val, NameBuff, MAXPATHL,
(char **)options[opt_idx].var == &p_tags, false, (char **)options[opt_idx].var == &p_tags, false,
(char_u **)options[opt_idx].var == (char_u **)&p_sps ? "file:" : (char **)options[opt_idx].var == &p_sps ? "file:" :
NULL); NULL);
if (strcmp(NameBuff, val) == 0) { // they are the same if (strcmp(NameBuff, val) == 0) { // they are the same
return NULL; return NULL;
@@ -2274,7 +2274,7 @@ static char *set_bool_option(const int opt_idx, char *const varp, const int valu
/// @param[in] opt_flags OPT_LOCAL, OPT_GLOBAL or OPT_MODELINE. /// @param[in] opt_flags OPT_LOCAL, OPT_GLOBAL or OPT_MODELINE.
/// ///
/// @return NULL on success, error message on error. /// @return NULL on success, error message on error.
static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, size_t errbuflen, static char *set_num_option(int opt_idx, char *varp, long value, char *errbuf, size_t errbuflen,
int opt_flags) int opt_flags)
{ {
char *errmsg = NULL; char *errmsg = NULL;
@@ -2905,7 +2905,7 @@ getoption_T get_option_value(const char *name, long *numval, char **stringval, u
return gov_unknown; return gov_unknown;
} }
char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), scope); char *varp = get_varp_scope(&(options[opt_idx]), scope);
if (flagsp != NULL) { if (flagsp != NULL) {
// Return the P_xxxx option flags. // Return the P_xxxx option flags.
@@ -3010,7 +3010,7 @@ int get_option_value_strict(char *name, int64_t *numval, char **stringval, int o
return rv; return rv;
} }
char_u *varp = NULL; char *varp = NULL;
if (opt_type == SREQ_GLOBAL) { if (opt_type == SREQ_GLOBAL) {
if (p->var == VAR_WIN) { if (p->var == VAR_WIN) {
@@ -3030,7 +3030,7 @@ int get_option_value_strict(char *name, int64_t *numval, char **stringval, int o
// only getting a pointer, no need to use aucmd_prepbuf() // only getting a pointer, no need to use aucmd_prepbuf()
curbuf = (buf_T *)from; curbuf = (buf_T *)from;
curwin->w_buffer = curbuf; curwin->w_buffer = curbuf;
varp = (char_u *)get_varp_scope(p, OPT_LOCAL); varp = get_varp_scope(p, OPT_LOCAL);
curbuf = save_curbuf; curbuf = save_curbuf;
curwin->w_buffer = curbuf; curwin->w_buffer = curbuf;
} }
@@ -3038,7 +3038,7 @@ int get_option_value_strict(char *name, int64_t *numval, char **stringval, int o
win_T *save_curwin = curwin; win_T *save_curwin = curwin;
curwin = (win_T *)from; curwin = (win_T *)from;
curbuf = curwin->w_buffer; curbuf = curwin->w_buffer;
varp = (char_u *)get_varp_scope(p, OPT_LOCAL); varp = get_varp_scope(p, OPT_LOCAL);
curwin = save_curwin; curwin = save_curwin;
curbuf = curwin->w_buffer; curbuf = curwin->w_buffer;
} }
@@ -3109,7 +3109,7 @@ char *set_option_value(const char *const name, const long number, const char *co
return set_string_option(opt_idx, s, opt_flags, errbuf, sizeof(errbuf)); return set_string_option(opt_idx, s, opt_flags, errbuf, sizeof(errbuf));
} }
char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags); char *varp = get_varp_scope(&(options[opt_idx]), opt_flags);
if (varp == NULL) { if (varp == NULL) {
// hidden option is not changed // hidden option is not changed
return NULL; return NULL;
@@ -3146,7 +3146,7 @@ char *set_option_value(const char *const name, const long number, const char *co
if (flags & P_NUM) { if (flags & P_NUM) {
return set_num_option(opt_idx, varp, numval, errbuf, sizeof(errbuf), opt_flags); return set_num_option(opt_idx, varp, numval, errbuf, sizeof(errbuf), opt_flags);
} }
return set_bool_option(opt_idx, (char *)varp, (int)numval, opt_flags); return set_bool_option(opt_idx, varp, (int)numval, opt_flags);
} }
/// Call set_option_value() and when an error is returned report it. /// Call set_option_value() and when an error is returned report it.
@@ -3243,7 +3243,7 @@ static void showoptions(bool all, int opt_flags)
varp = get_varp_scope(p, opt_flags); varp = get_varp_scope(p, opt_flags);
} }
} else { } else {
varp = (char *)get_varp(p); varp = get_varp(p);
} }
if (varp != NULL if (varp != NULL
&& (all == 1 || (all == 0 && !optval_default(p, varp)))) { && (all == 1 || (all == 0 && !optval_default(p, varp)))) {
@@ -3349,7 +3349,7 @@ static void showoneopt(vimoption_T *p, int opt_flags)
silent_mode = false; silent_mode = false;
info_message = true; // use os_msg(), not os_errmsg() info_message = true; // use os_msg(), not os_errmsg()
char_u *varp = (char_u *)get_varp_scope(p, opt_flags); char *varp = get_varp_scope(p, opt_flags);
// for 'modified' we also need to check if 'ff' or 'fenc' changed. // for 'modified' we also need to check if 'ff' or 'fenc' changed.
if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
@@ -3427,12 +3427,12 @@ int makeset(FILE *fd, int opt_flags, int local_only)
} }
if ((opt_flags & OPT_SKIPRTP) if ((opt_flags & OPT_SKIPRTP)
&& (p->var == (char_u *)&p_rtp || p->var == (char_u *)&p_pp)) { && (p->var == (char *)&p_rtp || p->var == (char *)&p_pp)) {
continue; continue;
} }
int round = 2; int round = 2;
char_u *varp_local = NULL; // fresh value char *varp_local = NULL; // fresh value
if (p->indir != PV_NONE) { if (p->indir != PV_NONE) {
if (p->var == VAR_WIN) { if (p->var == VAR_WIN) {
// skip window-local option when only doing globals // skip window-local option when only doing globals
@@ -3442,11 +3442,11 @@ int makeset(FILE *fd, int opt_flags, int local_only)
// When fresh value of window-local option is not at the // When fresh value of window-local option is not at the
// default, need to write it too. // default, need to write it too.
if (!(opt_flags & OPT_GLOBAL) && !local_only) { if (!(opt_flags & OPT_GLOBAL) && !local_only) {
char_u *varp_fresh = (char_u *)get_varp_scope(p, OPT_GLOBAL); // local value char *varp_fresh = get_varp_scope(p, OPT_GLOBAL); // local value
if (!optval_default(p, (char *)varp_fresh)) { if (!optval_default(p, varp_fresh)) {
round = 1; round = 1;
varp_local = (char_u *)varp; varp_local = varp;
varp = (char *)varp_fresh; varp = varp_fresh;
} }
} }
} }
@@ -3454,7 +3454,7 @@ int makeset(FILE *fd, int opt_flags, int local_only)
// Round 1: fresh value for window-local options. // Round 1: fresh value for window-local options.
// Round 2: other values // Round 2: other values
for (; round <= 2; varp = (char *)varp_local, round++) { for (; round <= 2; varp = varp_local, round++) {
char *cmd; char *cmd;
if (round == 1 || (opt_flags & OPT_GLOBAL)) { if (round == 1 || (opt_flags & OPT_GLOBAL)) {
cmd = "set"; cmd = "set";
@@ -3477,7 +3477,7 @@ int makeset(FILE *fd, int opt_flags, int local_only)
// already right, avoids reloading the syntax file. // already right, avoids reloading the syntax file.
if (p->indir == PV_SYN || p->indir == PV_FT) { if (p->indir == PV_SYN || p->indir == PV_FT) {
if (fprintf(fd, "if &%s != '%s'", p->fullname, if (fprintf(fd, "if &%s != '%s'", p->fullname,
*(char_u **)(varp)) < 0 *(char **)(varp)) < 0
|| put_eol(fd) < 0) { || put_eol(fd) < 0) {
return FAIL; return FAIL;
} }
@@ -3524,7 +3524,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_
} }
char *buf = NULL; char *buf = NULL;
char_u *part = NULL; char *part = NULL;
if (*valuep != NULL) { if (*valuep != NULL) {
if ((flags & P_EXPAND) != 0) { if ((flags & P_EXPAND) != 0) {
@@ -3552,8 +3552,8 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_
if (fprintf(fd, "%s %s+=", cmd, name) < 0) { if (fprintf(fd, "%s %s+=", cmd, name) < 0) {
goto fail; goto fail;
} }
(void)copy_option_part(&p, (char *)part, size, ","); (void)copy_option_part(&p, part, size, ",");
if (put_escstr(fd, (char *)part, 2) == FAIL || put_eol(fd) == FAIL) { if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL) {
goto fail; goto fail;
} }
} }
@@ -3586,9 +3586,9 @@ static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep)
return FAIL; return FAIL;
} }
long wc; long wc;
if (wc_use_keyname((char_u *)valuep, &wc)) { if (wc_use_keyname((char *)valuep, &wc)) {
// print 'wildchar' and 'wildcharm' as a key name // print 'wildchar' and 'wildcharm' as a key name
if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0) { if (fputs(get_special_key_name((int)wc, 0), fd) < 0) {
return FAIL; return FAIL;
} }
} else if (fprintf(fd, "%" PRId64, (int64_t)(*valuep)) < 0) { } else if (fprintf(fd, "%" PRId64, (int64_t)(*valuep)) < 0) {
@@ -3727,7 +3727,7 @@ char *get_varp_scope_from(vimoption_T *p, int scope, buf_T *buf, win_T *win)
if (p->var == VAR_WIN) { if (p->var == VAR_WIN) {
return GLOBAL_WO(get_varp_from(p, buf, win)); return GLOBAL_WO(get_varp_from(p, buf, win));
} }
return (char *)p->var; return p->var;
} }
if ((scope & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) { if ((scope & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) {
switch ((int)p->indir) { switch ((int)p->indir) {
@@ -3790,7 +3790,7 @@ char *get_varp_scope_from(vimoption_T *p, int scope, buf_T *buf, win_T *win)
} }
return NULL; // "cannot happen" return NULL; // "cannot happen"
} }
return (char *)get_varp_from(p, buf, win); return get_varp_from(p, buf, win);
} }
/// Get pointer to option variable, depending on local or global scope. /// Get pointer to option variable, depending on local or global scope.
@@ -3801,7 +3801,7 @@ char *get_varp_scope(vimoption_T *p, int scope)
return get_varp_scope_from(p, scope, curbuf, curwin); return get_varp_scope_from(p, scope, curbuf, curwin);
} }
static char_u *get_varp_from(vimoption_T *p, buf_T *buf, win_T *win) static char *get_varp_from(vimoption_T *p, buf_T *buf, win_T *win)
{ {
// hidden option, always return NULL // hidden option, always return NULL
if (p->var == NULL) { if (p->var == NULL) {
@@ -3815,308 +3815,308 @@ static char_u *get_varp_from(vimoption_T *p, buf_T *buf, win_T *win)
// global option with local value: use local value if it's been set // global option with local value: use local value if it's been set
case PV_EP: case PV_EP:
return *buf->b_p_ep != NUL return *buf->b_p_ep != NUL
? (char_u *)&buf->b_p_ep : p->var; ? (char *)&buf->b_p_ep : p->var;
case PV_KP: case PV_KP:
return *buf->b_p_kp != NUL return *buf->b_p_kp != NUL
? (char_u *)&buf->b_p_kp : p->var; ? (char *)&buf->b_p_kp : p->var;
case PV_PATH: case PV_PATH:
return *buf->b_p_path != NUL return *buf->b_p_path != NUL
? (char_u *)&(buf->b_p_path) : p->var; ? (char *)&(buf->b_p_path) : p->var;
case PV_AR: case PV_AR:
return buf->b_p_ar >= 0 return buf->b_p_ar >= 0
? (char_u *)&(buf->b_p_ar) : p->var; ? (char *)&(buf->b_p_ar) : p->var;
case PV_TAGS: case PV_TAGS:
return *buf->b_p_tags != NUL return *buf->b_p_tags != NUL
? (char_u *)&(buf->b_p_tags) : p->var; ? (char *)&(buf->b_p_tags) : p->var;
case PV_TC: case PV_TC:
return *buf->b_p_tc != NUL return *buf->b_p_tc != NUL
? (char_u *)&(buf->b_p_tc) : p->var; ? (char *)&(buf->b_p_tc) : p->var;
case PV_SISO: case PV_SISO:
return win->w_p_siso >= 0 return win->w_p_siso >= 0
? (char_u *)&(win->w_p_siso) : p->var; ? (char *)&(win->w_p_siso) : p->var;
case PV_SO: case PV_SO:
return win->w_p_so >= 0 return win->w_p_so >= 0
? (char_u *)&(win->w_p_so) : p->var; ? (char *)&(win->w_p_so) : p->var;
case PV_BKC: case PV_BKC:
return *buf->b_p_bkc != NUL return *buf->b_p_bkc != NUL
? (char_u *)&(buf->b_p_bkc) : p->var; ? (char *)&(buf->b_p_bkc) : p->var;
case PV_DEF: case PV_DEF:
return *buf->b_p_def != NUL return *buf->b_p_def != NUL
? (char_u *)&(buf->b_p_def) : p->var; ? (char *)&(buf->b_p_def) : p->var;
case PV_INC: case PV_INC:
return *buf->b_p_inc != NUL return *buf->b_p_inc != NUL
? (char_u *)&(buf->b_p_inc) : p->var; ? (char *)&(buf->b_p_inc) : p->var;
case PV_DICT: case PV_DICT:
return *buf->b_p_dict != NUL return *buf->b_p_dict != NUL
? (char_u *)&(buf->b_p_dict) : p->var; ? (char *)&(buf->b_p_dict) : p->var;
case PV_TSR: case PV_TSR:
return *buf->b_p_tsr != NUL return *buf->b_p_tsr != NUL
? (char_u *)&(buf->b_p_tsr) : p->var; ? (char *)&(buf->b_p_tsr) : p->var;
case PV_TSRFU: case PV_TSRFU:
return *buf->b_p_tsrfu != NUL return *buf->b_p_tsrfu != NUL
? (char_u *)&(buf->b_p_tsrfu) : p->var; ? (char *)&(buf->b_p_tsrfu) : p->var;
case PV_FP: case PV_FP:
return *buf->b_p_fp != NUL return *buf->b_p_fp != NUL
? (char_u *)&(buf->b_p_fp) : p->var; ? (char *)&(buf->b_p_fp) : p->var;
case PV_EFM: case PV_EFM:
return *buf->b_p_efm != NUL return *buf->b_p_efm != NUL
? (char_u *)&(buf->b_p_efm) : p->var; ? (char *)&(buf->b_p_efm) : p->var;
case PV_GP: case PV_GP:
return *buf->b_p_gp != NUL return *buf->b_p_gp != NUL
? (char_u *)&(buf->b_p_gp) : p->var; ? (char *)&(buf->b_p_gp) : p->var;
case PV_MP: case PV_MP:
return *buf->b_p_mp != NUL return *buf->b_p_mp != NUL
? (char_u *)&(buf->b_p_mp) : p->var; ? (char *)&(buf->b_p_mp) : p->var;
case PV_SBR: case PV_SBR:
return *win->w_p_sbr != NUL return *win->w_p_sbr != NUL
? (char_u *)&(win->w_p_sbr) : p->var; ? (char *)&(win->w_p_sbr) : p->var;
case PV_STL: case PV_STL:
return *win->w_p_stl != NUL return *win->w_p_stl != NUL
? (char_u *)&(win->w_p_stl) : p->var; ? (char *)&(win->w_p_stl) : p->var;
case PV_WBR: case PV_WBR:
return *win->w_p_wbr != NUL return *win->w_p_wbr != NUL
? (char_u *)&(win->w_p_wbr) : p->var; ? (char *)&(win->w_p_wbr) : p->var;
case PV_UL: case PV_UL:
return buf->b_p_ul != NO_LOCAL_UNDOLEVEL return buf->b_p_ul != NO_LOCAL_UNDOLEVEL
? (char_u *)&(buf->b_p_ul) : p->var; ? (char *)&(buf->b_p_ul) : p->var;
case PV_LW: case PV_LW:
return *buf->b_p_lw != NUL return *buf->b_p_lw != NUL
? (char_u *)&(buf->b_p_lw) : p->var; ? (char *)&(buf->b_p_lw) : p->var;
case PV_MENC: case PV_MENC:
return *buf->b_p_menc != NUL return *buf->b_p_menc != NUL
? (char_u *)&(buf->b_p_menc) : p->var; ? (char *)&(buf->b_p_menc) : p->var;
case PV_FCS: case PV_FCS:
return *win->w_p_fcs != NUL return *win->w_p_fcs != NUL
? (char_u *)&(win->w_p_fcs) : p->var; ? (char *)&(win->w_p_fcs) : p->var;
case PV_LCS: case PV_LCS:
return *win->w_p_lcs != NUL return *win->w_p_lcs != NUL
? (char_u *)&(win->w_p_lcs) : p->var; ? (char *)&(win->w_p_lcs) : p->var;
case PV_VE: case PV_VE:
return *win->w_p_ve != NUL return *win->w_p_ve != NUL
? (char_u *)&win->w_p_ve : p->var; ? (char *)&win->w_p_ve : p->var;
case PV_ARAB: case PV_ARAB:
return (char_u *)&(win->w_p_arab); return (char *)&(win->w_p_arab);
case PV_LIST: case PV_LIST:
return (char_u *)&(win->w_p_list); return (char *)&(win->w_p_list);
case PV_SPELL: case PV_SPELL:
return (char_u *)&(win->w_p_spell); return (char *)&(win->w_p_spell);
case PV_CUC: case PV_CUC:
return (char_u *)&(win->w_p_cuc); return (char *)&(win->w_p_cuc);
case PV_CUL: case PV_CUL:
return (char_u *)&(win->w_p_cul); return (char *)&(win->w_p_cul);
case PV_CULOPT: case PV_CULOPT:
return (char_u *)&(win->w_p_culopt); return (char *)&(win->w_p_culopt);
case PV_CC: case PV_CC:
return (char_u *)&(win->w_p_cc); return (char *)&(win->w_p_cc);
case PV_DIFF: case PV_DIFF:
return (char_u *)&(win->w_p_diff); return (char *)&(win->w_p_diff);
case PV_FDC: case PV_FDC:
return (char_u *)&(win->w_p_fdc); return (char *)&(win->w_p_fdc);
case PV_FEN: case PV_FEN:
return (char_u *)&(win->w_p_fen); return (char *)&(win->w_p_fen);
case PV_FDI: case PV_FDI:
return (char_u *)&(win->w_p_fdi); return (char *)&(win->w_p_fdi);
case PV_FDL: case PV_FDL:
return (char_u *)&(win->w_p_fdl); return (char *)&(win->w_p_fdl);
case PV_FDM: case PV_FDM:
return (char_u *)&(win->w_p_fdm); return (char *)&(win->w_p_fdm);
case PV_FML: case PV_FML:
return (char_u *)&(win->w_p_fml); return (char *)&(win->w_p_fml);
case PV_FDN: case PV_FDN:
return (char_u *)&(win->w_p_fdn); return (char *)&(win->w_p_fdn);
case PV_FDE: case PV_FDE:
return (char_u *)&(win->w_p_fde); return (char *)&(win->w_p_fde);
case PV_FDT: case PV_FDT:
return (char_u *)&(win->w_p_fdt); return (char *)&(win->w_p_fdt);
case PV_FMR: case PV_FMR:
return (char_u *)&(win->w_p_fmr); return (char *)&(win->w_p_fmr);
case PV_NU: case PV_NU:
return (char_u *)&(win->w_p_nu); return (char *)&(win->w_p_nu);
case PV_RNU: case PV_RNU:
return (char_u *)&(win->w_p_rnu); return (char *)&(win->w_p_rnu);
case PV_NUW: case PV_NUW:
return (char_u *)&(win->w_p_nuw); return (char *)&(win->w_p_nuw);
case PV_WFH: case PV_WFH:
return (char_u *)&(win->w_p_wfh); return (char *)&(win->w_p_wfh);
case PV_WFW: case PV_WFW:
return (char_u *)&(win->w_p_wfw); return (char *)&(win->w_p_wfw);
case PV_PVW: case PV_PVW:
return (char_u *)&(win->w_p_pvw); return (char *)&(win->w_p_pvw);
case PV_RL: case PV_RL:
return (char_u *)&(win->w_p_rl); return (char *)&(win->w_p_rl);
case PV_RLC: case PV_RLC:
return (char_u *)&(win->w_p_rlc); return (char *)&(win->w_p_rlc);
case PV_SCROLL: case PV_SCROLL:
return (char_u *)&(win->w_p_scr); return (char *)&(win->w_p_scr);
case PV_WRAP: case PV_WRAP:
return (char_u *)&(win->w_p_wrap); return (char *)&(win->w_p_wrap);
case PV_LBR: case PV_LBR:
return (char_u *)&(win->w_p_lbr); return (char *)&(win->w_p_lbr);
case PV_BRI: case PV_BRI:
return (char_u *)&(win->w_p_bri); return (char *)&(win->w_p_bri);
case PV_BRIOPT: case PV_BRIOPT:
return (char_u *)&(win->w_p_briopt); return (char *)&(win->w_p_briopt);
case PV_SCBIND: case PV_SCBIND:
return (char_u *)&(win->w_p_scb); return (char *)&(win->w_p_scb);
case PV_CRBIND: case PV_CRBIND:
return (char_u *)&(win->w_p_crb); return (char *)&(win->w_p_crb);
case PV_COCU: case PV_COCU:
return (char_u *)&(win->w_p_cocu); return (char *)&(win->w_p_cocu);
case PV_COLE: case PV_COLE:
return (char_u *)&(win->w_p_cole); return (char *)&(win->w_p_cole);
case PV_AI: case PV_AI:
return (char_u *)&(buf->b_p_ai); return (char *)&(buf->b_p_ai);
case PV_BIN: case PV_BIN:
return (char_u *)&(buf->b_p_bin); return (char *)&(buf->b_p_bin);
case PV_BOMB: case PV_BOMB:
return (char_u *)&(buf->b_p_bomb); return (char *)&(buf->b_p_bomb);
case PV_BH: case PV_BH:
return (char_u *)&(buf->b_p_bh); return (char *)&(buf->b_p_bh);
case PV_BT: case PV_BT:
return (char_u *)&(buf->b_p_bt); return (char *)&(buf->b_p_bt);
case PV_BL: case PV_BL:
return (char_u *)&(buf->b_p_bl); return (char *)&(buf->b_p_bl);
case PV_CHANNEL: case PV_CHANNEL:
return (char_u *)&(buf->b_p_channel); return (char *)&(buf->b_p_channel);
case PV_CI: case PV_CI:
return (char_u *)&(buf->b_p_ci); return (char *)&(buf->b_p_ci);
case PV_CIN: case PV_CIN:
return (char_u *)&(buf->b_p_cin); return (char *)&(buf->b_p_cin);
case PV_CINK: case PV_CINK:
return (char_u *)&(buf->b_p_cink); return (char *)&(buf->b_p_cink);
case PV_CINO: case PV_CINO:
return (char_u *)&(buf->b_p_cino); return (char *)&(buf->b_p_cino);
case PV_CINSD: case PV_CINSD:
return (char_u *)&(buf->b_p_cinsd); return (char *)&(buf->b_p_cinsd);
case PV_CINW: case PV_CINW:
return (char_u *)&(buf->b_p_cinw); return (char *)&(buf->b_p_cinw);
case PV_COM: case PV_COM:
return (char_u *)&(buf->b_p_com); return (char *)&(buf->b_p_com);
case PV_CMS: case PV_CMS:
return (char_u *)&(buf->b_p_cms); return (char *)&(buf->b_p_cms);
case PV_CPT: case PV_CPT:
return (char_u *)&(buf->b_p_cpt); return (char *)&(buf->b_p_cpt);
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
case PV_CSL: case PV_CSL:
return (char_u *)&(buf->b_p_csl); return (char *)&(buf->b_p_csl);
#endif #endif
case PV_CFU: case PV_CFU:
return (char_u *)&(buf->b_p_cfu); return (char *)&(buf->b_p_cfu);
case PV_OFU: case PV_OFU:
return (char_u *)&(buf->b_p_ofu); return (char *)&(buf->b_p_ofu);
case PV_EOF: case PV_EOF:
return (char_u *)&(buf->b_p_eof); return (char *)&(buf->b_p_eof);
case PV_EOL: case PV_EOL:
return (char_u *)&(buf->b_p_eol); return (char *)&(buf->b_p_eol);
case PV_FIXEOL: case PV_FIXEOL:
return (char_u *)&(buf->b_p_fixeol); return (char *)&(buf->b_p_fixeol);
case PV_ET: case PV_ET:
return (char_u *)&(buf->b_p_et); return (char *)&(buf->b_p_et);
case PV_FENC: case PV_FENC:
return (char_u *)&(buf->b_p_fenc); return (char *)&(buf->b_p_fenc);
case PV_FF: case PV_FF:
return (char_u *)&(buf->b_p_ff); return (char *)&(buf->b_p_ff);
case PV_FT: case PV_FT:
return (char_u *)&(buf->b_p_ft); return (char *)&(buf->b_p_ft);
case PV_FO: case PV_FO:
return (char_u *)&(buf->b_p_fo); return (char *)&(buf->b_p_fo);
case PV_FLP: case PV_FLP:
return (char_u *)&(buf->b_p_flp); return (char *)&(buf->b_p_flp);
case PV_IMI: case PV_IMI:
return (char_u *)&(buf->b_p_iminsert); return (char *)&(buf->b_p_iminsert);
case PV_IMS: case PV_IMS:
return (char_u *)&(buf->b_p_imsearch); return (char *)&(buf->b_p_imsearch);
case PV_INF: case PV_INF:
return (char_u *)&(buf->b_p_inf); return (char *)&(buf->b_p_inf);
case PV_ISK: case PV_ISK:
return (char_u *)&(buf->b_p_isk); return (char *)&(buf->b_p_isk);
case PV_INEX: case PV_INEX:
return (char_u *)&(buf->b_p_inex); return (char *)&(buf->b_p_inex);
case PV_INDE: case PV_INDE:
return (char_u *)&(buf->b_p_inde); return (char *)&(buf->b_p_inde);
case PV_INDK: case PV_INDK:
return (char_u *)&(buf->b_p_indk); return (char *)&(buf->b_p_indk);
case PV_FEX: case PV_FEX:
return (char_u *)&(buf->b_p_fex); return (char *)&(buf->b_p_fex);
case PV_LISP: case PV_LISP:
return (char_u *)&(buf->b_p_lisp); return (char *)&(buf->b_p_lisp);
case PV_LOP: case PV_LOP:
return (char_u *)&(buf->b_p_lop); return (char *)&(buf->b_p_lop);
case PV_ML: case PV_ML:
return (char_u *)&(buf->b_p_ml); return (char *)&(buf->b_p_ml);
case PV_MPS: case PV_MPS:
return (char_u *)&(buf->b_p_mps); return (char *)&(buf->b_p_mps);
case PV_MA: case PV_MA:
return (char_u *)&(buf->b_p_ma); return (char *)&(buf->b_p_ma);
case PV_MOD: case PV_MOD:
return (char_u *)&(buf->b_changed); return (char *)&(buf->b_changed);
case PV_NF: case PV_NF:
return (char_u *)&(buf->b_p_nf); return (char *)&(buf->b_p_nf);
case PV_PI: case PV_PI:
return (char_u *)&(buf->b_p_pi); return (char *)&(buf->b_p_pi);
case PV_QE: case PV_QE:
return (char_u *)&(buf->b_p_qe); return (char *)&(buf->b_p_qe);
case PV_RO: case PV_RO:
return (char_u *)&(buf->b_p_ro); return (char *)&(buf->b_p_ro);
case PV_SCBK: case PV_SCBK:
return (char_u *)&(buf->b_p_scbk); return (char *)&(buf->b_p_scbk);
case PV_SI: case PV_SI:
return (char_u *)&(buf->b_p_si); return (char *)&(buf->b_p_si);
case PV_STS: case PV_STS:
return (char_u *)&(buf->b_p_sts); return (char *)&(buf->b_p_sts);
case PV_SUA: case PV_SUA:
return (char_u *)&(buf->b_p_sua); return (char *)&(buf->b_p_sua);
case PV_SWF: case PV_SWF:
return (char_u *)&(buf->b_p_swf); return (char *)&(buf->b_p_swf);
case PV_SMC: case PV_SMC:
return (char_u *)&(buf->b_p_smc); return (char *)&(buf->b_p_smc);
case PV_SYN: case PV_SYN:
return (char_u *)&(buf->b_p_syn); return (char *)&(buf->b_p_syn);
case PV_SPC: case PV_SPC:
return (char_u *)&(win->w_s->b_p_spc); return (char *)&(win->w_s->b_p_spc);
case PV_SPF: case PV_SPF:
return (char_u *)&(win->w_s->b_p_spf); return (char *)&(win->w_s->b_p_spf);
case PV_SPL: case PV_SPL:
return (char_u *)&(win->w_s->b_p_spl); return (char *)&(win->w_s->b_p_spl);
case PV_SPO: case PV_SPO:
return (char_u *)&(win->w_s->b_p_spo); return (char *)&(win->w_s->b_p_spo);
case PV_SW: case PV_SW:
return (char_u *)&(buf->b_p_sw); return (char *)&(buf->b_p_sw);
case PV_TFU: case PV_TFU:
return (char_u *)&(buf->b_p_tfu); return (char *)&(buf->b_p_tfu);
case PV_TS: case PV_TS:
return (char_u *)&(buf->b_p_ts); return (char *)&(buf->b_p_ts);
case PV_TW: case PV_TW:
return (char_u *)&(buf->b_p_tw); return (char *)&(buf->b_p_tw);
case PV_UDF: case PV_UDF:
return (char_u *)&(buf->b_p_udf); return (char *)&(buf->b_p_udf);
case PV_WM: case PV_WM:
return (char_u *)&(buf->b_p_wm); return (char *)&(buf->b_p_wm);
case PV_VSTS: case PV_VSTS:
return (char_u *)&(buf->b_p_vsts); return (char *)&(buf->b_p_vsts);
case PV_VTS: case PV_VTS:
return (char_u *)&(buf->b_p_vts); return (char *)&(buf->b_p_vts);
case PV_KMAP: case PV_KMAP:
return (char_u *)&(buf->b_p_keymap); return (char *)&(buf->b_p_keymap);
case PV_SCL: case PV_SCL:
return (char_u *)&(win->w_p_scl); return (char *)&(win->w_p_scl);
case PV_WINHL: case PV_WINHL:
return (char_u *)&(win->w_p_winhl); return (char *)&(win->w_p_winhl);
case PV_WINBL: case PV_WINBL:
return (char_u *)&(win->w_p_winbl); return (char *)&(win->w_p_winbl);
case PV_STC: case PV_STC:
return (char_u *)&(win->w_p_stc); return (char *)&(win->w_p_stc);
default: default:
iemsg(_("E356: get_varp ERROR")); iemsg(_("E356: get_varp ERROR"));
} }
// always return a valid pointer to avoid a crash! // always return a valid pointer to avoid a crash!
return (char_u *)&(buf->b_p_wm); return (char *)&(buf->b_p_wm);
} }
/// Get pointer to option variable. /// Get pointer to option variable.
static inline char_u *get_varp(vimoption_T *p) static inline char *get_varp(vimoption_T *p)
{ {
return get_varp_from(p, curbuf, curwin); return get_varp_from(p, curbuf, curwin);
} }
@@ -4608,7 +4608,7 @@ void set_imsearch_global(buf_T *buf)
} }
static int expand_option_idx = -1; static int expand_option_idx = -1;
static char_u expand_option_name[5] = { 't', '_', NUL, NUL, NUL }; static char expand_option_name[5] = { 't', '_', NUL, NUL, NUL };
static int expand_option_flags = 0; static int expand_option_flags = 0;
/// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL /// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL
@@ -4670,8 +4670,8 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
} }
nextchar = *++p; nextchar = *++p;
is_term_option = true; is_term_option = true;
expand_option_name[2] = (char_u)KEY2TERMCAP0(key); expand_option_name[2] = (char)(uint8_t)KEY2TERMCAP0(key);
expand_option_name[3] = KEY2TERMCAP1(key); expand_option_name[3] = (char)(uint8_t)KEY2TERMCAP1(key);
} else { } else {
if (p[0] == 't' && p[1] == '_') { if (p[0] == 't' && p[1] == '_') {
p += 2; p += 2;
@@ -4683,8 +4683,8 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
} }
nextchar = *++p; nextchar = *++p;
is_term_option = true; is_term_option = true;
expand_option_name[2] = (char_u)p[-2]; expand_option_name[2] = p[-2];
expand_option_name[3] = (char_u)p[-1]; expand_option_name[3] = p[-1];
} else { } else {
// Allow * wildcard. // Allow * wildcard.
while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*') { while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*') {
@@ -4734,7 +4734,7 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
xp->xp_pattern = p + 1; xp->xp_pattern = p + 1;
if (flags & P_EXPAND) { if (flags & P_EXPAND) {
p = (char *)options[opt_idx].var; p = options[opt_idx].var;
if (p == (char *)&p_bdir if (p == (char *)&p_bdir
|| p == (char *)&p_dir || p == (char *)&p_dir
|| p == (char *)&p_path || p == (char *)&p_path
@@ -4778,7 +4778,7 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
} }
// for 'spellsuggest' start at "file:" // for 'spellsuggest' start at "file:"
if (options[opt_idx].var == (char_u *)&p_sps if (options[opt_idx].var == (char *)&p_sps
&& strncmp(p, "file:", 5) == 0) { && strncmp(p, "file:", 5) == 0) {
xp->xp_pattern = p + 5; xp->xp_pattern = p + 5;
break; break;
@@ -4915,7 +4915,7 @@ void ExpandOldSetting(int *numMatches, char ***matches)
// For a terminal key code expand_option_idx is < 0. // For a terminal key code expand_option_idx is < 0.
if (expand_option_idx < 0) { if (expand_option_idx < 0) {
expand_option_idx = findoption((const char *)expand_option_name); expand_option_idx = findoption(expand_option_name);
} }
if (expand_option_idx >= 0) { if (expand_option_idx >= 0) {
@@ -4959,8 +4959,8 @@ static void option_value2string(vimoption_T *opp, int scope)
if (opp->flags & P_NUM) { if (opp->flags & P_NUM) {
long wc = 0; long wc = 0;
if (wc_use_keyname((char_u *)varp, &wc)) { if (wc_use_keyname(varp, &wc)) {
xstrlcpy(NameBuff, (char *)get_special_key_name((int)wc, 0), sizeof(NameBuff)); xstrlcpy(NameBuff, get_special_key_name((int)wc, 0), sizeof(NameBuff));
} else if (wc != 0) { } else if (wc != 0) {
xstrlcpy(NameBuff, transchar((int)wc), sizeof(NameBuff)); xstrlcpy(NameBuff, transchar((int)wc), sizeof(NameBuff));
} else { } else {
@@ -4984,7 +4984,7 @@ static void option_value2string(vimoption_T *opp, int scope)
/// Return true if "varp" points to 'wildchar' or 'wildcharm' and it can be /// Return true if "varp" points to 'wildchar' or 'wildcharm' and it can be
/// printed as a keyname. /// printed as a keyname.
/// "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'. /// "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
static int wc_use_keyname(const char_u *varp, long *wcp) static int wc_use_keyname(const char *varp, long *wcp)
{ {
if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm)) { if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm)) {
*wcp = *(long *)varp; *wcp = *(long *)varp;
@@ -5198,7 +5198,7 @@ void fill_breakat_flags(void)
int fill_culopt_flags(char *val, win_T *wp) int fill_culopt_flags(char *val, win_T *wp)
{ {
char *p; char *p;
char_u culopt_flags_new = 0; uint8_t culopt_flags_new = 0;
if (val == NULL) { if (val == NULL) {
p = wp->w_p_culopt; p = wp->w_p_culopt;
@@ -5568,7 +5568,7 @@ dict_T *get_winbuf_options(const int bufopt)
if ((bufopt && (opt->indir & PV_BUF)) if ((bufopt && (opt->indir & PV_BUF))
|| (!bufopt && (opt->indir & PV_WIN))) { || (!bufopt && (opt->indir & PV_WIN))) {
char_u *varp = get_varp(opt); char *varp = get_varp(opt);
if (varp != NULL) { if (varp != NULL) {
if (opt->flags & P_STRING) { if (opt->flags & P_STRING) {
@@ -5673,7 +5673,7 @@ static Dictionary vimoption2dict(vimoption_T *opt, int req_scope, buf_T *buf, wi
const char *type; const char *type;
Object def; Object def;
// TODO(bfredl): do you even nocp? // TODO(bfredl): do you even nocp?
char_u *def_val = (char_u *)opt->def_val; char *def_val = opt->def_val;
if (opt->flags & P_STRING) { if (opt->flags & P_STRING) {
type = "string"; type = "string";
def = CSTR_TO_OBJ(def_val ? (char *)def_val : ""); def = CSTR_TO_OBJ(def_val ? (char *)def_val : "");

View File

@@ -993,7 +993,7 @@ typedef struct vimoption {
char *fullname; // full option name char *fullname; // full option name
char *shortname; // permissible abbreviation char *shortname; // permissible abbreviation
uint32_t flags; // see below uint32_t flags; // see below
char_u *var; // global option: pointer to variable; char *var; // global option: pointer to variable;
// window-local option: VAR_WIN; // window-local option: VAR_WIN;
// buffer-local option: global value // buffer-local option: global value
idopt_T indir; // global option: PV_NONE; idopt_T indir; // global option: PV_NONE;
@@ -1018,6 +1018,6 @@ typedef struct vimoption {
// Options local to a window have a value local to a buffer and global to all // Options local to a window have a value local to a buffer and global to all
// buffers. Indicate this by setting "var" to VAR_WIN. // buffers. Indicate this by setting "var" to VAR_WIN.
#define VAR_WIN ((char_u *)-1) #define VAR_WIN ((char *)-1)
#endif // NVIM_OPTION_DEFS_H #endif // NVIM_OPTION_DEFS_H

View File

@@ -150,7 +150,7 @@ typedef struct matchinf_S {
// for when checking a compound word // for when checking a compound word
int mi_compoff; // start of following word offset int mi_compoff; // start of following word offset
char_u mi_compflags[MAXWLEN]; // flags for compound words used uint8_t mi_compflags[MAXWLEN]; // flags for compound words used
int mi_complen; // nr of compound words used int mi_complen; // nr of compound words used
int mi_compextra; // nr of COMPOUNDROOT words int mi_compextra; // nr of COMPOUNDROOT words
@@ -961,7 +961,7 @@ bool can_compound(slang_T *slang, const char *word, const uint8_t *flags)
// compound rule. This is used to stop trying a compound if the flags // compound rule. This is used to stop trying a compound if the flags
// collected so far can't possibly match any compound rule. // collected so far can't possibly match any compound rule.
// Caller must check that slang->sl_comprules is not NULL. // Caller must check that slang->sl_comprules is not NULL.
bool match_compoundrule(slang_T *slang, const char_u *compflags) bool match_compoundrule(slang_T *slang, const uint8_t *compflags)
{ {
// loop over all the COMPOUNDRULE entries // loop over all the COMPOUNDRULE entries
for (char *p = (char *)slang->sl_comprules; *p != NUL; p++) { for (char *p = (char *)slang->sl_comprules; *p != NUL; p++) {
@@ -1748,7 +1748,7 @@ void count_common_word(slang_T *lp, char *word, int len, uint8_t count)
wc = xmalloc(offsetof(wordcount_T, wc_word) + p_len + 1); wc = xmalloc(offsetof(wordcount_T, wc_word) + p_len + 1);
memcpy(wc->wc_word, p, p_len + 1); memcpy(wc->wc_word, p, p_len + 1);
wc->wc_count = count; wc->wc_count = count;
hash_add_item(&lp->sl_wordcount, hi, (char *)wc->wc_word, hash); hash_add_item(&lp->sl_wordcount, hi, wc->wc_word, hash);
} else { } else {
wc = HI2WC(hi); wc = HI2WC(hi);
wc->wc_count = (uint16_t)(wc->wc_count + count); wc->wc_count = (uint16_t)(wc->wc_count + count);

View File

@@ -243,7 +243,7 @@ typedef enum {
typedef struct wordcount_S { typedef struct wordcount_S {
uint16_t wc_count; ///< nr of times word was seen uint16_t wc_count; ///< nr of times word was seen
char_u wc_word[]; ///< word char wc_word[]; ///< word
} wordcount_T; } wordcount_T;
#define WC_KEY_OFF offsetof(wordcount_T, wc_word) #define WC_KEY_OFF offsetof(wordcount_T, wc_word)

View File

@@ -404,14 +404,14 @@ typedef struct sblock_S sblock_T;
struct sblock_S { struct sblock_S {
int sb_used; // nr of bytes already in use int sb_used; // nr of bytes already in use
sblock_T *sb_next; // next block in list sblock_T *sb_next; // next block in list
char_u sb_data[]; // data char sb_data[]; // data
}; };
// A node in the tree. // A node in the tree.
typedef struct wordnode_S wordnode_T; typedef struct wordnode_S wordnode_T;
struct wordnode_S { struct wordnode_S {
union { // shared to save space union { // shared to save space
char_u hashkey[6]; // the hash key, only used while compressing uint8_t hashkey[6]; // the hash key, only used while compressing
int index; // index in written nodes (valid after first int index; // index in written nodes (valid after first
// round) // round)
} wn_u1; } wn_u1;
@@ -422,17 +422,17 @@ struct wordnode_S {
wordnode_T *wn_child; // child (next byte in word) wordnode_T *wn_child; // child (next byte in word)
wordnode_T *wn_sibling; // next sibling (alternate byte in word, wordnode_T *wn_sibling; // next sibling (alternate byte in word,
// always sorted) // always sorted)
int wn_refs; // Nr. of references to this node. Only int wn_refs; // Nr. of references to this node. Only
// relevant for first node in a list of // relevant for first node in a list of
// siblings, in following siblings it is // siblings, in following siblings it is
// always one. // always one.
char_u wn_byte; // Byte for this node. NUL for word end uint8_t wn_byte; // Byte for this node. NUL for word end
// Info for when "wn_byte" is NUL. // Info for when "wn_byte" is NUL.
// In PREFIXTREE "wn_region" is used for the prefcondnr. // In PREFIXTREE "wn_region" is used for the prefcondnr.
// In the soundfolded word tree "wn_flags" has the MSW of the wordnr and // In the soundfolded word tree "wn_flags" has the MSW of the wordnr and
// "wn_region" the LSW of the wordnr. // "wn_region" the LSW of the wordnr.
char_u wn_affixID; // supported/required prefix ID or 0 uint8_t wn_affixID; // supported/required prefix ID or 0
uint16_t wn_flags; // WF_ flags uint16_t wn_flags; // WF_ flags
int16_t wn_region; // region mask int16_t wn_region; // region mask
@@ -482,7 +482,7 @@ typedef struct spellinfo_S {
char *si_info; // info text chars or NULL char *si_info; // info text chars or NULL
int si_region_count; // number of regions supported (1 when there int si_region_count; // number of regions supported (1 when there
// are no regions) // are no regions)
char_u si_region_name[MAXREGIONS * 2 + 1]; char si_region_name[MAXREGIONS * 2 + 1];
// region names; used only if // region names; used only if
// si_region_count > 1) // si_region_count > 1)
@@ -508,7 +508,7 @@ typedef struct spellinfo_S {
garray_T si_comppat; // CHECKCOMPOUNDPATTERN items, each stored as garray_T si_comppat; // CHECKCOMPOUNDPATTERN items, each stored as
// a string // a string
char *si_compflags; // flags used for compounding char *si_compflags; // flags used for compounding
char_u si_nobreak; // NOBREAK char si_nobreak; // NOBREAK
char *si_syllable; // syllable string char *si_syllable; // syllable string
garray_T si_prefcond; // table with conditions for postponed garray_T si_prefcond; // table with conditions for postponed
// prefixes, each stored as a string // prefixes, each stored as a string
@@ -985,7 +985,7 @@ someerror:
if (c < 0) { if (c < 0) {
goto someerror; goto someerror;
} }
GA_APPEND(char_u, &ga, (char_u)c); GA_APPEND(uint8_t, &ga, (uint8_t)c);
if (c == NUL) { if (c == NUL) {
break; break;
} }
@@ -1060,7 +1060,7 @@ static int read_region_section(FILE *fd, slang_T *lp, int len)
static int read_charflags_section(FILE *fd) static int read_charflags_section(FILE *fd)
{ {
char *flags; char *flags;
char_u *fol; char *fol;
int flagslen, follen; int flagslen, follen;
// <charflagslen> <charflags> // <charflagslen> <charflags>
@@ -1070,7 +1070,7 @@ static int read_charflags_section(FILE *fd)
} }
// <folcharslen> <folchars> // <folcharslen> <folchars>
fol = (char_u *)read_cnt_string(fd, 2, &follen); fol = read_cnt_string(fd, 2, &follen);
if (follen < 0) { if (follen < 0) {
xfree(flags); xfree(flags);
return follen; return follen;
@@ -1078,7 +1078,7 @@ static int read_charflags_section(FILE *fd)
// Set the word-char flags and fill SPELL_ISUPPER() table. // Set the word-char flags and fill SPELL_ISUPPER() table.
if (flags != NULL && fol != NULL) { if (flags != NULL && fol != NULL) {
set_spell_charflags(flags, flagslen, (char *)fol); set_spell_charflags(flags, flagslen, fol);
} }
xfree(flags); xfree(flags);
@@ -2538,9 +2538,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname)
if (idx < 0) { if (idx < 0) {
// Not found, add a new condition. // Not found, add a new condition.
idx = spin->si_prefcond.ga_len; idx = spin->si_prefcond.ga_len;
char_u **pp = GA_APPEND_VIA_PTR(char_u *, &spin->si_prefcond); char **pp = GA_APPEND_VIA_PTR(char *, &spin->si_prefcond);
*pp = (aff_entry->ae_cond == NULL) ? *pp = (aff_entry->ae_cond == NULL) ?
NULL : (char_u *)getroom_save(spin, aff_entry->ae_cond); NULL : getroom_save(spin, aff_entry->ae_cond);
} }
// Add the prefix to the prefix tree. // Add the prefix to the prefix tree.
@@ -2565,7 +2565,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname)
if (aff_entry->ae_compforbid) { if (aff_entry->ae_compforbid) {
n |= WFP_COMPFORBID; n |= WFP_COMPFORBID;
} }
tree_add_word(spin, (char_u *)p, spin->si_prefroot, n, tree_add_word(spin, p, spin->si_prefroot, n,
idx, cur_aff->ah_newID); idx, cur_aff->ah_newID);
did_postpone_prefix = true; did_postpone_prefix = true;
} }
@@ -3232,7 +3232,7 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile)
if (spin->si_compflags != NULL) { if (spin->si_compflags != NULL) {
// Need to store the list of compound flags with the word. // Need to store the list of compound flags with the word.
// Concatenate them to the list of prefix IDs. // Concatenate them to the list of prefix IDs.
get_compflags(affile, afflist, (char_u *)store_afflist + pfxlen); get_compflags(affile, afflist, store_afflist + pfxlen);
} }
} }
@@ -3349,7 +3349,7 @@ static int get_pfxlist(afffile_T *affile, char *afflist, char *store_afflist)
// Get the list of compound IDs from the affix list "afflist" that are used // Get the list of compound IDs from the affix list "afflist" that are used
// for compound words. // for compound words.
// Puts the flags in "store_afflist[]". // Puts the flags in "store_afflist[]".
static void get_compflags(afffile_T *affile, char *afflist, char_u *store_afflist) static void get_compflags(afffile_T *affile, char *afflist, char *store_afflist)
{ {
int cnt = 0; int cnt = 0;
char key[AH_KEY_LEN]; char key[AH_KEY_LEN];
@@ -3362,7 +3362,7 @@ static void get_compflags(afffile_T *affile, char *afflist, char_u *store_afflis
xstrlcpy(key, prevp, (size_t)(p - prevp) + 1); xstrlcpy(key, prevp, (size_t)(p - prevp) + 1);
hi = hash_find(&affile->af_comp, (char *)key); hi = hash_find(&affile->af_comp, (char *)key);
if (!HASHITEM_EMPTY(hi)) { if (!HASHITEM_EMPTY(hi)) {
store_afflist[cnt++] = (char_u)HI2CI(hi)->ci_newID; store_afflist[cnt++] = (char)(uint8_t)HI2CI(hi)->ci_newID;
} }
} }
if (affile->af_flagtype == AFT_NUM && *p == ',') { if (affile->af_flagtype == AFT_NUM && *p == ',') {
@@ -3530,7 +3530,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_
if (spin->si_compflags != NULL) { if (spin->si_compflags != NULL) {
// Get compound IDS from the affix list. // Get compound IDS from the affix list.
get_compflags(affile, ae->ae_flags, get_compflags(affile, ae->ae_flags,
(char_u *)use_pfxlist + use_pfxlen); use_pfxlist + use_pfxlen);
} else { } else {
use_pfxlist[use_pfxlen] = NUL; use_pfxlist[use_pfxlen] = NUL;
} }
@@ -3835,7 +3835,7 @@ static void *getroom(spellinfo_T *spin, size_t len, bool align)
spin->si_blocks_cnt++; spin->si_blocks_cnt++;
} }
p = (char *)bl->sb_data + bl->sb_used; p = bl->sb_data + bl->sb_used;
bl->sb_used += (int)len; bl->sb_used += (int)len;
return p; return p;
@@ -3913,7 +3913,7 @@ static int store_word(spellinfo_T *spin, char *word, int flags, int region, cons
(void)spell_casefold(curwin, word, len, foldword, MAXWLEN); (void)spell_casefold(curwin, word, len, foldword, MAXWLEN);
for (const char *p = pfxlist; res == OK; p++) { for (const char *p = pfxlist; res == OK; p++) {
if (!need_affix || (p != NULL && *p != NUL)) { if (!need_affix || (p != NULL && *p != NUL)) {
res = tree_add_word(spin, (char_u *)foldword, spin->si_foldroot, ct | flags, res = tree_add_word(spin, foldword, spin->si_foldroot, ct | flags,
region, p == NULL ? 0 : *p); region, p == NULL ? 0 : *p);
} }
if (p == NULL || *p == NUL) { if (p == NULL || *p == NUL) {
@@ -3925,7 +3925,7 @@ static int store_word(spellinfo_T *spin, char *word, int flags, int region, cons
if (res == OK && (ct == WF_KEEPCAP || (flags & WF_KEEPCAP))) { if (res == OK && (ct == WF_KEEPCAP || (flags & WF_KEEPCAP))) {
for (const char *p = pfxlist; res == OK; p++) { for (const char *p = pfxlist; res == OK; p++) {
if (!need_affix || (p != NULL && *p != NUL)) { if (!need_affix || (p != NULL && *p != NUL)) {
res = tree_add_word(spin, (char_u *)word, spin->si_keeproot, flags, res = tree_add_word(spin, word, spin->si_keeproot, flags,
region, p == NULL ? 0 : *p); region, p == NULL ? 0 : *p);
} }
if (p == NULL || *p == NUL) { if (p == NULL || *p == NUL) {
@@ -3941,7 +3941,7 @@ static int store_word(spellinfo_T *spin, char *word, int flags, int region, cons
// When "flags" < 0 we are adding to the prefix tree where "flags" is used for // When "flags" < 0 we are adding to the prefix tree where "flags" is used for
// "rare" and "region" is the condition nr. // "rare" and "region" is the condition nr.
// Returns FAIL when out of memory. // Returns FAIL when out of memory.
static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root, int flags, static int tree_add_word(spellinfo_T *spin, const char *word, wordnode_T *root, int flags,
int region, int affixID) int region, int affixID)
{ {
wordnode_T *node = root; wordnode_T *node = root;
@@ -3993,7 +3993,7 @@ static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root
// higher byte value. For zero bytes (end of word) the sorting is // higher byte value. For zero bytes (end of word) the sorting is
// done on flags and then on affixID. // done on flags and then on affixID.
while (node != NULL while (node != NULL
&& (node->wn_byte < word[i] && (node->wn_byte < (uint8_t)word[i]
|| (node->wn_byte == NUL || (node->wn_byte == NUL
&& (flags < 0 && (flags < 0
? node->wn_affixID < (unsigned)affixID ? node->wn_affixID < (unsigned)affixID
@@ -4007,7 +4007,7 @@ static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root
node = *prev; node = *prev;
} }
if (node == NULL if (node == NULL
|| node->wn_byte != word[i] || node->wn_byte != (uint8_t)word[i]
|| (word[i] == NUL || (word[i] == NUL
&& (flags < 0 && (flags < 0
|| spin->si_sugtree || spin->si_sugtree
@@ -4018,7 +4018,7 @@ static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root
if (np == NULL) { if (np == NULL) {
return FAIL; return FAIL;
} }
np->wn_byte = word[i]; np->wn_byte = (uint8_t)word[i];
// If "node" is NULL this is a new child or the end of the sibling // If "node" is NULL this is a new child or the end of the sibling
// list: ref count is one. Otherwise use ref count of sibling and // list: ref count is one. Otherwise use ref count of sibling and
@@ -4040,7 +4040,7 @@ static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root
if (word[i] == NUL) { if (word[i] == NUL) {
node->wn_flags = (uint16_t)flags; node->wn_flags = (uint16_t)flags;
node->wn_region |= (int16_t)region; node->wn_region |= (int16_t)region;
node->wn_affixID = (char_u)affixID; node->wn_affixID = (uint8_t)affixID;
break; break;
} }
prev = &node->wn_child; prev = &node->wn_child;
@@ -4266,7 +4266,7 @@ static long node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, lo
// Make a hash key for the node and its siblings, so that we can quickly // Make a hash key for the node and its siblings, so that we can quickly
// find a lookalike node. This must be done after compressing the sibling // find a lookalike node. This must be done after compressing the sibling
// list, otherwise the hash key would become invalid by the compression. // list, otherwise the hash key would become invalid by the compression.
node->wn_u1.hashkey[0] = (char_u)len; node->wn_u1.hashkey[0] = (uint8_t)len;
nr = 0; nr = 0;
for (np = node; np != NULL; np = np->wn_sibling) { for (np = node; np != NULL; np = np->wn_sibling) {
if (np->wn_byte == NUL) { if (np->wn_byte == NUL) {
@@ -4281,13 +4281,13 @@ static long node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, lo
// Avoid NUL bytes, it terminates the hash key. // Avoid NUL bytes, it terminates the hash key.
n = nr & 0xff; n = nr & 0xff;
node->wn_u1.hashkey[1] = n == 0 ? 1 : (char_u)n; node->wn_u1.hashkey[1] = n == 0 ? 1 : (uint8_t)n;
n = (nr >> 8) & 0xff; n = (nr >> 8) & 0xff;
node->wn_u1.hashkey[2] = n == 0 ? 1 : (char_u)n; node->wn_u1.hashkey[2] = n == 0 ? 1 : (uint8_t)n;
n = (nr >> 16) & 0xff; n = (nr >> 16) & 0xff;
node->wn_u1.hashkey[3] = n == 0 ? 1 : (char_u)n; node->wn_u1.hashkey[3] = n == 0 ? 1 : (uint8_t)n;
n = (nr >> 24) & 0xff; n = (nr >> 24) & 0xff;
node->wn_u1.hashkey[4] = n == 0 ? 1 : (char_u)n; node->wn_u1.hashkey[4] = n == 0 ? 1 : (uint8_t)n;
node->wn_u1.hashkey[5] = NUL; node->wn_u1.hashkey[5] = NUL;
// Check for CTRL-C pressed now and then. // Check for CTRL-C pressed now and then.
@@ -4957,8 +4957,8 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang)
int depth; int depth;
idx_T arridx[MAXWLEN]; idx_T arridx[MAXWLEN];
int curi[MAXWLEN]; int curi[MAXWLEN];
char_u tword[MAXWLEN]; char tword[MAXWLEN];
char_u tsalword[MAXWLEN]; char tsalword[MAXWLEN];
int c; int c;
idx_T n; idx_T n;
unsigned words_done = 0; unsigned words_done = 0;
@@ -4999,7 +4999,7 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang)
if (c == 0) { if (c == 0) {
// Sound-fold the word. // Sound-fold the word.
tword[depth] = NUL; tword[depth] = NUL;
spell_soundfold(slang, (char *)tword, true, (char *)tsalword); spell_soundfold(slang, tword, true, tsalword);
// We use the "flags" field for the MSB of the wordnr, // We use the "flags" field for the MSB of the wordnr,
// "region" for the LSB of the wordnr. // "region" for the LSB of the wordnr.
@@ -5024,7 +5024,7 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang)
} }
} else { } else {
// Normal char, go one level deeper. // Normal char, go one level deeper.
tword[depth++] = (char_u)c; tword[depth++] = (char)(uint8_t)c;
arridx[depth] = idxs[n]; arridx[depth] = idxs[n];
curi[depth] = 1; curi[depth] = 1;
wordcount[depth] = 0; wordcount[depth] = 0;
@@ -5090,12 +5090,11 @@ static int sug_filltable(spellinfo_T *spin, wordnode_T *node, int startwordnr, g
// following bytes. // following bytes.
nr -= prev_nr; nr -= prev_nr;
prev_nr += nr; prev_nr += nr;
gap->ga_len += offset2bytes(nr, gap->ga_len += offset2bytes(nr, (char *)gap->ga_data + gap->ga_len);
(char_u *)gap->ga_data + gap->ga_len);
} }
// add the NUL byte // add the NUL byte
((char_u *)gap->ga_data)[gap->ga_len++] = NUL; ((char *)gap->ga_data)[gap->ga_len++] = NUL;
if (ml_append_buf(spin->si_spellbuf, (linenr_T)wordnr, if (ml_append_buf(spin->si_spellbuf, (linenr_T)wordnr,
gap->ga_data, gap->ga_len, true) == FAIL) { gap->ga_data, gap->ga_len, true) == FAIL) {
@@ -5126,8 +5125,9 @@ static int sug_filltable(spellinfo_T *spin, wordnode_T *node, int startwordnr, g
// Convert an offset into a minimal number of bytes. // Convert an offset into a minimal number of bytes.
// Similar to utf_char2byters, but use 8 bits in followup bytes and avoid NUL // Similar to utf_char2byters, but use 8 bits in followup bytes and avoid NUL
// bytes. // bytes.
static int offset2bytes(int nr, char_u *buf) static int offset2bytes(int nr, char *buf_in)
{ {
uint8_t *buf = (uint8_t *)buf_in;
int rem; int rem;
int b1, b2, b3, b4; int b1, b2, b3, b4;
@@ -5140,25 +5140,25 @@ static int offset2bytes(int nr, char_u *buf)
b4 = rem / 255 + 1; b4 = rem / 255 + 1;
if (b4 > 1 || b3 > 0x1f) { // 4 bytes if (b4 > 1 || b3 > 0x1f) { // 4 bytes
buf[0] = (char_u)(0xe0 + b4); buf[0] = (uint8_t)(0xe0 + b4);
buf[1] = (char_u)b3; buf[1] = (uint8_t)b3;
buf[2] = (char_u)b2; buf[2] = (uint8_t)b2;
buf[3] = (char_u)b1; buf[3] = (uint8_t)b1;
return 4; return 4;
} }
if (b3 > 1 || b2 > 0x3f) { // 3 bytes if (b3 > 1 || b2 > 0x3f) { // 3 bytes
buf[0] = (char_u)(0xc0 + b3); buf[0] = (uint8_t)(0xc0 + b3);
buf[1] = (char_u)b2; buf[1] = (uint8_t)b2;
buf[2] = (char_u)b1; buf[2] = (uint8_t)b1;
return 3; return 3;
} }
if (b2 > 1 || b1 > 0x7f) { // 2 bytes if (b2 > 1 || b1 > 0x7f) { // 2 bytes
buf[0] = (char_u)(0x80 + b2); buf[0] = (uint8_t)(0x80 + b2);
buf[1] = (char_u)b1; buf[1] = (uint8_t)b1;
return 2; return 2;
} }
// 1 byte // 1 byte
buf[0] = (char_u)b1; buf[0] = (uint8_t)b1;
return 1; return 1;
} }
@@ -5342,8 +5342,8 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool
semsg(_("E755: Invalid region in %s"), innames[i]); semsg(_("E755: Invalid region in %s"), innames[i]);
goto theend; goto theend;
} }
spin.si_region_name[i * 2] = (char_u)TOLOWER_ASC(innames[i][len - 2]); spin.si_region_name[i * 2] = (char)(uint8_t)TOLOWER_ASC(innames[i][len - 2]);
spin.si_region_name[i * 2 + 1] = (char_u)TOLOWER_ASC(innames[i][len - 1]); spin.si_region_name[i * 2 + 1] = (char)(uint8_t)TOLOWER_ASC(innames[i][len - 1]);
} }
} }
spin.si_region_count = incount; spin.si_region_count = incount;
@@ -5599,21 +5599,21 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo)
if (!undo) { if (!undo) {
fd = os_fopen(fname, "a"); fd = os_fopen(fname, "a");
if (fd == NULL && new_spf) { if (fd == NULL && new_spf) {
char_u *p; char *p;
// We just initialized the 'spellfile' option and can't open the // We just initialized the 'spellfile' option and can't open the
// file. We may need to create the "spell" directory first. We // file. We may need to create the "spell" directory first. We
// already checked the runtime directory is writable in // already checked the runtime directory is writable in
// init_spellfile(). // init_spellfile().
if (!dir_of_file_exists(fname) if (!dir_of_file_exists(fname)
&& (p = (char_u *)path_tail_with_sep(fname)) != (char_u *)fname) { && (p = path_tail_with_sep(fname)) != fname) {
int c = *p; char c = *p;
// The directory doesn't exist. Try creating it and opening // The directory doesn't exist. Try creating it and opening
// the file again. // the file again.
*p = NUL; *p = NUL;
os_mkdir(fname, 0755); os_mkdir(fname, 0755);
*p = (char_u)c; *p = c;
fd = os_fopen(fname, "a"); fd = os_fopen(fname, "a");
} }
} }

View File

@@ -92,7 +92,7 @@ getkey:
} }
#ifdef NVIM_LOG_DEBUG #ifdef NVIM_LOG_DEBUG
char *keyname = key == K_EVENT ? "K_EVENT" : (char *)get_special_key_name(key, mod_mask); char *keyname = key == K_EVENT ? "K_EVENT" : get_special_key_name(key, mod_mask);
DLOG("input: %s", keyname); DLOG("input: %s", keyname);
#endif #endif

View File

@@ -7,10 +7,6 @@
// dummy to pass an ACL to a function // dummy to pass an ACL to a function
typedef void *vim_acl_T; typedef void *vim_acl_T;
// Shorthand for unsigned variables. Many systems, but not all, have u_char
// already defined, so we use char_u to avoid trouble.
typedef unsigned char char_u;
// Can hold one decoded UTF-8 character. // Can hold one decoded UTF-8 character.
typedef uint32_t u8char_T; typedef uint32_t u8char_T;

View File

@@ -25,7 +25,6 @@ describe('ffi.cdef', function()
local ffi = require('ffi') local ffi = require('ffi')
ffi.cdef[[ ffi.cdef[[
typedef unsigned char char_u;
typedef struct window_S win_T; typedef struct window_S win_T;
typedef struct {} stl_hlrec_t; typedef struct {} stl_hlrec_t;
typedef struct {} StlClickRecord; typedef struct {} StlClickRecord;

View File

@@ -413,7 +413,7 @@ describe('treesitter highlighting', function()
it("supports injected languages", function() it("supports injected languages", function()
insert([[ insert([[
int x = INT_MAX; int x = INT_MAX;
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) #define READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
#define foo void main() { \ #define foo void main() { \
return 42; \ return 42; \
} }
@@ -421,7 +421,7 @@ describe('treesitter highlighting', function()
screen:expect{grid=[[ screen:expect{grid=[[
int x = INT_MAX; | int x = INT_MAX; |
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))| #define READ_STRING(x, y) (char *)read_string((x), (size_t)(y)) |
#define foo void main() { \ | #define foo void main() { \ |
return 42; \ | return 42; \ |
} | } |
@@ -450,7 +450,7 @@ describe('treesitter highlighting', function()
screen:expect{grid=[[ screen:expect{grid=[[
{3:int} x = {5:INT_MAX}; | {3:int} x = {5:INT_MAX}; |
#define {5:READ_STRING}(x, y) ({3:char_u} *)read_string((x), ({3:size_t})(y))| #define {5:READ_STRING}(x, y) ({3:char} *)read_string((x), ({3:size_t})(y)) |
#define foo {3:void} main() { \ | #define foo {3:void} main() { \ |
{4:return} {5:42}; \ | {4:return} {5:42}; \ |
} | } |
@@ -473,7 +473,7 @@ describe('treesitter highlighting', function()
it("supports overriding queries, like ", function() it("supports overriding queries, like ", function()
insert([[ insert([[
int x = INT_MAX; int x = INT_MAX;
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) #define READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
#define foo void main() { \ #define foo void main() { \
return 42; \ return 42; \
} }
@@ -489,7 +489,7 @@ describe('treesitter highlighting', function()
screen:expect{grid=[[ screen:expect{grid=[[
{3:int} x = {5:INT_MAX}; | {3:int} x = {5:INT_MAX}; |
#define {5:READ_STRING}(x, y) ({3:char_u} *)read_string((x), ({3:size_t})(y))| #define {5:READ_STRING}(x, y) ({3:char} *)read_string((x), ({3:size_t})(y)) |
#define foo {3:void} main() { \ | #define foo {3:void} main() { \ |
{4:return} {5:42}; \ | {4:return} {5:42}; \ |
} | } |
@@ -567,7 +567,7 @@ describe('treesitter highlighting', function()
it("supports highlighting with priority", function() it("supports highlighting with priority", function()
insert([[ insert([[
int x = INT_MAX; int x = INT_MAX;
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) #define READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
#define foo void main() { \ #define foo void main() { \
return 42; \ return 42; \
} }
@@ -580,7 +580,7 @@ describe('treesitter highlighting', function()
-- expect everything to have Constant highlight -- expect everything to have Constant highlight
screen:expect{grid=[[ screen:expect{grid=[[
{12:int}{8: x = INT_MAX;} | {12:int}{8: x = INT_MAX;} |
{8:#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))}| {8:#define READ_STRING(x, y) (char *)read_string((x), (size_t)(y))} |
{8:#define foo void main() { \} | {8:#define foo void main() { \} |
{8: return 42; \} | {8: return 42; \} |
{8: }} | {8: }} |

View File

@@ -627,8 +627,8 @@ end]]
before_each(function() before_each(function()
insert([[ insert([[
int x = INT_MAX; int x = INT_MAX;
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) #define READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
#define READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) #define READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
#define VALUE 123 #define VALUE 123
#define VALUE1 123 #define VALUE1 123
#define VALUE2 123 #define VALUE2 123
@@ -650,8 +650,8 @@ int x = INT_MAX;
{3, 14, 3, 17}, -- VALUE 123 {3, 14, 3, 17}, -- VALUE 123
{4, 15, 4, 18}, -- VALUE1 123 {4, 15, 4, 18}, -- VALUE1 123
{5, 15, 5, 18}, -- VALUE2 123 {5, 15, 5, 18}, -- VALUE2 123
{1, 26, 1, 65}, -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) {1, 26, 1, 63}, -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
{2, 29, 2, 68} -- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) {2, 29, 2, 66} -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
}, get_ranges()) }, get_ranges())
helpers.feed('ggo<esc>') helpers.feed('ggo<esc>')
@@ -661,8 +661,8 @@ int x = INT_MAX;
{4, 14, 4, 17}, -- VALUE 123 {4, 14, 4, 17}, -- VALUE 123
{5, 15, 5, 18}, -- VALUE1 123 {5, 15, 5, 18}, -- VALUE1 123
{6, 15, 6, 18}, -- VALUE2 123 {6, 15, 6, 18}, -- VALUE2 123
{2, 26, 2, 65}, -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) {2, 26, 2, 63}, -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
{3, 29, 3, 68} -- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) {3, 29, 3, 66} -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
}, get_ranges()) }, get_ranges())
end) end)
end) end)
@@ -682,8 +682,8 @@ int x = INT_MAX;
{3, 14, 5, 18}, -- VALUE 123 {3, 14, 5, 18}, -- VALUE 123
-- VALUE1 123 -- VALUE1 123
-- VALUE2 123 -- VALUE2 123
{1, 26, 2, 68} -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) {1, 26, 2, 66} -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
-- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
}, get_ranges()) }, get_ranges())
helpers.feed('ggo<esc>') helpers.feed('ggo<esc>')
@@ -694,8 +694,8 @@ int x = INT_MAX;
{4, 14, 6, 18}, -- VALUE 123 {4, 14, 6, 18}, -- VALUE 123
-- VALUE1 123 -- VALUE1 123
-- VALUE2 123 -- VALUE2 123
{2, 26, 3, 68} -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) {2, 26, 3, 66} -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
-- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
}, get_ranges()) }, get_ranges())
end) end)
end) end)
@@ -722,8 +722,8 @@ int x = INT_MAX;
{3, 14, 5, 18}, -- VALUE 123 {3, 14, 5, 18}, -- VALUE 123
-- VALUE1 123 -- VALUE1 123
-- VALUE2 123 -- VALUE2 123
{1, 26, 2, 68} -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) {1, 26, 2, 66} -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
-- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
}, get_ranges()) }, get_ranges())
helpers.feed('ggo<esc>') helpers.feed('ggo<esc>')
@@ -734,8 +734,8 @@ int x = INT_MAX;
{4, 14, 6, 18}, -- VALUE 123 {4, 14, 6, 18}, -- VALUE 123
-- VALUE1 123 -- VALUE1 123
-- VALUE2 123 -- VALUE2 123
{2, 26, 3, 68} -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) {2, 26, 3, 66} -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
-- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
}, get_ranges()) }, get_ranges())
end) end)
@@ -768,8 +768,8 @@ int x = INT_MAX;
{3, 15, 3, 16}, -- VALUE 123 {3, 15, 3, 16}, -- VALUE 123
{4, 16, 4, 17}, -- VALUE1 123 {4, 16, 4, 17}, -- VALUE1 123
{5, 16, 5, 17}, -- VALUE2 123 {5, 16, 5, 17}, -- VALUE2 123
{1, 26, 1, 65}, -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) {1, 26, 1, 63}, -- READ_STRING(x, y) (char *)read_string((x), (size_t)(y))
{2, 29, 2, 68} -- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) {2, 29, 2, 66} -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y))
}, get_ranges()) }, get_ranges())
end) end)
it("should list all directives", function() it("should list all directives", function()

View File

@@ -1,172 +0,0 @@
#include <stdbool.h>
#include "nvim/ascii.h"
#include "nvim/macros.h"
#include "nvim/charset.h"
#include "nvim/eval/typval.h"
#include "nvim/vim.h"
int hex2nr(int c)
{
if ((c >= 'a') && (c <= 'f')) {
return c - 'a' + 10;
}
if ((c >= 'A') && (c <= 'F')) {
return c - 'A' + 10;
}
return c - '0';
}
void vim_str2nr(const char_u *const start, int *const prep, int *const len,
const int what, varnumber_T *const nptr,
uvarnumber_T *const unptr, const int maxlen)
{
const char *ptr = (const char *)start;
#define STRING_ENDED(ptr) \
(!(maxlen == 0 || (int)((ptr) - (const char *)start) < maxlen))
int pre = 0; // default is decimal
const bool negative = (ptr[0] == '-');
uvarnumber_T un = 0;
if (negative) {
ptr++;
}
if (what & STR2NR_FORCE) {
// When forcing main consideration is skipping the prefix. Octal and decimal
// numbers have no prefixes to skip. pre is not set.
switch ((unsigned)what & (~(unsigned)STR2NR_FORCE)) {
case STR2NR_HEX: {
if (!STRING_ENDED(ptr + 2)
&& ptr[0] == '0'
&& (ptr[1] == 'x' || ptr[1] == 'X')
&& ascii_isxdigit(ptr[2])) {
ptr += 2;
}
goto vim_str2nr_hex;
}
case STR2NR_BIN: {
if (!STRING_ENDED(ptr + 2)
&& ptr[0] == '0'
&& (ptr[1] == 'b' || ptr[1] == 'B')
&& ascii_isbdigit(ptr[2])) {
ptr += 2;
}
goto vim_str2nr_bin;
}
case STR2NR_OCT: {
goto vim_str2nr_oct;
}
case 0: {
goto vim_str2nr_dec;
}
default: {
abort();
}
}
} else if ((what & (STR2NR_HEX|STR2NR_OCT|STR2NR_BIN))
&& !STRING_ENDED(ptr + 1)
&& ptr[0] == '0' && ptr[1] != '8' && ptr[1] != '9') {
pre = ptr[1];
// Detect hexadecimal: 0x or 0X followed by hex digit
if ((what & STR2NR_HEX)
&& !STRING_ENDED(ptr + 2)
&& (pre == 'X' || pre == 'x')
&& ascii_isxdigit(ptr[2])) {
ptr += 2;
goto vim_str2nr_hex;
}
// Detect binary: 0b or 0B followed by 0 or 1
if ((what & STR2NR_BIN)
&& !STRING_ENDED(ptr + 2)
&& (pre == 'B' || pre == 'b')
&& ascii_isbdigit(ptr[2])) {
ptr += 2;
goto vim_str2nr_bin;
}
// Detect octal number: zero followed by octal digits without '8' or '9'
pre = 0;
if (!(what & STR2NR_OCT)) {
goto vim_str2nr_dec;
}
for (int i = 2; !STRING_ENDED(ptr + i) && ascii_isdigit(ptr[i]); i++) {
if (ptr[i] > '7') {
goto vim_str2nr_dec;
}
}
pre = '0';
goto vim_str2nr_oct;
} else {
goto vim_str2nr_dec;
}
// Do the string-to-numeric conversion "manually" to avoid sscanf quirks.
abort(); // Shouldve used goto earlier.
#define PARSE_NUMBER(base, cond, conv) \
do { \
while (!STRING_ENDED(ptr) && (cond)) { \
/* avoid ubsan error for overflow */ \
if (un < UVARNUMBER_MAX / base) { \
un = base * un + (uvarnumber_T)(conv); \
} else { \
un = UVARNUMBER_MAX; \
} \
ptr++; \
} \
} while (0)
switch (pre) {
case 'b':
case 'B': {
vim_str2nr_bin:
PARSE_NUMBER(2, (*ptr == '0' || *ptr == '1'), (*ptr - '0'));
break;
}
case '0': {
vim_str2nr_oct:
PARSE_NUMBER(8, ('0' <= *ptr && *ptr <= '7'), (*ptr - '0'));
break;
}
case 0: {
vim_str2nr_dec:
PARSE_NUMBER(10, (ascii_isdigit(*ptr)), (*ptr - '0'));
break;
}
case 'x':
case 'X': {
vim_str2nr_hex:
PARSE_NUMBER(16, (ascii_isxdigit(*ptr)), (hex2nr(*ptr)));
break;
}
}
#undef PARSE_NUMBER
if (prep != NULL) {
*prep = pre;
}
if (len != NULL) {
*len = (int)(ptr - (const char *)start);
}
if (nptr != NULL) {
if (negative) { // account for leading '-' for decimal numbers
// avoid ubsan error for overflow
if (un > VARNUMBER_MAX) {
*nptr = VARNUMBER_MIN;
} else {
*nptr = -(varnumber_T)un;
}
} else {
if (un > VARNUMBER_MAX) {
un = VARNUMBER_MAX;
}
*nptr = (varnumber_T)un;
}
}
if (unptr != NULL) {
*unptr = un;
}
#undef STRING_ENDED
}

View File

@@ -1,195 +0,0 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
/// @file garray.c
///
/// Functions for handling growing arrays.
#include <string.h>
#include <inttypes.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/log.h"
#include "nvim/memory.h"
#include "nvim/path.h"
#include "nvim/garray.h"
#include "nvim/strings.h"
// #include "nvim/globals.h"
#include "nvim/memline.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "garray.c.generated.h"
#endif
/// Clear an allocated growing array.
void ga_clear(garray_T *gap)
{
xfree(gap->ga_data);
// Initialize growing array without resetting itemsize or growsize
gap->ga_data = NULL;
gap->ga_maxlen = 0;
gap->ga_len = 0;
}
/// Clear a growing array that contains a list of strings.
///
/// @param gap
void ga_clear_strings(garray_T *gap)
{
GA_DEEP_CLEAR_PTR(gap);
}
/// Initialize a growing array.
///
/// @param gap
/// @param itemsize
/// @param growsize
void ga_init(garray_T *gap, int itemsize, int growsize)
{
gap->ga_data = NULL;
gap->ga_maxlen = 0;
gap->ga_len = 0;
gap->ga_itemsize = itemsize;
ga_set_growsize(gap, growsize);
}
/// A setter for the growsize that guarantees it will be at least 1.
///
/// @param gap
/// @param growsize
void ga_set_growsize(garray_T *gap, int growsize)
{
if (growsize < 1) {
WLOG("trying to set an invalid ga_growsize: %d", growsize);
gap->ga_growsize = 1;
} else {
gap->ga_growsize = growsize;
}
}
/// Make room in growing array "gap" for at least "n" items.
///
/// @param gap
/// @param n
void ga_grow(garray_T *gap, int n)
{
if (gap->ga_maxlen - gap->ga_len >= n) {
// the garray still has enough space, do nothing
return;
}
if (gap->ga_growsize < 1) {
WLOG("ga_growsize(%d) is less than 1", gap->ga_growsize);
}
// the garray grows by at least growsize
if (n < gap->ga_growsize) {
n = gap->ga_growsize;
}
int new_maxlen = gap->ga_len + n;
size_t new_size = (size_t)(gap->ga_itemsize * new_maxlen);
size_t old_size = (size_t)(gap->ga_itemsize * gap->ga_maxlen);
// reallocate and clear the new memory
char *pp = xrealloc(gap->ga_data, new_size);
memset(pp + old_size, 0, new_size - old_size);
gap->ga_maxlen = new_maxlen;
gap->ga_data = pp;
}
/// For a growing array that contains a list of strings: concatenate all the
/// strings with sep as separator.
///
/// @param gap
/// @param sep
///
/// @returns the concatenated strings
char_u *ga_concat_strings_sep(const garray_T *gap, const char *sep)
FUNC_ATTR_NONNULL_RET
{
const size_t nelem = (size_t) gap->ga_len;
const char **strings = gap->ga_data;
if (nelem == 0) {
return (char_u *) xstrdup("");
}
size_t len = 0;
for (size_t i = 0; i < nelem; i++) {
len += strlen(strings[i]);
}
// add some space for the (num - 1) separators
len += (nelem - 1) * strlen(sep);
char *const ret = xmallocz(len);
char *s = ret;
for (size_t i = 0; i < nelem - 1; i++) {
s = xstpcpy(s, strings[i]);
s = xstpcpy(s, sep);
}
strcpy(s, strings[nelem - 1]);
return (char_u *) ret;
}
/// For a growing array that contains a list of strings: concatenate all the
/// strings with a separating comma.
///
/// @param gap
///
/// @returns the concatenated strings
char_u* ga_concat_strings(const garray_T *gap) FUNC_ATTR_NONNULL_RET
{
return ga_concat_strings_sep(gap, ",");
}
/// Concatenate a string to a growarray which contains characters.
/// When "s" is NULL does not do anything.
///
/// WARNING:
/// - Does NOT copy the NUL at the end!
/// - The parameter may not overlap with the growing array
///
/// @param gap
/// @param s
void ga_concat(garray_T *gap, const char_u *restrict s)
{
if (s == NULL) {
return;
}
ga_concat_len(gap, (const char *restrict) s, strlen((char *) s));
}
/// Concatenate a string to a growarray which contains characters
///
/// @param[out] gap Growarray to modify.
/// @param[in] s String to concatenate.
/// @param[in] len String length.
void ga_concat_len(garray_T *const gap, const char *restrict s,
const size_t len)
FUNC_ATTR_NONNULL_ALL
{
if (len) {
ga_grow(gap, (int) len);
char *data = gap->ga_data;
memcpy(data + gap->ga_len, s, len);
gap->ga_len += (int) len;
}
}
/// Append one byte to a growarray which contains bytes.
///
/// @param gap
/// @param c
void ga_append(garray_T *gap, char c)
{
GA_APPEND(char, gap, c);
}

View File

@@ -1,4 +0,0 @@
char *gettext(const char *s)
{
return (char *)s;
}

View File

@@ -1,559 +0,0 @@
#include <stdbool.h>
#include "nvim/types.h"
#include "nvim/keycodes.h"
#include "nvim/ascii.h"
#include "nvim/eval/typval.h"
#define MOD_KEYS_ENTRY_SIZE 5
static char_u modifier_keys_table[] =
{
MOD_MASK_SHIFT, '&', '9', '@', '1',
MOD_MASK_SHIFT, '&', '0', '@', '2',
MOD_MASK_SHIFT, '*', '1', '@', '4',
MOD_MASK_SHIFT, '*', '2', '@', '5',
MOD_MASK_SHIFT, '*', '3', '@', '6',
MOD_MASK_SHIFT, '*', '4', 'k', 'D',
MOD_MASK_SHIFT, '*', '5', 'k', 'L',
MOD_MASK_SHIFT, '*', '7', '@', '7',
MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_END, '@', '7',
MOD_MASK_SHIFT, '*', '9', '@', '9',
MOD_MASK_SHIFT, '*', '0', '@', '0',
MOD_MASK_SHIFT, '#', '1', '%', '1',
MOD_MASK_SHIFT, '#', '2', 'k', 'h',
MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_HOME, 'k', 'h',
MOD_MASK_SHIFT, '#', '3', 'k', 'I',
MOD_MASK_SHIFT, '#', '4', 'k', 'l',
MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_LEFT, 'k', 'l',
MOD_MASK_SHIFT, '%', 'a', '%', '3',
MOD_MASK_SHIFT, '%', 'b', '%', '4',
MOD_MASK_SHIFT, '%', 'c', '%', '5',
MOD_MASK_SHIFT, '%', 'd', '%', '7',
MOD_MASK_SHIFT, '%', 'e', '%', '8',
MOD_MASK_SHIFT, '%', 'f', '%', '9',
MOD_MASK_SHIFT, '%', 'g', '%', '0',
MOD_MASK_SHIFT, '%', 'h', '&', '3',
MOD_MASK_SHIFT, '%', 'i', 'k', 'r',
MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_RIGHT, 'k', 'r',
MOD_MASK_SHIFT, '%', 'j', '&', '5',
MOD_MASK_SHIFT, '!', '1', '&', '6',
MOD_MASK_SHIFT, '!', '2', '&', '7',
MOD_MASK_SHIFT, '!', '3', '&', '8',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_UP, 'k', 'u',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_DOWN, 'k', 'd',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF1, KS_EXTRA, (int)KE_XF1,
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF2, KS_EXTRA, (int)KE_XF2,
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF3, KS_EXTRA, (int)KE_XF3,
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF4, KS_EXTRA, (int)KE_XF4,
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F1, 'k', '1',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F2, 'k', '2',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F3, 'k', '3',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F4, 'k', '4',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F5, 'k', '5',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F6, 'k', '6',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F7, 'k', '7',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F8, 'k', '8',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F9, 'k', '9',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F10, 'k', ';',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F11, 'F', '1',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F12, 'F', '2',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F13, 'F', '3',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F14, 'F', '4',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F15, 'F', '5',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F16, 'F', '6',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F17, 'F', '7',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F18, 'F', '8',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F19, 'F', '9',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F20, 'F', 'A',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F21, 'F', 'B',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F22, 'F', 'C',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F23, 'F', 'D',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F24, 'F', 'E',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F25, 'F', 'F',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F26, 'F', 'G',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F27, 'F', 'H',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F28, 'F', 'I',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F29, 'F', 'J',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F30, 'F', 'K',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F31, 'F', 'L',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F32, 'F', 'M',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F33, 'F', 'N',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F34, 'F', 'O',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F35, 'F', 'P',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F36, 'F', 'Q',
MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F37, 'F', 'R',
MOD_MASK_SHIFT, 'k', 'B', KS_EXTRA, (int)KE_TAB,
NUL
};
int simplify_key(const int key, int *modifiers)
{
if (*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT)) {
// TAB is a special case.
if (key == TAB && (*modifiers & MOD_MASK_SHIFT)) {
*modifiers &= ~MOD_MASK_SHIFT;
return K_S_TAB;
}
const int key0 = KEY2TERMCAP0(key);
const int key1 = KEY2TERMCAP1(key);
for (int i = 0; modifier_keys_table[i] != NUL; i += MOD_KEYS_ENTRY_SIZE) {
if (key0 == modifier_keys_table[i + 3]
&& key1 == modifier_keys_table[i + 4]
&& (*modifiers & modifier_keys_table[i])) {
*modifiers &= ~modifier_keys_table[i];
return TERMCAP2KEY(modifier_keys_table[i + 1],
modifier_keys_table[i + 2]);
}
}
}
return key;
}
int handle_x_keys(const int key)
FUNC_ATTR_CONST FUNC_ATTR_WARN_UNUSED_RESULT
{
switch (key) {
case K_XUP: return K_UP;
case K_XDOWN: return K_DOWN;
case K_XLEFT: return K_LEFT;
case K_XRIGHT: return K_RIGHT;
case K_XHOME: return K_HOME;
case K_ZHOME: return K_HOME;
case K_XEND: return K_END;
case K_ZEND: return K_END;
case K_XF1: return K_F1;
case K_XF2: return K_F2;
case K_XF3: return K_F3;
case K_XF4: return K_F4;
case K_S_XF1: return K_S_F1;
case K_S_XF2: return K_S_F2;
case K_S_XF3: return K_S_F3;
case K_S_XF4: return K_S_F4;
}
return key;
}
static const struct key_name_entry {
int key; // Special key code or ascii value
const char *name; // Name of key
} key_names_table[] = {
{ ' ', "Space" },
{ TAB, "Tab" },
{ K_TAB, "Tab" },
{ NL, "NL" },
{ NL, "NewLine" }, // Alternative name
{ NL, "LineFeed" }, // Alternative name
{ NL, "LF" }, // Alternative name
{ CAR, "CR" },
{ CAR, "Return" }, // Alternative name
{ CAR, "Enter" }, // Alternative name
{ K_BS, "BS" },
{ K_BS, "BackSpace" }, // Alternative name
{ ESC, "Esc" },
{ CSI, "CSI" },
{ K_CSI, "xCSI" },
{ '|', "Bar" },
{ '\\', "Bslash" },
{ K_DEL, "Del" },
{ K_DEL, "Delete" }, // Alternative name
{ K_KDEL, "kDel" },
{ K_KDEL, "KPPeriod" }, // termkey KPPeriod value
{ K_UP, "Up" },
{ K_DOWN, "Down" },
{ K_LEFT, "Left" },
{ K_RIGHT, "Right" },
{ K_XUP, "xUp" },
{ K_XDOWN, "xDown" },
{ K_XLEFT, "xLeft" },
{ K_XRIGHT, "xRight" },
{ K_KUP, "kUp" },
{ K_KUP, "KP8" },
{ K_KDOWN, "kDown" },
{ K_KDOWN, "KP2" },
{ K_KLEFT, "kLeft" },
{ K_KLEFT, "KP4" },
{ K_KRIGHT, "kRight" },
{ K_KRIGHT, "KP6" },
{ K_F1, "F1" },
{ K_F2, "F2" },
{ K_F3, "F3" },
{ K_F4, "F4" },
{ K_F5, "F5" },
{ K_F6, "F6" },
{ K_F7, "F7" },
{ K_F8, "F8" },
{ K_F9, "F9" },
{ K_F10, "F10" },
{ K_F11, "F11" },
{ K_F12, "F12" },
{ K_F13, "F13" },
{ K_F14, "F14" },
{ K_F15, "F15" },
{ K_F16, "F16" },
{ K_F17, "F17" },
{ K_F18, "F18" },
{ K_F19, "F19" },
{ K_F20, "F20" },
{ K_F21, "F21" },
{ K_F22, "F22" },
{ K_F23, "F23" },
{ K_F24, "F24" },
{ K_F25, "F25" },
{ K_F26, "F26" },
{ K_F27, "F27" },
{ K_F28, "F28" },
{ K_F29, "F29" },
{ K_F30, "F30" },
{ K_F31, "F31" },
{ K_F32, "F32" },
{ K_F33, "F33" },
{ K_F34, "F34" },
{ K_F35, "F35" },
{ K_F36, "F36" },
{ K_F37, "F37" },
{ K_XF1, "xF1" },
{ K_XF2, "xF2" },
{ K_XF3, "xF3" },
{ K_XF4, "xF4" },
{ K_HELP, "Help" },
{ K_UNDO, "Undo" },
{ K_INS, "Insert" },
{ K_INS, "Ins" }, // Alternative name
{ K_KINS, "kInsert" },
{ K_KINS, "KP0" },
{ K_HOME, "Home" },
{ K_KHOME, "kHome" },
{ K_KHOME, "KP7" },
{ K_XHOME, "xHome" },
{ K_ZHOME, "zHome" },
{ K_END, "End" },
{ K_KEND, "kEnd" },
{ K_XEND, "xEnd" },
{ K_ZEND, "zEnd" },
{ K_PAGEUP, "PageUp" },
{ K_PAGEDOWN, "PageDown" },
{ K_KPAGEUP, "kPageUp" },
{ K_KPAGEUP, "KP9" },
{ K_KPAGEDOWN, "kPageDown" },
{ K_KPAGEDOWN, "KP3" },
{ K_KORIGIN, "kOrigin" },
{ K_KORIGIN, "KP5" },
{ K_KPLUS, "kPlus" },
{ K_KPLUS, "KPPlus" },
{ K_KMINUS, "kMinus" },
{ K_KMINUS, "KPMinus" },
{ K_KDIVIDE, "kDivide" },
{ K_KDIVIDE, "KPDiv" },
{ K_KMULTIPLY, "kMultiply" },
{ K_KMULTIPLY, "KPMult" },
{ K_KENTER, "kEnter" },
{ K_KENTER, "KPEnter" },
{ K_KPOINT, "kPoint" },
{ K_K0, "k0" },
{ K_K1, "k1" },
{ K_K2, "k2" },
{ K_K3, "k3" },
{ K_K4, "k4" },
{ K_K5, "k5" },
{ K_K6, "k6" },
{ K_K7, "k7" },
{ K_K8, "k8" },
{ K_K9, "k9" },
{ '<', "lt" },
{ K_MOUSE, "Mouse" },
{ K_LEFTMOUSE, "LeftMouse" },
{ K_LEFTMOUSE_NM, "LeftMouseNM" },
{ K_LEFTDRAG, "LeftDrag" },
{ K_LEFTRELEASE, "LeftRelease" },
{ K_LEFTRELEASE_NM, "LeftReleaseNM" },
{ K_MIDDLEMOUSE, "MiddleMouse" },
{ K_MIDDLEDRAG, "MiddleDrag" },
{ K_MIDDLERELEASE, "MiddleRelease" },
{ K_RIGHTMOUSE, "RightMouse" },
{ K_RIGHTDRAG, "RightDrag" },
{ K_RIGHTRELEASE, "RightRelease" },
{ K_MOUSEDOWN, "ScrollWheelUp" },
{ K_MOUSEUP, "ScrollWheelDown" },
{ K_MOUSELEFT, "ScrollWheelRight" },
{ K_MOUSERIGHT, "ScrollWheelLeft" },
{ K_MOUSEDOWN, "MouseDown" }, // OBSOLETE: Use
{ K_MOUSEUP, "MouseUp" }, // ScrollWheelXXX instead
{ K_X1MOUSE, "X1Mouse" },
{ K_X1DRAG, "X1Drag" },
{ K_X1RELEASE, "X1Release" },
{ K_X2MOUSE, "X2Mouse" },
{ K_X2DRAG, "X2Drag" },
{ K_X2RELEASE, "X2Release" },
{ K_DROP, "Drop" },
{ K_ZERO, "Nul" },
{ K_SNR, "SNR" },
{ K_PLUG, "Plug" },
{ K_PASTE, "Paste" },
{ 0, NULL }
};
int get_special_key_code(const char_u *name)
{
for (int i = 0; key_names_table[i].name != NULL; i++) {
const char *const table_name = key_names_table[i].name;
int j;
for (j = 0; ascii_isident(name[j]) && table_name[j] != NUL; j++) {
if (TOLOWER_ASC(table_name[j]) != TOLOWER_ASC(name[j])) {
break;
}
}
if (!ascii_isident(name[j]) && table_name[j] == NUL) {
return key_names_table[i].key;
}
}
return 0;
}
static const struct modmasktable {
short mod_mask; ///< Bit-mask for particular key modifier.
short mod_flag; ///< Bit(s) for particular key modifier.
char_u name; ///< Single letter name of modifier.
} mod_mask_table[] = {
{MOD_MASK_ALT, MOD_MASK_ALT, (char_u)'M'},
{MOD_MASK_META, MOD_MASK_META, (char_u)'T'},
{MOD_MASK_CTRL, MOD_MASK_CTRL, (char_u)'C'},
{MOD_MASK_SHIFT, MOD_MASK_SHIFT, (char_u)'S'},
{MOD_MASK_MULTI_CLICK, MOD_MASK_2CLICK, (char_u)'2'},
{MOD_MASK_MULTI_CLICK, MOD_MASK_3CLICK, (char_u)'3'},
{MOD_MASK_MULTI_CLICK, MOD_MASK_4CLICK, (char_u)'4'},
{MOD_MASK_CMD, MOD_MASK_CMD, (char_u)'D'},
// 'A' must be the last one
{MOD_MASK_ALT, MOD_MASK_ALT, (char_u)'A'},
{0, 0, NUL}
};
int name_to_mod_mask(int c)
{
c = TOUPPER_ASC(c);
for (size_t i = 0; mod_mask_table[i].mod_mask != 0; i++) {
if (c == mod_mask_table[i].name) {
return mod_mask_table[i].mod_flag;
}
}
return 0;
}
static int extract_modifiers(int key, int *modp)
{
int modifiers = *modp;
if (!(modifiers & MOD_MASK_CMD)) { // Command-key is special
if ((modifiers & MOD_MASK_SHIFT) && ASCII_ISALPHA(key)) {
key = TOUPPER_ASC(key);
modifiers &= ~MOD_MASK_SHIFT;
}
}
if ((modifiers & MOD_MASK_CTRL)
&& ((key >= '?' && key <= '_') || ASCII_ISALPHA(key))) {
key = Ctrl_chr(key);
modifiers &= ~MOD_MASK_CTRL;
if (key == 0) { // <C-@> is <Nul>
key = K_ZERO;
}
}
*modp = modifiers;
return key;
}
int find_special_key(const char_u **srcp, const size_t src_len, int *const modp,
const bool keycode, const bool keep_x_key,
const bool in_string)
{
const char_u *last_dash;
const char_u *end_of_name;
const char_u *src;
const char_u *bp;
const char_u *const end = *srcp + src_len - 1;
int modifiers;
int bit;
int key;
uvarnumber_T n;
int l;
if (src_len == 0) {
return 0;
}
src = *srcp;
if (src[0] != '<') {
return 0;
}
// Find end of modifier list
last_dash = src;
for (bp = src + 1; bp <= end && (*bp == '-' || ascii_isident(*bp)); bp++) {
if (*bp == '-') {
last_dash = bp;
if (bp + 1 <= end) {
l = utfc_ptr2len_len(bp + 1, (int)(end - bp) + 1);
// Anything accepted, like <C-?>.
// <C-"> or <M-"> are not special in strings as " is
// the string delimiter. With a backslash it works: <M-\">
if (end - bp > l && !(in_string && bp[1] == '"') && bp[2] == '>') {
bp += l;
} else if (end - bp > 2 && in_string && bp[1] == '\\'
&& bp[2] == '"' && bp[3] == '>') {
bp += 2;
}
}
}
if (end - bp > 3 && bp[0] == 't' && bp[1] == '_') {
bp += 3; // skip t_xx, xx may be '-' or '>'
} else if (end - bp > 4 && STRNICMP(bp, "char-", 5) == 0) {
vim_str2nr(bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0);
bp += l + 5;
break;
}
}
if (bp <= end && *bp == '>') { // found matching '>'
end_of_name = bp + 1;
/* Which modifiers are given? */
modifiers = 0x0;
for (bp = src + 1; bp < last_dash; bp++) {
if (*bp != '-') {
bit = name_to_mod_mask(*bp);
if (bit == 0x0) {
break; // Illegal modifier name
}
modifiers |= bit;
}
}
// Legal modifier name.
if (bp >= last_dash) {
if (STRNICMP(last_dash + 1, "char-", 5) == 0
&& ascii_isdigit(last_dash[6])) {
// <Char-123> or <Char-033> or <Char-0x33>
vim_str2nr(last_dash + 6, NULL, NULL, STR2NR_ALL, NULL, &n, 0);
key = (int)n;
} else {
int off = 1;
// Modifier with single letter, or special key name.
if (in_string && last_dash[1] == '\\' && last_dash[2] == '"') {
off = 2;
}
l = mb_ptr2len(last_dash + 1);
if (modifiers != 0 && last_dash[l + 1] == '>') {
key = PTR2CHAR(last_dash + off);
} else {
key = get_special_key_code(last_dash + off);
if (!keep_x_key) {
key = handle_x_keys(key);
}
}
}
// get_special_key_code() may return NUL for invalid
// special key name.
if (key != NUL) {
// Only use a modifier when there is no special key code that
// includes the modifier.
key = simplify_key(key, &modifiers);
if (!keycode) {
// don't want keycode, use single byte code
if (key == K_BS) {
key = BS;
} else if (key == K_DEL || key == K_KDEL) {
key = DEL;
}
}
// Normal Key with modifier:
// Try to make a single byte code (except for Alt/Meta modifiers).
if (!IS_SPECIAL(key)) {
key = extract_modifiers(key, &modifiers);
}
*modp = modifiers;
*srcp = end_of_name;
return key;
}
}
}
return 0;
}
char_u *add_char2buf(int c, char_u *s)
{
char_u temp[MB_MAXBYTES + 1];
const int len = utf_char2bytes(c, temp);
for (int i = 0; i < len; ++i) {
c = temp[i];
// Need to escape K_SPECIAL and CSI like in the typeahead buffer.
if (c == K_SPECIAL) {
*s++ = K_SPECIAL;
*s++ = KS_SPECIAL;
*s++ = KE_FILLER;
} else {
*s++ = c;
}
}
return s;
}
unsigned int trans_special(const char_u **srcp, const size_t src_len,
char_u *const dst, const bool keycode,
const bool in_string)
{
int modifiers = 0;
int key;
unsigned int dlen = 0;
key = find_special_key(srcp, src_len, &modifiers, keycode, false, in_string);
if (key == 0) {
return 0;
}
// Put the appropriate modifier in a string.
if (modifiers != 0) {
dst[dlen++] = K_SPECIAL;
dst[dlen++] = KS_MODIFIER;
dst[dlen++] = (char_u)modifiers;
}
if (IS_SPECIAL(key)) {
dst[dlen++] = K_SPECIAL;
dst[dlen++] = (char_u)KEY2TERMCAP0(key);
dst[dlen++] = KEY2TERMCAP1(key);
} else if (!keycode) {
dlen += (unsigned int)(*mb_char2bytes)(key, dst + dlen);
} else if (keycode) {
char_u *after = add_char2buf(key, dst + dlen);
assert(after >= dst && (uintmax_t)(after - dst) <= UINT_MAX);
dlen = (unsigned int)(after - dst);
} else {
dst[dlen++] = (char_u)key;
}
return dlen;
}

View File

@@ -1,266 +0,0 @@
#include <stddef.h>
#include <inttypes.h>
#include <assert.h>
#include <stdbool.h>
#include "nvim/types.h"
#include "nvim/mbyte.h"
#include "nvim/ascii.h"
const uint8_t utf8len_tab_zero[] = {
//1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 8 9 A B C D E F
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 2
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 4
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 6
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 8
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // A
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // C
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,0,0, // E
};
const uint8_t utf8len_tab[] = {
// ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?A ?B ?C ?D ?E ?F
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0?
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 1?
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2?
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 3?
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 4?
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 5?
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6?
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7?
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 8?
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 9?
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A?
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B?
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C?
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // D?
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // E?
4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 1, 1, // F?
};
int utf_ptr2char(const char_u *const p)
{
if (p[0] < 0x80) { // Be quick for ASCII.
return p[0];
}
const uint8_t len = utf8len_tab_zero[p[0]];
if (len > 1 && (p[1] & 0xc0) == 0x80) {
if (len == 2) {
return ((p[0] & 0x1f) << 6) + (p[1] & 0x3f);
}
if ((p[2] & 0xc0) == 0x80) {
if (len == 3) {
return (((p[0] & 0x0f) << 12) + ((p[1] & 0x3f) << 6)
+ (p[2] & 0x3f));
}
if ((p[3] & 0xc0) == 0x80) {
if (len == 4) {
return (((p[0] & 0x07) << 18) + ((p[1] & 0x3f) << 12)
+ ((p[2] & 0x3f) << 6) + (p[3] & 0x3f));
}
if ((p[4] & 0xc0) == 0x80) {
if (len == 5) {
return (((p[0] & 0x03) << 24) + ((p[1] & 0x3f) << 18)
+ ((p[2] & 0x3f) << 12) + ((p[3] & 0x3f) << 6)
+ (p[4] & 0x3f));
}
if ((p[5] & 0xc0) == 0x80 && len == 6) {
return (((p[0] & 0x01) << 30) + ((p[1] & 0x3f) << 24)
+ ((p[2] & 0x3f) << 18) + ((p[3] & 0x3f) << 12)
+ ((p[4] & 0x3f) << 6) + (p[5] & 0x3f));
}
}
}
}
}
// Illegal value: just return the first byte.
return p[0];
}
bool utf_composinglike(const char_u *p1, const char_u *p2)
{
return false;
}
char_u *string_convert(const vimconv_T *conv, char_u *data, size_t *size)
{
return NULL;
}
int utf_ptr2len_len(const char_u *p, int size)
{
int len;
int i;
int m;
len = utf8len_tab[*p];
if (len == 1)
return 1; /* NUL, ascii or illegal lead byte */
if (len > size)
m = size; /* incomplete byte sequence. */
else
m = len;
for (i = 1; i < m; ++i)
if ((p[i] & 0xc0) != 0x80)
return 1;
return len;
}
int utfc_ptr2len_len(const char_u *p, int size)
{
int len;
int prevlen;
if (size < 1 || *p == NUL)
return 0;
if (p[0] < 0x80 && (size == 1 || p[1] < 0x80)) /* be quick for ASCII */
return 1;
/* Skip over first UTF-8 char, stopping at a NUL byte. */
len = utf_ptr2len_len(p, size);
/* Check for illegal byte and incomplete byte sequence. */
if ((len == 1 && p[0] >= 0x80) || len > size)
return 1;
/*
* Check for composing characters. We can handle only the first six, but
* skip all of them (otherwise the cursor would get stuck).
*/
prevlen = 0;
while (len < size) {
int len_next_char;
if (p[len] < 0x80)
break;
/*
* Next character length should not go beyond size to ensure that
* UTF_COMPOSINGLIKE(...) does not read beyond size.
*/
len_next_char = utf_ptr2len_len(p + len, size - len);
if (len_next_char > size - len)
break;
if (!UTF_COMPOSINGLIKE(p + prevlen, p + len))
break;
/* Skip over composing char */
prevlen = len;
len += len_next_char;
}
return len;
}
int utf_char2len(const int c)
{
if (c < 0x80) {
return 1;
} else if (c < 0x800) {
return 2;
} else if (c < 0x10000) {
return 3;
} else if (c < 0x200000) {
return 4;
} else if (c < 0x4000000) {
return 5;
} else {
return 6;
}
}
int utf_char2bytes(const int c, char_u *const buf)
{
if (c < 0x80) { // 7 bits
buf[0] = c;
return 1;
} else if (c < 0x800) { // 11 bits
buf[0] = 0xc0 + ((unsigned)c >> 6);
buf[1] = 0x80 + (c & 0x3f);
return 2;
} else if (c < 0x10000) { // 16 bits
buf[0] = 0xe0 + ((unsigned)c >> 12);
buf[1] = 0x80 + (((unsigned)c >> 6) & 0x3f);
buf[2] = 0x80 + (c & 0x3f);
return 3;
} else if (c < 0x200000) { // 21 bits
buf[0] = 0xf0 + ((unsigned)c >> 18);
buf[1] = 0x80 + (((unsigned)c >> 12) & 0x3f);
buf[2] = 0x80 + (((unsigned)c >> 6) & 0x3f);
buf[3] = 0x80 + (c & 0x3f);
return 4;
} else if (c < 0x4000000) { // 26 bits
buf[0] = 0xf8 + ((unsigned)c >> 24);
buf[1] = 0x80 + (((unsigned)c >> 18) & 0x3f);
buf[2] = 0x80 + (((unsigned)c >> 12) & 0x3f);
buf[3] = 0x80 + (((unsigned)c >> 6) & 0x3f);
buf[4] = 0x80 + (c & 0x3f);
return 5;
} else { // 31 bits
buf[0] = 0xfc + ((unsigned)c >> 30);
buf[1] = 0x80 + (((unsigned)c >> 24) & 0x3f);
buf[2] = 0x80 + (((unsigned)c >> 18) & 0x3f);
buf[3] = 0x80 + (((unsigned)c >> 12) & 0x3f);
buf[4] = 0x80 + (((unsigned)c >> 6) & 0x3f);
buf[5] = 0x80 + (c & 0x3f);
return 6;
}
}
int utf_ptr2len(const char_u *const p)
{
if (*p == NUL) {
return 0;
}
const int len = utf8len_tab[*p];
for (int i = 1; i < len; i++) {
if ((p[i] & 0xc0) != 0x80) {
return 1;
}
}
return len;
}
int utfc_ptr2len(const char_u *const p)
{
uint8_t b0 = (uint8_t)(*p);
if (b0 == NUL) {
return 0;
}
if (b0 < 0x80 && p[1] < 0x80) { // be quick for ASCII
return 1;
}
// Skip over first UTF-8 char, stopping at a NUL byte.
int len = utf_ptr2len(p);
// Check for illegal byte.
if (len == 1 && b0 >= 0x80) {
return 1;
}
// Check for composing characters. We can handle only the first six, but
// skip all of them (otherwise the cursor would get stuck).
int prevlen = 0;
for (;;) {
if (p[len] < 0x80 || !UTF_COMPOSINGLIKE(p + prevlen, p + len)) {
return len;
}
// Skip over composing char.
prevlen = len;
len += utf_ptr2len(p + len);
}
}
void mb_copy_char(const char_u **fp, char_u **tp)
{
const size_t l = utfc_ptr2len(*fp);
memmove(*tp, *fp, (size_t)l);
*tp += l;
*fp += l;
}

View File

@@ -1,101 +0,0 @@
#include <stdlib.h>
#include <assert.h>
#include "nvim/lib/ringbuf.h"
enum { RB_SIZE = 1024 };
typedef struct {
void *ptr;
size_t size;
} AllocRecord;
RINGBUF_TYPEDEF(AllocRecords, AllocRecord)
RINGBUF_INIT(AllocRecords, arecs, AllocRecord, RINGBUF_DUMMY_FREE)
RINGBUF_STATIC(static, AllocRecords, AllocRecord, arecs, RB_SIZE)
size_t allocated_memory = 0;
size_t ever_allocated_memory = 0;
size_t allocated_memory_limit = SIZE_MAX;
void *xmalloc(const size_t size)
{
void *ret = malloc(size);
allocated_memory += size;
ever_allocated_memory += size;
assert(allocated_memory <= allocated_memory_limit);
assert(arecs_rb_length(&arecs) < RB_SIZE);
arecs_rb_push(&arecs, (AllocRecord) {
.ptr = ret,
.size = size,
});
return ret;
}
void xfree(void *const p)
{
if (p == NULL) {
return;
}
RINGBUF_FORALL(&arecs, AllocRecord, arec) {
if (arec->ptr == p) {
allocated_memory -= arec->size;
arecs_rb_remove(&arecs, arecs_rb_find_idx(&arecs, arec));
return;
}
}
abort();
}
void *xrealloc(void *const p, size_t new_size)
{
void *ret = realloc(p, new_size);
RINGBUF_FORALL(&arecs, AllocRecord, arec) {
if (arec->ptr == p) {
allocated_memory -= arec->size;
allocated_memory += new_size;
if (new_size > arec->size) {
ever_allocated_memory += (new_size - arec->size);
}
arec->ptr = ret;
arec->size = new_size;
return ret;
}
}
abort();
return (void *)(intptr_t)1;
}
char *xstrdup(const char *str)
FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET
FUNC_ATTR_NONNULL_ALL
{
return xmemdupz(str, strlen(str));
}
void *xmallocz(size_t size)
FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT
{
size_t total_size = size + 1;
assert(total_size > size);
void *ret = xmalloc(total_size);
((char *)ret)[size] = 0;
return ret;
}
char *xstpcpy(char *restrict dst, const char *restrict src)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
const size_t len = strlen(src);
return (char *)memcpy(dst, src, len + 1) + len;
}
void *xmemdupz(const void *data, size_t len)
FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT
FUNC_ATTR_NONNULL_ALL
{
return memcpy(xmallocz(len), data, len);
}

View File

@@ -1,101 +0,0 @@
#!/bin/sh
set -e
set -x
test -z "$POSH_VERSION" && set -u
PROJECT_SOURCE_DIR=.
PROJECT_BINARY_DIR="$PROJECT_SOURCE_DIR/build"
KLEE_TEST_DIR="$PROJECT_SOURCE_DIR/test/symbolic/klee"
KLEE_BIN_DIR="$PROJECT_BINARY_DIR/klee"
KLEE_OUT_DIR="$KLEE_BIN_DIR/out"
help() {
echo "Usage:"
echo
echo " $0 -c fname"
echo " $0 fname"
echo " $0 -s"
echo
echo "First form compiles executable out of test/symbolic/klee/{fname}.c."
echo "Compiled executable is placed into build/klee/{fname}. Must first"
echo "successfully compile Neovim in order to generate declarations."
echo
echo "Second form runs KLEE in a docker container using file "
echo "test/symbolic/klee/{fname.c}. Bitcode is placed into build/klee/a.bc,"
echo "results are placed into build/klee/out/. The latter is first deleted if"
echo "it exists."
echo
echo "Third form runs ktest-tool which prints errors found by KLEE via "
echo "the same container used to run KLEE."
}
main() {
local compile=
local print_errs=
if test "$1" = "--help" ; then
help
return
fi
if test "$1" = "-s" ; then
print_errs=1
shift
elif test "$1" = "-c" ; then
compile=1
shift
fi
if test -z "$print_errs" ; then
local test="$1" ; shift
fi
local includes=
includes="$includes -I$KLEE_TEST_DIR"
includes="$includes -I/home/klee/klee_src/include"
includes="$includes -I$PROJECT_SOURCE_DIR/src"
includes="$includes -I$PROJECT_BINARY_DIR/src/nvim/auto"
includes="$includes -I$PROJECT_BINARY_DIR/include"
includes="$includes -I$PROJECT_BINARY_DIR/cmake.config"
includes="$includes -I/host-includes"
local defines=
defines="$defines -DINCLUDE_GENERATED_DECLARATIONS"
test -z "$compile" && defines="$defines -DUSE_KLEE"
test -d "$KLEE_BIN_DIR" || mkdir -p "$KLEE_BIN_DIR"
if test -z "$compile" ; then
local line1='cd /image'
if test -z "$print_errs" ; then
test -d "$KLEE_OUT_DIR" && rm -r "$KLEE_OUT_DIR"
line1="$line1 && $(echo clang \
$includes $defines \
-o "$KLEE_BIN_DIR/a.bc" -emit-llvm -g -c \
"$KLEE_TEST_DIR/$test.c")"
line1="$line1 && klee --libc=uclibc --posix-runtime "
line1="$line1 '--output-dir=$KLEE_OUT_DIR' '$KLEE_BIN_DIR/a.bc'"
fi
local line2="for t in '$KLEE_OUT_DIR'/*.err"
line2="$line2 ; do ktest-tool --write-ints"
line2="$line2 \"\$(printf '%s' \"\$t\" | sed -e 's@\\.[^/]*\$@.ktest@')\""
line2="$line2 ; done"
printf '%s\n%s\n' "$line1" "$line2" | \
docker run \
--volume "$(cd "$PROJECT_SOURCE_DIR" && pwd)":/image \
--volume "/usr/include":/host-includes \
--interactive \
--rm \
--ulimit='stack=-1:-1' \
klee/klee \
/bin/sh -x
else
clang \
$includes $defines \
-o "$KLEE_BIN_DIR/$test" \
-O0 -g \
"$KLEE_TEST_DIR/$test.c"
fi
}
main "$@"

View File

@@ -1,105 +0,0 @@
#ifdef USE_KLEE
# include <klee/klee.h>
#else
# include <string.h>
# include <stdio.h>
#endif
#include <stddef.h>
#include <stdint.h>
#include <assert.h>
#include "nvim/viml/parser/expressions.h"
#include "nvim/viml/parser/parser.h"
#include "nvim/mbyte.h"
#include "nvim/memory.c"
#include "nvim/mbyte.c"
#include "nvim/charset.c"
#include "nvim/garray.c"
#include "nvim/gettext.c"
#include "nvim/keycodes.c"
#include "nvim/viml/parser/expressions.c"
#define INPUT_SIZE 7
uint8_t avoid_optimizing_out;
void simple_get_line(void *cookie, ParserLine *ret_pline)
{
ParserLine **plines_p = (ParserLine **)cookie;
*ret_pline = **plines_p;
(*plines_p)++;
}
int main(const int argc, const char *const *const argv,
const char *const *const environ)
{
char input[INPUT_SIZE];
uint8_t shift;
int flags;
avoid_optimizing_out = argc;
#ifndef USE_KLEE
sscanf(argv[2], "%d", &flags);
#endif
#ifdef USE_KLEE
klee_make_symbolic(input, sizeof(input), "input");
klee_make_symbolic(&shift, sizeof(shift), "shift");
klee_make_symbolic(&flags, sizeof(flags), "flags");
klee_assume(shift < INPUT_SIZE);
klee_assume(flags <= (kELFlagPeek|kELFlagAllowFloat|kELFlagForbidEOC
|kELFlagForbidScope|kELFlagIsNotCmp));
#endif
ParserLine plines[] = {
{
#ifdef USE_KLEE
.data = &input[shift],
.size = sizeof(input) - shift,
#else
.data = (const char *)argv[1],
.size = strlen(argv[1]),
#endif
.allocated = false,
},
{
.data = NULL,
.size = 0,
.allocated = false,
},
};
#ifdef USE_KLEE
assert(plines[0].size <= INPUT_SIZE);
assert((plines[0].data[0] != 5) | (plines[0].data[0] != argc));
#endif
ParserLine *cur_pline = &plines[0];
ParserState pstate = {
.reader = {
.get_line = simple_get_line,
.cookie = &cur_pline,
.lines = KV_INITIAL_VALUE,
.conv.vc_type = CONV_NONE,
},
.pos = { 0, 0 },
.colors = NULL,
.can_continuate = false,
};
kvi_init(pstate.reader.lines);
allocated_memory_limit = 0;
LexExprToken token = viml_pexpr_next_token(&pstate, flags);
if (flags & kELFlagPeek) {
assert(pstate.pos.line == 0 && pstate.pos.col == 0);
} else {
assert((pstate.pos.line == 0)
? (pstate.pos.col > 0)
: (pstate.pos.line == 1 && pstate.pos.col == 0));
}
assert(allocated_memory == 0);
assert(ever_allocated_memory == 0);
#ifndef USE_KLEE
fprintf(stderr, "tkn: %s\n", viml_pexpr_repr_token(&pstate, token, NULL));
#endif
}

View File

@@ -1,117 +0,0 @@
#ifdef USE_KLEE
# include <klee/klee.h>
#else
# include <string.h>
#endif
#include <stddef.h>
#include <stdint.h>
#include <assert.h>
#include "nvim/viml/parser/expressions.h"
#include "nvim/viml/parser/parser.h"
#include "nvim/mbyte.h"
#include "nvim/memory.c"
#include "nvim/mbyte.c"
#include "nvim/charset.c"
#include "nvim/garray.c"
#include "nvim/gettext.c"
#include "nvim/viml/parser/expressions.c"
#include "nvim/keycodes.c"
#define INPUT_SIZE 50
uint8_t avoid_optimizing_out;
void simple_get_line(void *cookie, ParserLine *ret_pline)
{
ParserLine **plines_p = (ParserLine **)cookie;
*ret_pline = **plines_p;
(*plines_p)++;
}
int main(const int argc, const char *const *const argv,
const char *const *const environ)
{
char input[INPUT_SIZE];
uint8_t shift;
unsigned flags;
const bool peek = false;
avoid_optimizing_out = argc;
#ifndef USE_KLEE
sscanf(argv[2], "%d", &flags);
#endif
#ifdef USE_KLEE
klee_make_symbolic(input, sizeof(input), "input");
klee_make_symbolic(&shift, sizeof(shift), "shift");
klee_make_symbolic(&flags, sizeof(flags), "flags");
klee_assume(shift < INPUT_SIZE);
klee_assume(
flags <= (kExprFlagsMulti|kExprFlagsDisallowEOC|kExprFlagsParseLet));
#endif
ParserLine plines[] = {
{
#ifdef USE_KLEE
.data = &input[shift],
.size = sizeof(input) - shift,
#else
.data = argv[1],
.size = strlen(argv[1]),
#endif
.allocated = false,
},
{
.data = NULL,
.size = 0,
.allocated = false,
},
};
#ifdef USE_KLEE
assert(plines[0].size <= INPUT_SIZE);
assert((plines[0].data[0] != 5) | (plines[0].data[0] != argc));
#endif
ParserLine *cur_pline = &plines[0];
ParserHighlight colors;
kvi_init(colors);
ParserState pstate = {
.reader = {
.get_line = simple_get_line,
.cookie = &cur_pline,
.lines = KV_INITIAL_VALUE,
.conv.vc_type = CONV_NONE,
},
.pos = { 0, 0 },
.colors = &colors,
.can_continuate = false,
};
kvi_init(pstate.reader.lines);
const ExprAST ast = viml_pexpr_parse(&pstate, (int)flags);
assert(ast.root != NULL || ast.err.msg);
if (flags & kExprFlagsParseLet) {
assert(ast.err.msg != NULL
|| ast.root->type == kExprNodeAssignment
|| (ast.root->type == kExprNodeListLiteral
&& ast.root->children != NULL)
|| ast.root->type == kExprNodeComplexIdentifier
|| ast.root->type == kExprNodeCurlyBracesIdentifier
|| ast.root->type == kExprNodePlainIdentifier
|| ast.root->type == kExprNodeRegister
|| ast.root->type == kExprNodeEnvironment
|| ast.root->type == kExprNodeOption
|| ast.root->type == kExprNodeSubscript
|| ast.root->type == kExprNodeConcatOrSubscript);
}
// Cant possibly have more highlight tokens then there are bytes in string.
assert(kv_size(colors) <= INPUT_SIZE - shift);
kvi_destroy(colors);
// Not destroying pstate.reader.lines because there is no way it could exceed
// its limits in the current circumstances.
viml_pexpr_free_ast(ast);
assert(allocated_memory == 0);
}

View File

@@ -349,7 +349,7 @@ local special_vals = nil
lua2typvalt = function(l, processed) lua2typvalt = function(l, processed)
if not special_vals then if not special_vals then
special_vals = { special_vals = {
[null_string] = {'VAR_STRING', {v_string=ffi.cast('char_u*', nil)}}, [null_string] = {'VAR_STRING', {v_string=ffi.cast('char*', nil)}},
[null_list] = {'VAR_LIST', {v_list=ffi.cast('list_T*', nil)}}, [null_list] = {'VAR_LIST', {v_list=ffi.cast('list_T*', nil)}},
[null_dict] = {'VAR_DICT', {v_dict=ffi.cast('dict_T*', nil)}}, [null_dict] = {'VAR_DICT', {v_dict=ffi.cast('dict_T*', nil)}},
[nil_value] = {'VAR_SPECIAL', {v_special=eval.kSpecialVarNull}}, [nil_value] = {'VAR_SPECIAL', {v_special=eval.kSpecialVarNull}},

View File

@@ -12,7 +12,7 @@ describe('trunc_string', function()
local buflen = 40 local buflen = 40
local function test_inplace(s, expected, room) local function test_inplace(s, expected, room)
room = room and room or 20 room = room and room or 20
local buf = cimp.xmalloc(ffi.sizeof('char_u') * buflen) local buf = cimp.xmalloc(ffi.sizeof('char') * buflen)
ffi.C.strcpy(buf, s) ffi.C.strcpy(buf, s)
cimp.trunc_string(buf, buf, room, buflen) cimp.trunc_string(buf, buf, room, buflen)
eq(expected, ffi.string(buf)) eq(expected, ffi.string(buf))
@@ -21,7 +21,7 @@ describe('trunc_string', function()
local function test_copy(s, expected, room) local function test_copy(s, expected, room)
room = room and room or 20 room = room and room or 20
local buf = cimp.xmalloc(ffi.sizeof('char_u') * buflen) local buf = cimp.xmalloc(ffi.sizeof('char') * buflen)
local str = cimp.xstrdup(to_cstr(s)) local str = cimp.xstrdup(to_cstr(s))
cimp.trunc_string(str, buf, room, buflen) cimp.trunc_string(str, buf, room, buflen)
eq(expected, ffi.string(buf)) eq(expected, ffi.string(buf))

View File

@@ -37,7 +37,7 @@ child_call_once(function()
-- requires refactor of UNDO_HASH_SIZE into constant/enum for ffi -- requires refactor of UNDO_HASH_SIZE into constant/enum for ffi
-- --
-- compute a hash for this undofile -- compute a hash for this undofile
buffer_hash = ffi.new('char_u[32]') buffer_hash = ffi.new('char[32]')
undo.u_compute_hash(file_buffer, buffer_hash) undo.u_compute_hash(file_buffer, buffer_hash)
end) end)