eval,*: Move get_tv_string to typval.c

Function was renamed and changed to return `const char *`.
This commit is contained in:
ZyX
2016-08-21 08:16:47 +03:00
parent 5cdf7177ec
commit 28dafe3ff0
28 changed files with 1072 additions and 992 deletions

View File

@@ -625,7 +625,7 @@ String cstr_as_string(char *str) FUNC_ATTR_PURE
if (str == NULL) {
return (String) STRING_INIT;
}
return (String) {.data = str, .size = strlen(str)};
return (String) { .data = str, .size = strlen(str) };
}
/// Converts from type Object to a VimL value.

View File

@@ -4207,11 +4207,11 @@ void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname)
#ifdef WIN32
if (!buf->b_p_bin) {
// If the file name is a shortcut file, use the file it links to.
char_u *rfname = (char_u *)os_resolve_shortcut(*ffname);
char *rfname = os_resolve_shortcut((const char *)(*ffname));
if (rfname != NULL) {
xfree(*ffname);
*ffname = rfname;
*sfname = rfname;
*ffname = (char_u *)rfname;
*sfname = (char_u *)rfname;
}
}
#endif

View File

@@ -3464,7 +3464,6 @@ expand_by_function (
{
list_T *matchlist = NULL;
dict_T *matchdict = NULL;
char_u *args[2];
char_u *funcname;
pos_T pos;
win_T *curwin_save;
@@ -3475,9 +3474,8 @@ expand_by_function (
if (*funcname == NUL)
return;
/* Call 'completefunc' to obtain the list of matches. */
args[0] = (char_u *)"0";
args[1] = base;
// Call 'completefunc' to obtain the list of matches.
const char_u *const args[2] = { (char_u *)"0", base };
pos = curwin->w_cursor;
curwin_save = curwin;
@@ -4589,7 +4587,6 @@ static int ins_complete(int c, bool enable_pum)
* Call user defined function 'completefunc' with "a:findstart"
* set to 1 to obtain the length of text to use for completion.
*/
char_u *args[2];
int col;
char_u *funcname;
pos_T pos;
@@ -4608,8 +4605,7 @@ static int ins_complete(int c, bool enable_pum)
return FAIL;
}
args[0] = (char_u *)"1";
args[1] = NULL;
const char_u *const args[2] = { (char_u *)"1", NULL };
pos = curwin->w_cursor;
curwin_save = curwin;
curbuf_save = curbuf;
@@ -7111,8 +7107,8 @@ static void ins_ctrl_g(void)
*/
static void ins_ctrl_hat(void)
{
if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) {
/* ":lmap" mappings exists, Toggle use of ":lmap" mappings. */
if (map_to_exists_mode("", LANGMAP, false)) {
// ":lmap" mappings exists, Toggle use of ":lmap" mappings.
if (State & LANGMAP) {
curbuf->b_p_iminsert = B_IMODE_NONE;
State &= ~LANGMAP;

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
#define NVIM_EVAL_H
#include "nvim/hashtab.h" // For hashtab_T
#include "nvim/buffer_defs.h" // For scid_T
#include "nvim/buffer_defs.h"
#include "nvim/ex_cmds_defs.h" // For exarg_T
#include "nvim/eval/typval.h"
#include "nvim/profile.h"

View File

@@ -77,10 +77,10 @@ int eexe_mod_op(typval_T *const tv1, const typval_T *const tv2,
if (tv2->v_type == VAR_FLOAT) {
break;
}
char *s = (char *)get_tv_string(tv1);
const char *tvs = tv_get_string(tv1);
char numbuf[NUMBUFLEN];
s = (char *)concat_str((char_u *)s,
get_tv_string_buf(tv2, (char_u *)numbuf));
char *const s = (char *)concat_str(
(const char_u *)tvs, get_tv_string_buf(tv2, (char_u *)numbuf));
tv_clear(tv1);
tv1->v_type = VAR_STRING;
tv1->vval.v_string = (char_u *)s;

View File

@@ -733,7 +733,7 @@ varnumber_T tv_list_find_nr(list_T *const l, const int n, bool *ret_error)
/// @param[in] n Index in a list.
///
/// @return [allocated] Copy of the list item string value.
char *tv_list_find_str(list_T *l, int n)
const char *tv_list_find_str(list_T *l, int n)
FUNC_ATTR_MALLOC
{
const listitem_T *const li = tv_list_find(l, n - 1);
@@ -741,7 +741,7 @@ char *tv_list_find_str(list_T *l, int n)
EMSGN(_(e_listidx), n);
return NULL;
}
return (char *)get_tv_string(&li->li_tv);
return tv_get_string(&li->li_tv);
}
/// Locate item in a list and return its index
@@ -2014,3 +2014,27 @@ bool tv_check_str_or_nr(const typval_T *const tv)
assert(false);
return false;
}
//{{{2 Get
/// Get the string value of a variable
///
/// @warning For number and special values it uses a single, static buffer. It
/// may be used only once, next call to get_tv_string may reuse it. Use
/// get_tv_string_buf() if you need to use tv_get_string() output after
/// calling it again.
///
/// @note get_tv_string_chk() and get_tv_string_buf_chk() are similar, but
/// return NULL on error.
///
/// @param[in] varp Varible to get value of.
///
/// @return Variable value if it is VAR_STRING variable, number converted to
/// a string for VAR_NUMBER, v: variable name for VAR_SPECIAL or empty
/// string.
const char *tv_get_string(const typval_T *const varp)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT
{
static char_u mybuf[NUMBUFLEN];
return (const char *)get_tv_string_buf((typval_T *)varp, mybuf);
}

View File

@@ -205,6 +205,8 @@ struct dictvar_S {
/// Type used for script ID
typedef int scid_T;
/// Format argument for scid_T
#define PRIdSCID "d"
// Structure to hold info for a function that is currently being executed.
typedef struct funccall_S funccall_T;

View File

@@ -270,7 +270,7 @@ do_exmode (
/*
* Execute a simple command line. Used for translated commands like "*".
*/
int do_cmdline_cmd(char *cmd)
int do_cmdline_cmd(const char *cmd)
{
return do_cmdline((char_u *)cmd, NULL, NULL,
DOCMD_NOWAIT|DOCMD_KEYTYPED);
@@ -9347,8 +9347,8 @@ static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp)
*p = '/';
}
/* escape special characters */
p = vim_strsave_fnameescape(sname, FALSE);
// Escape special characters.
p = (char_u *)vim_strsave_fnameescape((const char *)sname, false);
xfree(sname);
/* write the result */

View File

@@ -1149,23 +1149,25 @@ void ex_endwhile(exarg_T *eap)
*/
void ex_throw(exarg_T *eap)
{
char_u *arg = eap->arg;
char_u *value;
const char *arg = (const char *)eap->arg;
char *value;
if (*arg != NUL && *arg != '|' && *arg != '\n')
value = eval_to_string_skip(arg, &eap->nextcmd, eap->skip);
else {
if (*arg != NUL && *arg != '|' && *arg != '\n') {
value = eval_to_string_skip(arg, (const char **)&eap->nextcmd,
(bool)eap->skip);
} else {
EMSG(_(e_argreq));
value = NULL;
}
/* On error or when an exception is thrown during argument evaluation, do
* not throw. */
// On error or when an exception is thrown during argument evaluation, do
// not throw.
if (!eap->skip && value != NULL) {
if (throw_exception(value, ET_USER, NULL) == FAIL)
if (throw_exception((char_u *)value, ET_USER, NULL) == FAIL) {
xfree(value);
else
} else {
do_throw(eap->cstack);
}
}
}

View File

@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <inttypes.h>
#include "nvim/assert.h"
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/arabic.h"
@@ -960,7 +961,7 @@ static int command_line_handle_key(CommandLineState *s)
return command_line_not_changed(s);
case Ctrl_HAT:
if (map_to_exists_mode((char_u *)"", LANGMAP, false)) {
if (map_to_exists_mode("", LANGMAP, false)) {
// ":lmap" mappings exists, toggle use of mappings.
State ^= LANGMAP;
if (s->b_im_ptr != NULL) {
@@ -3120,9 +3121,10 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
#endif
}
#ifdef BACKSLASH_IN_FILENAME
p = vim_strsave_fnameescape(files[i], FALSE);
p = (char_u *)vim_strsave_fnameescape((const char *)files[i], false);
#else
p = vim_strsave_fnameescape(files[i], xp->xp_shell);
p = (char_u *)vim_strsave_fnameescape((const char *)files[i],
xp->xp_shell);
#endif
xfree(files[i]);
files[i] = p;
@@ -3152,42 +3154,49 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
}
}
/*
* Escape special characters in "fname" for when used as a file name argument
* after a Vim command, or, when "shell" is non-zero, a shell command.
* Returns the result in allocated memory.
*/
char_u *vim_strsave_fnameescape(char_u *fname, int shell) FUNC_ATTR_NONNULL_RET
/// Escape special characters in a file name for use as a command argument
///
/// @param[in] fname File name to escape.
/// @param[in] shell What to escape for: if false, escapes for VimL command,
/// if true then it escapes for a shell command.
///
/// @return [allocated] escaped file name.
char *vim_strsave_fnameescape(const char *const fname, const bool shell)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{
char_u *p;
#ifdef BACKSLASH_IN_FILENAME
#define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`%#'\"|!<")
char_u buf[20];
#define PATH_ESC_CHARS " \t\n*?[{`%#'\"|!<"
char_u buf[sizeof(PATH_ESC_CHARS)];
int j = 0;
/* Don't escape '[', '{' and '!' if they are in 'isfname'. */
for (p = PATH_ESC_CHARS; *p != NUL; ++p)
if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p))
buf[j++] = *p;
// Don't escape '[', '{' and '!' if they are in 'isfname'.
for (const char *s = PATH_ESC_CHARS; *s != NUL; s++) {
if ((*s != '[' && *s != '{' && *s != '!') || !vim_isfilec(*s)) {
buf[j++] = *s;
}
}
buf[j] = NUL;
p = vim_strsave_escaped(fname, buf);
char *p = (char *)vim_strsave_escaped((const char_u *)fname,
(const char_u *)buf);
#else
#define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<")
#define SHELL_ESC_CHARS ((char_u *)" \t\n*?[{`$\\%#'\"|!<>();&")
p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
char *p = (char *)vim_strsave_escaped(
(const char_u *)fname, (shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS));
if (shell && csh_like_shell()) {
/* For csh and similar shells need to put two backslashes before '!'.
* One is taken by Vim, one by the shell. */
char_u *s = vim_strsave_escaped(p, (char_u *)"!");
// For csh and similar shells need to put two backslashes before '!'.
// One is taken by Vim, one by the shell.
char *s = (char *)vim_strsave_escaped((const char_u *)p,
(const char_u *)"!");
xfree(p);
p = s;
}
#endif
/* '>' and '+' are special at the start of some commands, e.g. ":edit" and
* ":write". "cd -" has a special meaning. */
// '>' and '+' are special at the start of some commands, e.g. ":edit" and
// ":write". "cd -" has a special meaning.
if (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL)) {
escape_fname(&p);
escape_fname((char_u **)&p);
}
return p;
@@ -4197,9 +4206,11 @@ static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file,
char_u keep;
garray_T ga;
retstr = call_user_expand_func(call_func_retstr, xp, num_file, file);
if (retstr == NULL)
retstr = call_user_expand_func((user_expand_func_T)call_func_retstr, xp,
num_file, file);
if (retstr == NULL) {
return FAIL;
}
ga_init(&ga, (int)sizeof(char *), 3);
for (s = retstr; *s != NUL; s = e) {
@@ -4237,9 +4248,11 @@ static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file)
listitem_T *li;
garray_T ga;
retlist = call_user_expand_func(call_func_retlist, xp, num_file, file);
if (retlist == NULL)
retlist = call_user_expand_func((user_expand_func_T)call_func_retlist, xp,
num_file, file);
if (retlist == NULL) {
return FAIL;
}
ga_init(&ga, (int)sizeof(char *), 3);
/* Loop over the items in the list. */

View File

@@ -428,7 +428,7 @@ readfile (
}
if (!read_buffer && !read_stdin) {
perm = os_getperm(fname);
perm = os_getperm((const char *)fname);
#ifdef UNIX
// On Unix it is possible to read a directory, so we have to
// check for it before os_open().
@@ -2606,10 +2606,10 @@ buf_write (
newfile = TRUE;
perm = -1;
} else {
perm = os_getperm(fname);
if (perm < 0)
newfile = TRUE;
else if (os_isdir(fname)) {
perm = os_getperm((const char *)fname);
if (perm < 0) {
newfile = true;
} else if (os_isdir(fname)) {
errnum = (char_u *)"E502: ";
errmsg = (char_u *)_("is a directory");
goto fail;
@@ -3628,7 +3628,7 @@ restore_backup:
close(empty_fd);
}
if (org != NULL) {
os_setperm((char_u *)org, os_getperm(fname) & 0777);
os_setperm((char_u *)org, os_getperm((const char *)fname) & 0777);
xfree(org);
}
}
@@ -4548,9 +4548,9 @@ int put_time(FILE *fd, time_t time_)
/// os_rename() only works if both files are on the same file system, this
/// function will (attempts to?) copy the file across if rename fails -- webb
//
///
/// @return -1 for failure, 0 for success
int vim_rename(char_u *from, char_u *to)
int vim_rename(const char_u *from, const char_u *to)
{
int fd_in;
int fd_out;
@@ -4569,10 +4569,12 @@ int vim_rename(char_u *from, char_u *to)
* the file name differs we need to go through a temp file.
*/
if (fnamecmp(from, to) == 0) {
if (p_fic && STRCMP(path_tail(from), path_tail(to)) != 0)
if (p_fic && (STRCMP(path_tail((char_u *)from), path_tail((char_u *)to))
!= 0)) {
use_tmp_file = true;
else
} else {
return 0;
}
}
// Fail if the "from" file doesn't exist. Avoids that "to" is deleted.
@@ -4638,9 +4640,9 @@ int vim_rename(char_u *from, char_u *to)
/*
* Rename() failed, try copying the file.
*/
perm = os_getperm(from);
perm = os_getperm((const char *)from);
#ifdef HAVE_ACL
/* For systems that support ACL: get the ACL from the original file. */
// For systems that support ACL: get the ACL from the original file.
acl = mch_get_acl(from);
#endif
fd_in = os_open((char *)from, O_RDONLY, 0);
@@ -5261,7 +5263,7 @@ static void vim_maketempdir(void)
/// Delete "name" and everything in it, recursively.
/// @param name The path which should be deleted.
/// @return 0 for success, -1 if some file was not deleted.
int delete_recursive(char_u *name)
int delete_recursive(const char *name)
{
int result = 0;
@@ -5275,7 +5277,7 @@ int delete_recursive(char_u *name)
EW_DIR | EW_FILE | EW_SILENT | EW_ALLLINKS
| EW_DODOT | EW_EMPTYOK) == OK) {
for (int i = 0; i < file_count; i++) {
if (delete_recursive(files[i]) != 0) {
if (delete_recursive((const char *)files[i]) != 0) {
result = -1;
}
}
@@ -5285,9 +5287,9 @@ int delete_recursive(char_u *name)
}
xfree(exp);
os_rmdir((char *)name);
os_rmdir(name);
} else {
result = os_remove((char *)name) == 0 ? 0 : -1;
result = os_remove(name) == 0 ? 0 : -1;
}
return result;
@@ -5299,7 +5301,7 @@ void vim_deltempdir(void)
if (vim_tempdir != NULL) {
// remove the trailing path separator
path_tail(vim_tempdir)[-1] = NUL;
delete_recursive(vim_tempdir);
delete_recursive((const char *)vim_tempdir);
xfree(vim_tempdir);
vim_tempdir = NULL;
}

View File

@@ -3218,82 +3218,99 @@ showmap (
ui_flush(); /* show one line at a time */
}
/*
* Return TRUE if a map exists that has "str" in the rhs for mode "modechars".
* Recognize termcap codes in "str".
* Also checks mappings local to the current buffer.
*/
int map_to_exists(char_u *str, char_u *modechars, int abbr)
/// Check if a map exists that has given string in the rhs
///
/// Also checks mappings local to the current buffer.
///
/// @param[in] str String which mapping must have in the rhs. Termcap codes
/// are recognized in this argument.
/// @param[in] modechars Mode(s) in which mappings are checked.
/// @param[in] abbr true if checking abbreviations in place of mappings.
///
/// @return true if there is at least one mapping with given parameters.
bool map_to_exists(const char *const str, const char *const modechars,
const bool abbr)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
{
int mode = 0;
char_u *rhs;
char_u *buf;
int retval;
rhs = replace_termcodes(str, STRLEN(str), &buf, false, true, false,
CPO_TO_CPO_FLAGS);
char_u *buf;
char_u *const rhs = replace_termcodes((const char_u *)str, strlen(str), &buf,
false, true, false,
CPO_TO_CPO_FLAGS);
if (vim_strchr(modechars, 'n') != NULL)
mode |= NORMAL;
if (vim_strchr(modechars, 'v') != NULL)
mode |= VISUAL + SELECTMODE;
if (vim_strchr(modechars, 'x') != NULL)
mode |= VISUAL;
if (vim_strchr(modechars, 's') != NULL)
mode |= SELECTMODE;
if (vim_strchr(modechars, 'o') != NULL)
mode |= OP_PENDING;
if (vim_strchr(modechars, 'i') != NULL)
mode |= INSERT;
if (vim_strchr(modechars, 'l') != NULL)
mode |= LANGMAP;
if (vim_strchr(modechars, 'c') != NULL)
mode |= CMDLINE;
#define MAPMODE(mode, modechars, chr, modeflags) \
do { \
if (strchr(modechars, chr) != NULL) { \
mode |= modeflags; \
} \
} while (0)
MAPMODE(mode, modechars, 'n', NORMAL);
MAPMODE(mode, modechars, 'v', VISUAL|SELECTMODE);
MAPMODE(mode, modechars, 'x', VISUAL);
MAPMODE(mode, modechars, 's', SELECTMODE);
MAPMODE(mode, modechars, 'o', OP_PENDING);
MAPMODE(mode, modechars, 'i', INSERT);
MAPMODE(mode, modechars, 'l', LANGMAP);
MAPMODE(mode, modechars, 'c', CMDLINE);
#undef MAPMODE
retval = map_to_exists_mode(rhs, mode, abbr);
retval = map_to_exists_mode((const char *)rhs, mode, abbr);
xfree(buf);
return retval;
}
/*
* Return TRUE if a map exists that has "str" in the rhs for mode "mode".
* Also checks mappings local to the current buffer.
*/
int map_to_exists_mode(char_u *rhs, int mode, int abbr)
/// Check if a map exists that has given string in the rhs
///
/// Also checks mappings local to the current buffer.
///
/// @param[in] rhs String which mapping must have in the rhs. Termcap codes
/// are recognized in this argument.
/// @param[in] mode Mode(s) in which mappings are checked.
/// @param[in] abbr true if checking abbreviations in place of mappings.
///
/// @return true if there is at least one mapping with given parameters.
int map_to_exists_mode(const char *const rhs, const int mode, const bool abbr)
{
mapblock_T *mp;
int hash;
int expand_buffer = FALSE;
bool expand_buffer = false;
validate_maphash();
/* Do it twice: once for global maps and once for local maps. */
for (;; ) {
for (hash = 0; hash < 256; ++hash) {
// Do it twice: once for global maps and once for local maps.
for (;;) {
for (hash = 0; hash < 256; hash++) {
if (abbr) {
if (hash > 0) /* there is only one abbr list */
if (hash > 0) { // There is only one abbr list.
break;
if (expand_buffer)
}
if (expand_buffer) {
mp = curbuf->b_first_abbr;
else
} else {
mp = first_abbr;
} else if (expand_buffer)
}
} else if (expand_buffer) {
mp = curbuf->b_maphash[hash];
else
} else {
mp = maphash[hash];
}
for (; mp; mp = mp->m_next) {
if ((mp->m_mode & mode)
&& strstr((char *)mp->m_str, (char *)rhs) != NULL)
return TRUE;
&& strstr((char *)mp->m_str, rhs) != NULL) {
return true;
}
}
}
if (expand_buffer)
if (expand_buffer) {
break;
expand_buffer = TRUE;
}
expand_buffer = true;
}
return FALSE;
return false;
}
/*

View File

@@ -369,7 +369,6 @@ static void prt_get_attr(int hl_id, prt_text_attr_T *pattr, int modec)
{
int colorindex;
uint32_t fg_color;
char *color;
pattr->bold = (highlight_has_attr(hl_id, HL_BOLD, modec) != NULL);
pattr->italic = (highlight_has_attr(hl_id, HL_ITALIC, modec) != NULL);
@@ -377,11 +376,12 @@ static void prt_get_attr(int hl_id, prt_text_attr_T *pattr, int modec)
pattr->undercurl = (highlight_has_attr(hl_id, HL_UNDERCURL, modec) != NULL);
{
color = (char *)highlight_color(hl_id, (char_u *)"fg", modec);
if (color == NULL)
const char *color = highlight_color(hl_id, "fg", modec);
if (color == NULL) {
colorindex = 0;
else
} else {
colorindex = atoi(color);
}
if (colorindex >= 0 && colorindex < t_colors)
fg_color = prt_get_term_color(colorindex);

View File

@@ -718,7 +718,7 @@ int delete_first_msg(void)
void ex_messages(void *const eap_p)
FUNC_ATTR_NONNULL_ALL
{
exarg_T *eap = (exarg_T *)eap_p;
const exarg_T *const eap = (const exarg_T *)eap_p;
struct msg_hist *p;
int c = 0;

View File

@@ -147,7 +147,7 @@ void channel_from_connection(SocketWatcher *watcher)
/// @param name The event name, an arbitrary string
/// @param args Array with event arguments
/// @return True if the event was sent successfully, false otherwise.
bool channel_send_event(uint64_t id, char *name, Array args)
bool channel_send_event(uint64_t id, const char *name, Array args)
{
Channel *channel = NULL;
@@ -160,7 +160,7 @@ bool channel_send_event(uint64_t id, char *name, Array args)
if (channel) {
if (channel->pending_requests) {
// Pending request, queue the notification for later sending.
String method = cstr_as_string(name);
const String method = cstr_as_string((char *)name);
WBuffer *buffer = serialize_request(id, 0, method, args, &out_buffer, 1);
kv_push(channel->delayed_notifications, buffer);
} else {
@@ -182,7 +182,7 @@ bool channel_send_event(uint64_t id, char *name, Array args)
/// @param[out] error True if the return value is an error
/// @return Whatever the remote method returned
Object channel_send_call(uint64_t id,
char *method_name,
const char *method_name,
Array args,
Error *err)
{
@@ -519,10 +519,10 @@ static void send_error(Channel *channel, uint64_t id, char *err)
static void send_request(Channel *channel,
uint64_t id,
char *name,
const char *name,
Array args)
{
String method = {.size = strlen(name), .data = name};
const String method = cstr_as_string((char *)name);
channel_write(channel, serialize_request(channel->id,
id,
method,
@@ -532,10 +532,10 @@ static void send_request(Channel *channel,
}
static void send_event(Channel *channel,
char *name,
const char *name,
Array args)
{
String method = {.size = strlen(name), .data = name};
const String method = cstr_as_string((char *)name);
channel_write(channel, serialize_request(channel->id,
0,
method,
@@ -544,7 +544,7 @@ static void send_event(Channel *channel,
1));
}
static void broadcast_event(char *name, Array args)
static void broadcast_event(const char *name, Array args)
{
kvec_t(Channel *) subscribed = KV_INITIAL_VALUE;
Channel *channel;
@@ -560,7 +560,7 @@ static void broadcast_event(char *name, Array args)
goto end;
}
String method = {.size = strlen(name), .data = name};
const String method = cstr_as_string((char *)name);
WBuffer *buffer = serialize_request(0,
0,
method,
@@ -728,7 +728,7 @@ static void call_set_error(Channel *channel, char *msg)
static WBuffer *serialize_request(uint64_t channel_id,
uint64_t request_id,
String method,
const String method,
Array args,
msgpack_sbuffer *sbuffer,
size_t refcount)

View File

@@ -322,7 +322,7 @@ void msgpack_rpc_from_float(Float result, msgpack_packer *res)
msgpack_pack_double(res, result);
}
void msgpack_rpc_from_string(String result, msgpack_packer *res)
void msgpack_rpc_from_string(const String result, msgpack_packer *res)
FUNC_ATTR_NONNULL_ARG(2)
{
msgpack_pack_str(res, result.size);
@@ -478,7 +478,7 @@ Object msgpack_rpc_handle_invalid_arguments(uint64_t channel_id,
/// Serializes a msgpack-rpc request or notification(id == 0)
void msgpack_rpc_serialize_request(uint64_t request_id,
String method,
const String method,
Array args,
msgpack_packer *pac)
FUNC_ATTR_NONNULL_ARG(4)

View File

@@ -2075,7 +2075,6 @@ static void op_colon(oparg_T *oap)
*/
static void op_function(oparg_T *oap)
{
char_u *(argv[1]);
int save_virtual_op = virtual_op;
if (*p_opfunc == NUL)
@@ -2089,16 +2088,16 @@ static void op_function(oparg_T *oap)
decl(&curbuf->b_op_end);
}
if (oap->motion_type == kMTBlockWise) {
argv[0] = (char_u *)"block";
} else if (oap->motion_type == kMTLineWise) {
argv[0] = (char_u *)"line";
} else {
argv[0] = (char_u *)"char";
}
const char_u *const argv[1] = {
(const char_u *)(((const char *const[]) {
[kMTBlockWise] = "block",
[kMTLineWise] = "line",
[kMTCharWise] = "char",
})[oap->motion_type]),
};
/* Reset virtual_op so that 'virtualedit' can be changed in the
* function. */
// Reset virtual_op so that 'virtualedit' can be changed in the
// function.
virtual_op = MAYBE;
(void)call_func_retnr(p_opfunc, 1, argv, false);
@@ -4757,7 +4756,7 @@ static void nv_ident(cmdarg_T *cap)
ptr = vim_strnsave(ptr, n);
if (kp_ex) {
// Escape the argument properly for an Ex command
p = vim_strsave_fnameescape(ptr, false);
p = (char_u *)vim_strsave_fnameescape((const char *)ptr, false);
} else {
// Escape the argument properly for a shell command
p = vim_strsave_shellescape(ptr, true, true);

View File

@@ -91,11 +91,11 @@ int os_dirname(char_u *buf, size_t len)
/// Check if the given path is a directory and not a symlink to a directory.
/// @return `true` if `name` is a directory and NOT a symlink to a directory.
/// `false` if `name` is not a directory or if an error occurred.
bool os_isrealdir(const char_u *name)
bool os_isrealdir(const char *name)
FUNC_ATTR_NONNULL_ALL
{
uv_fs_t request;
if (uv_fs_lstat(&fs_loop, &request, (char *)name, NULL) != kLibuvSuccess) {
if (uv_fs_lstat(&fs_loop, &request, name, NULL) != kLibuvSuccess) {
return false;
}
if (S_ISLNK(request.statbuf.st_mode)) {
@@ -111,7 +111,7 @@ bool os_isrealdir(const char_u *name)
bool os_isdir(const char_u *name)
FUNC_ATTR_NONNULL_ALL
{
int32_t mode = os_getperm(name);
int32_t mode = os_getperm((const char *)name);
if (mode < 0) {
return false;
}
@@ -236,7 +236,8 @@ bool os_can_exe(const char_u *name, char_u **abspath, bool use_path)
pathext);
#else
// Must have path separator, cannot execute files in the current directory.
bool ok = gettail_dir(name) != name && is_executable((char *)name);
const bool ok = ((const char_u *)gettail_dir((const char *)name) != name
&& is_executable((char *)name));
#endif
if (ok) {
if (abspath != NULL) {
@@ -254,7 +255,7 @@ bool os_can_exe(const char_u *name, char_u **abspath, bool use_path)
static bool is_executable(const char *name)
FUNC_ATTR_NONNULL_ALL
{
int32_t mode = os_getperm((char_u *)name);
int32_t mode = os_getperm((const char *)name);
if (mode < 0) {
return false;
@@ -606,11 +607,11 @@ static int os_stat(const char *name, uv_stat_t *statbuf)
/// Get the file permissions for a given file.
///
/// @return libuv error code on error.
int32_t os_getperm(const char_u *name)
int32_t os_getperm(const char *name)
FUNC_ATTR_NONNULL_ALL
{
uv_stat_t statbuf;
int stat_result = os_stat((char *)name, &statbuf);
int stat_result = os_stat(name, &statbuf);
if (stat_result == kLibuvSuccess) {
return (int32_t)statbuf.st_mode;
} else {
@@ -979,13 +980,13 @@ bool os_fileid_equal_fileinfo(const FileID *file_id,
/// When "fname" is the name of a shortcut (*.lnk) resolve the file it points
/// to and return that name in allocated memory.
/// Otherwise NULL is returned.
char *os_resolve_shortcut(char_u *fname)
char *os_resolve_shortcut(const char *fname)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
{
HRESULT hr;
IPersistFile *ppf = NULL;
OLECHAR wsz[MAX_PATH];
char *rfname = NULL;
int len;
IShellLinkW *pslw = NULL;
WIN32_FIND_DATAW ffdw;
@@ -994,7 +995,7 @@ char *os_resolve_shortcut(char_u *fname)
if (fname == NULL) {
return rfname;
}
len = (int)STRLEN(fname);
const size_t len = strlen(fname);
if (len <= 4 || STRNICMP(fname + len - 4, ".lnk", 4) != 0) {
return rfname;
}
@@ -1006,7 +1007,7 @@ char *os_resolve_shortcut(char_u *fname)
&IID_IShellLinkW, (void **)&pslw);
if (hr == S_OK) {
WCHAR *p;
int conversion_result = utf8_to_utf16((char *)fname, &p);
const int conversion_result = utf8_to_utf16(fname, &p);
if (conversion_result != 0) {
EMSG2("utf8_to_utf16 failed: %s", uv_strerror(conversion_result));
}
@@ -1036,7 +1037,7 @@ char *os_resolve_shortcut(char_u *fname)
ZeroMemory(wsz, MAX_PATH * sizeof(WCHAR));
hr = pslw->lpVtbl->GetPath(pslw, wsz, MAX_PATH, &ffdw, 0);
if (hr == S_OK && wsz[0] != NUL) {
int conversion_result = utf16_to_utf8(wsz, &rfname);
const int conversion_result = utf16_to_utf8(wsz, &rfname);
if (conversion_result != 0) {
EMSG2("utf16_to_utf8 failed: %s", uv_strerror(conversion_result));
}

View File

@@ -110,14 +110,14 @@ void mch_copy_sec(char_u *from_file, char_u *to_file)
// Return a pointer to the ACL of file "fname" in allocated memory.
// Return NULL if the ACL is not available for whatever reason.
vim_acl_T mch_get_acl(char_u *fname)
vim_acl_T mch_get_acl(const char_u *fname)
{
vim_acl_T ret = NULL;
return ret;
}
// Set the ACL of file "fname" to "acl" (unless it's NULL).
void mch_set_acl(char_u *fname, vim_acl_T aclent)
void mch_set_acl(const char_u *fname, vim_acl_T aclent)
{
if (aclent == NULL)
return;

View File

@@ -159,7 +159,7 @@ const char_u *invocation_path_tail(const char_u *invocation, size_t *len)
/// @param fname A file path. (Must be != NULL.)
/// @return Pointer to first found path separator + 1.
/// An empty string, if `fname` doesn't contain a path separator,
char_u *path_next_component(char_u *fname)
const char *path_next_component(const char *fname)
{
assert(fname != NULL);
while (*fname != NUL && !vim_ispathsep(*fname)) {
@@ -431,7 +431,7 @@ bool add_pathsep(char *p)
///
/// @return [allocated] Copy of absolute path to `fname` or NULL when
/// `fname` is NULL.
char *FullName_save(char *fname, bool force)
char *FullName_save(const char *fname, bool force)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC
{
if (fname == NULL) {
@@ -906,9 +906,9 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
in_curdir = xcalloc((size_t)gap->ga_len, sizeof(char_u *));
for (int i = 0; i < gap->ga_len && !got_int; i++) {
char_u *path = fnames[i];
char_u *path = fnames[i];
int is_in_curdir;
char_u *dir_end = gettail_dir(path);
char_u *dir_end = (char_u *)gettail_dir((const char *)path);
char_u *pathsep_p;
char_u *path_cutoff;
@@ -1010,18 +1010,22 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
ga_remove_duplicate_strings(gap);
}
/// Return the end of the directory name, on the first path
/// separator:
/// "/path/file", "/path/dir/", "/path//dir", "/file"
/// ^ ^ ^ ^
char_u *gettail_dir(const char_u *fname)
/// Find end of the directory name
///
/// @param[in] fname File name to process.
///
/// @return end of the directory name, on the first path separator:
///
/// "/path/file", "/path/dir/", "/path//dir", "/file"
/// ^ ^ ^ ^
const char *gettail_dir(const char *const fname)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
const char_u *dir_end = fname;
const char_u *next_dir_end = fname;
const char *dir_end = fname;
const char *next_dir_end = fname;
bool look_for_sep = true;
const char_u *p;
for (p = fname; *p != NUL; ) {
for (const char *p = fname; *p != NUL; ) {
if (vim_ispathsep(*p)) {
if (look_for_sep) {
next_dir_end = p;
@@ -1034,7 +1038,7 @@ char_u *gettail_dir(const char_u *fname)
}
mb_ptr_adv(p);
}
return (char_u *)dir_end;
return dir_end;
}
@@ -1553,8 +1557,8 @@ void simplify_filename(char_u *filename)
p = tail; /* skip to char after ".." or "../" */
}
} else {
++components; /* simple path component */
p = path_next_component(p);
components++; // Simple path component.
p = (char_u *)path_next_component((const char *)p);
}
} while (*p != NUL);
}

View File

@@ -259,11 +259,11 @@ void sha256_finish(context_sha256_T *ctx, char_u digest[SHA256_SUM_SIZE])
///
/// @returns hex digest of "buf[buf_len]" in a static array.
/// if "salt" is not NULL also do "salt[salt_len]".
char_u *sha256_bytes(const char_u *restrict buf, size_t buf_len,
const char_u *restrict salt, size_t salt_len)
const char *sha256_bytes(const uint8_t *restrict buf, size_t buf_len,
const uint8_t *restrict salt, size_t salt_len)
{
char_u sha256sum[SHA256_SUM_SIZE];
static char_u hexit[SHA256_BUFFER_SIZE + 1]; // buf size + NULL
static char hexit[SHA256_BUFFER_SIZE + 1]; // buf size + NULL
context_sha256_T ctx;
sha256_self_test();
@@ -277,7 +277,7 @@ char_u *sha256_bytes(const char_u *restrict buf, size_t buf_len,
sha256_finish(&ctx, sha256sum);
for (size_t j = 0; j < SHA256_SUM_SIZE; j++) {
snprintf((char *) hexit + j * SHA_STEP, SHA_STEP+1, "%02x", sha256sum[j]);
snprintf(hexit + j * SHA_STEP, SHA_STEP + 1, "%02x", sha256sum[j]);
}
hexit[sizeof(hexit) - 1] = '\0';
return hexit;
@@ -308,7 +308,7 @@ bool sha256_self_test(void)
context_sha256_T ctx;
char_u buf[1000];
char_u sha256sum[SHA256_SUM_SIZE];
char_u *hexit;
const char *hexit;
static bool sha256_self_tested = false;
static bool failures = false;
@@ -320,8 +320,8 @@ bool sha256_self_test(void)
for (size_t i = 0; i < 3; i++) {
if (i < 2) {
hexit = sha256_bytes((char_u *) sha_self_test_msg[i],
STRLEN(sha_self_test_msg[i]),
hexit = sha256_bytes((uint8_t *)sha_self_test_msg[i],
strlen(sha_self_test_msg[i]),
NULL, 0);
STRCPY(output, hexit);
} else {

View File

@@ -82,8 +82,6 @@ KHASH_SET_INIT_STR(strset)
(buflist_new((char_u *)ffname, (char_u *)sfname, __VA_ARGS__))
#define convert_setup(vcp, from, to) \
(convert_setup(vcp, (char_u *)from, (char_u *)to))
#define os_getperm(f) \
(os_getperm((char_u *) f))
#define os_isdir(f) (os_isdir((char_u *) f))
#define regtilde(s, m) ((char *) regtilde((char_u *) s, m))
#define path_tail_with_sep(f) ((char *) path_tail_with_sep((char_u *)f))

View File

@@ -3232,7 +3232,7 @@ static void spell_suggest_expr(suginfo_T *su, char_u *expr)
list_T *list;
listitem_T *li;
int score;
char_u *p;
const char *p;
// The work is split up in a few parts to avoid having to export
// suginfo_T.
@@ -3244,9 +3244,10 @@ static void spell_suggest_expr(suginfo_T *su, char_u *expr)
if (li->li_tv.v_type == VAR_LIST) {
// Get the word and the score from the items.
score = get_spellword(li->li_tv.vval.v_list, &p);
if (score >= 0 && score <= su->su_maxscore)
add_suggestion(su, &su->su_ga, p, su->su_badlen,
score, 0, true, su->su_sallang, false);
if (score >= 0 && score <= su->su_maxscore) {
add_suggestion(su, &su->su_ga, (const char_u *)p, su->su_badlen,
score, 0, true, su->su_sallang, false);
}
}
tv_list_unref(list);
}
@@ -5616,7 +5617,7 @@ static void
add_suggestion (
suginfo_T *su,
garray_T *gap, // either su_ga or su_sga
char_u *goodword,
const char_u *goodword,
int badlenarg, // len of bad word replaced with "goodword"
int score,
int altscore,
@@ -5630,13 +5631,11 @@ add_suggestion (
int badlen; // len of bad word changed
suggest_T *stp;
suggest_T new_sug;
int i;
char_u *pgood, *pbad;
// Minimize "badlen" for consistency. Avoids that changing "the the" to
// "thee the" is added next to changing the first "the" the "thee".
pgood = goodword + STRLEN(goodword);
pbad = su->su_badptr + badlenarg;
const char_u *pgood = goodword + STRLEN(goodword);
char_u *pbad = su->su_badptr + badlenarg;
for (;; ) {
goodlen = (int)(pgood - goodword);
badlen = (int)(pbad - su->su_badptr);
@@ -5656,9 +5655,10 @@ add_suggestion (
// the first "the" to itself.
return;
if (GA_EMPTY(gap))
int i;
if (GA_EMPTY(gap)) {
i = -1;
else {
} else {
// Check if the word is already there. Also check the length that is
// being replaced "thes," -> "these" is a different suggestion from
// "thes" -> "these".
@@ -5857,27 +5857,31 @@ cleanup_suggestions (
return maxscore;
}
// Soundfold a string, for soundfold().
// Result is in allocated memory, NULL for an error.
char_u *eval_soundfold(char_u *word)
/// Soundfold a string, for soundfold()
///
/// @param[in] word Word to soundfold.
///
/// @return [allocated] soundfolded string or NULL in case of error. May return
/// copy of the input string if soundfolding is not
/// supported by any of the languages in &spellang.
char *eval_soundfold(const char *const word)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{
langp_T *lp;
char_u sound[MAXWLEN];
if (curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) {
// Use the sound-folding of the first language that supports it.
for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {
lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) {
langp_T *const lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
if (!GA_EMPTY(&lp->lp_slang->sl_sal)) {
// soundfold the word
spell_soundfold(lp->lp_slang, word, false, sound);
return vim_strsave(sound);
char_u sound[MAXWLEN];
spell_soundfold(lp->lp_slang, (char_u *)word, false, sound);
return xstrdup((const char *)sound);
}
}
}
// No language with sound folding, return word as-is.
return vim_strsave(word);
return xstrdup(word);
}
/// Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]".

View File

@@ -291,30 +291,33 @@ void vim_strup(char_u *p)
}
}
/*
* Make string "s" all upper-case and return it in allocated memory.
* Handles multi-byte characters as well as possible.
*/
char_u *strup_save(const char_u *orig)
/// Make given string all upper-case
///
/// Handels multi-byte characters as good as possible.
///
/// @param[in] orig Input string.
///
/// @return [allocated] upper-cased string.
char *strup_save(const char *const orig)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{
char_u *res = vim_strsave(orig);
char *res = xstrdup(orig);
char_u *p = res;
char *p = res;
while (*p != NUL) {
int l;
if (enc_utf8) {
int c = utf_ptr2char(p);
int c = utf_ptr2char((const char_u *)p);
int uc = utf_toupper(c);
/* Reallocate string when byte count changes. This is rare,
* thus it's OK to do another malloc()/free(). */
l = utf_ptr2len(p);
// Reallocate string when byte count changes. This is rare,
// thus it's OK to do another malloc()/free().
l = utf_ptr2len((const char_u *)p);
int newl = utf_char2len(uc);
if (newl != l) {
// TODO(philix): use xrealloc() in strup_save()
char_u *s = xmalloc(STRLEN(res) + (size_t)(1 + newl - l));
char *s = xmalloc(STRLEN(res) + (size_t)(1 + newl - l));
memcpy(s, res, (size_t)(p - res));
STRCPY(s + (p - res) + newl, p + l);
p = s + (p - res);
@@ -322,12 +325,13 @@ char_u *strup_save(const char_u *orig)
res = s;
}
utf_char2bytes(uc, p);
utf_char2bytes(uc, (char_u *)p);
p += newl;
} else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
p += l; /* skip multi-byte character */
else {
*p = (char_u) TOUPPER_LOC(*p); // note that toupper() can be a macro
} else if (has_mbyte && (l = (*mb_ptr2len)((const char_u *)p)) > 1) {
p += l; // Skip multi-byte character.
} else {
// note that toupper() can be a macro
*p = (char)(uint8_t)TOUPPER_LOC(*p);
p++;
}
}

View File

@@ -6930,21 +6930,21 @@ static int highlight_list_arg(int id, int didh, int type, int iarg, char_u *sarg
return didh;
}
/*
* Return "1" if highlight group "id" has attribute "flag".
* Return NULL otherwise.
*/
char_u *
highlight_has_attr (
int id,
int flag,
int modec // 'g' for GUI, 'c' for cterm
)
/// Check whether highlight group has attribute
///
/// @param[in] id Highilght group to check.
/// @param[in] flag Attribute to check.
/// @param[in] modec 'g' for GUI, 'c' for term.
///
/// @return "1" if highlight group has attribute, NULL otherwise.
const char *highlight_has_attr(const int id, const int flag, const int modec)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
{
int attr;
if (id <= 0 || id > highlight_ga.ga_len)
if (id <= 0 || id > highlight_ga.ga_len) {
return NULL;
}
if (modec == 'g') {
attr = HL_TABLE()[id - 1].sg_gui;
@@ -6952,39 +6952,42 @@ highlight_has_attr (
attr = HL_TABLE()[id - 1].sg_cterm;
}
if (attr & flag)
return (char_u *)"1";
return NULL;
return (attr & flag) ? "1" : NULL;
}
/*
* Return color name of highlight group "id".
*/
char_u *
highlight_color (
int id,
char_u *what, /* "font", "fg", "bg", "sp", "fg#", "bg#" or "sp#" */
int modec /* 'g' for GUI, 'c' for cterm, 't' for term */
)
/// Return color name of the given highlight group
///
/// @param[in] id Highlight group to work with.
/// @param[in] what What to return: one of "font", "fg", "bg", "sp", "fg#",
/// "bg#" or "sp#".
/// @param[in] modec 'g' for GUI, 'c' for cterm and 't' for term.
///
/// @return color name, possibly in a static buffer. Buffer will be overwritten
/// on next highlight_color() call. May return NULL.
const char *highlight_color(const int id, const char *const what,
const int modec)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
static char_u name[20];
static char name[20];
int n;
int fg = FALSE;
int sp = FALSE;
int font = FALSE;
bool fg = false;
bool sp = false;
bool font = false;
if (id <= 0 || id > highlight_ga.ga_len)
if (id <= 0 || id > highlight_ga.ga_len) {
return NULL;
}
if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'g')
fg = TRUE;
else if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'o'
&& TOLOWER_ASC(what[2]) == 'n' && TOLOWER_ASC(what[3]) == 't')
font = TRUE;
else if (TOLOWER_ASC(what[0]) == 's' && TOLOWER_ASC(what[1]) == 'p')
sp = TRUE;
else if (!(TOLOWER_ASC(what[0]) == 'b' && TOLOWER_ASC(what[1]) == 'g'))
if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'g') {
fg = true;
} else if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'o'
&& TOLOWER_ASC(what[2]) == 'n' && TOLOWER_ASC(what[3]) == 't') {
font = true;
} else if (TOLOWER_ASC(what[0]) == 's' && TOLOWER_ASC(what[1]) == 'p') {
sp = true;
} else if (!(TOLOWER_ASC(what[0]) == 'b' && TOLOWER_ASC(what[1]) == 'g')) {
return NULL;
}
if (modec == 'g') {
if (what[2] == '#' && ui_rgb_attached()) {
if (fg) {
@@ -6997,19 +7000,20 @@ highlight_color (
if (n < 0 || n > 0xffffff) {
return NULL;
}
snprintf((char *)name, sizeof(name), "#%06x", n);
snprintf(name, sizeof(name), "#%06x", n);
return name;
}
if (fg) {
return HL_TABLE()[id - 1].sg_rgb_fg_name;
return (const char *)HL_TABLE()[id - 1].sg_rgb_fg_name;
}
if (sp) {
return HL_TABLE()[id - 1].sg_rgb_sp_name;
return (const char *)HL_TABLE()[id - 1].sg_rgb_sp_name;
}
return HL_TABLE()[id - 1].sg_rgb_bg_name;
return (const char *)HL_TABLE()[id - 1].sg_rgb_bg_name;
}
if (font || sp)
if (font || sp) {
return NULL;
}
if (modec == 'c') {
if (fg) {
n = HL_TABLE()[id - 1].sg_cterm_fg - 1;
@@ -7019,10 +7023,10 @@ highlight_color (
if (n < 0) {
return NULL;
}
snprintf((char *)name, sizeof(name), "%d", n);
snprintf(name, sizeof(name), "%d", n);
return name;
}
/* term doesn't have color */
// term doesn't have color.
return NULL;
}
@@ -7133,7 +7137,7 @@ int syn_name2id(const char_u *name)
/*
* Return TRUE if highlight group "name" exists.
*/
int highlight_exists(char_u *name)
int highlight_exists(const char_u *name)
{
return syn_name2id(name) > 0;
}

View File

@@ -1081,7 +1081,7 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf,
*/
perm = 0600;
if (buf->b_ffname != NULL) {
perm = os_getperm(buf->b_ffname);
perm = os_getperm((const char *)buf->b_ffname);
if (perm < 0) {
perm = 0600;
}

View File

@@ -73,7 +73,7 @@ static char *features[] = {
};
// clang-format off
static int included_patches[] = {
static const int included_patches[] = {
// 2367,NA
// 2366 NA
// 2365 NA
@@ -2461,10 +2461,10 @@ static char *(extra_patches[]) = {
/// @param version Version string like "1.3.42"
///
/// @return true if Nvim is at or above the version.
bool has_nvim_version(char *version_str)
FUNC_ATTR_NONNULL_ALL
bool has_nvim_version(const char *const version_str)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
char *p = version_str;
const char *p = version_str;
int major = 0;
int minor = 0;
int patch = 0;
@@ -2473,7 +2473,7 @@ bool has_nvim_version(char *version_str)
return false;
}
major = atoi(p);
p = strchr(p, '.'); // Find the next dot.
p = strchr(p, '.'); // Find the next dot.
if (p) {
p++; // Advance past the dot.
@@ -2481,7 +2481,7 @@ bool has_nvim_version(char *version_str)
return false;
}
minor = atoi(p);
p = strchr(p, '.');
p = strchr(p, '.');
if (p) {
p++;
if (!ascii_isdigit(*p)) {