0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.1.1927: code for dealing with script files is spread out

Problem:    Code for dealing with script files is spread out.
Solution:   Move the code to scriptfile.c. (Yegappan Lakshmanan, closes #4861)
This commit is contained in:
Bram Moolenaar
2019-08-25 15:41:00 +02:00
parent c2b97643a8
commit 307c5a5bb7
14 changed files with 1751 additions and 1732 deletions

View File

@@ -90,6 +90,7 @@ SRC_ALL = \
src/regexp.c \ src/regexp.c \
src/regexp_nfa.c \ src/regexp_nfa.c \
src/regexp.h \ src/regexp.h \
src/scriptfile.c \
src/screen.c \ src/screen.c \
src/search.c \ src/search.c \
src/session.c \ src/session.c \
@@ -225,6 +226,7 @@ SRC_ALL = \
src/proto/profiler.pro \ src/proto/profiler.pro \
src/proto/quickfix.pro \ src/proto/quickfix.pro \
src/proto/regexp.pro \ src/proto/regexp.pro \
src/proto/scriptfile.pro \
src/proto/screen.pro \ src/proto/screen.pro \
src/proto/search.pro \ src/proto/search.pro \
src/proto/session.pro \ src/proto/session.pro \

View File

@@ -760,6 +760,7 @@ OBJ = \
$(OUTDIR)/profiler.o \ $(OUTDIR)/profiler.o \
$(OUTDIR)/quickfix.o \ $(OUTDIR)/quickfix.o \
$(OUTDIR)/regexp.o \ $(OUTDIR)/regexp.o \
$(OUTDIR)/scriptfile.o \
$(OUTDIR)/screen.o \ $(OUTDIR)/screen.o \
$(OUTDIR)/search.o \ $(OUTDIR)/search.o \
$(OUTDIR)/session.o \ $(OUTDIR)/session.o \

View File

@@ -77,6 +77,7 @@ SRC = arabic.c \
profiler.c \ profiler.c \
quickfix.c \ quickfix.c \
regexp.c \ regexp.c \
scriptfile.c \
screen.c \ screen.c \
search.c \ search.c \
session.c \ session.c \

View File

@@ -769,6 +769,7 @@ OBJ = \
$(OUTDIR)\profiler.obj \ $(OUTDIR)\profiler.obj \
$(OUTDIR)\quickfix.obj \ $(OUTDIR)\quickfix.obj \
$(OUTDIR)\regexp.obj \ $(OUTDIR)\regexp.obj \
$(OUTDIR)\scriptfile.obj \
$(OUTDIR)\screen.obj \ $(OUTDIR)\screen.obj \
$(OUTDIR)\search.obj \ $(OUTDIR)\search.obj \
$(OUTDIR)\session.obj \ $(OUTDIR)\session.obj \
@@ -1627,6 +1628,8 @@ $(OUTDIR)/quickfix.obj: $(OUTDIR) quickfix.c $(INCL)
$(OUTDIR)/regexp.obj: $(OUTDIR) regexp.c regexp_nfa.c $(INCL) $(OUTDIR)/regexp.obj: $(OUTDIR) regexp.c regexp_nfa.c $(INCL)
$(OUTDIR)/scriptfile.obj: $(OUTDIR) scriptfile.c $(INCL)
$(OUTDIR)/screen.obj: $(OUTDIR) screen.c $(INCL) $(OUTDIR)/screen.obj: $(OUTDIR) screen.c $(INCL)
$(OUTDIR)/search.obj: $(OUTDIR) search.c $(INCL) $(OUTDIR)/search.obj: $(OUTDIR) search.c $(INCL)
@@ -1805,6 +1808,7 @@ proto.h: \
proto/profiler.pro \ proto/profiler.pro \
proto/quickfix.pro \ proto/quickfix.pro \
proto/regexp.pro \ proto/regexp.pro \
proto/scriptfile.pro \
proto/screen.pro \ proto/screen.pro \
proto/search.pro \ proto/search.pro \
proto/session.pro \ proto/session.pro \

View File

@@ -315,6 +315,7 @@ SRC = arabic.c arglist.c autocmd.c beval.c blob.c blowfish.c buffer.c \
indent.c insexpand.c json.c list.c main.c map.c mark.c menu.c mbyte.c \ indent.c insexpand.c json.c list.c main.c map.c mark.c menu.c mbyte.c \
memfile.c memline.c message.c misc1.c misc2.c move.c normal.c ops.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 \ option.c popupmnu.c popupwin.c profiler.c quickfix.c regexp.c \
scriptfile.c \
search.c session.c sha256.c sign.c spell.c spellfile.c syntax.c tag.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 \ 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 \ userfunc.c version.c viminfo.c screen.c window.c os_unix.c os_vms.c \
@@ -332,6 +333,7 @@ OBJ = arabic.obj arglist.obj autocmd.obj beval.obj blob.obj blowfish.obj \
map.obj mark.obj menu.obj memfile.obj memline.obj message.obj \ map.obj mark.obj menu.obj memfile.obj memline.obj message.obj \
misc1.obj misc2.obj move.obj mbyte.obj normal.obj ops.obj option.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 \ popupmnu.obj popupwin.obj profiler.obj quickfix.obj regexp.obj \
scriptfile.obj \
search.obj session.obj sha256.obj sign.obj spell.obj spellfile.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 \ syntax.obj tag.obj term.obj termlib.obj testing.obj textprop.obj \
ui.obj undo.obj usercmd.obj userfunc.obj screen.obj version.obj \ ui.obj undo.obj usercmd.obj userfunc.obj screen.obj version.obj \
@@ -724,6 +726,10 @@ regexp.obj : regexp.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.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 \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h globals.h
scriptfile.obj : scriptfile.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
screen.obj : screen.c vim.h [.auto]config.h feature.h os_unix.h \ screen.obj : screen.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.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 \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \

View File

@@ -1636,6 +1636,7 @@ BASIC_SRC = \
pty.c \ pty.c \
quickfix.c \ quickfix.c \
regexp.c \ regexp.c \
scriptfile.c \
screen.c \ screen.c \
search.c \ search.c \
session.c \ session.c \
@@ -1761,6 +1762,7 @@ OBJ_COMMON = \
objects/pty.o \ objects/pty.o \
objects/quickfix.o \ objects/quickfix.o \
objects/regexp.o \ objects/regexp.o \
objects/scriptfile.o \
objects/screen.o \ objects/screen.o \
objects/search.o \ objects/search.o \
objects/session.o \ objects/session.o \
@@ -1911,6 +1913,7 @@ PRO_AUTO = \
pty.pro \ pty.pro \
quickfix.pro \ quickfix.pro \
regexp.pro \ regexp.pro \
scriptfile.pro \
screen.pro \ screen.pro \
search.pro \ search.pro \
session.pro \ session.pro \
@@ -3277,6 +3280,9 @@ objects/quickfix.o: quickfix.c
objects/regexp.o: regexp.c regexp_nfa.c objects/regexp.o: regexp.c regexp_nfa.c
$(CCC) -o $@ regexp.c $(CCC) -o $@ regexp.c
objects/scriptfile.o: scriptfile.c
$(CCC) -o $@ scriptfile.c
objects/screen.o: screen.c objects/screen.o: screen.c
$(CCC) -o $@ screen.c $(CCC) -o $@ screen.c
@@ -3724,6 +3730,10 @@ objects/regexp.o: regexp.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 \ 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/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
proto.h globals.h regexp_nfa.c proto.h globals.h regexp_nfa.c
objects/scriptfile.o: scriptfile.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/screen.o: screen.c vim.h protodef.h auto/config.h feature.h os_unix.h \ objects/screen.o: screen.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 \ 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/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \

View File

@@ -55,6 +55,7 @@ popupwin.c | popup window
profiler.c | vim script profiler profiler.c | vim script profiler
quickfix.c | quickfix commands (":make", ":cn") quickfix.c | quickfix commands (":make", ":cn")
regexp.c | pattern matching regexp.c | pattern matching
scriptfile.c | runtime directory handling and sourcing scripts
screen.c | updating the windows screen.c | updating the windows
search.c | pattern searching search.c | pattern searching
session.c | sessions and views session.c | sessions and views

View File

@@ -19,8 +19,6 @@ static void set_expand_context(expand_T *xp);
static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int); static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int);
static int expand_showtail(expand_T *xp); static int expand_showtail(expand_T *xp);
static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg); static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg);
static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]);
static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file);
#if defined(FEAT_EVAL) #if defined(FEAT_EVAL)
static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file); static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file);
static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file); static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file);
@@ -2564,160 +2562,6 @@ ExpandUserList(
} }
# endif # endif
/*
* Expand color scheme, compiler or filetype names.
* Search from 'runtimepath':
* 'runtimepath'/{dirnames}/{pat}.vim
* When "flags" has DIP_START: search also from 'start' of 'packpath':
* 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim
* When "flags" has DIP_OPT: search also from 'opt' of 'packpath':
* 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim
* "dirnames" is an array with one or more directory names.
*/
static int
ExpandRTDir(
char_u *pat,
int flags,
int *num_file,
char_u ***file,
char *dirnames[])
{
char_u *s;
char_u *e;
char_u *match;
garray_T ga;
int i;
int pat_len;
*num_file = 0;
*file = NULL;
pat_len = (int)STRLEN(pat);
ga_init2(&ga, (int)sizeof(char *), 10);
for (i = 0; dirnames[i] != NULL; ++i)
{
s = alloc(STRLEN(dirnames[i]) + pat_len + 7);
if (s == NULL)
{
ga_clear_strings(&ga);
return FAIL;
}
sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat);
globpath(p_rtp, s, &ga, 0);
vim_free(s);
}
if (flags & DIP_START) {
for (i = 0; dirnames[i] != NULL; ++i)
{
s = alloc(STRLEN(dirnames[i]) + pat_len + 22);
if (s == NULL)
{
ga_clear_strings(&ga);
return FAIL;
}
sprintf((char *)s, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat);
globpath(p_pp, s, &ga, 0);
vim_free(s);
}
}
if (flags & DIP_OPT) {
for (i = 0; dirnames[i] != NULL; ++i)
{
s = alloc(STRLEN(dirnames[i]) + pat_len + 20);
if (s == NULL)
{
ga_clear_strings(&ga);
return FAIL;
}
sprintf((char *)s, "pack/*/opt/*/%s/%s*.vim", dirnames[i], pat);
globpath(p_pp, s, &ga, 0);
vim_free(s);
}
}
for (i = 0; i < ga.ga_len; ++i)
{
match = ((char_u **)ga.ga_data)[i];
s = match;
e = s + STRLEN(s);
if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0)
{
e -= 4;
for (s = e; s > match; MB_PTR_BACK(match, s))
if (s < match || vim_ispathsep(*s))
break;
++s;
*e = NUL;
mch_memmove(match, s, e - s + 1);
}
}
if (ga.ga_len == 0)
return FAIL;
// Sort and remove duplicates which can happen when specifying multiple
// directories in dirnames.
remove_duplicates(&ga);
*file = ga.ga_data;
*num_file = ga.ga_len;
return OK;
}
/*
* Expand loadplugin names:
* 'packpath'/pack/ * /opt/{pat}
*/
static int
ExpandPackAddDir(
char_u *pat,
int *num_file,
char_u ***file)
{
char_u *s;
char_u *e;
char_u *match;
garray_T ga;
int i;
int pat_len;
*num_file = 0;
*file = NULL;
pat_len = (int)STRLEN(pat);
ga_init2(&ga, (int)sizeof(char *), 10);
s = alloc(pat_len + 26);
if (s == NULL)
{
ga_clear_strings(&ga);
return FAIL;
}
sprintf((char *)s, "pack/*/opt/%s*", pat);
globpath(p_pp, s, &ga, 0);
vim_free(s);
for (i = 0; i < ga.ga_len; ++i)
{
match = ((char_u **)ga.ga_data)[i];
s = gettail(match);
e = s + STRLEN(s);
mch_memmove(match, s, e - s + 1);
}
if (ga.ga_len == 0)
return FAIL;
// Sort and remove duplicates which can happen when specifying multiple
// directories in dirnames.
remove_duplicates(&ga);
*file = ga.ga_data;
*num_file = ga.ga_len;
return OK;
}
/* /*
* Expand "file" for all comma-separated directories in "path". * Expand "file" for all comma-separated directories in "path".
* Adds the matches to "ga". Caller must init "ga". * Adds the matches to "ga". Caller must init "ga".

File diff suppressed because it is too large Load Diff

View File

@@ -184,6 +184,7 @@ void qsort(void *base, size_t elm_count, size_t elm_size, int (*cmp)(const void
# include "quickfix.pro" # include "quickfix.pro"
# endif # endif
# include "regexp.pro" # include "regexp.pro"
# include "scriptfile.pro"
# include "screen.pro" # include "screen.pro"
# include "session.pro" # include "session.pro"
# if defined(FEAT_CRYPT) || defined(FEAT_PERSISTENT_UNDO) # if defined(FEAT_CRYPT) || defined(FEAT_PERSISTENT_UNDO)

View File

@@ -20,36 +20,10 @@ int check_fname(void);
int buf_write_all(buf_T *buf, int forceit); int buf_write_all(buf_T *buf, int forceit);
void ex_listdo(exarg_T *eap); void ex_listdo(exarg_T *eap);
void ex_compiler(exarg_T *eap); void ex_compiler(exarg_T *eap);
void ex_runtime(exarg_T *eap);
int do_in_path(char_u *path, char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie);
int do_in_runtimepath(char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie);
int source_runtime(char_u *name, int flags);
int source_in_path(char_u *path, char_u *name, int flags);
void add_pack_start_dirs(void);
void load_start_packages(void);
void ex_packloadall(exarg_T *eap);
void ex_packadd(exarg_T *eap);
void ex_options(exarg_T *eap);
void init_pyxversion(void); void init_pyxversion(void);
void ex_pyxfile(exarg_T *eap); void ex_pyxfile(exarg_T *eap);
void ex_pyx(exarg_T *eap); void ex_pyx(exarg_T *eap);
void ex_pyxdo(exarg_T *eap); void ex_pyxdo(exarg_T *eap);
void ex_source(exarg_T *eap);
linenr_T *source_breakpoint(void *cookie);
int *source_dbg_tick(void *cookie);
int source_level(void *cookie);
int do_source(char_u *fname, int check_other, int is_vimrc);
void ex_scriptnames(exarg_T *eap);
void scriptnames_slash_adjust(void);
char_u *get_scriptname(scid_T id);
void free_scriptnames(void);
linenr_T get_sourced_lnum(char_u *(*fgetline)(int, void *, int, int), void *cookie);
char_u *getsourceline(int c, void *cookie, int indent, int do_concat);
void ex_scriptencoding(exarg_T *eap);
void ex_scriptversion(exarg_T *eap);
void ex_finish(exarg_T *eap);
void do_finish(exarg_T *eap, int reanimate);
int source_finished(char_u *(*fgetline)(int, void *, int, int), void *cookie);
void ex_checktime(exarg_T *eap); void ex_checktime(exarg_T *eap);
char_u *get_mess_lang(void); char_u *get_mess_lang(void);
void set_lang_var(void); void set_lang_var(void);

30
src/proto/scriptfile.pro Normal file
View File

@@ -0,0 +1,30 @@
/* scriptfile.c */
void ex_runtime(exarg_T *eap);
int do_in_path(char_u *path, char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie);
int do_in_runtimepath(char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie);
int source_runtime(char_u *name, int flags);
int source_in_path(char_u *path, char_u *name, int flags);
void add_pack_start_dirs(void);
void load_start_packages(void);
void ex_packloadall(exarg_T *eap);
void ex_packadd(exarg_T *eap);
int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirnames[]);
int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file);
void ex_source(exarg_T *eap);
void ex_options(exarg_T *eap);
linenr_T *source_breakpoint(void *cookie);
int *source_dbg_tick(void *cookie);
int source_level(void *cookie);
int do_source(char_u *fname, int check_other, int is_vimrc);
void ex_scriptnames(exarg_T *eap);
void scriptnames_slash_adjust(void);
char_u *get_scriptname(scid_T id);
void free_scriptnames(void);
linenr_T get_sourced_lnum(char_u *(*fgetline)(int, void *, int, int), void *cookie);
char_u *getsourceline(int c, void *cookie, int indent, int do_concat);
void ex_scriptencoding(exarg_T *eap);
void ex_scriptversion(exarg_T *eap);
void ex_finish(exarg_T *eap);
void do_finish(exarg_T *eap, int reanimate);
int source_finished(char_u *(*fgetline)(int, void *, int, int), void *cookie);
/* vim: set ft=c : */

1693
src/scriptfile.c Normal file

File diff suppressed because it is too large Load Diff

View File

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