annotate src/scriptfile.c @ 18080:a6d218f99ff7 v8.1.2035

patch 8.1.2035: recognizing octal numbers is confusing Commit: https://github.com/vim/vim/commit/60a8de28d11595f4df0419ece8afa7d6accc9fbd Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 15 14:33:22 2019 +0200 patch 8.1.2035: recognizing octal numbers is confusing Problem: Recognizing octal numbers is confusing. Solution: Introduce scriptversion 4: do not use octal and allow for single quote inside numbers.
author Bram Moolenaar <Bram@vim.org>
date Sun, 15 Sep 2019 14:45:04 +0200
parents 8f4cc259ed7a
children 6c3a8312486d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17861
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * scriptfile.c: functions for dealing with the runtime directories/files
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
16 #if defined(FEAT_EVAL) || defined(PROTO)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
17 // The names of packages that once were loaded are remembered.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
18 static garray_T ga_loaded = {0, 0, sizeof(char_u *), 4, NULL};
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
19 #endif
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
20
17861
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 * ":runtime [what] {name}"
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 ex_runtime(exarg_T *eap)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 char_u *arg = eap->arg;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 char_u *p = skiptowhite(arg);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 int len = (int)(p - arg);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 int flags = eap->forceit ? DIP_ALL : 0;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 if (STRNCMP(arg, "START", len) == 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 flags += DIP_START + DIP_NORTP;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 arg = skipwhite(arg + len);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 else if (STRNCMP(arg, "OPT", len) == 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 flags += DIP_OPT + DIP_NORTP;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 arg = skipwhite(arg + len);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 else if (STRNCMP(arg, "PACK", len) == 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 flags += DIP_START + DIP_OPT + DIP_NORTP;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 arg = skipwhite(arg + len);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 else if (STRNCMP(arg, "ALL", len) == 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 flags += DIP_START + DIP_OPT;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 arg = skipwhite(arg + len);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 source_runtime(arg, flags);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 static void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 source_callback(char_u *fname, void *cookie UNUSED)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 (void)do_source(fname, FALSE, DOSO_NONE);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 * Find the file "name" in all directories in "path" and invoke
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 * "callback(fname, cookie)".
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 * "name" can contain wildcards.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 * When "flags" has DIP_ALL: source all files, otherwise only the first one.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 * When "flags" has DIP_DIR: find directories instead of files.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 * When "flags" has DIP_ERR: give an error message if there is no match.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 * return FAIL when no file could be sourced, OK otherwise.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 int
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 do_in_path(
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 char_u *path,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 char_u *name,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 int flags,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 void (*callback)(char_u *fname, void *ck),
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 void *cookie)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 char_u *rtp;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 char_u *np;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 char_u *buf;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 char_u *rtp_copy;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 char_u *tail;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 int num_files;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 char_u **files;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 int i;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 int did_one = FALSE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 #ifdef AMIGA
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 struct Process *proc = (struct Process *)FindTask(0L);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 APTR save_winptr = proc->pr_WindowPtr;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 // Avoid a requester here for a volume that doesn't exist.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 proc->pr_WindowPtr = (APTR)-1L;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 // Make a copy of 'runtimepath'. Invoking the callback may change the
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 // value.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 rtp_copy = vim_strsave(path);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 buf = alloc(MAXPATHL);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 if (buf != NULL && rtp_copy != NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 if (p_verbose > 1 && name != NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 verbose_enter();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 smsg(_("Searching for \"%s\" in \"%s\""),
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 (char *)name, (char *)path);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 verbose_leave();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 // Loop over all entries in 'runtimepath'.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 rtp = rtp_copy;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 while (*rtp != NUL && ((flags & DIP_ALL) || !did_one))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 size_t buflen;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 // Copy the path from 'runtimepath' to buf[].
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 copy_option_part(&rtp, buf, MAXPATHL, ",");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 buflen = STRLEN(buf);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 // Skip after or non-after directories.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 if (flags & (DIP_NOAFTER | DIP_AFTER))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 int is_after = buflen >= 5
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 && STRCMP(buf + buflen - 5, "after") == 0;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 if ((is_after && (flags & DIP_NOAFTER))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 || (!is_after && (flags & DIP_AFTER)))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 continue;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 if (name == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 (*callback)(buf, (void *) &cookie);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 if (!did_one)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 did_one = (cookie == NULL);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 else if (buflen + STRLEN(name) + 2 < MAXPATHL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 add_pathsep(buf);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 tail = buf + STRLEN(buf);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 // Loop over all patterns in "name"
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 np = name;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 while (*np != NUL && ((flags & DIP_ALL) || !did_one))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 // Append the pattern from "name" to buf[].
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 copy_option_part(&np, tail, (int)(MAXPATHL - (tail - buf)),
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 "\t ");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 if (p_verbose > 2)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 verbose_enter();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 smsg(_("Searching for \"%s\""), buf);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 verbose_leave();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 // Expand wildcards, invoke the callback for each match.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 if (gen_expand_wildcards(1, &buf, &num_files, &files,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 (flags & DIP_DIR) ? EW_DIR : EW_FILE) == OK)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 for (i = 0; i < num_files; ++i)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 (*callback)(files[i], cookie);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 did_one = TRUE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 if (!(flags & DIP_ALL))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 break;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 FreeWild(num_files, files);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 vim_free(buf);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 vim_free(rtp_copy);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 if (!did_one && name != NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 char *basepath = path == p_rtp ? "runtimepath" : "packpath";
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 if (flags & DIP_ERR)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 semsg(_(e_dirnotf), basepath, name);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 else if (p_verbose > 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 verbose_enter();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 smsg(_("not found in '%s': \"%s\""), basepath, name);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 verbose_leave();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 #ifdef AMIGA
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 proc->pr_WindowPtr = save_winptr;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 return did_one ? OK : FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 * Find "name" in "path". When found, invoke the callback function for
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 * it: callback(fname, "cookie")
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 * When "flags" has DIP_ALL repeat for all matches, otherwise only the first
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 * one is used.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 * Returns OK when at least one match found, FAIL otherwise.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 * If "name" is NULL calls callback for each entry in "path". Cookie is
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 * passed by reference in this case, setting it to NULL indicates that callback
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 * has done its job.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 static int
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 do_in_path_and_pp(
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 char_u *path,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 char_u *name,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 int flags,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 void (*callback)(char_u *fname, void *ck),
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 void *cookie)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 int done = FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 char_u *s;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 int len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 char *start_dir = "pack/*/start/*/%s";
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 char *opt_dir = "pack/*/opt/*/%s";
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 if ((flags & DIP_NORTP) == 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 done = do_in_path(path, name, flags, callback, cookie);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 len = (int)(STRLEN(start_dir) + STRLEN(name));
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 s = alloc(len);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 if (s == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 return FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 vim_snprintf((char *)s, len, start_dir, name);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 done = do_in_path(p_pp, s, flags, callback, cookie);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 vim_free(s);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_OPT))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 len = (int)(STRLEN(opt_dir) + STRLEN(name));
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 s = alloc(len);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 if (s == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 return FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 vim_snprintf((char *)s, len, opt_dir, name);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 done = do_in_path(p_pp, s, flags, callback, cookie);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 vim_free(s);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 return done;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 * Just like do_in_path_and_pp(), using 'runtimepath' for "path".
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 int
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 do_in_runtimepath(
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 char_u *name,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 int flags,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 void (*callback)(char_u *fname, void *ck),
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 void *cookie)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 return do_in_path_and_pp(p_rtp, name, flags, callback, cookie);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 * Source the file "name" from all directories in 'runtimepath'.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 * "name" can contain wildcards.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 * When "flags" has DIP_ALL: source all files, otherwise only the first one.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 * return FAIL when no file could be sourced, OK otherwise.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 int
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 source_runtime(char_u *name, int flags)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 return source_in_path(p_rtp, name, flags);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 * Just like source_runtime(), but use "path" instead of 'runtimepath'.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 int
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 source_in_path(char_u *path, char_u *name, int flags)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 return do_in_path_and_pp(path, name, flags, source_callback, NULL);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 #if defined(FEAT_EVAL) || defined(PROTO)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 * Expand wildcards in "pat" and invoke do_source() for each match.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 static void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 source_all_matches(char_u *pat)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 int num_files;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 char_u **files;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 int i;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) == OK)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 for (i = 0; i < num_files; ++i)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 (void)do_source(files[i], FALSE, DOSO_NONE);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 FreeWild(num_files, files);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 * Add the package directory to 'runtimepath'.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 static int
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 add_pack_dir_to_rtp(char_u *fname)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 char_u *p4, *p3, *p2, *p1, *p;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 char_u *entry;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 char_u *insp = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 int c;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 char_u *new_rtp;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 int keep;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 size_t oldlen;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 size_t addlen;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 size_t new_rtp_len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 char_u *afterdir = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 size_t afterlen = 0;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 char_u *after_insp = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 char_u *ffname = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 size_t fname_len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 char_u *buf = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 char_u *rtp_ffname;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 int match;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 int retval = FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 p4 = p3 = p2 = p1 = get_past_head(fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 for (p = p1; *p; MB_PTR_ADV(p))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 if (vim_ispathsep_nocolon(*p))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 p4 = p3; p3 = p2; p2 = p1; p1 = p;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 // now we have:
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 // rtp/pack/name/start/name
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 // p4 p3 p2 p1
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 //
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 // find the part up to "pack" in 'runtimepath'
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 c = *++p4; // append pathsep in order to expand symlink
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 *p4 = NUL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 ffname = fix_fname(fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 *p4 = c;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 if (ffname == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 return FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 // Find "ffname" in "p_rtp", ignoring '/' vs '\' differences.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 // Also stop at the first "after" directory.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 fname_len = STRLEN(ffname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 buf = alloc(MAXPATHL);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 if (buf == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 goto theend;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 for (entry = p_rtp; *entry != NUL; )
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 char_u *cur_entry = entry;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 copy_option_part(&entry, buf, MAXPATHL, ",");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 if (insp == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 add_pathsep(buf);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 rtp_ffname = fix_fname(buf);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 if (rtp_ffname == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 goto theend;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 vim_free(rtp_ffname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 if (match)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 // Insert "ffname" after this entry (and comma).
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 insp = entry;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 if ((p = (char_u *)strstr((char *)buf, "after")) != NULL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 && p > buf
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 && vim_ispathsep(p[-1])
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 && (vim_ispathsep(p[5]) || p[5] == NUL || p[5] == ','))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 if (insp == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 // Did not find "ffname" before the first "after" directory,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 // insert it before this entry.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 insp = cur_entry;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 after_insp = cur_entry;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 break;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 if (insp == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 // Both "fname" and "after" not found, append at the end.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 insp = p_rtp + STRLEN(p_rtp);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 // check if rtp/pack/name/start/name/after exists
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 afterdir = concat_fnames(fname, (char_u *)"after", TRUE);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 if (afterdir != NULL && mch_isdir(afterdir))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 afterlen = STRLEN(afterdir) + 1; // add one for comma
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 oldlen = STRLEN(p_rtp);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 addlen = STRLEN(fname) + 1; // add one for comma
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 new_rtp = alloc(oldlen + addlen + afterlen + 1); // add one for NUL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 if (new_rtp == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 goto theend;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 // We now have 'rtp' parts: {keep}{keep_after}{rest}.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 // Create new_rtp, first: {keep},{fname}
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 keep = (int)(insp - p_rtp);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 mch_memmove(new_rtp, p_rtp, keep);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 new_rtp_len = keep;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 if (*insp == NUL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 new_rtp[new_rtp_len++] = ','; // add comma before
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 mch_memmove(new_rtp + new_rtp_len, fname, addlen - 1);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 new_rtp_len += addlen - 1;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 if (*insp != NUL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 new_rtp[new_rtp_len++] = ','; // add comma after
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 if (afterlen > 0 && after_insp != NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 int keep_after = (int)(after_insp - p_rtp);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 // Add to new_rtp: {keep},{fname}{keep_after},{afterdir}
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 mch_memmove(new_rtp + new_rtp_len, p_rtp + keep,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 keep_after - keep);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 new_rtp_len += keep_after - keep;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 mch_memmove(new_rtp + new_rtp_len, afterdir, afterlen - 1);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 new_rtp_len += afterlen - 1;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 new_rtp[new_rtp_len++] = ',';
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 keep = keep_after;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 if (p_rtp[keep] != NUL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 // Append rest: {keep},{fname}{keep_after},{afterdir}{rest}
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 mch_memmove(new_rtp + new_rtp_len, p_rtp + keep, oldlen - keep + 1);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 new_rtp[new_rtp_len] = NUL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 if (afterlen > 0 && after_insp == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 // Append afterdir when "after" was not found:
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 // {keep},{fname}{rest},{afterdir}
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 STRCAT(new_rtp, ",");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 STRCAT(new_rtp, afterdir);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 set_option_value((char_u *)"rtp", 0L, new_rtp, 0);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 vim_free(new_rtp);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 retval = OK;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 theend:
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 vim_free(buf);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 vim_free(ffname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 vim_free(afterdir);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 return retval;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 * Load scripts in "plugin" and "ftdetect" directories of the package.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 static int
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 load_pack_plugin(char_u *fname)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 static char *plugpat = "%s/plugin/**/*.vim";
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 static char *ftpat = "%s/ftdetect/*.vim";
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 int len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 char_u *ffname = fix_fname(fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 char_u *pat = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 int retval = FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 if (ffname == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 return FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 len = (int)STRLEN(ffname) + (int)STRLEN(ftpat);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 pat = alloc(len);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 if (pat == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 goto theend;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 vim_snprintf((char *)pat, len, plugpat, ffname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 source_all_matches(pat);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 // If runtime/filetype.vim wasn't loaded yet, the scripts will be
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 // found when it loads.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 if (cmd != NULL && eval_to_number(cmd) > 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 do_cmdline_cmd((char_u *)"augroup filetypedetect");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 vim_snprintf((char *)pat, len, ftpat, ffname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 source_all_matches(pat);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 do_cmdline_cmd((char_u *)"augroup END");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 vim_free(cmd);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 vim_free(pat);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 retval = OK;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 theend:
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 vim_free(ffname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 return retval;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 // used for "cookie" of add_pack_plugin()
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 static int APP_ADD_DIR;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 static int APP_LOAD;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 static int APP_BOTH;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 static void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 add_pack_plugin(char_u *fname, void *cookie)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 if (cookie != &APP_LOAD)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 char_u *buf = alloc(MAXPATHL);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 char_u *p;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 int found = FALSE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 if (buf == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 return;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 p = p_rtp;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 while (*p != NUL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 copy_option_part(&p, buf, MAXPATHL, ",");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 if (pathcmp((char *)buf, (char *)fname, -1) == 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 found = TRUE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 break;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 vim_free(buf);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 if (!found)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 // directory is not yet in 'runtimepath', add it
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 if (add_pack_dir_to_rtp(fname) == FAIL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 return;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 if (cookie != &APP_ADD_DIR)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 load_pack_plugin(fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 * Add all packages in the "start" directory to 'runtimepath'.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 add_pack_start_dirs(void)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 add_pack_plugin, &APP_ADD_DIR);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 * Load plugins from all packages in the "start" directory.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 load_start_packages(void)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 did_source_packages = TRUE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 add_pack_plugin, &APP_LOAD);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 * ":packloadall"
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 * Find plugins in the package directories and source them.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 ex_packloadall(exarg_T *eap)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 if (!did_source_packages || eap->forceit)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 // First do a round to add all directories to 'runtimepath', then load
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 // the plugins. This allows for plugins to use an autoload directory
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 // of another plugin.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 add_pack_start_dirs();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 load_start_packages();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 * ":packadd[!] {name}"
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 ex_packadd(exarg_T *eap)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 static char *plugpat = "pack/*/%s/%s";
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 int len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 char *pat;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 int round;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 int res = OK;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 // Round 1: use "start", round 2: use "opt".
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 for (round = 1; round <= 2; ++round)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 // Only look under "start" when loading packages wasn't done yet.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 if (round == 1 && did_source_packages)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 continue;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 len = (int)STRLEN(plugpat) + (int)STRLEN(eap->arg) + 5;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 pat = alloc(len);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 if (pat == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 return;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 // The first round don't give a "not found" error, in the second round
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 // only when nothing was found in the first round.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 res = do_in_path(p_pp, (char_u *)pat,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0),
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 vim_free(pat);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 /*
17978
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
609 * Sort "gap" and remove duplicate entries. "gap" is expected to contain a
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
610 * list of file names in allocated memory.
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
611 */
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
612 void
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
613 remove_duplicates(garray_T *gap)
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
614 {
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
615 int i;
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
616 int j;
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
617 char_u **fnames = (char_u **)gap->ga_data;
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
618
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
619 sort_strings(fnames, gap->ga_len);
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
620 for (i = gap->ga_len - 1; i > 0; --i)
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
621 if (fnamecmp(fnames[i - 1], fnames[i]) == 0)
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
622 {
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
623 vim_free(fnames[i]);
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
624 for (j = i + 1; j < gap->ga_len; ++j)
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
625 fnames[j - 1] = fnames[j];
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
626 --gap->ga_len;
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
627 }
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
628 }
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
629
8f4cc259ed7a patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
630 /*
17861
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 * Expand color scheme, compiler or filetype names.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 * Search from 'runtimepath':
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 * 'runtimepath'/{dirnames}/{pat}.vim
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 * When "flags" has DIP_START: search also from 'start' of 'packpath':
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 * When "flags" has DIP_OPT: search also from 'opt' of 'packpath':
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 * "dirnames" is an array with one or more directory names.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 int
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 ExpandRTDir(
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 char_u *pat,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 int flags,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 int *num_file,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 char_u ***file,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 char *dirnames[])
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 char_u *s;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 char_u *e;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 char_u *match;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 garray_T ga;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 int i;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 int pat_len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 *num_file = 0;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 *file = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 pat_len = (int)STRLEN(pat);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 ga_init2(&ga, (int)sizeof(char *), 10);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 for (i = 0; dirnames[i] != NULL; ++i)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 s = alloc(STRLEN(dirnames[i]) + pat_len + 7);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 if (s == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 ga_clear_strings(&ga);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 return FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 globpath(p_rtp, s, &ga, 0);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 vim_free(s);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 if (flags & DIP_START) {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 for (i = 0; dirnames[i] != NULL; ++i)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 s = alloc(STRLEN(dirnames[i]) + pat_len + 22);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 if (s == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 ga_clear_strings(&ga);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 return FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 sprintf((char *)s, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 globpath(p_pp, s, &ga, 0);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 vim_free(s);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 if (flags & DIP_OPT) {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 for (i = 0; dirnames[i] != NULL; ++i)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 s = alloc(STRLEN(dirnames[i]) + pat_len + 20);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 if (s == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 ga_clear_strings(&ga);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 return FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 sprintf((char *)s, "pack/*/opt/*/%s/%s*.vim", dirnames[i], pat);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 globpath(p_pp, s, &ga, 0);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 vim_free(s);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 for (i = 0; i < ga.ga_len; ++i)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 match = ((char_u **)ga.ga_data)[i];
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 s = match;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 e = s + STRLEN(s);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 e -= 4;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 for (s = e; s > match; MB_PTR_BACK(match, s))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 if (s < match || vim_ispathsep(*s))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 break;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 ++s;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 *e = NUL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 mch_memmove(match, s, e - s + 1);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 if (ga.ga_len == 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 return FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 // Sort and remove duplicates which can happen when specifying multiple
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 // directories in dirnames.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 remove_duplicates(&ga);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 *file = ga.ga_data;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 *num_file = ga.ga_len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 return OK;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 * Expand loadplugin names:
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 * 'packpath'/pack/ * /opt/{pat}
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 int
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 ExpandPackAddDir(
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 char_u *pat,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 int *num_file,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 char_u ***file)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 char_u *s;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 char_u *e;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 char_u *match;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 garray_T ga;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 int i;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 int pat_len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 *num_file = 0;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 *file = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 pat_len = (int)STRLEN(pat);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 ga_init2(&ga, (int)sizeof(char *), 10);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 s = alloc(pat_len + 26);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 if (s == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 ga_clear_strings(&ga);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 return FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 sprintf((char *)s, "pack/*/opt/%s*", pat);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 globpath(p_pp, s, &ga, 0);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 vim_free(s);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 for (i = 0; i < ga.ga_len; ++i)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 match = ((char_u **)ga.ga_data)[i];
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 s = gettail(match);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 e = s + STRLEN(s);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 mch_memmove(match, s, e - s + 1);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 if (ga.ga_len == 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 return FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 // Sort and remove duplicates which can happen when specifying multiple
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 // directories in dirnames.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 remove_duplicates(&ga);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 *file = ga.ga_data;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 *num_file = ga.ga_len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 return OK;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 static void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 cmd_source(char_u *fname, exarg_T *eap)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 if (*fname == NUL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 emsg(_(e_argreq));
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 else if (eap != NULL && eap->forceit)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 // ":source!": read Normal mode commands
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 // Need to execute the commands directly. This is required at least
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 // for:
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 // - ":g" command busy
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 // - after ":argdo", ":windo" or ":bufdo"
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 // - another command follows
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 // - inside a loop
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 openscript(fname, global_busy || listcmd_busy || eap->nextcmd != NULL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 #ifdef FEAT_EVAL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 || eap->cstack->cs_idx >= 0
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 );
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 // ":source" read ex commands
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 else if (do_source(fname, FALSE, DOSO_NONE) == FAIL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 semsg(_(e_notopen), fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 * ":source {fname}"
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 ex_source(exarg_T *eap)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 #ifdef FEAT_BROWSE
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 if (cmdmod.browse)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 char_u *fname = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 fname = do_browse(0, (char_u *)_("Source Vim script"), eap->arg,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 NULL, NULL,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 (char_u *)_(BROWSE_FILTER_MACROS), NULL);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 if (fname != NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 cmd_source(fname, eap);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 vim_free(fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 cmd_source(eap->arg, eap);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 #if defined(FEAT_EVAL) || defined(PROTO)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 * ":options"
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 ex_options(
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 exarg_T *eap UNUSED)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 vim_setenv((char_u *)"OPTWIN_CMD",
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 (char_u *)(cmdmod.tab ? "tab"
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 : (cmdmod.split & WSP_VERT) ? "vert" : ""));
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 cmd_source((char_u *)SYS_OPTWIN_FILE, NULL);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 * ":source" and associated commands.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 * Structure used to store info for each sourced file.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 * It is shared between do_source() and getsourceline().
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 * This is required, because it needs to be handed to do_cmdline() and
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 * sourcing can be done recursively.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 struct source_cookie
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 FILE *fp; // opened file for sourcing
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 char_u *nextline; // if not NULL: line that was read ahead
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 linenr_T sourcing_lnum; // line number of the source file
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 int finished; // ":finish" used
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 #ifdef USE_CRNL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 int fileformat; // EOL_UNKNOWN, EOL_UNIX or EOL_DOS
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 int error; // TRUE if LF found after CR-LF
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 #ifdef FEAT_EVAL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 linenr_T breakpoint; // next line with breakpoint or zero
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 char_u *fname; // name of sourced file
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 int dbg_tick; // debug_tick when breakpoint was set
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 int level; // top nesting level of sourced file
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 vimconv_T conv; // type of conversion
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 };
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 #ifdef FEAT_EVAL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 * Return the address holding the next breakpoint line for a source cookie.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 linenr_T *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 source_breakpoint(void *cookie)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 return &((struct source_cookie *)cookie)->breakpoint;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 * Return the address holding the debug tick for a source cookie.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 int *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 source_dbg_tick(void *cookie)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 return &((struct source_cookie *)cookie)->dbg_tick;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 * Return the nesting level for a source cookie.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 int
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 source_level(void *cookie)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 return ((struct source_cookie *)cookie)->level;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 #if (defined(MSWIN) && defined(FEAT_CSCOPE)) || defined(HAVE_FD_CLOEXEC)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 # define USE_FOPEN_NOINH
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 * Special function to open a file without handle inheritance.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 * When possible the handle is closed on exec().
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 static FILE *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 fopen_noinh_readbin(char *filename)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 # ifdef MSWIN
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 int fd_tmp = mch_open(filename, O_RDONLY | O_BINARY | O_NOINHERIT, 0);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 # else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 int fd_tmp = mch_open(filename, O_RDONLY, 0);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 # endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 if (fd_tmp == -1)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 return NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 # ifdef HAVE_FD_CLOEXEC
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 int fdflags = fcntl(fd_tmp, F_GETFD);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 (void)fcntl(fd_tmp, F_SETFD, fdflags | FD_CLOEXEC);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 # endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 return fdopen(fd_tmp, READBIN);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 * do_source: Read the file "fname" and execute its lines as EX commands.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 * This function may be called recursively!
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 * return FAIL if file could not be opened, OK otherwise
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 int
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 do_source(
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 char_u *fname,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 int check_other, // check for .vimrc and _vimrc
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 int is_vimrc) // DOSO_ value
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 struct source_cookie cookie;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 char_u *save_sourcing_name;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 linenr_T save_sourcing_lnum;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 char_u *p;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 char_u *fname_exp;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 char_u *firstline = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 int retval = FAIL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 #ifdef FEAT_EVAL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 sctx_T save_current_sctx;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 static scid_T last_current_SID = 0;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 static int last_current_SID_seq = 0;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 funccal_entry_T funccalp_entry;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 int save_debug_break_level = debug_break_level;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 scriptitem_T *si = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 # ifdef UNIX
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 stat_T st;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 int stat_ok;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 # endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 #ifdef STARTUPTIME
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 struct timeval tv_rel;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 struct timeval tv_start;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 #ifdef FEAT_PROFILE
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 proftime_T wait_start;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 int trigger_source_post = FALSE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 p = expand_env_save(fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 if (p == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 return retval;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 fname_exp = fix_fname(p);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 vim_free(p);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 if (fname_exp == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 return retval;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 if (mch_isdir(fname_exp))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 smsg(_("Cannot source a directory: \"%s\""), fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 goto theend;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 // Apply SourceCmd autocommands, they should get the file and source it.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 if (has_autocmd(EVENT_SOURCECMD, fname_exp, NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 && apply_autocmds(EVENT_SOURCECMD, fname_exp, fname_exp,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 FALSE, curbuf))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 #ifdef FEAT_EVAL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 retval = aborting() ? FAIL : OK;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 #else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 retval = OK;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 if (retval == OK)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 // Apply SourcePost autocommands.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 FALSE, curbuf);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 goto theend;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 // Apply SourcePre autocommands, they may get the file.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 #ifdef USE_FOPEN_NOINH
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 cookie.fp = fopen_noinh_readbin((char *)fname_exp);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 #else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 cookie.fp = mch_fopen((char *)fname_exp, READBIN);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 if (cookie.fp == NULL && check_other)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 // Try again, replacing file name ".vimrc" by "_vimrc" or vice versa,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 // and ".exrc" by "_exrc" or vice versa.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 p = gettail(fname_exp);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 if ((*p == '.' || *p == '_')
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 && (STRICMP(p + 1, "vimrc") == 0
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 || STRICMP(p + 1, "gvimrc") == 0
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 || STRICMP(p + 1, "exrc") == 0))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 if (*p == '_')
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 *p = '.';
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 *p = '_';
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 #ifdef USE_FOPEN_NOINH
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 cookie.fp = fopen_noinh_readbin((char *)fname_exp);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 #else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 cookie.fp = mch_fopen((char *)fname_exp, READBIN);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 if (cookie.fp == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 if (p_verbose > 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 verbose_enter();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 if (sourcing_name == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 smsg(_("could not source \"%s\""), fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 smsg(_("line %ld: could not source \"%s\""),
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 sourcing_lnum, fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 verbose_leave();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 goto theend;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 // The file exists.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 // - In verbose mode, give a message.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 // - For a vimrc file, may want to set 'compatible', call vimrc_found().
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 if (p_verbose > 1)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 verbose_enter();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 if (sourcing_name == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 smsg(_("sourcing \"%s\""), fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 smsg(_("line %ld: sourcing \"%s\""),
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 sourcing_lnum, fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 verbose_leave();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 if (is_vimrc == DOSO_VIMRC)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 vimrc_found(fname_exp, (char_u *)"MYVIMRC");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 else if (is_vimrc == DOSO_GVIMRC)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 vimrc_found(fname_exp, (char_u *)"MYGVIMRC");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 #ifdef USE_CRNL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 // If no automatic file format: Set default to CR-NL.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 if (*p_ffs == NUL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 cookie.fileformat = EOL_DOS;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 cookie.fileformat = EOL_UNKNOWN;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 cookie.error = FALSE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 cookie.nextline = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 cookie.sourcing_lnum = 0;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 cookie.finished = FALSE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 #ifdef FEAT_EVAL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 // Check if this script has a breakpoint.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 cookie.breakpoint = dbg_find_breakpoint(TRUE, fname_exp, (linenr_T)0);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 cookie.fname = fname_exp;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 cookie.dbg_tick = debug_tick;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 cookie.level = ex_nesting_level;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 // Keep the sourcing name/lnum, for recursive calls.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 save_sourcing_name = sourcing_name;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 sourcing_name = fname_exp;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 save_sourcing_lnum = sourcing_lnum;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 sourcing_lnum = 0;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 #ifdef STARTUPTIME
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 if (time_fd != NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 time_push(&tv_rel, &tv_start);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 #ifdef FEAT_EVAL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 # ifdef FEAT_PROFILE
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 if (do_profiling == PROF_YES)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 prof_child_enter(&wait_start); // entering a child now
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 # endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 // Don't use local function variables, if called from a function.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 // Also starts profiling timer for nested script.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 save_funccal(&funccalp_entry);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 save_current_sctx = current_sctx;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 current_sctx.sc_lnum = 0;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 current_sctx.sc_version = 1;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 // Check if this script was sourced before to finds its SID.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 // If it's new, generate a new SID.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 // Always use a new sequence number.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 current_sctx.sc_seq = ++last_current_SID_seq;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 # ifdef UNIX
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 stat_ok = (mch_stat((char *)fname_exp, &st) >= 0);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 # endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 for (current_sctx.sc_sid = script_items.ga_len; current_sctx.sc_sid > 0;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 --current_sctx.sc_sid)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 si = &SCRIPT_ITEM(current_sctx.sc_sid);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 if (si->sn_name != NULL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 && (
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 # ifdef UNIX
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 // Compare dev/ino when possible, it catches symbolic
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 // links. Also compare file names, the inode may change
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 // when the file was edited.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 ((stat_ok && si->sn_dev_valid)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 && (si->sn_dev == st.st_dev
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 && si->sn_ino == st.st_ino)) ||
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 # endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 fnamecmp(si->sn_name, fname_exp) == 0))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 break;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 if (current_sctx.sc_sid == 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 current_sctx.sc_sid = ++last_current_SID;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 if (ga_grow(&script_items,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 (int)(current_sctx.sc_sid - script_items.ga_len)) == FAIL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 goto almosttheend;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 while (script_items.ga_len < current_sctx.sc_sid)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 ++script_items.ga_len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 SCRIPT_ITEM(script_items.ga_len).sn_name = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 # ifdef FEAT_PROFILE
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 SCRIPT_ITEM(script_items.ga_len).sn_prof_on = FALSE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 # endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 si = &SCRIPT_ITEM(current_sctx.sc_sid);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 si->sn_name = fname_exp;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 fname_exp = vim_strsave(si->sn_name); // used for autocmd
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 # ifdef UNIX
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 if (stat_ok)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 si->sn_dev_valid = TRUE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 si->sn_dev = st.st_dev;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 si->sn_ino = st.st_ino;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 si->sn_dev_valid = FALSE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 # endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 // Allocate the local script variables to use for this script.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 new_script_vars(current_sctx.sc_sid);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 # ifdef FEAT_PROFILE
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 if (do_profiling == PROF_YES)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 int forceit;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 // Check if we do profiling for this script.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 if (!si->sn_prof_on && has_profiling(TRUE, si->sn_name, &forceit))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 script_do_profile(si);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 si->sn_pr_force = forceit;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 if (si->sn_prof_on)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 ++si->sn_pr_count;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 profile_start(&si->sn_pr_start);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 profile_zero(&si->sn_pr_children);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 # endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 cookie.conv.vc_type = CONV_NONE; // no conversion
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 // Read the first line so we can check for a UTF-8 BOM.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 firstline = getsourceline(0, (void *)&cookie, 0, TRUE);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 && firstline[1] == 0xbb && firstline[2] == 0xbf)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 // Found BOM; setup conversion, skip over BOM and recode the line.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 p = string_convert(&cookie.conv, firstline + 3, NULL);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 if (p == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 p = vim_strsave(firstline + 3);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 if (p != NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 vim_free(firstline);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 firstline = p;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 // Call do_cmdline, which will call getsourceline() to get the lines.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 do_cmdline(firstline, getsourceline, (void *)&cookie,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 retval = OK;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 #ifdef FEAT_PROFILE
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 if (do_profiling == PROF_YES)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 // Get "si" again, "script_items" may have been reallocated.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 si = &SCRIPT_ITEM(current_sctx.sc_sid);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 if (si->sn_prof_on)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 profile_end(&si->sn_pr_start);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 profile_sub_wait(&wait_start, &si->sn_pr_start);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 profile_add(&si->sn_pr_total, &si->sn_pr_start);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 profile_self(&si->sn_pr_self, &si->sn_pr_start,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 &si->sn_pr_children);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 if (got_int)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 emsg(_(e_interr));
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 sourcing_name = save_sourcing_name;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 sourcing_lnum = save_sourcing_lnum;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 if (p_verbose > 1)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 verbose_enter();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 smsg(_("finished sourcing %s"), fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 if (sourcing_name != NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 smsg(_("continuing in %s"), sourcing_name);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 verbose_leave();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 #ifdef STARTUPTIME
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 if (time_fd != NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 vim_snprintf((char *)IObuff, IOSIZE, "sourcing %s", fname);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 time_msg((char *)IObuff, &tv_start);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 time_pop(&tv_rel);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 if (!got_int)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 trigger_source_post = TRUE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 #ifdef FEAT_EVAL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 // After a "finish" in debug mode, need to break at first command of next
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 // sourced file.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 if (save_debug_break_level > ex_nesting_level
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 && debug_break_level == ex_nesting_level)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 ++debug_break_level;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 #ifdef FEAT_EVAL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 almosttheend:
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 current_sctx = save_current_sctx;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 restore_funccal();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 # ifdef FEAT_PROFILE
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 if (do_profiling == PROF_YES)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 prof_child_exit(&wait_start); // leaving a child now
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 # endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 fclose(cookie.fp);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 vim_free(cookie.nextline);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 vim_free(firstline);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 convert_setup(&cookie.conv, NULL, NULL);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 if (trigger_source_post)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp, FALSE, curbuf);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 theend:
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 vim_free(fname_exp);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 return retval;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 #if defined(FEAT_EVAL) || defined(PROTO)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 * ":scriptnames"
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 ex_scriptnames(exarg_T *eap)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 int i;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 if (eap->addr_count > 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 // :script {scriptId}: edit the script
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 if (eap->line2 < 1 || eap->line2 > script_items.ga_len)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 emsg(_(e_invarg));
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 eap->arg = SCRIPT_ITEM(eap->line2).sn_name;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 do_exedit(eap, NULL);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 return;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 for (i = 1; i <= script_items.ga_len && !got_int; ++i)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 if (SCRIPT_ITEM(i).sn_name != NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 home_replace(NULL, SCRIPT_ITEM(i).sn_name,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 NameBuff, MAXPATHL, TRUE);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 smsg("%3d: %s", i, NameBuff);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 # if defined(BACKSLASH_IN_FILENAME) || defined(PROTO)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 * Fix slashes in the list of script names for 'shellslash'.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 scriptnames_slash_adjust(void)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 int i;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 for (i = 1; i <= script_items.ga_len; ++i)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 if (SCRIPT_ITEM(i).sn_name != NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 slash_adjust(SCRIPT_ITEM(i).sn_name);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 # endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 * Get a pointer to a script name. Used for ":verbose set".
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 char_u *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 get_scriptname(scid_T id)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 if (id == SID_MODELINE)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 return (char_u *)_("modeline");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 if (id == SID_CMDARG)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 return (char_u *)_("--cmd argument");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 if (id == SID_CARG)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 return (char_u *)_("-c argument");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 if (id == SID_ENV)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 return (char_u *)_("environment variable");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 if (id == SID_ERROR)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 return (char_u *)_("error handler");
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 return SCRIPT_ITEM(id).sn_name;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 # if defined(EXITFREE) || defined(PROTO)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 free_scriptnames(void)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 int i;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 for (i = script_items.ga_len; i > 0; --i)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 vim_free(SCRIPT_ITEM(i).sn_name);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 ga_clear(&script_items);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 }
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1364
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1365 void
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1366 free_autoload_scriptnames(void)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1367 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1368 ga_clear_strings(&ga_loaded);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1369 }
17861
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 # endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 linenr_T
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 get_sourced_lnum(char_u *(*fgetline)(int, void *, int, int), void *cookie)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 return fgetline == getsourceline
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 ? ((struct source_cookie *)cookie)->sourcing_lnum
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 : sourcing_lnum;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 static char_u *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 get_one_sourceline(struct source_cookie *sp)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 garray_T ga;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 int len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 int c;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 char_u *buf;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 #ifdef USE_CRNL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 int has_cr; // CR-LF found
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 int have_read = FALSE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 // use a growarray to store the sourced line
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 ga_init2(&ga, 1, 250);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 // Loop until there is a finished line (or end-of-file).
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 ++sp->sourcing_lnum;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 for (;;)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 // make room to read at least 120 (more) characters
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 if (ga_grow(&ga, 120) == FAIL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 break;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 buf = (char_u *)ga.ga_data;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 sp->fp) == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 break;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 len = ga.ga_len + (int)STRLEN(buf + ga.ga_len);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 #ifdef USE_CRNL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 // Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 // CTRL-Z by its own, or after a NL.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 if ( (len == 1 || (len >= 2 && buf[len - 2] == '\n'))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 && sp->fileformat == EOL_DOS
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 && buf[len - 1] == Ctrl_Z)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 buf[len - 1] = NUL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 break;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 have_read = TRUE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 ga.ga_len = len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 // If the line was longer than the buffer, read more.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 if (ga.ga_maxlen - ga.ga_len == 1 && buf[len - 1] != '\n')
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 continue;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 if (len >= 1 && buf[len - 1] == '\n') // remove trailing NL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 #ifdef USE_CRNL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 has_cr = (len >= 2 && buf[len - 2] == '\r');
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 if (sp->fileformat == EOL_UNKNOWN)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 if (has_cr)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 sp->fileformat = EOL_DOS;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 sp->fileformat = EOL_UNIX;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 if (sp->fileformat == EOL_DOS)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 if (has_cr) // replace trailing CR
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 buf[len - 2] = '\n';
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 --len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 --ga.ga_len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 else // lines like ":map xx yy^M" will have failed
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 if (!sp->error)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 msg_source(HL_ATTR(HLF_W));
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 emsg(_("W15: Warning: Wrong line separator, ^M may be missing"));
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 sp->error = TRUE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 sp->fileformat = EOL_UNIX;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 // The '\n' is escaped if there is an odd number of ^V's just
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 // before it, first set "c" just before the 'V's and then check
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 // len&c parities (is faster than ((len-c)%2 == 0)) -- Acevedo
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 for (c = len - 2; c >= 0 && buf[c] == Ctrl_V; c--)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 ;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 if ((len & 1) != (c & 1)) // escaped NL, read more
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 ++sp->sourcing_lnum;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 continue;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 buf[len - 1] = NUL; // remove the NL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 // Check for ^C here now and then, so recursive :so can be broken.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 line_breakcheck();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 break;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 if (have_read)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 return (char_u *)ga.ga_data;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 vim_free(ga.ga_data);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 return NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 * Get one full line from a sourced file.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 * Called by do_cmdline() when it's called from do_source().
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 * Return a pointer to the line in allocated memory.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 * Return NULL for end-of-file or some error.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 char_u *
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 getsourceline(int c UNUSED, void *cookie, int indent UNUSED, int do_concat)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 struct source_cookie *sp = (struct source_cookie *)cookie;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 char_u *line;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 char_u *p;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 #ifdef FEAT_EVAL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 // If breakpoints have been added/deleted need to check for it.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 if (sp->dbg_tick < debug_tick)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 sp->dbg_tick = debug_tick;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 # ifdef FEAT_PROFILE
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 if (do_profiling == PROF_YES)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 script_line_end();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 # endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 // Set the current sourcing line number.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 sourcing_lnum = sp->sourcing_lnum + 1;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 // Get current line. If there is a read-ahead line, use it, otherwise get
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 // one now.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 if (sp->finished)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 line = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 else if (sp->nextline == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 line = get_one_sourceline(sp);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 line = sp->nextline;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 sp->nextline = NULL;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 ++sp->sourcing_lnum;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 #ifdef FEAT_PROFILE
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 if (line != NULL && do_profiling == PROF_YES)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 script_line_start();
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 // Only concatenate lines starting with a \ when 'cpoptions' doesn't
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 // contain the 'C' flag.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 if (line != NULL && do_concat && vim_strchr(p_cpo, CPO_CONCAT) == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 // compensate for the one line read-ahead
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 --sp->sourcing_lnum;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 // Get the next line and concatenate it when it starts with a
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 // backslash. We always need to read the next line, keep it in
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 // sp->nextline.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 /* Also check for a comment in between continuation lines: "\ */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 sp->nextline = get_one_sourceline(sp);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 if (sp->nextline != NULL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 && (*(p = skipwhite(sp->nextline)) == '\\'
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 || (p[0] == '"' && p[1] == '\\' && p[2] == ' ')))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 garray_T ga;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 ga_init2(&ga, (int)sizeof(char_u), 400);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 ga_concat(&ga, line);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 if (*p == '\\')
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 ga_concat(&ga, p + 1);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 for (;;)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 vim_free(sp->nextline);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 sp->nextline = get_one_sourceline(sp);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 if (sp->nextline == NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 break;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 p = skipwhite(sp->nextline);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 if (*p == '\\')
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 // Adjust the growsize to the current length to speed up
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 // concatenating many lines.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 if (ga.ga_len > 400)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 if (ga.ga_len > 8000)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570 ga.ga_growsize = 8000;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 ga.ga_growsize = ga.ga_len;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 ga_concat(&ga, p + 1);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 else if (p[0] != '"' || p[1] != '\\' || p[2] != ' ')
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 break;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 ga_append(&ga, NUL);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 vim_free(line);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 line = ga.ga_data;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 if (line != NULL && sp->conv.vc_type != CONV_NONE)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 char_u *s;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 // Convert the encoding of the script line.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 s = string_convert(&sp->conv, line, NULL);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 if (s != NULL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 vim_free(line);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 line = s;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 #ifdef FEAT_EVAL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 // Did we encounter a breakpoint?
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 if (sp->breakpoint != 0 && sp->breakpoint <= sourcing_lnum)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 dbg_breakpoint(sp->fname, sourcing_lnum);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 // Find next breakpoint.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 sp->dbg_tick = debug_tick;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 return line;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 * ":scriptencoding": Set encoding conversion for a sourced script.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616 ex_scriptencoding(exarg_T *eap)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 struct source_cookie *sp;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619 char_u *name;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 if (!getline_equal(eap->getline, eap->cookie, getsourceline))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 emsg(_("E167: :scriptencoding used outside of a sourced file"));
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 return;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 if (*eap->arg != NUL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 name = enc_canonize(eap->arg);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 if (name == NULL) // out of memory
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 return;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 name = eap->arg;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 // Setup for conversion from the specified encoding to 'encoding'.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 sp = (struct source_cookie *)getline_cookie(eap->getline, eap->cookie);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 convert_setup(&sp->conv, name, p_enc);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 if (name != eap->arg)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 vim_free(name);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 * ":scriptversion": Set Vim script version for a sourced script.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 ex_scriptversion(exarg_T *eap UNUSED)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 #ifdef FEAT_EVAL
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 int nr;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 if (!getline_equal(eap->getline, eap->cookie, getsourceline))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 emsg(_("E984: :scriptversion used outside of a sourced file"));
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 return;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 nr = getdigits(&eap->arg);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 if (nr == 0 || *eap->arg != NUL)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 emsg(_(e_invarg));
18080
a6d218f99ff7 patch 8.1.2035: recognizing octal numbers is confusing
Bram Moolenaar <Bram@vim.org>
parents: 17978
diff changeset
1662 else if (nr > 4)
17861
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 semsg(_("E999: scriptversion not supported: %d"), nr);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 current_sctx.sc_version = nr;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 #endif
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 #if defined(FEAT_EVAL) || defined(PROTO)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 * ":finish": Mark a sourced file as finished.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 ex_finish(exarg_T *eap)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 if (getline_equal(eap->getline, eap->cookie, getsourceline))
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 do_finish(eap, FALSE);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 emsg(_("E168: :finish used outside of a sourced file"));
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 * Mark a sourced file as finished. Possibly makes the ":finish" pending.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 * Also called for a pending finish at the ":endtry" or after returning from
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 * an extra do_cmdline(). "reanimate" is used in the latter case.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 void
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 do_finish(exarg_T *eap, int reanimate)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 int idx;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 if (reanimate)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 ((struct source_cookie *)getline_cookie(eap->getline,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 eap->cookie))->finished = FALSE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 // Cleanup (and inactivate) conditionals, but stop when a try conditional
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 // not in its finally clause (which then is to be executed next) is found.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 // In this case, make the ":finish" pending for execution at the ":endtry".
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 // Otherwise, finish normally.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 idx = cleanup_conditionals(eap->cstack, 0, TRUE);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 if (idx >= 0)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 eap->cstack->cs_pending[idx] = CSTP_FINISH;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 report_make_pending(CSTP_FINISH, NULL);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 else
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 ((struct source_cookie *)getline_cookie(eap->getline,
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 eap->cookie))->finished = TRUE;
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 }
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 /*
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 * Return TRUE when a sourced file had the ":finish" command: Don't give error
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 * message for missing ":endif".
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 * Return FALSE when not sourcing a file.
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 */
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 int
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 source_finished(
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 char_u *(*fgetline)(int, void *, int, int),
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 void *cookie)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 {
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 return (getline_equal(fgetline, cookie, getsourceline)
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 && ((struct source_cookie *)getline_cookie(
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 fgetline, cookie))->finished);
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 }
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1726
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1727 /*
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1728 * Return the autoload script name for a function or variable name.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1729 * Returns NULL when out of memory.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1730 * Caller must make sure that "name" contains AUTOLOAD_CHAR.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1731 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1732 char_u *
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1733 autoload_name(char_u *name)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1734 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1735 char_u *p, *q = NULL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1736 char_u *scriptname;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1737
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1738 // Get the script file name: replace '#' with '/', append ".vim".
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1739 scriptname = alloc(STRLEN(name) + 14);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1740 if (scriptname == NULL)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1741 return NULL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1742 STRCPY(scriptname, "autoload/");
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1743 STRCAT(scriptname, name);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1744 for (p = scriptname + 9; (p = vim_strchr(p, AUTOLOAD_CHAR)) != NULL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1745 q = p, ++p)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1746 *p = '/';
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1747 STRCPY(q, ".vim");
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1748 return scriptname;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1749 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1750
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1751 /*
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1752 * If "name" has a package name try autoloading the script for it.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1753 * Return TRUE if a package was loaded.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1754 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1755 int
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1756 script_autoload(
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1757 char_u *name,
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1758 int reload) // load script again when already loaded
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1759 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1760 char_u *p;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1761 char_u *scriptname, *tofree;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1762 int ret = FALSE;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1763 int i;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1764
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1765 // If there is no '#' after name[0] there is no package name.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1766 p = vim_strchr(name, AUTOLOAD_CHAR);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1767 if (p == NULL || p == name)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1768 return FALSE;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1769
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1770 tofree = scriptname = autoload_name(name);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1771 if (scriptname == NULL)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1772 return FALSE;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1773
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1774 // Find the name in the list of previously loaded package names. Skip
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1775 // "autoload/", it's always the same.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1776 for (i = 0; i < ga_loaded.ga_len; ++i)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1777 if (STRCMP(((char_u **)ga_loaded.ga_data)[i] + 9, scriptname + 9) == 0)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1778 break;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1779 if (!reload && i < ga_loaded.ga_len)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1780 ret = FALSE; // was loaded already
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1781 else
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1782 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1783 // Remember the name if it wasn't loaded already.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1784 if (i == ga_loaded.ga_len && ga_grow(&ga_loaded, 1) == OK)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1785 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1786 ((char_u **)ga_loaded.ga_data)[ga_loaded.ga_len++] = scriptname;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1787 tofree = NULL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1788 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1789
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1790 // Try loading the package from $VIMRUNTIME/autoload/<name>.vim
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1791 if (source_runtime(scriptname, 0) == OK)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1792 ret = TRUE;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1793 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1794
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1795 vim_free(tofree);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1796 return ret;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1797 }
17861
0a5c615cd949 patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 #endif