/* vi:set ts=8 sts=4 sw=4 noet:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* session.c: session related functions
*/
#include "vim.h"
#if defined(FEAT_SESSION) || defined(PROTO)
static int did_lcd; // whether ":lcd" was produced for a session
/*
* Write a file name to the session file.
* Takes care of the "slash" option in 'sessionoptions' and escapes special
* characters.
* Returns FAIL if writing fails or out of memory.
*/
static int
ses_put_fname(FILE *fd, char_u *name, unsigned *flagp)
{
char_u *sname;
char_u *p;
int retval = OK;
sname = home_replace_save(NULL, name);
if (sname == NULL)
return FAIL;
if (*flagp & SSOP_SLASH)
{
// change all backslashes to forward slashes
for (p = sname; *p != NUL; MB_PTR_ADV(p))
if (*p == '\\')
*p = '/';
}
// escape special characters
p = vim_strsave_fnameescape(sname, VSE_NONE);
vim_free(sname);
if (p == NULL)
return FAIL;
// write the result
if (fputs((char *)p, fd) < 0)
retval = FAIL;
vim_free(p);
return retval;
}
/*
* Write a buffer name to the session file.
* Also ends the line, if "add_eol" is TRUE.
* Returns FAIL if writing fails.
*/
static int
ses_fname(