diff options
| author | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2023-04-02 10:11:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-02 16:11:42 +0800 |
| commit | d510bfbc8e447b1a60d5ec7faaa8f440eb4ef56f (patch) | |
| tree | cfe7dd74ad588e935ea7613fc91c99b819aa99ad /test | |
| parent | 9084948893f9c1669ab56061c8d04adabbb6c3cf (diff) | |
| download | rneovim-d510bfbc8e447b1a60d5ec7faaa8f440eb4ef56f.tar.gz rneovim-d510bfbc8e447b1a60d5ec7faaa8f440eb4ef56f.tar.bz2 rneovim-d510bfbc8e447b1a60d5ec7faaa8f440eb4ef56f.zip | |
refactor: remove char_u (#22829)
Closes https://github.com/neovim/neovim/issues/459
Diffstat (limited to 'test')
| -rw-r--r-- | test/functional/lua/ffi_spec.lua | 1 | ||||
| -rw-r--r-- | test/functional/treesitter/highlight_spec.lua | 14 | ||||
| -rw-r--r-- | test/functional/treesitter/parser_spec.lua | 32 | ||||
| -rw-r--r-- | test/symbolic/klee/nvim/charset.c | 172 | ||||
| -rw-r--r-- | test/symbolic/klee/nvim/garray.c | 195 | ||||
| -rw-r--r-- | test/symbolic/klee/nvim/gettext.c | 4 | ||||
| -rw-r--r-- | test/symbolic/klee/nvim/keymap.c | 559 | ||||
| -rw-r--r-- | test/symbolic/klee/nvim/mbyte.c | 266 | ||||
| -rw-r--r-- | test/symbolic/klee/nvim/memory.c | 101 | ||||
| -rwxr-xr-x | test/symbolic/klee/run.sh | 101 | ||||
| -rw-r--r-- | test/symbolic/klee/viml_expressions_lexer.c | 105 | ||||
| -rw-r--r-- | test/symbolic/klee/viml_expressions_parser.c | 117 | ||||
| -rw-r--r-- | test/unit/eval/helpers.lua | 2 | ||||
| -rw-r--r-- | test/unit/message_spec.lua | 4 | ||||
| -rw-r--r-- | test/unit/undo_spec.lua | 2 |
15 files changed, 27 insertions, 1648 deletions
diff --git a/test/functional/lua/ffi_spec.lua b/test/functional/lua/ffi_spec.lua index c492c1e765..3a37b18cd1 100644 --- a/test/functional/lua/ffi_spec.lua +++ b/test/functional/lua/ffi_spec.lua @@ -25,7 +25,6 @@ describe('ffi.cdef', function() local ffi = require('ffi') ffi.cdef[[ - typedef unsigned char char_u; typedef struct window_S win_T; typedef struct {} stl_hlrec_t; typedef struct {} StlClickRecord; diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index faeb4befcd..4e1efec404 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -413,7 +413,7 @@ describe('treesitter highlighting', function() it("supports injected languages", function() insert([[ 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() { \ return 42; \ } @@ -421,7 +421,7 @@ describe('treesitter highlighting', function() screen:expect{grid=[[ 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() { \ | return 42; \ | } | @@ -450,7 +450,7 @@ describe('treesitter highlighting', function() screen:expect{grid=[[ {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() { \ | {4:return} {5:42}; \ | } | @@ -473,7 +473,7 @@ describe('treesitter highlighting', function() it("supports overriding queries, like ", function() insert([[ 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() { \ return 42; \ } @@ -489,7 +489,7 @@ describe('treesitter highlighting', function() screen:expect{grid=[[ {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() { \ | {4:return} {5:42}; \ | } | @@ -567,7 +567,7 @@ describe('treesitter highlighting', function() it("supports highlighting with priority", function() insert([[ 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() { \ return 42; \ } @@ -580,7 +580,7 @@ describe('treesitter highlighting', function() -- expect everything to have Constant highlight screen:expect{grid=[[ {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: return 42; \} | {8: }} | diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua index 72a8cd9e9b..ea9958b12a 100644 --- a/test/functional/treesitter/parser_spec.lua +++ b/test/functional/treesitter/parser_spec.lua @@ -627,8 +627,8 @@ end]] before_each(function() insert([[ int x = INT_MAX; -#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) -#define READ_STRING_OK(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 *)read_string((x), (size_t)(y)) #define VALUE 123 #define VALUE1 123 #define VALUE2 123 @@ -650,8 +650,8 @@ int x = INT_MAX; {3, 14, 3, 17}, -- VALUE 123 {4, 15, 4, 18}, -- VALUE1 123 {5, 15, 5, 18}, -- VALUE2 123 - {1, 26, 1, 65}, -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) - {2, 29, 2, 68} -- READ_STRING_OK(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, 66} -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y)) }, get_ranges()) helpers.feed('ggo<esc>') @@ -661,8 +661,8 @@ int x = INT_MAX; {4, 14, 4, 17}, -- VALUE 123 {5, 15, 5, 18}, -- VALUE1 123 {6, 15, 6, 18}, -- VALUE2 123 - {2, 26, 2, 65}, -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) - {3, 29, 3, 68} -- READ_STRING_OK(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, 66} -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y)) }, get_ranges()) end) end) @@ -682,8 +682,8 @@ int x = INT_MAX; {3, 14, 5, 18}, -- VALUE 123 -- VALUE1 123 -- VALUE2 123 - {1, 26, 2, 68} -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) - -- READ_STRING_OK(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 *)read_string((x), (size_t)(y)) }, get_ranges()) helpers.feed('ggo<esc>') @@ -694,8 +694,8 @@ int x = INT_MAX; {4, 14, 6, 18}, -- VALUE 123 -- VALUE1 123 -- VALUE2 123 - {2, 26, 3, 68} -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) - -- READ_STRING_OK(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 *)read_string((x), (size_t)(y)) }, get_ranges()) end) end) @@ -722,8 +722,8 @@ int x = INT_MAX; {3, 14, 5, 18}, -- VALUE 123 -- VALUE1 123 -- VALUE2 123 - {1, 26, 2, 68} -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) - -- READ_STRING_OK(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 *)read_string((x), (size_t)(y)) }, get_ranges()) helpers.feed('ggo<esc>') @@ -734,8 +734,8 @@ int x = INT_MAX; {4, 14, 6, 18}, -- VALUE 123 -- VALUE1 123 -- VALUE2 123 - {2, 26, 3, 68} -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) - -- READ_STRING_OK(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 *)read_string((x), (size_t)(y)) }, get_ranges()) end) @@ -768,8 +768,8 @@ int x = INT_MAX; {3, 15, 3, 16}, -- VALUE 123 {4, 16, 4, 17}, -- VALUE1 123 {5, 16, 5, 17}, -- VALUE2 123 - {1, 26, 1, 65}, -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) - {2, 29, 2, 68} -- READ_STRING_OK(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, 66} -- READ_STRING_OK(x, y) (char *)read_string((x), (size_t)(y)) }, get_ranges()) end) it("should list all directives", function() diff --git a/test/symbolic/klee/nvim/charset.c b/test/symbolic/klee/nvim/charset.c deleted file mode 100644 index fd1c5ee4b9..0000000000 --- a/test/symbolic/klee/nvim/charset.c +++ /dev/null @@ -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(); // Should’ve 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 -} diff --git a/test/symbolic/klee/nvim/garray.c b/test/symbolic/klee/nvim/garray.c deleted file mode 100644 index 260870c3c2..0000000000 --- a/test/symbolic/klee/nvim/garray.c +++ /dev/null @@ -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); -} - diff --git a/test/symbolic/klee/nvim/gettext.c b/test/symbolic/klee/nvim/gettext.c deleted file mode 100644 index b9cc98d770..0000000000 --- a/test/symbolic/klee/nvim/gettext.c +++ /dev/null @@ -1,4 +0,0 @@ -char *gettext(const char *s) -{ - return (char *)s; -} diff --git a/test/symbolic/klee/nvim/keymap.c b/test/symbolic/klee/nvim/keymap.c deleted file mode 100644 index 1f7f0e0911..0000000000 --- a/test/symbolic/klee/nvim/keymap.c +++ /dev/null @@ -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; |