mirror of
https://github.com/neovim/neovim.git
synced 2025-09-19 09:48:19 +00:00
refactor: use xstrl{cpy,cat} on IObuff (#23648)
Replace usage of STR{CPY,CAT} with xstrl{cpy,cat} when using on IObuff Co-authored-by: ii14 <ii14@users.noreply.github.com>
This commit is contained in:
@@ -1084,11 +1084,11 @@ char *do_bufdel(int command, char *arg, int addr_count, int start_bnr, int end_b
|
|||||||
|
|
||||||
if (deleted == 0) {
|
if (deleted == 0) {
|
||||||
if (command == DOBUF_UNLOAD) {
|
if (command == DOBUF_UNLOAD) {
|
||||||
STRCPY(IObuff, _("E515: No buffers were unloaded"));
|
xstrlcpy(IObuff, _("E515: No buffers were unloaded"), IOSIZE);
|
||||||
} else if (command == DOBUF_DEL) {
|
} else if (command == DOBUF_DEL) {
|
||||||
STRCPY(IObuff, _("E516: No buffers were deleted"));
|
xstrlcpy(IObuff, _("E516: No buffers were deleted"), IOSIZE);
|
||||||
} else {
|
} else {
|
||||||
STRCPY(IObuff, _("E517: No buffers were wiped out"));
|
xstrlcpy(IObuff, _("E517: No buffers were wiped out"), IOSIZE);
|
||||||
}
|
}
|
||||||
errormsg = IObuff;
|
errormsg = IObuff;
|
||||||
} else if (deleted >= p_report) {
|
} else if (deleted >= p_report) {
|
||||||
|
@@ -745,7 +745,7 @@ static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_o
|
|||||||
// the ones from the original file.
|
// the ones from the original file.
|
||||||
// First find a file name that doesn't exist yet (use some
|
// First find a file name that doesn't exist yet (use some
|
||||||
// arbitrary numbers).
|
// arbitrary numbers).
|
||||||
STRCPY(IObuff, fname);
|
xstrlcpy(IObuff, fname, IOSIZE);
|
||||||
for (int i = 4913;; i += 123) {
|
for (int i = 4913;; i += 123) {
|
||||||
char *tail = path_tail(IObuff);
|
char *tail = path_tail(IObuff);
|
||||||
size_t size = (size_t)(tail - IObuff);
|
size_t size = (size_t)(tail - IObuff);
|
||||||
@@ -1749,24 +1749,24 @@ restore_backup:
|
|||||||
add_quoted_fname(IObuff, IOSIZE, buf, fname);
|
add_quoted_fname(IObuff, IOSIZE, buf, fname);
|
||||||
bool insert_space = false;
|
bool insert_space = false;
|
||||||
if (write_info.bw_conv_error) {
|
if (write_info.bw_conv_error) {
|
||||||
STRCAT(IObuff, _(" CONVERSION ERROR"));
|
xstrlcat(IObuff, _(" CONVERSION ERROR"), IOSIZE);
|
||||||
insert_space = true;
|
insert_space = true;
|
||||||
if (write_info.bw_conv_error_lnum != 0) {
|
if (write_info.bw_conv_error_lnum != 0) {
|
||||||
vim_snprintf_add(IObuff, IOSIZE, _(" in line %" PRId64 ";"),
|
vim_snprintf_add(IObuff, IOSIZE, _(" in line %" PRId64 ";"),
|
||||||
(int64_t)write_info.bw_conv_error_lnum);
|
(int64_t)write_info.bw_conv_error_lnum);
|
||||||
}
|
}
|
||||||
} else if (notconverted) {
|
} else if (notconverted) {
|
||||||
STRCAT(IObuff, _("[NOT converted]"));
|
xstrlcat(IObuff, _("[NOT converted]"), IOSIZE);
|
||||||
insert_space = true;
|
insert_space = true;
|
||||||
} else if (converted) {
|
} else if (converted) {
|
||||||
STRCAT(IObuff, _("[converted]"));
|
xstrlcat(IObuff, _("[converted]"), IOSIZE);
|
||||||
insert_space = true;
|
insert_space = true;
|
||||||
}
|
}
|
||||||
if (device) {
|
if (device) {
|
||||||
STRCAT(IObuff, _("[Device]"));
|
xstrlcat(IObuff, _("[Device]"), IOSIZE);
|
||||||
insert_space = true;
|
insert_space = true;
|
||||||
} else if (newfile) {
|
} else if (newfile) {
|
||||||
STRCAT(IObuff, new_file_message());
|
xstrlcat(IObuff, new_file_message(), IOSIZE);
|
||||||
insert_space = true;
|
insert_space = true;
|
||||||
}
|
}
|
||||||
if (no_eol) {
|
if (no_eol) {
|
||||||
@@ -1780,9 +1780,9 @@ restore_backup:
|
|||||||
msg_add_lines(insert_space, (long)lnum, nchars); // add line/char count
|
msg_add_lines(insert_space, (long)lnum, nchars); // add line/char count
|
||||||
if (!shortmess(SHM_WRITE)) {
|
if (!shortmess(SHM_WRITE)) {
|
||||||
if (append) {
|
if (append) {
|
||||||
STRCAT(IObuff, shortmess(SHM_WRI) ? _(" [a]") : _(" appended"));
|
xstrlcat(IObuff, shortmess(SHM_WRI) ? _(" [a]") : _(" appended"), IOSIZE);
|
||||||
} else {
|
} else {
|
||||||
STRCAT(IObuff, shortmess(SHM_WRI) ? _(" [w]") : _(" written"));
|
xstrlcat(IObuff, shortmess(SHM_WRI) ? _(" [w]") : _(" written"), IOSIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -641,9 +641,10 @@ void ex_history(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (; !got_int && histype1 <= histype2; histype1++) {
|
for (; !got_int && histype1 <= histype2; histype1++) {
|
||||||
STRCPY(IObuff, "\n # ");
|
xstrlcpy(IObuff, "\n # ", IOSIZE);
|
||||||
assert(history_names[histype1] != NULL);
|
assert(history_names[histype1] != NULL);
|
||||||
STRCAT(STRCAT(IObuff, history_names[histype1]), " history");
|
xstrlcat(IObuff, history_names[histype1], IOSIZE);
|
||||||
|
xstrlcat(IObuff, " history", IOSIZE);
|
||||||
msg_puts_title(IObuff);
|
msg_puts_title(IObuff);
|
||||||
int idx = hisidx[histype1];
|
int idx = hisidx[histype1];
|
||||||
histentry_T *hist = history[histype1];
|
histentry_T *hist = history[histype1];
|
||||||
@@ -669,7 +670,7 @@ void ex_history(exarg_T *eap)
|
|||||||
trunc_string(hist[i].hisstr, IObuff + strlen(IObuff),
|
trunc_string(hist[i].hisstr, IObuff + strlen(IObuff),
|
||||||
Columns - 10, IOSIZE - (int)strlen(IObuff));
|
Columns - 10, IOSIZE - (int)strlen(IObuff));
|
||||||
} else {
|
} else {
|
||||||
STRCAT(IObuff, hist[i].hisstr);
|
xstrlcat(IObuff, hist[i].hisstr, IOSIZE);
|
||||||
}
|
}
|
||||||
msg_outtrans(IObuff);
|
msg_outtrans(IObuff);
|
||||||
}
|
}
|
||||||
|
@@ -2892,9 +2892,9 @@ char *get_user_func_name(expand_T *xp, int idx)
|
|||||||
|
|
||||||
cat_func_name(IObuff, IOSIZE, fp);
|
cat_func_name(IObuff, IOSIZE, fp);
|
||||||
if (xp->xp_context != EXPAND_USER_FUNC) {
|
if (xp->xp_context != EXPAND_USER_FUNC) {
|
||||||
STRCAT(IObuff, "(");
|
xstrlcat(IObuff, "(", IOSIZE);
|
||||||
if (!fp->uf_varargs && GA_EMPTY(&fp->uf_args)) {
|
if (!fp->uf_varargs && GA_EMPTY(&fp->uf_args)) {
|
||||||
STRCAT(IObuff, ")");
|
xstrlcat(IObuff, ")", IOSIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return IObuff;
|
return IObuff;
|
||||||
@@ -3505,7 +3505,7 @@ char *get_return_cmd(void *rettv)
|
|||||||
s = "";
|
s = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
STRCPY(IObuff, ":return ");
|
xstrlcpy(IObuff, ":return ", IOSIZE);
|
||||||
xstrlcpy(IObuff + 8, s, IOSIZE - 8);
|
xstrlcpy(IObuff + 8, s, IOSIZE - 8);
|
||||||
if (strlen(s) + 8 >= IOSIZE) {
|
if (strlen(s) + 8 >= IOSIZE) {
|
||||||
STRCPY(IObuff + IOSIZE - 4, "...");
|
STRCPY(IObuff + IOSIZE - 4, "...");
|
||||||
|
@@ -1454,7 +1454,7 @@ bool parse_cmdline(char *cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, char **er
|
|||||||
}
|
}
|
||||||
// Fail if command is invalid
|
// Fail if command is invalid
|
||||||
if (eap->cmdidx == CMD_SIZE) {
|
if (eap->cmdidx == CMD_SIZE) {
|
||||||
STRCPY(IObuff, _(e_not_an_editor_command));
|
xstrlcpy(IObuff, _(e_not_an_editor_command), IOSIZE);
|
||||||
// If the modifier was parsed OK the error must be in the following command
|
// If the modifier was parsed OK the error must be in the following command
|
||||||
char *cmdname = after_modifier ? after_modifier : cmdline;
|
char *cmdname = after_modifier ? after_modifier : cmdline;
|
||||||
append_command(cmdname);
|
append_command(cmdname);
|
||||||
@@ -2044,7 +2044,7 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter
|
|||||||
// Check for wrong commands.
|
// Check for wrong commands.
|
||||||
if (ea.cmdidx == CMD_SIZE) {
|
if (ea.cmdidx == CMD_SIZE) {
|
||||||
if (!ea.skip) {
|
if (!ea.skip) {
|
||||||
STRCPY(IObuff, _(e_not_an_editor_command));
|
xstrlcpy(IObuff, _(e_not_an_editor_command), IOSIZE);
|
||||||
// If the modifier was parsed OK the error must be in the following
|
// If the modifier was parsed OK the error must be in the following
|
||||||
// command
|
// command
|
||||||
char *cmdname = after_modifier ? after_modifier : *cmdlinep;
|
char *cmdname = after_modifier ? after_modifier : *cmdlinep;
|
||||||
@@ -2321,7 +2321,7 @@ doend:
|
|||||||
if (errormsg != NULL && *errormsg != NUL && !did_emsg) {
|
if (errormsg != NULL && *errormsg != NUL && !did_emsg) {
|
||||||
if (flags & DOCMD_VERBOSE) {
|
if (flags & DOCMD_VERBOSE) {
|
||||||
if (errormsg != IObuff) {
|
if (errormsg != IObuff) {
|
||||||
STRCPY(IObuff, errormsg);
|
xstrlcpy(IObuff, errormsg, IOSIZE);
|
||||||
errormsg = IObuff;
|
errormsg = IObuff;
|
||||||
}
|
}
|
||||||
append_command(*ea.cmdlinep);
|
append_command(*ea.cmdlinep);
|
||||||
@@ -2888,7 +2888,7 @@ static void append_command(char *cmd)
|
|||||||
d -= utf_head_off(IObuff, d);
|
d -= utf_head_off(IObuff, d);
|
||||||
STRCPY(d, "...");
|
STRCPY(d, "...");
|
||||||
}
|
}
|
||||||
STRCAT(IObuff, ": ");
|
xstrlcat(IObuff, ": ", IOSIZE);
|
||||||
d = IObuff + strlen(IObuff);
|
d = IObuff + strlen(IObuff);
|
||||||
while (*s != NUL && d - IObuff + 5 < IOSIZE) {
|
while (*s != NUL && d - IObuff + 5 < IOSIZE) {
|
||||||
if ((uint8_t)s[0] == 0xc2 && (uint8_t)s[1] == 0xa0) {
|
if ((uint8_t)s[0] == 0xc2 && (uint8_t)s[1] == 0xa0) {
|
||||||
|
@@ -1693,22 +1693,22 @@ failed:
|
|||||||
|
|
||||||
#ifdef UNIX
|
#ifdef UNIX
|
||||||
if (S_ISFIFO(perm)) { // fifo
|
if (S_ISFIFO(perm)) { // fifo
|
||||||
STRCAT(IObuff, _("[fifo]"));
|
xstrlcat(IObuff, _("[fifo]"), IOSIZE);
|
||||||
c = true;
|
c = true;
|
||||||
}
|
}
|
||||||
if (S_ISSOCK(perm)) { // or socket
|
if (S_ISSOCK(perm)) { // or socket
|
||||||
STRCAT(IObuff, _("[socket]"));
|
xstrlcat(IObuff, _("[socket]"), IOSIZE);
|
||||||
c = true;
|
c = true;
|
||||||
}
|
}
|
||||||
# ifdef OPEN_CHR_FILES
|
# ifdef OPEN_CHR_FILES
|
||||||
if (S_ISCHR(perm)) { // or character special
|
if (S_ISCHR(perm)) { // or character special
|
||||||
STRCAT(IObuff, _("[character special]"));
|
xstrlcat(IObuff, _("[character special]"), IOSIZE);
|
||||||
c = true;
|
c = true;
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
if (curbuf->b_p_ro) {
|
if (curbuf->b_p_ro) {
|
||||||
STRCAT(IObuff, shortmess(SHM_RO) ? _("[RO]") : _("[readonly]"));
|
xstrlcat(IObuff, shortmess(SHM_RO) ? _("[RO]") : _("[readonly]"), IOSIZE);
|
||||||
c = true;
|
c = true;
|
||||||
}
|
}
|
||||||
if (read_no_eol_lnum) {
|
if (read_no_eol_lnum) {
|
||||||
@@ -1716,18 +1716,18 @@ failed:
|
|||||||
c = true;
|
c = true;
|
||||||
}
|
}
|
||||||
if (ff_error == EOL_DOS) {
|
if (ff_error == EOL_DOS) {
|
||||||
STRCAT(IObuff, _("[CR missing]"));
|
xstrlcat(IObuff, _("[CR missing]"), IOSIZE);
|
||||||
c = true;
|
c = true;
|
||||||
}
|
}
|
||||||
if (split) {
|
if (split) {
|
||||||
STRCAT(IObuff, _("[long lines split]"));
|
xstrlcat(IObuff, _("[long lines split]"), IOSIZE);
|
||||||
c = true;
|
c = true;
|
||||||
}
|
}
|
||||||
if (notconverted) {
|
if (notconverted) {
|
||||||
STRCAT(IObuff, _("[NOT converted]"));
|
xstrlcat(IObuff, _("[NOT converted]"), IOSIZE);
|
||||||
c = true;
|
c = true;
|
||||||
} else if (converted) {
|
} else if (converted) {
|
||||||
STRCAT(IObuff, _("[converted]"));
|
xstrlcat(IObuff, _("[converted]"), IOSIZE);
|
||||||
c = true;
|
c = true;
|
||||||
}
|
}
|
||||||
if (conv_error != 0) {
|
if (conv_error != 0) {
|
||||||
@@ -1739,7 +1739,7 @@ failed:
|
|||||||
_("[ILLEGAL BYTE in line %" PRId64 "]"), (int64_t)illegal_byte);
|
_("[ILLEGAL BYTE in line %" PRId64 "]"), (int64_t)illegal_byte);
|
||||||
c = true;
|
c = true;
|
||||||
} else if (error) {
|
} else if (error) {
|
||||||
STRCAT(IObuff, _("[READ ERRORS]"));
|
xstrlcat(IObuff, _("[READ ERRORS]"), IOSIZE);
|
||||||
c = true;
|
c = true;
|
||||||
}
|
}
|
||||||
if (msg_add_fileformat(fileformat)) {
|
if (msg_add_fileformat(fileformat)) {
|
||||||
@@ -2128,17 +2128,17 @@ bool msg_add_fileformat(int eol_type)
|
|||||||
{
|
{
|
||||||
#ifndef USE_CRNL
|
#ifndef USE_CRNL
|
||||||
if (eol_type == EOL_DOS) {
|
if (eol_type == EOL_DOS) {
|
||||||
STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[dos]") : _("[dos format]"));
|
xstrlcat(IObuff, shortmess(SHM_TEXT) ? _("[dos]") : _("[dos format]"), IOSIZE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (eol_type == EOL_MAC) {
|
if (eol_type == EOL_MAC) {
|
||||||
STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[mac]") : _("[mac format]"));
|
xstrlcat(IObuff, shortmess(SHM_TEXT) ? _("[mac]") : _("[mac format]"), IOSIZE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#ifdef USE_CRNL
|
#ifdef USE_CRNL
|
||||||
if (eol_type == EOL_UNIX) {
|
if (eol_type == EOL_UNIX) {
|
||||||
STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[unix]") : _("[unix format]"));
|
xstrlcat(IObuff, shortmess(SHM_TEXT) ? _("[unix]") : _("[unix format]"), IOSIZE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -2170,8 +2170,7 @@ void msg_add_lines(int insert_space, long lnum, off_T nchars)
|
|||||||
/// Append message for missing line separator to IObuff.
|
/// Append message for missing line separator to IObuff.
|
||||||
void msg_add_eol(void)
|
void msg_add_eol(void)
|
||||||
{
|
{
|
||||||
STRCAT(IObuff,
|
xstrlcat(IObuff, shortmess(SHM_LAST) ? _("[noeol]") : _("[Incomplete last line]"), IOSIZE);
|
||||||
shortmess(SHM_LAST) ? _("[noeol]") : _("[Incomplete last line]"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool time_differs(const FileInfo *file_info, long mtime, long mtime_ns) FUNC_ATTR_CONST
|
bool time_differs(const FileInfo *file_info, long mtime, long mtime_ns) FUNC_ATTR_CONST
|
||||||
|
@@ -1626,7 +1626,7 @@ int do_set(char *arg, int opt_flags)
|
|||||||
int i = (int)strlen(IObuff) + 2;
|
int i = (int)strlen(IObuff) + 2;
|
||||||
if (i + (arg - startarg) < IOSIZE) {
|
if (i + (arg - startarg) < IOSIZE) {
|
||||||
// append the argument with the error
|
// append the argument with the error
|
||||||
STRCAT(IObuff, ": ");
|
xstrlcat(IObuff, ": ", IOSIZE);
|
||||||
assert(arg >= startarg);
|
assert(arg >= startarg);
|
||||||
memmove(IObuff + i, startarg, (size_t)(arg - startarg));
|
memmove(IObuff + i, startarg, (size_t)(arg - startarg));
|
||||||
IObuff[i + (arg - startarg)] = NUL;
|
IObuff[i + (arg - startarg)] = NUL;
|
||||||
|
@@ -130,7 +130,7 @@ char *get_xdg_home(const XDGVarType idx)
|
|||||||
xstrlcpy(IObuff, appname, appname_len + 1);
|
xstrlcpy(IObuff, appname, appname_len + 1);
|
||||||
#if defined(MSWIN)
|
#if defined(MSWIN)
|
||||||
if (idx == kXDGDataHome || idx == kXDGStateHome) {
|
if (idx == kXDGDataHome || idx == kXDGStateHome) {
|
||||||
STRCAT(IObuff, "-data");
|
xstrlcat(IObuff, "-data", IOSIZE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
dir = concat_fnames_realloc(dir, IObuff, true);
|
dir = concat_fnames_realloc(dir, IObuff, true);
|
||||||
|
@@ -1547,7 +1547,7 @@ static inline char *add_dir(char *dest, const char *const dir, const size_t dir_
|
|||||||
xstrlcpy(IObuff, appname, appname_len + 1);
|
xstrlcpy(IObuff, appname, appname_len + 1);
|
||||||
#if defined(MSWIN)
|
#if defined(MSWIN)
|
||||||
if (type == kXDGDataHome || type == kXDGStateHome) {
|
if (type == kXDGDataHome || type == kXDGStateHome) {
|
||||||
STRCAT(IObuff, "-data");
|
xstrlcat(IObuff, "-data", IOSIZE);
|
||||||
appname_len += 5;
|
appname_len += 5;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -732,7 +732,7 @@ void do_tag(char *tag, int type, int count, int forceit, int verbose)
|
|||||||
num_matches,
|
num_matches,
|
||||||
max_num_matches != MAXCOL ? _(" or more") : "");
|
max_num_matches != MAXCOL ? _(" or more") : "");
|
||||||
if (ic) {
|
if (ic) {
|
||||||
STRCAT(IObuff, _(" Using tag with different case!"));
|
xstrlcat(IObuff, _(" Using tag with different case!"), IOSIZE);
|
||||||
}
|
}
|
||||||
if ((num_matches > prev_num_matches || new_tag)
|
if ((num_matches > prev_num_matches || new_tag)
|
||||||
&& num_matches > 1) {
|
&& num_matches > 1) {
|
||||||
|
@@ -418,11 +418,11 @@ static int assert_equalfile(typval_T *argvars)
|
|||||||
const int c2 = fgetc(fd2);
|
const int c2 = fgetc(fd2);
|
||||||
if (c1 == EOF) {
|
if (c1 == EOF) {
|
||||||
if (c2 != EOF) {
|
if (c2 != EOF) {
|
||||||
STRCPY(IObuff, "first file is shorter");
|
xstrlcpy(IObuff, "first file is shorter", IOSIZE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (c2 == EOF) {
|
} else if (c2 == EOF) {
|
||||||
STRCPY(IObuff, "second file is shorter");
|
xstrlcpy(IObuff, "second file is shorter", IOSIZE);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
line1[lineidx] = (char)c1;
|
line1[lineidx] = (char)c1;
|
||||||
|
@@ -2667,7 +2667,7 @@ void ex_undolist(exarg_T *eap)
|
|||||||
undo_fmt_time(IObuff + strlen(IObuff), IOSIZE - strlen(IObuff), uhp->uh_time);
|
undo_fmt_time(IObuff + strlen(IObuff), IOSIZE - strlen(IObuff), uhp->uh_time);
|
||||||
if (uhp->uh_save_nr > 0) {
|
if (uhp->uh_save_nr > 0) {
|
||||||
while (strlen(IObuff) < 33) {
|
while (strlen(IObuff) < 33) {
|
||||||
STRCAT(IObuff, " ");
|
xstrlcat(IObuff, " ", IOSIZE);
|
||||||
}
|
}
|
||||||
vim_snprintf_add(IObuff, IOSIZE, " %3ld", uhp->uh_save_nr);
|
vim_snprintf_add(IObuff, IOSIZE, " %3ld", uhp->uh_save_nr);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user