annotate src/scriptfile.c @ 32669:448aef880252

normalize line endings
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Jun 2023 09:54:34 +0200
parents b8e9ea3c1ed0
children 695b50472e85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
4 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
7 * See README.txt for an overview of the Vim source code.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
8 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
9
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
10 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
11 * scriptfile.c: functions for dealing with the runtime directories/files
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
12 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
13
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
14 #include "vim.h"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
15
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
16 #if defined(FEAT_EVAL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
17 // The names of packages that once were loaded are remembered.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
18 static garray_T ga_loaded = {0, 0, sizeof(char_u *), 4, NULL};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
19 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
20
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
21 // last used sequence number for sourcing scripts (current_sctx.sc_seq)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
22 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
23 static int last_current_SID_seq = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
24 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
25
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
26 static int do_source_ext(char_u *fname, int check_other, int is_vimrc, int *ret_sid, exarg_T *eap, int clearvars);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
27
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
28 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
29 * Initialize the execution stack.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
30 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
31 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
32 estack_init(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
33 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
34 estack_T *entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
35
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
36 if (ga_grow(&exestack, 10) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
37 mch_exit(0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
38 entry = ((estack_T *)exestack.ga_data) + exestack.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
39 entry->es_type = ETYPE_TOP;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
40 entry->es_name = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
41 entry->es_lnum = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
42 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
43 entry->es_info.ufunc = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
44 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
45 ++exestack.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
46 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
47
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
48 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
49 * Add an item to the execution stack.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
50 * Returns the new entry or NULL when out of memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
51 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
52 estack_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
53 estack_push(etype_T type, char_u *name, long lnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
54 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
55 estack_T *entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
56
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
57 // If memory allocation fails then we'll pop more than we push, eventually
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
58 // at the top level it will be OK again.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
59 if (ga_grow(&exestack, 1) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
60 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
61
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
62 entry = ((estack_T *)exestack.ga_data) + exestack.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
63 entry->es_type = type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
64 entry->es_name = name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
65 entry->es_lnum = lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
66 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
67 entry->es_info.ufunc = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
68 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
69 ++exestack.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
70 return entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
71 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
72
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
73 #if defined(FEAT_EVAL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
74 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
75 * Add a user function to the execution stack.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
76 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
77 estack_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
78 estack_push_ufunc(ufunc_T *ufunc, long lnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
79 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
80 estack_T *entry = estack_push(ETYPE_UFUNC,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
81 ufunc->uf_name_exp != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
82 ? ufunc->uf_name_exp : ufunc->uf_name, lnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
83 if (entry != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
84 entry->es_info.ufunc = ufunc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
85 return entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
86 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
87
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
88 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
89 * Return TRUE if "ufunc" with "lnum" is already at the top of the exe stack.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
90 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
91 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
92 estack_top_is_ufunc(ufunc_T *ufunc, long lnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
93 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
94 estack_T *entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
95
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
96 if (exestack.ga_len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
97 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
98 entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
99 return entry->es_type == ETYPE_UFUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
100 && STRCMP( entry->es_name, ufunc->uf_name_exp != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
101 ? ufunc->uf_name_exp : ufunc->uf_name) == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
102 && entry->es_lnum == lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
103 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
104 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
106 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
107 * Take an item off of the execution stack and return it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
108 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
109 estack_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
110 estack_pop(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
111 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
112 if (exestack.ga_len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
113 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
114 --exestack.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
115 return ((estack_T *)exestack.ga_data) + exestack.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
116 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
117
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
118 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
119 * Get the current value for "which" in allocated memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
120 * "which" is ESTACK_SFILE for <sfile>, ESTACK_STACK for <stack> or
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
121 * ESTACK_SCRIPT for <script>.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
122 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
123 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
124 estack_sfile(estack_arg_T which UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
125 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
126 estack_T *entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
127 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
128 garray_T ga;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
129 size_t len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
130 int idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
131 etype_T last_type = ETYPE_SCRIPT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
132 char *type_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
133 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
134
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
135 entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
136 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
137 if (which == ESTACK_SFILE && entry->es_type != ETYPE_UFUNC)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
138 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
139 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
140 if (entry->es_name == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
141 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
142 return vim_strsave(entry->es_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
143 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
144 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
145 // expand('<sfile>') works in a function for backwards compatibility, but
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
146 // may give an unexpected result. Disallow it in Vim 9 script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
147 if (which == ESTACK_SFILE && in_vim9script())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
148 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
149 int save_emsg_off = emsg_off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
150
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
151 if (emsg_off == 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
152 // f_expand() silences errors but we do want this one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
153 emsg_off = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
154 emsg(_(e_cannot_expand_sfile_in_vim9_function));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
155 emsg_off = save_emsg_off;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
156 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
157 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
158
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
159 // If evaluated in a function or autocommand, return the path of the script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
160 // where it is defined, at script level the current script path is returned
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
161 // instead.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
162 if (which == ESTACK_SCRIPT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
163 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
164 // Walk the stack backwards, starting from the current frame.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
165 for (idx = exestack.ga_len - 1; idx >= 0; --idx, --entry)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
166 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
167 if (entry->es_type == ETYPE_UFUNC || entry->es_type == ETYPE_AUCMD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
168 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
169 sctx_T *def_ctx = entry->es_type == ETYPE_UFUNC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
170 ? &entry->es_info.ufunc->uf_script_ctx
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
171 : acp_script_ctx(entry->es_info.aucmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
172
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
173 return def_ctx->sc_sid > 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
174 ? vim_strsave(SCRIPT_ITEM(def_ctx->sc_sid)->sn_name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
175 : NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
176 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
177 else if (entry->es_type == ETYPE_SCRIPT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
178 return vim_strsave(entry->es_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
179 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
180 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
181 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
182
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
183 // Give information about each stack entry up to the root.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
184 // For a function we compose the call stack, as it was done in the past:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
185 // "function One[123]..Two[456]..Three"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
186 ga_init2(&ga, sizeof(char), 100);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
187 for (idx = 0; idx < exestack.ga_len; ++idx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
188 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
189 entry = ((estack_T *)exestack.ga_data) + idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
190 if (entry->es_name != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
191 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
192 long lnum = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
193 char *dots;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
194
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
195 len = STRLEN(entry->es_name) + 15;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
196 type_name = "";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
197 if (entry->es_type != last_type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
198 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
199 switch (entry->es_type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
200 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
201 case ETYPE_SCRIPT: type_name = "script "; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
202 case ETYPE_UFUNC: type_name = "function "; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
203 default: type_name = ""; break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
204 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
205 last_type = entry->es_type;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
206 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
207 len += STRLEN(type_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
208 if (ga_grow(&ga, (int)len) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
209 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
210 if (idx == exestack.ga_len - 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
211 lnum = which == ESTACK_STACK ? SOURCING_LNUM : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
212 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
213 lnum = entry->es_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
214 dots = idx == exestack.ga_len - 1 ? "" : "..";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
215 if (lnum == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
216 // For the bottom entry of <sfile>: do not add the line number,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
217 // it is used in <slnum>. Also leave it out when the number is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
218 // not set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
219 vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s%s",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
220 type_name, entry->es_name, dots);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
221 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
222 vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s[%ld]%s",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
223 type_name, entry->es_name, lnum, dots);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
224 ga.ga_len += (int)STRLEN((char *)ga.ga_data + ga.ga_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
225 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
226 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
227
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
228 return (char_u *)ga.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
229 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
230 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
231
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
232 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
233 * Get DIP_ flags from the [where] argument of a :runtime command.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
234 * "*argp" is advanced to after the [where] argument if it is found.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
235 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
236 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
237 get_runtime_cmd_flags(char_u **argp, size_t where_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
238 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
239 char_u *arg = *argp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
240
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
241 if (where_len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
242 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
243
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
244 if (STRNCMP(arg, "START", where_len) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
245 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
246 *argp = skipwhite(arg + where_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
247 return DIP_START + DIP_NORTP;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
248 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
249 if (STRNCMP(arg, "OPT", where_len) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
250 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
251 *argp = skipwhite(arg + where_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
252 return DIP_OPT + DIP_NORTP;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
253 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
254 if (STRNCMP(arg, "PACK", where_len) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
255 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
256 *argp = skipwhite(arg + where_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
257 return DIP_START + DIP_OPT + DIP_NORTP;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
258 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
259 if (STRNCMP(arg, "ALL", where_len) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
260 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
261 *argp = skipwhite(arg + where_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
262 return DIP_START + DIP_OPT;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
263 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
264
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
265 return 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
266 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
267
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
268 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
269 * ":runtime [where] {name}"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
270 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
271 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
272 ex_runtime(exarg_T *eap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
273 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
274 char_u *arg = eap->arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
275 int flags = eap->forceit ? DIP_ALL : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
276 char_u *p = skiptowhite(arg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
277 flags += get_runtime_cmd_flags(&arg, p - arg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
278 source_runtime(arg, flags);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
279 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
280
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
281 static int runtime_expand_flags;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
282
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
283 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
284 * Set the completion context for the :runtime command.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
285 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
286 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
287 set_context_in_runtime_cmd(expand_T *xp, char_u *arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
288 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
289 char_u *p = skiptowhite(arg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
290 runtime_expand_flags
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
291 = *p != NUL ? get_runtime_cmd_flags(&arg, p - arg) : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
292 xp->xp_context = EXPAND_RUNTIME;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
293 xp->xp_pattern = arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
294 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
295
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
296 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
297 source_callback(char_u *fname, void *cookie)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
298 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
299 (void)do_source(fname, FALSE, DOSO_NONE, cookie);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
300 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
301
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
302 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
303 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
304 * Find an already loaded script "name".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
305 * If found returns its script ID. If not found returns -1.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
306 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
307 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
308 find_script_by_name(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
309 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
310 int sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
311 scriptitem_T *si;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
312
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
313 for (sid = script_items.ga_len; sid > 0; --sid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
314 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
315 // We used to check inode here, but that doesn't work:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
316 // - If a script is edited and written, it may get a different
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
317 // inode number, even though to the user it is the same script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
318 // - If a script is deleted and another script is written, with a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
319 // different name, the inode may be re-used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
320 si = SCRIPT_ITEM(sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
321 if (si->sn_name != NULL && fnamecmp(si->sn_name, name) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
322 return sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
323 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
324 return -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
325 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
326
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
327 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
328 * Add a new scriptitem with all items initialized.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
329 * When running out of memory "error" is set to FAIL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
330 * Returns the script ID.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
331 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
332 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
333 get_new_scriptitem(int *error)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
334 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
335 static scid_T last_current_SID = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
336 int sid = ++last_current_SID;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
337 scriptitem_T *si = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
338
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
339 if (ga_grow(&script_items, (int)(sid - script_items.ga_len)) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
340 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
341 *error = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
342 return sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
343 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
344 while (script_items.ga_len < sid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
345 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
346 si = ALLOC_CLEAR_ONE(scriptitem_T);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
347 if (si == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
348 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
349 *error = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
350 return sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
351 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
352 ++script_items.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
353 SCRIPT_ITEM(script_items.ga_len) = si;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
354 si->sn_name = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
355 si->sn_version = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
356
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
357 // Allocate the local script variables to use for this script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
358 new_script_vars(script_items.ga_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
359 ga_init2(&si->sn_var_vals, sizeof(svar_T), 10);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
360 hash_init(&si->sn_all_vars.dv_hashtab);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
361 ga_init2(&si->sn_imports, sizeof(imported_T), 10);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
362 ga_init2(&si->sn_type_list, sizeof(type_T), 10);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
363 # ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
364 si->sn_prof_on = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
365 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
366 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
367
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
368 // "si" can't be NULL, check only to avoid a compiler warning
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
369 if (si != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
370 // Used to check script variable index is still valid.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
371 si->sn_script_seq = current_sctx.sc_seq;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
372
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
373 return sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
374 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
375
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
376 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
377 get_new_scriptitem_for_fname(int *error, char_u *fname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
378 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
379 int sid = get_new_scriptitem(error);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
381 if (*error == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
382 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
383 scriptitem_T *si = SCRIPT_ITEM(sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
384
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
385 si->sn_name = vim_strsave(fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
386 si->sn_state = SN_STATE_NOT_LOADED;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
387 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
388 return sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
389 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
390
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
391 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
392 find_script_callback(char_u *fname, void *cookie)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
393 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
394 int sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
395 int error = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
396 int *ret_sid = cookie;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
397
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
398 sid = find_script_by_name(fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
399 if (sid < 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
400 // script does not exist yet, create a new scriptitem
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
401 sid = get_new_scriptitem_for_fname(&error, fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
402 *ret_sid = sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
403 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
404 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
405
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
406 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
407 * Find the file "name" in all directories in "path" and invoke
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
408 * "callback(fname, cookie)".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
409 * "name" can contain wildcards.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
410 * When "flags" has DIP_ALL: source all files, otherwise only the first one.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
411 * When "flags" has DIP_DIR: find directories instead of files.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
412 * When "flags" has DIP_ERR: give an error message if there is no match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
413 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
414 * return FAIL when no file could be sourced, OK otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
415 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
416 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
417 do_in_path(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
418 char_u *path,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
419 char_u *name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
420 int flags,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
421 void (*callback)(char_u *fname, void *ck),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
422 void *cookie)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
423 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
424 char_u *rtp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
425 char_u *np;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
426 char_u *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
427 char_u *rtp_copy;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
428 char_u *tail;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
429 int num_files;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
430 char_u **files;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
431 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
432 int did_one = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
433 #ifdef AMIGA
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
434 struct Process *proc = (struct Process *)FindTask(0L);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
435 APTR save_winptr = proc->pr_WindowPtr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
436
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
437 // Avoid a requester here for a volume that doesn't exist.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
438 proc->pr_WindowPtr = (APTR)-1L;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
439 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
440
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
441 // Make a copy of 'runtimepath'. Invoking the callback may change the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
442 // value.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
443 rtp_copy = vim_strsave(path);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
444 buf = alloc(MAXPATHL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
445 if (buf != NULL && rtp_copy != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
446 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
447 if (p_verbose > 10 && name != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
448 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
449 verbose_enter();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
450 smsg(_("Searching for \"%s\" in \"%s\""),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
451 (char *)name, (char *)path);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
452 verbose_leave();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
453 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
454
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
455 // Loop over all entries in 'runtimepath'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
456 rtp = rtp_copy;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
457 while (*rtp != NUL && ((flags & DIP_ALL) || !did_one))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
458 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
459 size_t buflen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
460
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
461 // Copy the path from 'runtimepath' to buf[].
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
462 copy_option_part(&rtp, buf, MAXPATHL, ",");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
463 buflen = STRLEN(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
464
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
465 // Skip after or non-after directories.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
466 if (flags & (DIP_NOAFTER | DIP_AFTER))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
467 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
468 int is_after = buflen >= 5
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
469 && STRCMP(buf + buflen - 5, "after") == 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
470
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
471 if ((is_after && (flags & DIP_NOAFTER))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
472 || (!is_after && (flags & DIP_AFTER)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
473 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
474 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
475
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
476 if (name == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
477 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
478 (*callback)(buf, (void *) &cookie);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
479 if (!did_one)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
480 did_one = (cookie == NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
481 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
482 else if (buflen + STRLEN(name) + 2 < MAXPATHL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
483 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
484 add_pathsep(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
485 tail = buf + STRLEN(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
486
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
487 // Loop over all patterns in "name"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
488 np = name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
489 while (*np != NUL && ((flags & DIP_ALL) || !did_one))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
490 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
491 // Append the pattern from "name" to buf[].
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
492 copy_option_part(&np, tail, (int)(MAXPATHL - (tail - buf)),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
493 "\t ");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
494
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
495 if (p_verbose > 10)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
496 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
497 verbose_enter();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
498 smsg(_("Searching for \"%s\""), buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
499 verbose_leave();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
500 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
501
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
502 // Expand wildcards, invoke the callback for each match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
503 if (gen_expand_wildcards(1, &buf, &num_files, &files,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
504 (flags & DIP_DIR) ? EW_DIR : EW_FILE) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
505 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
506 for (i = 0; i < num_files; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
507 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
508 (*callback)(files[i], cookie);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
509 did_one = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
510 if (!(flags & DIP_ALL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
511 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
512 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
513 FreeWild(num_files, files);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
514 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
515 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
516 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
517 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
518 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
519 vim_free(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
520 vim_free(rtp_copy);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
521 if (!did_one && name != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
522 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
523 char *basepath = path == p_rtp ? "runtimepath" : "packpath";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
524
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
525 if (flags & DIP_ERR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
526 semsg(_(e_directory_not_found_in_str_str), basepath, name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
527 else if (p_verbose > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
528 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
529 verbose_enter();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
530 smsg(_("not found in '%s': \"%s\""), basepath, name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
531 verbose_leave();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
532 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
533 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
534
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
535 #ifdef AMIGA
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
536 proc->pr_WindowPtr = save_winptr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
537 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
538
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
539 return did_one ? OK : FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
540 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
541
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
542 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
543 * Find "name" in "path". When found, invoke the callback function for
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
544 * it: callback(fname, "cookie")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
545 * When "flags" has DIP_ALL repeat for all matches, otherwise only the first
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
546 * one is used.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
547 * Returns OK when at least one match found, FAIL otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
548 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
549 * If "name" is NULL calls callback for each entry in "path". Cookie is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
550 * passed by reference in this case, setting it to NULL indicates that callback
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
551 * has done its job.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
552 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
553 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
554 do_in_path_and_pp(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
555 char_u *path,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
556 char_u *name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
557 int flags,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
558 void (*callback)(char_u *fname, void *ck),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
559 void *cookie)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
560 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
561 int done = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
562 char_u *s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
563 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
564 char *start_dir = "pack/*/start/*/%s";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
565 char *opt_dir = "pack/*/opt/*/%s";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
566
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
567 if ((flags & DIP_NORTP) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
568 done = do_in_path(path, name, flags, callback, cookie);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
569
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
570 if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
571 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
572 len = (int)(STRLEN(start_dir) + STRLEN(name));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
573 s = alloc(len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
574 if (s == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
575 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
576 vim_snprintf((char *)s, len, start_dir, name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
577 done = do_in_path(p_pp, s, flags, callback, cookie);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
578 vim_free(s);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
579 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
580
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
581 if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_OPT))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
582 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
583 len = (int)(STRLEN(opt_dir) + STRLEN(name));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
584 s = alloc(len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
585 if (s == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
586 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
587 vim_snprintf((char *)s, len, opt_dir, name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
588 done = do_in_path(p_pp, s, flags, callback, cookie);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
589 vim_free(s);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
590 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
591
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
592 return done;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
593 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
594
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
595 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
596 * Just like do_in_path_and_pp(), using 'runtimepath' for "path".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
597 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
598 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
599 do_in_runtimepath(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
600 char_u *name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
601 int flags,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
602 void (*callback)(char_u *fname, void *ck),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
603 void *cookie)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
604 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
605 return do_in_path_and_pp(p_rtp, name, flags, callback, cookie);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
606 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
607
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
608 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
609 * Source the file "name" from all directories in 'runtimepath'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
610 * "name" can contain wildcards.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
611 * When "flags" has DIP_ALL: source all files, otherwise only the first one.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
612 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
613 * return FAIL when no file could be sourced, OK otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
614 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
615 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
616 source_runtime(char_u *name, int flags)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
617 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
618 return source_in_path(p_rtp, name, flags, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
619 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
620
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
621 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
622 * Just like source_runtime(), but use "path" instead of 'runtimepath'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
623 * and return the script ID in "ret_sid".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
624 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
625 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
626 source_in_path(char_u *path, char_u *name, int flags, int *ret_sid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
627 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
628 return do_in_path_and_pp(path, name, flags, source_callback, ret_sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
629 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
630
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
631 #if defined(FEAT_EVAL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
632
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
633 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
634 * Find "name" in 'runtimepath'. If found a new scriptitem is created for it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
635 * and it's script ID is returned.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
636 * If not found returns -1.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
637 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
638 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
639 find_script_in_rtp(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
640 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
641 int sid = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
642
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
643 (void)do_in_path_and_pp(p_rtp, name, DIP_NOAFTER,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
644 find_script_callback, &sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
645 return sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
646 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
647
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
648 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
649 * Expand wildcards in "pat" and invoke do_source() for each match.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
650 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
651 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
652 source_all_matches(char_u *pat)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
653 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
654 int num_files;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
655 char_u **files;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
656 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
657
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
658 if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) != OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
659 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
660
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
661 for (i = 0; i < num_files; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
662 (void)do_source(files[i], FALSE, DOSO_NONE, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
663 FreeWild(num_files, files);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
664 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
665
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
666 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
667 * Add the package directory to 'runtimepath'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
668 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
669 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
670 add_pack_dir_to_rtp(char_u *fname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
671 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
672 char_u *p4, *p3, *p2, *p1, *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
673 char_u *entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
674 char_u *insp = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
675 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
676 char_u *new_rtp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
677 int keep;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
678 size_t oldlen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
679 size_t addlen;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
680 size_t new_rtp_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
681 char_u *afterdir = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
682 size_t afterlen = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
683 char_u *after_insp = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
684 char_u *ffname = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
685 size_t fname_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
686 char_u *buf = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
687 char_u *rtp_ffname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
688 int match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
689 int retval = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
690
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
691 p4 = p3 = p2 = p1 = get_past_head(fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
692 for (p = p1; *p; MB_PTR_ADV(p))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
693 if (vim_ispathsep_nocolon(*p))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
694 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
695 p4 = p3; p3 = p2; p2 = p1; p1 = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
696 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
697
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
698 // now we have:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
699 // rtp/pack/name/start/name
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
700 // p4 p3 p2 p1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
701 //
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
702 // find the part up to "pack" in 'runtimepath'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
703 c = *++p4; // append pathsep in order to expand symlink
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
704 *p4 = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
705 ffname = fix_fname(fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
706 *p4 = c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
707 if (ffname == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
708 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
709
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
710 // Find "ffname" in "p_rtp", ignoring '/' vs '\' differences.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
711 // Also stop at the first "after" directory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
712 fname_len = STRLEN(ffname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
713 buf = alloc(MAXPATHL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
714 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
715 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
716 for (entry = p_rtp; *entry != NUL; )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
717 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
718 char_u *cur_entry = entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
719
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
720 copy_option_part(&entry, buf, MAXPATHL, ",");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
721
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
722 if ((p = (char_u *)strstr((char *)buf, "after")) != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
723 && p > buf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
724 && vim_ispathsep(p[-1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
725 && (vim_ispathsep(p[5]) || p[5] == NUL || p[5] == ','))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
726 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
727 if (insp == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
728 // Did not find "ffname" before the first "after" directory,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
729 // insert it before this entry.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
730 insp = cur_entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
731 after_insp = cur_entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
732 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
733 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
734
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
735 if (insp == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
736 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
737 add_pathsep(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
738 rtp_ffname = fix_fname(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
739 if (rtp_ffname == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
740 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
741 match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
742 vim_free(rtp_ffname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
743 if (match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
744 // Insert "ffname" after this entry (and comma).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
745 insp = entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
746 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
747 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
748
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
749 if (insp == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
750 // Both "fname" and "after" not found, append at the end.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
751 insp = p_rtp + STRLEN(p_rtp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
752
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
753 // check if rtp/pack/name/start/name/after exists
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
754 afterdir = concat_fnames(fname, (char_u *)"after", TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
755 if (afterdir != NULL && mch_isdir(afterdir))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
756 afterlen = STRLEN(afterdir) + 1; // add one for comma
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
757
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
758 oldlen = STRLEN(p_rtp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
759 addlen = STRLEN(fname) + 1; // add one for comma
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
760 new_rtp = alloc(oldlen + addlen + afterlen + 1); // add one for NUL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
761 if (new_rtp == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
762 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
763
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
764 // We now have 'rtp' parts: {keep}{keep_after}{rest}.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
765 // Create new_rtp, first: {keep},{fname}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
766 keep = (int)(insp - p_rtp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
767 mch_memmove(new_rtp, p_rtp, keep);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
768 new_rtp_len = keep;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
769 if (*insp == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
770 new_rtp[new_rtp_len++] = ','; // add comma before
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
771 mch_memmove(new_rtp + new_rtp_len, fname, addlen - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
772 new_rtp_len += addlen - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
773 if (*insp != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
774 new_rtp[new_rtp_len++] = ','; // add comma after
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
775
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
776 if (afterlen > 0 && after_insp != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
777 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
778 int keep_after = (int)(after_insp - p_rtp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
779
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
780 // Add to new_rtp: {keep},{fname}{keep_after},{afterdir}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
781 mch_memmove(new_rtp + new_rtp_len, p_rtp + keep,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
782 keep_after - keep);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
783 new_rtp_len += keep_after - keep;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
784 mch_memmove(new_rtp + new_rtp_len, afterdir, afterlen - 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
785 new_rtp_len += afterlen - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
786 new_rtp[new_rtp_len++] = ',';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
787 keep = keep_after;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
788 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
789
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
790 if (p_rtp[keep] != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
791 // Append rest: {keep},{fname}{keep_after},{afterdir}{rest}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
792 mch_memmove(new_rtp + new_rtp_len, p_rtp + keep, oldlen - keep + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
793 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
794 new_rtp[new_rtp_len] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
795
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
796 if (afterlen > 0 && after_insp == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
797 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
798 // Append afterdir when "after" was not found:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
799 // {keep},{fname}{rest},{afterdir}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
800 STRCAT(new_rtp, ",");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
801 STRCAT(new_rtp, afterdir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
802 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
803
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
804 set_option_value_give_err((char_u *)"rtp", 0L, new_rtp, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
805 vim_free(new_rtp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
806 retval = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
807
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
808 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
809 vim_free(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
810 vim_free(ffname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
811 vim_free(afterdir);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
812 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
813 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
814
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
815 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
816 * Load scripts in "plugin" and "ftdetect" directories of the package.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
817 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
818 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
819 load_pack_plugin(char_u *fname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
820 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
821 static char *plugpat = "%s/plugin/**/*.vim";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
822 static char *ftpat = "%s/ftdetect/*.vim";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
823 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
824 char_u *ffname = fix_fname(fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
825 char_u *pat = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
826 int retval = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
827
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
828 if (ffname == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
829 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
830 len = (int)STRLEN(ffname) + (int)STRLEN(ftpat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
831 pat = alloc(len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
832 if (pat == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
833 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
834 vim_snprintf((char *)pat, len, plugpat, ffname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
835 source_all_matches(pat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
836
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
837 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
838 char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
839
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
840 // If runtime/filetype.vim wasn't loaded yet, the scripts will be
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
841 // found when it loads.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
842 if (cmd != NULL && eval_to_number(cmd, FALSE) > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
843 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
844 do_cmdline_cmd((char_u *)"augroup filetypedetect");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
845 vim_snprintf((char *)pat, len, ftpat, ffname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
846 source_all_matches(pat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
847 do_cmdline_cmd((char_u *)"augroup END");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
848 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
849 vim_free(cmd);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
850 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
851 vim_free(pat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
852 retval = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
853
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
854 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
855 vim_free(ffname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
856 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
857 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
858
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
859 // used for "cookie" of add_pack_plugin()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
860 static int APP_ADD_DIR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
861 static int APP_LOAD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
862 static int APP_BOTH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
863
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
864 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
865 add_pack_plugin(char_u *fname, void *cookie)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
866 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
867 if (cookie != &APP_LOAD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
868 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
869 char_u *buf = alloc(MAXPATHL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
870 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
871 int found = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
872
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
873 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
874 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
875 p = p_rtp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
876 while (*p != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
877 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
878 copy_option_part(&p, buf, MAXPATHL, ",");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
879 if (pathcmp((char *)buf, (char *)fname, -1) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
880 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
881 found = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
882 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
883 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
884 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
885 vim_free(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
886 if (!found)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
887 // directory is not yet in 'runtimepath', add it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
888 if (add_pack_dir_to_rtp(fname) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
889 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
890 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
891
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
892 if (cookie != &APP_ADD_DIR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
893 load_pack_plugin(fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
894 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
895
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
896 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
897 * Add all packages in the "start" directory to 'runtimepath'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
898 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
899 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
900 add_pack_start_dirs(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
901 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
902 do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
903 add_pack_plugin, &APP_ADD_DIR);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
904 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
905
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
906 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
907 * Load plugins from all packages in the "start" directory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
908 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
909 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
910 load_start_packages(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
911 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
912 did_source_packages = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
913 do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
914 add_pack_plugin, &APP_LOAD);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
915 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
916
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
917 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
918 * ":packloadall"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
919 * Find plugins in the package directories and source them.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
920 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
921 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
922 ex_packloadall(exarg_T *eap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
923 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
924 if (!did_source_packages || eap->forceit)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
925 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
926 // First do a round to add all directories to 'runtimepath', then load
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
927 // the plugins. This allows for plugins to use an autoload directory
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
928 // of another plugin.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
929 add_pack_start_dirs();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
930 load_start_packages();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
931 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
932 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
933
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
934 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
935 * ":packadd[!] {name}"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
936 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
937 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
938 ex_packadd(exarg_T *eap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
939 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
940 static char *plugpat = "pack/*/%s/%s";
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
941 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
942 char *pat;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
943 int round;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
944 int res = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
945
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
946 // Round 1: use "start", round 2: use "opt".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
947 for (round = 1; round <= 2; ++round)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
948 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
949 // Only look under "start" when loading packages wasn't done yet.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
950 if (round == 1 && did_source_packages)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
951 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
952
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
953 len = (int)STRLEN(plugpat) + (int)STRLEN(eap->arg) + 5;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
954 pat = alloc(len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
955 if (pat == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
956 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
957 vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
958 // The first round don't give a "not found" error, in the second round
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
959 // only when nothing was found in the first round.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
960 res = do_in_path(p_pp, (char_u *)pat,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
961 DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
962 add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
963 vim_free(pat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
964 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
965 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
966 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
967
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
968 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
969 * Sort "gap" and remove duplicate entries. "gap" is expected to contain a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
970 * list of file names in allocated memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
971 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
972 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
973 remove_duplicates(garray_T *gap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
974 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
975 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
976 int j;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
977 char_u **fnames = (char_u **)gap->ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
978
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
979 sort_strings(fnames, gap->ga_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
980 for (i = gap->ga_len - 1; i > 0; --i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
981 if (fnamecmp(fnames[i - 1], fnames[i]) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
982 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
983 vim_free(fnames[i]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
984 for (j = i + 1; j < gap->ga_len; ++j)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
985 fnames[j - 1] = fnames[j];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
986 --gap->ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
987 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
988 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
989
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
990 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
991 ExpandRTDir_int(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
992 char_u *pat,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
993 size_t pat_len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
994 int flags,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
995 int keep_ext,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
996 garray_T *gap,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
997 char *dirnames[])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
998 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
999 for (int i = 0; dirnames[i] != NULL; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1000 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1001 size_t buf_len = STRLEN(dirnames[i]) + pat_len + 22;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1002 char *buf = alloc(buf_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1003 if (buf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1004 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1005 ga_clear_strings(gap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1006 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1007 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1008 char *tail = buf + 15;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1009 size_t tail_buflen = buf_len - 15;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1010 int glob_flags = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1011 int expand_dirs = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1012
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1013 if (*(dirnames[i]) == NUL) // empty dir used for :runtime
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1014 vim_snprintf(tail, tail_buflen, "%s*.vim", pat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1015 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1016 vim_snprintf(tail, tail_buflen, "%s/%s*.vim", dirnames[i], pat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1017
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1018 expand:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1019 if ((flags & DIP_NORTP) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1020 globpath(p_rtp, (char_u *)tail, gap, glob_flags, expand_dirs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1021
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1022 if (flags & DIP_START)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1023 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1024 memcpy(tail - 15, "pack/*/start/*/", 15);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1025 globpath(p_pp, (char_u *)tail - 15, gap, glob_flags, expand_dirs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1026 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1027
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1028 if (flags & DIP_OPT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1029 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1030 memcpy(tail - 13, "pack/*/opt/*/", 13);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1031 globpath(p_pp, (char_u *)tail - 13, gap, glob_flags, expand_dirs);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1032 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1033
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1034 if (*(dirnames[i]) == NUL && !expand_dirs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1035 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1036 // expand dir names in another round
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1037 vim_snprintf(tail, tail_buflen, "%s*", pat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1038 glob_flags = WILD_ADD_SLASH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1039 expand_dirs = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1040 goto expand;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1041 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1042
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1043 vim_free(buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1044 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1045
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1046 int pat_pathsep_cnt = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1047 for (size_t i = 0; i < pat_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1048 if (vim_ispathsep(pat[i]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1049 ++pat_pathsep_cnt;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1050
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1051 for (int i = 0; i < gap->ga_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1052 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1053 char_u *match = ((char_u **)gap->ga_data)[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1054 char_u *s = match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1055 char_u *e = s + STRLEN(s);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1056 if (e - 4 > s && !keep_ext && STRNICMP(e - 4, ".vim", 4) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1057 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1058 e -= 4;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1059 *e = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1060 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1061
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1062 int match_pathsep_cnt = (e > s && e[-1] == '/') ? -1 : 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1063 for (s = e; s > match; MB_PTR_BACK(match, s))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1064 if (s < match || (vim_ispathsep(*s)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1065 && ++match_pathsep_cnt > pat_pathsep_cnt))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1066 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1067 ++s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1068 if (s != match)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1069 mch_memmove(match, s, e - s + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1070 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1071
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1072 if (gap->ga_len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1073 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1074
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1075 // Sort and remove duplicates which can happen when specifying multiple
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1076 // directories in dirnames.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1077 remove_duplicates(gap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1078 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1079
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1080 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1081 * Expand runtime file names.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1082 * Search from 'runtimepath':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1083 * 'runtimepath'/{dirnames}/{pat}.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1084 * When "flags" has DIP_START: search also from "start" of 'packpath':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1085 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1086 * When "flags" has DIP_OPT: search also from "opt" of 'packpath':
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1087 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1088 * "dirnames" is an array with one or more directory names.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1089 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1090 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1091 ExpandRTDir(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1092 char_u *pat,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1093 int flags,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1094 int *num_file,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1095 char_u ***file,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1096 char *dirnames[])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1097 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1098 *num_file = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1099 *file = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1100
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1101 garray_T ga;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1102 ga_init2(&ga, sizeof(char *), 10);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1103
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1104 ExpandRTDir_int(pat, STRLEN(pat), flags, FALSE, &ga, dirnames);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1106 if (ga.ga_len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1107 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1108
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1109 *file = ga.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1110 *num_file = ga.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1111 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1112 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1113
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1114 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1115 * Handle command line completion for :runtime command.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1116 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1117 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1118 expand_runtime_cmd(char_u *pat, int *numMatches, char_u ***matches)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1119 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1120 *numMatches = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1121 *matches = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1122
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1123 garray_T ga;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1124 ga_init2(&ga, sizeof(char *), 10);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1125
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1126 size_t pat_len = (int)STRLEN(pat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1127 char *dirnames[] = {"", NULL};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1128 ExpandRTDir_int(pat, pat_len, runtime_expand_flags, TRUE, &ga, dirnames);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1129
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1130 // Try to complete values for [where] argument when none was found.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1131 if (runtime_expand_flags == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1132 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1133 char *where_values[] = {"START", "OPT", "PACK", "ALL"};
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1134 for (size_t i = 0; i < ARRAY_LENGTH(where_values); ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1135 if (STRNCMP(pat, where_values[i], pat_len) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1136 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1137 char_u *p = vim_strsave((char_u *)where_values[i]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1138 if (p != NULL && ga_add_string(&ga, p) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1139 vim_free(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1140 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1141 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1142
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1143 if (ga.ga_len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1144 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1145
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1146 *matches = ga.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1147 *numMatches = ga.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1148 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1149 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1150
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1151 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1152 * Expand loadplugin names:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1153 * 'packpath'/pack/ * /opt/{pat}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1154 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1155 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1156 ExpandPackAddDir(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1157 char_u *pat,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1158 int *num_file,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1159 char_u ***file)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1160 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1161 char_u *s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1162 char_u *e;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1163 char_u *match;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1164 garray_T ga;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1165 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1166 int pat_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1167
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1168 *num_file = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1169 *file = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1170 pat_len = (int)STRLEN(pat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1171 ga_init2(&ga, sizeof(char *), 10);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1172
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1173 s = alloc(pat_len + 26);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1174 if (s == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1175 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1176 ga_clear_strings(&ga);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1177 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1178 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1179 sprintf((char *)s, "pack/*/opt/%s*", pat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1180 globpath(p_pp, s, &ga, 0, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1181 vim_free(s);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1182
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1183 for (i = 0; i < ga.ga_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1184 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1185 match = ((char_u **)ga.ga_data)[i];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1186 s = gettail(match);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1187 e = s + STRLEN(s);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1188 mch_memmove(match, s, e - s + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1189 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1190
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1191 if (ga.ga_len == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1192 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1193
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1194 // Sort and remove duplicates which can happen when specifying multiple
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1195 // directories in dirnames.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1196 remove_duplicates(&ga);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1197
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1198 *file = ga.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1199 *num_file = ga.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1200 return OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1201 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1202
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1203 static void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1204 cmd_source(char_u *fname, exarg_T *eap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1205 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1206 int clearvars = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1207
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1208 if (*fname != NUL && STRNCMP(fname, "++clear", 7) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1209 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1210 // ++clear argument is supplied
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1211 clearvars = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1212 fname = fname + 7;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1213 if (*fname != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1214 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1215 semsg(_(e_invalid_argument_str), eap->arg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1216 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1217 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1218 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1219
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1220 if (*fname != NUL && eap != NULL && eap->addr_count > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1221 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1222 // if a filename is specified to :source, then a range is not allowed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1223 emsg(_(e_no_range_allowed));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1224 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1225 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1226
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1227 if (eap != NULL && *fname == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1228 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1229 if (eap->forceit)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1230 // a file name is needed to source normal mode commands
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1231 emsg(_(e_argument_required));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1232 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1233 // source ex commands from the current buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1234 do_source_ext(NULL, FALSE, FALSE, NULL, eap, clearvars);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1235 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1236 else if (eap != NULL && eap->forceit)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1237 // ":source!": read Normal mode commands
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1238 // Need to execute the commands directly. This is required at least
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1239 // for:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1240 // - ":g" command busy
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1241 // - after ":argdo", ":windo" or ":bufdo"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1242 // - another command follows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1243 // - inside a loop
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1244 openscript(fname, global_busy || listcmd_busy || eap->nextcmd != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1245 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1246 || eap->cstack->cs_idx >= 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1247 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1248 );
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1249
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1250 // ":source" read ex commands
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1251 else if (do_source(fname, FALSE, DOSO_NONE, NULL) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1252 semsg(_(e_cant_open_file_str), fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1253 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1254
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1255 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1256 * ":source {fname}"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1257 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1258 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1259 ex_source(exarg_T *eap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1260 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1261 #ifdef FEAT_BROWSE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1262 if (cmdmod.cmod_flags & CMOD_BROWSE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1263 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1264 char_u *fname = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1265
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1266 fname = do_browse(0, (char_u *)_("Source Vim script"), eap->arg,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1267 NULL, NULL,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1268 (char_u *)_(BROWSE_FILTER_MACROS), NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1269 if (fname != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1270 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1271 cmd_source(fname, eap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1272 vim_free(fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1273 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1274 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1275 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1276 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1277 cmd_source(eap->arg, eap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1278 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1279
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1280 #if defined(FEAT_EVAL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1281 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1282 * ":options"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1283 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1284 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1285 ex_options(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1286 exarg_T *eap UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1287 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1288 char_u buf[500];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1289 int multi_mods = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1290
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1291 buf[0] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1292 (void)add_win_cmd_modifiers(buf, &cmdmod, &multi_mods);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1293
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1294 vim_setenv((char_u *)"OPTWIN_CMD", buf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1295 cmd_source((char_u *)SYS_OPTWIN_FILE, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1296 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1297 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1298
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1299 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1300 * ":source" and associated commands.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1301 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1302
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1303 #if defined(FEAT_EVAL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1304 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1305 * Return the address holding the next breakpoint line for a source cookie.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1306 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1307 linenr_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1308 source_breakpoint(void *cookie)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1309 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1310 return &((source_cookie_T *)cookie)->breakpoint;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1311 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1312
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1313 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1314 * Return the address holding the debug tick for a source cookie.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1315 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1316 int *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1317 source_dbg_tick(void *cookie)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1318 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1319 return &((source_cookie_T *)cookie)->dbg_tick;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1320 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1321
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1322 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1323 * Return the nesting level for a source cookie.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1324 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1325 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1326 source_level(void *cookie)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1327 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1328 return ((source_cookie_T *)cookie)->level;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1329 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1330
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1331 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1332 * Return the readahead line. Note that the pointer may become invalid when
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1333 * getting the next line, if it's concatenated with the next one.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1334 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1335 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1336 source_nextline(void *cookie)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1337 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1338 return ((source_cookie_T *)cookie)->nextline;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1339 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1340 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1341
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1342 #if (defined(MSWIN) && defined(FEAT_CSCOPE)) || defined(HAVE_FD_CLOEXEC)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1343 # define USE_FOPEN_NOINH
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1344 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1345 * Special function to open a file without handle inheritance.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1346 * When possible the handle is closed on exec().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1347 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1348 static FILE *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1349 fopen_noinh_readbin(char *filename)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1350 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1351 # ifdef MSWIN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1352 int fd_tmp = mch_open(filename, O_RDONLY | O_BINARY | O_NOINHERIT, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1353 # else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1354 int fd_tmp = mch_open(filename, O_RDONLY, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1355 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1356
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1357 if (fd_tmp == -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1358 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1359
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1360 # ifdef HAVE_FD_CLOEXEC
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1361 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1362 int fdflags = fcntl(fd_tmp, F_GETFD);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1363 if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1364 (void)fcntl(fd_tmp, F_SETFD, fdflags | FD_CLOEXEC);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1365 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1366 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1367
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1368 return fdopen(fd_tmp, READBIN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1369 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1370 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1371
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1372 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1373 * Initialization for sourcing lines from the current buffer. Reads all the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1374 * lines from the buffer and stores it in the cookie grow array.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1375 * Returns a pointer to the name ":source buffer=<n>" on success and NULL on
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1376 * failure.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1377 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1378 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1379 do_source_buffer_init(source_cookie_T *sp, exarg_T *eap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1380 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1381 linenr_T curr_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1382 char_u *line = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1383 char_u *fname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1384
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1385 CLEAR_FIELD(*sp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1386
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1387 if (curbuf == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1388 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1389
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1390 // Use ":source buffer=<num>" as the script name
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1391 vim_snprintf((char *)IObuff, IOSIZE, ":source buffer=%d", curbuf->b_fnum);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1392 fname = vim_strsave(IObuff);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1393 if (fname == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1394 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1395
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1396 ga_init2(&sp->buflines, sizeof(char_u *), 100);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1397
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1398 // Copy the lines from the buffer into a grow array
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1399 for (curr_lnum = eap->line1; curr_lnum <= eap->line2; curr_lnum++)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1400 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1401 line = vim_strsave(ml_get(curr_lnum));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1402 if (line == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1403 goto errret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1404 if (ga_add_string(&sp->buflines, line) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1405 goto errret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1406 line = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1407 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1408 sp->buf_lnum = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1409 sp->source_from_buf = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1410
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1411 return fname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1412
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1413 errret:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1414 vim_free(fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1415 vim_free(line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1416 ga_clear_strings(&sp->buflines);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1417 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1418 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1419
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1420 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1421 * Read the file "fname" and execute its lines as EX commands.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1422 * When "ret_sid" is not NULL and we loaded the script before, don't load it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1423 * again.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1424 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1425 * The "eap" argument is used when sourcing lines from a buffer instead of a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1426 * file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1427 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1428 * If "clearvars" is TRUE, then for scripts which are loaded more than
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1429 * once, clear all the functions and variables previously defined in that
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1430 * script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1431 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1432 * This function may be called recursively!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1433 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1434 * Return FAIL if file could not be opened, OK otherwise.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1435 * If a scriptitem_T was found or created "*ret_sid" is set to the SID.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1436 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1437 static int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1438 do_source_ext(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1439 char_u *fname,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1440 int check_other, // check for .vimrc and _vimrc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1441 int is_vimrc, // DOSO_ value
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1442 int *ret_sid UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1443 exarg_T *eap,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1444 int clearvars UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1445 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1446 source_cookie_T cookie;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1447 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1448 char_u *fname_not_fixed = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1449 char_u *fname_exp = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1450 char_u *firstline = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1451 int retval = FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1452 sctx_T save_current_sctx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1453 #ifdef STARTUPTIME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1454 struct timeval tv_rel;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1455 struct timeval tv_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1456 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1457 #ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1458 proftime_T wait_start;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1459 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1460 int save_sticky_cmdmod_flags = sticky_cmdmod_flags;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1461 int trigger_source_post = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1462 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1463 funccal_entry_T funccalp_entry;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1464 int save_debug_break_level = debug_break_level;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1465 int sid = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1466 scriptitem_T *si = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1467 int save_estack_compiling = estack_compiling;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1468 ESTACK_CHECK_DECLARATION;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1469 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1470
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1471 CLEAR_FIELD(cookie);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1472 if (fname == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1473 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1474 // sourcing lines from a buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1475 fname_exp = do_source_buffer_init(&cookie, eap);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1476 if (fname_exp == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1477 return FAIL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1478 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1479 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1480 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1481 fname_not_fixed = expand_env_save(fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1482 if (fname_not_fixed == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1483 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1484 fname_exp = fix_fname(fname_not_fixed);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1485 if (fname_exp == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1486 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1487 if (mch_isdir(fname_exp))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1488 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1489 smsg(_("Cannot source a directory: \"%s\""), fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1490 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1491 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1492 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1493 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1494 estack_compiling = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1495
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1496 // See if we loaded this script before.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1497 sid = find_script_by_name(fname_exp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1498 if (sid > 0 && ret_sid != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1499 && SCRIPT_ITEM(sid)->sn_state != SN_STATE_NOT_LOADED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1500 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1501 // Already loaded and no need to load again, return here.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1502 *ret_sid = sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1503 retval = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1504 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1505 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1506 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1507
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1508 // Apply SourceCmd autocommands, they should get the file and source it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1509 if (has_autocmd(EVENT_SOURCECMD, fname_exp, NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1510 && apply_autocmds(EVENT_SOURCECMD, fname_exp, fname_exp,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1511 FALSE, curbuf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1512 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1513 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1514 retval = aborting() ? FAIL : OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1515 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1516 retval = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1517 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1518 if (retval == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1519 // Apply SourcePost autocommands.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1520 apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1521 FALSE, curbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1522 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1523 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1524
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1525 // Apply SourcePre autocommands, they may get the file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1526 apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1527
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1528 if (!cookie.source_from_buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1529 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1530 #ifdef USE_FOPEN_NOINH
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1531 cookie.fp = fopen_noinh_readbin((char *)fname_exp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1532 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1533 cookie.fp = mch_fopen((char *)fname_exp, READBIN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1534 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1535 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1536 if (cookie.fp == NULL && check_other)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1537 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1538 // Try again, replacing file name ".vimrc" by "_vimrc" or vice versa,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1539 // and ".exrc" by "_exrc" or vice versa.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1540 p = gettail(fname_exp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1541 if ((*p == '.' || *p == '_')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1542 && (STRICMP(p + 1, "vimrc") == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1543 || STRICMP(p + 1, "gvimrc") == 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1544 || STRICMP(p + 1, "exrc") == 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1545 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1546 if (*p == '_')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1547 *p = '.';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1548 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1549 *p = '_';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1550 #ifdef USE_FOPEN_NOINH
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1551 cookie.fp = fopen_noinh_readbin((char *)fname_exp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1552 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1553 cookie.fp = mch_fopen((char *)fname_exp, READBIN);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1554 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1555 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1556 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1557
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1558 if (cookie.fp == NULL && !cookie.source_from_buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1559 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1560 if (p_verbose > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1561 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1562 verbose_enter();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1563 if (SOURCING_NAME == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1564 smsg(_("could not source \"%s\""), fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1565 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1566 smsg(_("line %ld: could not source \"%s\""),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1567 SOURCING_LNUM, fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1568 verbose_leave();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1569 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1570 goto theend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1571 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1572
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1573 // The file exists.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1574 // - In verbose mode, give a message.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1575 // - For a vimrc file, may want to set 'compatible', call vimrc_found().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1576 if (p_verbose > 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1577 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1578 verbose_enter();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1579 if (SOURCING_NAME == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1580 smsg(_("sourcing \"%s\""), fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1581 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1582 smsg(_("line %ld: sourcing \"%s\""), SOURCING_LNUM, fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1583 verbose_leave();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1584 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1585 if (is_vimrc == DOSO_VIMRC)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1586 vimrc_found(fname_exp, (char_u *)"MYVIMRC");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1587 else if (is_vimrc == DOSO_GVIMRC)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1588 vimrc_found(fname_exp, (char_u *)"MYGVIMRC");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1589
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1590 #ifdef USE_CRNL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1591 // If no automatic file format: Set default to CR-NL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1592 if (*p_ffs == NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1593 cookie.fileformat = EOL_DOS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1594 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1595 cookie.fileformat = EOL_UNKNOWN;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1596 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1597
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1598 if (fname == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1599 // When sourcing a range of lines from a buffer, use the buffer line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1600 // number.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1601 cookie.sourcing_lnum = eap->line1 - 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1602 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1603 cookie.sourcing_lnum = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1604
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1605 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1606 // Check if this script has a breakpoint.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1607 cookie.breakpoint = dbg_find_breakpoint(TRUE, fname_exp, (linenr_T)0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1608 cookie.fname = fname_exp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1609 cookie.dbg_tick = debug_tick;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1610
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1611 cookie.level = ex_nesting_level;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1612 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1613
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1614 #ifdef STARTUPTIME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1615 if (time_fd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1616 time_push(&tv_rel, &tv_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1617 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1618
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1619 // "legacy" does not apply to commands in the script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1620 sticky_cmdmod_flags = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1621
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1622 save_current_sctx = current_sctx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1623 if (cmdmod.cmod_flags & CMOD_VIM9CMD)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1624 // When the ":vim9cmd" command modifier is used, source the script as a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1625 // Vim9 script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1626 current_sctx.sc_version = SCRIPT_VERSION_VIM9;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1627 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1628 current_sctx.sc_version = 1; // default script version
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1629
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1630 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1631 current_sctx.sc_lnum = 0;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1632
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1633 # ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1634 if (do_profiling == PROF_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1635 prof_child_enter(&wait_start); // entering a child now
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1636 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1637
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1638 // Don't use local function variables, if called from a function.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1639 // Also starts profiling timer for nested script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1640 save_funccal(&funccalp_entry);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1641
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1642 // Reset "KeyTyped" to avoid some commands thinking they are invoked
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1643 // interactively. E.g. defining a function would output indent.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1644 int save_KeyTyped = KeyTyped;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1645 KeyTyped = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1646
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1647 // Check if this script was sourced before to find its SID.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1648 // Always use a new sequence number.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1649 current_sctx.sc_seq = ++last_current_SID_seq;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1650 if (sid > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1651 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1652 hashtab_T *ht;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1653 int todo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1654 hashitem_T *hi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1655 dictitem_T *di;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1656
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1657 // loading the same script again
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1658 current_sctx.sc_sid = sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1659 si = SCRIPT_ITEM(sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1660 if (si->sn_state == SN_STATE_NOT_LOADED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1661 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1662 // this script was found but not loaded yet
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1663 si->sn_state = SN_STATE_NEW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1664 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1665 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1666 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1667 si->sn_state = SN_STATE_RELOAD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1668
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1669 if (!clearvars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1670 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1671 // Script-local variables remain but "const" can be set again.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1672 // In Vim9 script variables will be cleared when "vim9script"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1673 // is encountered without the "noclear" argument.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1674 ht = &SCRIPT_VARS(sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1675 todo = (int)ht->ht_used;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1676 FOR_ALL_HASHTAB_ITEMS(ht, hi, todo)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1677 if (!HASHITEM_EMPTY(hi))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1678 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1679 --todo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1680 di = HI2DI(hi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1681 di->di_flags |= DI_FLAGS_RELOAD;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1682 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1683 // imports can be redefined once
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1684 mark_imports_for_reload(sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1685 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1686 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1687 clear_vim9_scriptlocal_vars(sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1688
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1689 // reset version, "vim9script" may have been added or removed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1690 si->sn_version = 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1691 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1692 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1693 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1694 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1695 int error = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1696
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1697 // It's new, generate a new SID and initialize the scriptitem.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1698 sid = get_new_scriptitem(&error);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1699 current_sctx.sc_sid = sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1700 if (error == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1701 goto almosttheend;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1702 si = SCRIPT_ITEM(sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1703 si->sn_name = fname_exp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1704 fname_exp = vim_strsave(si->sn_name); // used for autocmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1705 if (ret_sid != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1706 *ret_sid = sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1707
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1708 // Remember the "is_vimrc" flag for when the file is sourced again.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1709 si->sn_is_vimrc = is_vimrc;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1710 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1711
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1712 // Keep the sourcing name/lnum, for recursive calls.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1713 estack_push(ETYPE_SCRIPT, si->sn_name, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1714 ESTACK_CHECK_SETUP;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1715
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1716 # ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1717 if (do_profiling == PROF_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1718 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1719 int forceit;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1720
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1721 // Check if we do profiling for this script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1722 if (!si->sn_prof_on && has_profiling(TRUE, si->sn_name, &forceit))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1723 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1724 script_do_profile(si);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1725 si->sn_pr_force = forceit;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1726 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1727 if (si->sn_prof_on)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1728 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1729 ++si->sn_pr_count;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1730 profile_start(&si->sn_pr_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1731 profile_zero(&si->sn_pr_children);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1732 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1733 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1734 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1735 #else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1736 // Keep the sourcing name/lnum, for recursive calls.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1737 estack_push(ETYPE_SCRIPT, fname_exp, 0);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1738 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1739
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1740 cookie.conv.vc_type = CONV_NONE; // no conversion
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1741
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1742 // Read the first line so we can check for a UTF-8 BOM.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1743 firstline = getsourceline(0, (void *)&cookie, 0, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1744 if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1745 && firstline[1] == 0xbb && firstline[2] == 0xbf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1746 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1747 // Found BOM; setup conversion, skip over BOM and recode the line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1748 convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1749 p = string_convert(&cookie.conv, firstline + 3, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1750 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1751 p = vim_strsave(firstline + 3);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1752 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1753 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1754 vim_free(firstline);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1755 firstline = p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1756 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1757 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1758
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1759 // Call do_cmdline, which will call getsourceline() to get the lines.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1760 do_cmdline(firstline, getsourceline, (void *)&cookie,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1761 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1762 retval = OK;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1763
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1764 #ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1765 if (do_profiling == PROF_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1766 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1767 // Get "si" again, "script_items" may have been reallocated.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1768 si = SCRIPT_ITEM(sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1769 if (si->sn_prof_on)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1770 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1771 profile_end(&si->sn_pr_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1772 profile_sub_wait(&wait_start, &si->sn_pr_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1773 profile_add(&si->sn_pr_total, &si->sn_pr_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1774 profile_self(&si->sn_pr_self, &si->sn_pr_start,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1775 &si->sn_pr_children);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1776 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1777 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1778 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1779
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1780 if (got_int)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1781 emsg(_(e_interrupted));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1782 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1783 ESTACK_CHECK_NOW;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1784 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1785 estack_pop();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1786 if (p_verbose > 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1787 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1788 verbose_enter();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1789 smsg(_("finished sourcing %s"), fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1790 if (SOURCING_NAME != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1791 smsg(_("continuing in %s"), SOURCING_NAME);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1792 verbose_leave();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1793 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1794 #ifdef STARTUPTIME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1795 if (time_fd != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1796 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1797 vim_snprintf((char *)IObuff, IOSIZE, "sourcing %s", fname);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1798 time_msg((char *)IObuff, &tv_start);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1799 time_pop(&tv_rel);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1800 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1801 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1802
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1803 if (!got_int)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1804 trigger_source_post = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1805
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1806 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1807 // After a "finish" in debug mode, need to break at first command of next
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1808 // sourced file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1809 if (save_debug_break_level > ex_nesting_level
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1810 && debug_break_level == ex_nesting_level)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1811 ++debug_break_level;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1812 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1813
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1814 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1815 almosttheend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1816 // If "sn_save_cpo" is set that means we encountered "vim9script": restore
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1817 // 'cpoptions', unless in the main .vimrc file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1818 // Get "si" again, "script_items" may have been reallocated.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1819 si = SCRIPT_ITEM(sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1820 if (si->sn_save_cpo != NULL && si->sn_is_vimrc == DOSO_NONE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1821 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1822 if (STRCMP(p_cpo, CPO_VIM) != 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1823 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1824 char_u *f;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1825 char_u *t;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1826
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1827 // 'cpo' was changed in the script. Apply the same change to the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1828 // saved value, if possible.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1829 for (f = (char_u *)CPO_VIM; *f != NUL; ++f)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1830 if (vim_strchr(p_cpo, *f) == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1831 && (t = vim_strchr(si->sn_save_cpo, *f)) != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1832 // flag was removed, also remove it from the saved 'cpo'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1833 mch_memmove(t, t + 1, STRLEN(t));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1834 for (f = p_cpo; *f != NUL; ++f)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1835 if (vim_strchr((char_u *)CPO_VIM, *f) == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1836 && vim_strchr(si->sn_save_cpo, *f) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1837 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1838 // flag was added, also add it to the saved 'cpo'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1839 t = alloc(STRLEN(si->sn_save_cpo) + 2);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1840 if (t != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1841 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1842 *t = *f;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1843 STRCPY(t + 1, si->sn_save_cpo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1844 vim_free(si->sn_save_cpo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1845 si->sn_save_cpo = t;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1846 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1847 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1848 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1849 set_option_value_give_err((char_u *)"cpo",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1850 0L, si->sn_save_cpo, OPT_NO_REDRAW);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1851 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1852 VIM_CLEAR(si->sn_save_cpo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1853
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1854 restore_funccal();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1855 # ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1856 if (do_profiling == PROF_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1857 prof_child_exit(&wait_start); // leaving a child now
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1858 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1859
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1860 KeyTyped = save_KeyTyped;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1861 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1862 current_sctx = save_current_sctx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1863
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1864 if (cookie.fp != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1865 fclose(cookie.fp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1866 if (cookie.source_from_buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1867 ga_clear_strings(&cookie.buflines);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1868 vim_free(cookie.nextline);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1869 vim_free(firstline);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1870 convert_setup(&cookie.conv, NULL, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1871
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1872 if (trigger_source_post)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1873 apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp, FALSE, curbuf);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1874
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1875 theend:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1876 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1877 if (sid > 0 && ret_sid != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1878 && fname_not_fixed != NULL && fname_exp != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1879 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1880 int not_fixed_sid = find_script_by_name(fname_not_fixed);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1881
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1882 // If "fname_not_fixed" is a symlink then we source the linked file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1883 // If the original name is in the script list we add the ID of the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1884 // script that was actually sourced.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1885 if (SCRIPT_ID_VALID(not_fixed_sid) && not_fixed_sid != sid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1886 SCRIPT_ITEM(not_fixed_sid)->sn_sourced_sid = sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1887 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1888 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1889
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1890 vim_free(fname_not_fixed);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1891 vim_free(fname_exp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1892 sticky_cmdmod_flags = save_sticky_cmdmod_flags;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1893 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1894 estack_compiling = save_estack_compiling;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1895 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1896 return retval;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1897 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1898
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1899 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1900 do_source(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1901 char_u *fname,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1902 int check_other, // check for .vimrc and _vimrc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1903 int is_vimrc, // DOSO_ value
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1904 int *ret_sid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1905 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1906 return do_source_ext(fname, check_other, is_vimrc, ret_sid, NULL, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1907 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1908
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1909
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1910 #if defined(FEAT_EVAL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1911
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1912 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1913 * ":scriptnames"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1914 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1915 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1916 ex_scriptnames(exarg_T *eap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1917 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1918 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1919
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1920 if (eap->addr_count > 0 || *eap->arg != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1921 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1922 // :script {scriptId}: edit the script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1923 if (eap->addr_count > 0 && !SCRIPT_ID_VALID(eap->line2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1924 emsg(_(e_invalid_argument));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1925 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1926 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1927 if (eap->addr_count > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1928 eap->arg = SCRIPT_ITEM(eap->line2)->sn_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1929 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1930 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1931 expand_env(eap->arg, NameBuff, MAXPATHL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1932 eap->arg = NameBuff;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1933 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1934 do_exedit(eap, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1935 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1936 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1937 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1938
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1939 for (i = 1; i <= script_items.ga_len && !got_int; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1940 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1941 scriptitem_T *si = SCRIPT_ITEM(i);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1942
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1943 if (si->sn_name != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1944 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1945 char sourced_buf[20];
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1946
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1947 home_replace(NULL, si->sn_name, NameBuff, MAXPATHL, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1948 if (si->sn_sourced_sid > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1949 vim_snprintf(sourced_buf, 20, "->%d", si->sn_sourced_sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1950 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1951 sourced_buf[0] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1952 vim_snprintf((char *)IObuff, IOSIZE, "%3d%s%s: %s",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1953 i,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1954 sourced_buf,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1955 si->sn_state == SN_STATE_NOT_LOADED ? " A" : "",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1956 NameBuff);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1957 if (!message_filtered(IObuff))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1958 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1959 msg_putchar('\n');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1960 msg_outtrans(IObuff);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1961 out_flush(); // output one line at a time
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1962 ui_breakcheck();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1963 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1964 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1965 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1966 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1967
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1968 # if defined(BACKSLASH_IN_FILENAME) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1969 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1970 * Fix slashes in the list of script names for 'shellslash'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1971 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1972 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1973 scriptnames_slash_adjust(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1974 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1975 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1976
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1977 for (i = 1; i <= script_items.ga_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1978 if (SCRIPT_ITEM(i)->sn_name != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1979 slash_adjust(SCRIPT_ITEM(i)->sn_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1980 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1981 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1982
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1983 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1984 * Get a pointer to a script name. Used for ":verbose set".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1985 * Message appended to "Last set from "
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1986 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1987 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1988 get_scriptname(scid_T id)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1989 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1990 if (id == SID_MODELINE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1991 return (char_u *)_("modeline");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1992 if (id == SID_CMDARG)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1993 return (char_u *)_("--cmd argument");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1994 if (id == SID_CARG)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1995 return (char_u *)_("-c argument");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1996 if (id == SID_ENV)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1997 return (char_u *)_("environment variable");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1998 if (id == SID_ERROR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
1999 return (char_u *)_("error handler");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2000 if (id == SID_WINLAYOUT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2001 return (char_u *)_("changed window size");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2002 return SCRIPT_ITEM(id)->sn_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2003 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2004
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2005 # if defined(EXITFREE) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2006 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2007 free_scriptnames(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2008 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2009 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2010
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2011 for (i = script_items.ga_len; i > 0; --i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2012 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2013 scriptitem_T *si = SCRIPT_ITEM(i);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2014
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2015 // the variables themselves are cleared in evalvars_clear()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2016 vim_free(si->sn_vars);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2017
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2018 vim_free(si->sn_name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2019 free_imports_and_script_vars(i);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2020 free_string_option(si->sn_save_cpo);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2021 # ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2022 ga_clear(&si->sn_prl_ga);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2023 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2024 vim_free(si->sn_autoload_prefix);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2025 vim_free(si);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2026 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2027 ga_clear(&script_items);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2028 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2029
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2030 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2031 free_autoload_scriptnames(void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2032 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2033 ga_clear_strings(&ga_loaded);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2034 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2035 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2036
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2037 linenr_T
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2038 get_sourced_lnum(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2039 char_u *(*fgetline)(int, void *, int, getline_opt_T),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2040 void *cookie)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2041 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2042 return fgetline == getsourceline
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2043 ? ((source_cookie_T *)cookie)->sourcing_lnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2044 : SOURCING_LNUM;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2045 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2047 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2048 * Return a List of script-local functions defined in the script with id
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2049 * 'sid'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2050 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2051 static list_T *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2052 get_script_local_funcs(scid_T sid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2053 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2054 hashtab_T *functbl;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2055 hashitem_T *hi;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2056 long_u todo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2057 list_T *l;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2058
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2059 l = list_alloc();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2060 if (l == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2061 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2062
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2063 // Iterate through all the functions in the global function hash table
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2064 // looking for functions with script ID 'sid'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2065 functbl = func_tbl_get();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2066 todo = functbl->ht_used;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2067 FOR_ALL_HASHTAB_ITEMS(functbl, hi, todo)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2068 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2069 ufunc_T *fp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2070
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2071 if (HASHITEM_EMPTY(hi))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2072 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2073
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2074 --todo;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2075 fp = HI2UF(hi);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2076
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2077 // Add active functions with script id == 'sid'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2078 if (!(fp->uf_flags & FC_DEAD) && (fp->uf_script_ctx.sc_sid == sid))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2079 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2080 char_u *name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2081
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2082 if (fp->uf_name_exp != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2083 name = fp->uf_name_exp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2084 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2085 name = fp->uf_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2086
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2087 list_append_string(l, name, -1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2088 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2089 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2090
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2091 return l;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2092 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2093
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2094 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2095 * getscriptinfo() function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2096 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2097 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2098 f_getscriptinfo(typval_T *argvars, typval_T *rettv)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2099 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2100 list_T *l;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2101 char_u *pat = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2102 regmatch_T regmatch;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2103 int filterpat = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2104 scid_T sid = -1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2106 if (rettv_list_alloc(rettv) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2107 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2108
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2109 if (check_for_opt_dict_arg(argvars, 0) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2110 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2111
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2112 l = rettv->vval.v_list;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2113
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2114 regmatch.regprog = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2115 regmatch.rm_ic = p_ic;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2116
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2117 if (argvars[0].v_type == VAR_DICT)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2118 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2119 dictitem_T *sid_di = dict_find(argvars[0].vval.v_dict,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2120 (char_u *)"sid", 3);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2121 if (sid_di != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2122 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2123 int error = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2124 sid = tv_get_number_chk(&sid_di->di_tv, &error);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2125 if (error)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2126 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2127 if (sid <= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2128 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2129 semsg(_(e_invalid_value_for_argument_str_str), "sid",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2130 tv_get_string(&sid_di->di_tv));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2131 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2132 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2133 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2134 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2135 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2136 pat = dict_get_string(argvars[0].vval.v_dict, "name", TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2137 if (pat != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2138 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2139 if (regmatch.regprog != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2140 filterpat = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2141 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2142 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2143
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2144 for (varnumber_T i = sid > 0 ? sid : 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2145 (i == sid || sid <= 0) && i <= script_items.ga_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2146 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2147 scriptitem_T *si = SCRIPT_ITEM(i);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2148 dict_T *d;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2149
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2150 if (si->sn_name == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2151 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2152
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2153 if (filterpat && !vim_regexec(&regmatch, si->sn_name, (colnr_T)0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2154 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2155
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2156 if ((d = dict_alloc()) == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2157 || list_append_dict(l, d) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2158 || dict_add_string(d, "name", si->sn_name) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2159 || dict_add_number(d, "sid", i) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2160 || dict_add_number(d, "sourced", si->sn_sourced_sid) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2161 || dict_add_number(d, "version", si->sn_version) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2162 || dict_add_bool(d, "autoload",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2163 si->sn_state == SN_STATE_NOT_LOADED) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2164 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2165
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2166 // When a script ID is specified, return information about only the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2167 // specified script, and add the script-local variables and functions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2168 if (sid > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2169 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2170 dict_T *var_dict;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2171
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2172 var_dict = dict_copy(&si->sn_vars->sv_dict, TRUE, TRUE,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2173 get_copyID());
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2174 if (var_dict == NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2175 || dict_add_dict(d, "variables", var_dict) == FAIL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2176 || dict_add_list(d, "functions",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2177 get_script_local_funcs(sid)) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2178 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2179 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2180 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2181
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2182 vim_regfree(regmatch.regprog);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2183 vim_free(pat);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2184 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2185
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2186 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2187
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2188 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2189 get_one_sourceline(source_cookie_T *sp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2190 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2191 garray_T ga;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2192 int len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2193 int c;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2194 char_u *buf;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2195 #ifdef USE_CRNL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2196 int has_cr; // CR-LF found
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2197 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2198 int have_read = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2199
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2200 // use a growarray to store the sourced line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2201 ga_init2(&ga, 1, 250);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2202
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2203 // Loop until there is a finished line (or end-of-file).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2204 ++sp->sourcing_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2205 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2206 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2207 // make room to read at least 120 (more) characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2208 if (ga_grow(&ga, 120) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2209 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2210 if (sp->source_from_buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2211 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2212 if (sp->buf_lnum >= sp->buflines.ga_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2213 break; // all the lines are processed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2214 ga_concat(&ga, ((char_u **)sp->buflines.ga_data)[sp->buf_lnum]);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2215 sp->buf_lnum++;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2216 if (ga_grow(&ga, 1) == FAIL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2217 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2218 buf = (char_u *)ga.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2219 buf[ga.ga_len++] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2220 len = ga.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2221 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2222 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2223 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2224 buf = (char_u *)ga.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2225 if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2226 sp->fp) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2227 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2228 len = ga.ga_len + (int)STRLEN(buf + ga.ga_len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2229 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2230 #ifdef USE_CRNL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2231 // Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2232 // CTRL-Z by its own, or after a NL.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2233 if ( (len == 1 || (len >= 2 && buf[len - 2] == '\n'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2234 && sp->fileformat == EOL_DOS
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2235 && buf[len - 1] == Ctrl_Z)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2236 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2237 buf[len - 1] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2238 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2239 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2240 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2241
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2242 have_read = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2243 ga.ga_len = len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2244
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2245 // If the line was longer than the buffer, read more.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2246 if (ga.ga_maxlen - ga.ga_len == 1 && buf[len - 1] != '\n')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2247 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2248
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2249 if (len >= 1 && buf[len - 1] == '\n') // remove trailing NL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2250 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2251 #ifdef USE_CRNL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2252 has_cr = (len >= 2 && buf[len - 2] == '\r');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2253 if (sp->fileformat == EOL_UNKNOWN)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2254 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2255 if (has_cr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2256 sp->fileformat = EOL_DOS;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2257 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2258 sp->fileformat = EOL_UNIX;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2259 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2260
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2261 if (sp->fileformat == EOL_DOS)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2262 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2263 if (has_cr) // replace trailing CR
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2264 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2265 buf[len - 2] = '\n';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2266 --len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2267 --ga.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2268 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2269 else // lines like ":map xx yy^M" will have failed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2270 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2271 if (!sp->error)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2272 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2273 msg_source(HL_ATTR(HLF_W));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2274 emsg(_("W15: Warning: Wrong line separator, ^M may be missing"));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2275 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2276 sp->error = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2277 sp->fileformat = EOL_UNIX;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2278 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2279 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2280 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2281 // The '\n' is escaped if there is an odd number of ^V's just
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2282 // before it, first set "c" just before the 'V's and then check
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2283 // len&c parities (is faster than ((len-c)%2 == 0)) -- Acevedo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2284 for (c = len - 2; c >= 0 && buf[c] == Ctrl_V; c--)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2285 ;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2286 if ((len & 1) != (c & 1)) // escaped NL, read more
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2287 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2288 ++sp->sourcing_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2289 continue;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2290 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2291
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2292 buf[len - 1] = NUL; // remove the NL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2293 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2294
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2295 // Check for ^C here now and then, so recursive :so can be broken.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2296 line_breakcheck();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2297 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2298 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2299
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2300 if (have_read)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2301 return (char_u *)ga.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2302
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2303 vim_free(ga.ga_data);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2304 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2305 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2306
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2307 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2308 * Get one full line from a sourced file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2309 * Called by do_cmdline() when it's called from do_source().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2310 *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2311 * Return a pointer to the line in allocated memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2312 * Return NULL for end-of-file or some error.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2313 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2314 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2315 getsourceline(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2316 int c UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2317 void *cookie,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2318 int indent UNUSED,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2319 getline_opt_T options)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2320 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2321 source_cookie_T *sp = (source_cookie_T *)cookie;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2322 char_u *line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2323 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2324 int do_vim9_all = in_vim9script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2325 && options == GETLINE_CONCAT_ALL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2326 int do_bar_cont = do_vim9_all
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2327 || options == GETLINE_CONCAT_CONTBAR;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2328
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2329 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2330 // If breakpoints have been added/deleted need to check for it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2331 if ((sp->dbg_tick < debug_tick) && !sp->source_from_buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2332 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2333 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, SOURCING_LNUM);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2334 sp->dbg_tick = debug_tick;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2335 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2336 # ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2337 if (do_profiling == PROF_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2338 script_line_end();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2339 # endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2340 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2341
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2342 // Set the current sourcing line number.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2343 SOURCING_LNUM = sp->sourcing_lnum + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2344
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2345 // Get current line. If there is a read-ahead line, use it, otherwise get
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2346 // one now. "fp" is NULL if actually using a string.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2347 if (sp->finished || (!sp->source_from_buf && sp->fp == NULL))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2348 line = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2349 else if (sp->nextline == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2350 line = get_one_sourceline(sp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2351 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2352 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2353 line = sp->nextline;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2354 sp->nextline = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2355 ++sp->sourcing_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2356 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2357 #ifdef FEAT_PROFILE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2358 if (line != NULL && do_profiling == PROF_YES)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2359 script_line_start();
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2360 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2361
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2362 // Only concatenate lines starting with a \ when 'cpoptions' doesn't
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2363 // contain the 'C' flag.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2364 if (line != NULL && options != GETLINE_NONE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2365 && vim_strchr(p_cpo, CPO_CONCAT) == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2366 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2367 int comment_char = in_vim9script() ? '#' : '"';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2368
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2369 // compensate for the one line read-ahead
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2370 --sp->sourcing_lnum;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2371
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2372 // Get the next line and concatenate it when it starts with a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2373 // backslash. We always need to read the next line, keep it in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2374 // sp->nextline.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2375 /* Also check for a comment in between continuation lines: "\ */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2376 // Also check for a Vim9 comment, empty line, line starting with '|',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2377 // but not "||".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2378 sp->nextline = get_one_sourceline(sp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2379 if (sp->nextline != NULL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2380 && (*(p = skipwhite(sp->nextline)) == '\\'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2381 || (p[0] == comment_char
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2382 && p[1] == '\\' && p[2] == ' ')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2383 || (do_vim9_all && (*p == NUL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2384 || vim9_comment_start(p)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2385 || (do_bar_cont && p[0] == '|' && p[1] != '|')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2386 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2387 garray_T ga;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2388
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2389 ga_init2(&ga, sizeof(char_u), 400);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2390 ga_concat(&ga, line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2391 if (*p == '\\')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2392 ga_concat(&ga, p + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2393 else if (*p == '|')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2394 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2395 ga_concat(&ga, (char_u *)" ");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2396 ga_concat(&ga, p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2397 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2398 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2399 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2400 vim_free(sp->nextline);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2401 sp->nextline = get_one_sourceline(sp);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2402 if (sp->nextline == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2403 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2404 p = skipwhite(sp->nextline);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2405 if (*p == '\\' || (do_bar_cont && p[0] == '|' && p[1] != '|'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2406 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2407 // Adjust the growsize to the current length to speed up
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2408 // concatenating many lines.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2409 if (ga.ga_len > 400)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2410 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2411 if (ga.ga_len > 8000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2412 ga.ga_growsize = 8000;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2413 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2414 ga.ga_growsize = ga.ga_len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2415 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2416 if (*p == '\\')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2417 ga_concat(&ga, p + 1);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2418 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2419 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2420 ga_concat(&ga, (char_u *)" ");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2421 ga_concat(&ga, p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2422 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2423 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2424 else if (!(p[0] == (comment_char)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2425 && p[1] == '\\' && p[2] == ' ')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2426 && !(do_vim9_all && (*p == NUL || vim9_comment_start(p))))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2427 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2428 /* drop a # comment or "\ comment line */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2429 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2430 ga_append(&ga, NUL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2431 vim_free(line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2432 line = ga.ga_data;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2433 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2434 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2435
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2436 if (line != NULL && sp->conv.vc_type != CONV_NONE)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2437 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2438 char_u *s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2439
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2440 // Convert the encoding of the script line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2441 s = string_convert(&sp->conv, line, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2442 if (s != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2443 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2444 vim_free(line);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2445 line = s;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2446 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2447 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2448
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2449 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2450 // Did we encounter a breakpoint?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2451 if (!sp->source_from_buf && sp->breakpoint != 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2452 && sp->breakpoint <= SOURCING_LNUM)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2453 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2454 dbg_breakpoint(sp->fname, SOURCING_LNUM);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2455 // Find next breakpoint.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2456 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, SOURCING_LNUM);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2457 sp->dbg_tick = debug_tick;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2458 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2459 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2460
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2461 return line;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2462 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2463
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2464 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2465 * Returns TRUE if sourcing a script either from a file or a buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2466 * Otherwise returns FALSE.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2467 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2468 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2469 sourcing_a_script(exarg_T *eap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2470 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2471 return (getline_equal(eap->getline, eap->cookie, getsourceline));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2472 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2473
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2474 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2475 * ":scriptencoding": Set encoding conversion for a sourced script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2476 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2477 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2478 ex_scriptencoding(exarg_T *eap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2479 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2480 source_cookie_T *sp;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2481 char_u *name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2482
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2483 if (!sourcing_a_script(eap))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2484 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2485 emsg(_(e_scriptencoding_used_outside_of_sourced_file));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2486 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2487 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2488
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2489 if (*eap->arg != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2490 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2491 name = enc_canonize(eap->arg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2492 if (name == NULL) // out of memory
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2493 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2494 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2495 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2496 name = eap->arg;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2497
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2498 // Setup for conversion from the specified encoding to 'encoding'.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2499 sp = (source_cookie_T *)getline_cookie(eap->getline, eap->cookie);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2500 convert_setup(&sp->conv, name, p_enc);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2501
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2502 if (name != eap->arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2503 vim_free(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2504 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2505
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2506 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2507 * ":scriptversion": Set Vim script version for a sourced script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2508 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2509 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2510 ex_scriptversion(exarg_T *eap UNUSED)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2511 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2512 int nr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2513
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2514 if (!sourcing_a_script(eap))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2515 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2516 emsg(_(e_scriptversion_used_outside_of_sourced_file));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2517 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2518 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2519 if (in_vim9script())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2520 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2521 emsg(_(e_cannot_use_scriptversion_after_vim9script));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2522 return;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2523 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2524
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2525 nr = getdigits(&eap->arg);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2526 if (nr == 0 || *eap->arg != NUL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2527 emsg(_(e_invalid_argument));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2528 else if (nr > SCRIPT_VERSION_MAX)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2529 semsg(_(e_scriptversion_not_supported_nr), nr);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2530 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2531 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2532 current_sctx.sc_version = nr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2533 #ifdef FEAT_EVAL
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2534 SCRIPT_ITEM(current_sctx.sc_sid)->sn_version = nr;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2535 #endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2536 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2537 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2538
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2539 #if defined(FEAT_EVAL) || defined(PROTO)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2540 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2541 * ":finish": Mark a sourced file as finished.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2542 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2543 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2544 ex_finish(exarg_T *eap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2545 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2546 if (sourcing_a_script(eap))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2547 do_finish(eap, FALSE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2548 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2549 emsg(_(e_finish_used_outside_of_sourced_file));
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2550 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2551
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2552 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2553 * Mark a sourced file as finished. Possibly makes the ":finish" pending.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2554 * Also called for a pending finish at the ":endtry" or after returning from
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2555 * an extra do_cmdline(). "reanimate" is used in the latter case.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2556 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2557 void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2558 do_finish(exarg_T *eap, int reanimate)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2559 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2560 int idx;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2561
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2562 if (reanimate)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2563 ((source_cookie_T *)getline_cookie(eap->getline,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2564 eap->cookie))->finished = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2565
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2566 // Cleanup (and inactivate) conditionals, but stop when a try conditional
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2567 // not in its finally clause (which then is to be executed next) is found.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2568 // In this case, make the ":finish" pending for execution at the ":endtry".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2569 // Otherwise, finish normally.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2570 idx = cleanup_conditionals(eap->cstack, 0, TRUE);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2571 if (idx >= 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2572 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2573 eap->cstack->cs_pending[idx] = CSTP_FINISH;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2574 report_make_pending(CSTP_FINISH, NULL);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2575 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2576 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2577 ((source_cookie_T *)getline_cookie(eap->getline,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2578 eap->cookie))->finished = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2579 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2580
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2581
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2582 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2583 * Return TRUE when a sourced file had the ":finish" command: Don't give error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2584 * message for missing ":endif".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2585 * Return FALSE when not sourcing a file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2586 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2587 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2588 source_finished(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2589 char_u *(*fgetline)(int, void *, int, getline_opt_T),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2590 void *cookie)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2591 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2592 return (getline_equal(fgetline, cookie, getsourceline)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2593 && ((source_cookie_T *)getline_cookie(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2594 fgetline, cookie))->finished);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2595 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2596
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2597 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2598 * Find the path of a script below the "autoload" directory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2599 * Returns NULL if there is no "/autoload/" in the script name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2600 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2601 static char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2602 script_name_after_autoload(scriptitem_T *si)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2603 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2604 char_u *p = si->sn_name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2605 char_u *res = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2606
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2607 for (;;)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2608 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2609 char_u *n = (char_u *)strstr((char *)p, "autoload");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2610
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2611 if (n == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2612 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2613 if (n > p && vim_ispathsep(n[-1]) && vim_ispathsep(n[8]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2614 res = n + 9;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2615 p = n + 8;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2616 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2617 return res;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2618 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2619
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2620 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2621 * For an autoload script "autoload/dir/script.vim" return the prefix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2622 * "dir#script#" in allocated memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2623 * Returns NULL if anything is wrong.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2624 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2625 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2626 get_autoload_prefix(scriptitem_T *si)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2627 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2628 char_u *p = script_name_after_autoload(si);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2629 char_u *prefix;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2630
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2631 if (p == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2632 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2633 prefix = vim_strsave(p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2634 if (prefix == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2635 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2636
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2637 // replace all '/' with '#' and locate ".vim" at the end
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2638 for (p = prefix; *p != NUL; p += mb_ptr2len(p))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2639 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2640 if (vim_ispathsep(*p))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2641 *p = '#';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2642 else if (STRCMP(p, ".vim") == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2643 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2644 p[0] = '#';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2645 p[1] = NUL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2646 return prefix;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2647 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2648 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2649
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2650 // did not find ".vim" at the end
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2651 vim_free(prefix);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2652 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2653 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2654
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2655 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2656 * If in a Vim9 autoload script return "name" with the autoload prefix for the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2657 * script. If successful the returned name is allocated.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2658 * Otherwise it returns "name" unmodified.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2659 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2660 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2661 may_prefix_autoload(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2662 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2663 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2664 return name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2665
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2666 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2667
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2668 if (si->sn_autoload_prefix == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2669 return name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2670
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2671 char_u *basename = name;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2672 size_t len;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2673 char_u *res;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2674
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2675 if (*name == K_SPECIAL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2676 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2677 char_u *p = vim_strchr(name, '_');
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2678
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2679 // skip over "<SNR>99_"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2680 if (p != NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2681 basename = p + 1;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2682 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2683
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2684 len = STRLEN(si->sn_autoload_prefix) + STRLEN(basename) + 2;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2685 res = alloc(len);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2686 if (res == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2687 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2688
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2689 vim_snprintf((char *)res, len, "%s%s", si->sn_autoload_prefix, basename);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2690 return res;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2691 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2692
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2693 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2694 * Return the autoload script name for a function or variable name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2695 * Returns NULL when out of memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2696 * Caller must make sure that "name" contains AUTOLOAD_CHAR.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2697 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2698 char_u *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2699 autoload_name(char_u *name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2700 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2701 char_u *p, *q = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2702 char_u *scriptname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2703
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2704 // Get the script file name: replace '#' with '/', append ".vim".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2705 scriptname = alloc(STRLEN(name) + 14);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2706 if (scriptname == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2707 return NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2708 STRCPY(scriptname, "autoload/");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2709 STRCAT(scriptname, name[0] == 'g' && name[1] == ':' ? name + 2: name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2710 for (p = scriptname + 9; (p = vim_strchr(p, AUTOLOAD_CHAR)) != NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2711 q = p, ++p)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2712 *p = '/';
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2713 STRCPY(q, ".vim");
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2714 return scriptname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2715 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2716
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2717 /*
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2718 * If "name" has a package name try autoloading the script for it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2719 * Return TRUE if a package was loaded.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2720 */
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2721 int
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2722 script_autoload(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2723 char_u *name,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2724 int reload) // load script again when already loaded
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2725 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2726 char_u *p;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2727 char_u *scriptname, *tofree;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2728 int ret = FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2729 int i;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2730 int ret_sid;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2731
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2732 // If the name starts with "<SNR>123_" then "123" is the script ID.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2733 if (name[0] == K_SPECIAL && name[1] == KS_EXTRA && name[2] == KE_SNR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2734 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2735 p = name + 3;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2736 ret_sid = (int)getdigits(&p);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2737 if (*p == '_' && SCRIPT_ID_VALID(ret_sid))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2738 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2739 may_load_script(ret_sid, &ret);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2740 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2741 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2742 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2743
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2744 // If there is no '#' after name[0] there is no package name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2745 p = vim_strchr(name, AUTOLOAD_CHAR);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2746 if (p == NULL || p == name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2747 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2748
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2749 tofree = scriptname = autoload_name(name);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2750 if (scriptname == NULL)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2751 return FALSE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2752
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2753 // Find the name in the list of previously loaded package names. Skip
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2754 // "autoload/", it's always the same.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2755 for (i = 0; i < ga_loaded.ga_len; ++i)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2756 if (STRCMP(((char_u **)ga_loaded.ga_data)[i] + 9, scriptname + 9) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2757 break;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2758 if (!reload && i < ga_loaded.ga_len)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2759 ret = FALSE; // was loaded already
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2760 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2761 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2762 // Remember the name if it wasn't loaded already.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2763 if (i == ga_loaded.ga_len && ga_grow(&ga_loaded, 1) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2764 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2765 ((char_u **)ga_loaded.ga_data)[ga_loaded.ga_len++] = scriptname;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2766 tofree = NULL;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2767 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2768
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2769 // Try loading the package from $VIMRUNTIME/autoload/<name>.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2770 // Use "ret_sid" to avoid loading the same script again.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2771 if (source_in_path(p_rtp, scriptname, DIP_START, &ret_sid) == OK)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2772 ret = TRUE;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2773 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2774
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2775 vim_free(tofree);
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2776 return ret;
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2777 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32383
diff changeset
2778 #endif