Mercurial > vim
annotate src/ex_cmds2.c @ 8206:78f2e8c07973 v7.4.1396
commit https://github.com/vim/vim/commit/1daae446e58fd90f98c51ff3af8f54bfa5197751
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Feb 22 23:25:25 2016 +0100
patch 7.4.1396
Problem: Compiler warnings for conversions.
Solution: Add type cast.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 22 Feb 2016 23:30:07 +0100 |
parents | a8e7b8328cb4 |
children | 05b88224cea1 |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_cmds2.c: some more functions for command line commands | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 #include "version.h" | |
16 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
17 static void cmd_source(char_u *fname, exarg_T *eap); |
7 | 18 |
170 | 19 #ifdef FEAT_EVAL |
177 | 20 /* Growarray to store info about already sourced scripts. |
170 | 21 * For Unix also store the dev/ino, so that we don't have to stat() each |
22 * script when going through the list. */ | |
23 typedef struct scriptitem_S | |
24 { | |
25 char_u *sn_name; | |
26 # ifdef UNIX | |
1882 | 27 int sn_dev_valid; |
28 dev_t sn_dev; | |
170 | 29 ino_t sn_ino; |
30 # endif | |
31 # ifdef FEAT_PROFILE | |
32 int sn_prof_on; /* TRUE when script is/was profiled */ | |
177 | 33 int sn_pr_force; /* forceit: profile functions in this script */ |
170 | 34 proftime_T sn_pr_child; /* time set when going into first child */ |
35 int sn_pr_nest; /* nesting for sn_pr_child */ | |
36 /* profiling the script as a whole */ | |
37 int sn_pr_count; /* nr of times sourced */ | |
1624 | 38 proftime_T sn_pr_total; /* time spent in script + children */ |
39 proftime_T sn_pr_self; /* time spent in script itself */ | |
170 | 40 proftime_T sn_pr_start; /* time at script start */ |
41 proftime_T sn_pr_children; /* time in children after script start */ | |
42 /* profiling the script per line */ | |
43 garray_T sn_prl_ga; /* things stored for every line */ | |
44 proftime_T sn_prl_start; /* start time for current line */ | |
45 proftime_T sn_prl_children; /* time spent in children for this line */ | |
46 proftime_T sn_prl_wait; /* wait start time for current line */ | |
47 int sn_prl_idx; /* index of line being timed; -1 if none */ | |
48 int sn_prl_execed; /* line being timed was executed */ | |
49 # endif | |
50 } scriptitem_T; | |
51 | |
52 static garray_T script_items = {0, 0, sizeof(scriptitem_T), 4, NULL}; | |
53 #define SCRIPT_ITEM(id) (((scriptitem_T *)script_items.ga_data)[(id) - 1]) | |
54 | |
55 # ifdef FEAT_PROFILE | |
56 /* Struct used in sn_prl_ga for every line of a script. */ | |
57 typedef struct sn_prl_S | |
58 { | |
59 int snp_count; /* nr of times line was executed */ | |
1624 | 60 proftime_T sn_prl_total; /* time spent in a line + children */ |
61 proftime_T sn_prl_self; /* time spent in a line itself */ | |
170 | 62 } sn_prl_T; |
63 | |
64 # define PRL_ITEM(si, idx) (((sn_prl_T *)(si)->sn_prl_ga.ga_data)[(idx)]) | |
65 # endif | |
66 #endif | |
67 | |
7 | 68 #if defined(FEAT_EVAL) || defined(PROTO) |
69 static int debug_greedy = FALSE; /* batch mode debugging: don't save | |
70 and restore typeahead. */ | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
71 static int get_maxbacktrace_level(void); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
72 static void do_setdebugtracelevel(char_u *arg); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
73 static void do_checkbacktracelevel(void); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
74 static void do_showbacktrace(char_u *cmd); |
7 | 75 |
76 /* | |
77 * do_debug(): Debug mode. | |
78 * Repeatedly get Ex commands, until told to continue normal execution. | |
79 */ | |
80 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
81 do_debug(char_u *cmd) |
7 | 82 { |
83 int save_msg_scroll = msg_scroll; | |
84 int save_State = State; | |
85 int save_did_emsg = did_emsg; | |
86 int save_cmd_silent = cmd_silent; | |
87 int save_msg_silent = msg_silent; | |
88 int save_emsg_silent = emsg_silent; | |
89 int save_redir_off = redir_off; | |
90 tasave_T typeaheadbuf; | |
1462 | 91 int typeahead_saved = FALSE; |
1485 | 92 int save_ignore_script = 0; |
7 | 93 int save_ex_normal_busy; |
94 int n; | |
95 char_u *cmdline = NULL; | |
96 char_u *p; | |
97 char *tail = NULL; | |
98 static int last_cmd = 0; | |
99 #define CMD_CONT 1 | |
100 #define CMD_NEXT 2 | |
101 #define CMD_STEP 3 | |
102 #define CMD_FINISH 4 | |
103 #define CMD_QUIT 5 | |
104 #define CMD_INTERRUPT 6 | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
105 #define CMD_BACKTRACE 7 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
106 #define CMD_FRAME 8 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
107 #define CMD_UP 9 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
108 #define CMD_DOWN 10 |
7 | 109 |
110 #ifdef ALWAYS_USE_GUI | |
111 /* Can't do this when there is no terminal for input/output. */ | |
112 if (!gui.in_use) | |
113 { | |
114 /* Break as soon as possible. */ | |
115 debug_break_level = 9999; | |
116 return; | |
117 } | |
118 #endif | |
119 | |
120 /* Make sure we are in raw mode and start termcap mode. Might have side | |
121 * effects... */ | |
122 settmode(TMODE_RAW); | |
123 starttermcap(); | |
124 | |
125 ++RedrawingDisabled; /* don't redisplay the window */ | |
126 ++no_wait_return; /* don't wait for return */ | |
127 did_emsg = FALSE; /* don't use error from debugged stuff */ | |
128 cmd_silent = FALSE; /* display commands */ | |
129 msg_silent = FALSE; /* display messages */ | |
130 emsg_silent = FALSE; /* display error messages */ | |
131 redir_off = TRUE; /* don't redirect debug commands */ | |
132 | |
133 State = NORMAL; | |
134 #ifdef FEAT_SNIFF | |
135 want_sniff_request = 0; /* No K_SNIFF wanted */ | |
136 #endif | |
137 | |
138 if (!debug_did_msg) | |
139 MSG(_("Entering Debug mode. Type \"cont\" to continue.")); | |
140 if (sourcing_name != NULL) | |
141 msg(sourcing_name); | |
142 if (sourcing_lnum != 0) | |
274 | 143 smsg((char_u *)_("line %ld: %s"), (long)sourcing_lnum, cmd); |
7 | 144 else |
274 | 145 smsg((char_u *)_("cmd: %s"), cmd); |
7 | 146 |
147 /* | |
148 * Repeat getting a command and executing it. | |
149 */ | |
150 for (;;) | |
151 { | |
152 msg_scroll = TRUE; | |
153 need_wait_return = FALSE; | |
154 #ifdef FEAT_SNIFF | |
155 ProcessSniffRequests(); | |
156 #endif | |
157 /* Save the current typeahead buffer and replace it with an empty one. | |
158 * This makes sure we get input from the user here and don't interfere | |
159 * with the commands being executed. Reset "ex_normal_busy" to avoid | |
160 * the side effects of using ":normal". Save the stuff buffer and make | |
1462 | 161 * it empty. Set ignore_script to avoid reading from script input. */ |
7 | 162 save_ex_normal_busy = ex_normal_busy; |
163 ex_normal_busy = 0; | |
164 if (!debug_greedy) | |
1462 | 165 { |
7 | 166 save_typeahead(&typeaheadbuf); |
1462 | 167 typeahead_saved = TRUE; |
168 save_ignore_script = ignore_script; | |
169 ignore_script = TRUE; | |
170 } | |
7 | 171 |
531 | 172 cmdline = getcmdline_prompt('>', NULL, 0, EXPAND_NOTHING, NULL); |
7 | 173 |
1462 | 174 if (typeahead_saved) |
175 { | |
7 | 176 restore_typeahead(&typeaheadbuf); |
1462 | 177 ignore_script = save_ignore_script; |
178 } | |
7 | 179 ex_normal_busy = save_ex_normal_busy; |
180 | |
181 cmdline_row = msg_row; | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
182 msg_starthere(); |
7 | 183 if (cmdline != NULL) |
184 { | |
185 /* If this is a debug command, set "last_cmd". | |
186 * If not, reset "last_cmd". | |
187 * For a blank line use previous command. */ | |
188 p = skipwhite(cmdline); | |
189 if (*p != NUL) | |
190 { | |
191 switch (*p) | |
192 { | |
193 case 'c': last_cmd = CMD_CONT; | |
194 tail = "ont"; | |
195 break; | |
196 case 'n': last_cmd = CMD_NEXT; | |
197 tail = "ext"; | |
198 break; | |
199 case 's': last_cmd = CMD_STEP; | |
200 tail = "tep"; | |
201 break; | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
202 case 'f': |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
203 last_cmd = 0; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
204 if (p[1] == 'r') |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
205 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
206 last_cmd = CMD_FRAME; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
207 tail = "rame"; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
208 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
209 else |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
210 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
211 last_cmd = CMD_FINISH; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
212 tail = "inish"; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
213 } |
7 | 214 break; |
215 case 'q': last_cmd = CMD_QUIT; | |
216 tail = "uit"; | |
217 break; | |
218 case 'i': last_cmd = CMD_INTERRUPT; | |
219 tail = "nterrupt"; | |
220 break; | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
221 case 'b': last_cmd = CMD_BACKTRACE; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
222 if (p[1] == 't') |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
223 tail = "t"; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
224 else |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
225 tail = "acktrace"; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
226 break; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
227 case 'w': last_cmd = CMD_BACKTRACE; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
228 tail = "here"; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
229 break; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
230 case 'u': last_cmd = CMD_UP; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
231 tail = "p"; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
232 break; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
233 case 'd': last_cmd = CMD_DOWN; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
234 tail = "own"; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
235 break; |
7 | 236 default: last_cmd = 0; |
237 } | |
238 if (last_cmd != 0) | |
239 { | |
240 /* Check that the tail matches. */ | |
241 ++p; | |
242 while (*p != NUL && *p == *tail) | |
243 { | |
244 ++p; | |
245 ++tail; | |
246 } | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
247 if (ASCII_ISALPHA(*p) && last_cmd != CMD_FRAME) |
7 | 248 last_cmd = 0; |
249 } | |
250 } | |
251 | |
252 if (last_cmd != 0) | |
253 { | |
254 /* Execute debug command: decided where to break next and | |
255 * return. */ | |
256 switch (last_cmd) | |
257 { | |
258 case CMD_CONT: | |
259 debug_break_level = -1; | |
260 break; | |
261 case CMD_NEXT: | |
262 debug_break_level = ex_nesting_level; | |
263 break; | |
264 case CMD_STEP: | |
265 debug_break_level = 9999; | |
266 break; | |
267 case CMD_FINISH: | |
268 debug_break_level = ex_nesting_level - 1; | |
269 break; | |
270 case CMD_QUIT: | |
271 got_int = TRUE; | |
272 debug_break_level = -1; | |
273 break; | |
274 case CMD_INTERRUPT: | |
275 got_int = TRUE; | |
276 debug_break_level = 9999; | |
277 /* Do not repeat ">interrupt" cmd, continue stepping. */ | |
278 last_cmd = CMD_STEP; | |
279 break; | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
280 case CMD_BACKTRACE: |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
281 do_showbacktrace(cmd); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
282 continue; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
283 case CMD_FRAME: |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
284 if (*p == NUL) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
285 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
286 do_showbacktrace(cmd); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
287 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
288 else |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
289 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
290 p = skipwhite(p); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
291 do_setdebugtracelevel(p); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
292 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
293 continue; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
294 case CMD_UP: |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
295 debug_backtrace_level++; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
296 do_checkbacktracelevel(); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
297 continue; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
298 case CMD_DOWN: |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
299 debug_backtrace_level--; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
300 do_checkbacktracelevel(); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
301 continue; |
7 | 302 } |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
303 /* Going out reset backtrace_level */ |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
304 debug_backtrace_level = 0; |
7 | 305 break; |
306 } | |
307 | |
308 /* don't debug this command */ | |
309 n = debug_break_level; | |
310 debug_break_level = -1; | |
311 (void)do_cmdline(cmdline, getexline, NULL, | |
312 DOCMD_VERBOSE|DOCMD_EXCRESET); | |
313 debug_break_level = n; | |
314 | |
315 vim_free(cmdline); | |
316 } | |
317 lines_left = Rows - 1; | |
318 } | |
319 vim_free(cmdline); | |
320 | |
321 --RedrawingDisabled; | |
322 --no_wait_return; | |
323 redraw_all_later(NOT_VALID); | |
324 need_wait_return = FALSE; | |
325 msg_scroll = save_msg_scroll; | |
326 lines_left = Rows - 1; | |
327 State = save_State; | |
328 did_emsg = save_did_emsg; | |
329 cmd_silent = save_cmd_silent; | |
330 msg_silent = save_msg_silent; | |
331 emsg_silent = save_emsg_silent; | |
332 redir_off = save_redir_off; | |
333 | |
334 /* Only print the message again when typing a command before coming back | |
335 * here. */ | |
336 debug_did_msg = TRUE; | |
337 } | |
338 | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
339 static int |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
340 get_maxbacktrace_level(void) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
341 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
342 char *p, *q; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
343 int maxbacktrace = 1; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
344 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
345 maxbacktrace = 0; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
346 if (sourcing_name != NULL) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
347 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
348 p = (char *)sourcing_name; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
349 while ((q = strstr(p, "..")) != NULL) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
350 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
351 p = q + 2; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
352 maxbacktrace++; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
353 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
354 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
355 return maxbacktrace; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
356 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
357 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
358 static void |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
359 do_setdebugtracelevel(char_u *arg) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
360 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
361 int level; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
362 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
363 level = atoi((char *)arg); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
364 if (*arg == '+' || level < 0) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
365 debug_backtrace_level += level; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
366 else |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
367 debug_backtrace_level = level; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
368 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
369 do_checkbacktracelevel(); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
370 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
371 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
372 static void |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
373 do_checkbacktracelevel(void) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
374 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
375 if (debug_backtrace_level < 0) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
376 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
377 debug_backtrace_level = 0; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
378 MSG(_("frame is zero")); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
379 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
380 else |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
381 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
382 int max = get_maxbacktrace_level(); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
383 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
384 if (debug_backtrace_level > max) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
385 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
386 debug_backtrace_level = max; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
387 smsg((char_u *)_("frame at highest level: %d"), max); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
388 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
389 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
390 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
391 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
392 static void |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
393 do_showbacktrace(char_u *cmd) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
394 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
395 char *cur; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
396 char *next; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
397 int i = 0; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
398 int max = get_maxbacktrace_level(); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
399 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
400 if (sourcing_name != NULL) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
401 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
402 cur = (char *)sourcing_name; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
403 while (!got_int) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
404 { |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
405 next = strstr(cur, ".."); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
406 if (next != NULL) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
407 *next = NUL; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
408 if (i == max - debug_backtrace_level) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
409 smsg((char_u *)"->%d %s", max - i, cur); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
410 else |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
411 smsg((char_u *)" %d %s", max - i, cur); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
412 ++i; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
413 if (next == NULL) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
414 break; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
415 *next = '.'; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
416 cur = next + 2; |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
417 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
418 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
419 if (sourcing_lnum != 0) |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
420 smsg((char_u *)_("line %ld: %s"), (long)sourcing_lnum, cmd); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
421 else |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
422 smsg((char_u *)_("cmd: %s"), cmd); |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
423 } |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
424 |
7 | 425 /* |
426 * ":debug". | |
427 */ | |
428 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
429 ex_debug(exarg_T *eap) |
7 | 430 { |
431 int debug_break_level_save = debug_break_level; | |
432 | |
433 debug_break_level = 9999; | |
434 do_cmdline_cmd(eap->arg); | |
435 debug_break_level = debug_break_level_save; | |
436 } | |
437 | |
438 static char_u *debug_breakpoint_name = NULL; | |
439 static linenr_T debug_breakpoint_lnum; | |
440 | |
441 /* | |
442 * When debugging or a breakpoint is set on a skipped command, no debug prompt | |
443 * is shown by do_one_cmd(). This situation is indicated by debug_skipped, and | |
444 * debug_skipped_name is then set to the source name in the breakpoint case. If | |
445 * a skipped command decides itself that a debug prompt should be displayed, it | |
446 * can do so by calling dbg_check_skipped(). | |
447 */ | |
448 static int debug_skipped; | |
449 static char_u *debug_skipped_name; | |
450 | |
451 /* | |
452 * Go to debug mode when a breakpoint was encountered or "ex_nesting_level" is | |
453 * at or below the break level. But only when the line is actually | |
454 * executed. Return TRUE and set breakpoint_name for skipped commands that | |
455 * decide to execute something themselves. | |
456 * Called from do_one_cmd() before executing a command. | |
457 */ | |
458 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
459 dbg_check_breakpoint(exarg_T *eap) |
7 | 460 { |
461 char_u *p; | |
462 | |
463 debug_skipped = FALSE; | |
464 if (debug_breakpoint_name != NULL) | |
465 { | |
466 if (!eap->skip) | |
467 { | |
468 /* replace K_SNR with "<SNR>" */ | |
469 if (debug_breakpoint_name[0] == K_SPECIAL | |
470 && debug_breakpoint_name[1] == KS_EXTRA | |
471 && debug_breakpoint_name[2] == (int)KE_SNR) | |
472 p = (char_u *)"<SNR>"; | |
473 else | |
474 p = (char_u *)""; | |
274 | 475 smsg((char_u *)_("Breakpoint in \"%s%s\" line %ld"), |
476 p, | |
7 | 477 debug_breakpoint_name + (*p == NUL ? 0 : 3), |
478 (long)debug_breakpoint_lnum); | |
479 debug_breakpoint_name = NULL; | |
480 do_debug(eap->cmd); | |
481 } | |
482 else | |
483 { | |
484 debug_skipped = TRUE; | |
485 debug_skipped_name = debug_breakpoint_name; | |
486 debug_breakpoint_name = NULL; | |
487 } | |
488 } | |
489 else if (ex_nesting_level <= debug_break_level) | |
490 { | |
491 if (!eap->skip) | |
492 do_debug(eap->cmd); | |
493 else | |
494 { | |
495 debug_skipped = TRUE; | |
496 debug_skipped_name = NULL; | |
497 } | |
498 } | |
499 } | |
500 | |
501 /* | |
502 * Go to debug mode if skipped by dbg_check_breakpoint() because eap->skip was | |
503 * set. Return TRUE when the debug mode is entered this time. | |
504 */ | |
505 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
506 dbg_check_skipped(exarg_T *eap) |
7 | 507 { |
508 int prev_got_int; | |
509 | |
510 if (debug_skipped) | |
511 { | |
512 /* | |
513 * Save the value of got_int and reset it. We don't want a previous | |
514 * interruption cause flushing the input buffer. | |
515 */ | |
516 prev_got_int = got_int; | |
517 got_int = FALSE; | |
518 debug_breakpoint_name = debug_skipped_name; | |
519 /* eap->skip is TRUE */ | |
520 eap->skip = FALSE; | |
521 (void)dbg_check_breakpoint(eap); | |
522 eap->skip = TRUE; | |
523 got_int |= prev_got_int; | |
524 return TRUE; | |
525 } | |
526 return FALSE; | |
527 } | |
528 | |
529 /* | |
530 * The list of breakpoints: dbg_breakp. | |
531 * This is a grow-array of structs. | |
532 */ | |
533 struct debuggy | |
534 { | |
535 int dbg_nr; /* breakpoint number */ | |
536 int dbg_type; /* DBG_FUNC or DBG_FILE */ | |
537 char_u *dbg_name; /* function or file name */ | |
538 regprog_T *dbg_prog; /* regexp program */ | |
539 linenr_T dbg_lnum; /* line number in function or file */ | |
170 | 540 int dbg_forceit; /* ! used */ |
7 | 541 }; |
542 | |
543 static garray_T dbg_breakp = {0, 0, sizeof(struct debuggy), 4, NULL}; | |
170 | 544 #define BREAKP(idx) (((struct debuggy *)dbg_breakp.ga_data)[idx]) |
545 #define DEBUGGY(gap, idx) (((struct debuggy *)gap->ga_data)[idx]) | |
7 | 546 static int last_breakp = 0; /* nr of last defined breakpoint */ |
547 | |
170 | 548 #ifdef FEAT_PROFILE |
549 /* Profiling uses file and func names similar to breakpoints. */ | |
550 static garray_T prof_ga = {0, 0, sizeof(struct debuggy), 4, NULL}; | |
551 #endif | |
7 | 552 #define DBG_FUNC 1 |
553 #define DBG_FILE 2 | |
554 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
555 static int dbg_parsearg(char_u *arg, garray_T *gap); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
556 static linenr_T debuggy_find(int file,char_u *fname, linenr_T after, garray_T *gap, int *fp); |
7 | 557 |
558 /* | |
170 | 559 * Parse the arguments of ":profile", ":breakadd" or ":breakdel" and put them |
560 * in the entry just after the last one in dbg_breakp. Note that "dbg_name" | |
561 * is allocated. | |
7 | 562 * Returns FAIL for failure. |
563 */ | |
564 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
565 dbg_parsearg( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
566 char_u *arg, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
567 garray_T *gap) /* either &dbg_breakp or &prof_ga */ |
7 | 568 { |
569 char_u *p = arg; | |
570 char_u *q; | |
571 struct debuggy *bp; | |
10 | 572 int here = FALSE; |
7 | 573 |
170 | 574 if (ga_grow(gap, 1) == FAIL) |
7 | 575 return FAIL; |
170 | 576 bp = &DEBUGGY(gap, gap->ga_len); |
7 | 577 |
578 /* Find "func" or "file". */ | |
579 if (STRNCMP(p, "func", 4) == 0) | |
580 bp->dbg_type = DBG_FUNC; | |
581 else if (STRNCMP(p, "file", 4) == 0) | |
582 bp->dbg_type = DBG_FILE; | |
170 | 583 else if ( |
584 #ifdef FEAT_PROFILE | |
585 gap != &prof_ga && | |
586 #endif | |
587 STRNCMP(p, "here", 4) == 0) | |
10 | 588 { |
589 if (curbuf->b_ffname == NULL) | |
590 { | |
591 EMSG(_(e_noname)); | |
592 return FAIL; | |
593 } | |
594 bp->dbg_type = DBG_FILE; | |
595 here = TRUE; | |
596 } | |
7 | 597 else |
598 { | |
599 EMSG2(_(e_invarg2), p); | |
600 return FAIL; | |
601 } | |
602 p = skipwhite(p + 4); | |
603 | |
604 /* Find optional line number. */ | |
10 | 605 if (here) |
606 bp->dbg_lnum = curwin->w_cursor.lnum; | |
170 | 607 else if ( |
608 #ifdef FEAT_PROFILE | |
609 gap != &prof_ga && | |
610 #endif | |
611 VIM_ISDIGIT(*p)) | |
7 | 612 { |
613 bp->dbg_lnum = getdigits(&p); | |
614 p = skipwhite(p); | |
615 } | |
616 else | |
617 bp->dbg_lnum = 0; | |
618 | |
619 /* Find the function or file name. Don't accept a function name with (). */ | |
10 | 620 if ((!here && *p == NUL) |
621 || (here && *p != NUL) | |
7 | 622 || (bp->dbg_type == DBG_FUNC && strstr((char *)p, "()") != NULL)) |
623 { | |
624 EMSG2(_(e_invarg2), arg); | |
625 return FAIL; | |
626 } | |
627 | |
628 if (bp->dbg_type == DBG_FUNC) | |
629 bp->dbg_name = vim_strsave(p); | |
10 | 630 else if (here) |
631 bp->dbg_name = vim_strsave(curbuf->b_ffname); | |
7 | 632 else |
633 { | |
634 /* Expand the file name in the same way as do_source(). This means | |
635 * doing it twice, so that $DIR/file gets expanded when $DIR is | |
636 * "~/dir". */ | |
637 q = expand_env_save(p); | |
638 if (q == NULL) | |
639 return FAIL; | |
640 p = expand_env_save(q); | |
641 vim_free(q); | |
642 if (p == NULL) | |
643 return FAIL; | |
11 | 644 if (*p != '*') |
645 { | |
646 bp->dbg_name = fix_fname(p); | |
647 vim_free(p); | |
648 } | |
649 else | |
650 bp->dbg_name = p; | |
7 | 651 } |
652 | |
653 if (bp->dbg_name == NULL) | |
654 return FAIL; | |
655 return OK; | |
656 } | |
657 | |
658 /* | |
659 * ":breakadd". | |
660 */ | |
661 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
662 ex_breakadd(exarg_T *eap) |
7 | 663 { |
664 struct debuggy *bp; | |
665 char_u *pat; | |
170 | 666 garray_T *gap; |
667 | |
668 gap = &dbg_breakp; | |
669 #ifdef FEAT_PROFILE | |
670 if (eap->cmdidx == CMD_profile) | |
671 gap = &prof_ga; | |
672 #endif | |
673 | |
674 if (dbg_parsearg(eap->arg, gap) == OK) | |
675 { | |
676 bp = &DEBUGGY(gap, gap->ga_len); | |
677 bp->dbg_forceit = eap->forceit; | |
678 | |
7 | 679 pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE); |
680 if (pat != NULL) | |
681 { | |
682 bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING); | |
683 vim_free(pat); | |
684 } | |
685 if (pat == NULL || bp->dbg_prog == NULL) | |
686 vim_free(bp->dbg_name); | |
687 else | |
688 { | |
689 if (bp->dbg_lnum == 0) /* default line number is 1 */ | |
690 bp->dbg_lnum = 1; | |
170 | 691 #ifdef FEAT_PROFILE |
692 if (eap->cmdidx != CMD_profile) | |
693 #endif | |
694 { | |
695 DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp; | |
696 ++debug_tick; | |
697 } | |
698 ++gap->ga_len; | |
7 | 699 } |
700 } | |
701 } | |
702 | |
703 /* | |
704 * ":debuggreedy". | |
705 */ | |
706 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
707 ex_debuggreedy(exarg_T *eap) |
7 | 708 { |
709 if (eap->addr_count == 0 || eap->line2 != 0) | |
710 debug_greedy = TRUE; | |
711 else | |
712 debug_greedy = FALSE; | |
713 } | |
714 | |
715 /* | |
364 | 716 * ":breakdel" and ":profdel". |
7 | 717 */ |
718 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
719 ex_breakdel(exarg_T *eap) |
7 | 720 { |
721 struct debuggy *bp, *bpi; | |
722 int nr; | |
723 int todel = -1; | |
359 | 724 int del_all = FALSE; |
7 | 725 int i; |
726 linenr_T best_lnum = 0; | |
364 | 727 garray_T *gap; |
728 | |
729 gap = &dbg_breakp; | |
3604 | 730 if (eap->cmdidx == CMD_profdel) |
731 { | |
364 | 732 #ifdef FEAT_PROFILE |
733 gap = &prof_ga; | |
3604 | 734 #else |
735 ex_ni(eap); | |
736 return; | |
364 | 737 #endif |
3604 | 738 } |
7 | 739 |
740 if (vim_isdigit(*eap->arg)) | |
741 { | |
742 /* ":breakdel {nr}" */ | |
743 nr = atol((char *)eap->arg); | |
364 | 744 for (i = 0; i < gap->ga_len; ++i) |
745 if (DEBUGGY(gap, i).dbg_nr == nr) | |
7 | 746 { |
747 todel = i; | |
748 break; | |
749 } | |
750 } | |
359 | 751 else if (*eap->arg == '*') |
752 { | |
753 todel = 0; | |
754 del_all = TRUE; | |
755 } | |
7 | 756 else |
757 { | |
758 /* ":breakdel {func|file} [lnum] {name}" */ | |
364 | 759 if (dbg_parsearg(eap->arg, gap) == FAIL) |
7 | 760 return; |
364 | 761 bp = &DEBUGGY(gap, gap->ga_len); |
762 for (i = 0; i < gap->ga_len; ++i) | |
7 | 763 { |
364 | 764 bpi = &DEBUGGY(gap, i); |
7 | 765 if (bp->dbg_type == bpi->dbg_type |
766 && STRCMP(bp->dbg_name, bpi->dbg_name) == 0 | |
767 && (bp->dbg_lnum == bpi->dbg_lnum | |
768 || (bp->dbg_lnum == 0 | |
769 && (best_lnum == 0 | |
770 || bpi->dbg_lnum < best_lnum)))) | |
771 { | |
772 todel = i; | |
773 best_lnum = bpi->dbg_lnum; | |
774 } | |
775 } | |
776 vim_free(bp->dbg_name); | |
777 } | |
778 | |
779 if (todel < 0) | |
780 EMSG2(_("E161: Breakpoint not found: %s"), eap->arg); | |
781 else | |
364 | 782 { |
783 while (gap->ga_len > 0) | |
359 | 784 { |
364 | 785 vim_free(DEBUGGY(gap, todel).dbg_name); |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
786 vim_regfree(DEBUGGY(gap, todel).dbg_prog); |
364 | 787 --gap->ga_len; |
788 if (todel < gap->ga_len) | |
789 mch_memmove(&DEBUGGY(gap, todel), &DEBUGGY(gap, todel + 1), | |
790 (gap->ga_len - todel) * sizeof(struct debuggy)); | |
791 #ifdef FEAT_PROFILE | |
792 if (eap->cmdidx == CMD_breakdel) | |
793 #endif | |
794 ++debug_tick; | |
359 | 795 if (!del_all) |
796 break; | |
797 } | |
364 | 798 |
799 /* If all breakpoints were removed clear the array. */ | |
800 if (gap->ga_len == 0) | |
801 ga_clear(gap); | |
802 } | |
7 | 803 } |
804 | |
805 /* | |
806 * ":breaklist". | |
807 */ | |
808 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
809 ex_breaklist(exarg_T *eap UNUSED) |
7 | 810 { |
811 struct debuggy *bp; | |
812 int i; | |
813 | |
814 if (dbg_breakp.ga_len == 0) | |
815 MSG(_("No breakpoints defined")); | |
816 else | |
817 for (i = 0; i < dbg_breakp.ga_len; ++i) | |
818 { | |
819 bp = &BREAKP(i); | |
2921 | 820 if (bp->dbg_type == DBG_FILE) |
821 home_replace(NULL, bp->dbg_name, NameBuff, MAXPATHL, TRUE); | |
7 | 822 smsg((char_u *)_("%3d %s %s line %ld"), |
823 bp->dbg_nr, | |
824 bp->dbg_type == DBG_FUNC ? "func" : "file", | |
2921 | 825 bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff, |
7 | 826 (long)bp->dbg_lnum); |
827 } | |
828 } | |
829 | |
830 /* | |
831 * Find a breakpoint for a function or sourced file. | |
832 * Returns line number at which to break; zero when no matching breakpoint. | |
833 */ | |
834 linenr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
835 dbg_find_breakpoint( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
836 int file, /* TRUE for a file, FALSE for a function */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
837 char_u *fname, /* file or function name */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
838 linenr_T after) /* after this line number */ |
7 | 839 { |
170 | 840 return debuggy_find(file, fname, after, &dbg_breakp, NULL); |
841 } | |
842 | |
843 #if defined(FEAT_PROFILE) || defined(PROTO) | |
844 /* | |
845 * Return TRUE if profiling is on for a function or sourced file. | |
846 */ | |
847 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
848 has_profiling( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
849 int file, /* TRUE for a file, FALSE for a function */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
850 char_u *fname, /* file or function name */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
851 int *fp) /* return: forceit */ |
170 | 852 { |
853 return (debuggy_find(file, fname, (linenr_T)0, &prof_ga, fp) | |
854 != (linenr_T)0); | |
855 } | |
856 #endif | |
857 | |
858 /* | |
859 * Common code for dbg_find_breakpoint() and has_profiling(). | |
860 */ | |
861 static linenr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
862 debuggy_find( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
863 int file, /* TRUE for a file, FALSE for a function */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
864 char_u *fname, /* file or function name */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
865 linenr_T after, /* after this line number */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
866 garray_T *gap, /* either &dbg_breakp or &prof_ga */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
867 int *fp) /* if not NULL: return forceit */ |
170 | 868 { |
7 | 869 struct debuggy *bp; |
870 int i; | |
871 linenr_T lnum = 0; | |
872 char_u *name = fname; | |
873 int prev_got_int; | |
874 | |
170 | 875 /* Return quickly when there are no breakpoints. */ |
876 if (gap->ga_len == 0) | |
877 return (linenr_T)0; | |
878 | |
7 | 879 /* Replace K_SNR in function name with "<SNR>". */ |
880 if (!file && fname[0] == K_SPECIAL) | |
881 { | |
882 name = alloc((unsigned)STRLEN(fname) + 3); | |
883 if (name == NULL) | |
884 name = fname; | |
885 else | |
886 { | |
887 STRCPY(name, "<SNR>"); | |
888 STRCPY(name + 5, fname + 3); | |
889 } | |
890 } | |
891 | |
170 | 892 for (i = 0; i < gap->ga_len; ++i) |
893 { | |
894 /* Skip entries that are not useful or are for a line that is beyond | |
895 * an already found breakpoint. */ | |
896 bp = &DEBUGGY(gap, i); | |
897 if (((bp->dbg_type == DBG_FILE) == file && ( | |
898 #ifdef FEAT_PROFILE | |
899 gap == &prof_ga || | |
900 #endif | |
901 (bp->dbg_lnum > after && (lnum == 0 || bp->dbg_lnum < lnum))))) | |
7 | 902 { |
903 /* | |
170 | 904 * Save the value of got_int and reset it. We don't want a |
905 * previous interruption cancel matching, only hitting CTRL-C | |
906 * while matching should abort it. | |
7 | 907 */ |
908 prev_got_int = got_int; | |
909 got_int = FALSE; | |
6375 | 910 if (vim_regexec_prog(&bp->dbg_prog, FALSE, name, (colnr_T)0)) |
170 | 911 { |
7 | 912 lnum = bp->dbg_lnum; |
170 | 913 if (fp != NULL) |
914 *fp = bp->dbg_forceit; | |
915 } | |
7 | 916 got_int |= prev_got_int; |
917 } | |
918 } | |
919 if (name != fname) | |
920 vim_free(name); | |
921 | |
922 return lnum; | |
923 } | |
924 | |
925 /* | |
926 * Called when a breakpoint was encountered. | |
927 */ | |
928 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
929 dbg_breakpoint(char_u *name, linenr_T lnum) |
7 | 930 { |
931 /* We need to check if this line is actually executed in do_one_cmd() */ | |
932 debug_breakpoint_name = name; | |
933 debug_breakpoint_lnum = lnum; | |
934 } | |
170 | 935 |
936 | |
794 | 937 # if defined(FEAT_PROFILE) || defined(FEAT_RELTIME) || defined(PROTO) |
170 | 938 /* |
939 * Store the current time in "tm". | |
940 */ | |
941 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
942 profile_start(proftime_T *tm) |
170 | 943 { |
177 | 944 # ifdef WIN3264 |
945 QueryPerformanceCounter(tm); | |
946 # else | |
170 | 947 gettimeofday(tm, NULL); |
177 | 948 # endif |
170 | 949 } |
950 | |
951 /* | |
952 * Compute the elapsed time from "tm" till now and store in "tm". | |
953 */ | |
954 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
955 profile_end(proftime_T *tm) |
170 | 956 { |
957 proftime_T now; | |
958 | |
177 | 959 # ifdef WIN3264 |
960 QueryPerformanceCounter(&now); | |
961 tm->QuadPart = now.QuadPart - tm->QuadPart; | |
962 # else | |
170 | 963 gettimeofday(&now, NULL); |
964 tm->tv_usec = now.tv_usec - tm->tv_usec; | |
965 tm->tv_sec = now.tv_sec - tm->tv_sec; | |
966 if (tm->tv_usec < 0) | |
967 { | |
968 tm->tv_usec += 1000000; | |
969 --tm->tv_sec; | |
970 } | |
177 | 971 # endif |
170 | 972 } |
973 | |
974 /* | |
975 * Subtract the time "tm2" from "tm". | |
976 */ | |
977 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
978 profile_sub(proftime_T *tm, proftime_T *tm2) |
170 | 979 { |
177 | 980 # ifdef WIN3264 |
981 tm->QuadPart -= tm2->QuadPart; | |
982 # else | |
170 | 983 tm->tv_usec -= tm2->tv_usec; |
984 tm->tv_sec -= tm2->tv_sec; | |
985 if (tm->tv_usec < 0) | |
986 { | |
987 tm->tv_usec += 1000000; | |
988 --tm->tv_sec; | |
989 } | |
177 | 990 # endif |
170 | 991 } |
992 | |
993 /* | |
794 | 994 * Return a string that represents the time in "tm". |
995 * Uses a static buffer! | |
996 */ | |
997 char * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
998 profile_msg(proftime_T *tm) |
794 | 999 { |
1000 static char buf[50]; | |
1001 | |
1002 # ifdef WIN3264 | |
1003 LARGE_INTEGER fr; | |
1004 | |
1005 QueryPerformanceFrequency(&fr); | |
1006 sprintf(buf, "%10.6lf", (double)tm->QuadPart / (double)fr.QuadPart); | |
1007 # else | |
1008 sprintf(buf, "%3ld.%06ld", (long)tm->tv_sec, (long)tm->tv_usec); | |
1496 | 1009 # endif |
794 | 1010 return buf; |
1011 } | |
1012 | |
7979
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1013 # if defined(FEAT_FLOAT) || defined(PROTO) |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1014 /* |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1015 * Return a float that represents the time in "tm". |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1016 */ |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1017 float_T |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1018 profile_float(proftime_T *tm) |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1019 { |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1020 # ifdef WIN3264 |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1021 LARGE_INTEGER fr; |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1022 |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1023 QueryPerformanceFrequency(&fr); |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1024 return (float_T)tm->QuadPart / (float_T)fr.QuadPart; |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1025 # else |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1026 return (float_T)tm->tv_sec + (float_T)tm->tv_usec / 1000000.0; |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1027 # endif |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1028 } |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1029 # endif |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1030 |
794 | 1031 /* |
1496 | 1032 * Put the time "msec" past now in "tm". |
794 | 1033 */ |
1496 | 1034 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1035 profile_setlimit(long msec, proftime_T *tm) |
1496 | 1036 { |
1037 if (msec <= 0) /* no limit */ | |
1038 profile_zero(tm); | |
1039 else | |
1040 { | |
1041 # ifdef WIN3264 | |
1042 LARGE_INTEGER fr; | |
1043 | |
1044 QueryPerformanceCounter(tm); | |
1045 QueryPerformanceFrequency(&fr); | |
1517 | 1046 tm->QuadPart += (LONGLONG)((double)msec / 1000.0 * (double)fr.QuadPart); |
1496 | 1047 # else |
1048 long usec; | |
1049 | |
1050 gettimeofday(tm, NULL); | |
1051 usec = (long)tm->tv_usec + (long)msec * 1000; | |
1052 tm->tv_usec = usec % 1000000L; | |
1053 tm->tv_sec += usec / 1000000L; | |
1054 # endif | |
1055 } | |
1056 } | |
1057 | |
1058 /* | |
1059 * Return TRUE if the current time is past "tm". | |
1060 */ | |
1061 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1062 profile_passed_limit(proftime_T *tm) |
1496 | 1063 { |
1064 proftime_T now; | |
1065 | |
1066 # ifdef WIN3264 | |
1067 if (tm->QuadPart == 0) /* timer was not set */ | |
1068 return FALSE; | |
1069 QueryPerformanceCounter(&now); | |
1070 return (now.QuadPart > tm->QuadPart); | |
1071 # else | |
1072 if (tm->tv_sec == 0) /* timer was not set */ | |
1073 return FALSE; | |
1074 gettimeofday(&now, NULL); | |
1075 return (now.tv_sec > tm->tv_sec | |
1076 || (now.tv_sec == tm->tv_sec && now.tv_usec > tm->tv_usec)); | |
1077 # endif | |
1078 } | |
794 | 1079 |
1080 /* | |
1081 * Set the time in "tm" to zero. | |
1082 */ | |
1083 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1084 profile_zero(proftime_T *tm) |
794 | 1085 { |
1086 # ifdef WIN3264 | |
1087 tm->QuadPart = 0; | |
1088 # else | |
1089 tm->tv_usec = 0; | |
1090 tm->tv_sec = 0; | |
1091 # endif | |
1092 } | |
1093 | |
1496 | 1094 # endif /* FEAT_PROFILE || FEAT_RELTIME */ |
1095 | |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1096 #if defined(FEAT_SYN_HL) && defined(FEAT_RELTIME) && defined(FEAT_FLOAT) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1097 # if defined(HAVE_MATH_H) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1098 # include <math.h> |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1099 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1100 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1101 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1102 * Divide the time "tm" by "count" and store in "tm2". |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1103 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1104 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1105 profile_divide(proftime_T *tm, int count, proftime_T *tm2) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1106 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1107 if (count == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1108 profile_zero(tm2); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1109 else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1110 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1111 # ifdef WIN3264 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1112 tm2->QuadPart = tm->QuadPart / count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1113 # else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1114 double usec = (tm->tv_sec * 1000000.0 + tm->tv_usec) / count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1115 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1116 tm2->tv_sec = floor(usec / 1000000.0); |
4825
208a6c04e6b8
updated for version 7.3.1159
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1117 tm2->tv_usec = vim_round(usec - (tm2->tv_sec * 1000000.0)); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1118 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1119 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1120 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1121 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1122 |
1496 | 1123 # if defined(FEAT_PROFILE) || defined(PROTO) |
1124 /* | |
1125 * Functions for profiling. | |
1126 */ | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
1127 static void script_do_profile(scriptitem_T *si); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
1128 static void script_dump_profile(FILE *fd); |
1496 | 1129 static proftime_T prof_wait_time; |
1130 | |
794 | 1131 /* |
170 | 1132 * Add the time "tm2" to "tm". |
1133 */ | |
1134 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1135 profile_add(proftime_T *tm, proftime_T *tm2) |
170 | 1136 { |
177 | 1137 # ifdef WIN3264 |
1138 tm->QuadPart += tm2->QuadPart; | |
1139 # else | |
170 | 1140 tm->tv_usec += tm2->tv_usec; |
1141 tm->tv_sec += tm2->tv_sec; | |
1142 if (tm->tv_usec >= 1000000) | |
1143 { | |
1144 tm->tv_usec -= 1000000; | |
1145 ++tm->tv_sec; | |
1146 } | |
177 | 1147 # endif |
170 | 1148 } |
1149 | |
1150 /* | |
720 | 1151 * Add the "self" time from the total time and the children's time. |
1152 */ | |
1153 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1154 profile_self(proftime_T *self, proftime_T *total, proftime_T *children) |
720 | 1155 { |
1156 /* Check that the result won't be negative. Can happen with recursive | |
1157 * calls. */ | |
1158 #ifdef WIN3264 | |
1159 if (total->QuadPart <= children->QuadPart) | |
1160 return; | |
1161 #else | |
1162 if (total->tv_sec < children->tv_sec | |
1163 || (total->tv_sec == children->tv_sec | |
1164 && total->tv_usec <= children->tv_usec)) | |
1165 return; | |
1166 #endif | |
1167 profile_add(self, total); | |
1168 profile_sub(self, children); | |
1169 } | |
1170 | |
1171 /* | |
170 | 1172 * Get the current waittime. |
1173 */ | |
1174 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1175 profile_get_wait(proftime_T *tm) |
170 | 1176 { |
1177 *tm = prof_wait_time; | |
1178 } | |
1179 | |
1180 /* | |
1181 * Subtract the passed waittime since "tm" from "tma". | |
1182 */ | |
1183 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1184 profile_sub_wait(proftime_T *tm, proftime_T *tma) |
170 | 1185 { |
1186 proftime_T tm3 = prof_wait_time; | |
1187 | |
1188 profile_sub(&tm3, tm); | |
1189 profile_sub(tma, &tm3); | |
1190 } | |
1191 | |
1192 /* | |
1193 * Return TRUE if "tm1" and "tm2" are equal. | |
1194 */ | |
1195 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1196 profile_equal(proftime_T *tm1, proftime_T *tm2) |
170 | 1197 { |
177 | 1198 # ifdef WIN3264 |
1199 return (tm1->QuadPart == tm2->QuadPart); | |
1200 # else | |
170 | 1201 return (tm1->tv_usec == tm2->tv_usec && tm1->tv_sec == tm2->tv_sec); |
177 | 1202 # endif |
1203 } | |
1204 | |
1205 /* | |
1206 * Return <0, 0 or >0 if "tm1" < "tm2", "tm1" == "tm2" or "tm1" > "tm2" | |
1207 */ | |
1208 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1209 profile_cmp(const proftime_T *tm1, const proftime_T *tm2) |
177 | 1210 { |
1211 # ifdef WIN3264 | |
1212 return (int)(tm2->QuadPart - tm1->QuadPart); | |
1213 # else | |
1214 if (tm1->tv_sec == tm2->tv_sec) | |
1215 return tm2->tv_usec - tm1->tv_usec; | |
1216 return tm2->tv_sec - tm1->tv_sec; | |
1217 # endif | |
170 | 1218 } |
1219 | |
1220 static char_u *profile_fname = NULL; | |
790 | 1221 static proftime_T pause_time; |
170 | 1222 |
1223 /* | |
1224 * ":profile cmd args" | |
1225 */ | |
1226 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1227 ex_profile(exarg_T *eap) |
170 | 1228 { |
1229 char_u *e; | |
1230 int len; | |
1231 | |
1232 e = skiptowhite(eap->arg); | |
835 | 1233 len = (int)(e - eap->arg); |
170 | 1234 e = skipwhite(e); |
1235 | |
1236 if (len == 5 && STRNCMP(eap->arg, "start", 5) == 0 && *e != NUL) | |
1237 { | |
1238 vim_free(profile_fname); | |
6749 | 1239 profile_fname = expand_env_save_opt(e, TRUE); |
790 | 1240 do_profiling = PROF_YES; |
170 | 1241 profile_zero(&prof_wait_time); |
1242 set_vim_var_nr(VV_PROFILING, 1L); | |
1243 } | |
790 | 1244 else if (do_profiling == PROF_NONE) |
2085
5a84b6388a55
updated for version 7.2.369
Bram Moolenaar <bram@zimbu.org>
parents:
2068
diff
changeset
|
1245 EMSG(_("E750: First use \":profile start {fname}\"")); |
790 | 1246 else if (STRCMP(eap->arg, "pause") == 0) |
1247 { | |
1248 if (do_profiling == PROF_YES) | |
1249 profile_start(&pause_time); | |
1250 do_profiling = PROF_PAUSED; | |
1251 } | |
1252 else if (STRCMP(eap->arg, "continue") == 0) | |
1253 { | |
1254 if (do_profiling == PROF_PAUSED) | |
1255 { | |
1256 profile_end(&pause_time); | |
1257 profile_add(&prof_wait_time, &pause_time); | |
1258 } | |
1259 do_profiling = PROF_YES; | |
1260 } | |
170 | 1261 else |
1262 { | |
1263 /* The rest is similar to ":breakadd". */ | |
1264 ex_breakadd(eap); | |
1265 } | |
1266 } | |
1267 | |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1268 /* Command line expansion for :profile. */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1269 static enum |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1270 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1271 PEXP_SUBCMD, /* expand :profile sub-commands */ |
2711 | 1272 PEXP_FUNC /* expand :profile func {funcname} */ |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1273 } pexpand_what; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1274 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1275 static char *pexpand_cmds[] = { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1276 "start", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1277 #define PROFCMD_START 0 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1278 "pause", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1279 #define PROFCMD_PAUSE 1 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1280 "continue", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1281 #define PROFCMD_CONTINUE 2 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1282 "func", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1283 #define PROFCMD_FUNC 3 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1284 "file", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1285 #define PROFCMD_FILE 4 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1286 NULL |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1287 #define PROFCMD_LAST 5 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1288 }; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1289 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1290 /* |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1291 * Function given to ExpandGeneric() to obtain the profile command |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1292 * specific expansion. |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1293 */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1294 char_u * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1295 get_profile_name(expand_T *xp UNUSED, int idx) |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1296 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1297 switch (pexpand_what) |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1298 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1299 case PEXP_SUBCMD: |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1300 return (char_u *)pexpand_cmds[idx]; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1301 /* case PEXP_FUNC: TODO */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1302 default: |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1303 return NULL; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1304 } |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1305 } |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1306 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1307 /* |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1308 * Handle command line completion for :profile command. |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1309 */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1310 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1311 set_context_in_profile_cmd(expand_T *xp, char_u *arg) |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1312 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1313 char_u *end_subcmd; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1314 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1315 /* Default: expand subcommands. */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1316 xp->xp_context = EXPAND_PROFILE; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1317 pexpand_what = PEXP_SUBCMD; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1318 xp->xp_pattern = arg; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1319 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1320 end_subcmd = skiptowhite(arg); |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1321 if (*end_subcmd == NUL) |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1322 return; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1323 |
2100
7d121c69f540
updated for version 7.2.383
Bram Moolenaar <bram@zimbu.org>
parents:
2085
diff
changeset
|
1324 if (end_subcmd - arg == 5 && STRNCMP(arg, "start", 5) == 0) |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1325 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1326 xp->xp_context = EXPAND_FILES; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1327 xp->xp_pattern = skipwhite(end_subcmd); |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1328 return; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1329 } |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1330 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1331 /* TODO: expand function names after "func" */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1332 xp->xp_context = EXPAND_NOTHING; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1333 } |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1334 |
170 | 1335 /* |
1336 * Dump the profiling info. | |
1337 */ | |
1338 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1339 profile_dump(void) |
170 | 1340 { |
1341 FILE *fd; | |
1342 | |
1343 if (profile_fname != NULL) | |
1344 { | |
531 | 1345 fd = mch_fopen((char *)profile_fname, "w"); |
170 | 1346 if (fd == NULL) |
1347 EMSG2(_(e_notopen), profile_fname); | |
1348 else | |
1349 { | |
177 | 1350 script_dump_profile(fd); |
170 | 1351 func_dump_profile(fd); |
1352 fclose(fd); | |
1353 } | |
1354 } | |
1355 } | |
1356 | |
1357 /* | |
1358 * Start profiling script "fp". | |
1359 */ | |
1360 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1361 script_do_profile(scriptitem_T *si) |
170 | 1362 { |
1363 si->sn_pr_count = 0; | |
1364 profile_zero(&si->sn_pr_total); | |
1365 profile_zero(&si->sn_pr_self); | |
1366 | |
1367 ga_init2(&si->sn_prl_ga, sizeof(sn_prl_T), 100); | |
1368 si->sn_prl_idx = -1; | |
1369 si->sn_prof_on = TRUE; | |
1370 si->sn_pr_nest = 0; | |
1371 } | |
1372 | |
1373 /* | |
1374 * save time when starting to invoke another script or function. | |
1375 */ | |
1376 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1377 script_prof_save( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1378 proftime_T *tm) /* place to store wait time */ |
170 | 1379 { |
1380 scriptitem_T *si; | |
1381 | |
1382 if (current_SID > 0 && current_SID <= script_items.ga_len) | |
1383 { | |
1384 si = &SCRIPT_ITEM(current_SID); | |
1385 if (si->sn_prof_on && si->sn_pr_nest++ == 0) | |
1386 profile_start(&si->sn_pr_child); | |
1387 } | |
1388 profile_get_wait(tm); | |
1389 } | |
1390 | |
1391 /* | |
1392 * Count time spent in children after invoking another script or function. | |
1393 */ | |
1394 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1395 script_prof_restore(proftime_T *tm) |
170 | 1396 { |
1397 scriptitem_T *si; | |
1398 | |
1399 if (current_SID > 0 && current_SID <= script_items.ga_len) | |
1400 { | |
1401 si = &SCRIPT_ITEM(current_SID); | |
1402 if (si->sn_prof_on && --si->sn_pr_nest == 0) | |
1403 { | |
1404 profile_end(&si->sn_pr_child); | |
1405 profile_sub_wait(tm, &si->sn_pr_child); /* don't count wait time */ | |
1406 profile_add(&si->sn_pr_children, &si->sn_pr_child); | |
1407 profile_add(&si->sn_prl_children, &si->sn_pr_child); | |
1408 } | |
1409 } | |
1410 } | |
1411 | |
1412 static proftime_T inchar_time; | |
1413 | |
1414 /* | |
1415 * Called when starting to wait for the user to type a character. | |
1416 */ | |
1417 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1418 prof_inchar_enter(void) |
170 | 1419 { |
1420 profile_start(&inchar_time); | |
1421 } | |
1422 | |
1423 /* | |
1424 * Called when finished waiting for the user to type a character. | |
1425 */ | |
1426 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1427 prof_inchar_exit(void) |
170 | 1428 { |
1429 profile_end(&inchar_time); | |
1430 profile_add(&prof_wait_time, &inchar_time); | |
1431 } | |
1432 | |
1433 /* | |
1434 * Dump the profiling results for all scripts in file "fd". | |
1435 */ | |
1436 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1437 script_dump_profile(FILE *fd) |
170 | 1438 { |
1439 int id; | |
1440 scriptitem_T *si; | |
1441 int i; | |
1442 FILE *sfd; | |
1443 sn_prl_T *pp; | |
1444 | |
1445 for (id = 1; id <= script_items.ga_len; ++id) | |
1446 { | |
1447 si = &SCRIPT_ITEM(id); | |
1448 if (si->sn_prof_on) | |
1449 { | |
1450 fprintf(fd, "SCRIPT %s\n", si->sn_name); | |
1451 if (si->sn_pr_count == 1) | |
1452 fprintf(fd, "Sourced 1 time\n"); | |
1453 else | |
1454 fprintf(fd, "Sourced %d times\n", si->sn_pr_count); | |
1455 fprintf(fd, "Total time: %s\n", profile_msg(&si->sn_pr_total)); | |
1456 fprintf(fd, " Self time: %s\n", profile_msg(&si->sn_pr_self)); | |
1457 fprintf(fd, "\n"); | |
1458 fprintf(fd, "count total (s) self (s)\n"); | |
1459 | |
531 | 1460 sfd = mch_fopen((char *)si->sn_name, "r"); |
170 | 1461 if (sfd == NULL) |
1462 fprintf(fd, "Cannot open file!\n"); | |
1463 else | |
1464 { | |
1465 for (i = 0; i < si->sn_prl_ga.ga_len; ++i) | |
1466 { | |
1467 if (vim_fgets(IObuff, IOSIZE, sfd)) | |
1468 break; | |
1469 pp = &PRL_ITEM(si, i); | |
1470 if (pp->snp_count > 0) | |
1471 { | |
1472 fprintf(fd, "%5d ", pp->snp_count); | |
1473 if (profile_equal(&pp->sn_prl_total, &pp->sn_prl_self)) | |
1474 fprintf(fd, " "); | |
1475 else | |
1476 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_total)); | |
1477 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_self)); | |
1478 } | |
1479 else | |
1480 fprintf(fd, " "); | |
1481 fprintf(fd, "%s", IObuff); | |
1482 } | |
1483 fclose(sfd); | |
1484 } | |
1485 fprintf(fd, "\n"); | |
1486 } | |
1487 } | |
1488 } | |
1489 | |
1490 /* | |
1491 * Return TRUE when a function defined in the current script should be | |
1492 * profiled. | |
1493 */ | |
1494 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1495 prof_def_func(void) |
170 | 1496 { |
391 | 1497 if (current_SID > 0) |
1498 return SCRIPT_ITEM(current_SID).sn_pr_force; | |
1499 return FALSE; | |
170 | 1500 } |
1501 | |
1502 # endif | |
7 | 1503 #endif |
1504 | |
1505 /* | |
1506 * If 'autowrite' option set, try to write the file. | |
1507 * Careful: autocommands may make "buf" invalid! | |
1508 * | |
1509 * return FAIL for failure, OK otherwise | |
1510 */ | |
1511 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1512 autowrite(buf_T *buf, int forceit) |
7 | 1513 { |
1069 | 1514 int r; |
1515 | |
7 | 1516 if (!(p_aw || p_awa) || !p_write |
1517 #ifdef FEAT_QUICKFIX | |
1069 | 1518 /* never autowrite a "nofile" or "nowrite" buffer */ |
1519 || bt_dontwrite(buf) | |
7 | 1520 #endif |
1069 | 1521 || (!forceit && buf->b_p_ro) || buf->b_ffname == NULL) |
7 | 1522 return FAIL; |
1069 | 1523 r = buf_write_all(buf, forceit); |
1524 | |
1525 /* Writing may succeed but the buffer still changed, e.g., when there is a | |
1526 * conversion error. We do want to return FAIL then. */ | |
1527 if (buf_valid(buf) && bufIsChanged(buf)) | |
1528 r = FAIL; | |
1529 return r; | |
7 | 1530 } |
1531 | |
1532 /* | |
1533 * flush all buffers, except the ones that are readonly | |
1534 */ | |
1535 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1536 autowrite_all(void) |
7 | 1537 { |
1538 buf_T *buf; | |
1539 | |
1540 if (!(p_aw || p_awa) || !p_write) | |
1541 return; | |
1542 for (buf = firstbuf; buf; buf = buf->b_next) | |
1543 if (bufIsChanged(buf) && !buf->b_p_ro) | |
1544 { | |
1545 (void)buf_write_all(buf, FALSE); | |
1546 #ifdef FEAT_AUTOCMD | |
1547 /* an autocommand may have deleted the buffer */ | |
1548 if (!buf_valid(buf)) | |
1549 buf = firstbuf; | |
1550 #endif | |
1551 } | |
1552 } | |
1553 | |
1554 /* | |
5464 | 1555 * Return TRUE if buffer was changed and cannot be abandoned. |
1556 * For flags use the CCGD_ values. | |
7 | 1557 */ |
1558 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1559 check_changed(buf_T *buf, int flags) |
7 | 1560 { |
5464 | 1561 int forceit = (flags & CCGD_FORCEIT); |
1562 | |
7 | 1563 if ( !forceit |
1564 && bufIsChanged(buf) | |
5464 | 1565 && ((flags & CCGD_MULTWIN) || buf->b_nwindows <= 1) |
1566 && (!(flags & CCGD_AW) || autowrite(buf, forceit) == FAIL)) | |
7 | 1567 { |
1568 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
1569 if ((p_confirm || cmdmod.confirm) && p_write) | |
1570 { | |
1571 buf_T *buf2; | |
1572 int count = 0; | |
1573 | |
5464 | 1574 if (flags & CCGD_ALLBUF) |
7 | 1575 for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next) |
1576 if (bufIsChanged(buf2) | |
1577 && (buf2->b_ffname != NULL | |
1578 # ifdef FEAT_BROWSE | |
1579 || cmdmod.browse | |
1580 # endif | |
1581 )) | |
1582 ++count; | |
1583 # ifdef FEAT_AUTOCMD | |
1584 if (!buf_valid(buf)) | |
1585 /* Autocommand deleted buffer, oops! It's not changed now. */ | |
1586 return FALSE; | |
1587 # endif | |
1588 dialog_changed(buf, count > 1); | |
1589 # ifdef FEAT_AUTOCMD | |
1590 if (!buf_valid(buf)) | |
1591 /* Autocommand deleted buffer, oops! It's not changed now. */ | |
1592 return FALSE; | |
1593 # endif | |
1594 return bufIsChanged(buf); | |
1595 } | |
1596 #endif | |
5464 | 1597 if (flags & CCGD_EXCMD) |
1598 EMSG(_(e_nowrtmsg)); | |
1599 else | |
1600 EMSG(_(e_nowrtmsg_nobang)); | |
7 | 1601 return TRUE; |
1602 } | |
1603 return FALSE; | |
1604 } | |
1605 | |
1606 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) || defined(PROTO) | |
1607 | |
1608 #if defined(FEAT_BROWSE) || defined(PROTO) | |
1609 /* | |
1610 * When wanting to write a file without a file name, ask the user for a name. | |
1611 */ | |
1612 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1613 browse_save_fname(buf_T *buf) |
7 | 1614 { |
1615 if (buf->b_fname == NULL) | |
1616 { | |
1617 char_u *fname; | |
1618 | |
29 | 1619 fname = do_browse(BROWSE_SAVE, (char_u *)_("Save As"), |
1620 NULL, NULL, NULL, NULL, buf); | |
7 | 1621 if (fname != NULL) |
1622 { | |
1623 if (setfname(buf, fname, NULL, TRUE) == OK) | |
1624 buf->b_flags |= BF_NOTEDITED; | |
1625 vim_free(fname); | |
1626 } | |
1627 } | |
1628 } | |
1629 #endif | |
1630 | |
1631 /* | |
2849 | 1632 * Ask the user what to do when abandoning a changed buffer. |
7 | 1633 * Must check 'write' option first! |
1634 */ | |
1635 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1636 dialog_changed( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1637 buf_T *buf, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1638 int checkall) /* may abandon all changed buffers */ |
7 | 1639 { |
2770 | 1640 char_u buff[DIALOG_MSG_SIZE]; |
7 | 1641 int ret; |
1642 buf_T *buf2; | |
3486 | 1643 exarg_T ea; |
7 | 1644 |
314 | 1645 dialog_msg(buff, _("Save changes to \"%s\"?"), |
7 | 1646 (buf->b_fname != NULL) ? |
1647 buf->b_fname : (char_u *)_("Untitled")); | |
1648 if (checkall) | |
1649 ret = vim_dialog_yesnoallcancel(VIM_QUESTION, NULL, buff, 1); | |
1650 else | |
1651 ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1); | |
1652 | |
3486 | 1653 /* Init ea pseudo-structure, this is needed for the check_overwrite() |
1654 * function. */ | |
1655 ea.append = ea.forceit = FALSE; | |
1656 | |
7 | 1657 if (ret == VIM_YES) |
1658 { | |
1659 #ifdef FEAT_BROWSE | |
1660 /* May get file name, when there is none */ | |
1661 browse_save_fname(buf); | |
1662 #endif | |
3486 | 1663 if (buf->b_fname != NULL && check_overwrite(&ea, buf, |
1664 buf->b_fname, buf->b_ffname, FALSE) == OK) | |
1665 /* didn't hit Cancel */ | |
7 | 1666 (void)buf_write_all(buf, FALSE); |
1667 } | |
1668 else if (ret == VIM_NO) | |
1669 { | |
1670 unchanged(buf, TRUE); | |
1671 } | |
1672 else if (ret == VIM_ALL) | |
1673 { | |
1674 /* | |
1675 * Write all modified files that can be written. | |
1676 * Skip readonly buffers, these need to be confirmed | |
1677 * individually. | |
1678 */ | |
1679 for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next) | |
1680 { | |
1681 if (bufIsChanged(buf2) | |
1682 && (buf2->b_ffname != NULL | |
1683 #ifdef FEAT_BROWSE | |
1684 || cmdmod.browse | |
1685 #endif | |
1686 ) | |
1687 && !buf2->b_p_ro) | |
1688 { | |
1689 #ifdef FEAT_BROWSE | |
1690 /* May get file name, when there is none */ | |
1691 browse_save_fname(buf2); | |
1692 #endif | |
3486 | 1693 if (buf2->b_fname != NULL && check_overwrite(&ea, buf2, |
1694 buf2->b_fname, buf2->b_ffname, FALSE) == OK) | |
1695 /* didn't hit Cancel */ | |
7 | 1696 (void)buf_write_all(buf2, FALSE); |
1697 #ifdef FEAT_AUTOCMD | |
1698 /* an autocommand may have deleted the buffer */ | |
1699 if (!buf_valid(buf2)) | |
1700 buf2 = firstbuf; | |
1701 #endif | |
1702 } | |
1703 } | |
1704 } | |
1705 else if (ret == VIM_DISCARDALL) | |
1706 { | |
1707 /* | |
1708 * mark all buffers as unchanged | |
1709 */ | |
1710 for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next) | |
1711 unchanged(buf2, TRUE); | |
1712 } | |
1713 } | |
1714 #endif | |
1715 | |
1716 /* | |
1717 * Return TRUE if the buffer "buf" can be abandoned, either by making it | |
1718 * hidden, autowriting it or unloading it. | |
1719 */ | |
1720 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1721 can_abandon(buf_T *buf, int forceit) |
7 | 1722 { |
1723 return ( P_HID(buf) | |
1724 || !bufIsChanged(buf) | |
1725 || buf->b_nwindows > 1 | |
1726 || autowrite(buf, forceit) == OK | |
1727 || forceit); | |
1728 } | |
1729 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
1730 static void add_bufnum(int *bufnrs, int *bufnump, int nr); |
3429 | 1731 |
1732 /* | |
1733 * Add a buffer number to "bufnrs", unless it's already there. | |
1734 */ | |
1735 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1736 add_bufnum(int *bufnrs, int *bufnump, int nr) |
3429 | 1737 { |
1738 int i; | |
1739 | |
1740 for (i = 0; i < *bufnump; ++i) | |
1741 if (bufnrs[i] == nr) | |
1742 return; | |
1743 bufnrs[*bufnump] = nr; | |
1744 *bufnump = *bufnump + 1; | |
1745 } | |
1746 | |
7 | 1747 /* |
1748 * Return TRUE if any buffer was changed and cannot be abandoned. | |
1749 * That changed buffer becomes the current buffer. | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7107
diff
changeset
|
1750 * When "unload" is true the current buffer is unloaded instead of making it |
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7107
diff
changeset
|
1751 * hidden. This is used for ":q!". |
7 | 1752 */ |
1753 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1754 check_changed_any( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1755 int hidden, /* Only check hidden buffers */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1756 int unload) |
7 | 1757 { |
3429 | 1758 int ret = FALSE; |
7 | 1759 buf_T *buf; |
1760 int save; | |
3429 | 1761 int i; |
1762 int bufnum = 0; | |
1763 int bufcount = 0; | |
1764 int *bufnrs; | |
7 | 1765 #ifdef FEAT_WINDOWS |
3429 | 1766 tabpage_T *tp; |
7 | 1767 win_T *wp; |
1768 #endif | |
1769 | |
3429 | 1770 for (buf = firstbuf; buf != NULL; buf = buf->b_next) |
1771 ++bufcount; | |
1772 | |
1773 if (bufcount == 0) | |
1774 return FALSE; | |
1775 | |
1776 bufnrs = (int *)alloc(sizeof(int) * bufcount); | |
1777 if (bufnrs == NULL) | |
1778 return FALSE; | |
1779 | |
1780 /* curbuf */ | |
1781 bufnrs[bufnum++] = curbuf->b_fnum; | |
1782 #ifdef FEAT_WINDOWS | |
1783 /* buf in curtab */ | |
1784 FOR_ALL_WINDOWS(wp) | |
1785 if (wp->w_buffer != curbuf) | |
1786 add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum); | |
1787 | |
1788 /* buf in other tab */ | |
1789 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | |
1790 if (tp != curtab) | |
1791 for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) | |
1792 add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum); | |
1793 #endif | |
1794 /* any other buf */ | |
1795 for (buf = firstbuf; buf != NULL; buf = buf->b_next) | |
1796 add_bufnum(bufnrs, &bufnum, buf->b_fnum); | |
1797 | |
1798 for (i = 0; i < bufnum; ++i) | |
7 | 1799 { |
3429 | 1800 buf = buflist_findnr(bufnrs[i]); |
1801 if (buf == NULL) | |
1802 continue; | |
1803 if ((!hidden || buf->b_nwindows == 0) && bufIsChanged(buf)) | |
7 | 1804 { |
3429 | 1805 /* Try auto-writing the buffer. If this fails but the buffer no |
1806 * longer exists it's not changed, that's OK. */ | |
5464 | 1807 if (check_changed(buf, (p_awa ? CCGD_AW : 0) |
1808 | CCGD_MULTWIN | |
1809 | CCGD_ALLBUF) && buf_valid(buf)) | |
3429 | 1810 break; /* didn't save - still changes */ |
7 | 1811 } |
1812 } | |
1813 | |
3429 | 1814 if (i >= bufnum) |
1815 goto theend; | |
1816 | |
1817 ret = TRUE; | |
7 | 1818 exiting = FALSE; |
1819 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
1820 /* | |
1821 * When ":confirm" used, don't give an error message. | |
1822 */ | |
1823 if (!(p_confirm || cmdmod.confirm)) | |
1824 #endif | |
1825 { | |
1826 /* There must be a wait_return for this message, do_buffer() | |
1827 * may cause a redraw. But wait_return() is a no-op when vgetc() | |
1828 * is busy (Quit used from window menu), then make sure we don't | |
1829 * cause a scroll up. */ | |
823 | 1830 if (vgetc_busy > 0) |
7 | 1831 { |
1832 msg_row = cmdline_row; | |
1833 msg_col = 0; | |
1834 msg_didout = FALSE; | |
1835 } | |
1836 if (EMSG2(_("E162: No write since last change for buffer \"%s\""), | |
3839 | 1837 buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname)) |
7 | 1838 { |
1839 save = no_wait_return; | |
1840 no_wait_return = FALSE; | |
1841 wait_return(FALSE); | |
1842 no_wait_return = save; | |
1843 } | |
1844 } | |
1845 | |
1846 #ifdef FEAT_WINDOWS | |
1847 /* Try to find a window that contains the buffer. */ | |
1848 if (buf != curbuf) | |
3429 | 1849 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 1850 if (wp->w_buffer == buf) |
1851 { | |
3429 | 1852 goto_tabpage_win(tp, wp); |
7 | 1853 # ifdef FEAT_AUTOCMD |
1854 /* Paranoia: did autocms wipe out the buffer with changes? */ | |
1855 if (!buf_valid(buf)) | |
3429 | 1856 { |
1857 goto theend; | |
1858 } | |
7 | 1859 # endif |
3429 | 1860 goto buf_found; |
7 | 1861 } |
3429 | 1862 buf_found: |
7 | 1863 #endif |
1864 | |
1865 /* Open the changed buffer in the current window. */ | |
1866 if (buf != curbuf) | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7107
diff
changeset
|
1867 set_curbuf(buf, unload ? DOBUF_UNLOAD : DOBUF_GOTO); |
7 | 1868 |
3429 | 1869 theend: |
1870 vim_free(bufnrs); | |
1871 return ret; | |
7 | 1872 } |
1873 | |
1874 /* | |
1875 * return FAIL if there is no file name, OK if there is one | |
1876 * give error message for FAIL | |
1877 */ | |
1878 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1879 check_fname(void) |
7 | 1880 { |
1881 if (curbuf->b_ffname == NULL) | |
1882 { | |
1883 EMSG(_(e_noname)); | |
1884 return FAIL; | |
1885 } | |
1886 return OK; | |
1887 } | |
1888 | |
1889 /* | |
1890 * flush the contents of a buffer, unless it has no file name | |
1891 * | |
1892 * return FAIL for failure, OK otherwise | |
1893 */ | |
1894 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1895 buf_write_all(buf_T *buf, int forceit) |
7 | 1896 { |
1897 int retval; | |
1898 #ifdef FEAT_AUTOCMD | |
1899 buf_T *old_curbuf = curbuf; | |
1900 #endif | |
1901 | |
1902 retval = (buf_write(buf, buf->b_ffname, buf->b_fname, | |
1903 (linenr_T)1, buf->b_ml.ml_line_count, NULL, | |
1904 FALSE, forceit, TRUE, FALSE)); | |
1905 #ifdef FEAT_AUTOCMD | |
1906 if (curbuf != old_curbuf) | |
16 | 1907 { |
1908 msg_source(hl_attr(HLF_W)); | |
7 | 1909 MSG(_("Warning: Entered other buffer unexpectedly (check autocommands)")); |
16 | 1910 } |
7 | 1911 #endif |
1912 return retval; | |
1913 } | |
1914 | |
1915 /* | |
1916 * Code to handle the argument list. | |
1917 */ | |
1918 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
1919 static char_u *do_one_arg(char_u *str); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
1920 static int do_arglist(char_u *str, int what, int after); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
1921 static void alist_check_arg_idx(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
1922 static int editing_arg_idx(win_T *win); |
39 | 1923 #ifdef FEAT_LISTCMDS |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
1924 static int alist_add_list(int count, char_u **files, int after); |
39 | 1925 #endif |
1926 #define AL_SET 1 | |
1927 #define AL_ADD 2 | |
1928 #define AL_DEL 3 | |
1929 | |
7 | 1930 /* |
39 | 1931 * Isolate one argument, taking backticks. |
1932 * Changes the argument in-place, puts a NUL after it. Backticks remain. | |
7 | 1933 * Return a pointer to the start of the next argument. |
1934 */ | |
39 | 1935 static char_u * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1936 do_one_arg(char_u *str) |
7 | 1937 { |
1938 char_u *p; | |
1939 int inbacktick; | |
1940 | |
1941 inbacktick = FALSE; | |
1942 for (p = str; *str; ++str) | |
1943 { | |
39 | 1944 /* When the backslash is used for escaping the special meaning of a |
1945 * character we need to keep it until wildcard expansion. */ | |
7 | 1946 if (rem_backslash(str)) |
1947 { | |
1948 *p++ = *str++; | |
1949 *p++ = *str; | |
1950 } | |
1951 else | |
1952 { | |
39 | 1953 /* An item ends at a space not in backticks */ |
1954 if (!inbacktick && vim_isspace(*str)) | |
7 | 1955 break; |
39 | 1956 if (*str == '`') |
7 | 1957 inbacktick ^= TRUE; |
39 | 1958 *p++ = *str; |
7 | 1959 } |
1960 } | |
1961 str = skipwhite(str); | |
1962 *p = NUL; | |
1963 | |
1964 return str; | |
1965 } | |
1966 | |
41 | 1967 /* |
1968 * Separate the arguments in "str" and return a list of pointers in the | |
1969 * growarray "gap". | |
1970 */ | |
1971 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1972 get_arglist(garray_T *gap, char_u *str) |
41 | 1973 { |
1974 ga_init2(gap, (int)sizeof(char_u *), 20); | |
1975 while (*str != NUL) | |
1976 { | |
1977 if (ga_grow(gap, 1) == FAIL) | |
1978 { | |
1979 ga_clear(gap); | |
1980 return FAIL; | |
1981 } | |
1982 ((char_u **)gap->ga_data)[gap->ga_len++] = str; | |
1983 | |
1984 /* Isolate one argument, change it in-place, put a NUL after it. */ | |
1985 str = do_one_arg(str); | |
1986 } | |
1987 return OK; | |
1988 } | |
1989 | |
642 | 1990 #if defined(FEAT_QUICKFIX) || defined(FEAT_SYN_HL) || defined(PROTO) |
237 | 1991 /* |
1992 * Parse a list of arguments (file names), expand them and return in | |
3620 | 1993 * "fnames[fcountp]". When "wig" is TRUE, removes files matching 'wildignore'. |
237 | 1994 * Return FAIL or OK. |
1995 */ | |
1996 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1997 get_arglist_exp( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1998 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1999 int *fcountp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2000 char_u ***fnamesp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2001 int wig) |
237 | 2002 { |
2003 garray_T ga; | |
2004 int i; | |
2005 | |
2006 if (get_arglist(&ga, str) == FAIL) | |
2007 return FAIL; | |
3620 | 2008 if (wig == TRUE) |
2009 i = expand_wildcards(ga.ga_len, (char_u **)ga.ga_data, | |
2010 fcountp, fnamesp, EW_FILE|EW_NOTFOUND); | |
2011 else | |
2012 i = gen_expand_wildcards(ga.ga_len, (char_u **)ga.ga_data, | |
2013 fcountp, fnamesp, EW_FILE|EW_NOTFOUND); | |
2014 | |
237 | 2015 ga_clear(&ga); |
2016 return i; | |
2017 } | |
2018 #endif | |
2019 | |
7 | 2020 #if defined(FEAT_GUI) || defined(FEAT_CLIENTSERVER) || defined(PROTO) |
2021 /* | |
2022 * Redefine the argument list. | |
2023 */ | |
2024 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2025 set_arglist(char_u *str) |
7 | 2026 { |
2027 do_arglist(str, AL_SET, 0); | |
2028 } | |
2029 #endif | |
2030 | |
2031 /* | |
2032 * "what" == AL_SET: Redefine the argument list to 'str'. | |
2033 * "what" == AL_ADD: add files in 'str' to the argument list after "after". | |
2034 * "what" == AL_DEL: remove files in 'str' from the argument list. | |
2035 * | |
2036 * Return FAIL for failure, OK otherwise. | |
2037 */ | |
2038 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2039 do_arglist( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2040 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2041 int what UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2042 int after UNUSED) /* 0 means before first one */ |
7 | 2043 { |
2044 garray_T new_ga; | |
2045 int exp_count; | |
2046 char_u **exp_files; | |
2047 int i; | |
2048 #ifdef FEAT_LISTCMDS | |
2049 char_u *p; | |
2050 int match; | |
2051 #endif | |
2052 | |
2053 /* | |
7726
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2054 * Set default argument for ":argadd" command. |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2055 */ |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2056 if (what == AL_ADD && *str == NUL) |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2057 { |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2058 if (curbuf->b_ffname == NULL) |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2059 return FAIL; |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2060 str = curbuf->b_fname; |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2061 } |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2062 |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2063 /* |
7 | 2064 * Collect all file name arguments in "new_ga". |
2065 */ | |
41 | 2066 if (get_arglist(&new_ga, str) == FAIL) |
2067 return FAIL; | |
7 | 2068 |
2069 #ifdef FEAT_LISTCMDS | |
2070 if (what == AL_DEL) | |
2071 { | |
2072 regmatch_T regmatch; | |
2073 int didone; | |
2074 | |
2075 /* | |
2076 * Delete the items: use each item as a regexp and find a match in the | |
2077 * argument list. | |
2078 */ | |
4242 | 2079 regmatch.rm_ic = p_fic; /* ignore case when 'fileignorecase' is set */ |
7 | 2080 for (i = 0; i < new_ga.ga_len && !got_int; ++i) |
2081 { | |
2082 p = ((char_u **)new_ga.ga_data)[i]; | |
2083 p = file_pat_to_reg_pat(p, NULL, NULL, FALSE); | |
2084 if (p == NULL) | |
2085 break; | |
2086 regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); | |
2087 if (regmatch.regprog == NULL) | |
2088 { | |
2089 vim_free(p); | |
2090 break; | |
2091 } | |
2092 | |
2093 didone = FALSE; | |
2094 for (match = 0; match < ARGCOUNT; ++match) | |
2095 if (vim_regexec(®match, alist_name(&ARGLIST[match]), | |
2096 (colnr_T)0)) | |
2097 { | |
2098 didone = TRUE; | |
2099 vim_free(ARGLIST[match].ae_fname); | |
2100 mch_memmove(ARGLIST + match, ARGLIST + match + 1, | |
2101 (ARGCOUNT - match - 1) * sizeof(aentry_T)); | |
2102 --ALIST(curwin)->al_ga.ga_len; | |
2103 if (curwin->w_arg_idx > match) | |
2104 --curwin->w_arg_idx; | |
2105 --match; | |
2106 } | |
2107 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
2108 vim_regfree(regmatch.regprog); |
7 | 2109 vim_free(p); |
2110 if (!didone) | |
2111 EMSG2(_(e_nomatch2), ((char_u **)new_ga.ga_data)[i]); | |
2112 } | |
2113 ga_clear(&new_ga); | |
2114 } | |
2115 else | |
2116 #endif | |
2117 { | |
2118 i = expand_wildcards(new_ga.ga_len, (char_u **)new_ga.ga_data, | |
2119 &exp_count, &exp_files, EW_DIR|EW_FILE|EW_ADDSLASH|EW_NOTFOUND); | |
2120 ga_clear(&new_ga); | |
7625
b4384c581806
commit https://github.com/vim/vim/commit/2db5c3b3ceeaded7fb5a64dc5cb22b0cb95b78a1
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
2121 if (i == FAIL || exp_count == 0) |
7 | 2122 { |
2123 EMSG(_(e_nomatch)); | |
2124 return FAIL; | |
2125 } | |
2126 | |
2127 #ifdef FEAT_LISTCMDS | |
2128 if (what == AL_ADD) | |
2129 { | |
2130 (void)alist_add_list(exp_count, exp_files, after); | |
2131 vim_free(exp_files); | |
2132 } | |
2133 else /* what == AL_SET */ | |
2134 #endif | |
41 | 2135 alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0); |
7 | 2136 } |
2137 | |
2138 alist_check_arg_idx(); | |
2139 | |
2140 return OK; | |
2141 } | |
2142 | |
2143 /* | |
2144 * Check the validity of the arg_idx for each other window. | |
2145 */ | |
2146 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2147 alist_check_arg_idx(void) |
7 | 2148 { |
2149 #ifdef FEAT_WINDOWS | |
2150 win_T *win; | |
671 | 2151 tabpage_T *tp; |
2152 | |
2153 FOR_ALL_TAB_WINDOWS(tp, win) | |
7 | 2154 if (win->w_alist == curwin->w_alist) |
2155 check_arg_idx(win); | |
2156 #else | |
2157 check_arg_idx(curwin); | |
2158 #endif | |
2159 } | |
2160 | |
2161 /* | |
3312 | 2162 * Return TRUE if window "win" is editing the file at the current argument |
22 | 2163 * index. |
2164 */ | |
2165 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2166 editing_arg_idx(win_T *win) |
22 | 2167 { |
2168 return !(win->w_arg_idx >= WARGCOUNT(win) | |
2169 || (win->w_buffer->b_fnum | |
2170 != WARGLIST(win)[win->w_arg_idx].ae_fnum | |
2171 && (win->w_buffer->b_ffname == NULL | |
2172 || !(fullpathcmp( | |
2173 alist_name(&WARGLIST(win)[win->w_arg_idx]), | |
2174 win->w_buffer->b_ffname, TRUE) & FPC_SAME)))); | |
2175 } | |
2176 | |
2177 /* | |
7 | 2178 * Check if window "win" is editing the w_arg_idx file in its argument list. |
2179 */ | |
2180 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2181 check_arg_idx(win_T *win) |
7 | 2182 { |
22 | 2183 if (WARGCOUNT(win) > 1 && !editing_arg_idx(win)) |
7 | 2184 { |
2185 /* We are not editing the current entry in the argument list. | |
2186 * Set "arg_had_last" if we are editing the last one. */ | |
2187 win->w_arg_idx_invalid = TRUE; | |
2188 if (win->w_arg_idx != WARGCOUNT(win) - 1 | |
2189 && arg_had_last == FALSE | |
2190 #ifdef FEAT_WINDOWS | |
2191 && ALIST(win) == &global_alist | |
2192 #endif | |
2193 && GARGCOUNT > 0 | |
2194 && win->w_arg_idx < GARGCOUNT | |
2195 && (win->w_buffer->b_fnum == GARGLIST[GARGCOUNT - 1].ae_fnum | |
2196 || (win->w_buffer->b_ffname != NULL | |
2197 && (fullpathcmp(alist_name(&GARGLIST[GARGCOUNT - 1]), | |
2198 win->w_buffer->b_ffname, TRUE) & FPC_SAME)))) | |
2199 arg_had_last = TRUE; | |
2200 } | |
2201 else | |
2202 { | |
2203 /* We are editing the current entry in the argument list. | |
2204 * Set "arg_had_last" if it's also the last one */ | |
2205 win->w_arg_idx_invalid = FALSE; | |
2206 if (win->w_arg_idx == WARGCOUNT(win) - 1 | |
2207 #ifdef FEAT_WINDOWS | |
2208 && win->w_alist == &global_alist | |
2209 #endif | |
2210 ) | |
2211 arg_had_last = TRUE; | |
2212 } | |
2213 } | |
2214 | |
2215 /* | |
2216 * ":args", ":argslocal" and ":argsglobal". | |
2217 */ | |
2218 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2219 ex_args(exarg_T *eap) |
7 | 2220 { |
2221 int i; | |
2222 | |
2223 if (eap->cmdidx != CMD_args) | |
2224 { | |
2225 #if defined(FEAT_WINDOWS) && defined(FEAT_LISTCMDS) | |
2226 alist_unlink(ALIST(curwin)); | |
2227 if (eap->cmdidx == CMD_argglobal) | |
2228 ALIST(curwin) = &global_alist; | |
2229 else /* eap->cmdidx == CMD_arglocal */ | |
2230 alist_new(); | |
2231 #else | |
2232 ex_ni(eap); | |
2233 return; | |
2234 #endif | |
2235 } | |
2236 | |
2237 if (!ends_excmd(*eap->arg)) | |
2238 { | |
2239 /* | |
2240 * ":args file ..": define new argument list, handle like ":next" | |
2241 * Also for ":argslocal file .." and ":argsglobal file ..". | |
2242 */ | |
2243 ex_next(eap); | |
2244 } | |
2245 else | |
2246 #if defined(FEAT_WINDOWS) && defined(FEAT_LISTCMDS) | |
2247 if (eap->cmdidx == CMD_args) | |
2248 #endif | |
2249 { | |
2250 /* | |
2251 * ":args": list arguments. | |
2252 */ | |
2253 if (ARGCOUNT > 0) | |
2254 { | |
2255 /* Overwrite the command, for a short list there is no scrolling | |
2256 * required and no wait_return(). */ | |
2257 gotocmdline(TRUE); | |
2258 for (i = 0; i < ARGCOUNT; ++i) | |
2259 { | |
2260 if (i == curwin->w_arg_idx) | |
2261 msg_putchar('['); | |
2262 msg_outtrans(alist_name(&ARGLIST[i])); | |
2263 if (i == curwin->w_arg_idx) | |
2264 msg_putchar(']'); | |
2265 msg_putchar(' '); | |
2266 } | |
2267 } | |
2268 } | |
2269 #if defined(FEAT_WINDOWS) && defined(FEAT_LISTCMDS) | |
2270 else if (eap->cmdidx == CMD_arglocal) | |
2271 { | |
2272 garray_T *gap = &curwin->w_alist->al_ga; | |
2273 | |
2274 /* | |
2275 * ":argslocal": make a local copy of the global argument list. | |
2276 */ | |
2277 if (ga_grow(gap, GARGCOUNT) == OK) | |
2278 for (i = 0; i < GARGCOUNT; ++i) | |
2279 if (GARGLIST[i].ae_fname != NULL) | |
2280 { | |
2281 AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname = | |
2282 vim_strsave(GARGLIST[i].ae_fname); | |
2283 AARGLIST(curwin->w_alist)[gap->ga_len].ae_fnum = | |
2284 GARGLIST[i].ae_fnum; | |
2285 ++gap->ga_len; | |
2286 } | |
2287 } | |
2288 #endif | |
2289 } | |
2290 | |
2291 /* | |
2292 * ":previous", ":sprevious", ":Next" and ":sNext". | |
2293 */ | |
2294 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2295 ex_previous(exarg_T *eap) |
7 | 2296 { |
2297 /* If past the last one already, go to the last one. */ | |
2298 if (curwin->w_arg_idx - (int)eap->line2 >= ARGCOUNT) | |
2299 do_argfile(eap, ARGCOUNT - 1); | |
2300 else | |
2301 do_argfile(eap, curwin->w_arg_idx - (int)eap->line2); | |
2302 } | |
2303 | |
2304 /* | |
2305 * ":rewind", ":first", ":sfirst" and ":srewind". | |
2306 */ | |
2307 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2308 ex_rewind(exarg_T *eap) |
7 | 2309 { |
2310 do_argfile(eap, 0); | |
2311 } | |
2312 | |
2313 /* | |
2314 * ":last" and ":slast". | |
2315 */ | |
2316 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2317 ex_last(exarg_T *eap) |
7 | 2318 { |
2319 do_argfile(eap, ARGCOUNT - 1); | |
2320 } | |
2321 | |
2322 /* | |
2323 * ":argument" and ":sargument". | |
2324 */ | |
2325 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2326 ex_argument(exarg_T *eap) |
7 | 2327 { |
2328 int i; | |
2329 | |
2330 if (eap->addr_count > 0) | |
2331 i = eap->line2 - 1; | |
2332 else | |
2333 i = curwin->w_arg_idx; | |
2334 do_argfile(eap, i); | |
2335 } | |
2336 | |
2337 /* | |
2338 * Edit file "argn" of the argument lists. | |
2339 */ | |
2340 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2341 do_argfile(exarg_T *eap, int argn) |
7 | 2342 { |
2343 int other; | |
2344 char_u *p; | |
271 | 2345 int old_arg_idx = curwin->w_arg_idx; |
7 | 2346 |
2347 if (argn < 0 || argn >= ARGCOUNT) | |
2348 { | |
2349 if (ARGCOUNT <= 1) | |
2350 EMSG(_("E163: There is only one file to edit")); | |
2351 else if (argn < 0) | |
2352 EMSG(_("E164: Cannot go before first file")); | |
2353 else | |
2354 EMSG(_("E165: Cannot go beyond last file")); | |
2355 } | |
2356 else | |
2357 { | |
2358 setpcmark(); | |
2359 #ifdef FEAT_GUI | |
2360 need_mouse_correct = TRUE; | |
2361 #endif | |
2362 | |
2363 #ifdef FEAT_WINDOWS | |
683 | 2364 /* split window or create new tab page first */ |
2365 if (*eap->cmd == 's' || cmdmod.tab != 0) | |
7 | 2366 { |
2367 if (win_split(0, 0) == FAIL) | |
2368 return; | |
2583 | 2369 RESET_BINDING(curwin); |
7 | 2370 } |
2371 else | |
2372 #endif | |
2373 { | |
2374 /* | |
2375 * if 'hidden' set, only check for changed file when re-editing | |
2376 * the same buffer | |
2377 */ | |
2378 other = TRUE; | |
2379 if (P_HID(curbuf)) | |
2380 { | |
2381 p = fix_fname(alist_name(&ARGLIST[argn])); | |
2382 other = otherfile(p); | |
2383 vim_free(p); | |
2384 } | |
2385 if ((!P_HID(curbuf) || !other) | |
5464 | 2386 && check_changed(curbuf, CCGD_AW |
2387 | (other ? 0 : CCGD_MULTWIN) | |
2388 | (eap->forceit ? CCGD_FORCEIT : 0) | |
2389 | CCGD_EXCMD)) | |
7 | 2390 return; |
2391 } | |
2392 | |
2393 curwin->w_arg_idx = argn; | |
2394 if (argn == ARGCOUNT - 1 | |
2395 #ifdef FEAT_WINDOWS | |
2396 && curwin->w_alist == &global_alist | |
2397 #endif | |
2398 ) | |
2399 arg_had_last = TRUE; | |
2400 | |
271 | 2401 /* Edit the file; always use the last known line number. |
2402 * When it fails (e.g. Abort for already edited file) restore the | |
2403 * argument index. */ | |
2404 if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL, | |
7 | 2405 eap, ECMD_LAST, |
1743 | 2406 (P_HID(curwin->w_buffer) ? ECMD_HIDE : 0) |
2407 + (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL) | |
271 | 2408 curwin->w_arg_idx = old_arg_idx; |
7 | 2409 /* like Vi: set the mark where the cursor is in the file. */ |
271 | 2410 else if (eap->cmdidx != CMD_argdo) |
7 | 2411 setmark('\''); |
2412 } | |
2413 } | |
2414 | |
2415 /* | |
2416 * ":next", and commands that behave like it. | |
2417 */ | |
2418 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2419 ex_next(exarg_T *eap) |
7 | 2420 { |
2421 int i; | |
2422 | |
2423 /* | |
2424 * check for changed buffer now, if this fails the argument list is not | |
2425 * redefined. | |
2426 */ | |
2427 if ( P_HID(curbuf) | |
2428 || eap->cmdidx == CMD_snext | |
5464 | 2429 || !check_changed(curbuf, CCGD_AW |
2430 | (eap->forceit ? CCGD_FORCEIT : 0) | |
2431 | CCGD_EXCMD)) | |
7 | 2432 { |
2433 if (*eap->arg != NUL) /* redefine file list */ | |
2434 { | |
2435 if (do_arglist(eap->arg, AL_SET, 0) == FAIL) | |
2436 return; | |
2437 i = 0; | |
2438 } | |
2439 else | |
2440 i = curwin->w_arg_idx + (int)eap->line2; | |
2441 do_argfile(eap, i); | |
2442 } | |
2443 } | |
2444 | |
2445 #ifdef FEAT_LISTCMDS | |
2446 /* | |
2447 * ":argedit" | |
2448 */ | |
2449 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2450 ex_argedit(exarg_T *eap) |
7 | 2451 { |
2452 int fnum; | |
2453 int i; | |
2454 char_u *s; | |
2455 | |
2456 /* Add the argument to the buffer list and get the buffer number. */ | |
2457 fnum = buflist_add(eap->arg, BLN_LISTED); | |
2458 | |
2459 /* Check if this argument is already in the argument list. */ | |
2460 for (i = 0; i < ARGCOUNT; ++i) | |
2461 if (ARGLIST[i].ae_fnum == fnum) | |
2462 break; | |
2463 if (i == ARGCOUNT) | |
2464 { | |
2465 /* Can't find it, add it to the argument list. */ | |
2466 s = vim_strsave(eap->arg); | |
2467 if (s == NULL) | |
2468 return; | |
2469 i = alist_add_list(1, &s, | |
2470 eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1); | |
2471 if (i < 0) | |
2472 return; | |
2473 curwin->w_arg_idx = i; | |
2474 } | |
2475 | |
2476 alist_check_arg_idx(); | |
2477 | |
2478 /* Edit the argument. */ | |
2479 do_argfile(eap, i); | |
2480 } | |
2481 | |
2482 /* | |
2483 * ":argadd" | |
2484 */ | |
2485 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2486 ex_argadd(exarg_T *eap) |
7 | 2487 { |
2488 do_arglist(eap->arg, AL_ADD, | |
2489 eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1); | |
2490 #ifdef FEAT_TITLE | |
2491 maketitle(); | |
2492 #endif | |
2493 } | |
2494 | |
2495 /* | |
2496 * ":argdelete" | |
2497 */ | |
2498 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2499 ex_argdelete(exarg_T *eap) |
7 | 2500 { |
2501 int i; | |
2502 int n; | |
2503 | |
2504 if (eap->addr_count > 0) | |
2505 { | |
2506 /* ":1,4argdel": Delete all arguments in the range. */ | |
2507 if (eap->line2 > ARGCOUNT) | |
2508 eap->line2 = ARGCOUNT; | |
2509 n = eap->line2 - eap->line1 + 1; | |
2510 if (*eap->arg != NUL || n <= 0) | |
2511 EMSG(_(e_invarg)); | |
2512 else | |
2513 { | |
2514 for (i = eap->line1; i <= eap->line2; ++i) | |
2515 vim_free(ARGLIST[i - 1].ae_fname); | |
2516 mch_memmove(ARGLIST + eap->line1 - 1, ARGLIST + eap->line2, | |
2517 (size_t)((ARGCOUNT - eap->line2) * sizeof(aentry_T))); | |
2518 ALIST(curwin)->al_ga.ga_len -= n; | |
2519 if (curwin->w_arg_idx >= eap->line2) | |
2520 curwin->w_arg_idx -= n; | |
2521 else if (curwin->w_arg_idx > eap->line1) | |
2522 curwin->w_arg_idx = eap->line1; | |
7639
0ecb62a66a7a
commit https://github.com/vim/vim/commit/72defda84eb26be9e2ade56c7877b912f818026e
Christian Brabandt <cb@256bit.org>
parents:
7625
diff
changeset
|
2523 if (ARGCOUNT == 0) |
0ecb62a66a7a
commit https://github.com/vim/vim/commit/72defda84eb26be9e2ade56c7877b912f818026e
Christian Brabandt <cb@256bit.org>
parents:
7625
diff
changeset
|
2524 curwin->w_arg_idx = 0; |
0ecb62a66a7a
commit https://github.com/vim/vim/commit/72defda84eb26be9e2ade56c7877b912f818026e
Christian Brabandt <cb@256bit.org>
parents:
7625
diff
changeset
|
2525 else if (curwin->w_arg_idx >= ARGCOUNT) |
0ecb62a66a7a
commit https://github.com/vim/vim/commit/72defda84eb26be9e2ade56c7877b912f818026e
Christian Brabandt <cb@256bit.org>
parents:
7625
diff
changeset
|
2526 curwin->w_arg_idx = ARGCOUNT - 1; |
7 | 2527 } |
2528 } | |
2529 else if (*eap->arg == NUL) | |
2530 EMSG(_(e_argreq)); | |
2531 else | |
2532 do_arglist(eap->arg, AL_DEL, 0); | |
2533 #ifdef FEAT_TITLE | |
2534 maketitle(); | |
2535 #endif | |
2536 } | |
2537 | |
2538 /* | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2539 * ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo" |
7 | 2540 */ |
2541 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2542 ex_listdo(exarg_T *eap) |
7 | 2543 { |
2544 int i; | |
2545 #ifdef FEAT_WINDOWS | |
685 | 2546 win_T *wp; |
2547 tabpage_T *tp; | |
7 | 2548 #endif |
6641 | 2549 buf_T *buf = curbuf; |
7 | 2550 int next_fnum = 0; |
2551 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) | |
2552 char_u *save_ei = NULL; | |
2553 #endif | |
39 | 2554 char_u *p_shm_save; |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2555 #ifdef FEAT_QUICKFIX |
7107
84efaf06f195
commit https://github.com/vim/vim/commit/ed84b76021df763619cabaedddc44eb5ee849136
Christian Brabandt <cb@256bit.org>
parents:
7092
diff
changeset
|
2556 int qf_size = 0; |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2557 int qf_idx; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2558 #endif |
7 | 2559 |
2560 #ifndef FEAT_WINDOWS | |
2561 if (eap->cmdidx == CMD_windo) | |
2562 { | |
2563 ex_ni(eap); | |
2564 return; | |
2565 } | |
2566 #endif | |
2567 | |
2568 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) | |
819 | 2569 if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo) |
123 | 2570 /* Don't do syntax HL autocommands. Skipping the syntax file is a |
2571 * great speed improvement. */ | |
2572 save_ei = au_event_disable(",Syntax"); | |
7 | 2573 #endif |
6116 | 2574 #ifdef FEAT_CLIPBOARD |
2575 start_global_changes(); | |
2576 #endif | |
7 | 2577 |
2578 if (eap->cmdidx == CMD_windo | |
685 | 2579 || eap->cmdidx == CMD_tabdo |
7 | 2580 || P_HID(curbuf) |
5464 | 2581 || !check_changed(curbuf, CCGD_AW |
2582 | (eap->forceit ? CCGD_FORCEIT : 0) | |
2583 | CCGD_EXCMD)) | |
7 | 2584 { |
2585 i = 0; | |
6474 | 2586 /* start at the eap->line1 argument/window/buffer */ |
7 | 2587 #ifdef FEAT_WINDOWS |
685 | 2588 wp = firstwin; |
2589 tp = first_tabpage; | |
7 | 2590 #endif |
6474 | 2591 switch (eap->cmdidx) |
2592 { | |
2593 #ifdef FEAT_WINDOWS | |
2594 case CMD_windo: | |
2595 for ( ; wp != NULL && i + 1 < eap->line1; wp = wp->w_next) | |
2596 i++; | |
2597 break; | |
2598 case CMD_tabdo: | |
2599 for( ; tp != NULL && i + 1 < eap->line1; tp = tp->tp_next) | |
2600 i++; | |
2601 break; | |
2602 #endif | |
2603 case CMD_argdo: | |
2604 i = eap->line1 - 1; | |
2605 break; | |
2606 default: | |
2607 break; | |
2608 } | |
7 | 2609 /* set pcmark now */ |
2610 if (eap->cmdidx == CMD_bufdo) | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2611 { |
6641 | 2612 /* Advance to the first listed buffer after "eap->line1". */ |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2613 for (buf = firstbuf; buf != NULL && (buf->b_fnum < eap->line1 |
6641 | 2614 || !buf->b_p_bl); buf = buf->b_next) |
2615 if (buf->b_fnum > eap->line2) | |
2616 { | |
2617 buf = NULL; | |
2618 break; | |
2619 } | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2620 if (buf != NULL) |
6641 | 2621 goto_buffer(eap, DOBUF_FIRST, FORWARD, buf->b_fnum); |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2622 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2623 #ifdef FEAT_QUICKFIX |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2624 else if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2625 || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2626 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2627 qf_size = qf_get_size(eap); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2628 if (qf_size <= 0 || eap->line1 > qf_size) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2629 buf = NULL; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2630 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2631 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2632 ex_cc(eap); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2633 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2634 buf = curbuf; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2635 i = eap->line1 - 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2636 if (eap->addr_count <= 0) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2637 /* default is all the quickfix/location list entries */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2638 eap->line2 = qf_size; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2639 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2640 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2641 #endif |
7 | 2642 else |
2643 setpcmark(); | |
2644 listcmd_busy = TRUE; /* avoids setting pcmark below */ | |
2645 | |
6641 | 2646 while (!got_int && buf != NULL) |
7 | 2647 { |
2648 if (eap->cmdidx == CMD_argdo) | |
2649 { | |
2650 /* go to argument "i" */ | |
2651 if (i == ARGCOUNT) | |
2652 break; | |
2653 /* Don't call do_argfile() when already there, it will try | |
2654 * reloading the file. */ | |
22 | 2655 if (curwin->w_arg_idx != i || !editing_arg_idx(curwin)) |
39 | 2656 { |
2657 /* Clear 'shm' to avoid that the file message overwrites | |
2658 * any output from the command. */ | |
2659 p_shm_save = vim_strsave(p_shm); | |
2660 set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); | |
7 | 2661 do_argfile(eap, i); |
39 | 2662 set_option_value((char_u *)"shm", 0L, p_shm_save, 0); |
2663 vim_free(p_shm_save); | |
2664 } | |
7 | 2665 if (curwin->w_arg_idx != i) |
2666 break; | |
2667 } | |
2668 #ifdef FEAT_WINDOWS | |
2669 else if (eap->cmdidx == CMD_windo) | |
2670 { | |
685 | 2671 /* go to window "wp" */ |
2672 if (!win_valid(wp)) | |
7 | 2673 break; |
685 | 2674 win_goto(wp); |
1115 | 2675 if (curwin != wp) |
2676 break; /* something must be wrong */ | |
685 | 2677 wp = curwin->w_next; |
2678 } | |
2679 else if (eap->cmdidx == CMD_tabdo) | |
2680 { | |
2681 /* go to window "tp" */ | |
2682 if (!valid_tabpage(tp)) | |
2683 break; | |
4354 | 2684 goto_tabpage_tp(tp, TRUE, TRUE); |
685 | 2685 tp = tp->tp_next; |
7 | 2686 } |
2687 #endif | |
2688 else if (eap->cmdidx == CMD_bufdo) | |
2689 { | |
2690 /* Remember the number of the next listed buffer, in case | |
2691 * ":bwipe" is used or autocommands do something strange. */ | |
2692 next_fnum = -1; | |
2693 for (buf = curbuf->b_next; buf != NULL; buf = buf->b_next) | |
2694 if (buf->b_p_bl) | |
2695 { | |
2696 next_fnum = buf->b_fnum; | |
2697 break; | |
2698 } | |
2699 } | |
2700 | |
6474 | 2701 ++i; |
2702 | |
7 | 2703 /* execute the command */ |
2704 do_cmdline(eap->arg, eap->getline, eap->cookie, | |
2705 DOCMD_VERBOSE + DOCMD_NOWAIT); | |
2706 | |
2707 if (eap->cmdidx == CMD_bufdo) | |
2708 { | |
2709 /* Done? */ | |
6474 | 2710 if (next_fnum < 0 || next_fnum > eap->line2) |
7 | 2711 break; |
2712 /* Check if the buffer still exists. */ | |
2713 for (buf = firstbuf; buf != NULL; buf = buf->b_next) | |
2714 if (buf->b_fnum == next_fnum) | |
2715 break; | |
2716 if (buf == NULL) | |
2717 break; | |
39 | 2718 |
2719 /* Go to the next buffer. Clear 'shm' to avoid that the file | |
2720 * message overwrites any output from the command. */ | |
2721 p_shm_save = vim_strsave(p_shm); | |
2722 set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); | |
7 | 2723 goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum); |
39 | 2724 set_option_value((char_u *)"shm", 0L, p_shm_save, 0); |
2725 vim_free(p_shm_save); | |
2726 | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2727 /* If autocommands took us elsewhere, quit here. */ |
7 | 2728 if (curbuf->b_fnum != next_fnum) |
2729 break; | |
2730 } | |
2731 | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2732 #ifdef FEAT_QUICKFIX |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2733 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2734 || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2735 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2736 if (i >= qf_size || i >= eap->line2) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2737 break; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2738 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2739 qf_idx = qf_get_cur_idx(eap); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2740 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2741 ex_cnext(eap); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2742 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2743 /* If jumping to the next quickfix entry fails, quit here */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2744 if (qf_get_cur_idx(eap) == qf_idx) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2745 break; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2746 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2747 #endif |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2748 |
7 | 2749 if (eap->cmdidx == CMD_windo) |
2750 { | |
2751 validate_cursor(); /* cursor may have moved */ | |
2752 #ifdef FEAT_SCROLLBIND | |
2753 /* required when 'scrollbind' has been set */ | |
2754 if (curwin->w_p_scb) | |
2755 do_check_scrollbind(TRUE); | |
2756 #endif | |
2757 } | |
6474 | 2758 |
2759 #ifdef FEAT_WINDOWS | |
2760 if (eap->cmdidx == CMD_windo || eap->cmdidx == CMD_tabdo) | |
2761 if (i+1 > eap->line2) | |
2762 break; | |
2763 #endif | |
2764 if (eap->cmdidx == CMD_argdo && i >= eap->line2) | |
2765 break; | |
7 | 2766 } |
2767 listcmd_busy = FALSE; | |
2768 } | |
2769 | |
2770 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) | |
154 | 2771 if (save_ei != NULL) |
2772 { | |
2773 au_event_restore(save_ei); | |
2774 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, | |
2775 curbuf->b_fname, TRUE, curbuf); | |
2776 } | |
7 | 2777 #endif |
6116 | 2778 #ifdef FEAT_CLIPBOARD |
2779 end_global_changes(); | |
2780 #endif | |
7 | 2781 } |
2782 | |
2783 /* | |
2784 * Add files[count] to the arglist of the current window after arg "after". | |
2785 * The file names in files[count] must have been allocated and are taken over. | |
2786 * Files[] itself is not taken over. | |
2787 * Returns index of first added argument. Returns -1 when failed (out of mem). | |
2788 */ | |
2789 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2790 alist_add_list( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2791 int count, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2792 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2793 int after) /* where to add: 0 = before first one */ |
7 | 2794 { |
2795 int i; | |
7647
65b2d593c203
commit https://github.com/vim/vim/commit/a24f0a550fed3d9773800cf6be4efd072fff20ec
Christian Brabandt <cb@256bit.org>
parents:
7639
diff
changeset
|
2796 int old_argcount = ARGCOUNT; |
7 | 2797 |
2798 if (ga_grow(&ALIST(curwin)->al_ga, count) == OK) | |
2799 { | |
2800 if (after < 0) | |
2801 after = 0; | |
2802 if (after > ARGCOUNT) | |
2803 after = ARGCOUNT; | |
2804 if (after < ARGCOUNT) | |
2805 mch_memmove(&(ARGLIST[after + count]), &(ARGLIST[after]), | |
2806 (ARGCOUNT - after) * sizeof(aentry_T)); | |
2807 for (i = 0; i < count; ++i) | |
2808 { | |
2809 ARGLIST[after + i].ae_fname = files[i]; | |
2810 ARGLIST[after + i].ae_fnum = buflist_add(files[i], BLN_LISTED); | |
2811 } | |
2812 ALIST(curwin)->al_ga.ga_len += count; | |
7647
65b2d593c203
commit https://github.com/vim/vim/commit/a24f0a550fed3d9773800cf6be4efd072fff20ec
Christian Brabandt <cb@256bit.org>
parents:
7639
diff
changeset
|
2813 if (old_argcount > 0 && curwin->w_arg_idx >= after) |
65b2d593c203
commit https://github.com/vim/vim/commit/a24f0a550fed3d9773800cf6be4efd072fff20ec
Christian Brabandt <cb@256bit.org>
parents:
7639
diff
changeset
|
2814 curwin->w_arg_idx += count; |
7 | 2815 return after; |
2816 } | |
2817 | |
2818 for (i = 0; i < count; ++i) | |
2819 vim_free(files[i]); | |
2820 return -1; | |
2821 } | |
2822 | |
2823 #endif /* FEAT_LISTCMDS */ | |
2824 | |
2825 #ifdef FEAT_EVAL | |
2826 /* | |
2827 * ":compiler[!] {name}" | |
2828 */ | |
2829 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2830 ex_compiler(exarg_T *eap) |
7 | 2831 { |
2832 char_u *buf; | |
2833 char_u *old_cur_comp = NULL; | |
2834 char_u *p; | |
2835 | |
2836 if (*eap->arg == NUL) | |
2837 { | |
2838 /* List all compiler scripts. */ | |
2839 do_cmdline_cmd((char_u *)"echo globpath(&rtp, 'compiler/*.vim')"); | |
2840 /* ) keep the indenter happy... */ | |
2841 } | |
2842 else | |
2843 { | |
2844 buf = alloc((unsigned)(STRLEN(eap->arg) + 14)); | |
2845 if (buf != NULL) | |
2846 { | |
2847 if (eap->forceit) | |
2848 { | |
2849 /* ":compiler! {name}" sets global options */ | |
2850 do_cmdline_cmd((char_u *) | |
2851 "command -nargs=* CompilerSet set <args>"); | |
2852 } | |
2853 else | |
2854 { | |
2855 /* ":compiler! {name}" sets local options. | |
2856 * To remain backwards compatible "current_compiler" is always | |
2857 * used. A user's compiler plugin may set it, the distributed | |
2858 * plugin will then skip the settings. Afterwards set | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2859 * "b:current_compiler" and restore "current_compiler". |
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2860 * Explicitly prepend "g:" to make it work in a function. */ |
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2861 old_cur_comp = get_var_value((char_u *)"g:current_compiler"); |
7 | 2862 if (old_cur_comp != NULL) |
2863 old_cur_comp = vim_strsave(old_cur_comp); | |
2864 do_cmdline_cmd((char_u *) | |
2865 "command -nargs=* CompilerSet setlocal <args>"); | |
2866 } | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2867 do_unlet((char_u *)"g:current_compiler", TRUE); |
148 | 2868 do_unlet((char_u *)"b:current_compiler", TRUE); |
7 | 2869 |
2870 sprintf((char *)buf, "compiler/%s.vim", eap->arg); | |
480 | 2871 if (source_runtime(buf, TRUE) == FAIL) |
7 | 2872 EMSG2(_("E666: compiler not supported: %s"), eap->arg); |
2873 vim_free(buf); | |
2874 | |
2875 do_cmdline_cmd((char_u *)":delcommand CompilerSet"); | |
2876 | |
2877 /* Set "b:current_compiler" from "current_compiler". */ | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2878 p = get_var_value((char_u *)"g:current_compiler"); |
7 | 2879 if (p != NULL) |
2880 set_internal_string_var((char_u *)"b:current_compiler", p); | |
2881 | |
2882 /* Restore "current_compiler" for ":compiler {name}". */ | |
2883 if (!eap->forceit) | |
2884 { | |
2885 if (old_cur_comp != NULL) | |
2886 { | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2887 set_internal_string_var((char_u *)"g:current_compiler", |
7 | 2888 old_cur_comp); |
2889 vim_free(old_cur_comp); | |
2890 } | |
2891 else | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2892 do_unlet((char_u *)"g:current_compiler", TRUE); |
7 | 2893 } |
2894 } | |
2895 } | |
2896 } | |
2897 #endif | |
2898 | |
2899 /* | |
2900 * ":runtime {name}" | |
2901 */ | |
2902 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2903 ex_runtime(exarg_T *eap) |
7 | 2904 { |
480 | 2905 source_runtime(eap->arg, eap->forceit); |
7 | 2906 } |
2907 | |
2908 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2909 source_callback(char_u *fname, void *cookie UNUSED) |
7 | 2910 { |
819 | 2911 (void)do_source(fname, FALSE, DOSO_NONE); |
7 | 2912 } |
2913 | |
2914 /* | |
2915 * Source the file "name" from all directories in 'runtimepath'. | |
2916 * "name" can contain wildcards. | |
2917 * When "all" is TRUE, source all files, otherwise only the first one. | |
2918 * return FAIL when no file could be sourced, OK otherwise. | |
2919 */ | |
2920 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2921 source_runtime(char_u *name, int all) |
7 | 2922 { |
237 | 2923 return do_in_runtimepath(name, all, source_callback, NULL); |
7 | 2924 } |
2925 | |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2926 static int |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2927 do_in_path( |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2928 char_u *path, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2929 char_u *name, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2930 int all, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2931 void (*callback)(char_u *fname, void *ck), |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2932 void *cookie) |
7 | 2933 { |
2934 char_u *rtp; | |
2935 char_u *np; | |
2936 char_u *buf; | |
2937 char_u *rtp_copy; | |
2938 char_u *tail; | |
2939 int num_files; | |
2940 char_u **files; | |
2941 int i; | |
2942 int did_one = FALSE; | |
2943 #ifdef AMIGA | |
2944 struct Process *proc = (struct Process *)FindTask(0L); | |
2945 APTR save_winptr = proc->pr_WindowPtr; | |
2946 | |
2947 /* Avoid a requester here for a volume that doesn't exist. */ | |
2948 proc->pr_WindowPtr = (APTR)-1L; | |
2949 #endif | |
2950 | |
2951 /* Make a copy of 'runtimepath'. Invoking the callback may change the | |
2952 * value. */ | |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2953 rtp_copy = vim_strsave(path); |
7 | 2954 buf = alloc(MAXPATHL); |
2955 if (buf != NULL && rtp_copy != NULL) | |
2956 { | |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2957 if (p_verbose > 1 && name != NULL) |
294 | 2958 { |
2959 verbose_enter(); | |
274 | 2960 smsg((char_u *)_("Searching for \"%s\" in \"%s\""), |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2961 (char *)name, (char *)path); |
294 | 2962 verbose_leave(); |
2963 } | |
271 | 2964 |
7 | 2965 /* Loop over all entries in 'runtimepath'. */ |
2966 rtp = rtp_copy; | |
2967 while (*rtp != NUL && (all || !did_one)) | |
2968 { | |
2969 /* Copy the path from 'runtimepath' to buf[]. */ | |
2970 copy_option_part(&rtp, buf, MAXPATHL, ","); | |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2971 if (name == NULL) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2972 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2973 (*callback)(buf, (void *) &cookie); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2974 if (!did_one) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2975 did_one = (cookie == NULL); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2976 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2977 else if (STRLEN(buf) + STRLEN(name) + 2 < MAXPATHL) |
7 | 2978 { |
2979 add_pathsep(buf); | |
2980 tail = buf + STRLEN(buf); | |
2981 | |
2982 /* Loop over all patterns in "name" */ | |
2983 np = name; | |
2984 while (*np != NUL && (all || !did_one)) | |
2985 { | |
2986 /* Append the pattern from "name" to buf[]. */ | |
2987 copy_option_part(&np, tail, (int)(MAXPATHL - (tail - buf)), | |
2988 "\t "); | |
2989 | |
2990 if (p_verbose > 2) | |
294 | 2991 { |
2992 verbose_enter(); | |
274 | 2993 smsg((char_u *)_("Searching for \"%s\""), buf); |
294 | 2994 verbose_leave(); |
2995 } | |
7 | 2996 |
2997 /* Expand wildcards, invoke the callback for each match. */ | |
2998 if (gen_expand_wildcards(1, &buf, &num_files, &files, | |
2999 EW_FILE) == OK) | |
3000 { | |
3001 for (i = 0; i < num_files; ++i) | |
3002 { | |
237 | 3003 (*callback)(files[i], cookie); |
7 | 3004 did_one = TRUE; |
3005 if (!all) | |
3006 break; | |
3007 } | |
3008 FreeWild(num_files, files); | |
3009 } | |
3010 } | |
3011 } | |
3012 } | |
3013 } | |
3014 vim_free(buf); | |
3015 vim_free(rtp_copy); | |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
3016 if (p_verbose > 0 && !did_one && name != NULL) |
294 | 3017 { |
3018 verbose_enter(); | |
274 | 3019 smsg((char_u *)_("not found in 'runtimepath': \"%s\""), name); |
294 | 3020 verbose_leave(); |
3021 } | |
7 | 3022 |
3023 #ifdef AMIGA | |
3024 proc->pr_WindowPtr = save_winptr; | |
3025 #endif | |
3026 | |
3027 return did_one ? OK : FAIL; | |
3028 } | |
3029 | |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3030 /* |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3031 * Find "name" in 'runtimepath'. When found, invoke the callback function for |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3032 * it: callback(fname, "cookie") |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3033 * When "all" is TRUE repeat for all matches, otherwise only the first one is |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3034 * used. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3035 * Returns OK when at least one match found, FAIL otherwise. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3036 * |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3037 * If "name" is NULL calls callback for each entry in runtimepath. Cookie is |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3038 * passed by reference in this case, setting it to NULL indicates that callback |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3039 * has done its job. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3040 */ |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3041 int |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3042 do_in_runtimepath( |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3043 char_u *name, |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3044 int all, |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3045 void (*callback)(char_u *fname, void *ck), |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3046 void *cookie) |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3047 { |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3048 return do_in_path(p_rtp, name, all, callback, cookie); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3049 } |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3050 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3051 static void |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3052 source_pack_plugin(char_u *fname, void *cookie UNUSED) |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3053 { |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3054 char_u *p6, *p5, *p4, *p3, *p2, *p1, *p; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3055 int c; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3056 char_u *new_rtp; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3057 int keep; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3058 int oldlen; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3059 int addlen; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3060 |
8190
a8e7b8328cb4
commit https://github.com/vim/vim/commit/bdcd75275002c3b74015bb9bc0a01b13bb6107d4
Christian Brabandt <cb@256bit.org>
parents:
8182
diff
changeset
|
3061 p6 = p5 = p4 = p3 = p2 = p1 = get_past_head(fname); |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3062 for (p = p1; *p; mb_ptr_adv(p)) |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3063 if (vim_ispathsep_nocolon(*p)) |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3064 { |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3065 p6 = p5; p5 = p4; p4 = p3; p3 = p2; p2 = p1; p1 = p; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3066 } |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3067 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3068 /* now we have: |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3069 * rtp/pack/name/ever/name/plugin/name.vim |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3070 * p6 p5 p4 p3 p2 p1 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3071 */ |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3072 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3073 /* find the part up to "pack" in 'runtimepath' */ |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3074 c = *p6; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3075 *p6 = NUL; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3076 p = (char_u *)strstr((char *)p_rtp, (char *)fname); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3077 if (p == NULL) |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3078 /* not found, append at the end */ |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3079 p = p_rtp + STRLEN(p_rtp); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3080 else |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3081 /* append after the matching directory. */ |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3082 p += STRLEN(fname); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3083 *p6 = c; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3084 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3085 c = *p2; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3086 *p2 = NUL; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3087 if (strstr((char *)p_rtp, (char *)fname) == NULL) |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3088 { |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3089 /* directory not in 'runtimepath', add it */ |
8206
78f2e8c07973
commit https://github.com/vim/vim/commit/1daae446e58fd90f98c51ff3af8f54bfa5197751
Christian Brabandt <cb@256bit.org>
parents:
8190
diff
changeset
|
3090 oldlen = (int)STRLEN(p_rtp); |
78f2e8c07973
commit https://github.com/vim/vim/commit/1daae446e58fd90f98c51ff3af8f54bfa5197751
Christian Brabandt <cb@256bit.org>
parents:
8190
diff
changeset
|
3091 addlen = (int)STRLEN(fname); |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3092 new_rtp = alloc(oldlen + addlen + 2); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3093 if (new_rtp == NULL) |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3094 { |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3095 *p2 = c; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3096 return; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3097 } |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3098 keep = (int)(p - p_rtp); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3099 mch_memmove(new_rtp, p_rtp, keep); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3100 new_rtp[keep] = ','; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3101 mch_memmove(new_rtp + keep + 1, fname, addlen + 1); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3102 if (p_rtp[keep] != NUL) |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3103 mch_memmove(new_rtp + keep + 1 + addlen, p_rtp + keep, |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3104 oldlen - keep + 1); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3105 free_string_option(p_rtp); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3106 p_rtp = new_rtp; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3107 } |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3108 *p2 = c; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3109 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3110 (void)do_source(fname, FALSE, DOSO_NONE); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3111 } |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3112 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3113 /* |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3114 * Source the plugins in the package directories. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3115 */ |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3116 void |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3117 source_packages() |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3118 { |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3119 do_in_path(p_pp, (char_u *)"pack/*/ever/*/plugin/*.vim", |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3120 TRUE, source_pack_plugin, NULL); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3121 } |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3122 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3123 /* |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3124 * ":loadplugin {name}" |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3125 */ |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3126 void |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3127 ex_loadplugin(exarg_T *eap) |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3128 { |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3129 static char *pattern = "pack/*/opt/%s/plugin/*.vim"; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3130 int len; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3131 char *pat; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3132 |
8206
78f2e8c07973
commit https://github.com/vim/vim/commit/1daae446e58fd90f98c51ff3af8f54bfa5197751
Christian Brabandt <cb@256bit.org>
parents:
8190
diff
changeset
|
3133 len = (int)STRLEN(pattern) + (int)STRLEN(eap->arg); |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3134 pat = (char *)alloc(len); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3135 if (pat == NULL) |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3136 return; |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3137 vim_snprintf(pat, len, pattern, eap->arg); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3138 do_in_path(p_pp, (char_u *)pat, TRUE, source_pack_plugin, NULL); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3139 vim_free(pat); |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3140 } |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3141 |
7 | 3142 #if defined(FEAT_EVAL) && defined(FEAT_AUTOCMD) |
3143 /* | |
3144 * ":options" | |
3145 */ | |
3146 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3147 ex_options( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3148 exarg_T *eap UNUSED) |
7 | 3149 { |
3150 cmd_source((char_u *)SYS_OPTWIN_FILE, NULL); | |
3151 } | |
3152 #endif | |
3153 | |
3154 /* | |
3155 * ":source {fname}" | |
3156 */ | |
3157 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3158 ex_source(exarg_T *eap) |
7 | 3159 { |
3160 #ifdef FEAT_BROWSE | |
3161 if (cmdmod.browse) | |
3162 { | |
3163 char_u *fname = NULL; | |
3164 | |
29 | 3165 fname = do_browse(0, (char_u *)_("Source Vim script"), eap->arg, |
7 | 3166 NULL, NULL, BROWSE_FILTER_MACROS, NULL); |
3167 if (fname != NULL) | |
3168 { | |
3169 cmd_source(fname, eap); | |
3170 vim_free(fname); | |
3171 } | |
3172 } | |
3173 else | |
3174 #endif | |
3175 cmd_source(eap->arg, eap); | |
3176 } | |
3177 | |
3178 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3179 cmd_source(char_u *fname, exarg_T *eap) |
7 | 3180 { |
3181 if (*fname == NUL) | |
3182 EMSG(_(e_argreq)); | |
3183 | |
3184 else if (eap != NULL && eap->forceit) | |
4352 | 3185 /* ":source!": read Normal mode commands |
716 | 3186 * Need to execute the commands directly. This is required at least |
3187 * for: | |
7 | 3188 * - ":g" command busy |
3189 * - after ":argdo", ":windo" or ":bufdo" | |
3190 * - another command follows | |
3191 * - inside a loop | |
3192 */ | |
3193 openscript(fname, global_busy || listcmd_busy || eap->nextcmd != NULL | |
3194 #ifdef FEAT_EVAL | |
3195 || eap->cstack->cs_idx >= 0 | |
3196 #endif | |
3197 ); | |
3198 | |
3199 /* ":source" read ex commands */ | |
819 | 3200 else if (do_source(fname, FALSE, DOSO_NONE) == FAIL) |
7 | 3201 EMSG2(_(e_notopen), fname); |
3202 } | |
3203 | |
3204 /* | |
3205 * ":source" and associated commands. | |
3206 */ | |
3207 /* | |
3208 * Structure used to store info for each sourced file. | |
3209 * It is shared between do_source() and getsourceline(). | |
3210 * This is required, because it needs to be handed to do_cmdline() and | |
3211 * sourcing can be done recursively. | |
3212 */ | |
3213 struct source_cookie | |
3214 { | |
3215 FILE *fp; /* opened file for sourcing */ | |
3216 char_u *nextline; /* if not NULL: line that was read ahead */ | |
3217 int finished; /* ":finish" used */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
3218 #if defined(USE_CRNL) || defined(USE_CR) |
7 | 3219 int fileformat; /* EOL_UNKNOWN, EOL_UNIX or EOL_DOS */ |
3220 int error; /* TRUE if LF found after CR-LF */ | |
3221 #endif | |
3222 #ifdef FEAT_EVAL | |
3223 linenr_T breakpoint; /* next line with breakpoint or zero */ | |
3224 char_u *fname; /* name of sourced file */ | |
3225 int dbg_tick; /* debug_tick when breakpoint was set */ | |
3226 int level; /* top nesting level of sourced file */ | |
3227 #endif | |
3228 #ifdef FEAT_MBYTE | |
3229 vimconv_T conv; /* type of conversion */ | |
3230 #endif | |
3231 }; | |
3232 | |
3233 #ifdef FEAT_EVAL | |
3234 /* | |
3235 * Return the address holding the next breakpoint line for a source cookie. | |
3236 */ | |
3237 linenr_T * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3238 source_breakpoint(void *cookie) |
7 | 3239 { |
3240 return &((struct source_cookie *)cookie)->breakpoint; | |
3241 } | |
3242 | |
3243 /* | |
3244 * Return the address holding the debug tick for a source cookie. | |
3245 */ | |
3246 int * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3247 source_dbg_tick(void *cookie) |
7 | 3248 { |
3249 return &((struct source_cookie *)cookie)->dbg_tick; | |
3250 } | |
3251 | |
3252 /* | |
3253 * Return the nesting level for a source cookie. | |
3254 */ | |
3255 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3256 source_level(void *cookie) |
7 | 3257 { |
3258 return ((struct source_cookie *)cookie)->level; | |
3259 } | |
3260 #endif | |
3261 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
3262 static char_u *get_one_sourceline(struct source_cookie *sp); |
7 | 3263 |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3264 #if (defined(WIN32) && defined(FEAT_CSCOPE)) || defined(HAVE_FD_CLOEXEC) |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3265 # define USE_FOPEN_NOINH |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
3266 static FILE *fopen_noinh_readbin(char *filename); |
7 | 3267 |
3268 /* | |
3269 * Special function to open a file without handle inheritance. | |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3270 * When possible the handle is closed on exec(). |
7 | 3271 */ |
3272 static FILE * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3273 fopen_noinh_readbin(char *filename) |
7 | 3274 { |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3275 # ifdef WIN32 |
2058
fb1222c880fc
updated for version 7.2.344
Bram Moolenaar <bram@zimbu.org>
parents:
2057
diff
changeset
|
3276 int fd_tmp = mch_open(filename, O_RDONLY | O_BINARY | O_NOINHERIT, 0); |
fb1222c880fc
updated for version 7.2.344
Bram Moolenaar <bram@zimbu.org>
parents:
2057
diff
changeset
|
3277 # else |
fb1222c880fc
updated for version 7.2.344
Bram Moolenaar <bram@zimbu.org>
parents:
2057
diff
changeset
|
3278 int fd_tmp = mch_open(filename, O_RDONLY, 0); |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3279 # endif |
7 | 3280 |
3281 if (fd_tmp == -1) | |
3282 return NULL; | |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3283 |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3284 # ifdef HAVE_FD_CLOEXEC |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3285 { |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3286 int fdflags = fcntl(fd_tmp, F_GETFD); |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3287 if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0) |
7009 | 3288 (void)fcntl(fd_tmp, F_SETFD, fdflags | FD_CLOEXEC); |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3289 } |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3290 # endif |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3291 |
7 | 3292 return fdopen(fd_tmp, READBIN); |
3293 } | |
3294 #endif | |
3295 | |
3296 | |
3297 /* | |
3298 * do_source: Read the file "fname" and execute its lines as EX commands. | |
3299 * | |
3300 * This function may be called recursively! | |
3301 * | |
3302 * return FAIL if file could not be opened, OK otherwise | |
3303 */ | |
3304 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3305 do_source( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3306 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3307 int check_other, /* check for .vimrc and _vimrc */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3308 int is_vimrc) /* DOSO_ value */ |
7 | 3309 { |
3310 struct source_cookie cookie; | |
3311 char_u *save_sourcing_name; | |
3312 linenr_T save_sourcing_lnum; | |
3313 char_u *p; | |
3314 char_u *fname_exp; | |
1802 | 3315 char_u *firstline = NULL; |
7 | 3316 int retval = FAIL; |
3317 #ifdef FEAT_EVAL | |
3318 scid_T save_current_SID; | |
3319 static scid_T last_current_SID = 0; | |
3320 void *save_funccalp; | |
3321 int save_debug_break_level = debug_break_level; | |
170 | 3322 scriptitem_T *si = NULL; |
7 | 3323 # ifdef UNIX |
3324 struct stat st; | |
3325 int stat_ok; | |
3326 # endif | |
3327 #endif | |
3328 #ifdef STARTUPTIME | |
3329 struct timeval tv_rel; | |
3330 struct timeval tv_start; | |
3331 #endif | |
170 | 3332 #ifdef FEAT_PROFILE |
3333 proftime_T wait_start; | |
3334 #endif | |
7 | 3335 |
3336 p = expand_env_save(fname); | |
3337 if (p == NULL) | |
3338 return retval; | |
3339 fname_exp = fix_fname(p); | |
3340 vim_free(p); | |
3341 if (fname_exp == NULL) | |
3342 return retval; | |
3343 if (mch_isdir(fname_exp)) | |
3344 { | |
274 | 3345 smsg((char_u *)_("Cannot source a directory: \"%s\""), fname); |
7 | 3346 goto theend; |
3347 } | |
3348 | |
716 | 3349 #ifdef FEAT_AUTOCMD |
1061 | 3350 /* Apply SourceCmd autocommands, they should get the file and source it. */ |
3351 if (has_autocmd(EVENT_SOURCECMD, fname_exp, NULL) | |
3352 && apply_autocmds(EVENT_SOURCECMD, fname_exp, fname_exp, | |
3353 FALSE, curbuf)) | |
1515 | 3354 { |
1061 | 3355 # ifdef FEAT_EVAL |
1515 | 3356 retval = aborting() ? FAIL : OK; |
1061 | 3357 # else |
1515 | 3358 retval = OK; |
1061 | 3359 # endif |
1515 | 3360 goto theend; |
3361 } | |
1061 | 3362 |
3363 /* Apply SourcePre autocommands, they may get the file. */ | |
716 | 3364 apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf); |
3365 #endif | |
3366 | |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3367 #ifdef USE_FOPEN_NOINH |
7 | 3368 cookie.fp = fopen_noinh_readbin((char *)fname_exp); |
3369 #else | |
3370 cookie.fp = mch_fopen((char *)fname_exp, READBIN); | |
3371 #endif | |
3372 if (cookie.fp == NULL && check_other) | |
3373 { | |
3374 /* | |
3375 * Try again, replacing file name ".vimrc" by "_vimrc" or vice versa, | |
3376 * and ".exrc" by "_exrc" or vice versa. | |
3377 */ | |
3378 p = gettail(fname_exp); | |
3379 if ((*p == '.' || *p == '_') | |
3380 && (STRICMP(p + 1, "vimrc") == 0 | |
3381 || STRICMP(p + 1, "gvimrc") == 0 | |
3382 || STRICMP(p + 1, "exrc") == 0)) | |
3383 { | |
3384 if (*p == '_') | |
3385 *p = '.'; | |
3386 else | |
3387 *p = '_'; | |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3388 #ifdef USE_FOPEN_NOINH |
7 | 3389 cookie.fp = fopen_noinh_readbin((char *)fname_exp); |
3390 #else | |
3391 cookie.fp = mch_fopen((char *)fname_exp, READBIN); | |
3392 #endif | |
3393 } | |
3394 } | |
3395 | |
3396 if (cookie.fp == NULL) | |
3397 { | |
3398 if (p_verbose > 0) | |
3399 { | |
294 | 3400 verbose_enter(); |
7 | 3401 if (sourcing_name == NULL) |
274 | 3402 smsg((char_u *)_("could not source \"%s\""), fname); |
7 | 3403 else |
3404 smsg((char_u *)_("line %ld: could not source \"%s\""), | |
274 | 3405 sourcing_lnum, fname); |
294 | 3406 verbose_leave(); |
7 | 3407 } |
3408 goto theend; | |
3409 } | |
3410 | |
3411 /* | |
3412 * The file exists. | |
3413 * - In verbose mode, give a message. | |
3414 * - For a vimrc file, may want to set 'compatible', call vimrc_found(). | |
3415 */ | |
3416 if (p_verbose > 1) | |
3417 { | |
294 | 3418 verbose_enter(); |
7 | 3419 if (sourcing_name == NULL) |
274 | 3420 smsg((char_u *)_("sourcing \"%s\""), fname); |
7 | 3421 else |
3422 smsg((char_u *)_("line %ld: sourcing \"%s\""), | |
274 | 3423 sourcing_lnum, fname); |
294 | 3424 verbose_leave(); |
7 | 3425 } |
819 | 3426 if (is_vimrc == DOSO_VIMRC) |
3427 vimrc_found(fname_exp, (char_u *)"MYVIMRC"); | |
3428 else if (is_vimrc == DOSO_GVIMRC) | |
3429 vimrc_found(fname_exp, (char_u *)"MYGVIMRC"); | |
7 | 3430 |
3431 #ifdef USE_CRNL | |
3432 /* If no automatic file format: Set default to CR-NL. */ | |
3433 if (*p_ffs == NUL) | |
3434 cookie.fileformat = EOL_DOS; | |
3435 else | |
3436 cookie.fileformat = EOL_UNKNOWN; | |
3437 cookie.error = FALSE; | |
3438 #endif | |
3439 | |
3440 #ifdef USE_CR | |
3441 /* If no automatic file format: Set default to CR. */ | |
3442 if (*p_ffs == NUL) | |
3443 cookie.fileformat = EOL_MAC; | |
3444 else | |
3445 cookie.fileformat = EOL_UNKNOWN; | |
3446 cookie.error = FALSE; | |
3447 #endif | |
3448 | |
3449 cookie.nextline = NULL; | |
3450 cookie.finished = FALSE; | |
3451 | |
3452 #ifdef FEAT_EVAL | |
3453 /* | |
3454 * Check if this script has a breakpoint. | |
3455 */ | |
3456 cookie.breakpoint = dbg_find_breakpoint(TRUE, fname_exp, (linenr_T)0); | |
3457 cookie.fname = fname_exp; | |
3458 cookie.dbg_tick = debug_tick; | |
3459 | |
3460 cookie.level = ex_nesting_level; | |
3461 #endif | |
3462 | |
3463 /* | |
3464 * Keep the sourcing name/lnum, for recursive calls. | |
3465 */ | |
3466 save_sourcing_name = sourcing_name; | |
3467 sourcing_name = fname_exp; | |
3468 save_sourcing_lnum = sourcing_lnum; | |
3469 sourcing_lnum = 0; | |
3470 | |
1802 | 3471 #ifdef FEAT_MBYTE |
3472 cookie.conv.vc_type = CONV_NONE; /* no conversion */ | |
3473 | |
3474 /* Read the first line so we can check for a UTF-8 BOM. */ | |
3475 firstline = getsourceline(0, (void *)&cookie, 0); | |
3476 if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef | |
3477 && firstline[1] == 0xbb && firstline[2] == 0xbf) | |
3478 { | |
3479 /* Found BOM; setup conversion, skip over BOM and recode the line. */ | |
3480 convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc); | |
3481 p = string_convert(&cookie.conv, firstline + 3, NULL); | |
1804 | 3482 if (p == NULL) |
3483 p = vim_strsave(firstline + 3); | |
1802 | 3484 if (p != NULL) |
3485 { | |
3486 vim_free(firstline); | |
3487 firstline = p; | |
3488 } | |
3489 } | |
3490 #endif | |
3491 | |
7 | 3492 #ifdef STARTUPTIME |
2053
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3493 if (time_fd != NULL) |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3494 time_push(&tv_rel, &tv_start); |
7 | 3495 #endif |
3496 | |
3497 #ifdef FEAT_EVAL | |
170 | 3498 # ifdef FEAT_PROFILE |
790 | 3499 if (do_profiling == PROF_YES) |
170 | 3500 prof_child_enter(&wait_start); /* entering a child now */ |
3501 # endif | |
3502 | |
3503 /* Don't use local function variables, if called from a function. | |
3504 * Also starts profiling timer for nested script. */ | |
3505 save_funccalp = save_funccal(); | |
3506 | |
7 | 3507 /* |
3508 * Check if this script was sourced before to finds its SID. | |
3509 * If it's new, generate a new SID. | |
3510 */ | |
3511 save_current_SID = current_SID; | |
3512 # ifdef UNIX | |
3513 stat_ok = (mch_stat((char *)fname_exp, &st) >= 0); | |
3514 # endif | |
170 | 3515 for (current_SID = script_items.ga_len; current_SID > 0; --current_SID) |
3516 { | |
3517 si = &SCRIPT_ITEM(current_SID); | |
3518 if (si->sn_name != NULL | |
7 | 3519 && ( |
3520 # ifdef UNIX | |
161 | 3521 /* Compare dev/ino when possible, it catches symbolic |
3522 * links. Also compare file names, the inode may change | |
3523 * when the file was edited. */ | |
1882 | 3524 ((stat_ok && si->sn_dev_valid) |
170 | 3525 && (si->sn_dev == st.st_dev |
3526 && si->sn_ino == st.st_ino)) || | |
7 | 3527 # endif |
170 | 3528 fnamecmp(si->sn_name, fname_exp) == 0)) |
7 | 3529 break; |
170 | 3530 } |
7 | 3531 if (current_SID == 0) |
3532 { | |
3533 current_SID = ++last_current_SID; | |
170 | 3534 if (ga_grow(&script_items, (int)(current_SID - script_items.ga_len)) |
3535 == FAIL) | |
3536 goto almosttheend; | |
3537 while (script_items.ga_len < current_SID) | |
7 | 3538 { |
170 | 3539 ++script_items.ga_len; |
3540 SCRIPT_ITEM(script_items.ga_len).sn_name = NULL; | |
3541 # ifdef FEAT_PROFILE | |
3542 SCRIPT_ITEM(script_items.ga_len).sn_prof_on = FALSE; | |
3543 # endif | |
3544 } | |
3545 si = &SCRIPT_ITEM(current_SID); | |
3546 si->sn_name = fname_exp; | |
3547 fname_exp = NULL; | |
7 | 3548 # ifdef UNIX |
170 | 3549 if (stat_ok) |
3550 { | |
1882 | 3551 si->sn_dev_valid = TRUE; |
170 | 3552 si->sn_dev = st.st_dev; |
3553 si->sn_ino = st.st_ino; | |
3554 } | |
3555 else | |
1882 | 3556 si->sn_dev_valid = FALSE; |
7 | 3557 # endif |
170 | 3558 |
7 | 3559 /* Allocate the local script variables to use for this script. */ |
3560 new_script_vars(current_SID); | |
3561 } | |
3562 | |
170 | 3563 # ifdef FEAT_PROFILE |
790 | 3564 if (do_profiling == PROF_YES) |
170 | 3565 { |
3566 int forceit; | |
3567 | |
3568 /* Check if we do profiling for this script. */ | |
3569 if (!si->sn_prof_on && has_profiling(TRUE, si->sn_name, &forceit)) | |
3570 { | |
3571 script_do_profile(si); | |
3572 si->sn_pr_force = forceit; | |
3573 } | |
3574 if (si->sn_prof_on) | |
3575 { | |
3576 ++si->sn_pr_count; | |
3577 profile_start(&si->sn_pr_start); | |
3578 profile_zero(&si->sn_pr_children); | |
3579 } | |
3580 } | |
3581 # endif | |
7 | 3582 #endif |
3583 | |
3584 /* | |
3585 * Call do_cmdline, which will call getsourceline() to get the lines. | |
3586 */ | |
1802 | 3587 do_cmdline(firstline, getsourceline, (void *)&cookie, |
7 | 3588 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT); |
3589 retval = OK; | |
170 | 3590 |
3591 #ifdef FEAT_PROFILE | |
790 | 3592 if (do_profiling == PROF_YES) |
170 | 3593 { |
3594 /* Get "si" again, "script_items" may have been reallocated. */ | |
3595 si = &SCRIPT_ITEM(current_SID); | |
3596 if (si->sn_prof_on) | |
3597 { | |
3598 profile_end(&si->sn_pr_start); | |
3599 profile_sub_wait(&wait_start, &si->sn_pr_start); | |
3600 profile_add(&si->sn_pr_total, &si->sn_pr_start); | |
720 | 3601 profile_self(&si->sn_pr_self, &si->sn_pr_start, |
3602 &si->sn_pr_children); | |
170 | 3603 } |
3604 } | |
7 | 3605 #endif |
3606 | |
3607 if (got_int) | |
3608 EMSG(_(e_interr)); | |
3609 sourcing_name = save_sourcing_name; | |
3610 sourcing_lnum = save_sourcing_lnum; | |
3611 if (p_verbose > 1) | |
3612 { | |
294 | 3613 verbose_enter(); |
274 | 3614 smsg((char_u *)_("finished sourcing %s"), fname); |
7 | 3615 if (sourcing_name != NULL) |
274 | 3616 smsg((char_u *)_("continuing in %s"), sourcing_name); |
294 | 3617 verbose_leave(); |
7 | 3618 } |
3619 #ifdef STARTUPTIME | |
2053
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3620 if (time_fd != NULL) |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3621 { |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3622 vim_snprintf((char *)IObuff, IOSIZE, "sourcing %s", fname); |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3623 time_msg((char *)IObuff, &tv_start); |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3624 time_pop(&tv_rel); |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3625 } |
7 | 3626 #endif |
3627 | |
3628 #ifdef FEAT_EVAL | |
3629 /* | |
3630 * After a "finish" in debug mode, need to break at first command of next | |
3631 * sourced file. | |
3632 */ | |
3633 if (save_debug_break_level > ex_nesting_level | |
3634 && debug_break_level == ex_nesting_level) | |
3635 ++debug_break_level; | |
3636 #endif | |
3637 | |
170 | 3638 #ifdef FEAT_EVAL |
3639 almosttheend: | |
3640 current_SID = save_current_SID; | |
3641 restore_funccal(save_funccalp); | |
3642 # ifdef FEAT_PROFILE | |
790 | 3643 if (do_profiling == PROF_YES) |
170 | 3644 prof_child_exit(&wait_start); /* leaving a child now */ |
3645 # endif | |
3646 #endif | |
3647 fclose(cookie.fp); | |
3648 vim_free(cookie.nextline); | |
1802 | 3649 vim_free(firstline); |
170 | 3650 #ifdef FEAT_MBYTE |
3651 convert_setup(&cookie.conv, NULL, NULL); | |
3652 #endif | |
3653 | |
7 | 3654 theend: |
3655 vim_free(fname_exp); | |
3656 return retval; | |
3657 } | |
3658 | |
3659 #if defined(FEAT_EVAL) || defined(PROTO) | |
356 | 3660 |
7 | 3661 /* |
3662 * ":scriptnames" | |
3663 */ | |
3664 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3665 ex_scriptnames(exarg_T *eap UNUSED) |
7 | 3666 { |
3667 int i; | |
3668 | |
170 | 3669 for (i = 1; i <= script_items.ga_len && !got_int; ++i) |
3670 if (SCRIPT_ITEM(i).sn_name != NULL) | |
2921 | 3671 { |
3672 home_replace(NULL, SCRIPT_ITEM(i).sn_name, | |
3673 NameBuff, MAXPATHL, TRUE); | |
3674 smsg((char_u *)"%3d: %s", i, NameBuff); | |
3429 | 3675 } |
7 | 3676 } |
3677 | |
3678 # if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) | |
3679 /* | |
3680 * Fix slashes in the list of script names for 'shellslash'. | |
3681 */ | |
3682 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3683 scriptnames_slash_adjust(void) |
7 | 3684 { |
3685 int i; | |
3686 | |
170 | 3687 for (i = 1; i <= script_items.ga_len; ++i) |
3688 if (SCRIPT_ITEM(i).sn_name != NULL) | |
3689 slash_adjust(SCRIPT_ITEM(i).sn_name); | |
7 | 3690 } |
3691 # endif | |
3692 | |
3693 /* | |
3694 * Get a pointer to a script name. Used for ":verbose set". | |
3695 */ | |
3696 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3697 get_scriptname(scid_T id) |
7 | 3698 { |
3699 if (id == SID_MODELINE) | |
681 | 3700 return (char_u *)_("modeline"); |
7 | 3701 if (id == SID_CMDARG) |
681 | 3702 return (char_u *)_("--cmd argument"); |
7 | 3703 if (id == SID_CARG) |
681 | 3704 return (char_u *)_("-c argument"); |
7 | 3705 if (id == SID_ENV) |
681 | 3706 return (char_u *)_("environment variable"); |
3707 if (id == SID_ERROR) | |
3708 return (char_u *)_("error handler"); | |
170 | 3709 return SCRIPT_ITEM(id).sn_name; |
3710 } | |
3711 | |
356 | 3712 # if defined(EXITFREE) || defined(PROTO) |
3713 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3714 free_scriptnames(void) |
356 | 3715 { |
3716 int i; | |
3717 | |
3718 for (i = script_items.ga_len; i > 0; --i) | |
3719 vim_free(SCRIPT_ITEM(i).sn_name); | |
3720 ga_clear(&script_items); | |
3721 } | |
3722 # endif | |
3723 | |
7 | 3724 #endif |
3725 | |
3726 #if defined(USE_CR) || defined(PROTO) | |
3727 | |
3728 # if defined(__MSL__) && (__MSL__ >= 22) | |
3729 /* | |
3730 * Newer version of the Metrowerks library handle DOS and UNIX files | |
3731 * without help. | |
3732 * Test with earlier versions, MSL 2.2 is the library supplied with | |
3733 * Codewarrior Pro 2. | |
3734 */ | |
3735 char * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3736 fgets_cr(char *s, int n, FILE *stream) |
7 | 3737 { |
3738 return fgets(s, n, stream); | |
3739 } | |
3740 # else | |
3741 /* | |
3742 * Version of fgets() which also works for lines ending in a <CR> only | |
3743 * (Macintosh format). | |
3744 * For older versions of the Metrowerks library. | |
3745 * At least CodeWarrior 9 needed this code. | |
3746 */ | |
3747 char * | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
3748 fgets_cr(char *s, int n, FILE *stream) |
7 | 3749 { |
3750 int c = 0; | |
3751 int char_read = 0; | |
3752 | |
3753 while (!feof(stream) && c != '\r' && c != '\n' && char_read < n - 1) | |
3754 { | |
3755 c = fgetc(stream); | |
3756 s[char_read++] = c; | |
3757 /* If the file is in DOS format, we need to skip a NL after a CR. I | |
3758 * thought it was the other way around, but this appears to work... */ | |
3759 if (c == '\n') | |
3760 { | |
3761 c = fgetc(stream); | |
3762 if (c != '\r') | |
3763 ungetc(c, stream); | |
3764 } | |
3765 } | |
3766 | |
3767 s[char_read] = 0; | |
3768 if (char_read == 0) | |
3769 return NULL; | |
3770 | |
3771 if (feof(stream) && char_read == 1) | |
3772 return NULL; | |
3773 | |
3774 return s; | |
3775 } | |
3776 # endif | |
3777 #endif | |
3778 | |
3779 /* | |
3780 * Get one full line from a sourced file. | |
3781 * Called by do_cmdline() when it's called from do_source(). | |
3782 * | |
3783 * Return a pointer to the line in allocated memory. | |
3784 * Return NULL for end-of-file or some error. | |
3785 */ | |
3786 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3787 getsourceline(int c UNUSED, void *cookie, int indent UNUSED) |
7 | 3788 { |
3789 struct source_cookie *sp = (struct source_cookie *)cookie; | |
3790 char_u *line; | |
3336 | 3791 char_u *p; |
7 | 3792 |
3793 #ifdef FEAT_EVAL | |
3794 /* If breakpoints have been added/deleted need to check for it. */ | |
3795 if (sp->dbg_tick < debug_tick) | |
3796 { | |
3797 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum); | |
3798 sp->dbg_tick = debug_tick; | |
3799 } | |
170 | 3800 # ifdef FEAT_PROFILE |
790 | 3801 if (do_profiling == PROF_YES) |
170 | 3802 script_line_end(); |
3803 # endif | |
7 | 3804 #endif |
3805 /* | |
3806 * Get current line. If there is a read-ahead line, use it, otherwise get | |
3807 * one now. | |
3808 */ | |
3809 if (sp->finished) | |
3810 line = NULL; | |
3811 else if (sp->nextline == NULL) | |
3812 line = get_one_sourceline(sp); | |
3813 else | |
3814 { | |
3815 line = sp->nextline; | |
3816 sp->nextline = NULL; | |
3817 ++sourcing_lnum; | |
205 | 3818 } |
170 | 3819 #ifdef FEAT_PROFILE |
790 | 3820 if (line != NULL && do_profiling == PROF_YES) |
205 | 3821 script_line_start(); |
3822 #endif | |
7 | 3823 |
3824 /* Only concatenate lines starting with a \ when 'cpoptions' doesn't | |
3825 * contain the 'C' flag. */ | |
3826 if (line != NULL && (vim_strchr(p_cpo, CPO_CONCAT) == NULL)) | |
3827 { | |
3828 /* compensate for the one line read-ahead */ | |
3829 --sourcing_lnum; | |
3332 | 3830 |
3831 /* Get the next line and concatenate it when it starts with a | |
3832 * backslash. We always need to read the next line, keep it in | |
3833 * sp->nextline. */ | |
3834 sp->nextline = get_one_sourceline(sp); | |
3835 if (sp->nextline != NULL && *(p = skipwhite(sp->nextline)) == '\\') | |
7 | 3836 { |
3332 | 3837 garray_T ga; |
3838 | |
3378 | 3839 ga_init2(&ga, (int)sizeof(char_u), 400); |
3332 | 3840 ga_concat(&ga, line); |
3841 ga_concat(&ga, p + 1); | |
3842 for (;;) | |
3843 { | |
3844 vim_free(sp->nextline); | |
3845 sp->nextline = get_one_sourceline(sp); | |
3846 if (sp->nextline == NULL) | |
3847 break; | |
3848 p = skipwhite(sp->nextline); | |
3849 if (*p != '\\') | |
3850 break; | |
3378 | 3851 /* Adjust the growsize to the current length to speed up |
3852 * concatenating many lines. */ | |
3853 if (ga.ga_len > 400) | |
3854 { | |
3855 if (ga.ga_len > 8000) | |
3856 ga.ga_growsize = 8000; | |
3857 else | |
3858 ga.ga_growsize = ga.ga_len; | |
3859 } | |
3332 | 3860 ga_concat(&ga, p + 1); |
3861 } | |
3862 ga_append(&ga, NUL); | |
7 | 3863 vim_free(line); |
3332 | 3864 line = ga.ga_data; |
7 | 3865 } |
3866 } | |
3867 | |
3868 #ifdef FEAT_MBYTE | |
3869 if (line != NULL && sp->conv.vc_type != CONV_NONE) | |
3870 { | |
3336 | 3871 char_u *s; |
3872 | |
7 | 3873 /* Convert the encoding of the script line. */ |
3874 s = string_convert(&sp->conv, line, NULL); | |
3875 if (s != NULL) | |
3876 { | |
3877 vim_free(line); | |
3878 line = s; | |
3879 } | |
3880 } | |
3881 #endif | |
3882 | |
3883 #ifdef FEAT_EVAL | |
3884 /* Did we encounter a breakpoint? */ | |
3885 if (sp->breakpoint != 0 && sp->breakpoint <= sourcing_lnum) | |
3886 { | |
3887 dbg_breakpoint(sp->fname, sourcing_lnum); | |
3888 /* Find next breakpoint. */ | |
3889 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum); | |
3890 sp->dbg_tick = debug_tick; | |
3891 } | |
3892 #endif | |
3893 | |
3894 return line; | |
3895 } | |
3896 | |
3897 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3898 get_one_sourceline(struct source_cookie *sp) |
7 | 3899 { |
3900 garray_T ga; | |
3901 int len; | |
3902 int c; | |
3903 char_u *buf; | |
3904 #ifdef USE_CRNL | |
3905 int has_cr; /* CR-LF found */ | |
3906 #endif | |
3907 #ifdef USE_CR | |
3908 char_u *scan; | |
3909 #endif | |
3910 int have_read = FALSE; | |
3911 | |
3912 /* use a growarray to store the sourced line */ | |
154 | 3913 ga_init2(&ga, 1, 250); |
7 | 3914 |
3915 /* | |
3916 * Loop until there is a finished line (or end-of-file). | |
3917 */ | |
3918 sourcing_lnum++; | |
3919 for (;;) | |
3920 { | |
154 | 3921 /* make room to read at least 120 (more) characters */ |
3922 if (ga_grow(&ga, 120) == FAIL) | |
7 | 3923 break; |
3924 buf = (char_u *)ga.ga_data; | |
3925 | |
3926 #ifdef USE_CR | |
3927 if (sp->fileformat == EOL_MAC) | |
3928 { | |
41 | 3929 if (fgets_cr((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len, |
3930 sp->fp) == NULL) | |
7 | 3931 break; |
3932 } | |
3933 else | |
3934 #endif | |
41 | 3935 if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len, |
3936 sp->fp) == NULL) | |
7 | 3937 break; |
154 | 3938 len = ga.ga_len + (int)STRLEN(buf + ga.ga_len); |
7 | 3939 #ifdef USE_CRNL |
3940 /* Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the | |
3941 * CTRL-Z by its own, or after a NL. */ | |
3942 if ( (len == 1 || (len >= 2 && buf[len - 2] == '\n')) | |
3943 && sp->fileformat == EOL_DOS | |
3944 && buf[len - 1] == Ctrl_Z) | |
3945 { | |
3946 buf[len - 1] = NUL; | |
3947 break; | |
3948 } | |
3949 #endif | |
3950 | |
3951 #ifdef USE_CR | |
3952 /* If the read doesn't stop on a new line, and there's | |
3953 * some CR then we assume a Mac format */ | |
3954 if (sp->fileformat == EOL_UNKNOWN) | |
3955 { | |
3956 if (buf[len - 1] != '\n' && vim_strchr(buf, '\r') != NULL) | |
3957 sp->fileformat = EOL_MAC; | |
3958 else | |
3959 sp->fileformat = EOL_UNIX; | |
3960 } | |
3961 | |
3962 if (sp->fileformat == EOL_MAC) | |
3963 { | |
3964 scan = vim_strchr(buf, '\r'); | |
3965 | |
3966 if (scan != NULL) | |
3967 { | |
3968 *scan = '\n'; | |
3969 if (*(scan + 1) != 0) | |
3970 { | |
3971 *(scan + 1) = 0; | |
3972 fseek(sp->fp, (long)(scan - buf - len + 1), SEEK_CUR); | |
3973 } | |
3974 } | |
3975 len = STRLEN(buf); | |
3976 } | |
3977 #endif | |
3978 | |
3979 have_read = TRUE; | |
3980 ga.ga_len = len; | |
3981 | |
3982 /* If the line was longer than the buffer, read more. */ | |
41 | 3983 if (ga.ga_maxlen - ga.ga_len == 1 && buf[len - 1] != '\n') |
7 | 3984 continue; |
3985 | |
3986 if (len >= 1 && buf[len - 1] == '\n') /* remove trailing NL */ | |
3987 { | |
3988 #ifdef USE_CRNL | |
3989 has_cr = (len >= 2 && buf[len - 2] == '\r'); | |
3990 if (sp->fileformat == EOL_UNKNOWN) | |
3991 { | |
3992 if (has_cr) | |
3993 sp->fileformat = EOL_DOS; | |
3994 else | |
3995 sp->fileformat = EOL_UNIX; | |
3996 } | |
3997 | |
3998 if (sp->fileformat == EOL_DOS) | |
3999 { | |
4000 if (has_cr) /* replace trailing CR */ | |
4001 { | |
4002 buf[len - 2] = '\n'; | |
4003 --len; | |
4004 --ga.ga_len; | |
4005 } | |
4006 else /* lines like ":map xx yy^M" will have failed */ | |
4007 { | |
4008 if (!sp->error) | |
16 | 4009 { |
4010 msg_source(hl_attr(HLF_W)); | |
7 | 4011 EMSG(_("W15: Warning: Wrong line separator, ^M may be missing")); |
16 | 4012 } |
7 | 4013 sp->error = TRUE; |
4014 sp->fileformat = EOL_UNIX; | |
4015 } | |
4016 } | |
4017 #endif | |
4018 /* The '\n' is escaped if there is an odd number of ^V's just | |
4019 * before it, first set "c" just before the 'V's and then check | |
4020 * len&c parities (is faster than ((len-c)%2 == 0)) -- Acevedo */ | |
4021 for (c = len - 2; c >= 0 && buf[c] == Ctrl_V; c--) | |
4022 ; | |
4023 if ((len & 1) != (c & 1)) /* escaped NL, read more */ | |
4024 { | |
4025 sourcing_lnum++; | |
4026 continue; | |
4027 } | |
4028 | |
4029 buf[len - 1] = NUL; /* remove the NL */ | |
4030 } | |
4031 | |
4032 /* | |
4033 * Check for ^C here now and then, so recursive :so can be broken. | |
4034 */ | |
4035 line_breakcheck(); | |
4036 break; | |
4037 } | |
4038 | |
4039 if (have_read) | |
4040 return (char_u *)ga.ga_data; | |
4041 | |
4042 vim_free(ga.ga_data); | |
4043 return NULL; | |
4044 } | |
4045 | |
170 | 4046 #if defined(FEAT_PROFILE) || defined(PROTO) |
4047 /* | |
4048 * Called when starting to read a script line. | |
4049 * "sourcing_lnum" must be correct! | |
4050 * When skipping lines it may not actually be executed, but we won't find out | |
4051 * until later and we need to store the time now. | |
4052 */ | |
4053 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4054 script_line_start(void) |
170 | 4055 { |
4056 scriptitem_T *si; | |
4057 sn_prl_T *pp; | |
4058 | |
4059 if (current_SID <= 0 || current_SID > script_items.ga_len) | |
4060 return; | |
4061 si = &SCRIPT_ITEM(current_SID); | |
4062 if (si->sn_prof_on && sourcing_lnum >= 1) | |
4063 { | |
1624 | 4064 /* Grow the array before starting the timer, so that the time spent |
170 | 4065 * here isn't counted. */ |
7009 | 4066 (void)ga_grow(&si->sn_prl_ga, (int)(sourcing_lnum - si->sn_prl_ga.ga_len)); |
170 | 4067 si->sn_prl_idx = sourcing_lnum - 1; |
4068 while (si->sn_prl_ga.ga_len <= si->sn_prl_idx | |
4069 && si->sn_prl_ga.ga_len < si->sn_prl_ga.ga_maxlen) | |
4070 { | |
4071 /* Zero counters for a line that was not used before. */ | |
4072 pp = &PRL_ITEM(si, si->sn_prl_ga.ga_len); | |
4073 pp->snp_count = 0; | |
4074 profile_zero(&pp->sn_prl_total); | |
4075 profile_zero(&pp->sn_prl_self); | |
4076 ++si->sn_prl_ga.ga_len; | |
4077 } | |
4078 si->sn_prl_execed = FALSE; | |
4079 profile_start(&si->sn_prl_start); | |
4080 profile_zero(&si->sn_prl_children); | |
4081 profile_get_wait(&si->sn_prl_wait); | |
4082 } | |
4083 } | |
4084 | |
4085 /* | |
4086 * Called when actually executing a function line. | |
4087 */ | |
4088 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4089 script_line_exec(void) |
170 | 4090 { |
4091 scriptitem_T *si; | |
4092 | |
4093 if (current_SID <= 0 || current_SID > script_items.ga_len) | |
4094 return; | |
4095 si = &SCRIPT_ITEM(current_SID); | |
4096 if (si->sn_prof_on && si->sn_prl_idx >= 0) | |
4097 si->sn_prl_execed = TRUE; | |
4098 } | |
4099 | |
4100 /* | |
4101 * Called when done with a function line. | |
4102 */ | |
4103 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4104 script_line_end(void) |
170 | 4105 { |
4106 scriptitem_T *si; | |
4107 sn_prl_T *pp; | |
4108 | |
4109 if (current_SID <= 0 || current_SID > script_items.ga_len) | |
4110 return; | |
4111 si = &SCRIPT_ITEM(current_SID); | |
4112 if (si->sn_prof_on && si->sn_prl_idx >= 0 | |
4113 && si->sn_prl_idx < si->sn_prl_ga.ga_len) | |
4114 { | |
4115 if (si->sn_prl_execed) | |
4116 { | |
4117 pp = &PRL_ITEM(si, si->sn_prl_idx); | |
4118 ++pp->snp_count; | |
4119 profile_end(&si->sn_prl_start); | |
4120 profile_sub_wait(&si->sn_prl_wait, &si->sn_prl_start); | |
4121 profile_add(&pp->sn_prl_total, &si->sn_prl_start); | |
720 | 4122 profile_self(&pp->sn_prl_self, &si->sn_prl_start, |
4123 &si->sn_prl_children); | |
170 | 4124 } |
4125 si->sn_prl_idx = -1; | |
4126 } | |
4127 } | |
4128 #endif | |
4129 | |
7 | 4130 /* |
4131 * ":scriptencoding": Set encoding conversion for a sourced script. | |
4132 * Without the multi-byte feature it's simply ignored. | |
4133 */ | |
4134 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4135 ex_scriptencoding(exarg_T *eap UNUSED) |
7 | 4136 { |
4137 #ifdef FEAT_MBYTE | |
4138 struct source_cookie *sp; | |
4139 char_u *name; | |
4140 | |
4141 if (!getline_equal(eap->getline, eap->cookie, getsourceline)) | |
4142 { | |
4143 EMSG(_("E167: :scriptencoding used outside of a sourced file")); | |
4144 return; | |
4145 } | |
4146 | |
4147 if (*eap->arg != NUL) | |
4148 { | |
4149 name = enc_canonize(eap->arg); | |
4150 if (name == NULL) /* out of memory */ | |
4151 return; | |
4152 } | |
4153 else | |
4154 name = eap->arg; | |
4155 | |
4156 /* Setup for conversion from the specified encoding to 'encoding'. */ | |
4157 sp = (struct source_cookie *)getline_cookie(eap->getline, eap->cookie); | |
4158 convert_setup(&sp->conv, name, p_enc); | |
4159 | |
4160 if (name != eap->arg) | |
4161 vim_free(name); | |
4162 #endif | |
4163 } | |
4164 | |
4165 #if defined(FEAT_EVAL) || defined(PROTO) | |
4166 /* | |
4167 * ":finish": Mark a sourced file as finished. | |
4168 */ | |
4169 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4170 ex_finish(exarg_T *eap) |
7 | 4171 { |
4172 if (getline_equal(eap->getline, eap->cookie, getsourceline)) | |
4173 do_finish(eap, FALSE); | |
4174 else | |
4175 EMSG(_("E168: :finish used outside of a sourced file")); | |
4176 } | |
4177 | |
4178 /* | |
4179 * Mark a sourced file as finished. Possibly makes the ":finish" pending. | |
4180 * Also called for a pending finish at the ":endtry" or after returning from | |
4181 * an extra do_cmdline(). "reanimate" is used in the latter case. | |
4182 */ | |
4183 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4184 do_finish(exarg_T *eap, int reanimate) |
7 | 4185 { |
4186 int idx; | |
4187 | |
4188 if (reanimate) | |
4189 ((struct source_cookie *)getline_cookie(eap->getline, | |
4190 eap->cookie))->finished = FALSE; | |
4191 | |
4192 /* | |
4193 * Cleanup (and inactivate) conditionals, but stop when a try conditional | |
4194 * not in its finally clause (which then is to be executed next) is found. | |
4195 * In this case, make the ":finish" pending for execution at the ":endtry". | |
4196 * Otherwise, finish normally. | |
4197 */ | |
4198 idx = cleanup_conditionals(eap->cstack, 0, TRUE); | |
4199 if (idx >= 0) | |
4200 { | |
4201 eap->cstack->cs_pending[idx] = CSTP_FINISH; | |
4202 report_make_pending(CSTP_FINISH, NULL); | |
4203 } | |
4204 else | |
4205 ((struct source_cookie *)getline_cookie(eap->getline, | |
4206 eap->cookie))->finished = TRUE; | |
4207 } | |
4208 | |
4209 | |
4210 /* | |
4211 * Return TRUE when a sourced file had the ":finish" command: Don't give error | |
4212 * message for missing ":endif". | |
4213 * Return FALSE when not sourcing a file. | |
4214 */ | |
4215 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4216 source_finished( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4217 char_u *(*fgetline)(int, void *, int), |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4218 void *cookie) |
7 | 4219 { |
944 | 4220 return (getline_equal(fgetline, cookie, getsourceline) |
7 | 4221 && ((struct source_cookie *)getline_cookie( |
944 | 4222 fgetline, cookie))->finished); |
7 | 4223 } |
4224 #endif | |
4225 | |
4226 #if defined(FEAT_LISTCMDS) || defined(PROTO) | |
4227 /* | |
4228 * ":checktime [buffer]" | |
4229 */ | |
4230 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4231 ex_checktime(exarg_T *eap) |
7 | 4232 { |
4233 buf_T *buf; | |
4234 int save_no_check_timestamps = no_check_timestamps; | |
4235 | |
4236 no_check_timestamps = 0; | |
4237 if (eap->addr_count == 0) /* default is all buffers */ | |
4238 check_timestamps(FALSE); | |
4239 else | |
4240 { | |
4241 buf = buflist_findnr((int)eap->line2); | |
4242 if (buf != NULL) /* cannot happen? */ | |
4243 (void)buf_check_timestamp(buf, FALSE); | |
4244 } | |
4245 no_check_timestamps = save_no_check_timestamps; | |
4246 } | |
4247 #endif | |
4248 | |
4249 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ | |
4250 && (defined(FEAT_EVAL) || defined(FEAT_MULTI_LANG)) | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4251 # define HAVE_GET_LOCALE_VAL |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4252 static char_u *get_locale_val(int what); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4253 |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4254 static char_u * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4255 get_locale_val(int what) |
7 | 4256 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4257 char_u *loc; |
7 | 4258 |
4259 /* Obtain the locale value from the libraries. For DJGPP this is | |
4260 * redefined and it doesn't use the arguments. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4261 loc = (char_u *)setlocale(what, NULL); |
7 | 4262 |
823 | 4263 # ifdef WIN32 |
7 | 4264 if (loc != NULL) |
4265 { | |
4266 char_u *p; | |
4267 | |
823 | 4268 /* setocale() returns something like "LC_COLLATE=<name>;LC_..." when |
4269 * one of the values (e.g., LC_CTYPE) differs. */ | |
7 | 4270 p = vim_strchr(loc, '='); |
4271 if (p != NULL) | |
4272 { | |
4273 loc = ++p; | |
4274 while (*p != NUL) /* remove trailing newline */ | |
4275 { | |
823 | 4276 if (*p < ' ' || *p == ';') |
7 | 4277 { |
4278 *p = NUL; | |
4279 break; | |
4280 } | |
4281 ++p; | |
4282 } | |
4283 } | |
4284 } | |
4285 # endif | |
4286 | |
4287 return loc; | |
4288 } | |
4289 #endif | |
4290 | |
4291 | |
4292 #ifdef WIN32 | |
4293 /* | |
4294 * On MS-Windows locale names are strings like "German_Germany.1252", but | |
4295 * gettext expects "de". Try to translate one into another here for a few | |
4296 * supported languages. | |
4297 */ | |
4298 static char_u * | |
4299 gettext_lang(char_u *name) | |
4300 { | |
4301 int i; | |
4302 static char *(mtable[]) = { | |
4303 "afrikaans", "af", | |
4304 "czech", "cs", | |
4305 "dutch", "nl", | |
4306 "german", "de", | |
4307 "english_united kingdom", "en_GB", | |
4308 "spanish", "es", | |
4309 "french", "fr", | |
4310 "italian", "it", | |
4311 "japanese", "ja", | |
4312 "korean", "ko", | |
4313 "norwegian", "no", | |
4314 "polish", "pl", | |
4315 "russian", "ru", | |
4316 "slovak", "sk", | |
4317 "swedish", "sv", | |
4318 "ukrainian", "uk", | |
4319 "chinese_china", "zh_CN", | |
4320 "chinese_taiwan", "zh_TW", | |
4321 NULL}; | |
4322 | |
4323 for (i = 0; mtable[i] != NULL; i += 2) | |
4324 if (STRNICMP(mtable[i], name, STRLEN(mtable[i])) == 0) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4325 return (char_u *)mtable[i + 1]; |
7 | 4326 return name; |
4327 } | |
4328 #endif | |
4329 | |
4330 #if defined(FEAT_MULTI_LANG) || defined(PROTO) | |
4331 /* | |
4332 * Obtain the current messages language. Used to set the default for | |
4333 * 'helplang'. May return NULL or an empty string. | |
4334 */ | |
4335 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4336 get_mess_lang(void) |
7 | 4337 { |
4338 char_u *p; | |
4339 | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4340 # ifdef HAVE_GET_LOCALE_VAL |
7 | 4341 # if defined(LC_MESSAGES) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4342 p = get_locale_val(LC_MESSAGES); |
7 | 4343 # else |
4344 /* This is necessary for Win32, where LC_MESSAGES is not defined and $LANG | |
823 | 4345 * may be set to the LCID number. LC_COLLATE is the best guess, LC_TIME |
4346 * and LC_MONETARY may be set differently for a Japanese working in the | |
4347 * US. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4348 p = get_locale_val(LC_COLLATE); |
7 | 4349 # endif |
4350 # else | |
4351 p = mch_getenv((char_u *)"LC_ALL"); | |
4352 if (p == NULL || *p == NUL) | |
4353 { | |
4354 p = mch_getenv((char_u *)"LC_MESSAGES"); | |
4355 if (p == NULL || *p == NUL) | |
4356 p = mch_getenv((char_u *)"LANG"); | |
4357 } | |
4358 # endif | |
4359 # ifdef WIN32 | |
4360 p = gettext_lang(p); | |
4361 # endif | |
4362 return p; | |
4363 } | |
4364 #endif | |
4365 | |
45 | 4366 /* Complicated #if; matches with where get_mess_env() is used below. */ |
4367 #if (defined(FEAT_EVAL) && !((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ | |
4368 && defined(LC_MESSAGES))) \ | |
4369 || ((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ | |
4370 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) \ | |
4371 && !defined(LC_MESSAGES)) | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
4372 static char_u *get_mess_env(void); |
7 | 4373 |
4374 /* | |
4375 * Get the language used for messages from the environment. | |
4376 */ | |
4377 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4378 get_mess_env(void) |
7 | 4379 { |
4380 char_u *p; | |
4381 | |
4382 p = mch_getenv((char_u *)"LC_ALL"); | |
4383 if (p == NULL || *p == NUL) | |
4384 { | |
4385 p = mch_getenv((char_u *)"LC_MESSAGES"); | |
4386 if (p == NULL || *p == NUL) | |
4387 { | |
4388 p = mch_getenv((char_u *)"LANG"); | |
4389 if (p != NULL && VIM_ISDIGIT(*p)) | |
4390 p = NULL; /* ignore something like "1043" */ | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4391 # ifdef HAVE_GET_LOCALE_VAL |
7 | 4392 if (p == NULL || *p == NUL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4393 p = get_locale_val(LC_CTYPE); |
7 | 4394 # endif |
4395 } | |
4396 } | |
4397 return p; | |
4398 } | |
4399 #endif | |
4400 | |
4401 #if defined(FEAT_EVAL) || defined(PROTO) | |
4402 | |
4403 /* | |
4404 * Set the "v:lang" variable according to the current locale setting. | |
4405 * Also do "v:lc_time"and "v:ctype". | |
4406 */ | |
4407 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4408 set_lang_var(void) |
7 | 4409 { |
4410 char_u *loc; | |
4411 | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4412 # ifdef HAVE_GET_LOCALE_VAL |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4413 loc = get_locale_val(LC_CTYPE); |
7 | 4414 # else |
4415 /* setlocale() not supported: use the default value */ | |
4416 loc = (char_u *)"C"; | |
4417 # endif | |
4418 set_vim_var_string(VV_CTYPE, loc, -1); | |
4419 | |
4420 /* When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall | |
4421 * back to LC_CTYPE if it's empty. */ | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4422 # if defined(HAVE_GET_LOCALE_VAL) && defined(LC_MESSAGES) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4423 loc = get_locale_val(LC_MESSAGES); |
7 | 4424 # else |
4425 loc = get_mess_env(); | |
4426 # endif | |
4427 set_vim_var_string(VV_LANG, loc, -1); | |
4428 | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4429 # ifdef HAVE_GET_LOCALE_VAL |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4430 loc = get_locale_val(LC_TIME); |
7 | 4431 # endif |
4432 set_vim_var_string(VV_LC_TIME, loc, -1); | |
4433 } | |
4434 #endif | |
4435 | |
4436 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ | |
4437 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
4438 /* | |
4439 * ":language": Set the language (locale). | |
4440 */ | |
4441 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4442 ex_language(exarg_T *eap) |
7 | 4443 { |
4444 char *loc; | |
4445 char_u *p; | |
4446 char_u *name; | |
4447 int what = LC_ALL; | |
4448 char *whatstr = ""; | |
4449 #ifdef LC_MESSAGES | |
4450 # define VIM_LC_MESSAGES LC_MESSAGES | |
4451 #else | |
4452 # define VIM_LC_MESSAGES 6789 | |
4453 #endif | |
4454 | |
4455 name = eap->arg; | |
4456 | |
4457 /* Check for "messages {name}", "ctype {name}" or "time {name}" argument. | |
4458 * Allow abbreviation, but require at least 3 characters to avoid | |
4459 * confusion with a two letter language name "me" or "ct". */ | |
4460 p = skiptowhite(eap->arg); | |
4461 if ((*p == NUL || vim_iswhite(*p)) && p - eap->arg >= 3) | |
4462 { | |
4463 if (STRNICMP(eap->arg, "messages", p - eap->arg) == 0) | |
4464 { | |
4465 what = VIM_LC_MESSAGES; | |
4466 name = skipwhite(p); | |
4467 whatstr = "messages "; | |
4468 } | |
4469 else if (STRNICMP(eap->arg, "ctype", p - eap->arg) == 0) | |
4470 { | |
4471 what = LC_CTYPE; | |
4472 name = skipwhite(p); | |
4473 whatstr = "ctype "; | |
4474 } | |
4475 else if (STRNICMP(eap->arg, "time", p - eap->arg) == 0) | |
4476 { | |
4477 what = LC_TIME; | |
4478 name = skipwhite(p); | |
4479 whatstr = "time "; | |
4480 } | |
4481 } | |
4482 | |
4483 if (*name == NUL) | |
4484 { | |
4485 #ifndef LC_MESSAGES | |
4486 if (what == VIM_LC_MESSAGES) | |
4487 p = get_mess_env(); | |
4488 else | |
4489 #endif | |
4490 p = (char_u *)setlocale(what, NULL); | |
4491 if (p == NULL || *p == NUL) | |
4492 p = (char_u *)"Unknown"; | |
4493 smsg((char_u *)_("Current %slanguage: \"%s\""), whatstr, p); | |
4494 } | |
4495 else | |
4496 { | |
4497 #ifndef LC_MESSAGES | |
4498 if (what == VIM_LC_MESSAGES) | |
4499 loc = ""; | |
4500 else | |
4501 #endif | |
1624 | 4502 { |
7 | 4503 loc = setlocale(what, (char *)name); |
1624 | 4504 #if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
4505 /* Make sure strtod() uses a decimal point, not a comma. */ | |
4506 setlocale(LC_NUMERIC, "C"); | |
4507 #endif | |
4508 } | |
7 | 4509 if (loc == NULL) |
4510 EMSG2(_("E197: Cannot set language to \"%s\""), name); | |
4511 else | |
4512 { | |
4513 #ifdef HAVE_NL_MSG_CAT_CNTR | |
4514 /* Need to do this for GNU gettext, otherwise cached translations | |
4515 * will be used again. */ | |
4516 extern int _nl_msg_cat_cntr; | |
4517 | |
4518 ++_nl_msg_cat_cntr; | |
4519 #endif | |
1222 | 4520 /* Reset $LC_ALL, otherwise it would overrule everything. */ |
7 | 4521 vim_setenv((char_u *)"LC_ALL", (char_u *)""); |
4522 | |
4523 if (what != LC_TIME) | |
4524 { | |
4525 /* Tell gettext() what to translate to. It apparently doesn't | |
4526 * use the currently effective locale. Also do this when | |
4527 * FEAT_GETTEXT isn't defined, so that shell commands use this | |
4528 * value. */ | |
4529 if (what == LC_ALL) | |
534 | 4530 { |
7 | 4531 vim_setenv((char_u *)"LANG", name); |
5027
5751284311f3
updated for version 7.3.1257
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
4532 |
5751284311f3
updated for version 7.3.1257
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
4533 /* Clear $LANGUAGE because GNU gettext uses it. */ |
5751284311f3
updated for version 7.3.1257
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
4534 vim_setenv((char_u *)"LANGUAGE", (char_u *)""); |
534 | 4535 # ifdef WIN32 |
4536 /* Apparently MS-Windows printf() may cause a crash when | |
4537 * we give it 8-bit text while it's expecting text in the | |
4538 * current locale. This call avoids that. */ | |
4539 setlocale(LC_CTYPE, "C"); | |
4540 # endif | |
4541 } | |
7 | 4542 if (what != LC_CTYPE) |
4543 { | |
4544 char_u *mname; | |
4545 #ifdef WIN32 | |
4546 mname = gettext_lang(name); | |
4547 #else | |
4548 mname = name; | |
4549 #endif | |
4550 vim_setenv((char_u *)"LC_MESSAGES", mname); | |
4551 #ifdef FEAT_MULTI_LANG | |
4552 set_helplang_default(mname); | |
4553 #endif | |
4554 } | |
4555 } | |
4556 | |
4557 # ifdef FEAT_EVAL | |
4558 /* Set v:lang, v:lc_time and v:ctype to the final result. */ | |
4559 set_lang_var(); | |
4560 # endif | |
3149 | 4561 # ifdef FEAT_TITLE |
4562 maketitle(); | |
4563 # endif | |
7 | 4564 } |
4565 } | |
4566 } | |
4567 | |
4568 # if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
2849 | 4569 |
4570 static char_u **locales = NULL; /* Array of all available locales */ | |
4571 static int did_init_locales = FALSE; | |
4572 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
4573 static void init_locales(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
4574 static char_u **find_locales(void); |
2849 | 4575 |
4576 /* | |
4577 * Lazy initialization of all available locales. | |
4578 */ | |
4579 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4580 init_locales(void) |
2849 | 4581 { |
4582 if (!did_init_locales) | |
4583 { | |
4584 did_init_locales = TRUE; | |
4585 locales = find_locales(); | |
4586 } | |
4587 } | |
4588 | |
4589 /* Return an array of strings for all available locales + NULL for the | |
4590 * last element. Return NULL in case of error. */ | |
4591 static char_u ** | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4592 find_locales(void) |
2849 | 4593 { |
4594 garray_T locales_ga; | |
4595 char_u *loc; | |
4596 | |
4597 /* Find all available locales by running command "locale -a". If this | |
4598 * doesn't work we won't have completion. */ | |
4599 char_u *locale_a = get_cmd_output((char_u *)"locale -a", | |
5808 | 4600 NULL, SHELL_SILENT, NULL); |
2849 | 4601 if (locale_a == NULL) |
4602 return NULL; | |
4603 ga_init2(&locales_ga, sizeof(char_u *), 20); | |
4604 | |
4605 /* Transform locale_a string where each locale is separated by "\n" | |
4606 * into an array of locale strings. */ | |
4607 loc = (char_u *)strtok((char *)locale_a, "\n"); | |
4608 | |
4609 while (loc != NULL) | |
4610 { | |
4611 if (ga_grow(&locales_ga, 1) == FAIL) | |
4612 break; | |
4613 loc = vim_strsave(loc); | |
4614 if (loc == NULL) | |
4615 break; | |
4616 | |
4617 ((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] = loc; | |
4618 loc = (char_u *)strtok(NULL, "\n"); | |
4619 } | |
4620 vim_free(locale_a); | |
4621 if (ga_grow(&locales_ga, 1) == FAIL) | |
4622 { | |
4623 ga_clear(&locales_ga); | |
4624 return NULL; | |
4625 } | |
4626 ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; | |
4627 return (char_u **)locales_ga.ga_data; | |
4628 } | |
4629 | |
4630 # if defined(EXITFREE) || defined(PROTO) | |
4631 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4632 free_locales(void) |
2849 | 4633 { |
4634 int i; | |
4635 if (locales != NULL) | |
4636 { | |
4637 for (i = 0; locales[i] != NULL; i++) | |
4638 vim_free(locales[i]); | |
4639 vim_free(locales); | |
4640 locales = NULL; | |
4641 } | |
4642 } | |
4643 # endif | |
4644 | |
7 | 4645 /* |
4646 * Function given to ExpandGeneric() to obtain the possible arguments of the | |
4647 * ":language" command. | |
4648 */ | |
4649 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4650 get_lang_arg(expand_T *xp UNUSED, int idx) |
7 | 4651 { |
4652 if (idx == 0) | |
4653 return (char_u *)"messages"; | |
4654 if (idx == 1) | |
4655 return (char_u *)"ctype"; | |
4656 if (idx == 2) | |
4657 return (char_u *)"time"; | |
2849 | 4658 |
4659 init_locales(); | |
4660 if (locales == NULL) | |
4661 return NULL; | |
4662 return locales[idx - 3]; | |
4663 } | |
4664 | |
4665 /* | |
4666 * Function given to ExpandGeneric() to obtain the available locales. | |
4667 */ | |
4668 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4669 get_locales(expand_T *xp UNUSED, int idx) |
2849 | 4670 { |
4671 init_locales(); | |
4672 if (locales == NULL) | |
4673 return NULL; | |
4674 return locales[idx]; | |
7 | 4675 } |
4676 # endif | |
4677 | |
4678 #endif |