patch 8.1.1727: code for viminfo support is spread out

Problem:    Code for viminfo support is spread out.
Solution:   Move to code to viminfo.c. (Yegappan Lakshmanan, closes #4686)
This commit is contained in:
Bram Moolenaar 2019-07-21 19:25:37 +02:00
parent ed997adaa1
commit defa067c54
19 changed files with 1481 additions and 1452 deletions

View File

@ -110,6 +110,7 @@ SRC_ALL = \
src/version.c \
src/version.h \
src/vim.h \
src/viminfo.c \
src/winclip.c \
src/window.c \
src/tee/tee.c \
@ -234,6 +235,7 @@ SRC_ALL = \
src/proto/usercmd.pro \
src/proto/userfunc.pro \
src/proto/version.pro \
src/proto/viminfo.pro \
src/proto/winclip.pro \
src/proto/window.pro \
src/libvterm/.bzrignore \

View File

@ -772,6 +772,7 @@ OBJ = \
$(OUTDIR)/usercmd.o \
$(OUTDIR)/userfunc.o \
$(OUTDIR)/version.o \
$(OUTDIR)/viminfo.o \
$(OUTDIR)/winclip.o \
$(OUTDIR)/window.o

View File

@ -89,6 +89,7 @@ SRC = arabic.c \
usercmd.c \
userfunc.c \
version.c \
viminfo.c \
window.c \
OBJ = $(SRC:.c=.o)

View File

@ -780,6 +780,7 @@ OBJ = \
$(OUTDIR)\undo.obj \
$(OUTDIR)\usercmd.obj \
$(OUTDIR)\userfunc.obj \
$(OUTDIR)\viminfo.obj \
$(OUTDIR)\winclip.obj \
$(OUTDIR)\window.obj \
@ -1643,6 +1644,8 @@ $(OUTDIR)/usercmd.obj: $(OUTDIR) usercmd.c $(INCL)
$(OUTDIR)/userfunc.obj: $(OUTDIR) userfunc.c $(INCL)
$(OUTDIR)/viminfo.obj: $(OUTDIR) viminfo.c $(INCL)
$(OUTDIR)/window.obj: $(OUTDIR) window.c $(INCL)
$(OUTDIR)/xpm_w32.obj: $(OUTDIR) xpm_w32.c
@ -1798,6 +1801,7 @@ proto.h: \
proto/undo.pro \
proto/usercmd.pro \
proto/userfunc.pro \
proto/viminfo.pro \
proto/window.pro \
$(SOUND_PRO) \
$(NETBEANS_PRO) \

View File

@ -316,8 +316,8 @@ SRC = arabic.c autocmd.c beval.c blob.c blowfish.c buffer.c change.c charset.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 screen.c window.c os_unix.c \
os_vms.c pathdef.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)
@ -332,7 +332,7 @@ OBJ = arabic.obj autocmd.obj beval.obj blob.obj blowfish.obj buffer.obj change.
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 window.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)
@ -780,6 +780,10 @@ version.obj : version.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 version.h
viminfo.obj : viminfo.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 version.h
window.obj : window.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 \

View File

@ -1650,6 +1650,7 @@ BASIC_SRC = \
usercmd.c \
userfunc.c \
version.c \
viminfo.c \
window.c \
$(OS_EXTRA_SRC)
@ -1769,6 +1770,7 @@ OBJ_COMMON = \
objects/usercmd.o \
objects/userfunc.o \
objects/version.o \
objects/viminfo.o \
objects/window.o \
$(GUI_OBJ) \
$(TERM_OBJ) \
@ -1914,6 +1916,7 @@ PRO_AUTO = \
usercmd.pro \
userfunc.pro \
version.pro \
viminfo.pro \
window.pro \
beval.pro \
gui_beval.pro \
@ -3298,6 +3301,9 @@ objects/usercmd.o: usercmd.c
objects/userfunc.o: userfunc.c
$(CCC) -o $@ userfunc.c
objects/viminfo.o: viminfo.c
$(CCC) -o $@ viminfo.c
objects/window.o: window.c
$(CCC) -o $@ window.c
@ -3746,6 +3752,10 @@ objects/version.o: version.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 version.h
objects/viminfo.o: viminfo.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/window.o: window.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

@ -29,7 +29,6 @@
static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, int ignore_case);
static char_u *fname_match(regmatch_T *rmp, char_u *name, int ignore_case);
static void buflist_setfpos(buf_T *buf, win_T *win, linenr_T lnum, colnr_T col, int copy_options);
#ifdef UNIX
static buf_T *buflist_findname_stat(char_u *ffname, stat_T *st);
static int otherfile_buf(buf_T *buf, char_u *ffname, stat_T *stp);
@ -449,7 +448,8 @@ can_unload_buffer(buf_T *buf)
}
}
if (!can_unload)
emsg(_("E937: Attempt to delete a buffer that is in use"));
semsg(_("E937: Attempt to delete a buffer that is in use: %s"),
buf->b_fname);
return can_unload;
}
@ -2774,7 +2774,7 @@ buflist_nr2name(
* When "copy_options" is TRUE save the local window option values.
* When "lnum" is 0 only do the options.
*/
static void
void
buflist_setfpos(
buf_T *buf,
win_T *win,
@ -5545,112 +5545,6 @@ chk_modeline(
return retval;
}
#if defined(FEAT_VIMINFO) || defined(PROTO)
int
read_viminfo_bufferlist(
vir_T *virp,
int writing)
{
char_u *tab;
linenr_T lnum;
colnr_T col;
buf_T *buf;
char_u *sfname;
char_u *xline;
/* Handle long line and escaped characters. */
xline = viminfo_readstring(virp, 1, FALSE);
/* don't read in if there are files on the command-line or if writing: */
if (xline != NULL && !writing && ARGCOUNT == 0
&& find_viminfo_parameter('%') != NULL)
{
/* Format is: <fname> Tab <lnum> Tab <col>.
* Watch out for a Tab in the file name, work from the end. */
lnum = 0;
col = 0;
tab = vim_strrchr(xline, '\t');
if (tab != NULL)
{
*tab++ = '\0';
col = (colnr_T)atoi((char *)tab);
tab = vim_strrchr(xline, '\t');
if (tab != NULL)
{
*tab++ = '\0';
lnum = atol((char *)tab);
}
}
/* Expand "~/" in the file name at "line + 1" to a full path.
* Then try shortening it by comparing with the current directory */
expand_env(xline, NameBuff, MAXPATHL);
sfname = shorten_fname1(NameBuff);
buf = buflist_new(NameBuff, sfname, (linenr_T)0, BLN_LISTED);
if (buf != NULL) /* just in case... */
{
buf->b_last_cursor.lnum = lnum;
buf->b_last_cursor.col = col;
buflist_setfpos(buf, curwin, lnum, col, FALSE);
}
}
vim_free(xline);
return viminfo_readline(virp);
}
void
write_viminfo_bufferlist(FILE *fp)
{
buf_T *buf;
win_T *win;
tabpage_T *tp;
char_u *line;
int max_buffers;
if (find_viminfo_parameter('%') == NULL)
return;
/* Without a number -1 is returned: do all buffers. */
max_buffers = get_viminfo_parameter('%');
/* Allocate room for the file name, lnum and col. */
#define LINE_BUF_LEN (MAXPATHL + 40)
line = alloc(LINE_BUF_LEN);
if (line == NULL)
return;
FOR_ALL_TAB_WINDOWS(tp, win)
set_last_cursor(win);
fputs(_("\n# Buffer list:\n"), fp);
FOR_ALL_BUFFERS(buf)
{
if (buf->b_fname == NULL
|| !buf->b_p_bl
#ifdef FEAT_QUICKFIX
|| bt_quickfix(buf)
#endif
#ifdef FEAT_TERMINAL
|| bt_terminal(buf)
#endif
|| removable(buf->b_ffname))
continue;
if (max_buffers-- == 0)
break;
putc('%', fp);
home_replace(NULL, buf->b_ffname, line, MAXPATHL, TRUE);
vim_snprintf_add((char *)line, LINE_BUF_LEN, "\t%ld\t%d",
(long)buf->b_last_cursor.lnum,
buf->b_last_cursor.col);
viminfo_writestring(fp, line);
}
vim_free(line);
}
#endif
/*
* Return TRUE if "buf" is a normal buffer, 'buftype' is empty.
*/

View File

@ -36,7 +36,6 @@ static char *e_float_as_string = N_("E806: using Float as a String");
#define NAMESPACE_CHAR (char_u *)"abglstvw"
static dictitem_T globvars_var; /* variable used for g: */
#define globvarht globvardict.dv_hashtab
/*
* Old Vim variables such as "v:version" are also available without the "v:".
@ -9321,14 +9320,7 @@ script_autoload(
}
#if defined(FEAT_VIMINFO) || defined(FEAT_SESSION)
typedef enum
{
VAR_FLAVOUR_DEFAULT, /* doesn't start with uppercase */
VAR_FLAVOUR_SESSION, /* starts with uppercase, some lower */
VAR_FLAVOUR_VIMINFO /* all uppercase */
} var_flavour_T;
static var_flavour_T
var_flavour_T
var_flavour(char_u *varname)
{
char_u *p = varname;
@ -9345,161 +9337,6 @@ var_flavour(char_u *varname)
}
#endif
#if defined(FEAT_VIMINFO) || defined(PROTO)
/*
* Restore global vars that start with a capital from the viminfo file
*/
int
read_viminfo_varlist(vir_T *virp, int writing)
{
char_u *tab;
int type = VAR_NUMBER;
typval_T tv;
funccal_entry_T funccal_entry;
if (!writing && (find_viminfo_parameter('!') != NULL))
{
tab = vim_strchr(virp->vir_line + 1, '\t');
if (tab != NULL)
{
*tab++ = '\0'; /* isolate the variable name */
switch (*tab)
{
case 'S': type = VAR_STRING; break;
#ifdef FEAT_FLOAT
case 'F': type = VAR_FLOAT; break;
#endif
case 'D': type = VAR_DICT; break;
case 'L': type = VAR_LIST; break;
case 'B': type = VAR_BLOB; break;
case 'X': type = VAR_SPECIAL; break;
}
tab = vim_strchr(tab, '\t');
if (tab != NULL)
{
tv.v_type = type;
if (type == VAR_STRING || type == VAR_DICT
|| type == VAR_LIST || type == VAR_BLOB)
tv.vval.v_string = viminfo_readstring(virp,
(int)(tab - virp->vir_line + 1), TRUE);
#ifdef FEAT_FLOAT
else if (type == VAR_FLOAT)
(void)string2float(tab + 1, &tv.vval.v_float);
#endif
else
tv.vval.v_number = atol((char *)tab + 1);
if (type == VAR_DICT || type == VAR_LIST)
{
typval_T *etv = eval_expr(tv.vval.v_string, NULL);
if (etv == NULL)
/* Failed to parse back the dict or list, use it as a
* string. */
tv.v_type = VAR_STRING;
else
{
vim_free(tv.vval.v_string);
tv = *etv;
vim_free(etv);
}
}
else if (type == VAR_BLOB)
{
blob_T *blob = string2blob(tv.vval.v_string);
if (blob == NULL)
// Failed to parse back the blob, use it as a string.
tv.v_type = VAR_STRING;
else
{
vim_free(tv.vval.v_string);
tv.v_type = VAR_BLOB;
tv.vval.v_blob = blob;
}
}
/* when in a function use global variables */
save_funccal(&funccal_entry);
set_var(virp->vir_line + 1, &tv, FALSE);
restore_funccal();
if (tv.v_type == VAR_STRING)
vim_free(tv.vval.v_string);
else if (tv.v_type == VAR_DICT || tv.v_type == VAR_LIST ||
tv.v_type == VAR_BLOB)
clear_tv(&tv);
}
}
}
return viminfo_readline(virp);
}
/*
* Write global vars that start with a capital to the viminfo file
*/
void
write_viminfo_varlist(FILE *fp)
{
hashitem_T *hi;
dictitem_T *this_var;
int todo;
char *s = "";
char_u *p;
char_u *tofree;
char_u numbuf[NUMBUFLEN];
if (find_viminfo_parameter('!') == NULL)
return;
fputs(_("\n# global variables:\n"), fp);
todo = (int)globvarht.ht_used;
for (hi = globvarht.ht_array; todo > 0; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
--todo;
this_var = HI2DI(hi);
if (var_flavour(this_var->di_key) == VAR_FLAVOUR_VIMINFO)
{
switch (this_var->di_tv.v_type)
{
case VAR_STRING: s = "STR"; break;
case VAR_NUMBER: s = "NUM"; break;
case VAR_FLOAT: s = "FLO"; break;
case VAR_DICT: s = "DIC"; break;
case VAR_LIST: s = "LIS"; break;
case VAR_BLOB: s = "BLO"; break;
case VAR_SPECIAL: s = "XPL"; break;
case VAR_UNKNOWN:
case VAR_FUNC:
case VAR_PARTIAL:
case VAR_JOB:
case VAR_CHANNEL:
continue;
}
fprintf(fp, "!%s\t%s\t", this_var->di_key, s);
if (this_var->di_tv.v_type == VAR_SPECIAL)
{
sprintf((char *)numbuf, "%ld",
(long)this_var->di_tv.vval.v_number);
p = numbuf;
tofree = NULL;
}
else
p = echo_string(&this_var->di_tv, &tofree, numbuf, 0);
if (p != NULL)
viminfo_writestring(fp, p);
vim_free(tofree);
}
}
}
}
#endif
#if defined(FEAT_SESSION) || defined(PROTO)
int
store_session_globals(FILE *fd)

File diff suppressed because it is too large Load Diff

View File

@ -318,9 +318,7 @@ static int did_lcd; /* whether ":lcd" was produced for a session */
#ifndef FEAT_EVAL
# define ex_compiler ex_ni
#endif
#ifdef FEAT_VIMINFO
static void ex_viminfo(exarg_T *eap);
#else
#ifndef FEAT_VIMINFO
# define ex_viminfo ex_ni
#endif
static void ex_behave(exarg_T *eap);
@ -10713,31 +10711,6 @@ put_line(FILE *fd, char *s)
return OK;
}
#ifdef FEAT_VIMINFO
/*
* ":rviminfo" and ":wviminfo".
*/
static void
ex_viminfo(
exarg_T *eap)
{
char_u *save_viminfo;
save_viminfo = p_viminfo;
if (*p_viminfo == NUL)
p_viminfo = (char_u *)"'100";
if (eap->cmdidx == CMD_rviminfo)
{
if (read_viminfo(eap->arg, VIF_WANT_INFO | VIF_WANT_MARKS
| (eap->forceit ? VIF_FORCEIT : 0)) == FAIL)
emsg(_("E195: Cannot open viminfo file for reading"));
}
else
write_viminfo(eap->arg, eap->forceit);
p_viminfo = save_viminfo;
}
#endif
#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) || defined(PROTO)
/*
* Make a dialog message in "buff[DIALOG_MSG_SIZE]".

View File

@ -190,6 +190,7 @@ EXTERN int emsg_severe INIT(= FALSE); /* use message of next of several
EXTERN int did_endif INIT(= FALSE); /* just had ":endif" */
EXTERN dict_T vimvardict; /* Dictionary with v: variables */
EXTERN dict_T globvardict; /* Dictionary with g: variables */
#define globvarht globvardict.dv_hashtab
#endif
EXTERN int did_emsg; /* set by emsg() when the message
is displayed or thrown */

View File

@ -107,6 +107,9 @@ extern int _stricoll(char *a, char *b);
# ifdef FEAT_ARABIC
# include "arabic.pro"
# endif
# ifdef FEAT_VIMINFO
# include "viminfo.pro"
# endif
/* These prototypes cannot be produced automatically. */
int smsg(const char *, ...)

View File

@ -27,6 +27,7 @@ int buflist_findpat(char_u *pattern, char_u *pattern_end, int unlisted, int diff
int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options);
buf_T *buflist_findnr(int nr);
char_u *buflist_nr2name(int n, int fullname, int helptail);
void buflist_setfpos(buf_T *buf, win_T *win, linenr_T lnum, colnr_T col, int copy_options);
void get_winopts(buf_T *buf);
pos_T *buflist_findfpos(buf_T *buf);
linenr_T buflist_findlnum(buf_T *buf);
@ -55,8 +56,6 @@ char_u *alist_name(aentry_T *aep);
void do_arg_all(int count, int forceit, int keep_tabs);
void ex_buffer_all(exarg_T *eap);
void do_modelines(int flags);
int read_viminfo_bufferlist(vir_T *virp, int writing);
void write_viminfo_bufferlist(FILE *fp);
int bt_normal(buf_T *buf);
int bt_quickfix(buf_T *buf);
int bt_terminal(buf_T *buf);

View File

@ -126,8 +126,7 @@ 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);
int read_viminfo_varlist(vir_T *virp, int writing);
void write_viminfo_varlist(FILE *fp);
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);

View File

@ -10,13 +10,6 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out);
void do_shell(char_u *cmd, int flags);
char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp);
void append_redir(char_u *buf, int buflen, char_u *opt, char_u *fname);
int viminfo_error(char *errnum, char *message, char_u *line);
int read_viminfo(char_u *file, int flags);
void write_viminfo(char_u *file, int forceit);
int viminfo_readline(vir_T *virp);
char_u *viminfo_readstring(vir_T *virp, int off, int convert);
void viminfo_writestring(FILE *fd, char_u *p);
int barline_writestring(FILE *fd, char_u *s, int remaining_start);
time_T vim_time(void);
void do_fixdel(exarg_T *eap);
void print_line_no_prefix(linenr_T lnum, int use_number, int list);

10
src/proto/viminfo.pro Normal file
View File

@ -0,0 +1,10 @@
/* viminfo.c */
int viminfo_error(char *errnum, char *message, char_u *line);
int read_viminfo(char_u *file, int flags);
void write_viminfo(char_u *file, int forceit);
int viminfo_readline(vir_T *virp);
char_u *viminfo_readstring(vir_T *virp, int off, int convert);
void viminfo_writestring(FILE *fd, char_u *p);
int barline_writestring(FILE *fd, char_u *s, int remaining_start);
void ex_viminfo(exarg_T *eap);
/* vim: set ft=c : */

View File

@ -3725,6 +3725,14 @@ typedef enum {
CDSCOPE_WINDOW // :lcd
} cdscope_T;
// Variable flavor
typedef enum
{
VAR_FLAVOUR_DEFAULT, /* doesn't start with uppercase */
VAR_FLAVOUR_SESSION, /* starts with uppercase, some lower */
VAR_FLAVOUR_VIMINFO /* all uppercase */
} var_flavour_T;
// argument for mouse_find_win()
typedef enum {
IGNORE_POPUP, // only check non-popup windows

View File

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

1424
src/viminfo.c Normal file

File diff suppressed because it is too large Load Diff