0
0
mirror of https://github.com/vim/vim.git synced 2025-10-13 06:54:15 -04:00

patch 8.1.1985: code for dealing with paths is spread out

Problem:    Code for dealing with paths is spread out.
Solution:   Move path related functions from misc1.c to filepath.c.
            Remove NO_EXPANDPATH.
This commit is contained in:
Bram Moolenaar
2019-09-04 20:59:15 +02:00
parent 3f4f3d8e7e
commit 26262f8777
14 changed files with 2152 additions and 2173 deletions

View File

@@ -282,8 +282,6 @@ static void f_synIDattr(typval_T *argvars, typval_T *rettv);
static void f_synIDtrans(typval_T *argvars, typval_T *rettv);
static void f_synstack(typval_T *argvars, typval_T *rettv);
static void f_synconcealed(typval_T *argvars, typval_T *rettv);
static void f_system(typval_T *argvars, typval_T *rettv);
static void f_systemlist(typval_T *argvars, typval_T *rettv);
static void f_tabpagebuflist(typval_T *argvars, typval_T *rettv);
static void f_tabpagenr(typval_T *argvars, typval_T *rettv);
static void f_tabpagewinnr(typval_T *argvars, typval_T *rettv);
@@ -9252,205 +9250,6 @@ f_synstack(typval_T *argvars UNUSED, typval_T *rettv)
#endif
}
static void
get_cmd_output_as_rettv(
typval_T *argvars,
typval_T *rettv,
int retlist)
{
char_u *res = NULL;
char_u *p;
char_u *infile = NULL;
int err = FALSE;
FILE *fd;
list_T *list = NULL;
int flags = SHELL_SILENT;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
if (check_restricted() || check_secure())
goto errret;
if (argvars[1].v_type != VAR_UNKNOWN)
{
/*
* Write the text to a temp file, to be used for input of the shell
* command.
*/
if ((infile = vim_tempname('i', TRUE)) == NULL)
{
emsg(_(e_notmp));
goto errret;
}
fd = mch_fopen((char *)infile, WRITEBIN);
if (fd == NULL)
{
semsg(_(e_notopen), infile);
goto errret;
}
if (argvars[1].v_type == VAR_NUMBER)
{
linenr_T lnum;
buf_T *buf;
buf = buflist_findnr(argvars[1].vval.v_number);
if (buf == NULL)
{
semsg(_(e_nobufnr), argvars[1].vval.v_number);
fclose(fd);
goto errret;
}
for (lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++)
{
for (p = ml_get_buf(buf, lnum, FALSE); *p != NUL; ++p)
if (putc(*p == '\n' ? NUL : *p, fd) == EOF)
{
err = TRUE;
break;
}
if (putc(NL, fd) == EOF)
{
err = TRUE;
break;
}
}
}
else if (argvars[1].v_type == VAR_LIST)
{
if (write_list(fd, argvars[1].vval.v_list, TRUE) == FAIL)
err = TRUE;
}
else
{
size_t len;
char_u buf[NUMBUFLEN];
p = tv_get_string_buf_chk(&argvars[1], buf);
if (p == NULL)
{
fclose(fd);
goto errret; /* type error; errmsg already given */
}
len = STRLEN(p);
if (len > 0 && fwrite(p, len, 1, fd) != 1)
err = TRUE;
}
if (fclose(fd) != 0)
err = TRUE;
if (err)
{
emsg(_("E677: Error writing temp file"));
goto errret;
}
}
/* Omit SHELL_COOKED when invoked with ":silent". Avoids that the shell
* echoes typeahead, that messes up the display. */
if (!msg_silent)
flags += SHELL_COOKED;
if (retlist)
{
int len;
listitem_T *li;
char_u *s = NULL;
char_u *start;
char_u *end;
int i;
res = get_cmd_output(tv_get_string(&argvars[0]), infile, flags, &len);
if (res == NULL)
goto errret;
list = list_alloc();
if (list == NULL)
goto errret;
for (i = 0; i < len; ++i)
{
start = res + i;
while (i < len && res[i] != NL)
++i;
end = res + i;
s = alloc(end - start + 1);
if (s == NULL)
goto errret;
for (p = s; start < end; ++p, ++start)
*p = *start == NUL ? NL : *start;
*p = NUL;
li = listitem_alloc();
if (li == NULL)
{
vim_free(s);
goto errret;
}
li->li_tv.v_type = VAR_STRING;
li->li_tv.v_lock = 0;
li->li_tv.vval.v_string = s;
list_append(list, li);
}
rettv_list_set(rettv, list);
list = NULL;
}
else
{
res = get_cmd_output(tv_get_string(&argvars[0]), infile, flags, NULL);
#ifdef USE_CRNL
/* translate <CR><NL> into <NL> */
if (res != NULL)
{
char_u *s, *d;
d = res;
for (s = res; *s; ++s)
{
if (s[0] == CAR && s[1] == NL)
++s;
*d++ = *s;
}
*d = NUL;
}
#endif
rettv->vval.v_string = res;
res = NULL;
}
errret:
if (infile != NULL)
{
mch_remove(infile);
vim_free(infile);
}
if (res != NULL)
vim_free(res);
if (list != NULL)
list_free(list);
}
/*
* "system()" function
*/
static void
f_system(typval_T *argvars, typval_T *rettv)
{
get_cmd_output_as_rettv(argvars, rettv, FALSE);
}
/*
* "systemlist()" function
*/
static void
f_systemlist(typval_T *argvars, typval_T *rettv)
{
get_cmd_output_as_rettv(argvars, rettv, TRUE);
}
/*
* "tabpagebuflist()" function
*/