mirror of
https://github.com/neovim/neovim.git
synced 2025-09-12 22:38:16 +00:00
fileio: Refactor msg_add_fname to something which needs no comments
This commit is contained in:
@@ -2724,7 +2724,7 @@ fileinfo (
|
|||||||
else
|
else
|
||||||
name = curbuf->b_ffname;
|
name = curbuf->b_ffname;
|
||||||
home_replace(shorthelp ? curbuf : NULL, name, p,
|
home_replace(shorthelp ? curbuf : NULL, name, p,
|
||||||
(int)(IOSIZE - (p - buffer)), TRUE);
|
(size_t)(IOSIZE - (p - buffer)), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
vim_snprintf_add((char *)buffer, IOSIZE, "\"%s%s%s%s%s%s",
|
vim_snprintf_add((char *)buffer, IOSIZE, "\"%s%s%s%s%s%s",
|
||||||
@@ -2889,7 +2889,7 @@ void maketitle(void)
|
|||||||
buf[off++] = ' ';
|
buf[off++] = ' ';
|
||||||
buf[off++] = '(';
|
buf[off++] = '(';
|
||||||
home_replace(curbuf, curbuf->b_ffname,
|
home_replace(curbuf, curbuf->b_ffname,
|
||||||
buf + off, SPACE_FOR_DIR - off, TRUE);
|
buf + off, (size_t)(SPACE_FOR_DIR - off), true);
|
||||||
#ifdef BACKSLASH_IN_FILENAME
|
#ifdef BACKSLASH_IN_FILENAME
|
||||||
/* avoid "c:/name" to be reduced to "c" */
|
/* avoid "c:/name" to be reduced to "c" */
|
||||||
if (isalpha(buf[off]) && buf[off + 1] == ':')
|
if (isalpha(buf[off]) && buf[off + 1] == ':')
|
||||||
|
@@ -200,18 +200,14 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr)
|
|||||||
{
|
{
|
||||||
int msg_scroll_save;
|
int msg_scroll_save;
|
||||||
|
|
||||||
if (msg_silent != 0)
|
if (msg_silent != 0) {
|
||||||
return;
|
return;
|
||||||
msg_add_fname(buf, name); /* put file name in IObuff with quotes */
|
}
|
||||||
/* If it's extremely long, truncate it. */
|
add_quoted_fname((char *)IObuff, IOSIZE - 80, buf,(const char *)name);
|
||||||
if (STRLEN(IObuff) > IOSIZE - 80)
|
xstrlcat((char *)IObuff, (const char *)s, IOSIZE);
|
||||||
IObuff[IOSIZE - 80] = NUL;
|
// For the first message may have to start a new line.
|
||||||
STRCAT(IObuff, s);
|
// For further ones overwrite the previous one, reset msg_scroll before
|
||||||
/*
|
// calling filemess().
|
||||||
* For the first message may have to start a new line.
|
|
||||||
* For further ones overwrite the previous one, reset msg_scroll before
|
|
||||||
* calling filemess().
|
|
||||||
*/
|
|
||||||
msg_scroll_save = msg_scroll;
|
msg_scroll_save = msg_scroll;
|
||||||
if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0)
|
if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0)
|
||||||
msg_scroll = FALSE;
|
msg_scroll = FALSE;
|
||||||
@@ -1800,8 +1796,8 @@ failed:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!filtering && !(flags & READ_DUMMY)) {
|
if (!filtering && !(flags & READ_DUMMY)) {
|
||||||
msg_add_fname(curbuf, sfname); /* fname in IObuff with quotes */
|
add_quoted_fname((char *)IObuff, IOSIZE, curbuf,(const char *)sfname);
|
||||||
c = FALSE;
|
c = false;
|
||||||
|
|
||||||
#ifdef UNIX
|
#ifdef UNIX
|
||||||
# ifdef S_ISFIFO
|
# ifdef S_ISFIFO
|
||||||
@@ -3531,8 +3527,8 @@ restore_backup:
|
|||||||
fname = sfname; /* use shortname now, for the messages */
|
fname = sfname; /* use shortname now, for the messages */
|
||||||
#endif
|
#endif
|
||||||
if (!filtering) {
|
if (!filtering) {
|
||||||
msg_add_fname(buf, fname); /* put fname in IObuff with quotes */
|
add_quoted_fname((char *)IObuff, IOSIZE, buf,(const char *)fname);
|
||||||
c = FALSE;
|
c = false;
|
||||||
if (write_info.bw_conv_error) {
|
if (write_info.bw_conv_error) {
|
||||||
STRCAT(IObuff, _(" CONVERSION ERROR"));
|
STRCAT(IObuff, _(" CONVERSION ERROR"));
|
||||||
c = TRUE;
|
c = TRUE;
|
||||||
@@ -3681,10 +3677,11 @@ nofail:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (errmsg != NULL) {
|
if (errmsg != NULL) {
|
||||||
|
// - 100 to save some space for further error message
|
||||||
#ifndef UNIX
|
#ifndef UNIX
|
||||||
msg_add_fname(buf, sfname);
|
add_quoted_fname((char *)IObuff, IOSIZE - 100, buf, (const char *)sfname);
|
||||||
#else
|
#else
|
||||||
msg_add_fname(buf, fname);
|
add_quoted_fname((char *)IObuff, IOSIZE - 100, buf, (const char *)fname);
|
||||||
#endif
|
#endif
|
||||||
if (errnum != NULL) {
|
if (errnum != NULL) {
|
||||||
if (errmsgarg != 0) {
|
if (errmsgarg != 0) {
|
||||||
@@ -3811,16 +3808,25 @@ static int set_rw_fname(char_u *fname, char_u *sfname)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// Put file name into the specified buffer with quotes
|
||||||
* Put file name into IObuff with quotes.
|
///
|
||||||
*/
|
/// Replaces home directory at the start with `~`.
|
||||||
static void msg_add_fname(buf_T *buf, char_u *fname)
|
///
|
||||||
|
/// @param[out] ret_buf Buffer to save results to.
|
||||||
|
/// @param[in] buf_len ret_buf length.
|
||||||
|
/// @param[in] buf buf_T file name is coming from.
|
||||||
|
/// @param[in] fname File name to write.
|
||||||
|
static void add_quoted_fname(char *const ret_buf, const size_t buf_len,
|
||||||
|
const buf_T *const buf, const char *fname)
|
||||||
|
FUNC_ATTR_NONNULL_ARG(1)
|
||||||
{
|
{
|
||||||
if (fname == NULL)
|
if (fname == NULL) {
|
||||||
fname = (char_u *)"-stdin-";
|
fname = "-stdin-";
|
||||||
home_replace(buf, fname, IObuff + 1, IOSIZE - 4, TRUE);
|
}
|
||||||
IObuff[0] = '"';
|
ret_buf[0] = '"';
|
||||||
STRCAT(IObuff, "\" ");
|
home_replace(buf, (const char_u *)fname, (char_u *)ret_buf + 1,
|
||||||
|
(int)buf_len - 4, true);
|
||||||
|
xstrlcat(ret_buf, "\" ", buf_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Append message for text mode to IObuff.
|
/// Append message for text mode to IObuff.
|
||||||
|
@@ -703,7 +703,8 @@ char *vim_getenv(const char *name)
|
|||||||
/// @param dstlen Maximum length of the result
|
/// @param dstlen Maximum length of the result
|
||||||
/// @param one If true, only replace one file name, including spaces and commas
|
/// @param one If true, only replace one file name, including spaces and commas
|
||||||
/// in the file name
|
/// in the file name
|
||||||
void home_replace(buf_T *buf, char_u *src, char_u *dst, int dstlen, bool one)
|
void home_replace(const buf_T *const buf, const char_u *src,
|
||||||
|
char_u *dst, size_t dstlen, bool one)
|
||||||
{
|
{
|
||||||
size_t dirlen = 0, envlen = 0;
|
size_t dirlen = 0, envlen = 0;
|
||||||
size_t len;
|
size_t len;
|
||||||
@@ -717,7 +718,7 @@ void home_replace(buf_T *buf, char_u *src, char_u *dst, int dstlen, bool one)
|
|||||||
* If the file is a help file, remove the path completely.
|
* If the file is a help file, remove the path completely.
|
||||||
*/
|
*/
|
||||||
if (buf != NULL && buf->b_help) {
|
if (buf != NULL && buf->b_help) {
|
||||||
STRCPY(dst, path_tail(src));
|
xstrlcpy((char *)dst, (char *)path_tail(src), dstlen);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -809,7 +810,7 @@ char_u * home_replace_save(buf_T *buf, char_u *src) FUNC_ATTR_NONNULL_RET
|
|||||||
len += STRLEN(src);
|
len += STRLEN(src);
|
||||||
}
|
}
|
||||||
char_u *dst = xmalloc(len);
|
char_u *dst = xmalloc(len);
|
||||||
home_replace(buf, src, dst, (int)len, true);
|
home_replace(buf, src, dst, len, true);
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -84,15 +84,15 @@ FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname)
|
|||||||
///
|
///
|
||||||
/// @return pointer just past the last path separator (empty string, if fname
|
/// @return pointer just past the last path separator (empty string, if fname
|
||||||
/// ends in a slash), or empty string if fname is NULL.
|
/// ends in a slash), or empty string if fname is NULL.
|
||||||
char_u *path_tail(char_u *fname)
|
char_u *path_tail(const char_u *fname)
|
||||||
FUNC_ATTR_NONNULL_RET
|
FUNC_ATTR_NONNULL_RET
|
||||||
{
|
{
|
||||||
if (fname == NULL) {
|
if (fname == NULL) {
|
||||||
return (char_u *)"";
|
return (char_u *)"";
|
||||||
}
|
}
|
||||||
|
|
||||||
char_u *tail = get_past_head(fname);
|
const char_u *tail = get_past_head(fname);
|
||||||
char_u *p = tail;
|
const char_u *p = tail;
|
||||||
// Find last part of path.
|
// Find last part of path.
|
||||||
while (*p != NUL) {
|
while (*p != NUL) {
|
||||||
if (vim_ispathsep_nocolon(*p)) {
|
if (vim_ispathsep_nocolon(*p)) {
|
||||||
@@ -100,7 +100,7 @@ char_u *path_tail(char_u *fname)
|
|||||||
}
|
}
|
||||||
mb_ptr_adv(p);
|
mb_ptr_adv(p);
|
||||||
}
|
}
|
||||||
return tail;
|
return (char_u *)tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get pointer to tail of "fname", including path separators.
|
/// Get pointer to tail of "fname", including path separators.
|
||||||
@@ -174,9 +174,9 @@ const char *path_next_component(const char *fname)
|
|||||||
/// Get a pointer to one character past the head of a path name.
|
/// Get a pointer to one character past the head of a path name.
|
||||||
/// Unix: after "/"; Win: after "c:\"
|
/// Unix: after "/"; Win: after "c:\"
|
||||||
/// If there is no head, path is returned.
|
/// If there is no head, path is returned.
|
||||||
char_u *get_past_head(char_u *path)
|
char_u *get_past_head(const char_u *path)
|
||||||
{
|
{
|
||||||
char_u *retval = path;
|
const char_u *retval = path;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// May skip "c:"
|
// May skip "c:"
|
||||||
@@ -189,7 +189,7 @@ char_u *get_past_head(char_u *path)
|
|||||||
++retval;
|
++retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return (char_u *)retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user