refactor: remove some (const char **) casts (#24423)

This commit is contained in:
zeertzjq 2023-07-22 18:00:55 +08:00 committed by GitHub
parent 4b57ff77fe
commit d2efcbf2dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 51 additions and 52 deletions

View File

@ -2879,10 +2879,10 @@ bool checkforcmd(char **pp, const char *cmd, int len)
/// Append "cmd" to the error message in IObuff. /// Append "cmd" to the error message in IObuff.
/// Takes care of limiting the length and handling 0xa0, which would be /// Takes care of limiting the length and handling 0xa0, which would be
/// invisible otherwise. /// invisible otherwise.
static void append_command(char *cmd) static void append_command(const char *cmd)
{ {
size_t len = strlen(IObuff); size_t len = strlen(IObuff);
char *s = cmd; const char *s = cmd;
char *d; char *d;
if (len > IOSIZE - 100) { if (len > IOSIZE - 100) {
@ -2901,7 +2901,7 @@ static void append_command(char *cmd)
} else if (d - IObuff + utfc_ptr2len(s) + 1 >= IOSIZE) { } else if (d - IObuff + utfc_ptr2len(s) + 1 >= IOSIZE) {
break; break;
} else { } else {
mb_copy_char((const char **)&s, &d); mb_copy_char(&s, &d);
} }
} }
*d = NUL; *d = NUL;

View File

@ -3530,7 +3530,7 @@ void unputcmdline(void)
// part will be redrawn, otherwise it will not. If this function is called // part will be redrawn, otherwise it will not. If this function is called
// twice in a row, then 'redraw' should be false and redrawcmd() should be // twice in a row, then 'redraw' should be false and redrawcmd() should be
// called afterwards. // called afterwards.
void put_on_cmdline(char *str, int len, int redraw) void put_on_cmdline(const char *str, int len, int redraw)
{ {
int i; int i;
int m; int m;
@ -3740,7 +3740,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr)
// When "literally" is true, insert literally. // When "literally" is true, insert literally.
// When "literally" is false, insert as typed, but don't leave the command // When "literally" is false, insert as typed, but don't leave the command
// line. // line.
void cmdline_paste_str(char *s, int literally) void cmdline_paste_str(const char *s, int literally)
{ {
if (literally) { if (literally) {
put_on_cmdline(s, -1, true); put_on_cmdline(s, -1, true);
@ -3750,7 +3750,7 @@ void cmdline_paste_str(char *s, int literally)
if (cv == Ctrl_V && s[1]) { if (cv == Ctrl_V && s[1]) {
s++; s++;
} }
int c = mb_cptr2char_adv((const char **)&s); int c = mb_cptr2char_adv(&s);
if (cv == Ctrl_V || c == ESC || c == Ctrl_C if (cv == Ctrl_V || c == ESC || c == Ctrl_C
|| c == CAR || c == NL || c == Ctrl_L || c == CAR || c == NL || c == Ctrl_L
|| (c == Ctrl_BSL && *s == Ctrl_N)) { || (c == Ctrl_BSL && *s == Ctrl_N)) {

View File

@ -242,8 +242,8 @@ bool os_isatty(int fd)
size_t input_enqueue(String keys) size_t input_enqueue(String keys)
{ {
char *ptr = keys.data; const char *ptr = keys.data;
char *end = ptr + keys.size; const char *end = ptr + keys.size;
while (rbuffer_space(input_buffer) >= 19 && ptr < end) { while (rbuffer_space(input_buffer) >= 19 && ptr < end) {
// A "<x>" form occupies at least 1 characters, and produces up // A "<x>" form occupies at least 1 characters, and produces up
@ -254,8 +254,7 @@ size_t input_enqueue(String keys)
uint8_t buf[19] = { 0 }; uint8_t buf[19] = { 0 };
// Do not simplify the keys here. Simplification will be done later. // Do not simplify the keys here. Simplification will be done later.
unsigned new_size unsigned new_size
= trans_special((const char **)&ptr, (size_t)(end - ptr), (char *)buf, FSK_KEYCODE, true, = trans_special(&ptr, (size_t)(end - ptr), (char *)buf, FSK_KEYCODE, true, NULL);
NULL);
if (new_size) { if (new_size) {
new_size = handle_mouse_event(&ptr, buf, new_size); new_size = handle_mouse_event(&ptr, buf, new_size);
@ -264,7 +263,7 @@ size_t input_enqueue(String keys)
} }
if (*ptr == '<') { if (*ptr == '<') {
char *old_ptr = ptr; const char *old_ptr = ptr;
// Invalid or incomplete key sequence, skip until the next '>' or *end. // Invalid or incomplete key sequence, skip until the next '>' or *end.
do { do {
ptr++; ptr++;
@ -346,7 +345,7 @@ static uint8_t check_multiclick(int code, int grid, int row, int col)
// Mouse event handling code(Extract row/col if available and detect multiple // Mouse event handling code(Extract row/col if available and detect multiple
// clicks) // clicks)
static unsigned handle_mouse_event(char **ptr, uint8_t *buf, unsigned bufsize) static unsigned handle_mouse_event(const char **ptr, uint8_t *buf, unsigned bufsize)
{ {
int mouse_code = 0; int mouse_code = 0;
int type = 0; int type = 0;

View File

@ -1412,7 +1412,7 @@ static int cstrncmp(char *s1, char *s2, int *n)
// if it failed and it's utf8 and we want to combineignore: // if it failed and it's utf8 and we want to combineignore:
if (result != 0 && rex.reg_icombine) { if (result != 0 && rex.reg_icombine) {
char *str1, *str2; const char *str1, *str2;
int c1, c2, c11, c12; int c1, c2, c11, c12;
int junk; int junk;
@ -1422,8 +1422,8 @@ static int cstrncmp(char *s1, char *s2, int *n)
str2 = s2; str2 = s2;
c1 = c2 = 0; c1 = c2 = 0;
while ((int)(str1 - s1) < *n) { while ((int)(str1 - s1) < *n) {
c1 = mb_ptr2char_adv((const char **)&str1); c1 = mb_ptr2char_adv(&str1);
c2 = mb_ptr2char_adv((const char **)&str2); c2 = mb_ptr2char_adv(&str2);
// decompose the character if necessary, into 'base' characters // decompose the character if necessary, into 'base' characters
// because I don't care about Arabic, I will hard-code the Hebrew // because I don't care about Arabic, I will hard-code the Hebrew

View File

@ -2238,10 +2238,10 @@ static int find_region(const char *rp, const char *region)
/// @param[in] end End of word or NULL for NUL delimited string /// @param[in] end End of word or NULL for NUL delimited string
/// ///
/// @returns Case type of word /// @returns Case type of word
int captype(char *word, const char *end) int captype(const char *word, const char *end)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(1)
{ {
char *p; const char *p;
// find first letter // find first letter
for (p = word; !spell_iswordp_nmw(p, curwin); MB_PTR_ADV(p)) { for (p = word; !spell_iswordp_nmw(p, curwin); MB_PTR_ADV(p)) {
@ -2249,7 +2249,7 @@ int captype(char *word, const char *end)
return 0; // only non-word characters, illegal word return 0; // only non-word characters, illegal word
} }
} }
int c = mb_ptr2char_adv((const char **)&p); int c = mb_ptr2char_adv(&p);
bool allcap; bool allcap;
bool firstcap = allcap = SPELL_ISUPPER(c); bool firstcap = allcap = SPELL_ISUPPER(c);
bool past_second = false; // past second word char bool past_second = false; // past second word char
@ -2503,7 +2503,7 @@ static bool spell_iswordp_w(const int *p, const win_T *wp)
// Uses the character definitions from the .spl file. // Uses the character definitions from the .spl file.
// When using a multi-byte 'encoding' the length may change! // When using a multi-byte 'encoding' the length may change!
// Returns FAIL when something wrong. // Returns FAIL when something wrong.
int spell_casefold(const win_T *wp, char *str, int len, char *buf, int buflen) int spell_casefold(const win_T *wp, const char *str, int len, char *buf, int buflen)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
if (len >= buflen) { if (len >= buflen) {
@ -2514,12 +2514,12 @@ int spell_casefold(const win_T *wp, char *str, int len, char *buf, int buflen)
int outi = 0; int outi = 0;
// Fold one character at a time. // Fold one character at a time.
for (char *p = str; p < str + len;) { for (const char *p = str; p < str + len;) {
if (outi + MB_MAXBYTES > buflen) { if (outi + MB_MAXBYTES > buflen) {
buf[outi] = NUL; buf[outi] = NUL;
return FAIL; return FAIL;
} }
int c = mb_cptr2char_adv((const char **)&p); int c = mb_cptr2char_adv(&p);
// Exception: greek capital sigma 0x03A3 folds to 0x03C3, except // Exception: greek capital sigma 0x03A3 folds to 0x03C3, except
// when it is the last character in a word, then it folds to // when it is the last character in a word, then it folds to
@ -2668,10 +2668,10 @@ void ex_spellrepall(exarg_T *eap)
/// @param[in] word source string to copy /// @param[in] word source string to copy
/// @param[in,out] wcopy copied string, with case of first letter changed /// @param[in,out] wcopy copied string, with case of first letter changed
/// @param[in] upper True to upper case, otherwise lower case /// @param[in] upper True to upper case, otherwise lower case
void onecap_copy(char *word, char *wcopy, bool upper) void onecap_copy(const char *word, char *wcopy, bool upper)
{ {
char *p = word; const char *p = word;
int c = mb_cptr2char_adv((const char **)&p); int c = mb_cptr2char_adv(&p);
if (upper) { if (upper) {
c = SPELL_TOUPPER(c); c = SPELL_TOUPPER(c);
} else { } else {
@ -2683,11 +2683,11 @@ void onecap_copy(char *word, char *wcopy, bool upper)
// Make a copy of "word" with all the letters upper cased into // Make a copy of "word" with all the letters upper cased into
// "wcopy[MAXWLEN]". The result is NUL terminated. // "wcopy[MAXWLEN]". The result is NUL terminated.
void allcap_copy(char *word, char *wcopy) void allcap_copy(const char *word, char *wcopy)
{ {
char *d = wcopy; char *d = wcopy;
for (char *s = word; *s != NUL;) { for (const char *s = word; *s != NUL;) {
int c = mb_cptr2char_adv((const char **)&s); int c = mb_cptr2char_adv(&s);
if (c == 0xdf) { if (c == 0xdf) {
c = 'S'; c = 'S';
@ -2802,7 +2802,7 @@ void spell_soundfold(slang_T *slang, char *inword, bool folded, char *res)
// Perform sound folding of "inword" into "res" according to SOFOFROM and // Perform sound folding of "inword" into "res" according to SOFOFROM and
// SOFOTO lines. // SOFOTO lines.
static void spell_soundfold_sofo(slang_T *slang, char *inword, char *res) static void spell_soundfold_sofo(slang_T *slang, const char *inword, char *res)
{ {
int ri = 0; int ri = 0;
@ -2810,8 +2810,8 @@ static void spell_soundfold_sofo(slang_T *slang, char *inword, char *res)
// The sl_sal_first[] table contains the translation for chars up to // The sl_sal_first[] table contains the translation for chars up to
// 255, sl_sal the rest. // 255, sl_sal the rest.
for (char *s = inword; *s != NUL;) { for (const char *s = inword; *s != NUL;) {
int c = mb_cptr2char_adv((const char **)&s); int c = mb_cptr2char_adv(&s);
if (utf_class(c) == 0) { if (utf_class(c) == 0) {
c = ' '; c = ' ';
} else if (c < 256) { } else if (c < 256) {

View File

@ -1547,10 +1547,10 @@ static int read_compound(FILE *fd, slang_T *slang, int len)
// Set the SOFOFROM and SOFOTO items in language "lp". // Set the SOFOFROM and SOFOTO items in language "lp".
// Returns SP_*ERROR flags when there is something wrong. // Returns SP_*ERROR flags when there is something wrong.
static int set_sofo(slang_T *lp, char *from, char *to) static int set_sofo(slang_T *lp, const char *from, const char *to)
{ {
char *s; const char *s;
char *p; const char *p;
// Use "sl_sal" as an array with 256 pointers to a list of wide // Use "sl_sal" as an array with 256 pointers to a list of wide
// characters. The index is the low byte of the character. // characters. The index is the low byte of the character.
@ -1565,7 +1565,7 @@ static int set_sofo(slang_T *lp, char *from, char *to)
// First count the number of items for each list. Temporarily use // First count the number of items for each list. Temporarily use
// sl_sal_first[] for this. // sl_sal_first[] for this.
for (p = from, s = to; *p != NUL && *s != NUL;) { for (p = from, s = to; *p != NUL && *s != NUL;) {
const int c = mb_cptr2char_adv((const char **)&p); const int c = mb_cptr2char_adv(&p);
MB_CPTR_ADV(s); MB_CPTR_ADV(s);
if (c >= 256) { if (c >= 256) {
lp->sl_sal_first[c & 0xff]++; lp->sl_sal_first[c & 0xff]++;
@ -1588,8 +1588,8 @@ static int set_sofo(slang_T *lp, char *from, char *to)
// list. // list.
memset(lp->sl_sal_first, 0, sizeof(salfirst_T) * 256); memset(lp->sl_sal_first, 0, sizeof(salfirst_T) * 256);
for (p = from, s = to; *p != NUL && *s != NUL;) { for (p = from, s = to; *p != NUL && *s != NUL;) {
const int c = mb_cptr2char_adv((const char **)&p); const int c = mb_cptr2char_adv(&p);
const int i = mb_cptr2char_adv((const char **)&s); const int i = mb_cptr2char_adv(&s);
if (c >= 256) { if (c >= 256) {
// Append the from-to chars at the end of the list with // Append the from-to chars at the end of the list with
// the low byte. // the low byte.
@ -1657,13 +1657,13 @@ static void set_sal_first(slang_T *lp)
// Turn a multi-byte string into a wide character string. // Turn a multi-byte string into a wide character string.
// Return it in allocated memory. // Return it in allocated memory.
static int *mb_str2wide(char *s) static int *mb_str2wide(const char *s)
{ {
int i = 0; int i = 0;
int *res = xmalloc(((size_t)mb_charlen(s) + 1) * sizeof(int)); int *res = xmalloc(((size_t)mb_charlen(s) + 1) * sizeof(int));
for (char *p = s; *p != NUL;) { for (const char *p = s; *p != NUL;) {
res[i++] = mb_ptr2char_adv((const char **)&p); res[i++] = mb_ptr2char_adv(&p);
} }
res[i] = NUL; res[i] = NUL;
@ -5732,13 +5732,13 @@ static void init_spellfile(void)
/// Set the spell character tables from strings in the .spl file. /// Set the spell character tables from strings in the .spl file.
/// ///
/// @param cnt length of "flags" /// @param cnt length of "flags"
static void set_spell_charflags(const char *flags_in, int cnt, char *fol) static void set_spell_charflags(const char *flags_in, int cnt, const char *fol)
{ {
const uint8_t *flags = (uint8_t *)flags_in; const uint8_t *flags = (uint8_t *)flags_in;
// We build the new tables here first, so that we can compare with the // We build the new tables here first, so that we can compare with the
// previous one. // previous one.
spelltab_T new_st; spelltab_T new_st;
char *p = fol; const char *p = fol;
int c; int c;
clear_spell_chartab(&new_st); clear_spell_chartab(&new_st);
@ -5750,7 +5750,7 @@ static void set_spell_charflags(const char *flags_in, int cnt, char *fol)
} }
if (*p != NUL) { if (*p != NUL) {
c = mb_ptr2char_adv((const char **)&p); c = mb_ptr2char_adv(&p);
new_st.st_fold[i + 128] = (uint8_t)c; new_st.st_fold[i + 128] = (uint8_t)c;
if (i + 128 != c && new_st.st_isu[i + 128] && c < 256) { if (i + 128 != c && new_st.st_isu[i + 128] && c < 256) {
new_st.st_upper[c] = (uint8_t)(i + 128); new_st.st_upper[c] = (uint8_t)(i + 128);
@ -5814,9 +5814,9 @@ static int write_spell_prefcond(FILE *fd, garray_T *gap, size_t *fwv)
} }
// Use map string "map" for languages "lp". // Use map string "map" for languages "lp".
static void set_map_str(slang_T *lp, char *map) static void set_map_str(slang_T *lp, const char *map)
{ {
char *p; const char *p;
int headc = 0; int headc = 0;
if (*map == NUL) { if (*map == NUL) {
@ -5835,7 +5835,7 @@ static void set_map_str(slang_T *lp, char *map)
// "aaa/bbb/ccc/". Fill sl_map_array[c] with the character before c and // "aaa/bbb/ccc/". Fill sl_map_array[c] with the character before c and
// before the same slash. For characters above 255 sl_map_hash is used. // before the same slash. For characters above 255 sl_map_hash is used.
for (p = map; *p != NUL;) { for (p = map; *p != NUL;) {
int c = mb_cptr2char_adv((const char **)&p); int c = mb_cptr2char_adv(&p);
if (c == '/') { if (c == '/') {
headc = 0; headc = 0;
} else { } else {

View File

@ -128,8 +128,6 @@ void tinput_init(TermInput *input, Loop *loop)
input->in_fd = STDIN_FILENO; input->in_fd = STDIN_FILENO;
input->waiting_for_bg_response = 0; input->waiting_for_bg_response = 0;
input->extkeys_type = kExtkeysNone; input->extkeys_type = kExtkeysNone;
// The main thread is waiting for the UI thread to call CONTINUE, so it can
// safely access global variables.
input->ttimeout = (bool)p_ttimeout; input->ttimeout = (bool)p_ttimeout;
input->ttimeoutlen = p_ttm; input->ttimeoutlen = p_ttm;
input->key_buffer = rbuffer_new(KEY_BUFFER_SIZE); input->key_buffer = rbuffer_new(KEY_BUFFER_SIZE);
@ -372,9 +370,10 @@ static void forward_mouse_event(TermInput *input, TermKeyKey *key)
if (ev == TERMKEY_MOUSE_UNKNOWN && !(key->code.mouse[0] & 0x20)) { if (ev == TERMKEY_MOUSE_UNKNOWN && !(key->code.mouse[0] & 0x20)) {
int code = key->code.mouse[0] & ~0x3c; int code = key->code.mouse[0] & ~0x3c;
// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Other-buttons
if (code == 66 || code == 67) { if (code == 66 || code == 67) {
ev = TERMKEY_MOUSE_PRESS; ev = TERMKEY_MOUSE_PRESS;
button = code - 60; button = code + 4 - 64;
} }
} }

View File

@ -1143,10 +1143,11 @@ bool uc_split_args_iter(const char *arg, size_t arglen, size_t *end, char *buf,
} }
/// split and quote args for <f-args> /// split and quote args for <f-args>
static char *uc_split_args(char *arg, char **args, const size_t *arglens, size_t argc, size_t *lenp) static char *uc_split_args(const char *arg, char **args, const size_t *arglens, size_t argc,
size_t *lenp)
{ {
char *buf; char *buf;
char *p; const char *p;
char *q; char *q;
int len; int len;
@ -1229,7 +1230,7 @@ static char *uc_split_args(char *arg, char **args, const size_t *arglens, size_t
*q++ = ' '; *q++ = ' ';
*q++ = '"'; *q++ = '"';
} else { } else {
mb_copy_char((const char **)&p, &q); mb_copy_char(&p, &q);
} }
} }
} else { } else {
@ -1242,7 +1243,7 @@ static char *uc_split_args(char *arg, char **args, const size_t *arglens, size_t
*q++ = '\\'; *q++ = '\\';
*q++ = *p++; *q++ = *p++;
} else { } else {
mb_copy_char((const char **)&p, &q); mb_copy_char(&p, &q);
} }
} }
if (i != argc - 1) { if (i != argc - 1) {