1
0
Fork 0
mirror of https://github.com/vim/vim synced 2025-03-30 06:26:45 +02:00

patch 8.1.1766: code for writing session file is spread out

Problem:    Code for writing session file is spread out.
Solution:   Put it in one file. (Yegappan Lakshmanan, closes )
This commit is contained in:
Bram Moolenaar 2019-07-28 14:15:42 +02:00
parent f91aac5e3e
commit 8453807911
16 changed files with 1401 additions and 1422 deletions

View file

@ -88,6 +88,7 @@ SRC_ALL = \
src/regexp.h \
src/screen.c \
src/search.c \
src/session.c \
src/sha256.c \
src/sign.c \
src/sound.c \
@ -218,6 +219,7 @@ SRC_ALL = \
src/proto/regexp.pro \
src/proto/screen.pro \
src/proto/search.pro \
src/proto/session.pro \
src/proto/sha256.pro \
src/proto/sign.pro \
src/proto/sound.pro \

View file

@ -758,6 +758,7 @@ OBJ = \
$(OUTDIR)/regexp.o \
$(OUTDIR)/screen.o \
$(OUTDIR)/search.o \
$(OUTDIR)/session.o \
$(OUTDIR)/sha256.o \
$(OUTDIR)/sign.o \
$(OUTDIR)/spell.o \

View file

@ -75,6 +75,7 @@ SRC = arabic.c \
regexp.c \
screen.c \
search.c \
session.c \
sha256.c \
sign.c \
spell.c \

View file

@ -767,6 +767,7 @@ OBJ = \
$(OUTDIR)\regexp.obj \
$(OUTDIR)\screen.obj \
$(OUTDIR)\search.obj \
$(OUTDIR)\session.obj \
$(OUTDIR)\sha256.obj \
$(OUTDIR)\sign.obj \
$(OUTDIR)\spell.obj \
@ -1618,6 +1619,8 @@ $(OUTDIR)/screen.obj: $(OUTDIR) screen.c $(INCL)
$(OUTDIR)/search.obj: $(OUTDIR) search.c $(INCL)
$(OUTDIR)/session.obj: $(OUTDIR) session.c $(INCL)
$(OUTDIR)/sha256.obj: $(OUTDIR) sha256.c $(INCL)
$(OUTDIR)/sign.obj: $(OUTDIR) sign.c $(INCL)
@ -1788,6 +1791,7 @@ proto.h: \
proto/regexp.pro \
proto/screen.pro \
proto/search.pro \
proto/session.pro \
proto/sha256.pro \
proto/sign.pro \
proto/spell.pro \

View file

@ -314,10 +314,10 @@ SRC = arabic.c autocmd.c beval.c blob.c blowfish.c buffer.c change.c charset.c \
hardcopy.c hashtab.c highlight.c indent.c insexpand.c json.c list.c \
main.c mark.c menu.c mbyte.c memfile.c memline.c message.c misc1.c \
misc2.c move.c normal.c ops.c option.c popupmnu.c popupwin.c \
profiler.c quickfix.c regexp.c search.c sha256.c sign.c spell.c \
spellfile.c syntax.c tag.c term.c termlib.c testing.c textprop.c ui.c \
undo.c usercmd.c userfunc.c version.c viminfo.c screen.c window.c \
os_unix.c os_vms.c pathdef.c \
profiler.c quickfix.c regexp.c search.c session.c sha256.c sign.c \
spell.c spellfile.c syntax.c tag.c term.c termlib.c testing.c \
textprop.c ui.c undo.c usercmd.c userfunc.c version.c viminfo.c \
screen.c window.c os_unix.c os_vms.c pathdef.c \
$(GUI_SRC) $(PERL_SRC) $(PYTHON_SRC) $(TCL_SRC) \
$(RUBY_SRC) $(HANGULIN_SRC) $(MZSCH_SRC) $(XDIFF_SRC)
@ -330,10 +330,10 @@ OBJ = arabic.obj autocmd.obj beval.obj blob.obj blowfish.obj buffer.obj change.
mark.obj menu.obj memfile.obj memline.obj message.obj misc1.obj \
misc2.obj move.obj mbyte.obj normal.obj ops.obj option.obj \
popupmnu.obj popupwin.obj profiler.obj quickfix.obj regexp.obj \
search.obj sha256.obj sign.obj spell.obj spellfile.obj syntax.obj \
tag.obj term.obj termlib.obj testing.obj textprop.obj ui.obj undo.obj \
usercmd.obj userfunc.obj screen.obj version.obj viminfo.obj window.obj \
os_unix.obj os_vms.obj pathdef.obj if_mzsch.obj \
search.obj session.obj sha256.obj sign.obj spell.obj spellfile.obj \
syntax.obj tag.obj term.obj termlib.obj testing.obj textprop.obj \
ui.obj undo.obj usercmd.obj userfunc.obj screen.obj version.obj \
viminfo.obj window.obj os_unix.obj os_vms.obj pathdef.obj if_mzsch.obj \
$(GUI_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(TCL_OBJ) \
$(RUBY_OBJ) $(HANGULIN_OBJ) $(MZSCH_OBJ) $(XDIFF_OBJ)
@ -718,6 +718,10 @@ search.obj : search.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h
session.obj : session.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h
sha256.obj : sha256.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
beval.h [.proto]gui_beval.pro alloc.h ex_cmds.h spell.h proto.h \

View file

@ -405,7 +405,7 @@ CClink = $(CC)
# Set PATH environment variable to find lua or luajit executable.
# This requires at least "normal" features, "tiny" and "small" don't work.
#CONF_OPT_LUA = --enable-luainterp
#CONF_OPT_LUA = --enable-luainterp=dynamic
CONF_OPT_LUA = --enable-luainterp=dynamic
#CONF_OPT_LUA = --enable-luainterp --with-luajit
#CONF_OPT_LUA = --enable-luainterp=dynamic --with-luajit
# Lua installation dir (when not set uses $LUA_PREFIX or defaults to /usr)
@ -431,7 +431,7 @@ CClink = $(CC)
# When you get an error for a missing "perl.exp" file, try creating an empty
# one: "touch perl.exp".
# This requires at least "normal" features, "tiny" and "small" don't work.
#CONF_OPT_PERL = --enable-perlinterp
CONF_OPT_PERL = --enable-perlinterp
#CONF_OPT_PERL = --enable-perlinterp=dynamic
# PYTHON
@ -445,10 +445,10 @@ CClink = $(CC)
# dlopen(), dlsym(), dlclose(), i.e. pythonX.Y.so must be available
# However, this may still cause problems, such as "import termios" failing.
# Build two separate versions of Vim in that case.
#CONF_OPT_PYTHON = --enable-pythoninterp
CONF_OPT_PYTHON = --enable-pythoninterp
#CONF_OPT_PYTHON = --enable-pythoninterp --with-python-command=python2.7
#CONF_OPT_PYTHON = --enable-pythoninterp=dynamic
#CONF_OPT_PYTHON3 = --enable-python3interp
CONF_OPT_PYTHON3 = --enable-python3interp
#CONF_OPT_PYTHON3 = --enable-python3interp --with-python3-command=python3.6
#CONF_OPT_PYTHON3 = --enable-python3interp=dynamic
@ -458,14 +458,14 @@ CClink = $(CC)
# Note: you need the development package (e.g., ruby1.9.1-dev on Ubuntu).
# This requires at least "normal" features, "tiny" and "small" don't work.
#CONF_OPT_RUBY = --enable-rubyinterp
#CONF_OPT_RUBY = --enable-rubyinterp=dynamic
CONF_OPT_RUBY = --enable-rubyinterp=dynamic
#CONF_OPT_RUBY = --enable-rubyinterp --with-ruby-command=ruby1.9.1
# TCL
# Uncomment this when you want to include the Tcl interface.
# First one is for static linking, second one for dynamic loading.
#CONF_OPT_TCL = --enable-tclinterp
#CONF_OPT_TCL = --enable-tclinterp=dynamic
CONF_OPT_TCL = --enable-tclinterp=dynamic
#CONF_OPT_TCL = --enable-tclinterp --with-tclsh=tclsh8.4
# CSCOPE
@ -541,7 +541,7 @@ CClink = $(CC)
#CONF_OPT_FEAT = --with-features=small
#CONF_OPT_FEAT = --with-features=normal
#CONF_OPT_FEAT = --with-features=big
#CONF_OPT_FEAT = --with-features=huge
CONF_OPT_FEAT = --with-features=huge
# COMPILED BY - For including a specific e-mail address for ":version".
#CONF_OPT_COMPBY = "--with-compiledby=John Doe <JohnDoe@yahoo.com>"
@ -615,7 +615,7 @@ CClink = $(CC)
# Use this with GCC to check for mistakes, unused arguments, etc.
# Note: If you use -Wextra and get warnings in GTK code about function
# parameters, you can add -Wno-cast-function-type
#CFLAGS = -g -Wall -Wextra -Wshadow -Wmissing-prototypes -Wunreachable-code -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
CFLAGS = -g -Wall -Wextra -Wshadow -Wmissing-prototypes -Wunreachable-code -Wno-cast-function-type -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
# Add -Wpedantic to find // comments and other C99 constructs.
# Better disable Perl and Python to avoid a lot of warnings.
#CFLAGS = -g -Wall -Wextra -Wshadow -Wmissing-prototypes -Wpedantic -Wunreachable-code -Wunused-result -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
@ -704,7 +704,7 @@ SANITIZER_LIBS = $(SANITIZER_CFLAGS)
# Configuration is in the .ccmalloc or ~/.ccmalloc file.
# Doesn't work very well, since memory linked to from global variables
# (in libraries) is also marked as leaked memory.
#LEAK_CFLAGS = -DEXITFREE
LEAK_CFLAGS = -DEXITFREE
#LEAK_LIBS = -lccmalloc
# Uncomment this line to have Vim call abort() when an internal error is
@ -1634,6 +1634,7 @@ BASIC_SRC = \
regexp.c \
screen.c \
search.c \
session.c \
sha256.c \
sign.c \
sound.c \
@ -1754,6 +1755,7 @@ OBJ_COMMON = \
objects/regexp.o \
objects/screen.o \
objects/search.o \
objects/session.o \
objects/sha256.o \
objects/sign.o \
objects/sound.o \
@ -1899,6 +1901,7 @@ PRO_AUTO = \
regexp.pro \
screen.pro \
search.pro \
session.pro \
sha256.pro \
sign.pro \
sound.pro \
@ -3256,6 +3259,9 @@ objects/screen.o: screen.c
objects/search.o: search.c
$(CCC) -o $@ search.c
objects/session.o: session.c
$(CCC) -o $@ session.c
objects/sha256.o: sha256.c
$(CCC) -o $@ sha256.c
@ -3686,6 +3692,10 @@ objects/search.o: search.c vim.h protodef.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
proto.h globals.h
objects/session.o: session.c vim.h protodef.h auto/config.h feature.h \
os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
proto.h globals.h
objects/sha256.o: sha256.c vim.h protodef.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \

View file

@ -52,6 +52,7 @@ quickfix.c | quickfix commands (":make", ":cn")
regexp.c | pattern matching
screen.c | updating the windows
search.c | pattern searching
session.c | sessions and views
sign.c | signs
spell.c | spell checking
syntax.c | syntax and other highlighting

View file

@ -9319,93 +9319,6 @@ script_autoload(
return ret;
}
#if defined(FEAT_VIMINFO) || defined(FEAT_SESSION)
var_flavour_T
var_flavour(char_u *varname)
{
char_u *p = varname;
if (ASCII_ISUPPER(*p))
{
while (*(++p))
if (ASCII_ISLOWER(*p))
return VAR_FLAVOUR_SESSION;
return VAR_FLAVOUR_VIMINFO;
}
else
return VAR_FLAVOUR_DEFAULT;
}
#endif
#if defined(FEAT_SESSION) || defined(PROTO)
int
store_session_globals(FILE *fd)
{
hashitem_T *hi;
dictitem_T *this_var;
int todo;
char_u *p, *t;
todo = (int)globvarht.ht_used;
for (hi = globvarht.ht_array; todo > 0; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
--todo;
this_var = HI2DI(hi);
if ((this_var->di_tv.v_type == VAR_NUMBER
|| this_var->di_tv.v_type == VAR_STRING)
&& var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION)
{
/* Escape special characters with a backslash. Turn a LF and
* CR into \n and \r. */
p = vim_strsave_escaped(tv_get_string(&this_var->di_tv),
(char_u *)"\\\"\n\r");
if (p == NULL) /* out of memory */
break;
for (t = p; *t != NUL; ++t)
if (*t == '\n')
*t = 'n';
else if (*t == '\r')
*t = 'r';
if ((fprintf(fd, "let %s = %c%s%c",
this_var->di_key,
(this_var->di_tv.v_type == VAR_STRING) ? '"'
: ' ',
p,
(this_var->di_tv.v_type == VAR_STRING) ? '"'
: ' ') < 0)
|| put_eol(fd) == FAIL)
{
vim_free(p);
return FAIL;
}
vim_free(p);
}
#ifdef FEAT_FLOAT
else if (this_var->di_tv.v_type == VAR_FLOAT
&& var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION)
{
float_T f = this_var->di_tv.vval.v_float;
int sign = ' ';
if (f < 0)
{
f = -f;
sign = '-';
}
if ((fprintf(fd, "let %s = %c%f",
this_var->di_key, sign, f) < 0)
|| put_eol(fd) == FAIL)
return FAIL;
}
#endif
}
}
return OK;
}
#endif
/*
* Display script name where an item was last set.
* Should only be invoked when 'verbose' is non-zero.

File diff suppressed because it is too large Load diff

View file

@ -4678,80 +4678,3 @@ build_argv_from_list(list_T *l, char ***argv, int *argc)
}
# endif
#endif
#if defined(FEAT_SESSION) || defined(PROTO)
/*
* Generate a script that can be used to restore the current editing session.
* Save the value of v:this_session before running :mksession in order to make
* automagic session save fully transparent. Return TRUE on success.
*/
int
write_session_file(char_u *filename)
{
char_u *escaped_filename;
char *mksession_cmdline;
unsigned int save_ssop_flags;
int failed;
/*
* Build an ex command line to create a script that restores the current
* session if executed. Escape the filename to avoid nasty surprises.
*/
escaped_filename = vim_strsave_escaped(filename, escape_chars);
if (escaped_filename == NULL)
return FALSE;
mksession_cmdline = alloc(10 + (int)STRLEN(escaped_filename) + 1);
if (mksession_cmdline == NULL)
{
vim_free(escaped_filename);
return FALSE;
}
strcpy(mksession_cmdline, "mksession ");
STRCAT(mksession_cmdline, escaped_filename);
vim_free(escaped_filename);
/*
* Use a reasonable hardcoded set of 'sessionoptions' flags to avoid
* unpredictable effects when the session is saved automatically. Also,
* we definitely need SSOP_GLOBALS to be able to restore v:this_session.
* Don't use SSOP_BUFFERS to prevent the buffer list from becoming
* enormously large if the GNOME session feature is used regularly.
*/
save_ssop_flags = ssop_flags;
ssop_flags = (SSOP_BLANK|SSOP_CURDIR|SSOP_FOLDS|SSOP_GLOBALS
|SSOP_HELP|SSOP_OPTIONS|SSOP_WINSIZE|SSOP_TABPAGES);
do_cmdline_cmd((char_u *)"let Save_VV_this_session = v:this_session");
failed = (do_cmdline_cmd((char_u *)mksession_cmdline) == FAIL);
do_cmdline_cmd((char_u *)"let v:this_session = Save_VV_this_session");
do_unlet((char_u *)"Save_VV_this_session", TRUE);
ssop_flags = save_ssop_flags;
vim_free(mksession_cmdline);
/*
* Reopen the file and append a command to restore v:this_session,
* as if this save never happened. This is to avoid conflicts with
* the user's own sessions. FIXME: It's probably less hackish to add
* a "stealth" flag to 'sessionoptions' -- gotta ask Bram.
*/
if (!failed)
{
FILE *fd;
fd = open_exfile(filename, TRUE, APPENDBIN);
failed = (fd == NULL
|| put_line(fd, "let v:this_session = Save_VV_this_session") == FAIL
|| put_line(fd, "unlet Save_VV_this_session") == FAIL);
if (fd != NULL && fclose(fd) != 0)
failed = TRUE;
if (failed)
mch_remove(filename);
}
return !failed;
}
#endif

View file

@ -183,6 +183,9 @@ void qsort(void *base, size_t elm_count, size_t elm_size, int (*cmp)(const void
# endif
# include "regexp.pro"
# include "screen.pro"
# ifdef FEAT_SESSION
# include "session.pro"
# endif
# if defined(FEAT_CRYPT) || defined(FEAT_PERSISTENT_UNDO)
# include "sha256.pro"
# endif

View file

@ -126,8 +126,6 @@ void getwinvar(typval_T *argvars, typval_T *rettv, int off);
void setwinvar(typval_T *argvars, typval_T *rettv, int off);
char_u *autoload_name(char_u *name);
int script_autoload(char_u *name, int reload);
var_flavour_T var_flavour(char_u *varname);
int store_session_globals(FILE *fd);
void last_set_msg(sctx_T script_ctx);
void reset_v_option_vars(void);
void assert_error(garray_T *gap);

View file

@ -108,5 +108,4 @@ void parse_queued_messages(void);
int mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc);
int build_argv_from_string(char_u *cmd, char ***argv, int *argc);
int build_argv_from_list(list_T *l, char ***argv, int *argc);
int write_session_file(char_u *filename);
/* vim: set ft=c : */

8
src/proto/session.pro Normal file
View file

@ -0,0 +1,8 @@
/* session.c */
void ex_loadview(exarg_T *eap);
int write_session_file(char_u *filename);
void ex_mkrc(exarg_T *eap);
var_flavour_T var_flavour(char_u *varname);
int put_eol(FILE *fd);
int put_line(FILE *fd, char *s);
/* vim: set ft=c : */

1346
src/session.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -777,6 +777,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1766,
/**/
1765,
/**/