Mercurial > vim
annotate src/ex_cmds2.c @ 7887:a98b93736894 v7.4.1240
commit https://github.com/vim/vim/commit/bc073092254df17b282d162d8e8181e8f6a7a356
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Feb 2 18:50:45 2016 +0100
patch 7.4.1240
Problem: Visual studio tools are noisy.
Solution: Suppress startup info. (Mike Williams)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 02 Feb 2016 19:00:06 +0100 |
parents | 226ed297307f |
children | 22367b9f528a |
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 | |
1013 /* | |
1496 | 1014 * Put the time "msec" past now in "tm". |
794 | 1015 */ |
1496 | 1016 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1017 profile_setlimit(long msec, proftime_T *tm) |
1496 | 1018 { |
1019 if (msec <= 0) /* no limit */ | |
1020 profile_zero(tm); | |
1021 else | |
1022 { | |
1023 # ifdef WIN3264 | |
1024 LARGE_INTEGER fr; | |
1025 | |
1026 QueryPerformanceCounter(tm); | |
1027 QueryPerformanceFrequency(&fr); | |
1517 | 1028 tm->QuadPart += (LONGLONG)((double)msec / 1000.0 * (double)fr.QuadPart); |
1496 | 1029 # else |
1030 long usec; | |
1031 | |
1032 gettimeofday(tm, NULL); | |
1033 usec = (long)tm->tv_usec + (long)msec * 1000; | |
1034 tm->tv_usec = usec % 1000000L; | |
1035 tm->tv_sec += usec / 1000000L; | |
1036 # endif | |
1037 } | |
1038 } | |
1039 | |
1040 /* | |
1041 * Return TRUE if the current time is past "tm". | |
1042 */ | |
1043 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1044 profile_passed_limit(proftime_T *tm) |
1496 | 1045 { |
1046 proftime_T now; | |
1047 | |
1048 # ifdef WIN3264 | |
1049 if (tm->QuadPart == 0) /* timer was not set */ | |
1050 return FALSE; | |
1051 QueryPerformanceCounter(&now); | |
1052 return (now.QuadPart > tm->QuadPart); | |
1053 # else | |
1054 if (tm->tv_sec == 0) /* timer was not set */ | |
1055 return FALSE; | |
1056 gettimeofday(&now, NULL); | |
1057 return (now.tv_sec > tm->tv_sec | |
1058 || (now.tv_sec == tm->tv_sec && now.tv_usec > tm->tv_usec)); | |
1059 # endif | |
1060 } | |
794 | 1061 |
1062 /* | |
1063 * Set the time in "tm" to zero. | |
1064 */ | |
1065 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1066 profile_zero(proftime_T *tm) |
794 | 1067 { |
1068 # ifdef WIN3264 | |
1069 tm->QuadPart = 0; | |
1070 # else | |
1071 tm->tv_usec = 0; | |
1072 tm->tv_sec = 0; | |
1073 # endif | |
1074 } | |
1075 | |
1496 | 1076 # endif /* FEAT_PROFILE || FEAT_RELTIME */ |
1077 | |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1078 #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
|
1079 # if defined(HAVE_MATH_H) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1080 # include <math.h> |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1081 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1082 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1083 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1084 * 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
|
1085 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1086 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1087 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
|
1088 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1089 if (count == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1090 profile_zero(tm2); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1091 else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1092 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1093 # ifdef WIN3264 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1094 tm2->QuadPart = tm->QuadPart / count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1095 # else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1096 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
|
1097 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1098 tm2->tv_sec = floor(usec / 1000000.0); |
4825
208a6c04e6b8
updated for version 7.3.1159
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1099 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
|
1100 # endif |
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 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1103 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
1104 |
1496 | 1105 # if defined(FEAT_PROFILE) || defined(PROTO) |
1106 /* | |
1107 * Functions for profiling. | |
1108 */ | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
1109 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
|
1110 static void script_dump_profile(FILE *fd); |
1496 | 1111 static proftime_T prof_wait_time; |
1112 | |
794 | 1113 /* |
170 | 1114 * Add the time "tm2" to "tm". |
1115 */ | |
1116 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1117 profile_add(proftime_T *tm, proftime_T *tm2) |
170 | 1118 { |
177 | 1119 # ifdef WIN3264 |
1120 tm->QuadPart += tm2->QuadPart; | |
1121 # else | |
170 | 1122 tm->tv_usec += tm2->tv_usec; |
1123 tm->tv_sec += tm2->tv_sec; | |
1124 if (tm->tv_usec >= 1000000) | |
1125 { | |
1126 tm->tv_usec -= 1000000; | |
1127 ++tm->tv_sec; | |
1128 } | |
177 | 1129 # endif |
170 | 1130 } |
1131 | |
1132 /* | |
720 | 1133 * Add the "self" time from the total time and the children's time. |
1134 */ | |
1135 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1136 profile_self(proftime_T *self, proftime_T *total, proftime_T *children) |
720 | 1137 { |
1138 /* Check that the result won't be negative. Can happen with recursive | |
1139 * calls. */ | |
1140 #ifdef WIN3264 | |
1141 if (total->QuadPart <= children->QuadPart) | |
1142 return; | |
1143 #else | |
1144 if (total->tv_sec < children->tv_sec | |
1145 || (total->tv_sec == children->tv_sec | |
1146 && total->tv_usec <= children->tv_usec)) | |
1147 return; | |
1148 #endif | |
1149 profile_add(self, total); | |
1150 profile_sub(self, children); | |
1151 } | |
1152 | |
1153 /* | |
170 | 1154 * Get the current waittime. |
1155 */ | |
1156 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1157 profile_get_wait(proftime_T *tm) |
170 | 1158 { |
1159 *tm = prof_wait_time; | |
1160 } | |
1161 | |
1162 /* | |
1163 * Subtract the passed waittime since "tm" from "tma". | |
1164 */ | |
1165 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1166 profile_sub_wait(proftime_T *tm, proftime_T *tma) |
170 | 1167 { |
1168 proftime_T tm3 = prof_wait_time; | |
1169 | |
1170 profile_sub(&tm3, tm); | |
1171 profile_sub(tma, &tm3); | |
1172 } | |
1173 | |
1174 /* | |
1175 * Return TRUE if "tm1" and "tm2" are equal. | |
1176 */ | |
1177 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1178 profile_equal(proftime_T *tm1, proftime_T *tm2) |
170 | 1179 { |
177 | 1180 # ifdef WIN3264 |
1181 return (tm1->QuadPart == tm2->QuadPart); | |
1182 # else | |
170 | 1183 return (tm1->tv_usec == tm2->tv_usec && tm1->tv_sec == tm2->tv_sec); |
177 | 1184 # endif |
1185 } | |
1186 | |
1187 /* | |
1188 * Return <0, 0 or >0 if "tm1" < "tm2", "tm1" == "tm2" or "tm1" > "tm2" | |
1189 */ | |
1190 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1191 profile_cmp(const proftime_T *tm1, const proftime_T *tm2) |
177 | 1192 { |
1193 # ifdef WIN3264 | |
1194 return (int)(tm2->QuadPart - tm1->QuadPart); | |
1195 # else | |
1196 if (tm1->tv_sec == tm2->tv_sec) | |
1197 return tm2->tv_usec - tm1->tv_usec; | |
1198 return tm2->tv_sec - tm1->tv_sec; | |
1199 # endif | |
170 | 1200 } |
1201 | |
1202 static char_u *profile_fname = NULL; | |
790 | 1203 static proftime_T pause_time; |
170 | 1204 |
1205 /* | |
1206 * ":profile cmd args" | |
1207 */ | |
1208 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1209 ex_profile(exarg_T *eap) |
170 | 1210 { |
1211 char_u *e; | |
1212 int len; | |
1213 | |
1214 e = skiptowhite(eap->arg); | |
835 | 1215 len = (int)(e - eap->arg); |
170 | 1216 e = skipwhite(e); |
1217 | |
1218 if (len == 5 && STRNCMP(eap->arg, "start", 5) == 0 && *e != NUL) | |
1219 { | |
1220 vim_free(profile_fname); | |
6749 | 1221 profile_fname = expand_env_save_opt(e, TRUE); |
790 | 1222 do_profiling = PROF_YES; |
170 | 1223 profile_zero(&prof_wait_time); |
1224 set_vim_var_nr(VV_PROFILING, 1L); | |
1225 } | |
790 | 1226 else if (do_profiling == PROF_NONE) |
2085
5a84b6388a55
updated for version 7.2.369
Bram Moolenaar <bram@zimbu.org>
parents:
2068
diff
changeset
|
1227 EMSG(_("E750: First use \":profile start {fname}\"")); |
790 | 1228 else if (STRCMP(eap->arg, "pause") == 0) |
1229 { | |
1230 if (do_profiling == PROF_YES) | |
1231 profile_start(&pause_time); | |
1232 do_profiling = PROF_PAUSED; | |
1233 } | |
1234 else if (STRCMP(eap->arg, "continue") == 0) | |
1235 { | |
1236 if (do_profiling == PROF_PAUSED) | |
1237 { | |
1238 profile_end(&pause_time); | |
1239 profile_add(&prof_wait_time, &pause_time); | |
1240 } | |
1241 do_profiling = PROF_YES; | |
1242 } | |
170 | 1243 else |
1244 { | |
1245 /* The rest is similar to ":breakadd". */ | |
1246 ex_breakadd(eap); | |
1247 } | |
1248 } | |
1249 | |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1250 /* Command line expansion for :profile. */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1251 static enum |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1252 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1253 PEXP_SUBCMD, /* expand :profile sub-commands */ |
2711 | 1254 PEXP_FUNC /* expand :profile func {funcname} */ |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1255 } pexpand_what; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1256 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1257 static char *pexpand_cmds[] = { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1258 "start", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1259 #define PROFCMD_START 0 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1260 "pause", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1261 #define PROFCMD_PAUSE 1 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1262 "continue", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1263 #define PROFCMD_CONTINUE 2 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1264 "func", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1265 #define PROFCMD_FUNC 3 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1266 "file", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1267 #define PROFCMD_FILE 4 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1268 NULL |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1269 #define PROFCMD_LAST 5 |
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 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1272 /* |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1273 * 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
|
1274 * specific expansion. |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1275 */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1276 char_u * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1277 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
|
1278 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1279 switch (pexpand_what) |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1280 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1281 case PEXP_SUBCMD: |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1282 return (char_u *)pexpand_cmds[idx]; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1283 /* case PEXP_FUNC: TODO */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1284 default: |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1285 return NULL; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1286 } |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1287 } |
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 * Handle command line completion for :profile command. |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1291 */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1292 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1293 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
|
1294 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1295 char_u *end_subcmd; |
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 /* Default: expand subcommands. */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1298 xp->xp_context = EXPAND_PROFILE; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1299 pexpand_what = PEXP_SUBCMD; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1300 xp->xp_pattern = arg; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1301 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1302 end_subcmd = skiptowhite(arg); |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1303 if (*end_subcmd == NUL) |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1304 return; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1305 |
2100
7d121c69f540
updated for version 7.2.383
Bram Moolenaar <bram@zimbu.org>
parents:
2085
diff
changeset
|
1306 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
|
1307 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1308 xp->xp_context = EXPAND_FILES; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1309 xp->xp_pattern = skipwhite(end_subcmd); |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1310 return; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1311 } |
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 /* TODO: expand function names after "func" */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1314 xp->xp_context = EXPAND_NOTHING; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1315 } |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
1316 |
170 | 1317 /* |
1318 * Dump the profiling info. | |
1319 */ | |
1320 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1321 profile_dump(void) |
170 | 1322 { |
1323 FILE *fd; | |
1324 | |
1325 if (profile_fname != NULL) | |
1326 { | |
531 | 1327 fd = mch_fopen((char *)profile_fname, "w"); |
170 | 1328 if (fd == NULL) |
1329 EMSG2(_(e_notopen), profile_fname); | |
1330 else | |
1331 { | |
177 | 1332 script_dump_profile(fd); |
170 | 1333 func_dump_profile(fd); |
1334 fclose(fd); | |
1335 } | |
1336 } | |
1337 } | |
1338 | |
1339 /* | |
1340 * Start profiling script "fp". | |
1341 */ | |
1342 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1343 script_do_profile(scriptitem_T *si) |
170 | 1344 { |
1345 si->sn_pr_count = 0; | |
1346 profile_zero(&si->sn_pr_total); | |
1347 profile_zero(&si->sn_pr_self); | |
1348 | |
1349 ga_init2(&si->sn_prl_ga, sizeof(sn_prl_T), 100); | |
1350 si->sn_prl_idx = -1; | |
1351 si->sn_prof_on = TRUE; | |
1352 si->sn_pr_nest = 0; | |
1353 } | |
1354 | |
1355 /* | |
1356 * save time when starting to invoke another script or function. | |
1357 */ | |
1358 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1359 script_prof_save( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1360 proftime_T *tm) /* place to store wait time */ |
170 | 1361 { |
1362 scriptitem_T *si; | |
1363 | |
1364 if (current_SID > 0 && current_SID <= script_items.ga_len) | |
1365 { | |
1366 si = &SCRIPT_ITEM(current_SID); | |
1367 if (si->sn_prof_on && si->sn_pr_nest++ == 0) | |
1368 profile_start(&si->sn_pr_child); | |
1369 } | |
1370 profile_get_wait(tm); | |
1371 } | |
1372 | |
1373 /* | |
1374 * Count time spent in children after invoking 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_restore(proftime_T *tm) |
170 | 1378 { |
1379 scriptitem_T *si; | |
1380 | |
1381 if (current_SID > 0 && current_SID <= script_items.ga_len) | |
1382 { | |
1383 si = &SCRIPT_ITEM(current_SID); | |
1384 if (si->sn_prof_on && --si->sn_pr_nest == 0) | |
1385 { | |
1386 profile_end(&si->sn_pr_child); | |
1387 profile_sub_wait(tm, &si->sn_pr_child); /* don't count wait time */ | |
1388 profile_add(&si->sn_pr_children, &si->sn_pr_child); | |
1389 profile_add(&si->sn_prl_children, &si->sn_pr_child); | |
1390 } | |
1391 } | |
1392 } | |
1393 | |
1394 static proftime_T inchar_time; | |
1395 | |
1396 /* | |
1397 * Called when starting to wait for the user to type a character. | |
1398 */ | |
1399 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1400 prof_inchar_enter(void) |
170 | 1401 { |
1402 profile_start(&inchar_time); | |
1403 } | |
1404 | |
1405 /* | |
1406 * Called when finished waiting for the user to type a character. | |
1407 */ | |
1408 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1409 prof_inchar_exit(void) |
170 | 1410 { |
1411 profile_end(&inchar_time); | |
1412 profile_add(&prof_wait_time, &inchar_time); | |
1413 } | |
1414 | |
1415 /* | |
1416 * Dump the profiling results for all scripts in file "fd". | |
1417 */ | |
1418 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1419 script_dump_profile(FILE *fd) |
170 | 1420 { |
1421 int id; | |
1422 scriptitem_T *si; | |
1423 int i; | |
1424 FILE *sfd; | |
1425 sn_prl_T *pp; | |
1426 | |
1427 for (id = 1; id <= script_items.ga_len; ++id) | |
1428 { | |
1429 si = &SCRIPT_ITEM(id); | |
1430 if (si->sn_prof_on) | |
1431 { | |
1432 fprintf(fd, "SCRIPT %s\n", si->sn_name); | |
1433 if (si->sn_pr_count == 1) | |
1434 fprintf(fd, "Sourced 1 time\n"); | |
1435 else | |
1436 fprintf(fd, "Sourced %d times\n", si->sn_pr_count); | |
1437 fprintf(fd, "Total time: %s\n", profile_msg(&si->sn_pr_total)); | |
1438 fprintf(fd, " Self time: %s\n", profile_msg(&si->sn_pr_self)); | |
1439 fprintf(fd, "\n"); | |
1440 fprintf(fd, "count total (s) self (s)\n"); | |
1441 | |
531 | 1442 sfd = mch_fopen((char *)si->sn_name, "r"); |
170 | 1443 if (sfd == NULL) |
1444 fprintf(fd, "Cannot open file!\n"); | |
1445 else | |
1446 { | |
1447 for (i = 0; i < si->sn_prl_ga.ga_len; ++i) | |
1448 { | |
1449 if (vim_fgets(IObuff, IOSIZE, sfd)) | |
1450 break; | |
1451 pp = &PRL_ITEM(si, i); | |
1452 if (pp->snp_count > 0) | |
1453 { | |
1454 fprintf(fd, "%5d ", pp->snp_count); | |
1455 if (profile_equal(&pp->sn_prl_total, &pp->sn_prl_self)) | |
1456 fprintf(fd, " "); | |
1457 else | |
1458 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_total)); | |
1459 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_self)); | |
1460 } | |
1461 else | |
1462 fprintf(fd, " "); | |
1463 fprintf(fd, "%s", IObuff); | |
1464 } | |
1465 fclose(sfd); | |
1466 } | |
1467 fprintf(fd, "\n"); | |
1468 } | |
1469 } | |
1470 } | |
1471 | |
1472 /* | |
1473 * Return TRUE when a function defined in the current script should be | |
1474 * profiled. | |
1475 */ | |
1476 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1477 prof_def_func(void) |
170 | 1478 { |
391 | 1479 if (current_SID > 0) |
1480 return SCRIPT_ITEM(current_SID).sn_pr_force; | |
1481 return FALSE; | |
170 | 1482 } |
1483 | |
1484 # endif | |
7 | 1485 #endif |
1486 | |
1487 /* | |
1488 * If 'autowrite' option set, try to write the file. | |
1489 * Careful: autocommands may make "buf" invalid! | |
1490 * | |
1491 * return FAIL for failure, OK otherwise | |
1492 */ | |
1493 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1494 autowrite(buf_T *buf, int forceit) |
7 | 1495 { |
1069 | 1496 int r; |
1497 | |
7 | 1498 if (!(p_aw || p_awa) || !p_write |
1499 #ifdef FEAT_QUICKFIX | |
1069 | 1500 /* never autowrite a "nofile" or "nowrite" buffer */ |
1501 || bt_dontwrite(buf) | |
7 | 1502 #endif |
1069 | 1503 || (!forceit && buf->b_p_ro) || buf->b_ffname == NULL) |
7 | 1504 return FAIL; |
1069 | 1505 r = buf_write_all(buf, forceit); |
1506 | |
1507 /* Writing may succeed but the buffer still changed, e.g., when there is a | |
1508 * conversion error. We do want to return FAIL then. */ | |
1509 if (buf_valid(buf) && bufIsChanged(buf)) | |
1510 r = FAIL; | |
1511 return r; | |
7 | 1512 } |
1513 | |
1514 /* | |
1515 * flush all buffers, except the ones that are readonly | |
1516 */ | |
1517 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1518 autowrite_all(void) |
7 | 1519 { |
1520 buf_T *buf; | |
1521 | |
1522 if (!(p_aw || p_awa) || !p_write) | |
1523 return; | |
1524 for (buf = firstbuf; buf; buf = buf->b_next) | |
1525 if (bufIsChanged(buf) && !buf->b_p_ro) | |
1526 { | |
1527 (void)buf_write_all(buf, FALSE); | |
1528 #ifdef FEAT_AUTOCMD | |
1529 /* an autocommand may have deleted the buffer */ | |
1530 if (!buf_valid(buf)) | |
1531 buf = firstbuf; | |
1532 #endif | |
1533 } | |
1534 } | |
1535 | |
1536 /* | |
5464 | 1537 * Return TRUE if buffer was changed and cannot be abandoned. |
1538 * For flags use the CCGD_ values. | |
7 | 1539 */ |
1540 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1541 check_changed(buf_T *buf, int flags) |
7 | 1542 { |
5464 | 1543 int forceit = (flags & CCGD_FORCEIT); |
1544 | |
7 | 1545 if ( !forceit |
1546 && bufIsChanged(buf) | |
5464 | 1547 && ((flags & CCGD_MULTWIN) || buf->b_nwindows <= 1) |
1548 && (!(flags & CCGD_AW) || autowrite(buf, forceit) == FAIL)) | |
7 | 1549 { |
1550 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
1551 if ((p_confirm || cmdmod.confirm) && p_write) | |
1552 { | |
1553 buf_T *buf2; | |
1554 int count = 0; | |
1555 | |
5464 | 1556 if (flags & CCGD_ALLBUF) |
7 | 1557 for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next) |
1558 if (bufIsChanged(buf2) | |
1559 && (buf2->b_ffname != NULL | |
1560 # ifdef FEAT_BROWSE | |
1561 || cmdmod.browse | |
1562 # endif | |
1563 )) | |
1564 ++count; | |
1565 # ifdef FEAT_AUTOCMD | |
1566 if (!buf_valid(buf)) | |
1567 /* Autocommand deleted buffer, oops! It's not changed now. */ | |
1568 return FALSE; | |
1569 # endif | |
1570 dialog_changed(buf, count > 1); | |
1571 # ifdef FEAT_AUTOCMD | |
1572 if (!buf_valid(buf)) | |
1573 /* Autocommand deleted buffer, oops! It's not changed now. */ | |
1574 return FALSE; | |
1575 # endif | |
1576 return bufIsChanged(buf); | |
1577 } | |
1578 #endif | |
5464 | 1579 if (flags & CCGD_EXCMD) |
1580 EMSG(_(e_nowrtmsg)); | |
1581 else | |
1582 EMSG(_(e_nowrtmsg_nobang)); | |
7 | 1583 return TRUE; |
1584 } | |
1585 return FALSE; | |
1586 } | |
1587 | |
1588 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) || defined(PROTO) | |
1589 | |
1590 #if defined(FEAT_BROWSE) || defined(PROTO) | |
1591 /* | |
1592 * When wanting to write a file without a file name, ask the user for a name. | |
1593 */ | |
1594 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1595 browse_save_fname(buf_T *buf) |
7 | 1596 { |
1597 if (buf->b_fname == NULL) | |
1598 { | |
1599 char_u *fname; | |
1600 | |
29 | 1601 fname = do_browse(BROWSE_SAVE, (char_u *)_("Save As"), |
1602 NULL, NULL, NULL, NULL, buf); | |
7 | 1603 if (fname != NULL) |
1604 { | |
1605 if (setfname(buf, fname, NULL, TRUE) == OK) | |
1606 buf->b_flags |= BF_NOTEDITED; | |
1607 vim_free(fname); | |
1608 } | |
1609 } | |
1610 } | |
1611 #endif | |
1612 | |
1613 /* | |
2849 | 1614 * Ask the user what to do when abandoning a changed buffer. |
7 | 1615 * Must check 'write' option first! |
1616 */ | |
1617 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1618 dialog_changed( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1619 buf_T *buf, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1620 int checkall) /* may abandon all changed buffers */ |
7 | 1621 { |
2770 | 1622 char_u buff[DIALOG_MSG_SIZE]; |
7 | 1623 int ret; |
1624 buf_T *buf2; | |
3486 | 1625 exarg_T ea; |
7 | 1626 |
314 | 1627 dialog_msg(buff, _("Save changes to \"%s\"?"), |
7 | 1628 (buf->b_fname != NULL) ? |
1629 buf->b_fname : (char_u *)_("Untitled")); | |
1630 if (checkall) | |
1631 ret = vim_dialog_yesnoallcancel(VIM_QUESTION, NULL, buff, 1); | |
1632 else | |
1633 ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1); | |
1634 | |
3486 | 1635 /* Init ea pseudo-structure, this is needed for the check_overwrite() |
1636 * function. */ | |
1637 ea.append = ea.forceit = FALSE; | |
1638 | |
7 | 1639 if (ret == VIM_YES) |
1640 { | |
1641 #ifdef FEAT_BROWSE | |
1642 /* May get file name, when there is none */ | |
1643 browse_save_fname(buf); | |
1644 #endif | |
3486 | 1645 if (buf->b_fname != NULL && check_overwrite(&ea, buf, |
1646 buf->b_fname, buf->b_ffname, FALSE) == OK) | |
1647 /* didn't hit Cancel */ | |
7 | 1648 (void)buf_write_all(buf, FALSE); |
1649 } | |
1650 else if (ret == VIM_NO) | |
1651 { | |
1652 unchanged(buf, TRUE); | |
1653 } | |
1654 else if (ret == VIM_ALL) | |
1655 { | |
1656 /* | |
1657 * Write all modified files that can be written. | |
1658 * Skip readonly buffers, these need to be confirmed | |
1659 * individually. | |
1660 */ | |
1661 for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next) | |
1662 { | |
1663 if (bufIsChanged(buf2) | |
1664 && (buf2->b_ffname != NULL | |
1665 #ifdef FEAT_BROWSE | |
1666 || cmdmod.browse | |
1667 #endif | |
1668 ) | |
1669 && !buf2->b_p_ro) | |
1670 { | |
1671 #ifdef FEAT_BROWSE | |
1672 /* May get file name, when there is none */ | |
1673 browse_save_fname(buf2); | |
1674 #endif | |
3486 | 1675 if (buf2->b_fname != NULL && check_overwrite(&ea, buf2, |
1676 buf2->b_fname, buf2->b_ffname, FALSE) == OK) | |
1677 /* didn't hit Cancel */ | |
7 | 1678 (void)buf_write_all(buf2, FALSE); |
1679 #ifdef FEAT_AUTOCMD | |
1680 /* an autocommand may have deleted the buffer */ | |
1681 if (!buf_valid(buf2)) | |
1682 buf2 = firstbuf; | |
1683 #endif | |
1684 } | |
1685 } | |
1686 } | |
1687 else if (ret == VIM_DISCARDALL) | |
1688 { | |
1689 /* | |
1690 * mark all buffers as unchanged | |
1691 */ | |
1692 for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next) | |
1693 unchanged(buf2, TRUE); | |
1694 } | |
1695 } | |
1696 #endif | |
1697 | |
1698 /* | |
1699 * Return TRUE if the buffer "buf" can be abandoned, either by making it | |
1700 * hidden, autowriting it or unloading it. | |
1701 */ | |
1702 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1703 can_abandon(buf_T *buf, int forceit) |
7 | 1704 { |
1705 return ( P_HID(buf) | |
1706 || !bufIsChanged(buf) | |
1707 || buf->b_nwindows > 1 | |
1708 || autowrite(buf, forceit) == OK | |
1709 || forceit); | |
1710 } | |
1711 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
1712 static void add_bufnum(int *bufnrs, int *bufnump, int nr); |
3429 | 1713 |
1714 /* | |
1715 * Add a buffer number to "bufnrs", unless it's already there. | |
1716 */ | |
1717 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1718 add_bufnum(int *bufnrs, int *bufnump, int nr) |
3429 | 1719 { |
1720 int i; | |
1721 | |
1722 for (i = 0; i < *bufnump; ++i) | |
1723 if (bufnrs[i] == nr) | |
1724 return; | |
1725 bufnrs[*bufnump] = nr; | |
1726 *bufnump = *bufnump + 1; | |
1727 } | |
1728 | |
7 | 1729 /* |
1730 * Return TRUE if any buffer was changed and cannot be abandoned. | |
1731 * 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
|
1732 * 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
|
1733 * hidden. This is used for ":q!". |
7 | 1734 */ |
1735 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1736 check_changed_any( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1737 int hidden, /* Only check hidden buffers */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1738 int unload) |
7 | 1739 { |
3429 | 1740 int ret = FALSE; |
7 | 1741 buf_T *buf; |
1742 int save; | |
3429 | 1743 int i; |
1744 int bufnum = 0; | |
1745 int bufcount = 0; | |
1746 int *bufnrs; | |
7 | 1747 #ifdef FEAT_WINDOWS |
3429 | 1748 tabpage_T *tp; |
7 | 1749 win_T *wp; |
1750 #endif | |
1751 | |
3429 | 1752 for (buf = firstbuf; buf != NULL; buf = buf->b_next) |
1753 ++bufcount; | |
1754 | |
1755 if (bufcount == 0) | |
1756 return FALSE; | |
1757 | |
1758 bufnrs = (int *)alloc(sizeof(int) * bufcount); | |
1759 if (bufnrs == NULL) | |
1760 return FALSE; | |
1761 | |
1762 /* curbuf */ | |
1763 bufnrs[bufnum++] = curbuf->b_fnum; | |
1764 #ifdef FEAT_WINDOWS | |
1765 /* buf in curtab */ | |
1766 FOR_ALL_WINDOWS(wp) | |
1767 if (wp->w_buffer != curbuf) | |
1768 add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum); | |
1769 | |
1770 /* buf in other tab */ | |
1771 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | |
1772 if (tp != curtab) | |
1773 for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) | |
1774 add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum); | |
1775 #endif | |
1776 /* any other buf */ | |
1777 for (buf = firstbuf; buf != NULL; buf = buf->b_next) | |
1778 add_bufnum(bufnrs, &bufnum, buf->b_fnum); | |
1779 | |
1780 for (i = 0; i < bufnum; ++i) | |
7 | 1781 { |
3429 | 1782 buf = buflist_findnr(bufnrs[i]); |
1783 if (buf == NULL) | |
1784 continue; | |
1785 if ((!hidden || buf->b_nwindows == 0) && bufIsChanged(buf)) | |
7 | 1786 { |
3429 | 1787 /* Try auto-writing the buffer. If this fails but the buffer no |
1788 * longer exists it's not changed, that's OK. */ | |
5464 | 1789 if (check_changed(buf, (p_awa ? CCGD_AW : 0) |
1790 | CCGD_MULTWIN | |
1791 | CCGD_ALLBUF) && buf_valid(buf)) | |
3429 | 1792 break; /* didn't save - still changes */ |
7 | 1793 } |
1794 } | |
1795 | |
3429 | 1796 if (i >= bufnum) |
1797 goto theend; | |
1798 | |
1799 ret = TRUE; | |
7 | 1800 exiting = FALSE; |
1801 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
1802 /* | |
1803 * When ":confirm" used, don't give an error message. | |
1804 */ | |
1805 if (!(p_confirm || cmdmod.confirm)) | |
1806 #endif | |
1807 { | |
1808 /* There must be a wait_return for this message, do_buffer() | |
1809 * may cause a redraw. But wait_return() is a no-op when vgetc() | |
1810 * is busy (Quit used from window menu), then make sure we don't | |
1811 * cause a scroll up. */ | |
823 | 1812 if (vgetc_busy > 0) |
7 | 1813 { |
1814 msg_row = cmdline_row; | |
1815 msg_col = 0; | |
1816 msg_didout = FALSE; | |
1817 } | |
1818 if (EMSG2(_("E162: No write since last change for buffer \"%s\""), | |
3839 | 1819 buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname)) |
7 | 1820 { |
1821 save = no_wait_return; | |
1822 no_wait_return = FALSE; | |
1823 wait_return(FALSE); | |
1824 no_wait_return = save; | |
1825 } | |
1826 } | |
1827 | |
1828 #ifdef FEAT_WINDOWS | |
1829 /* Try to find a window that contains the buffer. */ | |
1830 if (buf != curbuf) | |
3429 | 1831 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 1832 if (wp->w_buffer == buf) |
1833 { | |
3429 | 1834 goto_tabpage_win(tp, wp); |
7 | 1835 # ifdef FEAT_AUTOCMD |
1836 /* Paranoia: did autocms wipe out the buffer with changes? */ | |
1837 if (!buf_valid(buf)) | |
3429 | 1838 { |
1839 goto theend; | |
1840 } | |
7 | 1841 # endif |
3429 | 1842 goto buf_found; |
7 | 1843 } |
3429 | 1844 buf_found: |
7 | 1845 #endif |
1846 | |
1847 /* Open the changed buffer in the current window. */ | |
1848 if (buf != curbuf) | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7107
diff
changeset
|
1849 set_curbuf(buf, unload ? DOBUF_UNLOAD : DOBUF_GOTO); |
7 | 1850 |
3429 | 1851 theend: |
1852 vim_free(bufnrs); | |
1853 return ret; | |
7 | 1854 } |
1855 | |
1856 /* | |
1857 * return FAIL if there is no file name, OK if there is one | |
1858 * give error message for FAIL | |
1859 */ | |
1860 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1861 check_fname(void) |
7 | 1862 { |
1863 if (curbuf->b_ffname == NULL) | |
1864 { | |
1865 EMSG(_(e_noname)); | |
1866 return FAIL; | |
1867 } | |
1868 return OK; | |
1869 } | |
1870 | |
1871 /* | |
1872 * flush the contents of a buffer, unless it has no file name | |
1873 * | |
1874 * return FAIL for failure, OK otherwise | |
1875 */ | |
1876 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1877 buf_write_all(buf_T *buf, int forceit) |
7 | 1878 { |
1879 int retval; | |
1880 #ifdef FEAT_AUTOCMD | |
1881 buf_T *old_curbuf = curbuf; | |
1882 #endif | |
1883 | |
1884 retval = (buf_write(buf, buf->b_ffname, buf->b_fname, | |
1885 (linenr_T)1, buf->b_ml.ml_line_count, NULL, | |
1886 FALSE, forceit, TRUE, FALSE)); | |
1887 #ifdef FEAT_AUTOCMD | |
1888 if (curbuf != old_curbuf) | |
16 | 1889 { |
1890 msg_source(hl_attr(HLF_W)); | |
7 | 1891 MSG(_("Warning: Entered other buffer unexpectedly (check autocommands)")); |
16 | 1892 } |
7 | 1893 #endif |
1894 return retval; | |
1895 } | |
1896 | |
1897 /* | |
1898 * Code to handle the argument list. | |
1899 */ | |
1900 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
1901 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
|
1902 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
|
1903 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
|
1904 static int editing_arg_idx(win_T *win); |
39 | 1905 #ifdef FEAT_LISTCMDS |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
1906 static int alist_add_list(int count, char_u **files, int after); |
39 | 1907 #endif |
1908 #define AL_SET 1 | |
1909 #define AL_ADD 2 | |
1910 #define AL_DEL 3 | |
1911 | |
7 | 1912 /* |
39 | 1913 * Isolate one argument, taking backticks. |
1914 * Changes the argument in-place, puts a NUL after it. Backticks remain. | |
7 | 1915 * Return a pointer to the start of the next argument. |
1916 */ | |
39 | 1917 static char_u * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1918 do_one_arg(char_u *str) |
7 | 1919 { |
1920 char_u *p; | |
1921 int inbacktick; | |
1922 | |
1923 inbacktick = FALSE; | |
1924 for (p = str; *str; ++str) | |
1925 { | |
39 | 1926 /* When the backslash is used for escaping the special meaning of a |
1927 * character we need to keep it until wildcard expansion. */ | |
7 | 1928 if (rem_backslash(str)) |
1929 { | |
1930 *p++ = *str++; | |
1931 *p++ = *str; | |
1932 } | |
1933 else | |
1934 { | |
39 | 1935 /* An item ends at a space not in backticks */ |
1936 if (!inbacktick && vim_isspace(*str)) | |
7 | 1937 break; |
39 | 1938 if (*str == '`') |
7 | 1939 inbacktick ^= TRUE; |
39 | 1940 *p++ = *str; |
7 | 1941 } |
1942 } | |
1943 str = skipwhite(str); | |
1944 *p = NUL; | |
1945 | |
1946 return str; | |
1947 } | |
1948 | |
41 | 1949 /* |
1950 * Separate the arguments in "str" and return a list of pointers in the | |
1951 * growarray "gap". | |
1952 */ | |
1953 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1954 get_arglist(garray_T *gap, char_u *str) |
41 | 1955 { |
1956 ga_init2(gap, (int)sizeof(char_u *), 20); | |
1957 while (*str != NUL) | |
1958 { | |
1959 if (ga_grow(gap, 1) == FAIL) | |
1960 { | |
1961 ga_clear(gap); | |
1962 return FAIL; | |
1963 } | |
1964 ((char_u **)gap->ga_data)[gap->ga_len++] = str; | |
1965 | |
1966 /* Isolate one argument, change it in-place, put a NUL after it. */ | |
1967 str = do_one_arg(str); | |
1968 } | |
1969 return OK; | |
1970 } | |
1971 | |
642 | 1972 #if defined(FEAT_QUICKFIX) || defined(FEAT_SYN_HL) || defined(PROTO) |
237 | 1973 /* |
1974 * Parse a list of arguments (file names), expand them and return in | |
3620 | 1975 * "fnames[fcountp]". When "wig" is TRUE, removes files matching 'wildignore'. |
237 | 1976 * Return FAIL or OK. |
1977 */ | |
1978 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1979 get_arglist_exp( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1980 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1981 int *fcountp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1982 char_u ***fnamesp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1983 int wig) |
237 | 1984 { |
1985 garray_T ga; | |
1986 int i; | |
1987 | |
1988 if (get_arglist(&ga, str) == FAIL) | |
1989 return FAIL; | |
3620 | 1990 if (wig == TRUE) |
1991 i = expand_wildcards(ga.ga_len, (char_u **)ga.ga_data, | |
1992 fcountp, fnamesp, EW_FILE|EW_NOTFOUND); | |
1993 else | |
1994 i = gen_expand_wildcards(ga.ga_len, (char_u **)ga.ga_data, | |
1995 fcountp, fnamesp, EW_FILE|EW_NOTFOUND); | |
1996 | |
237 | 1997 ga_clear(&ga); |
1998 return i; | |
1999 } | |
2000 #endif | |
2001 | |
7 | 2002 #if defined(FEAT_GUI) || defined(FEAT_CLIENTSERVER) || defined(PROTO) |
2003 /* | |
2004 * Redefine the argument list. | |
2005 */ | |
2006 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2007 set_arglist(char_u *str) |
7 | 2008 { |
2009 do_arglist(str, AL_SET, 0); | |
2010 } | |
2011 #endif | |
2012 | |
2013 /* | |
2014 * "what" == AL_SET: Redefine the argument list to 'str'. | |
2015 * "what" == AL_ADD: add files in 'str' to the argument list after "after". | |
2016 * "what" == AL_DEL: remove files in 'str' from the argument list. | |
2017 * | |
2018 * Return FAIL for failure, OK otherwise. | |
2019 */ | |
2020 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2021 do_arglist( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2022 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2023 int what UNUSED, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2024 int after UNUSED) /* 0 means before first one */ |
7 | 2025 { |
2026 garray_T new_ga; | |
2027 int exp_count; | |
2028 char_u **exp_files; | |
2029 int i; | |
2030 #ifdef FEAT_LISTCMDS | |
2031 char_u *p; | |
2032 int match; | |
2033 #endif | |
2034 | |
2035 /* | |
7726
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2036 * Set default argument for ":argadd" command. |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2037 */ |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2038 if (what == AL_ADD && *str == NUL) |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2039 { |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2040 if (curbuf->b_ffname == NULL) |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2041 return FAIL; |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2042 str = curbuf->b_fname; |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2043 } |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2044 |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
2045 /* |
7 | 2046 * Collect all file name arguments in "new_ga". |
2047 */ | |
41 | 2048 if (get_arglist(&new_ga, str) == FAIL) |
2049 return FAIL; | |
7 | 2050 |
2051 #ifdef FEAT_LISTCMDS | |
2052 if (what == AL_DEL) | |
2053 { | |
2054 regmatch_T regmatch; | |
2055 int didone; | |
2056 | |
2057 /* | |
2058 * Delete the items: use each item as a regexp and find a match in the | |
2059 * argument list. | |
2060 */ | |
4242 | 2061 regmatch.rm_ic = p_fic; /* ignore case when 'fileignorecase' is set */ |
7 | 2062 for (i = 0; i < new_ga.ga_len && !got_int; ++i) |
2063 { | |
2064 p = ((char_u **)new_ga.ga_data)[i]; | |
2065 p = file_pat_to_reg_pat(p, NULL, NULL, FALSE); | |
2066 if (p == NULL) | |
2067 break; | |
2068 regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); | |
2069 if (regmatch.regprog == NULL) | |
2070 { | |
2071 vim_free(p); | |
2072 break; | |
2073 } | |
2074 | |
2075 didone = FALSE; | |
2076 for (match = 0; match < ARGCOUNT; ++match) | |
2077 if (vim_regexec(®match, alist_name(&ARGLIST[match]), | |
2078 (colnr_T)0)) | |
2079 { | |
2080 didone = TRUE; | |
2081 vim_free(ARGLIST[match].ae_fname); | |
2082 mch_memmove(ARGLIST + match, ARGLIST + match + 1, | |
2083 (ARGCOUNT - match - 1) * sizeof(aentry_T)); | |
2084 --ALIST(curwin)->al_ga.ga_len; | |
2085 if (curwin->w_arg_idx > match) | |
2086 --curwin->w_arg_idx; | |
2087 --match; | |
2088 } | |
2089 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
2090 vim_regfree(regmatch.regprog); |
7 | 2091 vim_free(p); |
2092 if (!didone) | |
2093 EMSG2(_(e_nomatch2), ((char_u **)new_ga.ga_data)[i]); | |
2094 } | |
2095 ga_clear(&new_ga); | |
2096 } | |
2097 else | |
2098 #endif | |
2099 { | |
2100 i = expand_wildcards(new_ga.ga_len, (char_u **)new_ga.ga_data, | |
2101 &exp_count, &exp_files, EW_DIR|EW_FILE|EW_ADDSLASH|EW_NOTFOUND); | |
2102 ga_clear(&new_ga); | |
7625
b4384c581806
commit https://github.com/vim/vim/commit/2db5c3b3ceeaded7fb5a64dc5cb22b0cb95b78a1
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
2103 if (i == FAIL || exp_count == 0) |
7 | 2104 { |
2105 EMSG(_(e_nomatch)); | |
2106 return FAIL; | |
2107 } | |
2108 | |
2109 #ifdef FEAT_LISTCMDS | |
2110 if (what == AL_ADD) | |
2111 { | |
2112 (void)alist_add_list(exp_count, exp_files, after); | |
2113 vim_free(exp_files); | |
2114 } | |
2115 else /* what == AL_SET */ | |
2116 #endif | |
41 | 2117 alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0); |
7 | 2118 } |
2119 | |
2120 alist_check_arg_idx(); | |
2121 | |
2122 return OK; | |
2123 } | |
2124 | |
2125 /* | |
2126 * Check the validity of the arg_idx for each other window. | |
2127 */ | |
2128 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2129 alist_check_arg_idx(void) |
7 | 2130 { |
2131 #ifdef FEAT_WINDOWS | |
2132 win_T *win; | |
671 | 2133 tabpage_T *tp; |
2134 | |
2135 FOR_ALL_TAB_WINDOWS(tp, win) | |
7 | 2136 if (win->w_alist == curwin->w_alist) |
2137 check_arg_idx(win); | |
2138 #else | |
2139 check_arg_idx(curwin); | |
2140 #endif | |
2141 } | |
2142 | |
2143 /* | |
3312 | 2144 * Return TRUE if window "win" is editing the file at the current argument |
22 | 2145 * index. |
2146 */ | |
2147 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2148 editing_arg_idx(win_T *win) |
22 | 2149 { |
2150 return !(win->w_arg_idx >= WARGCOUNT(win) | |
2151 || (win->w_buffer->b_fnum | |
2152 != WARGLIST(win)[win->w_arg_idx].ae_fnum | |
2153 && (win->w_buffer->b_ffname == NULL | |
2154 || !(fullpathcmp( | |
2155 alist_name(&WARGLIST(win)[win->w_arg_idx]), | |
2156 win->w_buffer->b_ffname, TRUE) & FPC_SAME)))); | |
2157 } | |
2158 | |
2159 /* | |
7 | 2160 * Check if window "win" is editing the w_arg_idx file in its argument list. |
2161 */ | |
2162 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2163 check_arg_idx(win_T *win) |
7 | 2164 { |
22 | 2165 if (WARGCOUNT(win) > 1 && !editing_arg_idx(win)) |
7 | 2166 { |
2167 /* We are not editing the current entry in the argument list. | |
2168 * Set "arg_had_last" if we are editing the last one. */ | |
2169 win->w_arg_idx_invalid = TRUE; | |
2170 if (win->w_arg_idx != WARGCOUNT(win) - 1 | |
2171 && arg_had_last == FALSE | |
2172 #ifdef FEAT_WINDOWS | |
2173 && ALIST(win) == &global_alist | |
2174 #endif | |
2175 && GARGCOUNT > 0 | |
2176 && win->w_arg_idx < GARGCOUNT | |
2177 && (win->w_buffer->b_fnum == GARGLIST[GARGCOUNT - 1].ae_fnum | |
2178 || (win->w_buffer->b_ffname != NULL | |
2179 && (fullpathcmp(alist_name(&GARGLIST[GARGCOUNT - 1]), | |
2180 win->w_buffer->b_ffname, TRUE) & FPC_SAME)))) | |
2181 arg_had_last = TRUE; | |
2182 } | |
2183 else | |
2184 { | |
2185 /* We are editing the current entry in the argument list. | |
2186 * Set "arg_had_last" if it's also the last one */ | |
2187 win->w_arg_idx_invalid = FALSE; | |
2188 if (win->w_arg_idx == WARGCOUNT(win) - 1 | |
2189 #ifdef FEAT_WINDOWS | |
2190 && win->w_alist == &global_alist | |
2191 #endif | |
2192 ) | |
2193 arg_had_last = TRUE; | |
2194 } | |
2195 } | |
2196 | |
2197 /* | |
2198 * ":args", ":argslocal" and ":argsglobal". | |
2199 */ | |
2200 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2201 ex_args(exarg_T *eap) |
7 | 2202 { |
2203 int i; | |
2204 | |
2205 if (eap->cmdidx != CMD_args) | |
2206 { | |
2207 #if defined(FEAT_WINDOWS) && defined(FEAT_LISTCMDS) | |
2208 alist_unlink(ALIST(curwin)); | |
2209 if (eap->cmdidx == CMD_argglobal) | |
2210 ALIST(curwin) = &global_alist; | |
2211 else /* eap->cmdidx == CMD_arglocal */ | |
2212 alist_new(); | |
2213 #else | |
2214 ex_ni(eap); | |
2215 return; | |
2216 #endif | |
2217 } | |
2218 | |
2219 if (!ends_excmd(*eap->arg)) | |
2220 { | |
2221 /* | |
2222 * ":args file ..": define new argument list, handle like ":next" | |
2223 * Also for ":argslocal file .." and ":argsglobal file ..". | |
2224 */ | |
2225 ex_next(eap); | |
2226 } | |
2227 else | |
2228 #if defined(FEAT_WINDOWS) && defined(FEAT_LISTCMDS) | |
2229 if (eap->cmdidx == CMD_args) | |
2230 #endif | |
2231 { | |
2232 /* | |
2233 * ":args": list arguments. | |
2234 */ | |
2235 if (ARGCOUNT > 0) | |
2236 { | |
2237 /* Overwrite the command, for a short list there is no scrolling | |
2238 * required and no wait_return(). */ | |
2239 gotocmdline(TRUE); | |
2240 for (i = 0; i < ARGCOUNT; ++i) | |
2241 { | |
2242 if (i == curwin->w_arg_idx) | |
2243 msg_putchar('['); | |
2244 msg_outtrans(alist_name(&ARGLIST[i])); | |
2245 if (i == curwin->w_arg_idx) | |
2246 msg_putchar(']'); | |
2247 msg_putchar(' '); | |
2248 } | |
2249 } | |
2250 } | |
2251 #if defined(FEAT_WINDOWS) && defined(FEAT_LISTCMDS) | |
2252 else if (eap->cmdidx == CMD_arglocal) | |
2253 { | |
2254 garray_T *gap = &curwin->w_alist->al_ga; | |
2255 | |
2256 /* | |
2257 * ":argslocal": make a local copy of the global argument list. | |
2258 */ | |
2259 if (ga_grow(gap, GARGCOUNT) == OK) | |
2260 for (i = 0; i < GARGCOUNT; ++i) | |
2261 if (GARGLIST[i].ae_fname != NULL) | |
2262 { | |
2263 AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname = | |
2264 vim_strsave(GARGLIST[i].ae_fname); | |
2265 AARGLIST(curwin->w_alist)[gap->ga_len].ae_fnum = | |
2266 GARGLIST[i].ae_fnum; | |
2267 ++gap->ga_len; | |
2268 } | |
2269 } | |
2270 #endif | |
2271 } | |
2272 | |
2273 /* | |
2274 * ":previous", ":sprevious", ":Next" and ":sNext". | |
2275 */ | |
2276 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2277 ex_previous(exarg_T *eap) |
7 | 2278 { |
2279 /* If past the last one already, go to the last one. */ | |
2280 if (curwin->w_arg_idx - (int)eap->line2 >= ARGCOUNT) | |
2281 do_argfile(eap, ARGCOUNT - 1); | |
2282 else | |
2283 do_argfile(eap, curwin->w_arg_idx - (int)eap->line2); | |
2284 } | |
2285 | |
2286 /* | |
2287 * ":rewind", ":first", ":sfirst" and ":srewind". | |
2288 */ | |
2289 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2290 ex_rewind(exarg_T *eap) |
7 | 2291 { |
2292 do_argfile(eap, 0); | |
2293 } | |
2294 | |
2295 /* | |
2296 * ":last" and ":slast". | |
2297 */ | |
2298 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2299 ex_last(exarg_T *eap) |
7 | 2300 { |
2301 do_argfile(eap, ARGCOUNT - 1); | |
2302 } | |
2303 | |
2304 /* | |
2305 * ":argument" and ":sargument". | |
2306 */ | |
2307 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2308 ex_argument(exarg_T *eap) |
7 | 2309 { |
2310 int i; | |
2311 | |
2312 if (eap->addr_count > 0) | |
2313 i = eap->line2 - 1; | |
2314 else | |
2315 i = curwin->w_arg_idx; | |
2316 do_argfile(eap, i); | |
2317 } | |
2318 | |
2319 /* | |
2320 * Edit file "argn" of the argument lists. | |
2321 */ | |
2322 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2323 do_argfile(exarg_T *eap, int argn) |
7 | 2324 { |
2325 int other; | |
2326 char_u *p; | |
271 | 2327 int old_arg_idx = curwin->w_arg_idx; |
7 | 2328 |
2329 if (argn < 0 || argn >= ARGCOUNT) | |
2330 { | |
2331 if (ARGCOUNT <= 1) | |
2332 EMSG(_("E163: There is only one file to edit")); | |
2333 else if (argn < 0) | |
2334 EMSG(_("E164: Cannot go before first file")); | |
2335 else | |
2336 EMSG(_("E165: Cannot go beyond last file")); | |
2337 } | |
2338 else | |
2339 { | |
2340 setpcmark(); | |
2341 #ifdef FEAT_GUI | |
2342 need_mouse_correct = TRUE; | |
2343 #endif | |
2344 | |
2345 #ifdef FEAT_WINDOWS | |
683 | 2346 /* split window or create new tab page first */ |
2347 if (*eap->cmd == 's' || cmdmod.tab != 0) | |
7 | 2348 { |
2349 if (win_split(0, 0) == FAIL) | |
2350 return; | |
2583 | 2351 RESET_BINDING(curwin); |
7 | 2352 } |
2353 else | |
2354 #endif | |
2355 { | |
2356 /* | |
2357 * if 'hidden' set, only check for changed file when re-editing | |
2358 * the same buffer | |
2359 */ | |
2360 other = TRUE; | |
2361 if (P_HID(curbuf)) | |
2362 { | |
2363 p = fix_fname(alist_name(&ARGLIST[argn])); | |
2364 other = otherfile(p); | |
2365 vim_free(p); | |
2366 } | |
2367 if ((!P_HID(curbuf) || !other) | |
5464 | 2368 && check_changed(curbuf, CCGD_AW |
2369 | (other ? 0 : CCGD_MULTWIN) | |
2370 | (eap->forceit ? CCGD_FORCEIT : 0) | |
2371 | CCGD_EXCMD)) | |
7 | 2372 return; |
2373 } | |
2374 | |
2375 curwin->w_arg_idx = argn; | |
2376 if (argn == ARGCOUNT - 1 | |
2377 #ifdef FEAT_WINDOWS | |
2378 && curwin->w_alist == &global_alist | |
2379 #endif | |
2380 ) | |
2381 arg_had_last = TRUE; | |
2382 | |
271 | 2383 /* Edit the file; always use the last known line number. |
2384 * When it fails (e.g. Abort for already edited file) restore the | |
2385 * argument index. */ | |
2386 if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL, | |
7 | 2387 eap, ECMD_LAST, |
1743 | 2388 (P_HID(curwin->w_buffer) ? ECMD_HIDE : 0) |
2389 + (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL) | |
271 | 2390 curwin->w_arg_idx = old_arg_idx; |
7 | 2391 /* like Vi: set the mark where the cursor is in the file. */ |
271 | 2392 else if (eap->cmdidx != CMD_argdo) |
7 | 2393 setmark('\''); |
2394 } | |
2395 } | |
2396 | |
2397 /* | |
2398 * ":next", and commands that behave like it. | |
2399 */ | |
2400 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2401 ex_next(exarg_T *eap) |
7 | 2402 { |
2403 int i; | |
2404 | |
2405 /* | |
2406 * check for changed buffer now, if this fails the argument list is not | |
2407 * redefined. | |
2408 */ | |
2409 if ( P_HID(curbuf) | |
2410 || eap->cmdidx == CMD_snext | |
5464 | 2411 || !check_changed(curbuf, CCGD_AW |
2412 | (eap->forceit ? CCGD_FORCEIT : 0) | |
2413 | CCGD_EXCMD)) | |
7 | 2414 { |
2415 if (*eap->arg != NUL) /* redefine file list */ | |
2416 { | |
2417 if (do_arglist(eap->arg, AL_SET, 0) == FAIL) | |
2418 return; | |
2419 i = 0; | |
2420 } | |
2421 else | |
2422 i = curwin->w_arg_idx + (int)eap->line2; | |
2423 do_argfile(eap, i); | |
2424 } | |
2425 } | |
2426 | |
2427 #ifdef FEAT_LISTCMDS | |
2428 /* | |
2429 * ":argedit" | |
2430 */ | |
2431 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2432 ex_argedit(exarg_T *eap) |
7 | 2433 { |
2434 int fnum; | |
2435 int i; | |
2436 char_u *s; | |
2437 | |
2438 /* Add the argument to the buffer list and get the buffer number. */ | |
2439 fnum = buflist_add(eap->arg, BLN_LISTED); | |
2440 | |
2441 /* Check if this argument is already in the argument list. */ | |
2442 for (i = 0; i < ARGCOUNT; ++i) | |
2443 if (ARGLIST[i].ae_fnum == fnum) | |
2444 break; | |
2445 if (i == ARGCOUNT) | |
2446 { | |
2447 /* Can't find it, add it to the argument list. */ | |
2448 s = vim_strsave(eap->arg); | |
2449 if (s == NULL) | |
2450 return; | |
2451 i = alist_add_list(1, &s, | |
2452 eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1); | |
2453 if (i < 0) | |
2454 return; | |
2455 curwin->w_arg_idx = i; | |
2456 } | |
2457 | |
2458 alist_check_arg_idx(); | |
2459 | |
2460 /* Edit the argument. */ | |
2461 do_argfile(eap, i); | |
2462 } | |
2463 | |
2464 /* | |
2465 * ":argadd" | |
2466 */ | |
2467 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2468 ex_argadd(exarg_T *eap) |
7 | 2469 { |
2470 do_arglist(eap->arg, AL_ADD, | |
2471 eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1); | |
2472 #ifdef FEAT_TITLE | |
2473 maketitle(); | |
2474 #endif | |
2475 } | |
2476 | |
2477 /* | |
2478 * ":argdelete" | |
2479 */ | |
2480 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2481 ex_argdelete(exarg_T *eap) |
7 | 2482 { |
2483 int i; | |
2484 int n; | |
2485 | |
2486 if (eap->addr_count > 0) | |
2487 { | |
2488 /* ":1,4argdel": Delete all arguments in the range. */ | |
2489 if (eap->line2 > ARGCOUNT) | |
2490 eap->line2 = ARGCOUNT; | |
2491 n = eap->line2 - eap->line1 + 1; | |
2492 if (*eap->arg != NUL || n <= 0) | |
2493 EMSG(_(e_invarg)); | |
2494 else | |
2495 { | |
2496 for (i = eap->line1; i <= eap->line2; ++i) | |
2497 vim_free(ARGLIST[i - 1].ae_fname); | |
2498 mch_memmove(ARGLIST + eap->line1 - 1, ARGLIST + eap->line2, | |
2499 (size_t)((ARGCOUNT - eap->line2) * sizeof(aentry_T))); | |
2500 ALIST(curwin)->al_ga.ga_len -= n; | |
2501 if (curwin->w_arg_idx >= eap->line2) | |
2502 curwin->w_arg_idx -= n; | |
2503 else if (curwin->w_arg_idx > eap->line1) | |
2504 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
|
2505 if (ARGCOUNT == 0) |
0ecb62a66a7a
commit https://github.com/vim/vim/commit/72defda84eb26be9e2ade56c7877b912f818026e
Christian Brabandt <cb@256bit.org>
parents:
7625
diff
changeset
|
2506 curwin->w_arg_idx = 0; |
0ecb62a66a7a
commit https://github.com/vim/vim/commit/72defda84eb26be9e2ade56c7877b912f818026e
Christian Brabandt <cb@256bit.org>
parents:
7625
diff
changeset
|
2507 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
|
2508 curwin->w_arg_idx = ARGCOUNT - 1; |
7 | 2509 } |
2510 } | |
2511 else if (*eap->arg == NUL) | |
2512 EMSG(_(e_argreq)); | |
2513 else | |
2514 do_arglist(eap->arg, AL_DEL, 0); | |
2515 #ifdef FEAT_TITLE | |
2516 maketitle(); | |
2517 #endif | |
2518 } | |
2519 | |
2520 /* | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2521 * ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo" |
7 | 2522 */ |
2523 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2524 ex_listdo(exarg_T *eap) |
7 | 2525 { |
2526 int i; | |
2527 #ifdef FEAT_WINDOWS | |
685 | 2528 win_T *wp; |
2529 tabpage_T *tp; | |
7 | 2530 #endif |
6641 | 2531 buf_T *buf = curbuf; |
7 | 2532 int next_fnum = 0; |
2533 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) | |
2534 char_u *save_ei = NULL; | |
2535 #endif | |
39 | 2536 char_u *p_shm_save; |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2537 #ifdef FEAT_QUICKFIX |
7107
84efaf06f195
commit https://github.com/vim/vim/commit/ed84b76021df763619cabaedddc44eb5ee849136
Christian Brabandt <cb@256bit.org>
parents:
7092
diff
changeset
|
2538 int qf_size = 0; |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2539 int qf_idx; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2540 #endif |
7 | 2541 |
2542 #ifndef FEAT_WINDOWS | |
2543 if (eap->cmdidx == CMD_windo) | |
2544 { | |
2545 ex_ni(eap); | |
2546 return; | |
2547 } | |
2548 #endif | |
2549 | |
2550 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) | |
819 | 2551 if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo) |
123 | 2552 /* Don't do syntax HL autocommands. Skipping the syntax file is a |
2553 * great speed improvement. */ | |
2554 save_ei = au_event_disable(",Syntax"); | |
7 | 2555 #endif |
6116 | 2556 #ifdef FEAT_CLIPBOARD |
2557 start_global_changes(); | |
2558 #endif | |
7 | 2559 |
2560 if (eap->cmdidx == CMD_windo | |
685 | 2561 || eap->cmdidx == CMD_tabdo |
7 | 2562 || P_HID(curbuf) |
5464 | 2563 || !check_changed(curbuf, CCGD_AW |
2564 | (eap->forceit ? CCGD_FORCEIT : 0) | |
2565 | CCGD_EXCMD)) | |
7 | 2566 { |
2567 i = 0; | |
6474 | 2568 /* start at the eap->line1 argument/window/buffer */ |
7 | 2569 #ifdef FEAT_WINDOWS |
685 | 2570 wp = firstwin; |
2571 tp = first_tabpage; | |
7 | 2572 #endif |
6474 | 2573 switch (eap->cmdidx) |
2574 { | |
2575 #ifdef FEAT_WINDOWS | |
2576 case CMD_windo: | |
2577 for ( ; wp != NULL && i + 1 < eap->line1; wp = wp->w_next) | |
2578 i++; | |
2579 break; | |
2580 case CMD_tabdo: | |
2581 for( ; tp != NULL && i + 1 < eap->line1; tp = tp->tp_next) | |
2582 i++; | |
2583 break; | |
2584 #endif | |
2585 case CMD_argdo: | |
2586 i = eap->line1 - 1; | |
2587 break; | |
2588 default: | |
2589 break; | |
2590 } | |
7 | 2591 /* set pcmark now */ |
2592 if (eap->cmdidx == CMD_bufdo) | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2593 { |
6641 | 2594 /* 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
|
2595 for (buf = firstbuf; buf != NULL && (buf->b_fnum < eap->line1 |
6641 | 2596 || !buf->b_p_bl); buf = buf->b_next) |
2597 if (buf->b_fnum > eap->line2) | |
2598 { | |
2599 buf = NULL; | |
2600 break; | |
2601 } | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2602 if (buf != NULL) |
6641 | 2603 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
|
2604 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2605 #ifdef FEAT_QUICKFIX |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2606 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
|
2607 || 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
|
2608 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2609 qf_size = qf_get_size(eap); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2610 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
|
2611 buf = NULL; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2612 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2613 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2614 ex_cc(eap); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2615 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2616 buf = curbuf; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2617 i = eap->line1 - 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2618 if (eap->addr_count <= 0) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2619 /* 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
|
2620 eap->line2 = qf_size; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2621 } |
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 #endif |
7 | 2624 else |
2625 setpcmark(); | |
2626 listcmd_busy = TRUE; /* avoids setting pcmark below */ | |
2627 | |
6641 | 2628 while (!got_int && buf != NULL) |
7 | 2629 { |
2630 if (eap->cmdidx == CMD_argdo) | |
2631 { | |
2632 /* go to argument "i" */ | |
2633 if (i == ARGCOUNT) | |
2634 break; | |
2635 /* Don't call do_argfile() when already there, it will try | |
2636 * reloading the file. */ | |
22 | 2637 if (curwin->w_arg_idx != i || !editing_arg_idx(curwin)) |
39 | 2638 { |
2639 /* Clear 'shm' to avoid that the file message overwrites | |
2640 * any output from the command. */ | |
2641 p_shm_save = vim_strsave(p_shm); | |
2642 set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); | |
7 | 2643 do_argfile(eap, i); |
39 | 2644 set_option_value((char_u *)"shm", 0L, p_shm_save, 0); |
2645 vim_free(p_shm_save); | |
2646 } | |
7 | 2647 if (curwin->w_arg_idx != i) |
2648 break; | |
2649 } | |
2650 #ifdef FEAT_WINDOWS | |
2651 else if (eap->cmdidx == CMD_windo) | |
2652 { | |
685 | 2653 /* go to window "wp" */ |
2654 if (!win_valid(wp)) | |
7 | 2655 break; |
685 | 2656 win_goto(wp); |
1115 | 2657 if (curwin != wp) |
2658 break; /* something must be wrong */ | |
685 | 2659 wp = curwin->w_next; |
2660 } | |
2661 else if (eap->cmdidx == CMD_tabdo) | |
2662 { | |
2663 /* go to window "tp" */ | |
2664 if (!valid_tabpage(tp)) | |
2665 break; | |
4354 | 2666 goto_tabpage_tp(tp, TRUE, TRUE); |
685 | 2667 tp = tp->tp_next; |
7 | 2668 } |
2669 #endif | |
2670 else if (eap->cmdidx == CMD_bufdo) | |
2671 { | |
2672 /* Remember the number of the next listed buffer, in case | |
2673 * ":bwipe" is used or autocommands do something strange. */ | |
2674 next_fnum = -1; | |
2675 for (buf = curbuf->b_next; buf != NULL; buf = buf->b_next) | |
2676 if (buf->b_p_bl) | |
2677 { | |
2678 next_fnum = buf->b_fnum; | |
2679 break; | |
2680 } | |
2681 } | |
2682 | |
6474 | 2683 ++i; |
2684 | |
7 | 2685 /* execute the command */ |
2686 do_cmdline(eap->arg, eap->getline, eap->cookie, | |
2687 DOCMD_VERBOSE + DOCMD_NOWAIT); | |
2688 | |
2689 if (eap->cmdidx == CMD_bufdo) | |
2690 { | |
2691 /* Done? */ | |
6474 | 2692 if (next_fnum < 0 || next_fnum > eap->line2) |
7 | 2693 break; |
2694 /* Check if the buffer still exists. */ | |
2695 for (buf = firstbuf; buf != NULL; buf = buf->b_next) | |
2696 if (buf->b_fnum == next_fnum) | |
2697 break; | |
2698 if (buf == NULL) | |
2699 break; | |
39 | 2700 |
2701 /* Go to the next buffer. Clear 'shm' to avoid that the file | |
2702 * message overwrites any output from the command. */ | |
2703 p_shm_save = vim_strsave(p_shm); | |
2704 set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); | |
7 | 2705 goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum); |
39 | 2706 set_option_value((char_u *)"shm", 0L, p_shm_save, 0); |
2707 vim_free(p_shm_save); | |
2708 | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2709 /* If autocommands took us elsewhere, quit here. */ |
7 | 2710 if (curbuf->b_fnum != next_fnum) |
2711 break; | |
2712 } | |
2713 | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2714 #ifdef FEAT_QUICKFIX |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2715 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
|
2716 || 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
|
2717 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2718 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
|
2719 break; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2720 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2721 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
|
2722 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2723 ex_cnext(eap); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2724 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2725 /* 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
|
2726 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
|
2727 break; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2728 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2729 #endif |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2730 |
7 | 2731 if (eap->cmdidx == CMD_windo) |
2732 { | |
2733 validate_cursor(); /* cursor may have moved */ | |
2734 #ifdef FEAT_SCROLLBIND | |
2735 /* required when 'scrollbind' has been set */ | |
2736 if (curwin->w_p_scb) | |
2737 do_check_scrollbind(TRUE); | |
2738 #endif | |
2739 } | |
6474 | 2740 |
2741 #ifdef FEAT_WINDOWS | |
2742 if (eap->cmdidx == CMD_windo || eap->cmdidx == CMD_tabdo) | |
2743 if (i+1 > eap->line2) | |
2744 break; | |
2745 #endif | |
2746 if (eap->cmdidx == CMD_argdo && i >= eap->line2) | |
2747 break; | |
7 | 2748 } |
2749 listcmd_busy = FALSE; | |
2750 } | |
2751 | |
2752 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) | |
154 | 2753 if (save_ei != NULL) |
2754 { | |
2755 au_event_restore(save_ei); | |
2756 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, | |
2757 curbuf->b_fname, TRUE, curbuf); | |
2758 } | |
7 | 2759 #endif |
6116 | 2760 #ifdef FEAT_CLIPBOARD |
2761 end_global_changes(); | |
2762 #endif | |
7 | 2763 } |
2764 | |
2765 /* | |
2766 * Add files[count] to the arglist of the current window after arg "after". | |
2767 * The file names in files[count] must have been allocated and are taken over. | |
2768 * Files[] itself is not taken over. | |
2769 * Returns index of first added argument. Returns -1 when failed (out of mem). | |
2770 */ | |
2771 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2772 alist_add_list( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2773 int count, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2774 char_u **files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2775 int after) /* where to add: 0 = before first one */ |
7 | 2776 { |
2777 int i; | |
7647
65b2d593c203
commit https://github.com/vim/vim/commit/a24f0a550fed3d9773800cf6be4efd072fff20ec
Christian Brabandt <cb@256bit.org>
parents:
7639
diff
changeset
|
2778 int old_argcount = ARGCOUNT; |
7 | 2779 |
2780 if (ga_grow(&ALIST(curwin)->al_ga, count) == OK) | |
2781 { | |
2782 if (after < 0) | |
2783 after = 0; | |
2784 if (after > ARGCOUNT) | |
2785 after = ARGCOUNT; | |
2786 if (after < ARGCOUNT) | |
2787 mch_memmove(&(ARGLIST[after + count]), &(ARGLIST[after]), | |
2788 (ARGCOUNT - after) * sizeof(aentry_T)); | |
2789 for (i = 0; i < count; ++i) | |
2790 { | |
2791 ARGLIST[after + i].ae_fname = files[i]; | |
2792 ARGLIST[after + i].ae_fnum = buflist_add(files[i], BLN_LISTED); | |
2793 } | |
2794 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
|
2795 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
|
2796 curwin->w_arg_idx += count; |
7 | 2797 return after; |
2798 } | |
2799 | |
2800 for (i = 0; i < count; ++i) | |
2801 vim_free(files[i]); | |
2802 return -1; | |
2803 } | |
2804 | |
2805 #endif /* FEAT_LISTCMDS */ | |
2806 | |
2807 #ifdef FEAT_EVAL | |
2808 /* | |
2809 * ":compiler[!] {name}" | |
2810 */ | |
2811 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2812 ex_compiler(exarg_T *eap) |
7 | 2813 { |
2814 char_u *buf; | |
2815 char_u *old_cur_comp = NULL; | |
2816 char_u *p; | |
2817 | |
2818 if (*eap->arg == NUL) | |
2819 { | |
2820 /* List all compiler scripts. */ | |
2821 do_cmdline_cmd((char_u *)"echo globpath(&rtp, 'compiler/*.vim')"); | |
2822 /* ) keep the indenter happy... */ | |
2823 } | |
2824 else | |
2825 { | |
2826 buf = alloc((unsigned)(STRLEN(eap->arg) + 14)); | |
2827 if (buf != NULL) | |
2828 { | |
2829 if (eap->forceit) | |
2830 { | |
2831 /* ":compiler! {name}" sets global options */ | |
2832 do_cmdline_cmd((char_u *) | |
2833 "command -nargs=* CompilerSet set <args>"); | |
2834 } | |
2835 else | |
2836 { | |
2837 /* ":compiler! {name}" sets local options. | |
2838 * To remain backwards compatible "current_compiler" is always | |
2839 * used. A user's compiler plugin may set it, the distributed | |
2840 * 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
|
2841 * "b:current_compiler" and restore "current_compiler". |
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2842 * 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
|
2843 old_cur_comp = get_var_value((char_u *)"g:current_compiler"); |
7 | 2844 if (old_cur_comp != NULL) |
2845 old_cur_comp = vim_strsave(old_cur_comp); | |
2846 do_cmdline_cmd((char_u *) | |
2847 "command -nargs=* CompilerSet setlocal <args>"); | |
2848 } | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2849 do_unlet((char_u *)"g:current_compiler", TRUE); |
148 | 2850 do_unlet((char_u *)"b:current_compiler", TRUE); |
7 | 2851 |
2852 sprintf((char *)buf, "compiler/%s.vim", eap->arg); | |
480 | 2853 if (source_runtime(buf, TRUE) == FAIL) |
7 | 2854 EMSG2(_("E666: compiler not supported: %s"), eap->arg); |
2855 vim_free(buf); | |
2856 | |
2857 do_cmdline_cmd((char_u *)":delcommand CompilerSet"); | |
2858 | |
2859 /* Set "b:current_compiler" from "current_compiler". */ | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2860 p = get_var_value((char_u *)"g:current_compiler"); |
7 | 2861 if (p != NULL) |
2862 set_internal_string_var((char_u *)"b:current_compiler", p); | |
2863 | |
2864 /* Restore "current_compiler" for ":compiler {name}". */ | |
2865 if (!eap->forceit) | |
2866 { | |
2867 if (old_cur_comp != NULL) | |
2868 { | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2869 set_internal_string_var((char_u *)"g:current_compiler", |
7 | 2870 old_cur_comp); |
2871 vim_free(old_cur_comp); | |
2872 } | |
2873 else | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2874 do_unlet((char_u *)"g:current_compiler", TRUE); |
7 | 2875 } |
2876 } | |
2877 } | |
2878 } | |
2879 #endif | |
2880 | |
2881 /* | |
2882 * ":runtime {name}" | |
2883 */ | |
2884 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2885 ex_runtime(exarg_T *eap) |
7 | 2886 { |
480 | 2887 source_runtime(eap->arg, eap->forceit); |
7 | 2888 } |
2889 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
2890 static void source_callback(char_u *fname, void *cookie); |
237 | 2891 |
7 | 2892 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2893 source_callback(char_u *fname, void *cookie UNUSED) |
7 | 2894 { |
819 | 2895 (void)do_source(fname, FALSE, DOSO_NONE); |
7 | 2896 } |
2897 | |
2898 /* | |
2899 * Source the file "name" from all directories in 'runtimepath'. | |
2900 * "name" can contain wildcards. | |
2901 * When "all" is TRUE, source all files, otherwise only the first one. | |
2902 * return FAIL when no file could be sourced, OK otherwise. | |
2903 */ | |
2904 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2905 source_runtime(char_u *name, int all) |
7 | 2906 { |
237 | 2907 return do_in_runtimepath(name, all, source_callback, NULL); |
7 | 2908 } |
2909 | |
2910 /* | |
237 | 2911 * Find "name" in 'runtimepath'. When found, invoke the callback function for |
2912 * it: callback(fname, "cookie") | |
7 | 2913 * When "all" is TRUE repeat for all matches, otherwise only the first one is |
2914 * used. | |
2915 * Returns OK when at least one match found, FAIL otherwise. | |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2916 * |
6116 | 2917 * If "name" is NULL calls callback for each entry in runtimepath. Cookie is |
2918 * passed by reference in this case, setting it to NULL indicates that callback | |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2919 * has done its job. |
7 | 2920 */ |
2921 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2922 do_in_runtimepath( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2923 char_u *name, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2924 int all, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2925 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
|
2926 void *cookie) |
7 | 2927 { |
2928 char_u *rtp; | |
2929 char_u *np; | |
2930 char_u *buf; | |
2931 char_u *rtp_copy; | |
2932 char_u *tail; | |
2933 int num_files; | |
2934 char_u **files; | |
2935 int i; | |
2936 int did_one = FALSE; | |
2937 #ifdef AMIGA | |
2938 struct Process *proc = (struct Process *)FindTask(0L); | |
2939 APTR save_winptr = proc->pr_WindowPtr; | |
2940 | |
2941 /* Avoid a requester here for a volume that doesn't exist. */ | |
2942 proc->pr_WindowPtr = (APTR)-1L; | |
2943 #endif | |
2944 | |
2945 /* Make a copy of 'runtimepath'. Invoking the callback may change the | |
2946 * value. */ | |
2947 rtp_copy = vim_strsave(p_rtp); | |
2948 buf = alloc(MAXPATHL); | |
2949 if (buf != NULL && rtp_copy != NULL) | |
2950 { | |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2951 if (p_verbose > 1 && name != NULL) |
294 | 2952 { |
2953 verbose_enter(); | |
274 | 2954 smsg((char_u *)_("Searching for \"%s\" in \"%s\""), |
7 | 2955 (char *)name, (char *)p_rtp); |
294 | 2956 verbose_leave(); |
2957 } | |
271 | 2958 |
7 | 2959 /* Loop over all entries in 'runtimepath'. */ |
2960 rtp = rtp_copy; | |
2961 while (*rtp != NUL && (all || !did_one)) | |
2962 { | |
2963 /* Copy the path from 'runtimepath' to buf[]. */ | |
2964 copy_option_part(&rtp, buf, MAXPATHL, ","); | |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2965 if (name == NULL) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2966 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2967 (*callback)(buf, (void *) &cookie); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2968 if (!did_one) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2969 did_one = (cookie == NULL); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2970 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2971 else if (STRLEN(buf) + STRLEN(name) + 2 < MAXPATHL) |
7 | 2972 { |
2973 add_pathsep(buf); | |
2974 tail = buf + STRLEN(buf); | |
2975 | |
2976 /* Loop over all patterns in "name" */ | |
2977 np = name; | |
2978 while (*np != NUL && (all || !did_one)) | |
2979 { | |
2980 /* Append the pattern from "name" to buf[]. */ | |
2981 copy_option_part(&np, tail, (int)(MAXPATHL - (tail - buf)), | |
2982 "\t "); | |
2983 | |
2984 if (p_verbose > 2) | |
294 | 2985 { |
2986 verbose_enter(); | |
274 | 2987 smsg((char_u *)_("Searching for \"%s\""), buf); |
294 | 2988 verbose_leave(); |
2989 } | |
7 | 2990 |
2991 /* Expand wildcards, invoke the callback for each match. */ | |
2992 if (gen_expand_wildcards(1, &buf, &num_files, &files, | |
2993 EW_FILE) == OK) | |
2994 { | |
2995 for (i = 0; i < num_files; ++i) | |
2996 { | |
237 | 2997 (*callback)(files[i], cookie); |
7 | 2998 did_one = TRUE; |
2999 if (!all) | |
3000 break; | |
3001 } | |
3002 FreeWild(num_files, files); | |
3003 } | |
3004 } | |
3005 } | |
3006 } | |
3007 } | |
3008 vim_free(buf); | |
3009 vim_free(rtp_copy); | |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
3010 if (p_verbose > 0 && !did_one && name != NULL) |
294 | 3011 { |
3012 verbose_enter(); | |
274 | 3013 smsg((char_u *)_("not found in 'runtimepath': \"%s\""), name); |
294 | 3014 verbose_leave(); |
3015 } | |
7 | 3016 |
3017 #ifdef AMIGA | |
3018 proc->pr_WindowPtr = save_winptr; | |
3019 #endif | |
3020 | |
3021 return did_one ? OK : FAIL; | |
3022 } | |
3023 | |
3024 #if defined(FEAT_EVAL) && defined(FEAT_AUTOCMD) | |
3025 /* | |
3026 * ":options" | |
3027 */ | |
3028 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3029 ex_options( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3030 exarg_T *eap UNUSED) |
7 | 3031 { |
3032 cmd_source((char_u *)SYS_OPTWIN_FILE, NULL); | |
3033 } | |
3034 #endif | |
3035 | |
3036 /* | |
3037 * ":source {fname}" | |
3038 */ | |
3039 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3040 ex_source(exarg_T *eap) |
7 | 3041 { |
3042 #ifdef FEAT_BROWSE | |
3043 if (cmdmod.browse) | |
3044 { | |
3045 char_u *fname = NULL; | |
3046 | |
29 | 3047 fname = do_browse(0, (char_u *)_("Source Vim script"), eap->arg, |
7 | 3048 NULL, NULL, BROWSE_FILTER_MACROS, NULL); |
3049 if (fname != NULL) | |
3050 { | |
3051 cmd_source(fname, eap); | |
3052 vim_free(fname); | |
3053 } | |
3054 } | |
3055 else | |
3056 #endif | |
3057 cmd_source(eap->arg, eap); | |
3058 } | |
3059 | |
3060 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3061 cmd_source(char_u *fname, exarg_T *eap) |
7 | 3062 { |
3063 if (*fname == NUL) | |
3064 EMSG(_(e_argreq)); | |
3065 | |
3066 else if (eap != NULL && eap->forceit) | |
4352 | 3067 /* ":source!": read Normal mode commands |
716 | 3068 * Need to execute the commands directly. This is required at least |
3069 * for: | |
7 | 3070 * - ":g" command busy |
3071 * - after ":argdo", ":windo" or ":bufdo" | |
3072 * - another command follows | |
3073 * - inside a loop | |
3074 */ | |
3075 openscript(fname, global_busy || listcmd_busy || eap->nextcmd != NULL | |
3076 #ifdef FEAT_EVAL | |
3077 || eap->cstack->cs_idx >= 0 | |
3078 #endif | |
3079 ); | |
3080 | |
3081 /* ":source" read ex commands */ | |
819 | 3082 else if (do_source(fname, FALSE, DOSO_NONE) == FAIL) |
7 | 3083 EMSG2(_(e_notopen), fname); |
3084 } | |
3085 | |
3086 /* | |
3087 * ":source" and associated commands. | |
3088 */ | |
3089 /* | |
3090 * Structure used to store info for each sourced file. | |
3091 * It is shared between do_source() and getsourceline(). | |
3092 * This is required, because it needs to be handed to do_cmdline() and | |
3093 * sourcing can be done recursively. | |
3094 */ | |
3095 struct source_cookie | |
3096 { | |
3097 FILE *fp; /* opened file for sourcing */ | |
3098 char_u *nextline; /* if not NULL: line that was read ahead */ | |
3099 int finished; /* ":finish" used */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
3100 #if defined(USE_CRNL) || defined(USE_CR) |
7 | 3101 int fileformat; /* EOL_UNKNOWN, EOL_UNIX or EOL_DOS */ |
3102 int error; /* TRUE if LF found after CR-LF */ | |
3103 #endif | |
3104 #ifdef FEAT_EVAL | |
3105 linenr_T breakpoint; /* next line with breakpoint or zero */ | |
3106 char_u *fname; /* name of sourced file */ | |
3107 int dbg_tick; /* debug_tick when breakpoint was set */ | |
3108 int level; /* top nesting level of sourced file */ | |
3109 #endif | |
3110 #ifdef FEAT_MBYTE | |
3111 vimconv_T conv; /* type of conversion */ | |
3112 #endif | |
3113 }; | |
3114 | |
3115 #ifdef FEAT_EVAL | |
3116 /* | |
3117 * Return the address holding the next breakpoint line for a source cookie. | |
3118 */ | |
3119 linenr_T * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3120 source_breakpoint(void *cookie) |
7 | 3121 { |
3122 return &((struct source_cookie *)cookie)->breakpoint; | |
3123 } | |
3124 | |
3125 /* | |
3126 * Return the address holding the debug tick for a source cookie. | |
3127 */ | |
3128 int * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3129 source_dbg_tick(void *cookie) |
7 | 3130 { |
3131 return &((struct source_cookie *)cookie)->dbg_tick; | |
3132 } | |
3133 | |
3134 /* | |
3135 * Return the nesting level for a source cookie. | |
3136 */ | |
3137 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3138 source_level(void *cookie) |
7 | 3139 { |
3140 return ((struct source_cookie *)cookie)->level; | |
3141 } | |
3142 #endif | |
3143 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
3144 static char_u *get_one_sourceline(struct source_cookie *sp); |
7 | 3145 |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3146 #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
|
3147 # define USE_FOPEN_NOINH |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
3148 static FILE *fopen_noinh_readbin(char *filename); |
7 | 3149 |
3150 /* | |
3151 * 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
|
3152 * When possible the handle is closed on exec(). |
7 | 3153 */ |
3154 static FILE * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3155 fopen_noinh_readbin(char *filename) |
7 | 3156 { |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3157 # ifdef WIN32 |
2058
fb1222c880fc
updated for version 7.2.344
Bram Moolenaar <bram@zimbu.org>
parents:
2057
diff
changeset
|
3158 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
|
3159 # else |
fb1222c880fc
updated for version 7.2.344
Bram Moolenaar <bram@zimbu.org>
parents:
2057
diff
changeset
|
3160 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
|
3161 # endif |
7 | 3162 |
3163 if (fd_tmp == -1) | |
3164 return NULL; | |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3165 |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3166 # ifdef HAVE_FD_CLOEXEC |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3167 { |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3168 int fdflags = fcntl(fd_tmp, F_GETFD); |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3169 if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0) |
7009 | 3170 (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
|
3171 } |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3172 # endif |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3173 |
7 | 3174 return fdopen(fd_tmp, READBIN); |
3175 } | |
3176 #endif | |
3177 | |
3178 | |
3179 /* | |
3180 * do_source: Read the file "fname" and execute its lines as EX commands. | |
3181 * | |
3182 * This function may be called recursively! | |
3183 * | |
3184 * return FAIL if file could not be opened, OK otherwise | |
3185 */ | |
3186 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3187 do_source( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3188 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3189 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
|
3190 int is_vimrc) /* DOSO_ value */ |
7 | 3191 { |
3192 struct source_cookie cookie; | |
3193 char_u *save_sourcing_name; | |
3194 linenr_T save_sourcing_lnum; | |
3195 char_u *p; | |
3196 char_u *fname_exp; | |
1802 | 3197 char_u *firstline = NULL; |
7 | 3198 int retval = FAIL; |
3199 #ifdef FEAT_EVAL | |
3200 scid_T save_current_SID; | |
3201 static scid_T last_current_SID = 0; | |
3202 void *save_funccalp; | |
3203 int save_debug_break_level = debug_break_level; | |
170 | 3204 scriptitem_T *si = NULL; |
7 | 3205 # ifdef UNIX |
3206 struct stat st; | |
3207 int stat_ok; | |
3208 # endif | |
3209 #endif | |
3210 #ifdef STARTUPTIME | |
3211 struct timeval tv_rel; | |
3212 struct timeval tv_start; | |
3213 #endif | |
170 | 3214 #ifdef FEAT_PROFILE |
3215 proftime_T wait_start; | |
3216 #endif | |
7 | 3217 |
3218 p = expand_env_save(fname); | |
3219 if (p == NULL) | |
3220 return retval; | |
3221 fname_exp = fix_fname(p); | |
3222 vim_free(p); | |
3223 if (fname_exp == NULL) | |
3224 return retval; | |
3225 if (mch_isdir(fname_exp)) | |
3226 { | |
274 | 3227 smsg((char_u *)_("Cannot source a directory: \"%s\""), fname); |
7 | 3228 goto theend; |
3229 } | |
3230 | |
716 | 3231 #ifdef FEAT_AUTOCMD |
1061 | 3232 /* Apply SourceCmd autocommands, they should get the file and source it. */ |
3233 if (has_autocmd(EVENT_SOURCECMD, fname_exp, NULL) | |
3234 && apply_autocmds(EVENT_SOURCECMD, fname_exp, fname_exp, | |
3235 FALSE, curbuf)) | |
1515 | 3236 { |
1061 | 3237 # ifdef FEAT_EVAL |
1515 | 3238 retval = aborting() ? FAIL : OK; |
1061 | 3239 # else |
1515 | 3240 retval = OK; |
1061 | 3241 # endif |
1515 | 3242 goto theend; |
3243 } | |
1061 | 3244 |
3245 /* Apply SourcePre autocommands, they may get the file. */ | |
716 | 3246 apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf); |
3247 #endif | |
3248 | |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3249 #ifdef USE_FOPEN_NOINH |
7 | 3250 cookie.fp = fopen_noinh_readbin((char *)fname_exp); |
3251 #else | |
3252 cookie.fp = mch_fopen((char *)fname_exp, READBIN); | |
3253 #endif | |
3254 if (cookie.fp == NULL && check_other) | |
3255 { | |
3256 /* | |
3257 * Try again, replacing file name ".vimrc" by "_vimrc" or vice versa, | |
3258 * and ".exrc" by "_exrc" or vice versa. | |
3259 */ | |
3260 p = gettail(fname_exp); | |
3261 if ((*p == '.' || *p == '_') | |
3262 && (STRICMP(p + 1, "vimrc") == 0 | |
3263 || STRICMP(p + 1, "gvimrc") == 0 | |
3264 || STRICMP(p + 1, "exrc") == 0)) | |
3265 { | |
3266 if (*p == '_') | |
3267 *p = '.'; | |
3268 else | |
3269 *p = '_'; | |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3270 #ifdef USE_FOPEN_NOINH |
7 | 3271 cookie.fp = fopen_noinh_readbin((char *)fname_exp); |
3272 #else | |
3273 cookie.fp = mch_fopen((char *)fname_exp, READBIN); | |
3274 #endif | |
3275 } | |
3276 } | |
3277 | |
3278 if (cookie.fp == NULL) | |
3279 { | |
3280 if (p_verbose > 0) | |
3281 { | |
294 | 3282 verbose_enter(); |
7 | 3283 if (sourcing_name == NULL) |
274 | 3284 smsg((char_u *)_("could not source \"%s\""), fname); |
7 | 3285 else |
3286 smsg((char_u *)_("line %ld: could not source \"%s\""), | |
274 | 3287 sourcing_lnum, fname); |
294 | 3288 verbose_leave(); |
7 | 3289 } |
3290 goto theend; | |
3291 } | |
3292 | |
3293 /* | |
3294 * The file exists. | |
3295 * - In verbose mode, give a message. | |
3296 * - For a vimrc file, may want to set 'compatible', call vimrc_found(). | |
3297 */ | |
3298 if (p_verbose > 1) | |
3299 { | |
294 | 3300 verbose_enter(); |
7 | 3301 if (sourcing_name == NULL) |
274 | 3302 smsg((char_u *)_("sourcing \"%s\""), fname); |
7 | 3303 else |
3304 smsg((char_u *)_("line %ld: sourcing \"%s\""), | |
274 | 3305 sourcing_lnum, fname); |
294 | 3306 verbose_leave(); |
7 | 3307 } |
819 | 3308 if (is_vimrc == DOSO_VIMRC) |
3309 vimrc_found(fname_exp, (char_u *)"MYVIMRC"); | |
3310 else if (is_vimrc == DOSO_GVIMRC) | |
3311 vimrc_found(fname_exp, (char_u *)"MYGVIMRC"); | |
7 | 3312 |
3313 #ifdef USE_CRNL | |
3314 /* If no automatic file format: Set default to CR-NL. */ | |
3315 if (*p_ffs == NUL) | |
3316 cookie.fileformat = EOL_DOS; | |
3317 else | |
3318 cookie.fileformat = EOL_UNKNOWN; | |
3319 cookie.error = FALSE; | |
3320 #endif | |
3321 | |
3322 #ifdef USE_CR | |
3323 /* If no automatic file format: Set default to CR. */ | |
3324 if (*p_ffs == NUL) | |
3325 cookie.fileformat = EOL_MAC; | |
3326 else | |
3327 cookie.fileformat = EOL_UNKNOWN; | |
3328 cookie.error = FALSE; | |
3329 #endif | |
3330 | |
3331 cookie.nextline = NULL; | |
3332 cookie.finished = FALSE; | |
3333 | |
3334 #ifdef FEAT_EVAL | |
3335 /* | |
3336 * Check if this script has a breakpoint. | |
3337 */ | |
3338 cookie.breakpoint = dbg_find_breakpoint(TRUE, fname_exp, (linenr_T)0); | |
3339 cookie.fname = fname_exp; | |
3340 cookie.dbg_tick = debug_tick; | |
3341 | |
3342 cookie.level = ex_nesting_level; | |
3343 #endif | |
3344 | |
3345 /* | |
3346 * Keep the sourcing name/lnum, for recursive calls. | |
3347 */ | |
3348 save_sourcing_name = sourcing_name; | |
3349 sourcing_name = fname_exp; | |
3350 save_sourcing_lnum = sourcing_lnum; | |
3351 sourcing_lnum = 0; | |
3352 | |
1802 | 3353 #ifdef FEAT_MBYTE |
3354 cookie.conv.vc_type = CONV_NONE; /* no conversion */ | |
3355 | |
3356 /* Read the first line so we can check for a UTF-8 BOM. */ | |
3357 firstline = getsourceline(0, (void *)&cookie, 0); | |
3358 if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef | |
3359 && firstline[1] == 0xbb && firstline[2] == 0xbf) | |
3360 { | |
3361 /* Found BOM; setup conversion, skip over BOM and recode the line. */ | |
3362 convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc); | |
3363 p = string_convert(&cookie.conv, firstline + 3, NULL); | |
1804 | 3364 if (p == NULL) |
3365 p = vim_strsave(firstline + 3); | |
1802 | 3366 if (p != NULL) |
3367 { | |
3368 vim_free(firstline); | |
3369 firstline = p; | |
3370 } | |
3371 } | |
3372 #endif | |
3373 | |
7 | 3374 #ifdef STARTUPTIME |
2053
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3375 if (time_fd != NULL) |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3376 time_push(&tv_rel, &tv_start); |
7 | 3377 #endif |
3378 | |
3379 #ifdef FEAT_EVAL | |
170 | 3380 # ifdef FEAT_PROFILE |
790 | 3381 if (do_profiling == PROF_YES) |
170 | 3382 prof_child_enter(&wait_start); /* entering a child now */ |
3383 # endif | |
3384 | |
3385 /* Don't use local function variables, if called from a function. | |
3386 * Also starts profiling timer for nested script. */ | |
3387 save_funccalp = save_funccal(); | |
3388 | |
7 | 3389 /* |
3390 * Check if this script was sourced before to finds its SID. | |
3391 * If it's new, generate a new SID. | |
3392 */ | |
3393 save_current_SID = current_SID; | |
3394 # ifdef UNIX | |
3395 stat_ok = (mch_stat((char *)fname_exp, &st) >= 0); | |
3396 # endif | |
170 | 3397 for (current_SID = script_items.ga_len; current_SID > 0; --current_SID) |
3398 { | |
3399 si = &SCRIPT_ITEM(current_SID); | |
3400 if (si->sn_name != NULL | |
7 | 3401 && ( |
3402 # ifdef UNIX | |
161 | 3403 /* Compare dev/ino when possible, it catches symbolic |
3404 * links. Also compare file names, the inode may change | |
3405 * when the file was edited. */ | |
1882 | 3406 ((stat_ok && si->sn_dev_valid) |
170 | 3407 && (si->sn_dev == st.st_dev |
3408 && si->sn_ino == st.st_ino)) || | |
7 | 3409 # endif |
170 | 3410 fnamecmp(si->sn_name, fname_exp) == 0)) |
7 | 3411 break; |
170 | 3412 } |
7 | 3413 if (current_SID == 0) |
3414 { | |
3415 current_SID = ++last_current_SID; | |
170 | 3416 if (ga_grow(&script_items, (int)(current_SID - script_items.ga_len)) |
3417 == FAIL) | |
3418 goto almosttheend; | |
3419 while (script_items.ga_len < current_SID) | |
7 | 3420 { |
170 | 3421 ++script_items.ga_len; |
3422 SCRIPT_ITEM(script_items.ga_len).sn_name = NULL; | |
3423 # ifdef FEAT_PROFILE | |
3424 SCRIPT_ITEM(script_items.ga_len).sn_prof_on = FALSE; | |
3425 # endif | |
3426 } | |
3427 si = &SCRIPT_ITEM(current_SID); | |
3428 si->sn_name = fname_exp; | |
3429 fname_exp = NULL; | |
7 | 3430 # ifdef UNIX |
170 | 3431 if (stat_ok) |
3432 { | |
1882 | 3433 si->sn_dev_valid = TRUE; |
170 | 3434 si->sn_dev = st.st_dev; |
3435 si->sn_ino = st.st_ino; | |
3436 } | |
3437 else | |
1882 | 3438 si->sn_dev_valid = FALSE; |
7 | 3439 # endif |
170 | 3440 |
7 | 3441 /* Allocate the local script variables to use for this script. */ |
3442 new_script_vars(current_SID); | |
3443 } | |
3444 | |
170 | 3445 # ifdef FEAT_PROFILE |
790 | 3446 if (do_profiling == PROF_YES) |
170 | 3447 { |
3448 int forceit; | |
3449 | |
3450 /* Check if we do profiling for this script. */ | |
3451 if (!si->sn_prof_on && has_profiling(TRUE, si->sn_name, &forceit)) | |
3452 { | |
3453 script_do_profile(si); | |
3454 si->sn_pr_force = forceit; | |
3455 } | |
3456 if (si->sn_prof_on) | |
3457 { | |
3458 ++si->sn_pr_count; | |
3459 profile_start(&si->sn_pr_start); | |
3460 profile_zero(&si->sn_pr_children); | |
3461 } | |
3462 } | |
3463 # endif | |
7 | 3464 #endif |
3465 | |
3466 /* | |
3467 * Call do_cmdline, which will call getsourceline() to get the lines. | |
3468 */ | |
1802 | 3469 do_cmdline(firstline, getsourceline, (void *)&cookie, |
7 | 3470 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT); |
3471 retval = OK; | |
170 | 3472 |
3473 #ifdef FEAT_PROFILE | |
790 | 3474 if (do_profiling == PROF_YES) |
170 | 3475 { |
3476 /* Get "si" again, "script_items" may have been reallocated. */ | |
3477 si = &SCRIPT_ITEM(current_SID); | |
3478 if (si->sn_prof_on) | |
3479 { | |
3480 profile_end(&si->sn_pr_start); | |
3481 profile_sub_wait(&wait_start, &si->sn_pr_start); | |
3482 profile_add(&si->sn_pr_total, &si->sn_pr_start); | |
720 | 3483 profile_self(&si->sn_pr_self, &si->sn_pr_start, |
3484 &si->sn_pr_children); | |
170 | 3485 } |
3486 } | |
7 | 3487 #endif |
3488 | |
3489 if (got_int) | |
3490 EMSG(_(e_interr)); | |
3491 sourcing_name = save_sourcing_name; | |
3492 sourcing_lnum = save_sourcing_lnum; | |
3493 if (p_verbose > 1) | |
3494 { | |
294 | 3495 verbose_enter(); |
274 | 3496 smsg((char_u *)_("finished sourcing %s"), fname); |
7 | 3497 if (sourcing_name != NULL) |
274 | 3498 smsg((char_u *)_("continuing in %s"), sourcing_name); |
294 | 3499 verbose_leave(); |
7 | 3500 } |
3501 #ifdef STARTUPTIME | |
2053
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3502 if (time_fd != NULL) |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3503 { |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3504 vim_snprintf((char *)IObuff, IOSIZE, "sourcing %s", fname); |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3505 time_msg((char *)IObuff, &tv_start); |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3506 time_pop(&tv_rel); |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3507 } |
7 | 3508 #endif |
3509 | |
3510 #ifdef FEAT_EVAL | |
3511 /* | |
3512 * After a "finish" in debug mode, need to break at first command of next | |
3513 * sourced file. | |
3514 */ | |
3515 if (save_debug_break_level > ex_nesting_level | |
3516 && debug_break_level == ex_nesting_level) | |
3517 ++debug_break_level; | |
3518 #endif | |
3519 | |
170 | 3520 #ifdef FEAT_EVAL |
3521 almosttheend: | |
3522 current_SID = save_current_SID; | |
3523 restore_funccal(save_funccalp); | |
3524 # ifdef FEAT_PROFILE | |
790 | 3525 if (do_profiling == PROF_YES) |
170 | 3526 prof_child_exit(&wait_start); /* leaving a child now */ |
3527 # endif | |
3528 #endif | |
3529 fclose(cookie.fp); | |
3530 vim_free(cookie.nextline); | |
1802 | 3531 vim_free(firstline); |
170 | 3532 #ifdef FEAT_MBYTE |
3533 convert_setup(&cookie.conv, NULL, NULL); | |
3534 #endif | |
3535 | |
7 | 3536 theend: |
3537 vim_free(fname_exp); | |
3538 return retval; | |
3539 } | |
3540 | |
3541 #if defined(FEAT_EVAL) || defined(PROTO) | |
356 | 3542 |
7 | 3543 /* |
3544 * ":scriptnames" | |
3545 */ | |
3546 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3547 ex_scriptnames(exarg_T *eap UNUSED) |
7 | 3548 { |
3549 int i; | |
3550 | |
170 | 3551 for (i = 1; i <= script_items.ga_len && !got_int; ++i) |
3552 if (SCRIPT_ITEM(i).sn_name != NULL) | |
2921 | 3553 { |
3554 home_replace(NULL, SCRIPT_ITEM(i).sn_name, | |
3555 NameBuff, MAXPATHL, TRUE); | |
3556 smsg((char_u *)"%3d: %s", i, NameBuff); | |
3429 | 3557 } |
7 | 3558 } |
3559 | |
3560 # if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) | |
3561 /* | |
3562 * Fix slashes in the list of script names for 'shellslash'. | |
3563 */ | |
3564 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3565 scriptnames_slash_adjust(void) |
7 | 3566 { |
3567 int i; | |
3568 | |
170 | 3569 for (i = 1; i <= script_items.ga_len; ++i) |
3570 if (SCRIPT_ITEM(i).sn_name != NULL) | |
3571 slash_adjust(SCRIPT_ITEM(i).sn_name); | |
7 | 3572 } |
3573 # endif | |
3574 | |
3575 /* | |
3576 * Get a pointer to a script name. Used for ":verbose set". | |
3577 */ | |
3578 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3579 get_scriptname(scid_T id) |
7 | 3580 { |
3581 if (id == SID_MODELINE) | |
681 | 3582 return (char_u *)_("modeline"); |
7 | 3583 if (id == SID_CMDARG) |
681 | 3584 return (char_u *)_("--cmd argument"); |
7 | 3585 if (id == SID_CARG) |
681 | 3586 return (char_u *)_("-c argument"); |
7 | 3587 if (id == SID_ENV) |
681 | 3588 return (char_u *)_("environment variable"); |
3589 if (id == SID_ERROR) | |
3590 return (char_u *)_("error handler"); | |
170 | 3591 return SCRIPT_ITEM(id).sn_name; |
3592 } | |
3593 | |
356 | 3594 # if defined(EXITFREE) || defined(PROTO) |
3595 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3596 free_scriptnames(void) |
356 | 3597 { |
3598 int i; | |
3599 | |
3600 for (i = script_items.ga_len; i > 0; --i) | |
3601 vim_free(SCRIPT_ITEM(i).sn_name); | |
3602 ga_clear(&script_items); | |
3603 } | |
3604 # endif | |
3605 | |
7 | 3606 #endif |
3607 | |
3608 #if defined(USE_CR) || defined(PROTO) | |
3609 | |
3610 # if defined(__MSL__) && (__MSL__ >= 22) | |
3611 /* | |
3612 * Newer version of the Metrowerks library handle DOS and UNIX files | |
3613 * without help. | |
3614 * Test with earlier versions, MSL 2.2 is the library supplied with | |
3615 * Codewarrior Pro 2. | |
3616 */ | |
3617 char * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3618 fgets_cr(char *s, int n, FILE *stream) |
7 | 3619 { |
3620 return fgets(s, n, stream); | |
3621 } | |
3622 # else | |
3623 /* | |
3624 * Version of fgets() which also works for lines ending in a <CR> only | |
3625 * (Macintosh format). | |
3626 * For older versions of the Metrowerks library. | |
3627 * At least CodeWarrior 9 needed this code. | |
3628 */ | |
3629 char * | |
7856
226ed297307f
commit https://github.com/vim/vim/commit/d14e00ea67afbaa8cb4a7e6b1eb306da6a2d5adb
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
3630 fgets_cr(char *s, int n, FILE *stream) |
7 | 3631 { |
3632 int c = 0; | |
3633 int char_read = 0; | |
3634 | |
3635 while (!feof(stream) && c != '\r' && c != '\n' && char_read < n - 1) | |
3636 { | |
3637 c = fgetc(stream); | |
3638 s[char_read++] = c; | |
3639 /* If the file is in DOS format, we need to skip a NL after a CR. I | |
3640 * thought it was the other way around, but this appears to work... */ | |
3641 if (c == '\n') | |
3642 { | |
3643 c = fgetc(stream); | |
3644 if (c != '\r') | |
3645 ungetc(c, stream); | |
3646 } | |
3647 } | |
3648 | |
3649 s[char_read] = 0; | |
3650 if (char_read == 0) | |
3651 return NULL; | |
3652 | |
3653 if (feof(stream) && char_read == 1) | |
3654 return NULL; | |
3655 | |
3656 return s; | |
3657 } | |
3658 # endif | |
3659 #endif | |
3660 | |
3661 /* | |
3662 * Get one full line from a sourced file. | |
3663 * Called by do_cmdline() when it's called from do_source(). | |
3664 * | |
3665 * Return a pointer to the line in allocated memory. | |
3666 * Return NULL for end-of-file or some error. | |
3667 */ | |
3668 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3669 getsourceline(int c UNUSED, void *cookie, int indent UNUSED) |
7 | 3670 { |
3671 struct source_cookie *sp = (struct source_cookie *)cookie; | |
3672 char_u *line; | |
3336 | 3673 char_u *p; |
7 | 3674 |
3675 #ifdef FEAT_EVAL | |
3676 /* If breakpoints have been added/deleted need to check for it. */ | |
3677 if (sp->dbg_tick < debug_tick) | |
3678 { | |
3679 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum); | |
3680 sp->dbg_tick = debug_tick; | |
3681 } | |
170 | 3682 # ifdef FEAT_PROFILE |
790 | 3683 if (do_profiling == PROF_YES) |
170 | 3684 script_line_end(); |
3685 # endif | |
7 | 3686 #endif |
3687 /* | |
3688 * Get current line. If there is a read-ahead line, use it, otherwise get | |
3689 * one now. | |
3690 */ | |
3691 if (sp->finished) | |
3692 line = NULL; | |
3693 else if (sp->nextline == NULL) | |
3694 line = get_one_sourceline(sp); | |
3695 else | |
3696 { | |
3697 line = sp->nextline; | |
3698 sp->nextline = NULL; | |
3699 ++sourcing_lnum; | |
205 | 3700 } |
170 | 3701 #ifdef FEAT_PROFILE |
790 | 3702 if (line != NULL && do_profiling == PROF_YES) |
205 | 3703 script_line_start(); |
3704 #endif | |
7 | 3705 |
3706 /* Only concatenate lines starting with a \ when 'cpoptions' doesn't | |
3707 * contain the 'C' flag. */ | |
3708 if (line != NULL && (vim_strchr(p_cpo, CPO_CONCAT) == NULL)) | |
3709 { | |
3710 /* compensate for the one line read-ahead */ | |
3711 --sourcing_lnum; | |
3332 | 3712 |
3713 /* Get the next line and concatenate it when it starts with a | |
3714 * backslash. We always need to read the next line, keep it in | |
3715 * sp->nextline. */ | |
3716 sp->nextline = get_one_sourceline(sp); | |
3717 if (sp->nextline != NULL && *(p = skipwhite(sp->nextline)) == '\\') | |
7 | 3718 { |
3332 | 3719 garray_T ga; |
3720 | |
3378 | 3721 ga_init2(&ga, (int)sizeof(char_u), 400); |
3332 | 3722 ga_concat(&ga, line); |
3723 ga_concat(&ga, p + 1); | |
3724 for (;;) | |
3725 { | |
3726 vim_free(sp->nextline); | |
3727 sp->nextline = get_one_sourceline(sp); | |
3728 if (sp->nextline == NULL) | |
3729 break; | |
3730 p = skipwhite(sp->nextline); | |
3731 if (*p != '\\') | |
3732 break; | |
3378 | 3733 /* Adjust the growsize to the current length to speed up |
3734 * concatenating many lines. */ | |
3735 if (ga.ga_len > 400) | |
3736 { | |
3737 if (ga.ga_len > 8000) | |
3738 ga.ga_growsize = 8000; | |
3739 else | |
3740 ga.ga_growsize = ga.ga_len; | |
3741 } | |
3332 | 3742 ga_concat(&ga, p + 1); |
3743 } | |
3744 ga_append(&ga, NUL); | |
7 | 3745 vim_free(line); |
3332 | 3746 line = ga.ga_data; |
7 | 3747 } |
3748 } | |
3749 | |
3750 #ifdef FEAT_MBYTE | |
3751 if (line != NULL && sp->conv.vc_type != CONV_NONE) | |
3752 { | |
3336 | 3753 char_u *s; |
3754 | |
7 | 3755 /* Convert the encoding of the script line. */ |
3756 s = string_convert(&sp->conv, line, NULL); | |
3757 if (s != NULL) | |
3758 { | |
3759 vim_free(line); | |
3760 line = s; | |
3761 } | |
3762 } | |
3763 #endif | |
3764 | |
3765 #ifdef FEAT_EVAL | |
3766 /* Did we encounter a breakpoint? */ | |
3767 if (sp->breakpoint != 0 && sp->breakpoint <= sourcing_lnum) | |
3768 { | |
3769 dbg_breakpoint(sp->fname, sourcing_lnum); | |
3770 /* Find next breakpoint. */ | |
3771 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum); | |
3772 sp->dbg_tick = debug_tick; | |
3773 } | |
3774 #endif | |
3775 | |
3776 return line; | |
3777 } | |
3778 | |
3779 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3780 get_one_sourceline(struct source_cookie *sp) |
7 | 3781 { |
3782 garray_T ga; | |
3783 int len; | |
3784 int c; | |
3785 char_u *buf; | |
3786 #ifdef USE_CRNL | |
3787 int has_cr; /* CR-LF found */ | |
3788 #endif | |
3789 #ifdef USE_CR | |
3790 char_u *scan; | |
3791 #endif | |
3792 int have_read = FALSE; | |
3793 | |
3794 /* use a growarray to store the sourced line */ | |
154 | 3795 ga_init2(&ga, 1, 250); |
7 | 3796 |
3797 /* | |
3798 * Loop until there is a finished line (or end-of-file). | |
3799 */ | |
3800 sourcing_lnum++; | |
3801 for (;;) | |
3802 { | |
154 | 3803 /* make room to read at least 120 (more) characters */ |
3804 if (ga_grow(&ga, 120) == FAIL) | |
7 | 3805 break; |
3806 buf = (char_u *)ga.ga_data; | |
3807 | |
3808 #ifdef USE_CR | |
3809 if (sp->fileformat == EOL_MAC) | |
3810 { | |
41 | 3811 if (fgets_cr((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len, |
3812 sp->fp) == NULL) | |
7 | 3813 break; |
3814 } | |
3815 else | |
3816 #endif | |
41 | 3817 if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len, |
3818 sp->fp) == NULL) | |
7 | 3819 break; |
154 | 3820 len = ga.ga_len + (int)STRLEN(buf + ga.ga_len); |
7 | 3821 #ifdef USE_CRNL |
3822 /* Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the | |
3823 * CTRL-Z by its own, or after a NL. */ | |
3824 if ( (len == 1 || (len >= 2 && buf[len - 2] == '\n')) | |
3825 && sp->fileformat == EOL_DOS | |
3826 && buf[len - 1] == Ctrl_Z) | |
3827 { | |
3828 buf[len - 1] = NUL; | |
3829 break; | |
3830 } | |
3831 #endif | |
3832 | |
3833 #ifdef USE_CR | |
3834 /* If the read doesn't stop on a new line, and there's | |
3835 * some CR then we assume a Mac format */ | |
3836 if (sp->fileformat == EOL_UNKNOWN) | |
3837 { | |
3838 if (buf[len - 1] != '\n' && vim_strchr(buf, '\r') != NULL) | |
3839 sp->fileformat = EOL_MAC; | |
3840 else | |
3841 sp->fileformat = EOL_UNIX; | |
3842 } | |
3843 | |
3844 if (sp->fileformat == EOL_MAC) | |
3845 { | |
3846 scan = vim_strchr(buf, '\r'); | |
3847 | |
3848 if (scan != NULL) | |
3849 { | |
3850 *scan = '\n'; | |
3851 if (*(scan + 1) != 0) | |
3852 { | |
3853 *(scan + 1) = 0; | |
3854 fseek(sp->fp, (long)(scan - buf - len + 1), SEEK_CUR); | |
3855 } | |
3856 } | |
3857 len = STRLEN(buf); | |
3858 } | |
3859 #endif | |
3860 | |
3861 have_read = TRUE; | |
3862 ga.ga_len = len; | |
3863 | |
3864 /* If the line was longer than the buffer, read more. */ | |
41 | 3865 if (ga.ga_maxlen - ga.ga_len == 1 && buf[len - 1] != '\n') |
7 | 3866 continue; |
3867 | |
3868 if (len >= 1 && buf[len - 1] == '\n') /* remove trailing NL */ | |
3869 { | |
3870 #ifdef USE_CRNL | |
3871 has_cr = (len >= 2 && buf[len - 2] == '\r'); | |
3872 if (sp->fileformat == EOL_UNKNOWN) | |
3873 { | |
3874 if (has_cr) | |
3875 sp->fileformat = EOL_DOS; | |
3876 else | |
3877 sp->fileformat = EOL_UNIX; | |
3878 } | |
3879 | |
3880 if (sp->fileformat == EOL_DOS) | |
3881 { | |
3882 if (has_cr) /* replace trailing CR */ | |
3883 { | |
3884 buf[len - 2] = '\n'; | |
3885 --len; | |
3886 --ga.ga_len; | |
3887 } | |
3888 else /* lines like ":map xx yy^M" will have failed */ | |
3889 { | |
3890 if (!sp->error) | |
16 | 3891 { |
3892 msg_source(hl_attr(HLF_W)); | |
7 | 3893 EMSG(_("W15: Warning: Wrong line separator, ^M may be missing")); |
16 | 3894 } |
7 | 3895 sp->error = TRUE; |
3896 sp->fileformat = EOL_UNIX; | |
3897 } | |
3898 } | |
3899 #endif | |
3900 /* The '\n' is escaped if there is an odd number of ^V's just | |
3901 * before it, first set "c" just before the 'V's and then check | |
3902 * len&c parities (is faster than ((len-c)%2 == 0)) -- Acevedo */ | |
3903 for (c = len - 2; c >= 0 && buf[c] == Ctrl_V; c--) | |
3904 ; | |
3905 if ((len & 1) != (c & 1)) /* escaped NL, read more */ | |
3906 { | |
3907 sourcing_lnum++; | |
3908 continue; | |
3909 } | |
3910 | |
3911 buf[len - 1] = NUL; /* remove the NL */ | |
3912 } | |
3913 | |
3914 /* | |
3915 * Check for ^C here now and then, so recursive :so can be broken. | |
3916 */ | |
3917 line_breakcheck(); | |
3918 break; | |
3919 } | |
3920 | |
3921 if (have_read) | |
3922 return (char_u *)ga.ga_data; | |
3923 | |
3924 vim_free(ga.ga_data); | |
3925 return NULL; | |
3926 } | |
3927 | |
170 | 3928 #if defined(FEAT_PROFILE) || defined(PROTO) |
3929 /* | |
3930 * Called when starting to read a script line. | |
3931 * "sourcing_lnum" must be correct! | |
3932 * When skipping lines it may not actually be executed, but we won't find out | |
3933 * until later and we need to store the time now. | |
3934 */ | |
3935 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3936 script_line_start(void) |
170 | 3937 { |
3938 scriptitem_T *si; | |
3939 sn_prl_T *pp; | |
3940 | |
3941 if (current_SID <= 0 || current_SID > script_items.ga_len) | |
3942 return; | |
3943 si = &SCRIPT_ITEM(current_SID); | |
3944 if (si->sn_prof_on && sourcing_lnum >= 1) | |
3945 { | |
1624 | 3946 /* Grow the array before starting the timer, so that the time spent |
170 | 3947 * here isn't counted. */ |
7009 | 3948 (void)ga_grow(&si->sn_prl_ga, (int)(sourcing_lnum - si->sn_prl_ga.ga_len)); |
170 | 3949 si->sn_prl_idx = sourcing_lnum - 1; |
3950 while (si->sn_prl_ga.ga_len <= si->sn_prl_idx | |
3951 && si->sn_prl_ga.ga_len < si->sn_prl_ga.ga_maxlen) | |
3952 { | |
3953 /* Zero counters for a line that was not used before. */ | |
3954 pp = &PRL_ITEM(si, si->sn_prl_ga.ga_len); | |
3955 pp->snp_count = 0; | |
3956 profile_zero(&pp->sn_prl_total); | |
3957 profile_zero(&pp->sn_prl_self); | |
3958 ++si->sn_prl_ga.ga_len; | |
3959 } | |
3960 si->sn_prl_execed = FALSE; | |
3961 profile_start(&si->sn_prl_start); | |
3962 profile_zero(&si->sn_prl_children); | |
3963 profile_get_wait(&si->sn_prl_wait); | |
3964 } | |
3965 } | |
3966 | |
3967 /* | |
3968 * Called when actually executing a function line. | |
3969 */ | |
3970 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3971 script_line_exec(void) |
170 | 3972 { |
3973 scriptitem_T *si; | |
3974 | |
3975 if (current_SID <= 0 || current_SID > script_items.ga_len) | |
3976 return; | |
3977 si = &SCRIPT_ITEM(current_SID); | |
3978 if (si->sn_prof_on && si->sn_prl_idx >= 0) | |
3979 si->sn_prl_execed = TRUE; | |
3980 } | |
3981 | |
3982 /* | |
3983 * Called when done with a function line. | |
3984 */ | |
3985 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3986 script_line_end(void) |
170 | 3987 { |
3988 scriptitem_T *si; | |
3989 sn_prl_T *pp; | |
3990 | |
3991 if (current_SID <= 0 || current_SID > script_items.ga_len) | |
3992 return; | |
3993 si = &SCRIPT_ITEM(current_SID); | |
3994 if (si->sn_prof_on && si->sn_prl_idx >= 0 | |
3995 && si->sn_prl_idx < si->sn_prl_ga.ga_len) | |
3996 { | |
3997 if (si->sn_prl_execed) | |
3998 { | |
3999 pp = &PRL_ITEM(si, si->sn_prl_idx); | |
4000 ++pp->snp_count; | |
4001 profile_end(&si->sn_prl_start); | |
4002 profile_sub_wait(&si->sn_prl_wait, &si->sn_prl_start); | |
4003 profile_add(&pp->sn_prl_total, &si->sn_prl_start); | |
720 | 4004 profile_self(&pp->sn_prl_self, &si->sn_prl_start, |
4005 &si->sn_prl_children); | |
170 | 4006 } |
4007 si->sn_prl_idx = -1; | |
4008 } | |
4009 } | |
4010 #endif | |
4011 | |
7 | 4012 /* |
4013 * ":scriptencoding": Set encoding conversion for a sourced script. | |
4014 * Without the multi-byte feature it's simply ignored. | |
4015 */ | |
4016 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4017 ex_scriptencoding(exarg_T *eap UNUSED) |
7 | 4018 { |
4019 #ifdef FEAT_MBYTE | |
4020 struct source_cookie *sp; | |
4021 char_u *name; | |
4022 | |
4023 if (!getline_equal(eap->getline, eap->cookie, getsourceline)) | |
4024 { | |
4025 EMSG(_("E167: :scriptencoding used outside of a sourced file")); | |
4026 return; | |
4027 } | |
4028 | |
4029 if (*eap->arg != NUL) | |
4030 { | |
4031 name = enc_canonize(eap->arg); | |
4032 if (name == NULL) /* out of memory */ | |
4033 return; | |
4034 } | |
4035 else | |
4036 name = eap->arg; | |
4037 | |
4038 /* Setup for conversion from the specified encoding to 'encoding'. */ | |
4039 sp = (struct source_cookie *)getline_cookie(eap->getline, eap->cookie); | |
4040 convert_setup(&sp->conv, name, p_enc); | |
4041 | |
4042 if (name != eap->arg) | |
4043 vim_free(name); | |
4044 #endif | |
4045 } | |
4046 | |
4047 #if defined(FEAT_EVAL) || defined(PROTO) | |
4048 /* | |
4049 * ":finish": Mark a sourced file as finished. | |
4050 */ | |
4051 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4052 ex_finish(exarg_T *eap) |
7 | 4053 { |
4054 if (getline_equal(eap->getline, eap->cookie, getsourceline)) | |
4055 do_finish(eap, FALSE); | |
4056 else | |
4057 EMSG(_("E168: :finish used outside of a sourced file")); | |
4058 } | |
4059 | |
4060 /* | |
4061 * Mark a sourced file as finished. Possibly makes the ":finish" pending. | |
4062 * Also called for a pending finish at the ":endtry" or after returning from | |
4063 * an extra do_cmdline(). "reanimate" is used in the latter case. | |
4064 */ | |
4065 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4066 do_finish(exarg_T *eap, int reanimate) |
7 | 4067 { |
4068 int idx; | |
4069 | |
4070 if (reanimate) | |
4071 ((struct source_cookie *)getline_cookie(eap->getline, | |
4072 eap->cookie))->finished = FALSE; | |
4073 | |
4074 /* | |
4075 * Cleanup (and inactivate) conditionals, but stop when a try conditional | |
4076 * not in its finally clause (which then is to be executed next) is found. | |
4077 * In this case, make the ":finish" pending for execution at the ":endtry". | |
4078 * Otherwise, finish normally. | |
4079 */ | |
4080 idx = cleanup_conditionals(eap->cstack, 0, TRUE); | |
4081 if (idx >= 0) | |
4082 { | |
4083 eap->cstack->cs_pending[idx] = CSTP_FINISH; | |
4084 report_make_pending(CSTP_FINISH, NULL); | |
4085 } | |
4086 else | |
4087 ((struct source_cookie *)getline_cookie(eap->getline, | |
4088 eap->cookie))->finished = TRUE; | |
4089 } | |
4090 | |
4091 | |
4092 /* | |
4093 * Return TRUE when a sourced file had the ":finish" command: Don't give error | |
4094 * message for missing ":endif". | |
4095 * Return FALSE when not sourcing a file. | |
4096 */ | |
4097 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4098 source_finished( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4099 char_u *(*fgetline)(int, void *, int), |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4100 void *cookie) |
7 | 4101 { |
944 | 4102 return (getline_equal(fgetline, cookie, getsourceline) |
7 | 4103 && ((struct source_cookie *)getline_cookie( |
944 | 4104 fgetline, cookie))->finished); |
7 | 4105 } |
4106 #endif | |
4107 | |
4108 #if defined(FEAT_LISTCMDS) || defined(PROTO) | |
4109 /* | |
4110 * ":checktime [buffer]" | |
4111 */ | |
4112 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4113 ex_checktime(exarg_T *eap) |
7 | 4114 { |
4115 buf_T *buf; | |
4116 int save_no_check_timestamps = no_check_timestamps; | |
4117 | |
4118 no_check_timestamps = 0; | |
4119 if (eap->addr_count == 0) /* default is all buffers */ | |
4120 check_timestamps(FALSE); | |
4121 else | |
4122 { | |
4123 buf = buflist_findnr((int)eap->line2); | |
4124 if (buf != NULL) /* cannot happen? */ | |
4125 (void)buf_check_timestamp(buf, FALSE); | |
4126 } | |
4127 no_check_timestamps = save_no_check_timestamps; | |
4128 } | |
4129 #endif | |
4130 | |
4131 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ | |
4132 && (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
|
4133 # define HAVE_GET_LOCALE_VAL |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
4134 static char *get_locale_val(int what); |
7 | 4135 |
4136 static char * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4137 get_locale_val(int what) |
7 | 4138 { |
4139 char *loc; | |
4140 | |
4141 /* Obtain the locale value from the libraries. For DJGPP this is | |
4142 * redefined and it doesn't use the arguments. */ | |
4143 loc = setlocale(what, NULL); | |
4144 | |
823 | 4145 # ifdef WIN32 |
7 | 4146 if (loc != NULL) |
4147 { | |
4148 char_u *p; | |
4149 | |
823 | 4150 /* setocale() returns something like "LC_COLLATE=<name>;LC_..." when |
4151 * one of the values (e.g., LC_CTYPE) differs. */ | |
7 | 4152 p = vim_strchr(loc, '='); |
4153 if (p != NULL) | |
4154 { | |
4155 loc = ++p; | |
4156 while (*p != NUL) /* remove trailing newline */ | |
4157 { | |
823 | 4158 if (*p < ' ' || *p == ';') |
7 | 4159 { |
4160 *p = NUL; | |
4161 break; | |
4162 } | |
4163 ++p; | |
4164 } | |
4165 } | |
4166 } | |
4167 # endif | |
4168 | |
4169 return loc; | |
4170 } | |
4171 #endif | |
4172 | |
4173 | |
4174 #ifdef WIN32 | |
4175 /* | |
4176 * On MS-Windows locale names are strings like "German_Germany.1252", but | |
4177 * gettext expects "de". Try to translate one into another here for a few | |
4178 * supported languages. | |
4179 */ | |
4180 static char_u * | |
4181 gettext_lang(char_u *name) | |
4182 { | |
4183 int i; | |
4184 static char *(mtable[]) = { | |
4185 "afrikaans", "af", | |
4186 "czech", "cs", | |
4187 "dutch", "nl", | |
4188 "german", "de", | |
4189 "english_united kingdom", "en_GB", | |
4190 "spanish", "es", | |
4191 "french", "fr", | |
4192 "italian", "it", | |
4193 "japanese", "ja", | |
4194 "korean", "ko", | |
4195 "norwegian", "no", | |
4196 "polish", "pl", | |
4197 "russian", "ru", | |
4198 "slovak", "sk", | |
4199 "swedish", "sv", | |
4200 "ukrainian", "uk", | |
4201 "chinese_china", "zh_CN", | |
4202 "chinese_taiwan", "zh_TW", | |
4203 NULL}; | |
4204 | |
4205 for (i = 0; mtable[i] != NULL; i += 2) | |
4206 if (STRNICMP(mtable[i], name, STRLEN(mtable[i])) == 0) | |
4207 return mtable[i + 1]; | |
4208 return name; | |
4209 } | |
4210 #endif | |
4211 | |
4212 #if defined(FEAT_MULTI_LANG) || defined(PROTO) | |
4213 /* | |
4214 * Obtain the current messages language. Used to set the default for | |
4215 * 'helplang'. May return NULL or an empty string. | |
4216 */ | |
4217 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4218 get_mess_lang(void) |
7 | 4219 { |
4220 char_u *p; | |
4221 | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4222 # ifdef HAVE_GET_LOCALE_VAL |
7 | 4223 # if defined(LC_MESSAGES) |
4224 p = (char_u *)get_locale_val(LC_MESSAGES); | |
4225 # else | |
4226 /* This is necessary for Win32, where LC_MESSAGES is not defined and $LANG | |
823 | 4227 * may be set to the LCID number. LC_COLLATE is the best guess, LC_TIME |
4228 * and LC_MONETARY may be set differently for a Japanese working in the | |
4229 * US. */ | |
4230 p = (char_u *)get_locale_val(LC_COLLATE); | |
7 | 4231 # endif |
4232 # else | |
4233 p = mch_getenv((char_u *)"LC_ALL"); | |
4234 if (p == NULL || *p == NUL) | |
4235 { | |
4236 p = mch_getenv((char_u *)"LC_MESSAGES"); | |
4237 if (p == NULL || *p == NUL) | |
4238 p = mch_getenv((char_u *)"LANG"); | |
4239 } | |
4240 # endif | |
4241 # ifdef WIN32 | |
4242 p = gettext_lang(p); | |
4243 # endif | |
4244 return p; | |
4245 } | |
4246 #endif | |
4247 | |
45 | 4248 /* Complicated #if; matches with where get_mess_env() is used below. */ |
4249 #if (defined(FEAT_EVAL) && !((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ | |
4250 && defined(LC_MESSAGES))) \ | |
4251 || ((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ | |
4252 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) \ | |
4253 && !defined(LC_MESSAGES)) | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
4254 static char_u *get_mess_env(void); |
7 | 4255 |
4256 /* | |
4257 * Get the language used for messages from the environment. | |
4258 */ | |
4259 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4260 get_mess_env(void) |
7 | 4261 { |
4262 char_u *p; | |
4263 | |
4264 p = mch_getenv((char_u *)"LC_ALL"); | |
4265 if (p == NULL || *p == NUL) | |
4266 { | |
4267 p = mch_getenv((char_u *)"LC_MESSAGES"); | |
4268 if (p == NULL || *p == NUL) | |
4269 { | |
4270 p = mch_getenv((char_u *)"LANG"); | |
4271 if (p != NULL && VIM_ISDIGIT(*p)) | |
4272 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
|
4273 # ifdef HAVE_GET_LOCALE_VAL |
7 | 4274 if (p == NULL || *p == NUL) |
4275 p = (char_u *)get_locale_val(LC_CTYPE); | |
4276 # endif | |
4277 } | |
4278 } | |
4279 return p; | |
4280 } | |
4281 #endif | |
4282 | |
4283 #if defined(FEAT_EVAL) || defined(PROTO) | |
4284 | |
4285 /* | |
4286 * Set the "v:lang" variable according to the current locale setting. | |
4287 * Also do "v:lc_time"and "v:ctype". | |
4288 */ | |
4289 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4290 set_lang_var(void) |
7 | 4291 { |
4292 char_u *loc; | |
4293 | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4294 # ifdef HAVE_GET_LOCALE_VAL |
7 | 4295 loc = (char_u *)get_locale_val(LC_CTYPE); |
4296 # else | |
4297 /* setlocale() not supported: use the default value */ | |
4298 loc = (char_u *)"C"; | |
4299 # endif | |
4300 set_vim_var_string(VV_CTYPE, loc, -1); | |
4301 | |
4302 /* When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall | |
4303 * 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
|
4304 # if defined(HAVE_GET_LOCALE_VAL) && defined(LC_MESSAGES) |
7 | 4305 loc = (char_u *)get_locale_val(LC_MESSAGES); |
4306 # else | |
4307 loc = get_mess_env(); | |
4308 # endif | |
4309 set_vim_var_string(VV_LANG, loc, -1); | |
4310 | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4311 # ifdef HAVE_GET_LOCALE_VAL |
7 | 4312 loc = (char_u *)get_locale_val(LC_TIME); |
4313 # endif | |
4314 set_vim_var_string(VV_LC_TIME, loc, -1); | |
4315 } | |
4316 #endif | |
4317 | |
4318 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ | |
4319 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
4320 /* | |
4321 * ":language": Set the language (locale). | |
4322 */ | |
4323 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4324 ex_language(exarg_T *eap) |
7 | 4325 { |
4326 char *loc; | |
4327 char_u *p; | |
4328 char_u *name; | |
4329 int what = LC_ALL; | |
4330 char *whatstr = ""; | |
4331 #ifdef LC_MESSAGES | |
4332 # define VIM_LC_MESSAGES LC_MESSAGES | |
4333 #else | |
4334 # define VIM_LC_MESSAGES 6789 | |
4335 #endif | |
4336 | |
4337 name = eap->arg; | |
4338 | |
4339 /* Check for "messages {name}", "ctype {name}" or "time {name}" argument. | |
4340 * Allow abbreviation, but require at least 3 characters to avoid | |
4341 * confusion with a two letter language name "me" or "ct". */ | |
4342 p = skiptowhite(eap->arg); | |
4343 if ((*p == NUL || vim_iswhite(*p)) && p - eap->arg >= 3) | |
4344 { | |
4345 if (STRNICMP(eap->arg, "messages", p - eap->arg) == 0) | |
4346 { | |
4347 what = VIM_LC_MESSAGES; | |
4348 name = skipwhite(p); | |
4349 whatstr = "messages "; | |
4350 } | |
4351 else if (STRNICMP(eap->arg, "ctype", p - eap->arg) == 0) | |
4352 { | |
4353 what = LC_CTYPE; | |
4354 name = skipwhite(p); | |
4355 whatstr = "ctype "; | |
4356 } | |
4357 else if (STRNICMP(eap->arg, "time", p - eap->arg) == 0) | |
4358 { | |
4359 what = LC_TIME; | |
4360 name = skipwhite(p); | |
4361 whatstr = "time "; | |
4362 } | |
4363 } | |
4364 | |
4365 if (*name == NUL) | |
4366 { | |
4367 #ifndef LC_MESSAGES | |
4368 if (what == VIM_LC_MESSAGES) | |
4369 p = get_mess_env(); | |
4370 else | |
4371 #endif | |
4372 p = (char_u *)setlocale(what, NULL); | |
4373 if (p == NULL || *p == NUL) | |
4374 p = (char_u *)"Unknown"; | |
4375 smsg((char_u *)_("Current %slanguage: \"%s\""), whatstr, p); | |
4376 } | |
4377 else | |
4378 { | |
4379 #ifndef LC_MESSAGES | |
4380 if (what == VIM_LC_MESSAGES) | |
4381 loc = ""; | |
4382 else | |
4383 #endif | |
1624 | 4384 { |
7 | 4385 loc = setlocale(what, (char *)name); |
1624 | 4386 #if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
4387 /* Make sure strtod() uses a decimal point, not a comma. */ | |
4388 setlocale(LC_NUMERIC, "C"); | |
4389 #endif | |
4390 } | |
7 | 4391 if (loc == NULL) |
4392 EMSG2(_("E197: Cannot set language to \"%s\""), name); | |
4393 else | |
4394 { | |
4395 #ifdef HAVE_NL_MSG_CAT_CNTR | |
4396 /* Need to do this for GNU gettext, otherwise cached translations | |
4397 * will be used again. */ | |
4398 extern int _nl_msg_cat_cntr; | |
4399 | |
4400 ++_nl_msg_cat_cntr; | |
4401 #endif | |
1222 | 4402 /* Reset $LC_ALL, otherwise it would overrule everything. */ |
7 | 4403 vim_setenv((char_u *)"LC_ALL", (char_u *)""); |
4404 | |
4405 if (what != LC_TIME) | |
4406 { | |
4407 /* Tell gettext() what to translate to. It apparently doesn't | |
4408 * use the currently effective locale. Also do this when | |
4409 * FEAT_GETTEXT isn't defined, so that shell commands use this | |
4410 * value. */ | |
4411 if (what == LC_ALL) | |
534 | 4412 { |
7 | 4413 vim_setenv((char_u *)"LANG", name); |
5027
5751284311f3
updated for version 7.3.1257
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
4414 |
5751284311f3
updated for version 7.3.1257
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
4415 /* Clear $LANGUAGE because GNU gettext uses it. */ |
5751284311f3
updated for version 7.3.1257
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
4416 vim_setenv((char_u *)"LANGUAGE", (char_u *)""); |
534 | 4417 # ifdef WIN32 |
4418 /* Apparently MS-Windows printf() may cause a crash when | |
4419 * we give it 8-bit text while it's expecting text in the | |
4420 * current locale. This call avoids that. */ | |
4421 setlocale(LC_CTYPE, "C"); | |
4422 # endif | |
4423 } | |
7 | 4424 if (what != LC_CTYPE) |
4425 { | |
4426 char_u *mname; | |
4427 #ifdef WIN32 | |
4428 mname = gettext_lang(name); | |
4429 #else | |
4430 mname = name; | |
4431 #endif | |
4432 vim_setenv((char_u *)"LC_MESSAGES", mname); | |
4433 #ifdef FEAT_MULTI_LANG | |
4434 set_helplang_default(mname); | |
4435 #endif | |
4436 } | |
4437 } | |
4438 | |
4439 # ifdef FEAT_EVAL | |
4440 /* Set v:lang, v:lc_time and v:ctype to the final result. */ | |
4441 set_lang_var(); | |
4442 # endif | |
3149 | 4443 # ifdef FEAT_TITLE |
4444 maketitle(); | |
4445 # endif | |
7 | 4446 } |
4447 } | |
4448 } | |
4449 | |
4450 # if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
2849 | 4451 |
4452 static char_u **locales = NULL; /* Array of all available locales */ | |
4453 static int did_init_locales = FALSE; | |
4454 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
4455 static void init_locales(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
4456 static char_u **find_locales(void); |
2849 | 4457 |
4458 /* | |
4459 * Lazy initialization of all available locales. | |
4460 */ | |
4461 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4462 init_locales(void) |
2849 | 4463 { |
4464 if (!did_init_locales) | |
4465 { | |
4466 did_init_locales = TRUE; | |
4467 locales = find_locales(); | |
4468 } | |
4469 } | |
4470 | |
4471 /* Return an array of strings for all available locales + NULL for the | |
4472 * last element. Return NULL in case of error. */ | |
4473 static char_u ** | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4474 find_locales(void) |
2849 | 4475 { |
4476 garray_T locales_ga; | |
4477 char_u *loc; | |
4478 | |
4479 /* Find all available locales by running command "locale -a". If this | |
4480 * doesn't work we won't have completion. */ | |
4481 char_u *locale_a = get_cmd_output((char_u *)"locale -a", | |
5808 | 4482 NULL, SHELL_SILENT, NULL); |
2849 | 4483 if (locale_a == NULL) |
4484 return NULL; | |
4485 ga_init2(&locales_ga, sizeof(char_u *), 20); | |
4486 | |
4487 /* Transform locale_a string where each locale is separated by "\n" | |
4488 * into an array of locale strings. */ | |
4489 loc = (char_u *)strtok((char *)locale_a, "\n"); | |
4490 | |
4491 while (loc != NULL) | |
4492 { | |
4493 if (ga_grow(&locales_ga, 1) == FAIL) | |
4494 break; | |
4495 loc = vim_strsave(loc); | |
4496 if (loc == NULL) | |
4497 break; | |
4498 | |
4499 ((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] = loc; | |
4500 loc = (char_u *)strtok(NULL, "\n"); | |
4501 } | |
4502 vim_free(locale_a); | |
4503 if (ga_grow(&locales_ga, 1) == FAIL) | |
4504 { | |
4505 ga_clear(&locales_ga); | |
4506 return NULL; | |
4507 } | |
4508 ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; | |
4509 return (char_u **)locales_ga.ga_data; | |
4510 } | |
4511 | |
4512 # if defined(EXITFREE) || defined(PROTO) | |
4513 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4514 free_locales(void) |
2849 | 4515 { |
4516 int i; | |
4517 if (locales != NULL) | |
4518 { | |
4519 for (i = 0; locales[i] != NULL; i++) | |
4520 vim_free(locales[i]); | |
4521 vim_free(locales); | |
4522 locales = NULL; | |
4523 } | |
4524 } | |
4525 # endif | |
4526 | |
7 | 4527 /* |
4528 * Function given to ExpandGeneric() to obtain the possible arguments of the | |
4529 * ":language" command. | |
4530 */ | |
4531 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4532 get_lang_arg(expand_T *xp UNUSED, int idx) |
7 | 4533 { |
4534 if (idx == 0) | |
4535 return (char_u *)"messages"; | |
4536 if (idx == 1) | |
4537 return (char_u *)"ctype"; | |
4538 if (idx == 2) | |
4539 return (char_u *)"time"; | |
2849 | 4540 |
4541 init_locales(); | |
4542 if (locales == NULL) | |
4543 return NULL; | |
4544 return locales[idx - 3]; | |
4545 } | |
4546 | |
4547 /* | |
4548 * Function given to ExpandGeneric() to obtain the available locales. | |
4549 */ | |
4550 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4551 get_locales(expand_T *xp UNUSED, int idx) |
2849 | 4552 { |
4553 init_locales(); | |
4554 if (locales == NULL) | |
4555 return NULL; | |
4556 return locales[idx]; | |
7 | 4557 } |
4558 # endif | |
4559 | |
4560 #endif |