Mercurial > vim
annotate src/misc2.c @ 8334:ad4b00bf2984 v7.4.1459
commit https://github.com/vim/vim/commit/e081e21f760bffc24ca98d5f9bbdb5f02e6aea79
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 28 22:33:46 2016 +0100
patch 7.4.1459
Problem: MS-Windows doesn't know socklen_t.
Solution: Use previous method for WIN32.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 28 Feb 2016 22:45:04 +0100 |
parents | 05b88224cea1 |
children | c66e1f50c142 |
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 * misc2.c: Various functions. | |
12 */ | |
13 #include "vim.h" | |
14 | |
359 | 15 static char_u *username = NULL; /* cached result of mch_get_user_name() */ |
16 | |
17 static char_u *ff_expand_buffer = NULL; /* used for expanding filenames */ | |
18 | |
7 | 19 #if defined(FEAT_VIRTUALEDIT) || defined(PROTO) |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
20 static int coladvance2(pos_T *pos, int addspaces, int finetune, colnr_T wcol); |
7 | 21 |
22 /* | |
23 * Return TRUE if in the current mode we need to use virtual. | |
24 */ | |
25 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
26 virtual_active(void) |
7 | 27 { |
28 /* While an operator is being executed we return "virtual_op", because | |
29 * VIsual_active has already been reset, thus we can't check for "block" | |
30 * being used. */ | |
31 if (virtual_op != MAYBE) | |
32 return virtual_op; | |
33 return (ve_flags == VE_ALL | |
34 || ((ve_flags & VE_BLOCK) && VIsual_active && VIsual_mode == Ctrl_V) | |
35 || ((ve_flags & VE_INSERT) && (State & INSERT))); | |
36 } | |
37 | |
38 /* | |
39 * Get the screen position of the cursor. | |
40 */ | |
41 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
42 getviscol(void) |
7 | 43 { |
44 colnr_T x; | |
45 | |
46 getvvcol(curwin, &curwin->w_cursor, &x, NULL, NULL); | |
47 return (int)x; | |
48 } | |
49 | |
50 /* | |
51 * Get the screen position of character col with a coladd in the cursor line. | |
52 */ | |
53 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
54 getviscol2(colnr_T col, colnr_T coladd) |
7 | 55 { |
56 colnr_T x; | |
57 pos_T pos; | |
58 | |
59 pos.lnum = curwin->w_cursor.lnum; | |
60 pos.col = col; | |
61 pos.coladd = coladd; | |
62 getvvcol(curwin, &pos, &x, NULL, NULL); | |
63 return (int)x; | |
64 } | |
65 | |
66 /* | |
1209 | 67 * Go to column "wcol", and add/insert white space as necessary to get the |
7 | 68 * cursor in that column. |
69 * The caller must have saved the cursor line for undo! | |
70 */ | |
71 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
72 coladvance_force(colnr_T wcol) |
7 | 73 { |
74 int rc = coladvance2(&curwin->w_cursor, TRUE, FALSE, wcol); | |
75 | |
76 if (wcol == MAXCOL) | |
77 curwin->w_valid &= ~VALID_VIRTCOL; | |
78 else | |
79 { | |
80 /* Virtcol is valid */ | |
81 curwin->w_valid |= VALID_VIRTCOL; | |
82 curwin->w_virtcol = wcol; | |
83 } | |
84 return rc; | |
85 } | |
86 #endif | |
87 | |
88 /* | |
89 * Try to advance the Cursor to the specified screen column. | |
90 * If virtual editing: fine tune the cursor position. | |
91 * Note that all virtual positions off the end of a line should share | |
92 * a curwin->w_cursor.col value (n.b. this is equal to STRLEN(line)), | |
93 * beginning at coladd 0. | |
94 * | |
95 * return OK if desired column is reached, FAIL if not | |
96 */ | |
97 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
98 coladvance(colnr_T wcol) |
7 | 99 { |
100 int rc = getvpos(&curwin->w_cursor, wcol); | |
101 | |
102 if (wcol == MAXCOL || rc == FAIL) | |
103 curwin->w_valid &= ~VALID_VIRTCOL; | |
44 | 104 else if (*ml_get_cursor() != TAB) |
7 | 105 { |
44 | 106 /* Virtcol is valid when not on a TAB */ |
7 | 107 curwin->w_valid |= VALID_VIRTCOL; |
108 curwin->w_virtcol = wcol; | |
109 } | |
110 return rc; | |
111 } | |
112 | |
113 /* | |
114 * Return in "pos" the position of the cursor advanced to screen column "wcol". | |
115 * return OK if desired column is reached, FAIL if not | |
116 */ | |
117 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
118 getvpos(pos_T *pos, colnr_T wcol) |
7 | 119 { |
120 #ifdef FEAT_VIRTUALEDIT | |
121 return coladvance2(pos, FALSE, virtual_active(), wcol); | |
122 } | |
123 | |
124 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
125 coladvance2( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
126 pos_T *pos, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
127 int addspaces, /* change the text to achieve our goal? */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
128 int finetune, /* change char offset for the exact column */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
129 colnr_T wcol) /* column to move to */ |
7 | 130 { |
131 #endif | |
132 int idx; | |
133 char_u *ptr; | |
134 char_u *line; | |
135 colnr_T col = 0; | |
136 int csize = 0; | |
137 int one_more; | |
138 #ifdef FEAT_LINEBREAK | |
139 int head = 0; | |
140 #endif | |
141 | |
772 | 142 one_more = (State & INSERT) |
143 || restart_edit != NUL | |
144 || (VIsual_active && *p_sel != 'o') | |
145 #ifdef FEAT_VIRTUALEDIT | |
782 | 146 || ((ve_flags & VE_ONEMORE) && wcol < MAXCOL) |
772 | 147 #endif |
148 ; | |
1982 | 149 line = ml_get_buf(curbuf, pos->lnum, FALSE); |
7 | 150 |
151 if (wcol >= MAXCOL) | |
152 { | |
153 idx = (int)STRLEN(line) - 1 + one_more; | |
154 col = wcol; | |
155 | |
156 #ifdef FEAT_VIRTUALEDIT | |
157 if ((addspaces || finetune) && !VIsual_active) | |
158 { | |
159 curwin->w_curswant = linetabsize(line) + one_more; | |
160 if (curwin->w_curswant > 0) | |
161 --curwin->w_curswant; | |
162 } | |
163 #endif | |
164 } | |
165 else | |
166 { | |
167 #ifdef FEAT_VIRTUALEDIT | |
168 int width = W_WIDTH(curwin) - win_col_off(curwin); | |
169 | |
620 | 170 if (finetune |
7 | 171 && curwin->w_p_wrap |
172 # ifdef FEAT_VERTSPLIT | |
173 && curwin->w_width != 0 | |
174 # endif | |
175 && wcol >= (colnr_T)width) | |
176 { | |
177 csize = linetabsize(line); | |
178 if (csize > 0) | |
179 csize--; | |
180 | |
620 | 181 if (wcol / width > (colnr_T)csize / width |
182 && ((State & INSERT) == 0 || (int)wcol > csize + 1)) | |
7 | 183 { |
184 /* In case of line wrapping don't move the cursor beyond the | |
620 | 185 * right screen edge. In Insert mode allow going just beyond |
186 * the last character (like what happens when typing and | |
187 * reaching the right window edge). */ | |
7 | 188 wcol = (csize / width + 1) * width - 1; |
189 } | |
190 } | |
191 #endif | |
192 | |
193 ptr = line; | |
194 while (col <= wcol && *ptr != NUL) | |
195 { | |
196 /* Count a tab for what it's worth (if list mode not on) */ | |
197 #ifdef FEAT_LINEBREAK | |
5995 | 198 csize = win_lbr_chartabsize(curwin, line, ptr, col, &head); |
39 | 199 mb_ptr_adv(ptr); |
7 | 200 #else |
5995 | 201 csize = lbr_chartabsize_adv(line, &ptr, col); |
7 | 202 #endif |
203 col += csize; | |
204 } | |
205 idx = (int)(ptr - line); | |
206 /* | |
207 * Handle all the special cases. The virtual_active() check | |
208 * is needed to ensure that a virtual position off the end of | |
209 * a line has the correct indexing. The one_more comparison | |
210 * replaces an explicit add of one_more later on. | |
211 */ | |
212 if (col > wcol || (!virtual_active() && one_more == 0)) | |
213 { | |
214 idx -= 1; | |
215 # ifdef FEAT_LINEBREAK | |
216 /* Don't count the chars from 'showbreak'. */ | |
217 csize -= head; | |
218 # endif | |
219 col -= csize; | |
220 } | |
221 | |
222 #ifdef FEAT_VIRTUALEDIT | |
223 if (virtual_active() | |
224 && addspaces | |
225 && ((col != wcol && col != wcol + 1) || csize > 1)) | |
226 { | |
227 /* 'virtualedit' is set: The difference between wcol and col is | |
228 * filled with spaces. */ | |
229 | |
230 if (line[idx] == NUL) | |
231 { | |
232 /* Append spaces */ | |
233 int correct = wcol - col; | |
234 char_u *newline = alloc(idx + correct + 1); | |
235 int t; | |
236 | |
237 if (newline == NULL) | |
238 return FAIL; | |
239 | |
240 for (t = 0; t < idx; ++t) | |
241 newline[t] = line[t]; | |
242 | |
243 for (t = 0; t < correct; ++t) | |
244 newline[t + idx] = ' '; | |
245 | |
246 newline[idx + correct] = NUL; | |
247 | |
248 ml_replace(pos->lnum, newline, FALSE); | |
249 changed_bytes(pos->lnum, (colnr_T)idx); | |
250 idx += correct; | |
251 col = wcol; | |
252 } | |
253 else | |
254 { | |
255 /* Break a tab */ | |
256 int linelen = (int)STRLEN(line); | |
257 int correct = wcol - col - csize + 1; /* negative!! */ | |
840 | 258 char_u *newline; |
7 | 259 int t, s = 0; |
260 int v; | |
261 | |
840 | 262 if (-correct > csize) |
263 return FAIL; | |
264 | |
265 newline = alloc(linelen + csize); | |
266 if (newline == NULL) | |
7 | 267 return FAIL; |
268 | |
269 for (t = 0; t < linelen; t++) | |
270 { | |
271 if (t != idx) | |
272 newline[s++] = line[t]; | |
273 else | |
274 for (v = 0; v < csize; v++) | |
275 newline[s++] = ' '; | |
276 } | |
277 | |
278 newline[linelen + csize - 1] = NUL; | |
279 | |
280 ml_replace(pos->lnum, newline, FALSE); | |
281 changed_bytes(pos->lnum, idx); | |
282 idx += (csize - 1 + correct); | |
283 col += correct; | |
284 } | |
285 } | |
286 #endif | |
287 } | |
288 | |
289 if (idx < 0) | |
290 pos->col = 0; | |
291 else | |
292 pos->col = idx; | |
293 | |
294 #ifdef FEAT_VIRTUALEDIT | |
295 pos->coladd = 0; | |
296 | |
297 if (finetune) | |
298 { | |
299 if (wcol == MAXCOL) | |
300 { | |
301 /* The width of the last character is used to set coladd. */ | |
302 if (!one_more) | |
303 { | |
304 colnr_T scol, ecol; | |
305 | |
306 getvcol(curwin, pos, &scol, NULL, &ecol); | |
307 pos->coladd = ecol - scol; | |
308 } | |
309 } | |
310 else | |
311 { | |
312 int b = (int)wcol - (int)col; | |
313 | |
314 /* The difference between wcol and col is used to set coladd. */ | |
315 if (b > 0 && b < (MAXCOL - 2 * W_WIDTH(curwin))) | |
316 pos->coladd = b; | |
317 | |
318 col += b; | |
319 } | |
320 } | |
321 #endif | |
322 | |
323 #ifdef FEAT_MBYTE | |
1982 | 324 /* prevent from moving onto a trail byte */ |
7 | 325 if (has_mbyte) |
2933 | 326 mb_adjustpos(curbuf, pos); |
7 | 327 #endif |
328 | |
329 if (col < wcol) | |
330 return FAIL; | |
331 return OK; | |
332 } | |
333 | |
334 /* | |
1621 | 335 * Increment the cursor position. See inc() for return values. |
7 | 336 */ |
337 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
338 inc_cursor(void) |
7 | 339 { |
340 return inc(&curwin->w_cursor); | |
341 } | |
342 | |
1621 | 343 /* |
344 * Increment the line pointer "lp" crossing line boundaries as necessary. | |
345 * Return 1 when going to the next line. | |
346 * Return 2 when moving forward onto a NUL at the end of the line). | |
347 * Return -1 when at the end of file. | |
348 * Return 0 otherwise. | |
349 */ | |
7 | 350 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
351 inc(pos_T *lp) |
7 | 352 { |
353 char_u *p = ml_get_pos(lp); | |
354 | |
355 if (*p != NUL) /* still within line, move to next char (may be NUL) */ | |
356 { | |
357 #ifdef FEAT_MBYTE | |
358 if (has_mbyte) | |
359 { | |
474 | 360 int l = (*mb_ptr2len)(p); |
7 | 361 |
362 lp->col += l; | |
363 return ((p[l] != NUL) ? 0 : 2); | |
364 } | |
365 #endif | |
366 lp->col++; | |
367 #ifdef FEAT_VIRTUALEDIT | |
368 lp->coladd = 0; | |
369 #endif | |
370 return ((p[1] != NUL) ? 0 : 2); | |
371 } | |
372 if (lp->lnum != curbuf->b_ml.ml_line_count) /* there is a next line */ | |
373 { | |
374 lp->col = 0; | |
375 lp->lnum++; | |
376 #ifdef FEAT_VIRTUALEDIT | |
377 lp->coladd = 0; | |
378 #endif | |
379 return 1; | |
380 } | |
381 return -1; | |
382 } | |
383 | |
384 /* | |
385 * incl(lp): same as inc(), but skip the NUL at the end of non-empty lines | |
386 */ | |
387 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
388 incl(pos_T *lp) |
7 | 389 { |
390 int r; | |
391 | |
392 if ((r = inc(lp)) >= 1 && lp->col) | |
393 r = inc(lp); | |
394 return r; | |
395 } | |
396 | |
397 /* | |
398 * dec(p) | |
399 * | |
400 * Decrement the line pointer 'p' crossing line boundaries as necessary. | |
401 * Return 1 when crossing a line, -1 when at start of file, 0 otherwise. | |
402 */ | |
403 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
404 dec_cursor(void) |
7 | 405 { |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
406 return dec(&curwin->w_cursor); |
7 | 407 } |
408 | |
409 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
410 dec(pos_T *lp) |
7 | 411 { |
412 char_u *p; | |
413 | |
414 #ifdef FEAT_VIRTUALEDIT | |
415 lp->coladd = 0; | |
416 #endif | |
417 if (lp->col > 0) /* still within line */ | |
418 { | |
419 lp->col--; | |
420 #ifdef FEAT_MBYTE | |
421 if (has_mbyte) | |
422 { | |
423 p = ml_get(lp->lnum); | |
424 lp->col -= (*mb_head_off)(p, p + lp->col); | |
425 } | |
426 #endif | |
427 return 0; | |
428 } | |
429 if (lp->lnum > 1) /* there is a prior line */ | |
430 { | |
431 lp->lnum--; | |
432 p = ml_get(lp->lnum); | |
433 lp->col = (colnr_T)STRLEN(p); | |
434 #ifdef FEAT_MBYTE | |
435 if (has_mbyte) | |
436 lp->col -= (*mb_head_off)(p, p + lp->col); | |
437 #endif | |
438 return 1; | |
439 } | |
440 return -1; /* at start of file */ | |
441 } | |
442 | |
443 /* | |
444 * decl(lp): same as dec(), but skip the NUL at the end of non-empty lines | |
445 */ | |
446 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
447 decl(pos_T *lp) |
7 | 448 { |
449 int r; | |
450 | |
451 if ((r = dec(lp)) == 1 && lp->col) | |
452 r = dec(lp); | |
453 return r; | |
454 } | |
455 | |
456 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
457 * Get the line number relative to the current cursor position, i.e. the |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
458 * difference between line number and cursor position. Only look for lines that |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
459 * can be visible, folded lines don't count. |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
460 */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
461 linenr_T |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
462 get_cursor_rel_lnum( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
463 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
464 linenr_T lnum) /* line number to get the result for */ |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
465 { |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
466 linenr_T cursor = wp->w_cursor.lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
467 linenr_T retval = 0; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
468 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
469 #ifdef FEAT_FOLDING |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
470 if (hasAnyFolding(wp)) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
471 { |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
472 if (lnum > cursor) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
473 { |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
474 while (lnum > cursor) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
475 { |
5564 | 476 (void)hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
477 /* if lnum and cursor are in the same fold, |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
478 * now lnum <= cursor */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
479 if (lnum > cursor) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
480 retval++; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
481 lnum--; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
482 } |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
483 } |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
484 else if (lnum < cursor) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
485 { |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
486 while (lnum < cursor) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
487 { |
5564 | 488 (void)hasFoldingWin(wp, lnum, NULL, &lnum, TRUE, NULL); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
489 /* if lnum and cursor are in the same fold, |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
490 * now lnum >= cursor */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
491 if (lnum < cursor) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
492 retval--; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
493 lnum++; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
494 } |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
495 } |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
496 /* else if (lnum == cursor) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
497 * retval = 0; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
498 */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
499 } |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
500 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
501 #endif |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
502 retval = lnum - cursor; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
503 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
504 return retval; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
505 } |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
506 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2027
diff
changeset
|
507 /* |
7 | 508 * Make sure curwin->w_cursor.lnum is valid. |
509 */ | |
510 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
511 check_cursor_lnum(void) |
7 | 512 { |
513 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
514 { | |
515 #ifdef FEAT_FOLDING | |
516 /* If there is a closed fold at the end of the file, put the cursor in | |
517 * its first line. Otherwise in the last line. */ | |
518 if (!hasFolding(curbuf->b_ml.ml_line_count, | |
519 &curwin->w_cursor.lnum, NULL)) | |
520 #endif | |
521 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
522 } | |
523 if (curwin->w_cursor.lnum <= 0) | |
524 curwin->w_cursor.lnum = 1; | |
525 } | |
526 | |
527 /* | |
528 * Make sure curwin->w_cursor.col is valid. | |
529 */ | |
530 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
531 check_cursor_col(void) |
7 | 532 { |
2933 | 533 check_cursor_col_win(curwin); |
534 } | |
535 | |
536 /* | |
537 * Make sure win->w_cursor.col is valid. | |
538 */ | |
539 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
540 check_cursor_col_win(win_T *win) |
2933 | 541 { |
7 | 542 colnr_T len; |
543 #ifdef FEAT_VIRTUALEDIT | |
2933 | 544 colnr_T oldcol = win->w_cursor.col; |
545 colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd; | |
546 #endif | |
547 | |
548 len = (colnr_T)STRLEN(ml_get_buf(win->w_buffer, win->w_cursor.lnum, FALSE)); | |
7 | 549 if (len == 0) |
2933 | 550 win->w_cursor.col = 0; |
551 else if (win->w_cursor.col >= len) | |
7 | 552 { |
1488 | 553 /* Allow cursor past end-of-line when: |
554 * - in Insert mode or restarting Insert mode | |
555 * - in Visual mode and 'selection' isn't "old" | |
556 * - 'virtualedit' is set */ | |
620 | 557 if ((State & INSERT) || restart_edit |
7 | 558 || (VIsual_active && *p_sel != 'o') |
1488 | 559 #ifdef FEAT_VIRTUALEDIT |
560 || (ve_flags & VE_ONEMORE) | |
561 #endif | |
7 | 562 || virtual_active()) |
2933 | 563 win->w_cursor.col = len; |
7 | 564 else |
1099 | 565 { |
2933 | 566 win->w_cursor.col = len - 1; |
1099 | 567 #ifdef FEAT_MBYTE |
2933 | 568 /* Move the cursor to the head byte. */ |
1099 | 569 if (has_mbyte) |
2933 | 570 mb_adjustpos(win->w_buffer, &win->w_cursor); |
1099 | 571 #endif |
572 } | |
7 | 573 } |
2933 | 574 else if (win->w_cursor.col < 0) |
575 win->w_cursor.col = 0; | |
7 | 576 |
577 #ifdef FEAT_VIRTUALEDIT | |
578 /* If virtual editing is on, we can leave the cursor on the old position, | |
579 * only we must set it to virtual. But don't do it when at the end of the | |
580 * line. */ | |
581 if (oldcol == MAXCOL) | |
2933 | 582 win->w_cursor.coladd = 0; |
7 | 583 else if (ve_flags == VE_ALL) |
1841 | 584 { |
2933 | 585 if (oldcoladd > win->w_cursor.col) |
586 win->w_cursor.coladd = oldcoladd - win->w_cursor.col; | |
1841 | 587 else |
588 /* avoid weird number when there is a miscalculation or overflow */ | |
2933 | 589 win->w_cursor.coladd = 0; |
1841 | 590 } |
7 | 591 #endif |
592 } | |
593 | |
594 /* | |
595 * make sure curwin->w_cursor in on a valid character | |
596 */ | |
597 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
598 check_cursor(void) |
7 | 599 { |
600 check_cursor_lnum(); | |
601 check_cursor_col(); | |
602 } | |
603 | |
604 #if defined(FEAT_TEXTOBJ) || defined(PROTO) | |
605 /* | |
606 * Make sure curwin->w_cursor is not on the NUL at the end of the line. | |
607 * Allow it when in Visual mode and 'selection' is not "old". | |
608 */ | |
609 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
610 adjust_cursor_col(void) |
7 | 611 { |
612 if (curwin->w_cursor.col > 0 | |
613 && (!VIsual_active || *p_sel == 'o') | |
614 && gchar_cursor() == NUL) | |
615 --curwin->w_cursor.col; | |
616 } | |
617 #endif | |
618 | |
619 /* | |
620 * When curwin->w_leftcol has changed, adjust the cursor position. | |
621 * Return TRUE if the cursor was moved. | |
622 */ | |
623 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
624 leftcol_changed(void) |
7 | 625 { |
626 long lastcol; | |
627 colnr_T s, e; | |
628 int retval = FALSE; | |
629 | |
630 changed_cline_bef_curs(); | |
631 lastcol = curwin->w_leftcol + W_WIDTH(curwin) - curwin_col_off() - 1; | |
632 validate_virtcol(); | |
633 | |
634 /* | |
635 * If the cursor is right or left of the screen, move it to last or first | |
636 * character. | |
637 */ | |
638 if (curwin->w_virtcol > (colnr_T)(lastcol - p_siso)) | |
639 { | |
640 retval = TRUE; | |
641 coladvance((colnr_T)(lastcol - p_siso)); | |
642 } | |
643 else if (curwin->w_virtcol < curwin->w_leftcol + p_siso) | |
644 { | |
645 retval = TRUE; | |
646 (void)coladvance((colnr_T)(curwin->w_leftcol + p_siso)); | |
647 } | |
648 | |
649 /* | |
650 * If the start of the character under the cursor is not on the screen, | |
651 * advance the cursor one more char. If this fails (last char of the | |
652 * line) adjust the scrolling. | |
653 */ | |
654 getvvcol(curwin, &curwin->w_cursor, &s, NULL, &e); | |
655 if (e > (colnr_T)lastcol) | |
656 { | |
657 retval = TRUE; | |
658 coladvance(s - 1); | |
659 } | |
660 else if (s < curwin->w_leftcol) | |
661 { | |
662 retval = TRUE; | |
663 if (coladvance(e + 1) == FAIL) /* there isn't another character */ | |
664 { | |
665 curwin->w_leftcol = s; /* adjust w_leftcol instead */ | |
666 changed_cline_bef_curs(); | |
667 } | |
668 } | |
669 | |
670 if (retval) | |
671 curwin->w_set_curswant = TRUE; | |
672 redraw_later(NOT_VALID); | |
673 return retval; | |
674 } | |
675 | |
676 /********************************************************************** | |
677 * Various routines dealing with allocation and deallocation of memory. | |
678 */ | |
679 | |
680 #if defined(MEM_PROFILE) || defined(PROTO) | |
681 | |
682 # define MEM_SIZES 8200 | |
683 static long_u mem_allocs[MEM_SIZES]; | |
684 static long_u mem_frees[MEM_SIZES]; | |
685 static long_u mem_allocated; | |
686 static long_u mem_freed; | |
687 static long_u mem_peak; | |
688 static long_u num_alloc; | |
689 static long_u num_freed; | |
690 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
691 static void mem_pre_alloc_s(size_t *sizep); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
692 static void mem_pre_alloc_l(long_u *sizep); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
693 static void mem_post_alloc(void **pp, size_t size); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
694 static void mem_pre_free(void **pp); |
7 | 695 |
696 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
697 mem_pre_alloc_s(size_t *sizep) |
7 | 698 { |
699 *sizep += sizeof(size_t); | |
700 } | |
701 | |
702 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
703 mem_pre_alloc_l(long_u *sizep) |
7 | 704 { |
705 *sizep += sizeof(size_t); | |
706 } | |
707 | |
708 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
709 mem_post_alloc( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
710 void **pp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
711 size_t size) |
7 | 712 { |
713 if (*pp == NULL) | |
714 return; | |
715 size -= sizeof(size_t); | |
716 *(long_u *)*pp = size; | |
717 if (size <= MEM_SIZES-1) | |
718 mem_allocs[size-1]++; | |
719 else | |
720 mem_allocs[MEM_SIZES-1]++; | |
721 mem_allocated += size; | |
722 if (mem_allocated - mem_freed > mem_peak) | |
723 mem_peak = mem_allocated - mem_freed; | |
724 num_alloc++; | |
725 *pp = (void *)((char *)*pp + sizeof(size_t)); | |
726 } | |
727 | |
728 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
729 mem_pre_free(void **pp) |
7 | 730 { |
731 long_u size; | |
732 | |
733 *pp = (void *)((char *)*pp - sizeof(size_t)); | |
734 size = *(size_t *)*pp; | |
735 if (size <= MEM_SIZES-1) | |
736 mem_frees[size-1]++; | |
737 else | |
738 mem_frees[MEM_SIZES-1]++; | |
739 mem_freed += size; | |
740 num_freed++; | |
741 } | |
742 | |
743 /* | |
744 * called on exit via atexit() | |
745 */ | |
746 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
747 vim_mem_profile_dump(void) |
7 | 748 { |
749 int i, j; | |
750 | |
751 printf("\r\n"); | |
752 j = 0; | |
753 for (i = 0; i < MEM_SIZES - 1; i++) | |
754 { | |
755 if (mem_allocs[i] || mem_frees[i]) | |
756 { | |
757 if (mem_frees[i] > mem_allocs[i]) | |
758 printf("\r\n%s", _("ERROR: ")); | |
759 printf("[%4d / %4lu-%-4lu] ", i + 1, mem_allocs[i], mem_frees[i]); | |
760 j++; | |
761 if (j > 3) | |
762 { | |
763 j = 0; | |
764 printf("\r\n"); | |
765 } | |
766 } | |
767 } | |
768 | |
769 i = MEM_SIZES - 1; | |
770 if (mem_allocs[i]) | |
771 { | |
772 printf("\r\n"); | |
773 if (mem_frees[i] > mem_allocs[i]) | |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2522
diff
changeset
|
774 puts(_("ERROR: ")); |
7 | 775 printf("[>%d / %4lu-%-4lu]", i, mem_allocs[i], mem_frees[i]); |
776 } | |
777 | |
778 printf(_("\n[bytes] total alloc-freed %lu-%lu, in use %lu, peak use %lu\n"), | |
779 mem_allocated, mem_freed, mem_allocated - mem_freed, mem_peak); | |
780 printf(_("[calls] total re/malloc()'s %lu, total free()'s %lu\n\n"), | |
781 num_alloc, num_freed); | |
782 } | |
783 | |
784 #endif /* MEM_PROFILE */ | |
785 | |
7513
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
786 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
787 static int alloc_does_fail(long_u size); |
7593
87e607fb6853
commit https://github.com/vim/vim/commit/a260b87d9da17f605666630f18c1ed909c2b8bae
Christian Brabandt <cb@256bit.org>
parents:
7545
diff
changeset
|
788 |
7513
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
789 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
790 alloc_does_fail(long_u size) |
7513
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
791 { |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
792 if (alloc_fail_countdown == 0) |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
793 { |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
794 if (--alloc_fail_repeat <= 0) |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
795 alloc_fail_id = 0; |
7593
87e607fb6853
commit https://github.com/vim/vim/commit/a260b87d9da17f605666630f18c1ed909c2b8bae
Christian Brabandt <cb@256bit.org>
parents:
7545
diff
changeset
|
796 do_outofmem_msg(size); |
7513
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
797 return TRUE; |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
798 } |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
799 --alloc_fail_countdown; |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
800 return FALSE; |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
801 } |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
802 #endif |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
803 |
7 | 804 /* |
805 * Some memory is reserved for error messages and for being able to | |
806 * call mf_release_all(), which needs some memory for mf_trans_add(). | |
807 */ | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8174
diff
changeset
|
808 #define KEEP_ROOM (2 * 8192L) |
3634 | 809 #define KEEP_ROOM_KB (KEEP_ROOM / 1024L) |
7 | 810 |
811 /* | |
1576 | 812 * Note: if unsigned is 16 bits we can only allocate up to 64K with alloc(). |
7 | 813 * Use lalloc for larger blocks. |
814 */ | |
815 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
816 alloc(unsigned size) |
7 | 817 { |
818 return (lalloc((long_u)size, TRUE)); | |
819 } | |
820 | |
821 /* | |
7513
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
822 * alloc() with an ID for alloc_fail(). |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
823 */ |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
824 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
825 alloc_id(unsigned size, alloc_id_T id UNUSED) |
7513
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
826 { |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
827 #ifdef FEAT_EVAL |
7593
87e607fb6853
commit https://github.com/vim/vim/commit/a260b87d9da17f605666630f18c1ed909c2b8bae
Christian Brabandt <cb@256bit.org>
parents:
7545
diff
changeset
|
828 if (alloc_fail_id == id && alloc_does_fail((long_u)size)) |
7513
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
829 return NULL; |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
830 #endif |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
831 return (lalloc((long_u)size, TRUE)); |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
832 } |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
833 |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
834 /* |
7 | 835 * Allocate memory and set all bytes to zero. |
836 */ | |
837 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
838 alloc_clear(unsigned size) |
7 | 839 { |
840 char_u *p; | |
841 | |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2522
diff
changeset
|
842 p = lalloc((long_u)size, TRUE); |
7 | 843 if (p != NULL) |
844 (void)vim_memset(p, 0, (size_t)size); | |
845 return p; | |
846 } | |
847 | |
848 /* | |
849 * alloc() with check for maximum line length | |
850 */ | |
851 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
852 alloc_check(unsigned size) |
7 | 853 { |
854 #if !defined(UNIX) && !defined(__EMX__) | |
855 if (sizeof(int) == 2 && size > 0x7fff) | |
856 { | |
857 /* Don't hide this message */ | |
858 emsg_silent = 0; | |
859 EMSG(_("E340: Line is becoming too long")); | |
860 return NULL; | |
861 } | |
862 #endif | |
863 return (lalloc((long_u)size, TRUE)); | |
864 } | |
865 | |
866 /* | |
867 * Allocate memory like lalloc() and set all bytes to zero. | |
868 */ | |
869 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
870 lalloc_clear(long_u size, int message) |
7 | 871 { |
872 char_u *p; | |
873 | |
874 p = (lalloc(size, message)); | |
875 if (p != NULL) | |
876 (void)vim_memset(p, 0, (size_t)size); | |
877 return p; | |
878 } | |
879 | |
880 /* | |
881 * Low level memory allocation function. | |
882 * This is used often, KEEP IT FAST! | |
883 */ | |
884 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
885 lalloc(long_u size, int message) |
7 | 886 { |
887 char_u *p; /* pointer to new storage space */ | |
888 static int releasing = FALSE; /* don't do mf_release_all() recursive */ | |
889 int try_again; | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8174
diff
changeset
|
890 #if defined(HAVE_AVAIL_MEM) |
7 | 891 static long_u allocated = 0; /* allocated since last avail check */ |
892 #endif | |
893 | |
894 /* Safety check for allocating zero bytes */ | |
895 if (size == 0) | |
896 { | |
897 /* Don't hide this message */ | |
898 emsg_silent = 0; | |
899 EMSGN(_("E341: Internal error: lalloc(%ld, )"), size); | |
900 return NULL; | |
901 } | |
902 | |
903 #ifdef MEM_PROFILE | |
904 mem_pre_alloc_l(&size); | |
905 #endif | |
906 | |
907 /* | |
908 * Loop when out of memory: Try to release some memfile blocks and | |
909 * if some blocks are released call malloc again. | |
910 */ | |
911 for (;;) | |
912 { | |
913 /* | |
914 * Handle three kind of systems: | |
915 * 1. No check for available memory: Just return. | |
916 * 2. Slow check for available memory: call mch_avail_mem() after | |
917 * allocating KEEP_ROOM amount of memory. | |
918 * 3. Strict check for available memory: call mch_avail_mem() | |
919 */ | |
920 if ((p = (char_u *)malloc((size_t)size)) != NULL) | |
921 { | |
922 #ifndef HAVE_AVAIL_MEM | |
923 /* 1. No check for available memory: Just return. */ | |
924 goto theend; | |
925 #else | |
926 /* 2. Slow check for available memory: call mch_avail_mem() after | |
927 * allocating (KEEP_ROOM / 2) amount of memory. */ | |
928 allocated += size; | |
929 if (allocated < KEEP_ROOM / 2) | |
930 goto theend; | |
931 allocated = 0; | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8174
diff
changeset
|
932 |
7 | 933 /* 3. check for available memory: call mch_avail_mem() */ |
3634 | 934 if (mch_avail_mem(TRUE) < KEEP_ROOM_KB && !releasing) |
7 | 935 { |
1737 | 936 free((char *)p); /* System is low... no go! */ |
7 | 937 p = NULL; |
938 } | |
939 else | |
940 goto theend; | |
941 #endif | |
942 } | |
943 /* | |
944 * Remember that mf_release_all() is being called to avoid an endless | |
945 * loop, because mf_release_all() may call alloc() recursively. | |
946 */ | |
947 if (releasing) | |
948 break; | |
949 releasing = TRUE; | |
448 | 950 |
951 clear_sb_text(); /* free any scrollback text */ | |
952 try_again = mf_release_all(); /* release as many blocks as possible */ | |
953 | |
7 | 954 releasing = FALSE; |
955 if (!try_again) | |
956 break; | |
957 } | |
958 | |
959 if (message && p == NULL) | |
960 do_outofmem_msg(size); | |
961 | |
962 theend: | |
963 #ifdef MEM_PROFILE | |
964 mem_post_alloc((void **)&p, (size_t)size); | |
965 #endif | |
966 return p; | |
967 } | |
968 | |
7513
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
969 /* |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
970 * lalloc() with an ID for alloc_fail(). |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
971 */ |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
972 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
973 lalloc_id(long_u size, int message, alloc_id_T id UNUSED) |
7513
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
974 { |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
975 #ifdef FEAT_EVAL |
7593
87e607fb6853
commit https://github.com/vim/vim/commit/a260b87d9da17f605666630f18c1ed909c2b8bae
Christian Brabandt <cb@256bit.org>
parents:
7545
diff
changeset
|
976 if (alloc_fail_id == id && alloc_does_fail(size)) |
7513
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
977 return NULL; |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
978 #endif |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
979 return (lalloc((long_u)size, message)); |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
980 } |
37e061ec063c
commit https://github.com/vim/vim/commit/75bdf6aa30a5c99d67c42886cf7a4a000bbaa422
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
981 |
7 | 982 #if defined(MEM_PROFILE) || defined(PROTO) |
983 /* | |
984 * realloc() with memory profiling. | |
985 */ | |
986 void * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
987 mem_realloc(void *ptr, size_t size) |
7 | 988 { |
989 void *p; | |
990 | |
991 mem_pre_free(&ptr); | |
992 mem_pre_alloc_s(&size); | |
993 | |
994 p = realloc(ptr, size); | |
995 | |
996 mem_post_alloc(&p, size); | |
997 | |
998 return p; | |
999 } | |
1000 #endif | |
1001 | |
1002 /* | |
1003 * Avoid repeating the error message many times (they take 1 second each). | |
1004 * Did_outofmem_msg is reset when a character is read. | |
1005 */ | |
1006 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1007 do_outofmem_msg(long_u size) |
7 | 1008 { |
1009 if (!did_outofmem_msg) | |
1010 { | |
1011 /* Don't hide this message */ | |
1012 emsg_silent = 0; | |
3156 | 1013 |
1014 /* Must come first to avoid coming back here when printing the error | |
1015 * message fails, e.g. when setting v:errmsg. */ | |
1016 did_outofmem_msg = TRUE; | |
1017 | |
7 | 1018 EMSGN(_("E342: Out of memory! (allocating %lu bytes)"), size); |
1019 } | |
1020 } | |
1021 | |
356 | 1022 #if defined(EXITFREE) || defined(PROTO) |
359 | 1023 |
1024 # if defined(FEAT_SEARCHPATH) | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
1025 static void free_findfile(void); |
359 | 1026 # endif |
1027 | |
356 | 1028 /* |
1029 * Free everything that we allocated. | |
1030 * Can be used to detect memory leaks, e.g., with ccmalloc. | |
359 | 1031 * NOTE: This is tricky! Things are freed that functions depend on. Don't be |
1032 * surprised if Vim crashes... | |
1033 * Some things can't be freed, esp. things local to a library function. | |
356 | 1034 */ |
1035 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1036 free_all_mem(void) |
356 | 1037 { |
1038 buf_T *buf, *nextbuf; | |
359 | 1039 static int entered = FALSE; |
1040 | |
1041 /* When we cause a crash here it is caught and Vim tries to exit cleanly. | |
1042 * Don't try freeing everything again. */ | |
1043 if (entered) | |
1044 return; | |
1045 entered = TRUE; | |
356 | 1046 |
1446 | 1047 # ifdef FEAT_AUTOCMD |
6222 | 1048 /* Don't want to trigger autocommands from here on. */ |
1049 block_autocmds(); | |
1446 | 1050 # endif |
1051 | |
1052 # ifdef FEAT_WINDOWS | |
2363
acbb3a9ccc07
Avoid error when exiting in diff mode with EXITFREE defined.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
1053 /* Close all tabs and windows. Reset 'equalalways' to avoid redraws. */ |
acbb3a9ccc07
Avoid error when exiting in diff mode with EXITFREE defined.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
1054 p_ea = FALSE; |
766 | 1055 if (first_tabpage->tp_next != NULL) |
1056 do_cmdline_cmd((char_u *)"tabonly!"); | |
1057 if (firstwin != lastwin) | |
1058 do_cmdline_cmd((char_u *)"only!"); | |
1446 | 1059 # endif |
673 | 1060 |
741 | 1061 # if defined(FEAT_SPELL) |
356 | 1062 /* Free all spell info. */ |
1063 spell_free_all(); | |
1064 # endif | |
1065 | |
359 | 1066 # if defined(FEAT_USR_CMDS) |
356 | 1067 /* Clear user commands (before deleting buffers). */ |
1068 ex_comclear(NULL); | |
359 | 1069 # endif |
356 | 1070 |
1071 # ifdef FEAT_MENU | |
1072 /* Clear menus. */ | |
1073 do_cmdline_cmd((char_u *)"aunmenu *"); | |
1993 | 1074 # ifdef FEAT_MULTI_LANG |
1075 do_cmdline_cmd((char_u *)"menutranslate clear"); | |
1076 # endif | |
356 | 1077 # endif |
1078 | |
359 | 1079 /* Clear mappings, abbreviations, breakpoints. */ |
1993 | 1080 do_cmdline_cmd((char_u *)"lmapclear"); |
1081 do_cmdline_cmd((char_u *)"xmapclear"); | |
356 | 1082 do_cmdline_cmd((char_u *)"mapclear"); |
1083 do_cmdline_cmd((char_u *)"mapclear!"); | |
1084 do_cmdline_cmd((char_u *)"abclear"); | |
359 | 1085 # if defined(FEAT_EVAL) |
1086 do_cmdline_cmd((char_u *)"breakdel *"); | |
1087 # endif | |
362 | 1088 # if defined(FEAT_PROFILE) |
1089 do_cmdline_cmd((char_u *)"profdel *"); | |
1090 # endif | |
1828 | 1091 # if defined(FEAT_KEYMAP) |
1092 do_cmdline_cmd((char_u *)"set keymap="); | |
1093 #endif | |
359 | 1094 |
1095 # ifdef FEAT_TITLE | |
1096 free_titles(); | |
1097 # endif | |
1098 # if defined(FEAT_SEARCHPATH) | |
1099 free_findfile(); | |
1100 # endif | |
356 | 1101 |
1102 /* Obviously named calls. */ | |
1103 # if defined(FEAT_AUTOCMD) | |
1104 free_all_autocmds(); | |
1105 # endif | |
1106 clear_termcodes(); | |
359 | 1107 free_all_options(); |
1108 free_all_marks(); | |
1109 alist_clear(&global_alist); | |
1110 free_homedir(); | |
3744 | 1111 # if defined(FEAT_CMDL_COMPL) |
1112 free_users(); | |
1113 # endif | |
359 | 1114 free_search_patterns(); |
1115 free_old_sub(); | |
1116 free_last_insert(); | |
1117 free_prev_shellcmd(); | |
1118 free_regexp_stuff(); | |
1119 free_tag_stuff(); | |
1120 free_cd_dir(); | |
1828 | 1121 # ifdef FEAT_SIGNS |
1122 free_signs(); | |
1123 # endif | |
1446 | 1124 # ifdef FEAT_EVAL |
359 | 1125 set_expr_line(NULL); |
1446 | 1126 # endif |
1127 # ifdef FEAT_DIFF | |
673 | 1128 diff_clear(curtab); |
1446 | 1129 # endif |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
1130 # ifdef FEAT_CHANNEL |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
1131 channel_free_all(); |
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
7840
diff
changeset
|
1132 # endif |
626 | 1133 clear_sb_text(); /* free any scrollback text */ |
359 | 1134 |
1135 /* Free some global vars. */ | |
1136 vim_free(username); | |
1422 | 1137 # ifdef FEAT_CLIPBOARD |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1138 vim_regfree(clip_exclude_prog); |
1422 | 1139 # endif |
359 | 1140 vim_free(last_cmdline); |
1446 | 1141 # ifdef FEAT_CMDHIST |
359 | 1142 vim_free(new_last_cmdline); |
1446 | 1143 # endif |
680 | 1144 set_keep_msg(NULL, 0); |
359 | 1145 vim_free(ff_expand_buffer); |
356 | 1146 |
1147 /* Clear cmdline history. */ | |
1148 p_hi = 0; | |
1446 | 1149 # ifdef FEAT_CMDHIST |
356 | 1150 init_history(); |
1446 | 1151 # endif |
356 | 1152 |
359 | 1153 #ifdef FEAT_QUICKFIX |
1446 | 1154 { |
1863 | 1155 win_T *win; |
1156 tabpage_T *tab; | |
1446 | 1157 |
1158 qf_free_all(NULL); | |
1159 /* Free all location lists */ | |
1863 | 1160 FOR_ALL_TAB_WINDOWS(tab, win) |
1446 | 1161 qf_free_all(win); |
1162 } | |
359 | 1163 #endif |
1164 | |
1165 /* Close all script inputs. */ | |
1166 close_all_scripts(); | |
1167 | |
1168 #if defined(FEAT_WINDOWS) | |
1169 /* Destroy all windows. Must come before freeing buffers. */ | |
1170 win_free_all(); | |
1171 #endif | |
1172 | |
1576 | 1173 /* Free all buffers. Reset 'autochdir' to avoid accessing things that |
1174 * were freed already. */ | |
1175 #ifdef FEAT_AUTOCHDIR | |
1176 p_acd = FALSE; | |
1177 #endif | |
356 | 1178 for (buf = firstbuf; buf != NULL; ) |
1179 { | |
1180 nextbuf = buf->b_next; | |
3365 | 1181 close_buffer(NULL, buf, DOBUF_WIPE, FALSE); |
356 | 1182 if (buf_valid(buf)) |
1183 buf = nextbuf; /* didn't work, try next one */ | |
1184 else | |
1185 buf = firstbuf; | |
1186 } | |
1187 | |
359 | 1188 #ifdef FEAT_ARABIC |
1189 free_cmdline_buf(); | |
356 | 1190 #endif |
1191 | |
1192 /* Clear registers. */ | |
1193 clear_registers(); | |
1194 ResetRedobuff(); | |
1195 ResetRedobuff(); | |
1196 | |
1071 | 1197 #if defined(FEAT_CLIENTSERVER) && defined(FEAT_X11) |
359 | 1198 vim_free(serverDelayedStartName); |
1199 #endif | |
1200 | |
356 | 1201 /* highlight info */ |
1202 free_highlight(); | |
1203 | |
362 | 1204 reset_last_sourcing(); |
1205 | |
766 | 1206 #ifdef FEAT_WINDOWS |
853 | 1207 free_tabpage(first_tabpage); |
1208 first_tabpage = NULL; | |
766 | 1209 #endif |
1210 | |
356 | 1211 # ifdef UNIX |
1212 /* Machine-specific free. */ | |
1213 mch_free_mem(); | |
1214 # endif | |
1215 | |
1216 /* message history */ | |
1217 for (;;) | |
1218 if (delete_first_msg() == FAIL) | |
1219 break; | |
1220 | |
1221 # ifdef FEAT_EVAL | |
1222 eval_clear(); | |
1223 # endif | |
1224 | |
359 | 1225 free_termoptions(); |
1226 | |
356 | 1227 /* screenlines (can't display anything now!) */ |
1228 free_screenlines(); | |
1229 | |
1230 #if defined(USE_XSMP) | |
1231 xsmp_close(); | |
1232 #endif | |
359 | 1233 #ifdef FEAT_GUI_GTK |
1234 gui_mch_free_all(); | |
1235 #endif | |
1236 clear_hl_tables(); | |
356 | 1237 |
1238 vim_free(IObuff); | |
1239 vim_free(NameBuff); | |
1240 } | |
1241 #endif | |
1242 | |
7 | 1243 /* |
2656 | 1244 * Copy "string" into newly allocated memory. |
7 | 1245 */ |
1246 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1247 vim_strsave(char_u *string) |
7 | 1248 { |
1249 char_u *p; | |
1250 unsigned len; | |
1251 | |
1252 len = (unsigned)STRLEN(string) + 1; | |
1253 p = alloc(len); | |
1254 if (p != NULL) | |
1255 mch_memmove(p, string, (size_t)len); | |
1256 return p; | |
1257 } | |
1258 | |
2656 | 1259 /* |
1260 * Copy up to "len" bytes of "string" into newly allocated memory and | |
1261 * terminate with a NUL. | |
1262 * The allocated memory always has size "len + 1", also when "string" is | |
1263 * shorter. | |
1264 */ | |
7 | 1265 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1266 vim_strnsave(char_u *string, int len) |
7 | 1267 { |
1268 char_u *p; | |
1269 | |
1270 p = alloc((unsigned)(len + 1)); | |
1271 if (p != NULL) | |
1272 { | |
1273 STRNCPY(p, string, len); | |
1274 p[len] = NUL; | |
1275 } | |
1276 return p; | |
1277 } | |
1278 | |
1279 /* | |
1280 * Same as vim_strsave(), but any characters found in esc_chars are preceded | |
1281 * by a backslash. | |
1282 */ | |
1283 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1284 vim_strsave_escaped(char_u *string, char_u *esc_chars) |
7 | 1285 { |
16 | 1286 return vim_strsave_escaped_ext(string, esc_chars, '\\', FALSE); |
7 | 1287 } |
1288 | |
1289 /* | |
1290 * Same as vim_strsave_escaped(), but when "bsl" is TRUE also escape | |
1291 * characters where rem_backslash() would remove the backslash. | |
16 | 1292 * Escape the characters with "cc". |
7 | 1293 */ |
1294 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1295 vim_strsave_escaped_ext( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1296 char_u *string, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1297 char_u *esc_chars, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1298 int cc, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1299 int bsl) |
7 | 1300 { |
1301 char_u *p; | |
1302 char_u *p2; | |
1303 char_u *escaped_string; | |
1304 unsigned length; | |
1305 #ifdef FEAT_MBYTE | |
1306 int l; | |
1307 #endif | |
1308 | |
1309 /* | |
1310 * First count the number of backslashes required. | |
1311 * Then allocate the memory and insert them. | |
1312 */ | |
1313 length = 1; /* count the trailing NUL */ | |
1314 for (p = string; *p; p++) | |
1315 { | |
1316 #ifdef FEAT_MBYTE | |
474 | 1317 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
7 | 1318 { |
1319 length += l; /* count a multibyte char */ | |
1320 p += l - 1; | |
1321 continue; | |
1322 } | |
1323 #endif | |
1324 if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p))) | |
1325 ++length; /* count a backslash */ | |
1326 ++length; /* count an ordinary char */ | |
1327 } | |
1328 escaped_string = alloc(length); | |
1329 if (escaped_string != NULL) | |
1330 { | |
1331 p2 = escaped_string; | |
1332 for (p = string; *p; p++) | |
1333 { | |
1334 #ifdef FEAT_MBYTE | |
474 | 1335 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
7 | 1336 { |
1337 mch_memmove(p2, p, (size_t)l); | |
1338 p2 += l; | |
1339 p += l - 1; /* skip multibyte char */ | |
1340 continue; | |
1341 } | |
1342 #endif | |
1343 if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p))) | |
16 | 1344 *p2++ = cc; |
7 | 1345 *p2++ = *p; |
1346 } | |
1347 *p2 = NUL; | |
1348 } | |
1349 return escaped_string; | |
1350 } | |
1351 | |
1685 | 1352 /* |
1353 * Return TRUE when 'shell' has "csh" in the tail. | |
1354 */ | |
1355 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1356 csh_like_shell(void) |
1685 | 1357 { |
1358 return (strstr((char *)gettail(p_sh), "csh") != NULL); | |
1359 } | |
1712 | 1360 |
985 | 1361 /* |
1362 * Escape "string" for use as a shell argument with system(). | |
1993 | 1363 * This uses single quotes, except when we know we need to use double quotes |
985 | 1364 * (MS-DOS and MS-Windows without 'shellslash' set). |
1673 | 1365 * Escape a newline, depending on the 'shell' option. |
1366 * When "do_special" is TRUE also replace "!", "%", "#" and things starting | |
1367 * with "<" like "<cfile>". | |
5690 | 1368 * When "do_newline" is FALSE do not escape newline unless it is csh shell. |
985 | 1369 * Returns the result in allocated memory, NULL if we have run out. |
1370 */ | |
1371 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1372 vim_strsave_shellescape(char_u *string, int do_special, int do_newline) |
985 | 1373 { |
1374 unsigned length; | |
1375 char_u *p; | |
1376 char_u *d; | |
1377 char_u *escaped_string; | |
1661 | 1378 int l; |
1673 | 1379 int csh_like; |
1380 | |
1381 /* Only csh and similar shells expand '!' within single quotes. For sh and | |
1382 * the like we must not put a backslash before it, it will be taken | |
1383 * literally. If do_special is set the '!' will be escaped twice. | |
1384 * Csh also needs to have "\n" escaped twice when do_special is set. */ | |
1685 | 1385 csh_like = csh_like_shell(); |
985 | 1386 |
1387 /* First count the number of extra bytes required. */ | |
1072 | 1388 length = (unsigned)STRLEN(string) + 3; /* two quotes and a trailing NUL */ |
985 | 1389 for (p = string; *p != NUL; mb_ptr_adv(p)) |
1390 { | |
8140
563c923b1584
commit https://github.com/vim/vim/commit/cf7164a088664961e7d70dd100c5874dc5ceb293
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
1391 # if defined(WIN32) || defined(DOS) |
985 | 1392 if (!p_ssl) |
1393 { | |
1394 if (*p == '"') | |
1395 ++length; /* " -> "" */ | |
1396 } | |
1397 else | |
1398 # endif | |
1399 if (*p == '\'') | |
1400 length += 3; /* ' => '\'' */ | |
5690 | 1401 if ((*p == '\n' && (csh_like || do_newline)) |
1402 || (*p == '!' && (csh_like || do_special))) | |
1673 | 1403 { |
1404 ++length; /* insert backslash */ | |
1405 if (csh_like && do_special) | |
1406 ++length; /* insert backslash */ | |
1407 } | |
1661 | 1408 if (do_special && find_cmdline_var(p, &l) >= 0) |
1409 { | |
1410 ++length; /* insert backslash */ | |
1411 p += l - 1; | |
1412 } | |
985 | 1413 } |
1414 | |
1415 /* Allocate memory for the result and fill it. */ | |
1416 escaped_string = alloc(length); | |
1417 if (escaped_string != NULL) | |
1418 { | |
1419 d = escaped_string; | |
1420 | |
1421 /* add opening quote */ | |
8140
563c923b1584
commit https://github.com/vim/vim/commit/cf7164a088664961e7d70dd100c5874dc5ceb293
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
1422 # if defined(WIN32) || defined(DOS) |
985 | 1423 if (!p_ssl) |
1424 *d++ = '"'; | |
1425 else | |
1426 # endif | |
1427 *d++ = '\''; | |
1428 | |
1429 for (p = string; *p != NUL; ) | |
1430 { | |
8140
563c923b1584
commit https://github.com/vim/vim/commit/cf7164a088664961e7d70dd100c5874dc5ceb293
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
1431 # if defined(WIN32) || defined(DOS) |
985 | 1432 if (!p_ssl) |
1433 { | |
1434 if (*p == '"') | |
1435 { | |
1436 *d++ = '"'; | |
1437 *d++ = '"'; | |
1438 ++p; | |
1439 continue; | |
1440 } | |
1441 } | |
1442 else | |
1443 # endif | |
1444 if (*p == '\'') | |
1445 { | |
1661 | 1446 *d++ = '\''; |
1447 *d++ = '\\'; | |
1448 *d++ = '\''; | |
1449 *d++ = '\''; | |
985 | 1450 ++p; |
1451 continue; | |
1452 } | |
5690 | 1453 if ((*p == '\n' && (csh_like || do_newline)) |
1454 || (*p == '!' && (csh_like || do_special))) | |
1673 | 1455 { |
1456 *d++ = '\\'; | |
1457 if (csh_like && do_special) | |
1458 *d++ = '\\'; | |
1459 *d++ = *p++; | |
1460 continue; | |
1461 } | |
1661 | 1462 if (do_special && find_cmdline_var(p, &l) >= 0) |
1463 { | |
1464 *d++ = '\\'; /* insert backslash */ | |
1465 while (--l >= 0) /* copy the var */ | |
1466 *d++ = *p++; | |
2009 | 1467 continue; |
1661 | 1468 } |
985 | 1469 |
1470 MB_COPY_CHAR(p, d); | |
1471 } | |
1472 | |
1473 /* add terminating quote and finish with a NUL */ | |
8140
563c923b1584
commit https://github.com/vim/vim/commit/cf7164a088664961e7d70dd100c5874dc5ceb293
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
1474 # if defined(WIN32) || defined(DOS) |
985 | 1475 if (!p_ssl) |
1476 *d++ = '"'; | |
1477 else | |
1478 # endif | |
1479 *d++ = '\''; | |
1480 *d = NUL; | |
1481 } | |
1482 | |
1483 return escaped_string; | |
1484 } | |
1485 | |
7 | 1486 /* |
1487 * Like vim_strsave(), but make all characters uppercase. | |
1488 * This uses ASCII lower-to-upper case translation, language independent. | |
1489 */ | |
1490 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1491 vim_strsave_up(char_u *string) |
7 | 1492 { |
1493 char_u *p1; | |
1494 | |
1495 p1 = vim_strsave(string); | |
1496 vim_strup(p1); | |
1497 return p1; | |
1498 } | |
1499 | |
1500 /* | |
1501 * Like vim_strnsave(), but make all characters uppercase. | |
1502 * This uses ASCII lower-to-upper case translation, language independent. | |
1503 */ | |
1504 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1505 vim_strnsave_up(char_u *string, int len) |
7 | 1506 { |
1507 char_u *p1; | |
1508 | |
1509 p1 = vim_strnsave(string, len); | |
1510 vim_strup(p1); | |
1511 return p1; | |
1512 } | |
1513 | |
1514 /* | |
1515 * ASCII lower-to-upper case translation, language independent. | |
1516 */ | |
1517 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1518 vim_strup( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1519 char_u *p) |
7 | 1520 { |
1521 char_u *p2; | |
1522 int c; | |
1523 | |
1524 if (p != NULL) | |
1525 { | |
1526 p2 = p; | |
1527 while ((c = *p2) != NUL) | |
1528 #ifdef EBCDIC | |
1529 *p2++ = isalpha(c) ? toupper(c) : c; | |
1530 #else | |
1531 *p2++ = (c < 'a' || c > 'z') ? c : (c - 0x20); | |
1532 #endif | |
1533 } | |
1534 } | |
1535 | |
741 | 1536 #if defined(FEAT_EVAL) || defined(FEAT_SPELL) || defined(PROTO) |
323 | 1537 /* |
1538 * Make string "s" all upper-case and return it in allocated memory. | |
1539 * Handles multi-byte characters as well as possible. | |
1540 * Returns NULL when out of memory. | |
1541 */ | |
1542 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1543 strup_save(char_u *orig) |
323 | 1544 { |
1545 char_u *p; | |
1546 char_u *res; | |
1547 | |
1548 res = p = vim_strsave(orig); | |
1549 | |
1550 if (res != NULL) | |
1551 while (*p != NUL) | |
1552 { | |
1553 # ifdef FEAT_MBYTE | |
1554 int l; | |
1555 | |
1556 if (enc_utf8) | |
1557 { | |
1558 int c, uc; | |
3263 | 1559 int newl; |
323 | 1560 char_u *s; |
1561 | |
1562 c = utf_ptr2char(p); | |
1563 uc = utf_toupper(c); | |
1564 | |
1565 /* Reallocate string when byte count changes. This is rare, | |
1566 * thus it's OK to do another malloc()/free(). */ | |
474 | 1567 l = utf_ptr2len(p); |
3263 | 1568 newl = utf_char2len(uc); |
1569 if (newl != l) | |
323 | 1570 { |
3263 | 1571 s = alloc((unsigned)STRLEN(res) + 1 + newl - l); |
323 | 1572 if (s == NULL) |
1573 break; | |
1574 mch_memmove(s, res, p - res); | |
3263 | 1575 STRCPY(s + (p - res) + newl, p + l); |
323 | 1576 p = s + (p - res); |
1577 vim_free(res); | |
1578 res = s; | |
1579 } | |
1580 | |
1581 utf_char2bytes(uc, p); | |
3263 | 1582 p += newl; |
323 | 1583 } |
474 | 1584 else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
323 | 1585 p += l; /* skip multi-byte character */ |
1586 else | |
1587 # endif | |
1588 { | |
1589 *p = TOUPPER_LOC(*p); /* note that toupper() can be a macro */ | |
1590 p++; | |
1591 } | |
1592 } | |
1593 | |
1594 return res; | |
1595 } | |
1596 #endif | |
1597 | |
7 | 1598 /* |
1599 * delete spaces at the end of a string | |
1600 */ | |
1601 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1602 del_trailing_spaces(char_u *ptr) |
7 | 1603 { |
1604 char_u *q; | |
1605 | |
1606 q = ptr + STRLEN(ptr); | |
1607 while (--q > ptr && vim_iswhite(q[0]) && q[-1] != '\\' && q[-1] != Ctrl_V) | |
1608 *q = NUL; | |
1609 } | |
1610 | |
1611 /* | |
323 | 1612 * Like strncpy(), but always terminate the result with one NUL. |
378 | 1613 * "to" must be "len + 1" long! |
7 | 1614 */ |
1615 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1616 vim_strncpy(char_u *to, char_u *from, size_t len) |
7 | 1617 { |
323 | 1618 STRNCPY(to, from, len); |
1619 to[len] = NUL; | |
7 | 1620 } |
1621 | |
1622 /* | |
2768 | 1623 * Like strcat(), but make sure the result fits in "tosize" bytes and is |
1624 * always NUL terminated. | |
1625 */ | |
1626 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1627 vim_strcat(char_u *to, char_u *from, size_t tosize) |
2768 | 1628 { |
1629 size_t tolen = STRLEN(to); | |
1630 size_t fromlen = STRLEN(from); | |
1631 | |
1632 if (tolen + fromlen + 1 > tosize) | |
1633 { | |
1634 mch_memmove(to + tolen, from, tosize - tolen - 1); | |
1635 to[tosize - 1] = NUL; | |
1636 } | |
1637 else | |
1638 STRCPY(to + tolen, from); | |
1639 } | |
1640 | |
1641 /* | |
7 | 1642 * Isolate one part of a string option where parts are separated with |
1643 * "sep_chars". | |
459 | 1644 * The part is copied into "buf[maxlen]". |
7 | 1645 * "*option" is advanced to the next part. |
1646 * The length is returned. | |
1647 */ | |
1648 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1649 copy_option_part( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1650 char_u **option, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1651 char_u *buf, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1652 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1653 char *sep_chars) |
7 | 1654 { |
1655 int len = 0; | |
1656 char_u *p = *option; | |
1657 | |
1658 /* skip '.' at start of option part, for 'suffixes' */ | |
1659 if (*p == '.') | |
1660 buf[len++] = *p++; | |
1661 while (*p != NUL && vim_strchr((char_u *)sep_chars, *p) == NULL) | |
1662 { | |
1663 /* | |
1664 * Skip backslash before a separator character and space. | |
1665 */ | |
1666 if (p[0] == '\\' && vim_strchr((char_u *)sep_chars, p[1]) != NULL) | |
1667 ++p; | |
1668 if (len < maxlen - 1) | |
1669 buf[len++] = *p; | |
1670 ++p; | |
1671 } | |
1672 buf[len] = NUL; | |
1673 | |
1674 if (*p != NUL && *p != ',') /* skip non-standard separator */ | |
1675 ++p; | |
1676 p = skip_to_option_part(p); /* p points to next file name */ | |
1677 | |
1678 *option = p; | |
1679 return len; | |
1680 } | |
1681 | |
1682 /* | |
625 | 1683 * Replacement for free() that ignores NULL pointers. |
1684 * Also skip free() when exiting for sure, this helps when we caught a deadly | |
1685 * signal that was caused by a crash in free(). | |
7 | 1686 */ |
1687 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1688 vim_free(void *x) |
7 | 1689 { |
625 | 1690 if (x != NULL && !really_exiting) |
7 | 1691 { |
1692 #ifdef MEM_PROFILE | |
1693 mem_pre_free(&x); | |
1694 #endif | |
1695 free(x); | |
1696 } | |
1697 } | |
1698 | |
1699 #ifndef HAVE_MEMSET | |
1700 void * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1701 vim_memset(void *ptr, int c, size_t size) |
7 | 1702 { |
1703 char *p = ptr; | |
1704 | |
1705 while (size-- > 0) | |
1706 *p++ = c; | |
1707 return ptr; | |
1708 } | |
1709 #endif | |
1710 | |
1711 #ifdef VIM_MEMCMP | |
1712 /* | |
1713 * Return zero when "b1" and "b2" are the same for "len" bytes. | |
1714 * Return non-zero otherwise. | |
1715 */ | |
1716 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1717 vim_memcmp(void *b1, void *b2, size_t len) |
7 | 1718 { |
1719 char_u *p1 = (char_u *)b1, *p2 = (char_u *)b2; | |
1720 | |
1721 for ( ; len > 0; --len) | |
1722 { | |
1723 if (*p1 != *p2) | |
1724 return 1; | |
1725 ++p1; | |
1726 ++p2; | |
1727 } | |
1728 return 0; | |
1729 } | |
1730 #endif | |
1731 | |
1732 #ifdef VIM_MEMMOVE | |
1733 /* | |
1734 * Version of memmove() that handles overlapping source and destination. | |
1735 * For systems that don't have a function that is guaranteed to do that (SYSV). | |
1736 */ | |
1737 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1738 mch_memmove(void *src_arg, *dst_arg, size_t len) |
7 | 1739 { |
1740 /* | |
1741 * A void doesn't have a size, we use char pointers. | |
1742 */ | |
1743 char *dst = dst_arg, *src = src_arg; | |
1744 | |
1745 /* overlap, copy backwards */ | |
1746 if (dst > src && dst < src + len) | |
1747 { | |
1748 src += len; | |
1749 dst += len; | |
1750 while (len-- > 0) | |
1751 *--dst = *--src; | |
1752 } | |
1753 else /* copy forwards */ | |
1754 while (len-- > 0) | |
1755 *dst++ = *src++; | |
1756 } | |
1757 #endif | |
1758 | |
1759 #if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) || defined(PROTO) | |
1760 /* | |
1761 * Compare two strings, ignoring case, using current locale. | |
1762 * Doesn't work for multi-byte characters. | |
1763 * return 0 for match, < 0 for smaller, > 0 for bigger | |
1764 */ | |
1765 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1766 vim_stricmp(char *s1, char *s2) |
7 | 1767 { |
1768 int i; | |
1769 | |
1770 for (;;) | |
1771 { | |
1772 i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2); | |
1773 if (i != 0) | |
1774 return i; /* this character different */ | |
1775 if (*s1 == NUL) | |
1776 break; /* strings match until NUL */ | |
1777 ++s1; | |
1778 ++s2; | |
1779 } | |
1780 return 0; /* strings match */ | |
1781 } | |
1782 #endif | |
1783 | |
1784 #if (!defined(HAVE_STRNCASECMP) && !defined(HAVE_STRNICMP)) || defined(PROTO) | |
1785 /* | |
1786 * Compare two strings, for length "len", ignoring case, using current locale. | |
1787 * Doesn't work for multi-byte characters. | |
1788 * return 0 for match, < 0 for smaller, > 0 for bigger | |
1789 */ | |
1790 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1791 vim_strnicmp(char *s1, char *s2, size_t len) |
7 | 1792 { |
1793 int i; | |
1794 | |
1795 while (len > 0) | |
1796 { | |
1797 i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2); | |
1798 if (i != 0) | |
1799 return i; /* this character different */ | |
1800 if (*s1 == NUL) | |
1801 break; /* strings match until NUL */ | |
1802 ++s1; | |
1803 ++s2; | |
1804 --len; | |
1805 } | |
1806 return 0; /* strings match */ | |
1807 } | |
1808 #endif | |
1809 | |
1810 /* | |
1811 * Version of strchr() and strrchr() that handle unsigned char strings | |
170 | 1812 * with characters from 128 to 255 correctly. It also doesn't return a |
1813 * pointer to the NUL at the end of the string. | |
7 | 1814 */ |
1815 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1816 vim_strchr(char_u *string, int c) |
7 | 1817 { |
1818 char_u *p; | |
1819 int b; | |
1820 | |
1821 p = string; | |
1822 #ifdef FEAT_MBYTE | |
1823 if (enc_utf8 && c >= 0x80) | |
1824 { | |
1825 while (*p != NUL) | |
1826 { | |
6765 | 1827 int l = (*mb_ptr2len)(p); |
1828 | |
1829 /* Avoid matching an illegal byte here. */ | |
1830 if (utf_ptr2char(p) == c && l > 1) | |
7 | 1831 return p; |
6765 | 1832 p += l; |
7 | 1833 } |
1834 return NULL; | |
1835 } | |
1836 if (enc_dbcs != 0 && c > 255) | |
1837 { | |
1838 int n2 = c & 0xff; | |
1839 | |
1840 c = ((unsigned)c >> 8) & 0xff; | |
1841 while ((b = *p) != NUL) | |
1842 { | |
1843 if (b == c && p[1] == n2) | |
1844 return p; | |
474 | 1845 p += (*mb_ptr2len)(p); |
7 | 1846 } |
1847 return NULL; | |
1848 } | |
1849 if (has_mbyte) | |
1850 { | |
1851 while ((b = *p) != NUL) | |
1852 { | |
1853 if (b == c) | |
1854 return p; | |
474 | 1855 p += (*mb_ptr2len)(p); |
7 | 1856 } |
1857 return NULL; | |
1858 } | |
1859 #endif | |
1860 while ((b = *p) != NUL) | |
1861 { | |
1862 if (b == c) | |
1863 return p; | |
1864 ++p; | |
1865 } | |
1866 return NULL; | |
1867 } | |
1868 | |
1869 /* | |
170 | 1870 * Version of strchr() that only works for bytes and handles unsigned char |
1871 * strings with characters above 128 correctly. It also doesn't return a | |
1872 * pointer to the NUL at the end of the string. | |
1873 */ | |
1874 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1875 vim_strbyte(char_u *string, int c) |
170 | 1876 { |
1877 char_u *p = string; | |
1878 | |
1879 while (*p != NUL) | |
1880 { | |
1881 if (*p == c) | |
1882 return p; | |
1883 ++p; | |
1884 } | |
1885 return NULL; | |
1886 } | |
1887 | |
1888 /* | |
7 | 1889 * Search for last occurrence of "c" in "string". |
500 | 1890 * Return NULL if not found. |
170 | 1891 * Does not handle multi-byte char for "c"! |
7 | 1892 */ |
1893 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1894 vim_strrchr(char_u *string, int c) |
7 | 1895 { |
1896 char_u *retval = NULL; | |
170 | 1897 char_u *p = string; |
1898 | |
1899 while (*p) | |
7 | 1900 { |
170 | 1901 if (*p == c) |
1902 retval = p; | |
1903 mb_ptr_adv(p); | |
7 | 1904 } |
1905 return retval; | |
1906 } | |
1907 | |
1908 /* | |
1909 * Vim's version of strpbrk(), in case it's missing. | |
1910 * Don't generate a prototype for this, causes problems when it's not used. | |
1911 */ | |
1912 #ifndef PROTO | |
1913 # ifndef HAVE_STRPBRK | |
1914 # ifdef vim_strpbrk | |
1915 # undef vim_strpbrk | |
1916 # endif | |
1917 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1918 vim_strpbrk(char_u *s, char_u *charset) |
7 | 1919 { |
1920 while (*s) | |
1921 { | |
1922 if (vim_strchr(charset, *s) != NULL) | |
1923 return s; | |
39 | 1924 mb_ptr_adv(s); |
7 | 1925 } |
1926 return NULL; | |
1927 } | |
1928 # endif | |
1929 #endif | |
1930 | |
1931 /* | |
1932 * Vim has its own isspace() function, because on some machines isspace() | |
1933 * can't handle characters above 128. | |
1934 */ | |
1935 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1936 vim_isspace(int x) |
7 | 1937 { |
1938 return ((x >= 9 && x <= 13) || x == ' '); | |
1939 } | |
1940 | |
1941 /************************************************************************ | |
119 | 1942 * Functions for handling growing arrays. |
7 | 1943 */ |
1944 | |
1945 /* | |
1946 * Clear an allocated growing array. | |
1947 */ | |
1948 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1949 ga_clear(garray_T *gap) |
7 | 1950 { |
1951 vim_free(gap->ga_data); | |
1952 ga_init(gap); | |
1953 } | |
1954 | |
1955 /* | |
1956 * Clear a growing array that contains a list of strings. | |
1957 */ | |
1958 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1959 ga_clear_strings(garray_T *gap) |
7 | 1960 { |
1961 int i; | |
1962 | |
1963 for (i = 0; i < gap->ga_len; ++i) | |
1964 vim_free(((char_u **)(gap->ga_data))[i]); | |
1965 ga_clear(gap); | |
1966 } | |
1967 | |
1968 /* | |
1969 * Initialize a growing array. Don't forget to set ga_itemsize and | |
1970 * ga_growsize! Or use ga_init2(). | |
1971 */ | |
1972 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1973 ga_init(garray_T *gap) |
7 | 1974 { |
1975 gap->ga_data = NULL; | |
41 | 1976 gap->ga_maxlen = 0; |
7 | 1977 gap->ga_len = 0; |
1978 } | |
1979 | |
1980 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1981 ga_init2(garray_T *gap, int itemsize, int growsize) |
7 | 1982 { |
1983 ga_init(gap); | |
1984 gap->ga_itemsize = itemsize; | |
1985 gap->ga_growsize = growsize; | |
1986 } | |
1987 | |
1988 /* | |
1989 * Make room in growing array "gap" for at least "n" items. | |
1990 * Return FAIL for failure, OK otherwise. | |
1991 */ | |
1992 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1993 ga_grow(garray_T *gap, int n) |
7 | 1994 { |
3376 | 1995 size_t old_len; |
1996 size_t new_len; | |
7 | 1997 char_u *pp; |
1998 | |
41 | 1999 if (gap->ga_maxlen - gap->ga_len < n) |
7 | 2000 { |
2001 if (n < gap->ga_growsize) | |
2002 n = gap->ga_growsize; | |
3376 | 2003 new_len = gap->ga_itemsize * (gap->ga_len + n); |
2004 pp = (gap->ga_data == NULL) | |
3386 | 2005 ? alloc((unsigned)new_len) : vim_realloc(gap->ga_data, new_len); |
7 | 2006 if (pp == NULL) |
2007 return FAIL; | |
3376 | 2008 old_len = gap->ga_itemsize * gap->ga_maxlen; |
2009 vim_memset(pp + old_len, 0, new_len - old_len); | |
41 | 2010 gap->ga_maxlen = gap->ga_len + n; |
7 | 2011 gap->ga_data = pp; |
2012 } | |
2013 return OK; | |
2014 } | |
2015 | |
2016 /* | |
2487
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2017 * For a growing array that contains a list of strings: concatenate all the |
5873 | 2018 * strings with a separating "sep". |
2487
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2019 * Returns NULL when out of memory. |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2020 */ |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2021 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2022 ga_concat_strings(garray_T *gap, char *sep) |
2487
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2023 { |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2024 int i; |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2025 int len = 0; |
5873 | 2026 int sep_len = (int)STRLEN(sep); |
2487
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2027 char_u *s; |
5873 | 2028 char_u *p; |
2487
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2029 |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2030 for (i = 0; i < gap->ga_len; ++i) |
5873 | 2031 len += (int)STRLEN(((char_u **)(gap->ga_data))[i]) + sep_len; |
2487
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2032 |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2033 s = alloc(len + 1); |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2034 if (s != NULL) |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2035 { |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2036 *s = NUL; |
5873 | 2037 p = s; |
2487
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2038 for (i = 0; i < gap->ga_len; ++i) |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2039 { |
5873 | 2040 if (p != s) |
2041 { | |
2042 STRCPY(p, sep); | |
2043 p += sep_len; | |
2044 } | |
2045 STRCPY(p, ((char_u **)(gap->ga_data))[i]); | |
2046 p += STRLEN(p); | |
2487
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2047 } |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2048 } |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2049 return s; |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2050 } |
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2051 |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2052 #if defined(FEAT_VIMINFO) || defined(PROTO) |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2053 /* |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2054 * Make a copy of string "p" and add it to "gap". |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2055 * When out of memory nothing changes. |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2056 */ |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2057 void |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2058 ga_add_string(garray_T *gap, char_u *p) |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2059 { |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2060 char_u *cp = vim_strsave(p); |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2061 |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2062 if (cp != NULL) |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2063 { |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2064 if (ga_grow(gap, 1) == OK) |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2065 ((char_u **)(gap->ga_data))[gap->ga_len++] = cp; |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2066 else |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2067 vim_free(cp); |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2068 } |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2069 } |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2070 #endif |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7617
diff
changeset
|
2071 |
2487
7ec9ada2cd81
Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents:
2445
diff
changeset
|
2072 /* |
7 | 2073 * Concatenate a string to a growarray which contains characters. |
7277
6600871bb38c
commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
7214
diff
changeset
|
2074 * When "s" is NULL does not do anything. |
7 | 2075 * Note: Does NOT copy the NUL at the end! |
2076 */ | |
2077 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2078 ga_concat(garray_T *gap, char_u *s) |
7 | 2079 { |
7277
6600871bb38c
commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
7214
diff
changeset
|
2080 int len; |
6600871bb38c
commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
7214
diff
changeset
|
2081 |
6600871bb38c
commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
7214
diff
changeset
|
2082 if (s == NULL) |
6600871bb38c
commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
7214
diff
changeset
|
2083 return; |
6600871bb38c
commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
7214
diff
changeset
|
2084 len = (int)STRLEN(s); |
7 | 2085 if (ga_grow(gap, len) == OK) |
2086 { | |
2087 mch_memmove((char *)gap->ga_data + gap->ga_len, s, (size_t)len); | |
2088 gap->ga_len += len; | |
2089 } | |
2090 } | |
2091 | |
2092 /* | |
2093 * Append one byte to a growarray which contains bytes. | |
2094 */ | |
2095 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2096 ga_append(garray_T *gap, int c) |
7 | 2097 { |
2098 if (ga_grow(gap, 1) == OK) | |
2099 { | |
2100 *((char *)gap->ga_data + gap->ga_len) = c; | |
2101 ++gap->ga_len; | |
2102 } | |
2103 } | |
2104 | |
5995 | 2105 #if (defined(UNIX) && !defined(USE_SYSTEM)) || defined(WIN3264) \ |
2106 || defined(PROTO) | |
2935 | 2107 /* |
2108 * Append the text in "gap" below the cursor line and clear "gap". | |
2109 */ | |
2110 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2111 append_ga_line(garray_T *gap) |
2935 | 2112 { |
2113 /* Remove trailing CR. */ | |
2114 if (gap->ga_len > 0 | |
2115 && !curbuf->b_p_bin | |
2116 && ((char_u *)gap->ga_data)[gap->ga_len - 1] == CAR) | |
2117 --gap->ga_len; | |
2118 ga_append(gap, NUL); | |
2119 ml_append(curwin->w_cursor.lnum++, gap->ga_data, 0, FALSE); | |
2120 gap->ga_len = 0; | |
2121 } | |
2122 #endif | |
2123 | |
7 | 2124 /************************************************************************ |
2125 * functions that use lookup tables for various things, generally to do with | |
2126 * special key codes. | |
2127 */ | |
2128 | |
2129 /* | |
2130 * Some useful tables. | |
2131 */ | |
2132 | |
2133 static struct modmasktable | |
2134 { | |
2135 short mod_mask; /* Bit-mask for particular key modifier */ | |
2136 short mod_flag; /* Bit(s) for particular key modifier */ | |
2137 char_u name; /* Single letter name of modifier */ | |
2138 } mod_mask_table[] = | |
2139 { | |
2140 {MOD_MASK_ALT, MOD_MASK_ALT, (char_u)'M'}, | |
179 | 2141 {MOD_MASK_META, MOD_MASK_META, (char_u)'T'}, |
7 | 2142 {MOD_MASK_CTRL, MOD_MASK_CTRL, (char_u)'C'}, |
2143 {MOD_MASK_SHIFT, MOD_MASK_SHIFT, (char_u)'S'}, | |
2144 {MOD_MASK_MULTI_CLICK, MOD_MASK_2CLICK, (char_u)'2'}, | |
2145 {MOD_MASK_MULTI_CLICK, MOD_MASK_3CLICK, (char_u)'3'}, | |
2146 {MOD_MASK_MULTI_CLICK, MOD_MASK_4CLICK, (char_u)'4'}, | |
2147 #ifdef MACOS | |
2148 {MOD_MASK_CMD, MOD_MASK_CMD, (char_u)'D'}, | |
2149 #endif | |
2150 /* 'A' must be the last one */ | |
2151 {MOD_MASK_ALT, MOD_MASK_ALT, (char_u)'A'}, | |
2152 {0, 0, NUL} | |
2153 }; | |
2154 | |
2155 /* | |
2156 * Shifted key terminal codes and their unshifted equivalent. | |
1209 | 2157 * Don't add mouse codes here, they are handled separately! |
7 | 2158 */ |
2159 #define MOD_KEYS_ENTRY_SIZE 5 | |
2160 | |
2161 static char_u modifier_keys_table[] = | |
2162 { | |
2163 /* mod mask with modifier without modifier */ | |
2164 MOD_MASK_SHIFT, '&', '9', '@', '1', /* begin */ | |
2165 MOD_MASK_SHIFT, '&', '0', '@', '2', /* cancel */ | |
2166 MOD_MASK_SHIFT, '*', '1', '@', '4', /* command */ | |
2167 MOD_MASK_SHIFT, '*', '2', '@', '5', /* copy */ | |
2168 MOD_MASK_SHIFT, '*', '3', '@', '6', /* create */ | |
2169 MOD_MASK_SHIFT, '*', '4', 'k', 'D', /* delete char */ | |
2170 MOD_MASK_SHIFT, '*', '5', 'k', 'L', /* delete line */ | |
2171 MOD_MASK_SHIFT, '*', '7', '@', '7', /* end */ | |
2172 MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_END, '@', '7', /* end */ | |
2173 MOD_MASK_SHIFT, '*', '9', '@', '9', /* exit */ | |
2174 MOD_MASK_SHIFT, '*', '0', '@', '0', /* find */ | |
2175 MOD_MASK_SHIFT, '#', '1', '%', '1', /* help */ | |
2176 MOD_MASK_SHIFT, '#', '2', 'k', 'h', /* home */ | |
2177 MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_HOME, 'k', 'h', /* home */ | |
2178 MOD_MASK_SHIFT, '#', '3', 'k', 'I', /* insert */ | |
2179 MOD_MASK_SHIFT, '#', '4', 'k', 'l', /* left arrow */ | |
2180 MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_LEFT, 'k', 'l', /* left arrow */ | |
2181 MOD_MASK_SHIFT, '%', 'a', '%', '3', /* message */ | |
2182 MOD_MASK_SHIFT, '%', 'b', '%', '4', /* move */ | |
2183 MOD_MASK_SHIFT, '%', 'c', '%', '5', /* next */ | |
2184 MOD_MASK_SHIFT, '%', 'd', '%', '7', /* options */ | |
2185 MOD_MASK_SHIFT, '%', 'e', '%', '8', /* previous */ | |
2186 MOD_MASK_SHIFT, '%', 'f', '%', '9', /* print */ | |
2187 MOD_MASK_SHIFT, '%', 'g', '%', '0', /* redo */ | |
2188 MOD_MASK_SHIFT, '%', 'h', '&', '3', /* replace */ | |
2189 MOD_MASK_SHIFT, '%', 'i', 'k', 'r', /* right arr. */ | |
2190 MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_RIGHT, 'k', 'r', /* right arr. */ | |
2191 MOD_MASK_SHIFT, '%', 'j', '&', '5', /* resume */ | |
2192 MOD_MASK_SHIFT, '!', '1', '&', '6', /* save */ | |
2193 MOD_MASK_SHIFT, '!', '2', '&', '7', /* suspend */ | |
2194 MOD_MASK_SHIFT, '!', '3', '&', '8', /* undo */ | |
2195 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_UP, 'k', 'u', /* up arrow */ | |
2196 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_DOWN, 'k', 'd', /* down arrow */ | |
2197 | |
2198 /* vt100 F1 */ | |
2199 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF1, KS_EXTRA, (int)KE_XF1, | |
2200 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF2, KS_EXTRA, (int)KE_XF2, | |
2201 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF3, KS_EXTRA, (int)KE_XF3, | |
2202 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF4, KS_EXTRA, (int)KE_XF4, | |
2203 | |
2204 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F1, 'k', '1', /* F1 */ | |
2205 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F2, 'k', '2', | |
2206 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F3, 'k', '3', | |
2207 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F4, 'k', '4', | |
2208 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F5, 'k', '5', | |
2209 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F6, 'k', '6', | |
2210 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F7, 'k', '7', | |
2211 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F8, 'k', '8', | |
2212 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F9, 'k', '9', | |
2213 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F10, 'k', ';', /* F10 */ | |
2214 | |
2215 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F11, 'F', '1', | |
2216 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F12, 'F', '2', | |
2217 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F13, 'F', '3', | |
2218 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F14, 'F', '4', | |
2219 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F15, 'F', '5', | |
2220 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F16, 'F', '6', | |
2221 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F17, 'F', '7', | |
2222 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F18, 'F', '8', | |
2223 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F19, 'F', '9', | |
2224 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F20, 'F', 'A', | |
2225 | |
2226 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F21, 'F', 'B', | |
2227 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F22, 'F', 'C', | |
2228 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F23, 'F', 'D', | |
2229 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F24, 'F', 'E', | |
2230 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F25, 'F', 'F', | |
2231 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F26, 'F', 'G', | |
2232 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F27, 'F', 'H', | |
2233 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F28, 'F', 'I', | |
2234 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F29, 'F', 'J', | |
2235 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F30, 'F', 'K', | |
2236 | |
2237 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F31, 'F', 'L', | |
2238 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F32, 'F', 'M', | |
2239 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F33, 'F', 'N', | |
2240 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F34, 'F', 'O', | |
2241 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F35, 'F', 'P', | |
2242 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F36, 'F', 'Q', | |
2243 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F37, 'F', 'R', | |
2244 | |
2245 /* TAB pseudo code*/ | |
2246 MOD_MASK_SHIFT, 'k', 'B', KS_EXTRA, (int)KE_TAB, | |
2247 | |
2248 NUL | |
2249 }; | |
2250 | |
2251 static struct key_name_entry | |
2252 { | |
2253 int key; /* Special key code or ascii value */ | |
2254 char_u *name; /* Name of key */ | |
2255 } key_names_table[] = | |
2256 { | |
2257 {' ', (char_u *)"Space"}, | |
2258 {TAB, (char_u *)"Tab"}, | |
2259 {K_TAB, (char_u *)"Tab"}, | |
2260 {NL, (char_u *)"NL"}, | |
2261 {NL, (char_u *)"NewLine"}, /* Alternative name */ | |
2262 {NL, (char_u *)"LineFeed"}, /* Alternative name */ | |
2263 {NL, (char_u *)"LF"}, /* Alternative name */ | |
2264 {CAR, (char_u *)"CR"}, | |
2265 {CAR, (char_u *)"Return"}, /* Alternative name */ | |
2266 {CAR, (char_u *)"Enter"}, /* Alternative name */ | |
2267 {K_BS, (char_u *)"BS"}, | |
2268 {K_BS, (char_u *)"BackSpace"}, /* Alternative name */ | |
2269 {ESC, (char_u *)"Esc"}, | |
2270 {CSI, (char_u *)"CSI"}, | |
2271 {K_CSI, (char_u *)"xCSI"}, | |
2272 {'|', (char_u *)"Bar"}, | |
2273 {'\\', (char_u *)"Bslash"}, | |
2274 {K_DEL, (char_u *)"Del"}, | |
2275 {K_DEL, (char_u *)"Delete"}, /* Alternative name */ | |
2276 {K_KDEL, (char_u *)"kDel"}, | |
2277 {K_UP, (char_u *)"Up"}, | |
2278 {K_DOWN, (char_u *)"Down"}, | |
2279 {K_LEFT, (char_u *)"Left"}, | |
2280 {K_RIGHT, (char_u *)"Right"}, | |
180 | 2281 {K_XUP, (char_u *)"xUp"}, |
2282 {K_XDOWN, (char_u *)"xDown"}, | |
2283 {K_XLEFT, (char_u *)"xLeft"}, | |
2284 {K_XRIGHT, (char_u *)"xRight"}, | |
7 | 2285 |
2286 {K_F1, (char_u *)"F1"}, | |
2287 {K_F2, (char_u *)"F2"}, | |
2288 {K_F3, (char_u *)"F3"}, | |
2289 {K_F4, (char_u *)"F4"}, | |
2290 {K_F5, (char_u *)"F5"}, | |
2291 {K_F6, (char_u *)"F6"}, | |
2292 {K_F7, (char_u *)"F7"}, | |
2293 {K_F8, (char_u *)"F8"}, | |
2294 {K_F9, (char_u *)"F9"}, | |
2295 {K_F10, (char_u *)"F10"}, | |
2296 | |
2297 {K_F11, (char_u *)"F11"}, | |
2298 {K_F12, (char_u *)"F12"}, | |
2299 {K_F13, (char_u *)"F13"}, | |
2300 {K_F14, (char_u *)"F14"}, | |
2301 {K_F15, (char_u *)"F15"}, | |
2302 {K_F16, (char_u *)"F16"}, | |
2303 {K_F17, (char_u *)"F17"}, | |
2304 {K_F18, (char_u *)"F18"}, | |
2305 {K_F19, (char_u *)"F19"}, | |
2306 {K_F20, (char_u *)"F20"}, | |
2307 | |
2308 {K_F21, (char_u *)"F21"}, | |
2309 {K_F22, (char_u *)"F22"}, | |
2310 {K_F23, (char_u *)"F23"}, | |
2311 {K_F24, (char_u *)"F24"}, | |
2312 {K_F25, (char_u *)"F25"}, | |
2313 {K_F26, (char_u *)"F26"}, | |
2314 {K_F27, (char_u *)"F27"}, | |
2315 {K_F28, (char_u *)"F28"}, | |
2316 {K_F29, (char_u *)"F29"}, | |
2317 {K_F30, (char_u *)"F30"}, | |
2318 | |
2319 {K_F31, (char_u *)"F31"}, | |
2320 {K_F32, (char_u *)"F32"}, | |
2321 {K_F33, (char_u *)"F33"}, | |
2322 {K_F34, (char_u *)"F34"}, | |
2323 {K_F35, (char_u *)"F35"}, | |
2324 {K_F36, (char_u *)"F36"}, | |
2325 {K_F37, (char_u *)"F37"}, | |
2326 | |
2327 {K_XF1, (char_u *)"xF1"}, | |
2328 {K_XF2, (char_u *)"xF2"}, | |
2329 {K_XF3, (char_u *)"xF3"}, | |
2330 {K_XF4, (char_u *)"xF4"}, | |
2331 | |
2332 {K_HELP, (char_u *)"Help"}, | |
2333 {K_UNDO, (char_u *)"Undo"}, | |
2334 {K_INS, (char_u *)"Insert"}, | |
2335 {K_INS, (char_u *)"Ins"}, /* Alternative name */ | |
2336 {K_KINS, (char_u *)"kInsert"}, | |
2337 {K_HOME, (char_u *)"Home"}, | |
2338 {K_KHOME, (char_u *)"kHome"}, | |
2339 {K_XHOME, (char_u *)"xHome"}, | |
230 | 2340 {K_ZHOME, (char_u *)"zHome"}, |
7 | 2341 {K_END, (char_u *)"End"}, |
2342 {K_KEND, (char_u *)"kEnd"}, | |
2343 {K_XEND, (char_u *)"xEnd"}, | |
230 | 2344 {K_ZEND, (char_u *)"zEnd"}, |
7 | 2345 {K_PAGEUP, (char_u *)"PageUp"}, |
2346 {K_PAGEDOWN, (char_u *)"PageDown"}, | |
2347 {K_KPAGEUP, (char_u *)"kPageUp"}, | |
2348 {K_KPAGEDOWN, (char_u *)"kPageDown"}, | |
2349 | |
2350 {K_KPLUS, (char_u *)"kPlus"}, | |
2351 {K_KMINUS, (char_u *)"kMinus"}, | |
2352 {K_KDIVIDE, (char_u *)"kDivide"}, | |
2353 {K_KMULTIPLY, (char_u *)"kMultiply"}, | |
2354 {K_KENTER, (char_u *)"kEnter"}, | |
2355 {K_KPOINT, (char_u *)"kPoint"}, | |
2356 | |
2357 {K_K0, (char_u *)"k0"}, | |
2358 {K_K1, (char_u *)"k1"}, | |
2359 {K_K2, (char_u *)"k2"}, | |
2360 {K_K3, (char_u *)"k3"}, | |
2361 {K_K4, (char_u *)"k4"}, | |
2362 {K_K5, (char_u *)"k5"}, | |
2363 {K_K6, (char_u *)"k6"}, | |
2364 {K_K7, (char_u *)"k7"}, | |
2365 {K_K8, (char_u *)"k8"}, | |
2366 {K_K9, (char_u *)"k9"}, | |
2367 | |
2368 {'<', (char_u *)"lt"}, | |
2369 | |
2370 {K_MOUSE, (char_u *)"Mouse"}, | |
3273 | 2371 #ifdef FEAT_MOUSE_NET |
7 | 2372 {K_NETTERM_MOUSE, (char_u *)"NetMouse"}, |
3273 | 2373 #endif |
2374 #ifdef FEAT_MOUSE_DEC | |
7 | 2375 {K_DEC_MOUSE, (char_u *)"DecMouse"}, |
3273 | 2376 #endif |
2377 #ifdef FEAT_MOUSE_JSB | |
7 | 2378 {K_JSBTERM_MOUSE, (char_u *)"JsbMouse"}, |
3273 | 2379 #endif |
2380 #ifdef FEAT_MOUSE_PTERM | |
7 | 2381 {K_PTERM_MOUSE, (char_u *)"PtermMouse"}, |
3273 | 2382 #endif |
2383 #ifdef FEAT_MOUSE_URXVT | |
2384 {K_URXVT_MOUSE, (char_u *)"UrxvtMouse"}, | |
2385 #endif | |
3746 | 2386 #ifdef FEAT_MOUSE_SGR |
2387 {K_SGR_MOUSE, (char_u *)"SgrMouse"}, | |
2388 #endif | |
7 | 2389 {K_LEFTMOUSE, (char_u *)"LeftMouse"}, |
2390 {K_LEFTMOUSE_NM, (char_u *)"LeftMouseNM"}, | |
2391 {K_LEFTDRAG, (char_u *)"LeftDrag"}, | |
2392 {K_LEFTRELEASE, (char_u *)"LeftRelease"}, | |
2393 {K_LEFTRELEASE_NM, (char_u *)"LeftReleaseNM"}, | |
2394 {K_MIDDLEMOUSE, (char_u *)"MiddleMouse"}, | |
2395 {K_MIDDLEDRAG, (char_u *)"MiddleDrag"}, | |
2396 {K_MIDDLERELEASE, (char_u *)"MiddleRelease"}, | |
2397 {K_RIGHTMOUSE, (char_u *)"RightMouse"}, | |
2398 {K_RIGHTDRAG, (char_u *)"RightDrag"}, | |
2399 {K_RIGHTRELEASE, (char_u *)"RightRelease"}, | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2363
diff
changeset
|
2400 {K_MOUSEDOWN, (char_u *)"ScrollWheelUp"}, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2363
diff
changeset
|
2401 {K_MOUSEUP, (char_u *)"ScrollWheelDown"}, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2363
diff
changeset
|
2402 {K_MOUSELEFT, (char_u *)"ScrollWheelRight"}, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2363
diff
changeset
|
2403 {K_MOUSERIGHT, (char_u *)"ScrollWheelLeft"}, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2363
diff
changeset
|
2404 {K_MOUSEDOWN, (char_u *)"MouseDown"}, /* OBSOLETE: Use */ |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2363
diff
changeset
|
2405 {K_MOUSEUP, (char_u *)"MouseUp"}, /* ScrollWheelXXX instead */ |
7 | 2406 {K_X1MOUSE, (char_u *)"X1Mouse"}, |
2407 {K_X1DRAG, (char_u *)"X1Drag"}, | |
2408 {K_X1RELEASE, (char_u *)"X1Release"}, | |
2409 {K_X2MOUSE, (char_u *)"X2Mouse"}, | |
2410 {K_X2DRAG, (char_u *)"X2Drag"}, | |
2411 {K_X2RELEASE, (char_u *)"X2Release"}, | |
2412 {K_DROP, (char_u *)"Drop"}, | |
2413 {K_ZERO, (char_u *)"Nul"}, | |
2414 #ifdef FEAT_EVAL | |
2415 {K_SNR, (char_u *)"SNR"}, | |
2416 #endif | |
2417 {K_PLUG, (char_u *)"Plug"}, | |
6245 | 2418 {K_CURSORHOLD, (char_u *)"CursorHold"}, |
7 | 2419 {0, NULL} |
2420 }; | |
2421 | |
2422 #define KEY_NAMES_TABLE_LEN (sizeof(key_names_table) / sizeof(struct key_name_entry)) | |
2423 | |
2424 #ifdef FEAT_MOUSE | |
2425 static struct mousetable | |
2426 { | |
2427 int pseudo_code; /* Code for pseudo mouse event */ | |
2428 int button; /* Which mouse button is it? */ | |
2429 int is_click; /* Is it a mouse button click event? */ | |
2430 int is_drag; /* Is it a mouse drag event? */ | |
2431 } mouse_table[] = | |
2432 { | |
2433 {(int)KE_LEFTMOUSE, MOUSE_LEFT, TRUE, FALSE}, | |
2434 #ifdef FEAT_GUI | |
2435 {(int)KE_LEFTMOUSE_NM, MOUSE_LEFT, TRUE, FALSE}, | |
2436 #endif | |
2437 {(int)KE_LEFTDRAG, MOUSE_LEFT, FALSE, TRUE}, | |
2438 {(int)KE_LEFTRELEASE, MOUSE_LEFT, FALSE, FALSE}, | |
2439 #ifdef FEAT_GUI | |
2440 {(int)KE_LEFTRELEASE_NM, MOUSE_LEFT, FALSE, FALSE}, | |
2441 #endif | |
2442 {(int)KE_MIDDLEMOUSE, MOUSE_MIDDLE, TRUE, FALSE}, | |
2443 {(int)KE_MIDDLEDRAG, MOUSE_MIDDLE, FALSE, TRUE}, | |
2444 {(int)KE_MIDDLERELEASE, MOUSE_MIDDLE, FALSE, FALSE}, | |
2445 {(int)KE_RIGHTMOUSE, MOUSE_RIGHT, TRUE, FALSE}, | |
2446 {(int)KE_RIGHTDRAG, MOUSE_RIGHT, FALSE, TRUE}, | |
2447 {(int)KE_RIGHTRELEASE, MOUSE_RIGHT, FALSE, FALSE}, | |
2448 {(int)KE_X1MOUSE, MOUSE_X1, TRUE, FALSE}, | |
2449 {(int)KE_X1DRAG, MOUSE_X1, FALSE, TRUE}, | |
2450 {(int)KE_X1RELEASE, MOUSE_X1, FALSE, FALSE}, | |
2451 {(int)KE_X2MOUSE, MOUSE_X2, TRUE, FALSE}, | |
2452 {(int)KE_X2DRAG, MOUSE_X2, FALSE, TRUE}, | |
2453 {(int)KE_X2RELEASE, MOUSE_X2, FALSE, FALSE}, | |
2454 /* DRAG without CLICK */ | |
2455 {(int)KE_IGNORE, MOUSE_RELEASE, FALSE, TRUE}, | |
2456 /* RELEASE without CLICK */ | |
2457 {(int)KE_IGNORE, MOUSE_RELEASE, FALSE, FALSE}, | |
2458 {0, 0, 0, 0}, | |
2459 }; | |
2460 #endif /* FEAT_MOUSE */ | |
2461 | |
2462 /* | |
2463 * Return the modifier mask bit (MOD_MASK_*) which corresponds to the given | |
2464 * modifier name ('S' for Shift, 'C' for Ctrl etc). | |
2465 */ | |
2466 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2467 name_to_mod_mask(int c) |
7 | 2468 { |
2469 int i; | |
2470 | |
2471 c = TOUPPER_ASC(c); | |
2472 for (i = 0; mod_mask_table[i].mod_mask != 0; i++) | |
2473 if (c == mod_mask_table[i].name) | |
2474 return mod_mask_table[i].mod_flag; | |
2475 return 0; | |
2476 } | |
2477 | |
2478 /* | |
2479 * Check if if there is a special key code for "key" that includes the | |
2480 * modifiers specified. | |
2481 */ | |
2482 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2483 simplify_key(int key, int *modifiers) |
7 | 2484 { |
2485 int i; | |
2486 int key0; | |
2487 int key1; | |
2488 | |
2489 if (*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT)) | |
2490 { | |
2491 /* TAB is a special case */ | |
2492 if (key == TAB && (*modifiers & MOD_MASK_SHIFT)) | |
2493 { | |
2494 *modifiers &= ~MOD_MASK_SHIFT; | |
2495 return K_S_TAB; | |
2496 } | |
2497 key0 = KEY2TERMCAP0(key); | |
2498 key1 = KEY2TERMCAP1(key); | |
2499 for (i = 0; modifier_keys_table[i] != NUL; i += MOD_KEYS_ENTRY_SIZE) | |
2500 if (key0 == modifier_keys_table[i + 3] | |
2501 && key1 == modifier_keys_table[i + 4] | |
2502 && (*modifiers & modifier_keys_table[i])) | |
2503 { | |
2504 *modifiers &= ~modifier_keys_table[i]; | |
2505 return TERMCAP2KEY(modifier_keys_table[i + 1], | |
2506 modifier_keys_table[i + 2]); | |
2507 } | |
2508 } | |
2509 return key; | |
2510 } | |
2511 | |
2512 /* | |
180 | 2513 * Change <xHome> to <Home>, <xUp> to <Up>, etc. |
2514 */ | |
2515 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2516 handle_x_keys(int key) |
180 | 2517 { |
2518 switch (key) | |
2519 { | |
2520 case K_XUP: return K_UP; | |
2521 case K_XDOWN: return K_DOWN; | |
2522 case K_XLEFT: return K_LEFT; | |
2523 case K_XRIGHT: return K_RIGHT; | |
2524 case K_XHOME: return K_HOME; | |
230 | 2525 case K_ZHOME: return K_HOME; |
180 | 2526 case K_XEND: return K_END; |
230 | 2527 case K_ZEND: return K_END; |
180 | 2528 case K_XF1: return K_F1; |
2529 case K_XF2: return K_F2; | |
2530 case K_XF3: return K_F3; | |
2531 case K_XF4: return K_F4; | |
2532 case K_S_XF1: return K_S_F1; | |
2533 case K_S_XF2: return K_S_F2; | |
2534 case K_S_XF3: return K_S_F3; | |
2535 case K_S_XF4: return K_S_F4; | |
2536 } | |
2537 return key; | |
2538 } | |
2539 | |
2540 /* | |
7 | 2541 * Return a string which contains the name of the given key when the given |
2542 * modifiers are down. | |
2543 */ | |
2544 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2545 get_special_key_name(int c, int modifiers) |
7 | 2546 { |
2547 static char_u string[MAX_KEY_NAME_LEN + 1]; | |
2548 | |
2549 int i, idx; | |
2550 int table_idx; | |
2551 char_u *s; | |
2552 | |
2553 string[0] = '<'; | |
2554 idx = 1; | |
2555 | |
2556 /* Key that stands for a normal character. */ | |
2557 if (IS_SPECIAL(c) && KEY2TERMCAP0(c) == KS_KEY) | |
2558 c = KEY2TERMCAP1(c); | |
2559 | |
2560 /* | |
2561 * Translate shifted special keys into unshifted keys and set modifier. | |
2562 * Same for CTRL and ALT modifiers. | |
2563 */ | |
2564 if (IS_SPECIAL(c)) | |
2565 { | |
2566 for (i = 0; modifier_keys_table[i] != 0; i += MOD_KEYS_ENTRY_SIZE) | |
2567 if ( KEY2TERMCAP0(c) == (int)modifier_keys_table[i + 1] | |
2568 && (int)KEY2TERMCAP1(c) == (int)modifier_keys_table[i + 2]) | |
2569 { | |
2570 modifiers |= modifier_keys_table[i]; | |
2571 c = TERMCAP2KEY(modifier_keys_table[i + 3], | |
2572 modifier_keys_table[i + 4]); | |
2573 break; | |
2574 } | |
2575 } | |
2576 | |
2577 /* try to find the key in the special key table */ | |
2578 table_idx = find_special_key_in_table(c); | |
2579 | |
2580 /* | |
2581 * When not a known special key, and not a printable character, try to | |
2582 * extract modifiers. | |
2583 */ | |
2584 if (c > 0 | |
2585 #ifdef FEAT_MBYTE | |
2586 && (*mb_char2len)(c) == 1 | |
2587 #endif | |
2588 ) | |
2589 { | |
2590 if (table_idx < 0 | |
2591 && (!vim_isprintc(c) || (c & 0x7f) == ' ') | |
2592 && (c & 0x80)) | |
2593 { | |
2594 c &= 0x7f; | |
2595 modifiers |= MOD_MASK_ALT; | |
2596 /* try again, to find the un-alted key in the special key table */ | |
2597 table_idx = find_special_key_in_table(c); | |
2598 } | |
2599 if (table_idx < 0 && !vim_isprintc(c) && c < ' ') | |
2600 { | |
2601 #ifdef EBCDIC | |
2602 c = CtrlChar(c); | |
2603 #else | |
2604 c += '@'; | |
2605 #endif | |
2606 modifiers |= MOD_MASK_CTRL; | |
2607 } | |
2608 } | |
2609 | |
2610 /* translate the modifier into a string */ | |
2611 for (i = 0; mod_mask_table[i].name != 'A'; i++) | |
2612 if ((modifiers & mod_mask_table[i].mod_mask) | |
2613 == mod_mask_table[i].mod_flag) | |
2614 { | |
2615 string[idx++] = mod_mask_table[i].name; | |
2616 string[idx++] = (char_u)'-'; | |
2617 } | |
2618 | |
2619 if (table_idx < 0) /* unknown special key, may output t_xx */ | |
2620 { | |
2621 if (IS_SPECIAL(c)) | |
2622 { | |
2623 string[idx++] = 't'; | |
2624 string[idx++] = '_'; | |
2625 string[idx++] = KEY2TERMCAP0(c); | |
2626 string[idx++] = KEY2TERMCAP1(c); | |
2627 } | |
2628 /* Not a special key, only modifiers, output directly */ | |
2629 else | |
2630 { | |
2631 #ifdef FEAT_MBYTE | |
2632 if (has_mbyte && (*mb_char2len)(c) > 1) | |
2633 idx += (*mb_char2bytes)(c, string + idx); | |
2634 else | |
2635 #endif | |
2636 if (vim_isprintc(c)) | |
2637 string[idx++] = c; | |
2638 else | |
2639 { | |
2640 s = transchar(c); | |
2641 while (*s) | |
2642 string[idx++] = *s++; | |
2643 } | |
2644 } | |
2645 } | |
2646 else /* use name of special key */ | |
2647 { | |
2648 STRCPY(string + idx, key_names_table[table_idx].name); | |
2649 idx = (int)STRLEN(string); | |
2650 } | |
2651 string[idx++] = '>'; | |
2652 string[idx] = NUL; | |
2653 return string; | |
2654 } | |
2655 | |
2656 /* | |
2657 * Try translating a <> name at (*srcp)[] to dst[]. | |
2658 * Return the number of characters added to dst[], zero for no match. | |
2659 * If there is a match, srcp is advanced to after the <> name. | |
2660 * dst[] must be big enough to hold the result (up to six characters)! | |
2661 */ | |
2662 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2663 trans_special( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2664 char_u **srcp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2665 char_u *dst, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2666 int keycode) /* prefer key code, e.g. K_DEL instead of DEL */ |
7 | 2667 { |
2668 int modifiers = 0; | |
2669 int key; | |
2670 int dlen = 0; | |
2671 | |
1775 | 2672 key = find_special_key(srcp, &modifiers, keycode, FALSE); |
7 | 2673 if (key == 0) |
2674 return 0; | |
2675 | |
2676 /* Put the appropriate modifier in a string */ | |
2677 if (modifiers != 0) | |
2678 { | |
2679 dst[dlen++] = K_SPECIAL; | |
2680 dst[dlen++] = KS_MODIFIER; | |
2681 dst[dlen++] = modifiers; | |
2682 } | |
2683 | |
2684 if (IS_SPECIAL(key)) | |
2685 { | |
2686 dst[dlen++] = K_SPECIAL; | |
2687 dst[dlen++] = KEY2TERMCAP0(key); | |
2688 dst[dlen++] = KEY2TERMCAP1(key); | |
2689 } | |
2690 #ifdef FEAT_MBYTE | |
2691 else if (has_mbyte && !keycode) | |
2692 dlen += (*mb_char2bytes)(key, dst + dlen); | |
2693 #endif | |
2694 else if (keycode) | |
2695 dlen = (int)(add_char2buf(key, dst + dlen) - dst); | |
2696 else | |
2697 dst[dlen++] = key; | |
2698 | |
2699 return dlen; | |
2700 } | |
2701 | |
2702 /* | |
2703 * Try translating a <> name at (*srcp)[], return the key and modifiers. | |
2704 * srcp is advanced to after the <> name. | |
2705 * returns 0 if there is no match. | |
2706 */ | |
2707 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2708 find_special_key( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2709 char_u **srcp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2710 int *modp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2711 int keycode, /* prefer key code, e.g. K_DEL instead of DEL */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2712 int keep_x_key) /* don't translate xHome to Home key */ |
7 | 2713 { |
2714 char_u *last_dash; | |
2715 char_u *end_of_name; | |
2716 char_u *src; | |
2717 char_u *bp; | |
2718 int modifiers; | |
2719 int bit; | |
2720 int key; | |
835 | 2721 unsigned long n; |
3024 | 2722 int l; |
7 | 2723 |
2724 src = *srcp; | |
2725 if (src[0] != '<') | |
2726 return 0; | |
2727 | |
2728 /* Find end of modifier list */ | |
2729 last_dash = src; | |
2730 for (bp = src + 1; *bp == '-' || vim_isIDc(*bp); bp++) | |
2731 { | |
2732 if (*bp == '-') | |
2733 { | |
2734 last_dash = bp; | |
3024 | 2735 if (bp[1] != NUL) |
2736 { | |
2737 #ifdef FEAT_MBYTE | |
2738 if (has_mbyte) | |
2739 l = mb_ptr2len(bp + 1); | |
2740 else | |
2741 #endif | |
2742 l = 1; | |
2743 if (bp[l + 1] == '>') | |
2744 bp += l; /* anything accepted, like <C-?> */ | |
2745 } | |
7 | 2746 } |
2747 if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3]) | |
2748 bp += 3; /* skip t_xx, xx may be '-' or '>' */ | |
3026 | 2749 else if (STRNICMP(bp, "char-", 5) == 0) |
2750 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
2751 vim_str2nr(bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0); |
3026 | 2752 bp += l + 5; |
2753 break; | |
2754 } | |
7 | 2755 } |
2756 | |
2757 if (*bp == '>') /* found matching '>' */ | |
2758 { | |
2759 end_of_name = bp + 1; | |
2760 | |
2761 /* Which modifiers are given? */ | |
2762 modifiers = 0x0; | |
2763 for (bp = src + 1; bp < last_dash; bp++) | |
2764 { | |
2765 if (*bp != '-') | |
2766 { | |
2767 bit = name_to_mod_mask(*bp); | |
2768 if (bit == 0x0) | |
2769 break; /* Illegal modifier name */ | |
2770 modifiers |= bit; | |
2771 } | |
2772 } | |
2773 | |
2774 /* | |
2775 * Legal modifier name. | |
2776 */ | |
2777 if (bp >= last_dash) | |
2778 { | |
3024 | 2779 if (STRNICMP(last_dash + 1, "char-", 5) == 0 |
2780 && VIM_ISDIGIT(last_dash[6])) | |
2781 { | |
2782 /* <Char-123> or <Char-033> or <Char-0x33> */ | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
2783 vim_str2nr(last_dash + 6, NULL, NULL, STR2NR_ALL, NULL, &n, 0); |
3026 | 2784 key = (int)n; |
3024 | 2785 } |
7 | 2786 else |
180 | 2787 { |
3026 | 2788 /* |
2789 * Modifier with single letter, or special key name. | |
2790 */ | |
2791 #ifdef FEAT_MBYTE | |
2792 if (has_mbyte) | |
2793 l = mb_ptr2len(last_dash + 1); | |
2794 else | |
2795 #endif | |
2796 l = 1; | |
2797 if (modifiers != 0 && last_dash[l + 1] == '>') | |
2798 key = PTR2CHAR(last_dash + 1); | |
2799 else | |
2800 { | |
2801 key = get_special_key_code(last_dash + 1); | |
2802 if (!keep_x_key) | |
2803 key = handle_x_keys(key); | |
2804 } | |
180 | 2805 } |
7 | 2806 |
2807 /* | |
2808 * get_special_key_code() may return NUL for invalid | |
2809 * special key name. | |
2810 */ | |
2811 if (key != NUL) | |
2812 { | |
2813 /* | |
2814 * Only use a modifier when there is no special key code that | |
2815 * includes the modifier. | |
2816 */ | |
2817 key = simplify_key(key, &modifiers); | |
2818 | |
2819 if (!keycode) | |
2820 { | |
2821 /* don't want keycode, use single byte code */ | |
2822 if (key == K_BS) | |
2823 key = BS; | |
2824 else if (key == K_DEL || key == K_KDEL) | |
2825 key = DEL; | |
2826 } | |
2827 | |
2828 /* | |
2829 * Normal Key with modifier: Try to make a single byte code. | |
2830 */ | |
2831 if (!IS_SPECIAL(key)) | |
2832 key = extract_modifiers(key, &modifiers); | |
2833 | |
2834 *modp = modifiers; | |
2835 *srcp = end_of_name; | |
2836 return key; | |
2837 } | |
2838 } | |
2839 } | |
2840 return 0; | |
2841 } | |
2842 | |
2843 /* | |
2844 * Try to include modifiers in the key. | |
2845 * Changes "Shift-a" to 'A', "Alt-A" to 0xc0, etc. | |
2846 */ | |
2847 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2848 extract_modifiers(int key, int *modp) |
7 | 2849 { |
2850 int modifiers = *modp; | |
2851 | |
2852 #ifdef MACOS | |
4352 | 2853 /* Command-key really special, no fancynest */ |
7 | 2854 if (!(modifiers & MOD_MASK_CMD)) |
2855 #endif | |
2856 if ((modifiers & MOD_MASK_SHIFT) && ASCII_ISALPHA(key)) | |
2857 { | |
2858 key = TOUPPER_ASC(key); | |
2859 modifiers &= ~MOD_MASK_SHIFT; | |
2860 } | |
2861 if ((modifiers & MOD_MASK_CTRL) | |
2862 #ifdef EBCDIC | |
2863 /* * TODO: EBCDIC Better use: | |
2864 * && (Ctrl_chr(key) || key == '?') | |
2865 * ??? */ | |
2866 && strchr("?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_", key) | |
2867 != NULL | |
2868 #else | |
2869 && ((key >= '?' && key <= '_') || ASCII_ISALPHA(key)) | |
2870 #endif | |
2871 ) | |
2872 { | |
2873 key = Ctrl_chr(key); | |
2874 modifiers &= ~MOD_MASK_CTRL; | |
2875 /* <C-@> is <Nul> */ | |
2876 if (key == 0) | |
2877 key = K_ZERO; | |
2878 } | |
2879 #ifdef MACOS | |
4352 | 2880 /* Command-key really special, no fancynest */ |
7 | 2881 if (!(modifiers & MOD_MASK_CMD)) |
2882 #endif | |
2883 if ((modifiers & MOD_MASK_ALT) && key < 0x80 | |
2884 #ifdef FEAT_MBYTE | |
2885 && !enc_dbcs /* avoid creating a lead byte */ | |
2886 #endif | |
2887 ) | |
2888 { | |
2889 key |= 0x80; | |
2890 modifiers &= ~MOD_MASK_ALT; /* remove the META modifier */ | |
2891 } | |
2892 | |
2893 *modp = modifiers; | |
2894 return key; | |
2895 } | |
2896 | |
2897 /* | |
2898 * Try to find key "c" in the special key table. | |
2899 * Return the index when found, -1 when not found. | |
2900 */ | |
2901 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2902 find_special_key_in_table(int c) |
7 | 2903 { |
2904 int i; | |
2905 | |
2906 for (i = 0; key_names_table[i].name != NULL; i++) | |
2907 if (c == key_names_table[i].key) | |
2908 break; | |
2909 if (key_names_table[i].name == NULL) | |
2910 i = -1; | |
2911 return i; | |
2912 } | |
2913 | |
2914 /* | |
2915 * Find the special key with the given name (the given string does not have to | |
2916 * end with NUL, the name is assumed to end before the first non-idchar). | |
2917 * If the name starts with "t_" the next two characters are interpreted as a | |
2918 * termcap name. | |
2919 * Return the key code, or 0 if not found. | |
2920 */ | |
2921 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2922 get_special_key_code(char_u *name) |
7 | 2923 { |
2924 char_u *table_name; | |
2925 char_u string[3]; | |
2926 int i, j; | |
2927 | |
2928 /* | |
2929 * If it's <t_xx> we get the code for xx from the termcap | |
2930 */ | |
2931 if (name[0] == 't' && name[1] == '_' && name[2] != NUL && name[3] != NUL) | |
2932 { | |
2933 string[0] = name[2]; | |
2934 string[1] = name[3]; | |
2935 string[2] = NUL; | |
2936 if (add_termcap_entry(string, FALSE) == OK) | |
2937 return TERMCAP2KEY(name[2], name[3]); | |
2938 } | |
2939 else | |
2940 for (i = 0; key_names_table[i].name != NULL; i++) | |
2941 { | |
2942 table_name = key_names_table[i].name; | |
2943 for (j = 0; vim_isIDc(name[j]) && table_name[j] != NUL; j++) | |
2944 if (TOLOWER_ASC(table_name[j]) != TOLOWER_ASC(name[j])) | |
2945 break; | |
2946 if (!vim_isIDc(name[j]) && table_name[j] == NUL) | |
2947 return key_names_table[i].key; | |
2948 } | |
2949 return 0; | |
2950 } | |
2951 | |
1661 | 2952 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
7 | 2953 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2954 get_key_name(int i) |
7 | 2955 { |
1881 | 2956 if (i >= (int)KEY_NAMES_TABLE_LEN) |
7 | 2957 return NULL; |
2958 return key_names_table[i].name; | |
2959 } | |
2960 #endif | |
2961 | |
1661 | 2962 #if defined(FEAT_MOUSE) || defined(PROTO) |
7 | 2963 /* |
2964 * Look up the given mouse code to return the relevant information in the other | |
2965 * arguments. Return which button is down or was released. | |
2966 */ | |
2967 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2968 get_mouse_button(int code, int *is_click, int *is_drag) |
7 | 2969 { |
2970 int i; | |
2971 | |
2972 for (i = 0; mouse_table[i].pseudo_code; i++) | |
2973 if (code == mouse_table[i].pseudo_code) | |
2974 { | |
2975 *is_click = mouse_table[i].is_click; | |
2976 *is_drag = mouse_table[i].is_drag; | |
2977 return mouse_table[i].button; | |
2978 } | |
2979 return 0; /* Shouldn't get here */ | |
2980 } | |
2981 | |
2982 /* | |
2983 * Return the appropriate pseudo mouse event token (KE_LEFTMOUSE etc) based on | |
2984 * the given information about which mouse button is down, and whether the | |
2985 * mouse was clicked, dragged or released. | |
2986 */ | |
2987 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2988 get_pseudo_mouse_code( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2989 int button, /* eg MOUSE_LEFT */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2990 int is_click, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2991 int is_drag) |
7 | 2992 { |
2993 int i; | |
2994 | |
2995 for (i = 0; mouse_table[i].pseudo_code; i++) | |
2996 if (button == mouse_table[i].button | |
2997 && is_click == mouse_table[i].is_click | |
2998 && is_drag == mouse_table[i].is_drag) | |
2999 { | |
3000 #ifdef FEAT_GUI | |
263 | 3001 /* Trick: a non mappable left click and release has mouse_col -1 |
3002 * or added MOUSE_COLOFF. Used for 'mousefocus' in | |
3003 * gui_mouse_moved() */ | |
3004 if (mouse_col < 0 || mouse_col > MOUSE_COLOFF) | |
7 | 3005 { |
263 | 3006 if (mouse_col < 0) |
3007 mouse_col = 0; | |
3008 else | |
3009 mouse_col -= MOUSE_COLOFF; | |
7 | 3010 if (mouse_table[i].pseudo_code == (int)KE_LEFTMOUSE) |
3011 return (int)KE_LEFTMOUSE_NM; | |
3012 if (mouse_table[i].pseudo_code == (int)KE_LEFTRELEASE) | |
3013 return (int)KE_LEFTRELEASE_NM; | |
3014 } | |
3015 #endif | |
3016 return mouse_table[i].pseudo_code; | |
3017 } | |
1209 | 3018 return (int)KE_IGNORE; /* not recognized, ignore it */ |
7 | 3019 } |
3020 #endif /* FEAT_MOUSE */ | |
3021 | |
3022 /* | |
3023 * Return the current end-of-line type: EOL_DOS, EOL_UNIX or EOL_MAC. | |
3024 */ | |
3025 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3026 get_fileformat(buf_T *buf) |
7 | 3027 { |
3028 int c = *buf->b_p_ff; | |
3029 | |
3030 if (buf->b_p_bin || c == 'u') | |
3031 return EOL_UNIX; | |
3032 if (c == 'm') | |
3033 return EOL_MAC; | |
3034 return EOL_DOS; | |
3035 } | |
3036 | |
3037 /* | |
3038 * Like get_fileformat(), but override 'fileformat' with "p" for "++opt=val" | |
3039 * argument. | |
3040 */ | |
3041 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3042 get_fileformat_force( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3043 buf_T *buf, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3044 exarg_T *eap) /* can be NULL! */ |
7 | 3045 { |
3046 int c; | |
3047 | |
3048 if (eap != NULL && eap->force_ff != 0) | |
3049 c = eap->cmd[eap->force_ff]; | |
3050 else | |
3051 { | |
3052 if ((eap != NULL && eap->force_bin != 0) | |
3053 ? (eap->force_bin == FORCE_BIN) : buf->b_p_bin) | |
3054 return EOL_UNIX; | |
3055 c = *buf->b_p_ff; | |
3056 } | |
3057 if (c == 'u') | |
3058 return EOL_UNIX; | |
3059 if (c == 'm') | |
3060 return EOL_MAC; | |
3061 return EOL_DOS; | |
3062 } | |
3063 | |
3064 /* | |
3065 * Set the current end-of-line type to EOL_DOS, EOL_UNIX or EOL_MAC. | |
3066 * Sets both 'textmode' and 'fileformat'. | |
3067 * Note: Does _not_ set global value of 'textmode'! | |
3068 */ | |
3069 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3070 set_fileformat( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3071 int t, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3072 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */ |
7 | 3073 { |
3074 char *p = NULL; | |
3075 | |
3076 switch (t) | |
3077 { | |
3078 case EOL_DOS: | |
3079 p = FF_DOS; | |
3080 curbuf->b_p_tx = TRUE; | |
3081 break; | |
3082 case EOL_UNIX: | |
3083 p = FF_UNIX; | |
3084 curbuf->b_p_tx = FALSE; | |
3085 break; | |
3086 case EOL_MAC: | |
3087 p = FF_MAC; | |
3088 curbuf->b_p_tx = FALSE; | |
3089 break; | |
3090 } | |
3091 if (p != NULL) | |
3092 set_string_option_direct((char_u *)"ff", -1, (char_u *)p, | |
694 | 3093 OPT_FREE | opt_flags, 0); |
3094 | |
7 | 3095 #ifdef FEAT_WINDOWS |
671 | 3096 /* This may cause the buffer to become (un)modified. */ |
7 | 3097 check_status(curbuf); |
673 | 3098 redraw_tabline = TRUE; |
7 | 3099 #endif |
3100 #ifdef FEAT_TITLE | |
3101 need_maketitle = TRUE; /* set window title later */ | |
3102 #endif | |
3103 } | |
3104 | |
3105 /* | |
3106 * Return the default fileformat from 'fileformats'. | |
3107 */ | |
3108 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3109 default_fileformat(void) |
7 | 3110 { |
3111 switch (*p_ffs) | |
3112 { | |
3113 case 'm': return EOL_MAC; | |
3114 case 'd': return EOL_DOS; | |
3115 } | |
3116 return EOL_UNIX; | |
3117 } | |
3118 | |
3119 /* | |
3120 * Call shell. Calls mch_call_shell, with 'shellxquote' added. | |
3121 */ | |
3122 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3123 call_shell(char_u *cmd, int opt) |
7 | 3124 { |
3125 char_u *ncmd; | |
3126 int retval; | |
170 | 3127 #ifdef FEAT_PROFILE |
3128 proftime_T wait_time; | |
3129 #endif | |
7 | 3130 |
3131 if (p_verbose > 3) | |
3132 { | |
293 | 3133 verbose_enter(); |
273 | 3134 smsg((char_u *)_("Calling shell to execute: \"%s\""), |
7 | 3135 cmd == NULL ? p_sh : cmd); |
3136 out_char('\n'); | |
3137 cursor_on(); | |
293 | 3138 verbose_leave(); |
7 | 3139 } |
3140 | |
170 | 3141 #ifdef FEAT_PROFILE |
789 | 3142 if (do_profiling == PROF_YES) |
170 | 3143 prof_child_enter(&wait_time); |
3144 #endif | |
3145 | |
7 | 3146 if (*p_sh == NUL) |
3147 { | |
3148 EMSG(_(e_shellempty)); | |
3149 retval = -1; | |
3150 } | |
3151 else | |
3152 { | |
3153 #ifdef FEAT_GUI_MSWIN | |
3154 /* Don't hide the pointer while executing a shell command. */ | |
3155 gui_mch_mousehide(FALSE); | |
3156 #endif | |
3157 #ifdef FEAT_GUI | |
3158 ++hold_gui_events; | |
3159 #endif | |
3160 /* The external command may update a tags file, clear cached tags. */ | |
3161 tag_freematch(); | |
3162 | |
3163 if (cmd == NULL || *p_sxq == NUL) | |
3164 retval = mch_call_shell(cmd, opt); | |
3165 else | |
3166 { | |
3359 | 3167 char_u *ecmd = cmd; |
3168 | |
3169 if (*p_sxe != NUL && STRCMP(p_sxq, "(") == 0) | |
3170 { | |
3171 ecmd = vim_strsave_escaped_ext(cmd, p_sxe, '^', FALSE); | |
3172 if (ecmd == NULL) | |
3173 ecmd = cmd; | |
3174 } | |
3175 ncmd = alloc((unsigned)(STRLEN(ecmd) + STRLEN(p_sxq) * 2 + 1)); | |
7 | 3176 if (ncmd != NULL) |
3177 { | |
3178 STRCPY(ncmd, p_sxq); | |
3359 | 3179 STRCAT(ncmd, ecmd); |
3357 | 3180 /* When 'shellxquote' is ( append ). |
3181 * When 'shellxquote' is "( append )". */ | |
3182 STRCAT(ncmd, STRCMP(p_sxq, "(") == 0 ? (char_u *)")" | |
3183 : STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\"" | |
3184 : p_sxq); | |
7 | 3185 retval = mch_call_shell(ncmd, opt); |
3186 vim_free(ncmd); | |
3187 } | |
3188 else | |
3189 retval = -1; | |
3359 | 3190 if (ecmd != cmd) |
3191 vim_free(ecmd); | |
7 | 3192 } |
3193 #ifdef FEAT_GUI | |
3194 --hold_gui_events; | |
3195 #endif | |
3196 /* | |
3197 * Check the window size, in case it changed while executing the | |
3198 * external command. | |
3199 */ | |
3200 shell_resized_check(); | |
3201 } | |
3202 | |
3203 #ifdef FEAT_EVAL | |
3204 set_vim_var_nr(VV_SHELL_ERROR, (long)retval); | |
170 | 3205 # ifdef FEAT_PROFILE |
789 | 3206 if (do_profiling == PROF_YES) |
170 | 3207 prof_child_exit(&wait_time); |
3208 # endif | |
7 | 3209 #endif |
3210 | |
3211 return retval; | |
3212 } | |
3213 | |
3214 /* | |
789 | 3215 * VISUAL, SELECTMODE and OP_PENDING State are never set, they are equal to |
3216 * NORMAL State with a condition. This function returns the real State. | |
7 | 3217 */ |
3218 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3219 get_real_state(void) |
7 | 3220 { |
3221 if (State & NORMAL) | |
3222 { | |
3223 if (VIsual_active) | |
789 | 3224 { |
3225 if (VIsual_select) | |
3226 return SELECTMODE; | |
7 | 3227 return VISUAL; |
789 | 3228 } |
5735 | 3229 else if (finish_op) |
3230 return OP_PENDING; | |
7 | 3231 } |
3232 return State; | |
3233 } | |
3234 | |
39 | 3235 #if defined(FEAT_MBYTE) || defined(PROTO) |
3236 /* | |
3237 * Return TRUE if "p" points to just after a path separator. | |
2939 | 3238 * Takes care of multi-byte characters. |
39 | 3239 * "b" must point to the start of the file name |
3240 */ | |
3241 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3242 after_pathsep(char_u *b, char_u *p) |
39 | 3243 { |
2939 | 3244 return p > b && vim_ispathsep(p[-1]) |
39 | 3245 && (!has_mbyte || (*mb_head_off)(b, p - 1) == 0); |
3246 } | |
3247 #endif | |
3248 | |
3249 /* | |
3250 * Return TRUE if file names "f1" and "f2" are in the same directory. | |
3251 * "f1" may be a short name, "f2" must be a full path. | |
3252 */ | |
3253 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3254 same_directory(char_u *f1, char_u *f2) |
39 | 3255 { |
3256 char_u ffname[MAXPATHL]; | |
3257 char_u *t1; | |
3258 char_u *t2; | |
3259 | |
3260 /* safety check */ | |
3261 if (f1 == NULL || f2 == NULL) | |
3262 return FALSE; | |
3263 | |
3264 (void)vim_FullName(f1, ffname, MAXPATHL, FALSE); | |
3265 t1 = gettail_sep(ffname); | |
3266 t2 = gettail_sep(f2); | |
3267 return (t1 - ffname == t2 - f2 | |
3268 && pathcmp((char *)ffname, (char *)f2, (int)(t1 - ffname)) == 0); | |
3269 } | |
3270 | |
7 | 3271 #if defined(FEAT_SESSION) || defined(MSWIN) || defined(FEAT_GUI_MAC) \ |
574 | 3272 || ((defined(FEAT_GUI_GTK)) \ |
11 | 3273 && ( defined(FEAT_WINDOWS) || defined(FEAT_DND)) ) \ |
7 | 3274 || defined(FEAT_SUN_WORKSHOP) || defined(FEAT_NETBEANS_INTG) \ |
3275 || defined(PROTO) | |
3276 /* | |
3277 * Change to a file's directory. | |
3278 * Caller must call shorten_fnames()! | |
3279 * Return OK or FAIL. | |
3280 */ | |
3281 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3282 vim_chdirfile(char_u *fname) |
7 | 3283 { |
39 | 3284 char_u dir[MAXPATHL]; |
3285 | |
418 | 3286 vim_strncpy(dir, fname, MAXPATHL - 1); |
39 | 3287 *gettail_sep(dir) = NUL; |
3288 return mch_chdir((char *)dir) == 0 ? OK : FAIL; | |
7 | 3289 } |
3290 #endif | |
3291 | |
3292 #if defined(STAT_IGNORES_SLASH) || defined(PROTO) | |
3293 /* | |
3294 * Check if "name" ends in a slash and is not a directory. | |
3295 * Used for systems where stat() ignores a trailing slash on a file name. | |
3296 * The Vim code assumes a trailing slash is only ignored for a directory. | |
3297 */ | |
3298 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3299 illegal_slash(char *name) |
7 | 3300 { |
3301 if (name[0] == NUL) | |
3302 return FALSE; /* no file name is not illegal */ | |
3303 if (name[strlen(name) - 1] != '/') | |
3304 return FALSE; /* no trailing slash */ | |
3305 if (mch_isdir((char_u *)name)) | |
3306 return FALSE; /* trailing slash for a directory */ | |
3307 return TRUE; | |
3308 } | |
3309 #endif | |
3310 | |
3311 #if defined(CURSOR_SHAPE) || defined(PROTO) | |
3312 | |
3313 /* | |
3314 * Handling of cursor and mouse pointer shapes in various modes. | |
3315 */ | |
3316 | |
3317 cursorentry_T shape_table[SHAPE_IDX_COUNT] = | |
3318 { | |
3319 /* The values will be filled in from the 'guicursor' and 'mouseshape' | |
3320 * defaults when Vim starts. | |
3321 * Adjust the SHAPE_IDX_ defines when making changes! */ | |
3322 {0, 0, 0, 700L, 400L, 250L, 0, 0, "n", SHAPE_CURSOR+SHAPE_MOUSE}, | |
3323 {0, 0, 0, 700L, 400L, 250L, 0, 0, "v", SHAPE_CURSOR+SHAPE_MOUSE}, | |
3324 {0, 0, 0, 700L, 400L, 250L, 0, 0, "i", SHAPE_CURSOR+SHAPE_MOUSE}, | |
3325 {0, 0, 0, 700L, 400L, 250L, 0, 0, "r", SHAPE_CURSOR+SHAPE_MOUSE}, | |
3326 {0, 0, 0, 700L, 400L, 250L, 0, 0, "c", SHAPE_CURSOR+SHAPE_MOUSE}, | |
3327 {0, 0, 0, 700L, 400L, 250L, 0, 0, "ci", SHAPE_CURSOR+SHAPE_MOUSE}, | |
3328 {0, 0, 0, 700L, 400L, 250L, 0, 0, "cr", SHAPE_CURSOR+SHAPE_MOUSE}, | |
3329 {0, 0, 0, 700L, 400L, 250L, 0, 0, "o", SHAPE_CURSOR+SHAPE_MOUSE}, | |
3330 {0, 0, 0, 700L, 400L, 250L, 0, 0, "ve", SHAPE_CURSOR+SHAPE_MOUSE}, | |
3331 {0, 0, 0, 0L, 0L, 0L, 0, 0, "e", SHAPE_MOUSE}, | |
3332 {0, 0, 0, 0L, 0L, 0L, 0, 0, "s", SHAPE_MOUSE}, | |
3333 {0, 0, 0, 0L, 0L, 0L, 0, 0, "sd", SHAPE_MOUSE}, | |
3334 {0, 0, 0, 0L, 0L, 0L, 0, 0, "vs", SHAPE_MOUSE}, | |
3335 {0, 0, 0, 0L, 0L, 0L, 0, 0, "vd", SHAPE_MOUSE}, | |
3336 {0, 0, 0, 0L, 0L, 0L, 0, 0, "m", SHAPE_MOUSE}, | |
3337 {0, 0, 0, 0L, 0L, 0L, 0, 0, "ml", SHAPE_MOUSE}, | |
3338 {0, 0, 0, 100L, 100L, 100L, 0, 0, "sm", SHAPE_CURSOR}, | |
3339 }; | |
3340 | |
3341 #ifdef FEAT_MOUSESHAPE | |
3342 /* | |
3343 * Table with names for mouse shapes. Keep in sync with all the tables for | |
3344 * mch_set_mouse_shape()!. | |
3345 */ | |
3346 static char * mshape_names[] = | |
3347 { | |
3348 "arrow", /* default, must be the first one */ | |
3349 "blank", /* hidden */ | |
3350 "beam", | |
3351 "updown", | |
3352 "udsizing", | |
3353 "leftright", | |
3354 "lrsizing", | |
3355 "busy", | |
3356 "no", | |
3357 "crosshair", | |
3358 "hand1", | |
3359 "hand2", | |
3360 "pencil", | |
3361 "question", | |
3362 "rightup-arrow", | |
3363 "up-arrow", | |
3364 NULL | |
3365 }; | |
3366 #endif | |
3367 | |
3368 /* | |
3369 * Parse the 'guicursor' option ("what" is SHAPE_CURSOR) or 'mouseshape' | |
3370 * ("what" is SHAPE_MOUSE). | |
3371 * Returns error message for an illegal option, NULL otherwise. | |
3372 */ | |
3373 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3374 parse_shape_opt(int what) |
7 | 3375 { |
3376 char_u *modep; | |
3377 char_u *colonp; | |
3378 char_u *commap; | |
3379 char_u *slashp; | |
3380 char_u *p, *endp; | |
3381 int idx = 0; /* init for GCC */ | |
3382 int all_idx; | |
3383 int len; | |
3384 int i; | |
3385 long n; | |
3386 int found_ve = FALSE; /* found "ve" flag */ | |
3387 int round; | |
3388 | |
3389 /* | |
3390 * First round: check for errors; second round: do it for real. | |
3391 */ | |
3392 for (round = 1; round <= 2; ++round) | |
3393 { | |
3394 /* | |
3395 * Repeat for all comma separated parts. | |
3396 */ | |
3397 #ifdef FEAT_MOUSESHAPE | |
3398 if (what == SHAPE_MOUSE) | |
3399 modep = p_mouseshape; | |
3400 else | |
3401 #endif | |
3402 modep = p_guicursor; | |
3403 while (*modep != NUL) | |
3404 { | |
3405 colonp = vim_strchr(modep, ':'); | |
3406 if (colonp == NULL) | |
3407 return (char_u *)N_("E545: Missing colon"); | |
3408 if (colonp == modep) | |
3409 return (char_u *)N_("E546: Illegal mode"); | |
3410 commap = vim_strchr(modep, ','); | |
3411 | |
3412 /* | |
3413 * Repeat for all mode's before the colon. | |
3414 * For the 'a' mode, we loop to handle all the modes. | |
3415 */ | |
3416 all_idx = -1; | |
3417 while (modep < colonp || all_idx >= 0) | |
3418 { | |
3419 if (all_idx < 0) | |
3420 { | |
3421 /* Find the mode. */ | |
3422 if (modep[1] == '-' || modep[1] == ':') | |
3423 len = 1; | |
3424 else | |
3425 len = 2; | |
3426 if (len == 1 && TOLOWER_ASC(modep[0]) == 'a') | |
3427 all_idx = SHAPE_IDX_COUNT - 1; | |
3428 else | |
3429 { | |
3430 for (idx = 0; idx < SHAPE_IDX_COUNT; ++idx) | |
3431 if (STRNICMP(modep, shape_table[idx].name, len) | |
3432 == 0) | |
3433 break; | |
3434 if (idx == SHAPE_IDX_COUNT | |
3435 || (shape_table[idx].used_for & what) == 0) | |
3436 return (char_u *)N_("E546: Illegal mode"); | |
3437 if (len == 2 && modep[0] == 'v' && modep[1] == 'e') | |
3438 found_ve = TRUE; | |
3439 } | |
3440 modep += len + 1; | |
3441 } | |
3442 | |
3443 if (all_idx >= 0) | |
3444 idx = all_idx--; | |
3445 else if (round == 2) | |
3446 { | |
3447 #ifdef FEAT_MOUSESHAPE | |
3448 if (what == SHAPE_MOUSE) | |
3449 { | |
3450 /* Set the default, for the missing parts */ | |
3451 shape_table[idx].mshape = 0; | |
3452 } | |
3453 else | |
3454 #endif | |
3455 { | |
3456 /* Set the defaults, for the missing parts */ | |
3457 shape_table[idx].shape = SHAPE_BLOCK; | |
3458 shape_table[idx].blinkwait = 700L; | |
3459 shape_table[idx].blinkon = 400L; | |
3460 shape_table[idx].blinkoff = 250L; | |
3461 } | |
3462 } | |
3463 | |
3464 /* Parse the part after the colon */ | |
3465 for (p = colonp + 1; *p && *p != ','; ) | |
3466 { | |
3467 #ifdef FEAT_MOUSESHAPE | |
3468 if (what == SHAPE_MOUSE) | |
3469 { | |
3470 for (i = 0; ; ++i) | |
3471 { | |
3472 if (mshape_names[i] == NULL) | |
3473 { | |
3474 if (!VIM_ISDIGIT(*p)) | |
3475 return (char_u *)N_("E547: Illegal mouseshape"); | |
3476 if (round == 2) | |
3477 shape_table[idx].mshape = | |
3478 getdigits(&p) + MSHAPE_NUMBERED; | |
3479 else | |
3480 (void)getdigits(&p); | |
3481 break; | |
3482 } | |
3483 len = (int)STRLEN(mshape_names[i]); | |
3484 if (STRNICMP(p, mshape_names[i], len) == 0) | |
3485 { | |
3486 if (round == 2) | |
3487 shape_table[idx].mshape = i; | |
3488 p += len; | |
3489 break; | |
3490 } | |
3491 } | |
3492 } | |
3493 else /* if (what == SHAPE_MOUSE) */ | |
3494 #endif | |
3495 { | |
3496 /* | |
3497 * First handle the ones with a number argument. | |
3498 */ | |
3499 i = *p; | |
3500 len = 0; | |
3501 if (STRNICMP(p, "ver", 3) == 0) | |
3502 len = 3; | |
3503 else if (STRNICMP(p, "hor", 3) == 0) | |
3504 len = 3; | |
3505 else if (STRNICMP(p, "blinkwait", 9) == 0) | |
3506 len = 9; | |
3507 else if (STRNICMP(p, "blinkon", 7) == 0) | |
3508 len = 7; | |
3509 else if (STRNICMP(p, "blinkoff", 8) == 0) | |
3510 len = 8; | |
3511 if (len != 0) | |
3512 { | |
3513 p += len; | |
3514 if (!VIM_ISDIGIT(*p)) | |
3515 return (char_u *)N_("E548: digit expected"); | |
3516 n = getdigits(&p); | |
3517 if (len == 3) /* "ver" or "hor" */ | |
3518 { | |
3519 if (n == 0) | |
3520 return (char_u *)N_("E549: Illegal percentage"); | |
3521 if (round == 2) | |
3522 { | |
3523 if (TOLOWER_ASC(i) == 'v') | |
3524 shape_table[idx].shape = SHAPE_VER; | |
3525 else | |
3526 shape_table[idx].shape = SHAPE_HOR; | |
3527 shape_table[idx].percentage = n; | |
3528 } | |
3529 } | |
3530 else if (round == 2) | |
3531 { | |
3532 if (len == 9) | |
3533 shape_table[idx].blinkwait = n; | |
3534 else if (len == 7) | |
3535 shape_table[idx].blinkon = n; | |
3536 else | |
3537 shape_table[idx].blinkoff = n; | |
3538 } | |
3539 } | |
3540 else if (STRNICMP(p, "block", 5) == 0) | |
3541 { | |
3542 if (round == 2) | |
3543 shape_table[idx].shape = SHAPE_BLOCK; | |
3544 p += 5; | |
3545 } | |
3546 else /* must be a highlight group name then */ | |
3547 { | |
3548 endp = vim_strchr(p, '-'); | |
3549 if (commap == NULL) /* last part */ | |
3550 { | |
3551 if (endp == NULL) | |
3552 endp = p + STRLEN(p); /* find end of part */ | |
3553 } | |
3554 else if (endp > commap || endp == NULL) | |
3555 endp = commap; | |
3556 slashp = vim_strchr(p, '/'); | |
3557 if (slashp != NULL && slashp < endp) | |
3558 { | |
3559 /* "group/langmap_group" */ | |
3560 i = syn_check_group(p, (int)(slashp - p)); | |
3561 p = slashp + 1; | |
3562 } | |
3563 if (round == 2) | |
3564 { | |
3565 shape_table[idx].id = syn_check_group(p, | |
3566 (int)(endp - p)); | |
3567 shape_table[idx].id_lm = shape_table[idx].id; | |
3568 if (slashp != NULL && slashp < endp) | |
3569 shape_table[idx].id = i; | |
3570 } | |
3571 p = endp; | |
3572 } | |
3573 } /* if (what != SHAPE_MOUSE) */ | |
3574 | |
3575 if (*p == '-') | |
3576 ++p; | |
3577 } | |
3578 } | |
3579 modep = p; | |
3580 if (*modep == ',') | |
3581 ++modep; | |
3582 } | |
3583 } | |
3584 | |
3585 /* If the 's' flag is not given, use the 'v' cursor for 's' */ | |
3586 if (!found_ve) | |
3587 { | |
3588 #ifdef FEAT_MOUSESHAPE | |
3589 if (what == SHAPE_MOUSE) | |
3590 { | |
3591 shape_table[SHAPE_IDX_VE].mshape = shape_table[SHAPE_IDX_V].mshape; | |
3592 } | |
3593 else | |
3594 #endif | |
3595 { | |
3596 shape_table[SHAPE_IDX_VE].shape = shape_table[SHAPE_IDX_V].shape; | |
3597 shape_table[SHAPE_IDX_VE].percentage = | |
3598 shape_table[SHAPE_IDX_V].percentage; | |
3599 shape_table[SHAPE_IDX_VE].blinkwait = | |
3600 shape_table[SHAPE_IDX_V].blinkwait; | |
3601 shape_table[SHAPE_IDX_VE].blinkon = | |
3602 shape_table[SHAPE_IDX_V].blinkon; | |
3603 shape_table[SHAPE_IDX_VE].blinkoff = | |
3604 shape_table[SHAPE_IDX_V].blinkoff; | |
3605 shape_table[SHAPE_IDX_VE].id = shape_table[SHAPE_IDX_V].id; | |
3606 shape_table[SHAPE_IDX_VE].id_lm = shape_table[SHAPE_IDX_V].id_lm; | |
3607 } | |
3608 } | |
3609 | |
3610 return NULL; | |
3611 } | |
3612 | |
500 | 3613 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
3614 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 3615 /* |
3616 * Return the index into shape_table[] for the current mode. | |
3617 * When "mouse" is TRUE, consider indexes valid for the mouse pointer. | |
3618 */ | |
3619 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3620 get_shape_idx(int mouse) |
7 | 3621 { |
3622 #ifdef FEAT_MOUSESHAPE | |
3623 if (mouse && (State == HITRETURN || State == ASKMORE)) | |
3624 { | |
3625 # ifdef FEAT_GUI | |
87 | 3626 int x, y; |
3627 gui_mch_getmouse(&x, &y); | |
3628 if (Y_2_ROW(y) == Rows - 1) | |
7 | 3629 return SHAPE_IDX_MOREL; |
3630 # endif | |
3631 return SHAPE_IDX_MORE; | |
3632 } | |
3633 if (mouse && drag_status_line) | |
3634 return SHAPE_IDX_SDRAG; | |
3635 # ifdef FEAT_VERTSPLIT | |
3636 if (mouse && drag_sep_line) | |
3637 return SHAPE_IDX_VDRAG; | |
3638 # endif | |
3639 #endif | |
3640 if (!mouse && State == SHOWMATCH) | |
3641 return SHAPE_IDX_SM; | |
3642 #ifdef FEAT_VREPLACE | |
3643 if (State & VREPLACE_FLAG) | |
3644 return SHAPE_IDX_R; | |
3645 #endif | |
3646 if (State & REPLACE_FLAG) | |
3647 return SHAPE_IDX_R; | |
3648 if (State & INSERT) | |
3649 return SHAPE_IDX_I; | |
3650 if (State & CMDLINE) | |
3651 { | |
3652 if (cmdline_at_end()) | |
3653 return SHAPE_IDX_C; | |
3654 if (cmdline_overstrike()) | |
3655 return SHAPE_IDX_CR; | |
3656 return SHAPE_IDX_CI; | |
3657 } | |
3658 if (finish_op) | |
3659 return SHAPE_IDX_O; | |
3660 if (VIsual_active) | |
3661 { | |
3662 if (*p_sel == 'e') | |
3663 return SHAPE_IDX_VE; | |
3664 else | |
3665 return SHAPE_IDX_V; | |
3666 } | |
3667 return SHAPE_IDX_N; | |
3668 } | |
500 | 3669 #endif |
7 | 3670 |
3671 # if defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
3672 static int old_mouse_shape = 0; | |
3673 | |
3674 /* | |
3675 * Set the mouse shape: | |
3676 * If "shape" is -1, use shape depending on the current mode, | |
3677 * depending on the current state. | |
3678 * If "shape" is -2, only update the shape when it's CLINE or STATUS (used | |
3679 * when the mouse moves off the status or command line). | |
3680 */ | |
3681 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3682 update_mouseshape(int shape_idx) |
7 | 3683 { |
3684 int new_mouse_shape; | |
3685 | |
3686 /* Only works in GUI mode. */ | |
227 | 3687 if (!gui.in_use || gui.starting) |
7 | 3688 return; |
3689 | |
3690 /* Postpone the updating when more is to come. Speeds up executing of | |
3691 * mappings. */ | |
3692 if (shape_idx == -1 && char_avail()) | |
3693 { | |
3694 postponed_mouseshape = TRUE; | |
3695 return; | |
3696 } | |
3697 | |
864 | 3698 /* When ignoring the mouse don't change shape on the statusline. */ |
3699 if (*p_mouse == NUL | |
3700 && (shape_idx == SHAPE_IDX_CLINE | |
3701 || shape_idx == SHAPE_IDX_STATUS | |
3702 || shape_idx == SHAPE_IDX_VSEP)) | |
3703 shape_idx = -2; | |
3704 | |
7 | 3705 if (shape_idx == -2 |
3706 && old_mouse_shape != shape_table[SHAPE_IDX_CLINE].mshape | |
3707 && old_mouse_shape != shape_table[SHAPE_IDX_STATUS].mshape | |
3708 && old_mouse_shape != shape_table[SHAPE_IDX_VSEP].mshape) | |
3709 return; | |
3710 if (shape_idx < 0) | |
3711 new_mouse_shape = shape_table[get_shape_idx(TRUE)].mshape; | |
3712 else | |
3713 new_mouse_shape = shape_table[shape_idx].mshape; | |
3714 if (new_mouse_shape != old_mouse_shape) | |
3715 { | |
3716 mch_set_mouse_shape(new_mouse_shape); | |
3717 old_mouse_shape = new_mouse_shape; | |
3718 } | |
3719 postponed_mouseshape = FALSE; | |
3720 } | |
3721 # endif | |
3722 | |
3723 #endif /* CURSOR_SHAPE */ | |
3724 | |
3725 | |
3726 /* TODO: make some #ifdef for this */ | |
3727 /*--------[ file searching ]-------------------------------------------------*/ | |
3728 /* | |
3729 * File searching functions for 'path', 'tags' and 'cdpath' options. | |
3730 * External visible functions: | |
3731 * vim_findfile_init() creates/initialises the search context | |
3732 * vim_findfile_free_visited() free list of visited files/dirs of search | |
3733 * context | |
3734 * vim_findfile() find a file in the search context | |
3735 * vim_findfile_cleanup() cleanup/free search context created by | |
3736 * vim_findfile_init() | |
3737 * | |
3738 * All static functions and variables start with 'ff_' | |
3739 * | |
3740 * In general it works like this: | |
3741 * First you create yourself a search context by calling vim_findfile_init(). | |
3742 * It is possible to give a search context from a previous call to | |
3743 * vim_findfile_init(), so it can be reused. After this you call vim_findfile() | |
3744 * until you are satisfied with the result or it returns NULL. On every call it | |
3745 * returns the next file which matches the conditions given to | |
3746 * vim_findfile_init(). If it doesn't find a next file it returns NULL. | |
3747 * | |
3748 * It is possible to call vim_findfile_init() again to reinitialise your search | |
3749 * with some new parameters. Don't forget to pass your old search context to | |
3750 * it, so it can reuse it and especially reuse the list of already visited | |
3751 * directories. If you want to delete the list of already visited directories | |
3752 * simply call vim_findfile_free_visited(). | |
3753 * | |
3754 * When you are done call vim_findfile_cleanup() to free the search context. | |
3755 * | |
3756 * The function vim_findfile_init() has a long comment, which describes the | |
3757 * needed parameters. | |
3758 * | |
3759 * | |
3760 * | |
3761 * ATTENTION: | |
3762 * ========== | |
1072 | 3763 * Also we use an allocated search context here, this functions are NOT |
7 | 3764 * thread-safe!!!!! |
3765 * | |
3766 * To minimize parameter passing (or because I'm to lazy), only the | |
3767 * external visible functions get a search context as a parameter. This is | |
3768 * then assigned to a static global, which is used throughout the local | |
3769 * functions. | |
3770 */ | |
3771 | |
3772 /* | |
3773 * type for the directory search stack | |
3774 */ | |
3775 typedef struct ff_stack | |
3776 { | |
3777 struct ff_stack *ffs_prev; | |
3778 | |
3779 /* the fix part (no wildcards) and the part containing the wildcards | |
3780 * of the search path | |
3781 */ | |
3782 char_u *ffs_fix_path; | |
3783 #ifdef FEAT_PATH_EXTRA | |
3784 char_u *ffs_wc_path; | |
3785 #endif | |
3786 | |
3787 /* files/dirs found in the above directory, matched by the first wildcard | |
3788 * of wc_part | |
3789 */ | |
3790 char_u **ffs_filearray; | |
3791 int ffs_filearray_size; | |
3792 char_u ffs_filearray_cur; /* needed for partly handled dirs */ | |
3793 | |
3794 /* to store status of partly handled directories | |
1541 | 3795 * 0: we work on this directory for the first time |
7 | 3796 * 1: this directory was partly searched in an earlier step |
1541 | 3797 */ |
7 | 3798 int ffs_stage; |
3799 | |
3800 /* How deep are we in the directory tree? | |
3801 * Counts backward from value of level parameter to vim_findfile_init | |
3802 */ | |
3803 int ffs_level; | |
3804 | |
3805 /* Did we already expand '**' to an empty string? */ | |
3806 int ffs_star_star_empty; | |
3807 } ff_stack_T; | |
3808 | |
3809 /* | |
3810 * type for already visited directories or files. | |
3811 */ | |
3812 typedef struct ff_visited | |
3813 { | |
3814 struct ff_visited *ffv_next; | |
3815 | |
3816 #ifdef FEAT_PATH_EXTRA | |
3817 /* Visited directories are different if the wildcard string are | |
3818 * different. So we have to save it. | |
3819 */ | |
3820 char_u *ffv_wc_path; | |
3821 #endif | |
3822 /* for unix use inode etc for comparison (needed because of links), else | |
3823 * use filename. | |
3824 */ | |
3825 #ifdef UNIX | |
1881 | 3826 int ffv_dev_valid; /* ffv_dev and ffv_ino were set */ |
3827 dev_t ffv_dev; /* device number */ | |
7 | 3828 ino_t ffv_ino; /* inode number */ |
3829 #endif | |
3830 /* The memory for this struct is allocated according to the length of | |
3831 * ffv_fname. | |
3832 */ | |
3833 char_u ffv_fname[1]; /* actually longer */ | |
3834 } ff_visited_T; | |
3835 | |
3836 /* | |
3837 * We might have to manage several visited lists during a search. | |
1209 | 3838 * This is especially needed for the tags option. If tags is set to: |
7 | 3839 * "./++/tags,./++/TAGS,++/tags" (replace + with *) |
3840 * So we have to do 3 searches: | |
3841 * 1) search from the current files directory downward for the file "tags" | |
3842 * 2) search from the current files directory downward for the file "TAGS" | |
3843 * 3) search from Vims current directory downwards for the file "tags" | |
3844 * As you can see, the first and the third search are for the same file, so for | |
3845 * the third search we can use the visited list of the first search. For the | |
3846 * second search we must start from a empty visited list. | |
3847 * The struct ff_visited_list_hdr is used to manage a linked list of already | |
3848 * visited lists. | |
3849 */ | |
3850 typedef struct ff_visited_list_hdr | |
3851 { | |
3852 struct ff_visited_list_hdr *ffvl_next; | |
3853 | |
3854 /* the filename the attached visited list is for */ | |
3855 char_u *ffvl_filename; | |
3856 | |
3857 ff_visited_T *ffvl_visited_list; | |
3858 | |
3859 } ff_visited_list_hdr_T; | |
3860 | |
3861 | |
3862 /* | |
3863 * '**' can be expanded to several directory levels. | |
1209 | 3864 * Set the default maximum depth. |
7 | 3865 */ |
3866 #define FF_MAX_STAR_STAR_EXPAND ((char_u)30) | |
1541 | 3867 |
7 | 3868 /* |
3869 * The search context: | |
3870 * ffsc_stack_ptr: the stack for the dirs to search | |
3871 * ffsc_visited_list: the currently active visited list | |
3872 * ffsc_dir_visited_list: the currently active visited list for search dirs | |
3873 * ffsc_visited_lists_list: the list of all visited lists | |
3874 * ffsc_dir_visited_lists_list: the list of all visited lists for search dirs | |
3875 * ffsc_file_to_search: the file to search for | |
3876 * ffsc_start_dir: the starting directory, if search path was relative | |
3877 * ffsc_fix_path: the fix part of the given path (without wildcards) | |
3878 * Needed for upward search. | |
3879 * ffsc_wc_path: the part of the given path containing wildcards | |
3880 * ffsc_level: how many levels of dirs to search downwards | |
3881 * ffsc_stopdirs_v: array of stop directories for upward search | |
1541 | 3882 * ffsc_find_what: FINDFILE_BOTH, FINDFILE_DIR or FINDFILE_FILE |
2521
d890c820722f
Fix: 'suffixesadd' was used for finding tags file.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
3883 * ffsc_tagfile: searching for tags file, don't use 'suffixesadd' |
7 | 3884 */ |
3885 typedef struct ff_search_ctx_T | |
3886 { | |
3887 ff_stack_T *ffsc_stack_ptr; | |
3888 ff_visited_list_hdr_T *ffsc_visited_list; | |
3889 ff_visited_list_hdr_T *ffsc_dir_visited_list; | |
3890 ff_visited_list_hdr_T *ffsc_visited_lists_list; | |
3891 ff_visited_list_hdr_T *ffsc_dir_visited_lists_list; | |
3892 char_u *ffsc_file_to_search; | |
3893 char_u *ffsc_start_dir; | |
3894 char_u *ffsc_fix_path; | |
3895 #ifdef FEAT_PATH_EXTRA | |
3896 char_u *ffsc_wc_path; | |
3897 int ffsc_level; | |
3898 char_u **ffsc_stopdirs_v; | |
3899 #endif | |
1541 | 3900 int ffsc_find_what; |
2521
d890c820722f
Fix: 'suffixesadd' was used for finding tags file.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
3901 int ffsc_tagfile; |
359 | 3902 } ff_search_ctx_T; |
3903 | |
7 | 3904 /* locally needed functions */ |
3905 #ifdef FEAT_PATH_EXTRA | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3906 static int ff_check_visited(ff_visited_T **, char_u *, char_u *); |
7 | 3907 #else |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3908 static int ff_check_visited(ff_visited_T **, char_u *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3909 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3910 static void vim_findfile_free_visited_list(ff_visited_list_hdr_T **list_headp); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3911 static void ff_free_visited_list(ff_visited_T *vl); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3912 static ff_visited_list_hdr_T* ff_get_visited_list(char_u *, ff_visited_list_hdr_T **list_headp); |
7 | 3913 #ifdef FEAT_PATH_EXTRA |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3914 static int ff_wc_equal(char_u *s1, char_u *s2); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3915 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3916 |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3917 static void ff_push(ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3918 static ff_stack_T *ff_pop(ff_search_ctx_T *search_ctx); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3919 static void ff_clear(ff_search_ctx_T *search_ctx); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3920 static void ff_free_stack_element(ff_stack_T *stack_ptr); |
7 | 3921 #ifdef FEAT_PATH_EXTRA |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3922 static ff_stack_T *ff_create_stack_element(char_u *, char_u *, int, int); |
7 | 3923 #else |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3924 static ff_stack_T *ff_create_stack_element(char_u *, int, int); |
7 | 3925 #endif |
3926 #ifdef FEAT_PATH_EXTRA | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
3927 static int ff_path_in_stoplist(char_u *, int, char_u **); |
7 | 3928 #endif |
3929 | |
3202 | 3930 static char_u e_pathtoolong[] = N_("E854: path too long for completion"); |
3931 | |
7 | 3932 #if 0 |
3933 /* | |
3934 * if someone likes findfirst/findnext, here are the functions | |
3935 * NOT TESTED!! | |
3936 */ | |
3937 | |
3938 static void *ff_fn_search_context = NULL; | |
3939 | |
3940 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3941 vim_findfirst(char_u *path, char_u *filename, int level) |
7 | 3942 { |
3943 ff_fn_search_context = | |
3944 vim_findfile_init(path, filename, NULL, level, TRUE, FALSE, | |
3945 ff_fn_search_context, rel_fname); | |
3946 if (NULL == ff_fn_search_context) | |
3947 return NULL; | |
3948 else | |
3949 return vim_findnext() | |
3950 } | |
3951 | |
3952 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3953 vim_findnext(void) |
7 | 3954 { |
3955 char_u *ret = vim_findfile(ff_fn_search_context); | |
3956 | |
3957 if (NULL == ret) | |
3958 { | |
3959 vim_findfile_cleanup(ff_fn_search_context); | |
3960 ff_fn_search_context = NULL; | |
3961 } | |
3962 return ret; | |
3963 } | |
3964 #endif | |
3965 | |
3966 /* | |
2522
d7ecfc8b784c
Update help about wildcards in 'tags' option.
Bram Moolenaar <bram@vim.org>
parents:
2521
diff
changeset
|
3967 * Initialization routine for vim_findfile(). |
7 | 3968 * |
2211
dded7e33d0a9
Fix wrong memory access when clearing crypt key.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
3969 * Returns the newly allocated search context or NULL if an error occurred. |
7 | 3970 * |
3971 * Don't forget to clean up by calling vim_findfile_cleanup() if you are done | |
3972 * with the search context. | |
3973 * | |
3974 * Find the file 'filename' in the directory 'path'. | |
3975 * The parameter 'path' may contain wildcards. If so only search 'level' | |
3976 * directories deep. The parameter 'level' is the absolute maximum and is | |
3977 * not related to restricts given to the '**' wildcard. If 'level' is 100 | |
3978 * and you use '**200' vim_findfile() will stop after 100 levels. | |
3979 * | |
1541 | 3980 * 'filename' cannot contain wildcards! It is used as-is, no backslashes to |
3981 * escape special characters. | |
3982 * | |
7 | 3983 * If 'stopdirs' is not NULL and nothing is found downward, the search is |
3984 * restarted on the next higher directory level. This is repeated until the | |
3985 * start-directory of a search is contained in 'stopdirs'. 'stopdirs' has the | |
3986 * format ";*<dirname>*\(;<dirname>\)*;\=$". | |
3987 * | |
3988 * If the 'path' is relative, the starting dir for the search is either VIM's | |
3989 * current dir or if the path starts with "./" the current files dir. | |
2211
dded7e33d0a9
Fix wrong memory access when clearing crypt key.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
3990 * If the 'path' is absolute, the starting dir is that part of the path before |
7 | 3991 * the first wildcard. |
3992 * | |
3993 * Upward search is only done on the starting dir. | |
3994 * | |
3995 * If 'free_visited' is TRUE the list of already visited files/directories is | |
3996 * cleared. Set this to FALSE if you just want to search from another | |
3997 * directory, but want to be sure that no directory from a previous search is | |
3998 * searched again. This is useful if you search for a file at different places. | |
3999 * The list of visited files/dirs can also be cleared with the function | |
4000 * vim_findfile_free_visited(). | |
4001 * | |
1541 | 4002 * Set the parameter 'find_what' to FINDFILE_DIR if you want to search for |
4003 * directories only, FINDFILE_FILE for files only, FINDFILE_BOTH for both. | |
7 | 4004 * |
4005 * A search context returned by a previous call to vim_findfile_init() can be | |
1541 | 4006 * passed in the parameter "search_ctx_arg". This context is reused and |
4007 * reinitialized with the new parameters. The list of already visited | |
7 | 4008 * directories from this context is only deleted if the parameter |
1541 | 4009 * "free_visited" is true. Be aware that the passed "search_ctx_arg" is freed |
4010 * if the reinitialization fails. | |
7 | 4011 * |
1541 | 4012 * If you don't have a search context from a previous call "search_ctx_arg" |
4013 * must be NULL. | |
7 | 4014 * |
4015 * This function silently ignores a few errors, vim_findfile() will have | |
4016 * limited functionality then. | |
4017 */ | |
4018 void * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4019 vim_findfile_init( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4020 char_u *path, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4021 char_u *filename, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4022 char_u *stopdirs UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4023 int level, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4024 int free_visited, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4025 int find_what, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4026 void *search_ctx_arg, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4027 int tagfile, /* expanding names of tags files */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4028 char_u *rel_fname) /* file name to use for "." */ |
7 | 4029 { |
4030 #ifdef FEAT_PATH_EXTRA | |
1541 | 4031 char_u *wc_part; |
4032 #endif | |
4033 ff_stack_T *sptr; | |
4034 ff_search_ctx_T *search_ctx; | |
7 | 4035 |
4036 /* If a search context is given by the caller, reuse it, else allocate a | |
4037 * new one. | |
4038 */ | |
1541 | 4039 if (search_ctx_arg != NULL) |
4040 search_ctx = search_ctx_arg; | |
7 | 4041 else |
4042 { | |
1541 | 4043 search_ctx = (ff_search_ctx_T*)alloc((unsigned)sizeof(ff_search_ctx_T)); |
4044 if (search_ctx == NULL) | |
7 | 4045 goto error_return; |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
2211
diff
changeset
|
4046 vim_memset(search_ctx, 0, sizeof(ff_search_ctx_T)); |
7 | 4047 } |
1541 | 4048 search_ctx->ffsc_find_what = find_what; |
2521
d890c820722f
Fix: 'suffixesadd' was used for finding tags file.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4049 search_ctx->ffsc_tagfile = tagfile; |
7 | 4050 |
4051 /* clear the search context, but NOT the visited lists */ | |
1541 | 4052 ff_clear(search_ctx); |
7 | 4053 |
4054 /* clear visited list if wanted */ | |
4055 if (free_visited == TRUE) | |
1541 | 4056 vim_findfile_free_visited(search_ctx); |
7 | 4057 else |
4058 { | |
4059 /* Reuse old visited lists. Get the visited list for the given | |
4060 * filename. If no list for the current filename exists, creates a new | |
1541 | 4061 * one. */ |
4062 search_ctx->ffsc_visited_list = ff_get_visited_list(filename, | |
4063 &search_ctx->ffsc_visited_lists_list); | |
4064 if (search_ctx->ffsc_visited_list == NULL) | |
7 | 4065 goto error_return; |
1541 | 4066 search_ctx->ffsc_dir_visited_list = ff_get_visited_list(filename, |
4067 &search_ctx->ffsc_dir_visited_lists_list); | |
4068 if (search_ctx->ffsc_dir_visited_list == NULL) | |
7 | 4069 goto error_return; |
4070 } | |
4071 | |
4072 if (ff_expand_buffer == NULL) | |
4073 { | |
4074 ff_expand_buffer = (char_u*)alloc(MAXPATHL); | |
4075 if (ff_expand_buffer == NULL) | |
4076 goto error_return; | |
4077 } | |
4078 | |
4079 /* Store information on starting dir now if path is relative. | |
20 | 4080 * If path is absolute, we do that later. */ |
7 | 4081 if (path[0] == '.' |
4082 && (vim_ispathsep(path[1]) || path[1] == NUL) | |
4083 && (!tagfile || vim_strchr(p_cpo, CPO_DOTTAG) == NULL) | |
4084 && rel_fname != NULL) | |
4085 { | |
4086 int len = (int)(gettail(rel_fname) - rel_fname); | |
4087 | |
4088 if (!vim_isAbsName(rel_fname) && len + 1 < MAXPATHL) | |
4089 { | |
4090 /* Make the start dir an absolute path name. */ | |
418 | 4091 vim_strncpy(ff_expand_buffer, rel_fname, len); |
1541 | 4092 search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, FALSE); |
7 | 4093 } |
4094 else | |
1541 | 4095 search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len); |
4096 if (search_ctx->ffsc_start_dir == NULL) | |
7 | 4097 goto error_return; |
4098 if (*++path != NUL) | |
4099 ++path; | |
4100 } | |
4101 else if (*path == NUL || !vim_isAbsName(path)) | |
4102 { | |
4103 #ifdef BACKSLASH_IN_FILENAME | |
4104 /* "c:dir" needs "c:" to be expanded, otherwise use current dir */ | |
4105 if (*path != NUL && path[1] == ':') | |
4106 { | |
4107 char_u drive[3]; | |
4108 | |
4109 drive[0] = path[0]; | |
4110 drive[1] = ':'; | |
4111 drive[2] = NUL; | |
4112 if (vim_FullName(drive, ff_expand_buffer, MAXPATHL, TRUE) == FAIL) | |
4113 goto error_return; | |
4114 path += 2; | |
4115 } | |
4116 else | |
4117 #endif | |
4118 if (mch_dirname(ff_expand_buffer, MAXPATHL) == FAIL) | |
4119 goto error_return; | |
4120 | |
1541 | 4121 search_ctx->ffsc_start_dir = vim_strsave(ff_expand_buffer); |
4122 if (search_ctx->ffsc_start_dir == NULL) | |
7 | 4123 goto error_return; |
4124 | |
4125 #ifdef BACKSLASH_IN_FILENAME | |
4126 /* A path that starts with "/dir" is relative to the drive, not to the | |
4127 * directory (but not for "//machine/dir"). Only use the drive name. */ | |
4128 if ((*path == '/' || *path == '\\') | |
4129 && path[1] != path[0] | |
1541 | 4130 && search_ctx->ffsc_start_dir[1] == ':') |
4131 search_ctx->ffsc_start_dir[2] = NUL; | |
7 | 4132 #endif |
4133 } | |
4134 | |
4135 #ifdef FEAT_PATH_EXTRA | |
4136 /* | |
4137 * If stopdirs are given, split them into an array of pointers. | |
4138 * If this fails (mem allocation), there is no upward search at all or a | |
4139 * stop directory is not recognized -> continue silently. | |
4140 * If stopdirs just contains a ";" or is empty, | |
1541 | 4141 * search_ctx->ffsc_stopdirs_v will only contain a NULL pointer. This |
7 | 4142 * is handled as unlimited upward search. See function |
4143 * ff_path_in_stoplist() for details. | |
4144 */ | |
4145 if (stopdirs != NULL) | |
4146 { | |
4147 char_u *walker = stopdirs; | |
4148 int dircount; | |
4149 | |
4150 while (*walker == ';') | |
4151 walker++; | |
4152 | |
4153 dircount = 1; | |
1541 | 4154 search_ctx->ffsc_stopdirs_v = |
4155 (char_u **)alloc((unsigned)sizeof(char_u *)); | |
4156 | |
4157 if (search_ctx->ffsc_stopdirs_v != NULL) | |
7 | 4158 { |
4159 do | |
4160 { | |
4161 char_u *helper; | |
4162 void *ptr; | |
4163 | |
4164 helper = walker; | |
1541 | 4165 ptr = vim_realloc(search_ctx->ffsc_stopdirs_v, |
7 | 4166 (dircount + 1) * sizeof(char_u *)); |
4167 if (ptr) | |
1541 | 4168 search_ctx->ffsc_stopdirs_v = ptr; |
7 | 4169 else |
4170 /* ignore, keep what we have and continue */ | |
4171 break; | |
4172 walker = vim_strchr(walker, ';'); | |
4173 if (walker) | |
4174 { | |
1541 | 4175 search_ctx->ffsc_stopdirs_v[dircount-1] = |
4176 vim_strnsave(helper, (int)(walker - helper)); | |
7 | 4177 walker++; |
4178 } | |
4179 else | |
4180 /* this might be "", which means ascent till top | |
4181 * of directory tree. | |
4182 */ | |
1541 | 4183 search_ctx->ffsc_stopdirs_v[dircount-1] = |
4184 vim_strsave(helper); | |
7 | 4185 |
4186 dircount++; | |
4187 | |
4188 } while (walker != NULL); | |
1541 | 4189 search_ctx->ffsc_stopdirs_v[dircount-1] = NULL; |
7 | 4190 } |
4191 } | |
4192 #endif | |
4193 | |
4194 #ifdef FEAT_PATH_EXTRA | |
1541 | 4195 search_ctx->ffsc_level = level; |
7 | 4196 |
4197 /* split into: | |
4198 * -fix path | |
4199 * -wildcard_stuff (might be NULL) | |
4200 */ | |
4201 wc_part = vim_strchr(path, '*'); | |
4202 if (wc_part != NULL) | |
4203 { | |
4204 int llevel; | |
4205 int len; | |
29 | 4206 char *errpt; |
7 | 4207 |
4208 /* save the fix part of the path */ | |
1541 | 4209 search_ctx->ffsc_fix_path = vim_strnsave(path, (int)(wc_part - path)); |
7 | 4210 |
4211 /* | |
4212 * copy wc_path and add restricts to the '**' wildcard. | |
1209 | 4213 * The octet after a '**' is used as a (binary) counter. |
7 | 4214 * So '**3' is transposed to '**^C' ('^C' is ASCII value 3) |
4215 * or '**76' is transposed to '**N'( 'N' is ASCII value 76). | |
4216 * For EBCDIC you get different character values. | |
4217 * If no restrict is given after '**' the default is used. | |
1993 | 4218 * Due to this technique the path looks awful if you print it as a |
7 | 4219 * string. |
4220 */ | |
4221 len = 0; | |
4222 while (*wc_part != NUL) | |
4223 { | |
3202 | 4224 if (len + 5 >= MAXPATHL) |
4225 { | |
4226 EMSG(_(e_pathtoolong)); | |
4227 break; | |
4228 } | |
7 | 4229 if (STRNCMP(wc_part, "**", 2) == 0) |
4230 { | |
4231 ff_expand_buffer[len++] = *wc_part++; | |
4232 ff_expand_buffer[len++] = *wc_part++; | |
4233 | |
29 | 4234 llevel = strtol((char *)wc_part, &errpt, 10); |
4235 if ((char_u *)errpt != wc_part && llevel > 0 && llevel < 255) | |
7 | 4236 ff_expand_buffer[len++] = llevel; |
29 | 4237 else if ((char_u *)errpt != wc_part && llevel == 0) |
7 | 4238 /* restrict is 0 -> remove already added '**' */ |
4239 len -= 2; | |
4240 else | |
4241 ff_expand_buffer[len++] = FF_MAX_STAR_STAR_EXPAND; | |
29 | 4242 wc_part = (char_u *)errpt; |
461 | 4243 if (*wc_part != NUL && !vim_ispathsep(*wc_part)) |
7 | 4244 { |
4245 EMSG2(_("E343: Invalid path: '**[number]' must be at the end of the path or be followed by '%s'."), PATHSEPSTR); | |
4246 goto error_return; | |
4247 } | |
4248 } | |
4249 else | |
4250 ff_expand_buffer[len++] = *wc_part++; | |
4251 } | |
4252 ff_expand_buffer[len] = NUL; | |
1541 | 4253 search_ctx->ffsc_wc_path = vim_strsave(ff_expand_buffer); |
4254 | |
4255 if (search_ctx->ffsc_wc_path == NULL) | |
7 | 4256 goto error_return; |
4257 } | |
4258 else | |
4259 #endif | |
1541 | 4260 search_ctx->ffsc_fix_path = vim_strsave(path); |
4261 | |
4262 if (search_ctx->ffsc_start_dir == NULL) | |
7 | 4263 { |
4264 /* store the fix part as startdir. | |
4265 * This is needed if the parameter path is fully qualified. | |
4266 */ | |
1541 | 4267 search_ctx->ffsc_start_dir = vim_strsave(search_ctx->ffsc_fix_path); |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4268 if (search_ctx->ffsc_start_dir == NULL) |
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4269 goto error_return; |
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4270 search_ctx->ffsc_fix_path[0] = NUL; |
7 | 4271 } |
4272 | |
4273 /* create an absolute path */ | |
3202 | 4274 if (STRLEN(search_ctx->ffsc_start_dir) |
4275 + STRLEN(search_ctx->ffsc_fix_path) + 3 >= MAXPATHL) | |
4276 { | |
4277 EMSG(_(e_pathtoolong)); | |
4278 goto error_return; | |
4279 } | |
1541 | 4280 STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir); |
7 | 4281 add_pathsep(ff_expand_buffer); |
5108
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4282 { |
5124
6f24376028af
updated for version 7.3.1305
Bram Moolenaar <bram@vim.org>
parents:
5116
diff
changeset
|
4283 int eb_len = (int)STRLEN(ff_expand_buffer); |
6f24376028af
updated for version 7.3.1305
Bram Moolenaar <bram@vim.org>
parents:
5116
diff
changeset
|
4284 char_u *buf = alloc(eb_len |
6f24376028af
updated for version 7.3.1305
Bram Moolenaar <bram@vim.org>
parents:
5116
diff
changeset
|
4285 + (int)STRLEN(search_ctx->ffsc_fix_path) + 1); |
5108
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4286 |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4287 STRCPY(buf, ff_expand_buffer); |
5110
dafd77a15d44
updated for version 7.3.1298
Bram Moolenaar <bram@vim.org>
parents:
5108
diff
changeset
|
4288 STRCPY(buf + eb_len, search_ctx->ffsc_fix_path); |
5108
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4289 if (mch_isdir(buf)) |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4290 { |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4291 STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path); |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4292 add_pathsep(ff_expand_buffer); |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4293 } |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4294 #ifdef FEAT_PATH_EXTRA |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4295 else |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4296 { |
5116
6cabac58f26f
updated for version 7.3.1301
Bram Moolenaar <bram@vim.org>
parents:
5110
diff
changeset
|
4297 char_u *p = gettail(search_ctx->ffsc_fix_path); |
5571 | 4298 char_u *wc_path = NULL; |
4299 char_u *temp = NULL; | |
5108
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4300 int len = 0; |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4301 |
5116
6cabac58f26f
updated for version 7.3.1301
Bram Moolenaar <bram@vim.org>
parents:
5110
diff
changeset
|
4302 if (p > search_ctx->ffsc_fix_path) |
5108
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4303 { |
5124
6f24376028af
updated for version 7.3.1305
Bram Moolenaar <bram@vim.org>
parents:
5116
diff
changeset
|
4304 len = (int)(p - search_ctx->ffsc_fix_path) - 1; |
5108
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4305 STRNCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, len); |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4306 add_pathsep(ff_expand_buffer); |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4307 } |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4308 else |
5124
6f24376028af
updated for version 7.3.1305
Bram Moolenaar <bram@vim.org>
parents:
5116
diff
changeset
|
4309 len = (int)STRLEN(search_ctx->ffsc_fix_path); |
5108
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4310 |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4311 if (search_ctx->ffsc_wc_path != NULL) |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4312 { |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4313 wc_path = vim_strsave(search_ctx->ffsc_wc_path); |
5124
6f24376028af
updated for version 7.3.1305
Bram Moolenaar <bram@vim.org>
parents:
5116
diff
changeset
|
4314 temp = alloc((int)(STRLEN(search_ctx->ffsc_wc_path) |
5151
d0288faf3086
updated for version 7.4a.002
Bram Moolenaar <bram@vim.org>
parents:
5124
diff
changeset
|
4315 + STRLEN(search_ctx->ffsc_fix_path + len) |
d0288faf3086
updated for version 7.4a.002
Bram Moolenaar <bram@vim.org>
parents:
5124
diff
changeset
|
4316 + 1)); |
7148
339e657a6ed6
commit https://github.com/vim/vim/commit/c79a5452acd695238798947e40086f9823c400e7
Christian Brabandt <cb@256bit.org>
parents:
7131
diff
changeset
|
4317 if (temp == NULL || wc_path == NULL) |
339e657a6ed6
commit https://github.com/vim/vim/commit/c79a5452acd695238798947e40086f9823c400e7
Christian Brabandt <cb@256bit.org>
parents:
7131
diff
changeset
|
4318 { |
339e657a6ed6
commit https://github.com/vim/vim/commit/c79a5452acd695238798947e40086f9823c400e7
Christian Brabandt <cb@256bit.org>
parents:
7131
diff
changeset
|
4319 vim_free(buf); |
339e657a6ed6
commit https://github.com/vim/vim/commit/c79a5452acd695238798947e40086f9823c400e7
Christian Brabandt <cb@256bit.org>
parents:
7131
diff
changeset
|
4320 vim_free(temp); |
339e657a6ed6
commit https://github.com/vim/vim/commit/c79a5452acd695238798947e40086f9823c400e7
Christian Brabandt <cb@256bit.org>
parents:
7131
diff
changeset
|
4321 vim_free(wc_path); |
339e657a6ed6
commit https://github.com/vim/vim/commit/c79a5452acd695238798947e40086f9823c400e7
Christian Brabandt <cb@256bit.org>
parents:
7131
diff
changeset
|
4322 goto error_return; |
339e657a6ed6
commit https://github.com/vim/vim/commit/c79a5452acd695238798947e40086f9823c400e7
Christian Brabandt <cb@256bit.org>
parents:
7131
diff
changeset
|
4323 } |
339e657a6ed6
commit https://github.com/vim/vim/commit/c79a5452acd695238798947e40086f9823c400e7
Christian Brabandt <cb@256bit.org>
parents:
7131
diff
changeset
|
4324 |
339e657a6ed6
commit https://github.com/vim/vim/commit/c79a5452acd695238798947e40086f9823c400e7
Christian Brabandt <cb@256bit.org>
parents:
7131
diff
changeset
|
4325 STRCPY(temp, search_ctx->ffsc_fix_path + len); |
339e657a6ed6
commit https://github.com/vim/vim/commit/c79a5452acd695238798947e40086f9823c400e7
Christian Brabandt <cb@256bit.org>
parents:
7131
diff
changeset
|
4326 STRCAT(temp, search_ctx->ffsc_wc_path); |
339e657a6ed6
commit https://github.com/vim/vim/commit/c79a5452acd695238798947e40086f9823c400e7
Christian Brabandt <cb@256bit.org>
parents:
7131
diff
changeset
|
4327 vim_free(search_ctx->ffsc_wc_path); |
5108
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4328 vim_free(wc_path); |
7148
339e657a6ed6
commit https://github.com/vim/vim/commit/c79a5452acd695238798947e40086f9823c400e7
Christian Brabandt <cb@256bit.org>
parents:
7131
diff
changeset
|
4329 search_ctx->ffsc_wc_path = temp; |
5108
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4330 } |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4331 } |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4332 #endif |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4333 vim_free(buf); |
cb0a5c9c0f9b
updated for version 7.3.1297
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4334 } |
7 | 4335 |
4336 sptr = ff_create_stack_element(ff_expand_buffer, | |
4337 #ifdef FEAT_PATH_EXTRA | |
1541 | 4338 search_ctx->ffsc_wc_path, |
7 | 4339 #endif |
4340 level, 0); | |
4341 | |
4342 if (sptr == NULL) | |
4343 goto error_return; | |
4344 | |
1541 | 4345 ff_push(search_ctx, sptr); |
4346 | |
4347 search_ctx->ffsc_file_to_search = vim_strsave(filename); | |
4348 if (search_ctx->ffsc_file_to_search == NULL) | |
7 | 4349 goto error_return; |
4350 | |
1541 | 4351 return search_ctx; |
7 | 4352 |
4353 error_return: | |
4354 /* | |
4355 * We clear the search context now! | |
4356 * Even when the caller gave us a (perhaps valid) context we free it here, | |
4357 * as we might have already destroyed it. | |
4358 */ | |
1541 | 4359 vim_findfile_cleanup(search_ctx); |
7 | 4360 return NULL; |
4361 } | |
4362 | |
4363 #if defined(FEAT_PATH_EXTRA) || defined(PROTO) | |
4364 /* | |
4365 * Get the stopdir string. Check that ';' is not escaped. | |
4366 */ | |
4367 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4368 vim_findfile_stopdir(char_u *buf) |
7 | 4369 { |
4370 char_u *r_ptr = buf; | |
4371 | |
4372 while (*r_ptr != NUL && *r_ptr != ';') | |
4373 { | |
4374 if (r_ptr[0] == '\\' && r_ptr[1] == ';') | |
4375 { | |
2984 | 4376 /* Overwrite the escape char, |
4377 * use STRLEN(r_ptr) to move the trailing '\0'. */ | |
1621 | 4378 STRMOVE(r_ptr, r_ptr + 1); |
7 | 4379 r_ptr++; |
4380 } | |
4381 r_ptr++; | |
4382 } | |
4383 if (*r_ptr == ';') | |
4384 { | |
4385 *r_ptr = 0; | |
4386 r_ptr++; | |
4387 } | |
4388 else if (*r_ptr == NUL) | |
4389 r_ptr = NULL; | |
4390 return r_ptr; | |
4391 } | |
4392 #endif | |
4393 | |
1541 | 4394 /* |
4395 * Clean up the given search context. Can handle a NULL pointer. | |
4396 */ | |
7 | 4397 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4398 vim_findfile_cleanup(void *ctx) |
7 | 4399 { |
359 | 4400 if (ctx == NULL) |
7 | 4401 return; |
4402 | |
4403 vim_findfile_free_visited(ctx); | |
1541 | 4404 ff_clear(ctx); |
7 | 4405 vim_free(ctx); |
4406 } | |
4407 | |
4408 /* | |
4409 * Find a file in a search context. | |
4410 * The search context was created with vim_findfile_init() above. | |
4411 * Return a pointer to an allocated file name or NULL if nothing found. | |
4412 * To get all matching files call this function until you get NULL. | |
4413 * | |
20 | 4414 * If the passed search_context is NULL, NULL is returned. |
7 | 4415 * |
4416 * The search algorithm is depth first. To change this replace the | |
4417 * stack with a list (don't forget to leave partly searched directories on the | |
4418 * top of the list). | |
4419 */ | |
4420 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4421 vim_findfile(void *search_ctx_arg) |
7 | 4422 { |
4423 char_u *file_path; | |
4424 #ifdef FEAT_PATH_EXTRA | |
4425 char_u *rest_of_wildcards; | |
4426 char_u *path_end = NULL; | |
4427 #endif | |
1541 | 4428 ff_stack_T *stackp; |
7 | 4429 #if defined(FEAT_SEARCHPATH) || defined(FEAT_PATH_EXTRA) |
4430 int len; | |
4431 #endif | |
4432 int i; | |
4433 char_u *p; | |
4434 #ifdef FEAT_SEARCHPATH | |
4435 char_u *suf; | |
4436 #endif | |
1541 | 4437 ff_search_ctx_T *search_ctx; |
4438 | |
4439 if (search_ctx_arg == NULL) | |
7 | 4440 return NULL; |
4441 | |
1541 | 4442 search_ctx = (ff_search_ctx_T *)search_ctx_arg; |
7 | 4443 |
4444 /* | |
4445 * filepath is used as buffer for various actions and as the storage to | |
4446 * return a found filename. | |
4447 */ | |
4448 if ((file_path = alloc((int)MAXPATHL)) == NULL) | |
4449 return NULL; | |
4450 | |
4451 #ifdef FEAT_PATH_EXTRA | |
4452 /* store the end of the start dir -- needed for upward search */ | |
1541 | 4453 if (search_ctx->ffsc_start_dir != NULL) |
4454 path_end = &search_ctx->ffsc_start_dir[ | |
4455 STRLEN(search_ctx->ffsc_start_dir)]; | |
7 | 4456 #endif |
4457 | |
4458 #ifdef FEAT_PATH_EXTRA | |
4459 /* upward search loop */ | |
4460 for (;;) | |
4461 { | |
4462 #endif | |
4463 /* downward search loop */ | |
4464 for (;;) | |
4465 { | |
4466 /* check if user user wants to stop the search*/ | |
4467 ui_breakcheck(); | |
4468 if (got_int) | |
4469 break; | |
4470 | |
4471 /* get directory to work on from stack */ | |
1541 | 4472 stackp = ff_pop(search_ctx); |
4473 if (stackp == NULL) | |
7 | 4474 break; |
4475 | |
4476 /* | |
4477 * TODO: decide if we leave this test in | |
4478 * | |
4479 * GOOD: don't search a directory(-tree) twice. | |
4480 * BAD: - check linked list for every new directory entered. | |
4481 * - check for double files also done below | |
4482 * | |
4483 * Here we check if we already searched this directory. | |
4484 * We already searched a directory if: | |
4485 * 1) The directory is the same. | |
4486 * 2) We would use the same wildcard string. | |
4487 * | |
4488 * Good if you have links on same directory via several ways | |
4489 * or you have selfreferences in directories (e.g. SuSE Linux 6.3: | |
4490 * /etc/rc.d/init.d is linked to /etc/rc.d -> endless loop) | |
4491 * | |
4492 * This check is only needed for directories we work on for the | |
1541 | 4493 * first time (hence stackp->ff_filearray == NULL) |
7 | 4494 */ |
1541 | 4495 if (stackp->ffs_filearray == NULL |
4496 && ff_check_visited(&search_ctx->ffsc_dir_visited_list | |
7 | 4497 ->ffvl_visited_list, |
1541 | 4498 stackp->ffs_fix_path |
7 | 4499 #ifdef FEAT_PATH_EXTRA |
1541 | 4500 , stackp->ffs_wc_path |
7 | 4501 #endif |
4502 ) == FAIL) | |
4503 { | |
4504 #ifdef FF_VERBOSE | |
4505 if (p_verbose >= 5) | |
4506 { | |
293 | 4507 verbose_enter_scroll(); |
7 | 4508 smsg((char_u *)"Already Searched: %s (%s)", |
1541 | 4509 stackp->ffs_fix_path, stackp->ffs_wc_path); |
7 | 4510 /* don't overwrite this either */ |
4511 msg_puts((char_u *)"\n"); | |
293 | 4512 verbose_leave_scroll(); |
7 | 4513 } |
4514 #endif | |
1541 | 4515 ff_free_stack_element(stackp); |
7 | 4516 continue; |
4517 } | |
4518 #ifdef FF_VERBOSE | |
4519 else if (p_verbose >= 5) | |
4520 { | |
293 | 4521 verbose_enter_scroll(); |
273 | 4522 smsg((char_u *)"Searching: %s (%s)", |
1541 | 4523 stackp->ffs_fix_path, stackp->ffs_wc_path); |
7 | 4524 /* don't overwrite this either */ |
4525 msg_puts((char_u *)"\n"); | |
293 | 4526 verbose_leave_scroll(); |
7 | 4527 } |
4528 #endif | |
4529 | |
4530 /* check depth */ | |
1541 | 4531 if (stackp->ffs_level <= 0) |
7 | 4532 { |
1541 | 4533 ff_free_stack_element(stackp); |
7 | 4534 continue; |
4535 } | |
4536 | |
4537 file_path[0] = NUL; | |
4538 | |
4539 /* | |
4540 * If no filearray till now expand wildcards | |
4541 * The function expand_wildcards() can handle an array of paths | |
4542 * and all possible expands are returned in one array. We use this | |
4543 * to handle the expansion of '**' into an empty string. | |
4544 */ | |
1541 | 4545 if (stackp->ffs_filearray == NULL) |
7 | 4546 { |
4547 char_u *dirptrs[2]; | |
4548 | |
4549 /* we use filepath to build the path expand_wildcards() should | |
4550 * expand. | |
4551 */ | |
4552 dirptrs[0] = file_path; | |
4553 dirptrs[1] = NULL; | |
4554 | |
4555 /* if we have a start dir copy it in */ | |
1541 | 4556 if (!vim_isAbsName(stackp->ffs_fix_path) |
4557 && search_ctx->ffsc_start_dir) | |
7 | 4558 { |
1541 | 4559 STRCPY(file_path, search_ctx->ffsc_start_dir); |
7 | 4560 add_pathsep(file_path); |
4561 } | |
4562 | |
4563 /* append the fix part of the search path */ | |
1541 | 4564 STRCAT(file_path, stackp->ffs_fix_path); |
7 | 4565 add_pathsep(file_path); |
4566 | |
4567 #ifdef FEAT_PATH_EXTRA | |
1541 | 4568 rest_of_wildcards = stackp->ffs_wc_path; |
7 | 4569 if (*rest_of_wildcards != NUL) |
4570 { | |
4571 len = (int)STRLEN(file_path); | |
4572 if (STRNCMP(rest_of_wildcards, "**", 2) == 0) | |
4573 { | |
4574 /* pointer to the restrict byte | |
4575 * The restrict byte is not a character! | |
4576 */ | |
4577 p = rest_of_wildcards + 2; | |
4578 | |
4579 if (*p > 0) | |
4580 { | |
4581 (*p)--; | |
4582 file_path[len++] = '*'; | |
4583 } | |
4584 | |
4585 if (*p == 0) | |
4586 { | |
4587 /* remove '**<numb> from wildcards */ | |
1621 | 4588 STRMOVE(rest_of_wildcards, rest_of_wildcards + 3); |
7 | 4589 } |
4590 else | |
4591 rest_of_wildcards += 3; | |
4592 | |
1541 | 4593 if (stackp->ffs_star_star_empty == 0) |
7 | 4594 { |
4595 /* if not done before, expand '**' to empty */ | |
1541 | 4596 stackp->ffs_star_star_empty = 1; |
4597 dirptrs[1] = stackp->ffs_fix_path; | |
7 | 4598 } |
4599 } | |
4600 | |
4601 /* | |
4602 * Here we copy until the next path separator or the end of | |
4603 * the path. If we stop at a path separator, there is | |
1209 | 4604 * still something else left. This is handled below by |
7 | 4605 * pushing every directory returned from expand_wildcards() |
4606 * on the stack again for further search. | |
4607 */ | |
4608 while (*rest_of_wildcards | |
4609 && !vim_ispathsep(*rest_of_wildcards)) | |
4610 file_path[len++] = *rest_of_wildcards++; | |
4611 | |
4612 file_path[len] = NUL; | |
4613 if (vim_ispathsep(*rest_of_wildcards)) | |
4614 rest_of_wildcards++; | |
4615 } | |
4616 #endif | |
4617 | |
4618 /* | |
4619 * Expand wildcards like "*" and "$VAR". | |
4620 * If the path is a URL don't try this. | |
4621 */ | |
4622 if (path_with_url(dirptrs[0])) | |
4623 { | |
1541 | 4624 stackp->ffs_filearray = (char_u **) |
7 | 4625 alloc((unsigned)sizeof(char *)); |
1541 | 4626 if (stackp->ffs_filearray != NULL |
4627 && (stackp->ffs_filearray[0] | |
7 | 4628 = vim_strsave(dirptrs[0])) != NULL) |
1541 | 4629 stackp->ffs_filearray_size = 1; |
7 | 4630 else |
1541 | 4631 stackp->ffs_filearray_size = 0; |
7 | 4632 } |
4633 else | |
2984 | 4634 /* Add EW_NOTWILD because the expanded path may contain |
4635 * wildcard characters that are to be taken literally. | |
4636 * This is a bit of a hack. */ | |
7 | 4637 expand_wildcards((dirptrs[1] == NULL) ? 1 : 2, dirptrs, |
1541 | 4638 &stackp->ffs_filearray_size, |
4639 &stackp->ffs_filearray, | |
2984 | 4640 EW_DIR|EW_ADDSLASH|EW_SILENT|EW_NOTWILD); |
7 | 4641 |
1541 | 4642 stackp->ffs_filearray_cur = 0; |
4643 stackp->ffs_stage = 0; | |
7 | 4644 } |
4645 #ifdef FEAT_PATH_EXTRA | |
4646 else | |
1541 | 4647 rest_of_wildcards = &stackp->ffs_wc_path[ |
4648 STRLEN(stackp->ffs_wc_path)]; | |
4649 #endif | |
4650 | |
4651 if (stackp->ffs_stage == 0) | |
7 | 4652 { |
4653 /* this is the first time we work on this directory */ | |
4654 #ifdef FEAT_PATH_EXTRA | |
4655 if (*rest_of_wildcards == NUL) | |
4656 #endif | |
4657 { | |
4658 /* | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
4659 * We don't have further wildcards to expand, so we have to |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
4660 * check for the final file now. |
7 | 4661 */ |
1541 | 4662 for (i = stackp->ffs_filearray_cur; |
4663 i < stackp->ffs_filearray_size; ++i) | |
7 | 4664 { |
1541 | 4665 if (!path_with_url(stackp->ffs_filearray[i]) |
4666 && !mch_isdir(stackp->ffs_filearray[i])) | |
7 | 4667 continue; /* not a directory */ |
4668 | |
1993 | 4669 /* prepare the filename to be checked for existence |
7 | 4670 * below */ |
1541 | 4671 STRCPY(file_path, stackp->ffs_filearray[i]); |
7 | 4672 add_pathsep(file_path); |
1541 | 4673 STRCAT(file_path, search_ctx->ffsc_file_to_search); |
7 | 4674 |
4675 /* | |
4676 * Try without extra suffix and then with suffixes | |
4677 * from 'suffixesadd'. | |
4678 */ | |
4679 #ifdef FEAT_SEARCHPATH | |
4680 len = (int)STRLEN(file_path); | |
2521
d890c820722f
Fix: 'suffixesadd' was used for finding tags file.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4681 if (search_ctx->ffsc_tagfile) |
d890c820722f
Fix: 'suffixesadd' was used for finding tags file.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4682 suf = (char_u *)""; |
d890c820722f
Fix: 'suffixesadd' was used for finding tags file.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4683 else |
d890c820722f
Fix: 'suffixesadd' was used for finding tags file.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
4684 suf = curbuf->b_p_sua; |
7 | 4685 for (;;) |
4686 #endif | |
4687 { | |
4688 /* if file exists and we didn't already find it */ | |
4689 if ((path_with_url(file_path) | |
1541 | 4690 || (mch_getperm(file_path) >= 0 |
4691 && (search_ctx->ffsc_find_what | |
4692 == FINDFILE_BOTH | |
4693 || ((search_ctx->ffsc_find_what | |
4694 == FINDFILE_DIR) | |
4695 == mch_isdir(file_path))))) | |
7 | 4696 #ifndef FF_VERBOSE |
4697 && (ff_check_visited( | |
1541 | 4698 &search_ctx->ffsc_visited_list->ffvl_visited_list, |
7 | 4699 file_path |
4700 #ifdef FEAT_PATH_EXTRA | |
4701 , (char_u *)"" | |
4702 #endif | |
4703 ) == OK) | |
4704 #endif | |
4705 ) | |
4706 { | |
4707 #ifdef FF_VERBOSE | |
4708 if (ff_check_visited( | |
1541 | 4709 &search_ctx->ffsc_visited_list->ffvl_visited_list, |
7 | 4710 file_path |
4711 #ifdef FEAT_PATH_EXTRA | |
4712 , (char_u *)"" | |
4713 #endif | |
4714 ) == FAIL) | |
4715 { | |
4716 if (p_verbose >= 5) | |
4717 { | |
293 | 4718 verbose_enter_scroll(); |
273 | 4719 smsg((char_u *)"Already: %s", |
7 | 4720 file_path); |
4721 /* don't overwrite this either */ | |
4722 msg_puts((char_u *)"\n"); | |
293 | 4723 verbose_leave_scroll(); |
7 | 4724 } |
4725 continue; | |
4726 } | |
4727 #endif | |
4728 | |
4729 /* push dir to examine rest of subdirs later */ | |
1541 | 4730 stackp->ffs_filearray_cur = i + 1; |
4731 ff_push(search_ctx, stackp); | |
7 | 4732 |
1789 | 4733 if (!path_with_url(file_path)) |
4734 simplify_filename(file_path); | |
7 | 4735 if (mch_dirname(ff_expand_buffer, MAXPATHL) |
4736 == OK) | |
4737 { | |
4738 p = shorten_fname(file_path, | |
4739 ff_expand_buffer); | |
4740 if (p != NULL) | |
1621 | 4741 STRMOVE(file_path, p); |
7 | 4742 } |
4743 #ifdef FF_VERBOSE | |
4744 if (p_verbose >= 5) | |
4745 { | |
293 | 4746 verbose_enter_scroll(); |
273 | 4747 smsg((char_u *)"HIT: %s", file_path); |
7 | 4748 /* don't overwrite this either */ |
4749 msg_puts((char_u *)"\n"); | |
293 | 4750 verbose_leave_scroll(); |
7 | 4751 } |
4752 #endif | |
4753 return file_path; | |
4754 } | |
4755 | |
4756 #ifdef FEAT_SEARCHPATH | |
4757 /* Not found or found already, try next suffix. */ | |
4758 if (*suf == NUL) | |
4759 break; | |
4760 copy_option_part(&suf, file_path + len, | |
4761 MAXPATHL - len, ","); | |
4762 #endif | |
4763 } | |
4764 } | |
4765 } | |
4766 #ifdef FEAT_PATH_EXTRA | |
4767 else | |
4768 { | |
4769 /* | |
4770 * still wildcards left, push the directories for further | |
4771 * search | |
4772 */ | |
1541 | 4773 for (i = stackp->ffs_filearray_cur; |
4774 i < stackp->ffs_filearray_size; ++i) | |
7 | 4775 { |
1541 | 4776 if (!mch_isdir(stackp->ffs_filearray[i])) |
7 | 4777 continue; /* not a directory */ |
4778 | |
1541 | 4779 ff_push(search_ctx, |
4780 ff_create_stack_element( | |
4781 stackp->ffs_filearray[i], | |
4782 rest_of_wildcards, | |
4783 stackp->ffs_level - 1, 0)); | |
7 | 4784 } |
4785 } | |
4786 #endif | |
1541 | 4787 stackp->ffs_filearray_cur = 0; |
4788 stackp->ffs_stage = 1; | |
7 | 4789 } |
4790 | |
4791 #ifdef FEAT_PATH_EXTRA | |
4792 /* | |
4793 * if wildcards contains '**' we have to descent till we reach the | |
4794 * leaves of the directory tree. | |
4795 */ | |
1541 | 4796 if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0) |
7 | 4797 { |
1541 | 4798 for (i = stackp->ffs_filearray_cur; |
4799 i < stackp->ffs_filearray_size; ++i) | |
7 | 4800 { |
1541 | 4801 if (fnamecmp(stackp->ffs_filearray[i], |
4802 stackp->ffs_fix_path) == 0) | |
7 | 4803 continue; /* don't repush same directory */ |
1541 | 4804 if (!mch_isdir(stackp->ffs_filearray[i])) |
7 | 4805 continue; /* not a directory */ |
1541 | 4806 ff_push(search_ctx, |
4807 ff_create_stack_element(stackp->ffs_filearray[i], | |
4808 stackp->ffs_wc_path, stackp->ffs_level - 1, 1)); | |
7 | 4809 } |
4810 } | |
4811 #endif | |
4812 | |
4813 /* we are done with the current directory */ | |
1541 | 4814 ff_free_stack_element(stackp); |
7 | 4815 |
4816 } | |
4817 | |
4818 #ifdef FEAT_PATH_EXTRA | |
4819 /* If we reached this, we didn't find anything downwards. | |
4820 * Let's check if we should do an upward search. | |
4821 */ | |
1541 | 4822 if (search_ctx->ffsc_start_dir |
4823 && search_ctx->ffsc_stopdirs_v != NULL && !got_int) | |
7 | 4824 { |
4825 ff_stack_T *sptr; | |
4826 | |
4827 /* is the last starting directory in the stop list? */ | |
1541 | 4828 if (ff_path_in_stoplist(search_ctx->ffsc_start_dir, |
4829 (int)(path_end - search_ctx->ffsc_start_dir), | |
4830 search_ctx->ffsc_stopdirs_v) == TRUE) | |
7 | 4831 break; |
4832 | |
4833 /* cut of last dir */ | |
1541 | 4834 while (path_end > search_ctx->ffsc_start_dir |
4835 && vim_ispathsep(*path_end)) | |
7 | 4836 path_end--; |
1541 | 4837 while (path_end > search_ctx->ffsc_start_dir |
4838 && !vim_ispathsep(path_end[-1])) | |
7 | 4839 path_end--; |
4840 *path_end = 0; | |
4841 path_end--; | |
4842 | |
1541 | 4843 if (*search_ctx->ffsc_start_dir == 0) |
7 | 4844 break; |
4845 | |
1541 | 4846 STRCPY(file_path, search_ctx->ffsc_start_dir); |
7 | 4847 add_pathsep(file_path); |
1541 | 4848 STRCAT(file_path, search_ctx->ffsc_fix_path); |
7 | 4849 |
4850 /* create a new stack entry */ | |
4851 sptr = ff_create_stack_element(file_path, | |
1541 | 4852 search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0); |
7 | 4853 if (sptr == NULL) |
4854 break; | |
1541 | 4855 ff_push(search_ctx, sptr); |
7 | 4856 } |
4857 else | |
4858 break; | |
4859 } | |
4860 #endif | |
4861 | |
4862 vim_free(file_path); | |
4863 return NULL; | |
4864 } | |
4865 | |
4866 /* | |
4867 * Free the list of lists of visited files and directories | |
4868 * Can handle it if the passed search_context is NULL; | |
4869 */ | |
4870 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4871 vim_findfile_free_visited(void *search_ctx_arg) |
7 | 4872 { |
1541 | 4873 ff_search_ctx_T *search_ctx; |
4874 | |
4875 if (search_ctx_arg == NULL) | |
7 | 4876 return; |
4877 | |
1541 | 4878 search_ctx = (ff_search_ctx_T *)search_ctx_arg; |
4879 vim_findfile_free_visited_list(&search_ctx->ffsc_visited_lists_list); | |
4880 vim_findfile_free_visited_list(&search_ctx->ffsc_dir_visited_lists_list); | |
7 | 4881 } |
4882 | |
4883 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4884 vim_findfile_free_visited_list(ff_visited_list_hdr_T **list_headp) |
7 | 4885 { |
4886 ff_visited_list_hdr_T *vp; | |
4887 | |
4888 while (*list_headp != NULL) | |
4889 { | |
4890 vp = (*list_headp)->ffvl_next; | |
4891 ff_free_visited_list((*list_headp)->ffvl_visited_list); | |
4892 | |
4893 vim_free((*list_headp)->ffvl_filename); | |
4894 vim_free(*list_headp); | |
4895 *list_headp = vp; | |
4896 } | |
4897 *list_headp = NULL; | |
4898 } | |
4899 | |
4900 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4901 ff_free_visited_list(ff_visited_T *vl) |
7 | 4902 { |
4903 ff_visited_T *vp; | |
4904 | |
4905 while (vl != NULL) | |
4906 { | |
4907 vp = vl->ffv_next; | |
4908 #ifdef FEAT_PATH_EXTRA | |
4909 vim_free(vl->ffv_wc_path); | |
4910 #endif | |
4911 vim_free(vl); | |
4912 vl = vp; | |
4913 } | |
4914 vl = NULL; | |
4915 } | |
4916 | |
4917 /* | |
4918 * Returns the already visited list for the given filename. If none is found it | |
4919 * allocates a new one. | |
4920 */ | |
4921 static ff_visited_list_hdr_T* | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4922 ff_get_visited_list( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4923 char_u *filename, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4924 ff_visited_list_hdr_T **list_headp) |
7 | 4925 { |
4926 ff_visited_list_hdr_T *retptr = NULL; | |
4927 | |
4928 /* check if a visited list for the given filename exists */ | |
4929 if (*list_headp != NULL) | |
4930 { | |
4931 retptr = *list_headp; | |
4932 while (retptr != NULL) | |
4933 { | |
4934 if (fnamecmp(filename, retptr->ffvl_filename) == 0) | |
4935 { | |
4936 #ifdef FF_VERBOSE | |
4937 if (p_verbose >= 5) | |
4938 { | |
293 | 4939 verbose_enter_scroll(); |
273 | 4940 smsg((char_u *)"ff_get_visited_list: FOUND list for %s", |
7 | 4941 filename); |
4942 /* don't overwrite this either */ | |
4943 msg_puts((char_u *)"\n"); | |
293 | 4944 verbose_leave_scroll(); |
7 | 4945 } |
4946 #endif | |
4947 return retptr; | |
4948 } | |
4949 retptr = retptr->ffvl_next; | |
4950 } | |
4951 } | |
4952 | |
4953 #ifdef FF_VERBOSE | |
4954 if (p_verbose >= 5) | |
4955 { | |
293 | 4956 verbose_enter_scroll(); |
273 | 4957 smsg((char_u *)"ff_get_visited_list: new list for %s", filename); |
7 | 4958 /* don't overwrite this either */ |
4959 msg_puts((char_u *)"\n"); | |
293 | 4960 verbose_leave_scroll(); |
7 | 4961 } |
4962 #endif | |
4963 | |
4964 /* | |
4965 * if we reach this we didn't find a list and we have to allocate new list | |
4966 */ | |
4967 retptr = (ff_visited_list_hdr_T*)alloc((unsigned)sizeof(*retptr)); | |
4968 if (retptr == NULL) | |
4969 return NULL; | |
4970 | |
4971 retptr->ffvl_visited_list = NULL; | |
4972 retptr->ffvl_filename = vim_strsave(filename); | |
4973 if (retptr->ffvl_filename == NULL) | |
4974 { | |
4975 vim_free(retptr); | |
4976 return NULL; | |
4977 } | |
4978 retptr->ffvl_next = *list_headp; | |
4979 *list_headp = retptr; | |
4980 | |
4981 return retptr; | |
4982 } | |
4983 | |
4984 #ifdef FEAT_PATH_EXTRA | |
4985 /* | |
4986 * check if two wildcard paths are equal. Returns TRUE or FALSE. | |
4987 * They are equal if: | |
4988 * - both paths are NULL | |
4989 * - they have the same length | |
4990 * - char by char comparison is OK | |
4991 * - the only differences are in the counters behind a '**', so | |
4992 * '**\20' is equal to '**\24' | |
4993 */ | |
4994 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4995 ff_wc_equal(char_u *s1, char_u *s2) |
7 | 4996 { |
7044
7758d6245c3a
commit https://github.com/vim/vim/commit/f6470c288cb6f8efd60a507baf2c070f9d209ae6
Christian Brabandt <cb@256bit.org>
parents:
6929
diff
changeset
|
4997 int i, j; |
7062
6deb9d802fe4
commit https://github.com/vim/vim/commit/d43f0951bca162d4491d57df9277b5dbc462944f
Christian Brabandt <cb@256bit.org>
parents:
7044
diff
changeset
|
4998 int c1 = NUL; |
6deb9d802fe4
commit https://github.com/vim/vim/commit/d43f0951bca162d4491d57df9277b5dbc462944f
Christian Brabandt <cb@256bit.org>
parents:
7044
diff
changeset
|
4999 int c2 = NUL; |
4246 | 5000 int prev1 = NUL; |
5001 int prev2 = NUL; | |
7 | 5002 |
5003 if (s1 == s2) | |
5004 return TRUE; | |
5005 | |
5006 if (s1 == NULL || s2 == NULL) | |
5007 return FALSE; | |
5008 | |
7062
6deb9d802fe4
commit https://github.com/vim/vim/commit/d43f0951bca162d4491d57df9277b5dbc462944f
Christian Brabandt <cb@256bit.org>
parents:
7044
diff
changeset
|
5009 for (i = 0, j = 0; s1[i] != NUL && s2[j] != NUL;) |
7 | 5010 { |
7062
6deb9d802fe4
commit https://github.com/vim/vim/commit/d43f0951bca162d4491d57df9277b5dbc462944f
Christian Brabandt <cb@256bit.org>
parents:
7044
diff
changeset
|
5011 c1 = PTR2CHAR(s1 + i); |
6deb9d802fe4
commit https://github.com/vim/vim/commit/d43f0951bca162d4491d57df9277b5dbc462944f
Christian Brabandt <cb@256bit.org>
parents:
7044
diff
changeset
|
5012 c2 = PTR2CHAR(s2 + j); |
4246 | 5013 |
5014 if ((p_fic ? MB_TOLOWER(c1) != MB_TOLOWER(c2) : c1 != c2) | |
5015 && (prev1 != '*' || prev2 != '*')) | |
7062
6deb9d802fe4
commit https://github.com/vim/vim/commit/d43f0951bca162d4491d57df9277b5dbc462944f
Christian Brabandt <cb@256bit.org>
parents:
7044
diff
changeset
|
5016 return FALSE; |
4246 | 5017 prev2 = prev1; |
5018 prev1 = c1; | |
7044
7758d6245c3a
commit https://github.com/vim/vim/commit/f6470c288cb6f8efd60a507baf2c070f9d209ae6
Christian Brabandt <cb@256bit.org>
parents:
6929
diff
changeset
|
5019 |
7758d6245c3a
commit https://github.com/vim/vim/commit/f6470c288cb6f8efd60a507baf2c070f9d209ae6
Christian Brabandt <cb@256bit.org>
parents:
6929
diff
changeset
|
5020 i += MB_PTR2LEN(s1 + i); |
7758d6245c3a
commit https://github.com/vim/vim/commit/f6470c288cb6f8efd60a507baf2c070f9d209ae6
Christian Brabandt <cb@256bit.org>
parents:
6929
diff
changeset
|
5021 j += MB_PTR2LEN(s2 + j); |
7 | 5022 } |
7131
cc5570ed684e
commit https://github.com/vim/vim/commit/4d0c7bc74ac6fad5cb599dc3ade6996e848d83b6
Christian Brabandt <cb@256bit.org>
parents:
7111
diff
changeset
|
5023 return s1[i] == s2[j]; |
7 | 5024 } |
5025 #endif | |
5026 | |
5027 /* | |
5028 * maintains the list of already visited files and dirs | |
5029 * returns FAIL if the given file/dir is already in the list | |
5030 * returns OK if it is newly added | |
5031 * | |
5032 * TODO: What to do on memory allocation problems? | |
5033 * -> return TRUE - Better the file is found several times instead of | |
5034 * never. | |
5035 */ | |
5036 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5037 ff_check_visited( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5038 ff_visited_T **visited_list, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5039 char_u *fname |
7 | 5040 #ifdef FEAT_PATH_EXTRA |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5041 , char_u *wc_path |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5042 #endif |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5043 ) |
7 | 5044 { |
5045 ff_visited_T *vp; | |
5046 #ifdef UNIX | |
5047 struct stat st; | |
5048 int url = FALSE; | |
5049 #endif | |
5050 | |
5051 /* For an URL we only compare the name, otherwise we compare the | |
5052 * device/inode (unix) or the full path name (not Unix). */ | |
5053 if (path_with_url(fname)) | |
5054 { | |
418 | 5055 vim_strncpy(ff_expand_buffer, fname, MAXPATHL - 1); |
7 | 5056 #ifdef UNIX |
5057 url = TRUE; | |
5058 #endif | |
5059 } | |
5060 else | |
5061 { | |
5062 ff_expand_buffer[0] = NUL; | |
5063 #ifdef UNIX | |
5064 if (mch_stat((char *)fname, &st) < 0) | |
5065 #else | |
5066 if (vim_FullName(fname, ff_expand_buffer, MAXPATHL, TRUE) == FAIL) | |
5067 #endif | |
5068 return FAIL; | |
5069 } | |
5070 | |
5071 /* check against list of already visited files */ | |
5072 for (vp = *visited_list; vp != NULL; vp = vp->ffv_next) | |
5073 { | |
5074 if ( | |
5075 #ifdef UNIX | |
1881 | 5076 !url ? (vp->ffv_dev_valid && vp->ffv_dev == st.st_dev |
5077 && vp->ffv_ino == st.st_ino) | |
5078 : | |
7 | 5079 #endif |
5080 fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0 | |
5081 ) | |
5082 { | |
5083 #ifdef FEAT_PATH_EXTRA | |
5084 /* are the wildcard parts equal */ | |
5085 if (ff_wc_equal(vp->ffv_wc_path, wc_path) == TRUE) | |
5086 #endif | |
5087 /* already visited */ | |
5088 return FAIL; | |
5089 } | |
5090 } | |
5091 | |
5092 /* | |
5093 * New file/dir. Add it to the list of visited files/dirs. | |
5094 */ | |
5095 vp = (ff_visited_T *)alloc((unsigned)(sizeof(ff_visited_T) | |
5096 + STRLEN(ff_expand_buffer))); | |
5097 | |
5098 if (vp != NULL) | |
5099 { | |
5100 #ifdef UNIX | |
5101 if (!url) | |
5102 { | |
1881 | 5103 vp->ffv_dev_valid = TRUE; |
7 | 5104 vp->ffv_ino = st.st_ino; |
5105 vp->ffv_dev = st.st_dev; | |
5106 vp->ffv_fname[0] = NUL; | |
5107 } | |
5108 else | |
5109 { | |
1881 | 5110 vp->ffv_dev_valid = FALSE; |
7 | 5111 #endif |
5112 STRCPY(vp->ffv_fname, ff_expand_buffer); | |
5113 #ifdef UNIX | |
5114 } | |
5115 #endif | |
5116 #ifdef FEAT_PATH_EXTRA | |
5117 if (wc_path != NULL) | |
5118 vp->ffv_wc_path = vim_strsave(wc_path); | |
5119 else | |
5120 vp->ffv_wc_path = NULL; | |
5121 #endif | |
5122 | |
5123 vp->ffv_next = *visited_list; | |
5124 *visited_list = vp; | |
5125 } | |
5126 | |
5127 return OK; | |
5128 } | |
5129 | |
5130 /* | |
5131 * create stack element from given path pieces | |
5132 */ | |
5133 static ff_stack_T * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5134 ff_create_stack_element( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5135 char_u *fix_part, |
7 | 5136 #ifdef FEAT_PATH_EXTRA |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5137 char_u *wc_part, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5138 #endif |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5139 int level, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5140 int star_star_empty) |
7 | 5141 { |
5142 ff_stack_T *new; | |
5143 | |
5144 new = (ff_stack_T *)alloc((unsigned)sizeof(ff_stack_T)); | |
5145 if (new == NULL) | |
5146 return NULL; | |
5147 | |
5148 new->ffs_prev = NULL; | |
5149 new->ffs_filearray = NULL; | |
5150 new->ffs_filearray_size = 0; | |
5151 new->ffs_filearray_cur = 0; | |
5152 new->ffs_stage = 0; | |
5153 new->ffs_level = level; | |
5154 new->ffs_star_star_empty = star_star_empty;; | |
5155 | |
5156 /* the following saves NULL pointer checks in vim_findfile */ | |
5157 if (fix_part == NULL) | |
5158 fix_part = (char_u *)""; | |
5159 new->ffs_fix_path = vim_strsave(fix_part); | |
5160 | |
5161 #ifdef FEAT_PATH_EXTRA | |
5162 if (wc_part == NULL) | |
5163 wc_part = (char_u *)""; | |
5164 new->ffs_wc_path = vim_strsave(wc_part); | |
5165 #endif | |
5166 | |
5167 if (new->ffs_fix_path == NULL | |
5168 #ifdef FEAT_PATH_EXTRA | |
5169 || new->ffs_wc_path == NULL | |
5170 #endif | |
5171 ) | |
5172 { | |
5173 ff_free_stack_element(new); | |
5174 new = NULL; | |
5175 } | |
5176 | |
5177 return new; | |
5178 } | |
5179 | |
5180 /* | |
1541 | 5181 * Push a dir on the directory stack. |
7 | 5182 */ |
5183 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5184 ff_push(ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr) |
7 | 5185 { |
5186 /* check for NULL pointer, not to return an error to the user, but | |
359 | 5187 * to prevent a crash */ |
1541 | 5188 if (stack_ptr != NULL) |
7 | 5189 { |
1541 | 5190 stack_ptr->ffs_prev = search_ctx->ffsc_stack_ptr; |
5191 search_ctx->ffsc_stack_ptr = stack_ptr; | |
7 | 5192 } |
5193 } | |
5194 | |
5195 /* | |
1541 | 5196 * Pop a dir from the directory stack. |
5197 * Returns NULL if stack is empty. | |
7 | 5198 */ |
5199 static ff_stack_T * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5200 ff_pop(ff_search_ctx_T *search_ctx) |
7 | 5201 { |
5202 ff_stack_T *sptr; | |
5203 | |
1541 | 5204 sptr = search_ctx->ffsc_stack_ptr; |
5205 if (search_ctx->ffsc_stack_ptr != NULL) | |
5206 search_ctx->ffsc_stack_ptr = search_ctx->ffsc_stack_ptr->ffs_prev; | |
7 | 5207 |
5208 return sptr; | |
5209 } | |
5210 | |
5211 /* | |
5212 * free the given stack element | |
5213 */ | |
5214 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5215 ff_free_stack_element(ff_stack_T *stack_ptr) |
7 | 5216 { |
5217 /* vim_free handles possible NULL pointers */ | |
1541 | 5218 vim_free(stack_ptr->ffs_fix_path); |
7 | 5219 #ifdef FEAT_PATH_EXTRA |
1541 | 5220 vim_free(stack_ptr->ffs_wc_path); |
5221 #endif | |
5222 | |
5223 if (stack_ptr->ffs_filearray != NULL) | |
5224 FreeWild(stack_ptr->ffs_filearray_size, stack_ptr->ffs_filearray); | |
5225 | |
5226 vim_free(stack_ptr); | |
7 | 5227 } |
5228 | |
5229 /* | |
1541 | 5230 * Clear the search context, but NOT the visited list. |
7 | 5231 */ |
5232 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5233 ff_clear(ff_search_ctx_T *search_ctx) |
7 | 5234 { |
5235 ff_stack_T *sptr; | |
5236 | |
5237 /* clear up stack */ | |
1541 | 5238 while ((sptr = ff_pop(search_ctx)) != NULL) |
7 | 5239 ff_free_stack_element(sptr); |
5240 | |
1541 | 5241 vim_free(search_ctx->ffsc_file_to_search); |
5242 vim_free(search_ctx->ffsc_start_dir); | |
5243 vim_free(search_ctx->ffsc_fix_path); | |
7 | 5244 #ifdef FEAT_PATH_EXTRA |
1541 | 5245 vim_free(search_ctx->ffsc_wc_path); |
7 | 5246 #endif |
5247 | |
5248 #ifdef FEAT_PATH_EXTRA | |
1541 | 5249 if (search_ctx->ffsc_stopdirs_v != NULL) |
7 | 5250 { |
5251 int i = 0; | |
5252 | |
1541 | 5253 while (search_ctx->ffsc_stopdirs_v[i] != NULL) |
7 | 5254 { |
1541 | 5255 vim_free(search_ctx->ffsc_stopdirs_v[i]); |
7 | 5256 i++; |
5257 } | |
1541 | 5258 vim_free(search_ctx->ffsc_stopdirs_v); |
7 | 5259 } |
1541 | 5260 search_ctx->ffsc_stopdirs_v = NULL; |
7 | 5261 #endif |
5262 | |
5263 /* reset everything */ | |
1541 | 5264 search_ctx->ffsc_file_to_search = NULL; |
5265 search_ctx->ffsc_start_dir = NULL; | |
5266 search_ctx->ffsc_fix_path = NULL; | |
7 | 5267 #ifdef FEAT_PATH_EXTRA |
1541 | 5268 search_ctx->ffsc_wc_path = NULL; |
5269 search_ctx->ffsc_level = 0; | |
7 | 5270 #endif |
5271 } | |
5272 | |
5273 #ifdef FEAT_PATH_EXTRA | |
5274 /* | |
5275 * check if the given path is in the stopdirs | |
5276 * returns TRUE if yes else FALSE | |
5277 */ | |
5278 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5279 ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v) |
7 | 5280 { |
5281 int i = 0; | |
5282 | |
5283 /* eat up trailing path separators, except the first */ | |
461 | 5284 while (path_len > 1 && vim_ispathsep(path[path_len - 1])) |
7 | 5285 path_len--; |
5286 | |
5287 /* if no path consider it as match */ | |
5288 if (path_len == 0) | |
5289 return TRUE; | |
5290 | |
5291 for (i = 0; stopdirs_v[i] != NULL; i++) | |
5292 { | |
5293 if ((int)STRLEN(stopdirs_v[i]) > path_len) | |
5294 { | |
5295 /* match for parent directory. So '/home' also matches | |
5296 * '/home/rks'. Check for PATHSEP in stopdirs_v[i], else | |
5297 * '/home/r' would also match '/home/rks' | |
5298 */ | |
5299 if (fnamencmp(stopdirs_v[i], path, path_len) == 0 | |
461 | 5300 && vim_ispathsep(stopdirs_v[i][path_len])) |
7 | 5301 return TRUE; |
5302 } | |
5303 else | |
5304 { | |
5305 if (fnamecmp(stopdirs_v[i], path) == 0) | |
5306 return TRUE; | |
5307 } | |
5308 } | |
5309 return FALSE; | |
5310 } | |
5311 #endif | |
5312 | |
5313 #if defined(FEAT_SEARCHPATH) || defined(PROTO) | |
5314 /* | |
1541 | 5315 * Find the file name "ptr[len]" in the path. Also finds directory names. |
7 | 5316 * |
5317 * On the first call set the parameter 'first' to TRUE to initialize | |
5318 * the search. For repeating calls to FALSE. | |
5319 * | |
5320 * Repeating calls will return other files called 'ptr[len]' from the path. | |
5321 * | |
5322 * Only on the first call 'ptr' and 'len' are used. For repeating calls they | |
5323 * don't need valid values. | |
5324 * | |
5325 * If nothing found on the first call the option FNAME_MESS will issue the | |
5326 * message: | |
5327 * 'Can't find file "<file>" in path' | |
5328 * On repeating calls: | |
5329 * 'No more file "<file>" found in path' | |
5330 * | |
5331 * options: | |
5332 * FNAME_MESS give error message when not found | |
5333 * | |
5334 * Uses NameBuff[]! | |
5335 * | |
5336 * Returns an allocated string for the file name. NULL for error. | |
5337 * | |
5338 */ | |
5339 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5340 find_file_in_path( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5341 char_u *ptr, /* file name */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5342 int len, /* length of file name */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5343 int options, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5344 int first, /* use count'th matching file name */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5345 char_u *rel_fname) /* file name searching relative to */ |
7 | 5346 { |
5347 return find_file_in_path_option(ptr, len, options, first, | |
5348 *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path, | |
1541 | 5349 FINDFILE_BOTH, rel_fname, curbuf->b_p_sua); |
7 | 5350 } |
5351 | |
359 | 5352 static char_u *ff_file_to_find = NULL; |
5353 static void *fdip_search_ctx = NULL; | |
5354 | |
5355 #if defined(EXITFREE) | |
5356 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5357 free_findfile(void) |
359 | 5358 { |
5359 vim_free(ff_file_to_find); | |
5360 vim_findfile_cleanup(fdip_search_ctx); | |
5361 } | |
5362 #endif | |
5363 | |
7 | 5364 /* |
5365 * Find the directory name "ptr[len]" in the path. | |
5366 * | |
5367 * options: | |
5368 * FNAME_MESS give error message when not found | |
6633 | 5369 * FNAME_UNESC unescape backslashes. |
7 | 5370 * |
5371 * Uses NameBuff[]! | |
5372 * | |
5373 * Returns an allocated string for the file name. NULL for error. | |
5374 */ | |
5375 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5376 find_directory_in_path( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5377 char_u *ptr, /* file name */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5378 int len, /* length of file name */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5379 int options, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5380 char_u *rel_fname) /* file name searching relative to */ |
7 | 5381 { |
5382 return find_file_in_path_option(ptr, len, options, TRUE, p_cdpath, | |
1541 | 5383 FINDFILE_DIR, rel_fname, (char_u *)""); |
7 | 5384 } |
5385 | |
19 | 5386 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5387 find_file_in_path_option( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5388 char_u *ptr, /* file name */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5389 int len, /* length of file name */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5390 int options, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5391 int first, /* use count'th matching file name */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5392 char_u *path_option, /* p_path or p_cdpath */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5393 int find_what, /* FINDFILE_FILE, _DIR or _BOTH */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5394 char_u *rel_fname, /* file name we are looking relative to. */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5395 char_u *suffixes) /* list of suffixes, 'suffixesadd' option */ |
7 | 5396 { |
5397 static char_u *dir; | |
5398 static int did_findfile_init = FALSE; | |
5399 char_u save_char; | |
5400 char_u *file_name = NULL; | |
5401 char_u *buf = NULL; | |
5402 int rel_to_curdir; | |
5403 #ifdef AMIGA | |
5404 struct Process *proc = (struct Process *)FindTask(0L); | |
5405 APTR save_winptr = proc->pr_WindowPtr; | |
5406 | |
5407 /* Avoid a requester here for a volume that doesn't exist. */ | |
5408 proc->pr_WindowPtr = (APTR)-1L; | |
5409 #endif | |
5410 | |
5411 if (first == TRUE) | |
5412 { | |
5413 /* copy file name into NameBuff, expanding environment variables */ | |
5414 save_char = ptr[len]; | |
5415 ptr[len] = NUL; | |
7617
80bc36419c21
commit https://github.com/vim/vim/commit/58adb14739fa240ca6020cede9ab1f1cb07bd90a
Christian Brabandt <cb@256bit.org>
parents:
7593
diff
changeset
|
5416 expand_env_esc(ptr, NameBuff, MAXPATHL, FALSE, TRUE, NULL); |
7 | 5417 ptr[len] = save_char; |
5418 | |
359 | 5419 vim_free(ff_file_to_find); |
5420 ff_file_to_find = vim_strsave(NameBuff); | |
5421 if (ff_file_to_find == NULL) /* out of memory */ | |
7 | 5422 { |
5423 file_name = NULL; | |
5424 goto theend; | |
5425 } | |
6633 | 5426 if (options & FNAME_UNESC) |
5427 { | |
5428 /* Change all "\ " to " ". */ | |
5429 for (ptr = ff_file_to_find; *ptr != NUL; ++ptr) | |
5430 if (ptr[0] == '\\' && ptr[1] == ' ') | |
5431 mch_memmove(ptr, ptr + 1, STRLEN(ptr)); | |
5432 } | |
7 | 5433 } |
5434 | |
359 | 5435 rel_to_curdir = (ff_file_to_find[0] == '.' |
5436 && (ff_file_to_find[1] == NUL | |
5437 || vim_ispathsep(ff_file_to_find[1]) | |
5438 || (ff_file_to_find[1] == '.' | |
5439 && (ff_file_to_find[2] == NUL | |
5440 || vim_ispathsep(ff_file_to_find[2]))))); | |
5441 if (vim_isAbsName(ff_file_to_find) | |
7 | 5442 /* "..", "../path", "." and "./path": don't use the path_option */ |
5443 || rel_to_curdir | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8174
diff
changeset
|
5444 #if defined(MSWIN) |
7 | 5445 /* handle "\tmp" as absolute path */ |
359 | 5446 || vim_ispathsep(ff_file_to_find[0]) |
1993 | 5447 /* handle "c:name" as absolute path */ |
359 | 5448 || (ff_file_to_find[0] != NUL && ff_file_to_find[1] == ':') |
7 | 5449 #endif |
5450 #ifdef AMIGA | |
5451 /* handle ":tmp" as absolute path */ | |
359 | 5452 || ff_file_to_find[0] == ':' |
7 | 5453 #endif |
5454 ) | |
5455 { | |
5456 /* | |
5457 * Absolute path, no need to use "path_option". | |
5458 * If this is not a first call, return NULL. We already returned a | |
5459 * filename on the first call. | |
5460 */ | |
5461 if (first == TRUE) | |
5462 { | |
5463 int l; | |
5464 int run; | |
5465 | |
359 | 5466 if (path_with_url(ff_file_to_find)) |
7 | 5467 { |
359 | 5468 file_name = vim_strsave(ff_file_to_find); |
7 | 5469 goto theend; |
5470 } | |
5471 | |
5472 /* When FNAME_REL flag given first use the directory of the file. | |
5473 * Otherwise or when this fails use the current directory. */ | |
5474 for (run = 1; run <= 2; ++run) | |
5475 { | |
359 | 5476 l = (int)STRLEN(ff_file_to_find); |
7 | 5477 if (run == 1 |
5478 && rel_to_curdir | |
5479 && (options & FNAME_REL) | |
5480 && rel_fname != NULL | |
5481 && STRLEN(rel_fname) + l < MAXPATHL) | |
5482 { | |
5483 STRCPY(NameBuff, rel_fname); | |
359 | 5484 STRCPY(gettail(NameBuff), ff_file_to_find); |
7 | 5485 l = (int)STRLEN(NameBuff); |
5486 } | |
5487 else | |
5488 { | |
359 | 5489 STRCPY(NameBuff, ff_file_to_find); |
7 | 5490 run = 2; |
5491 } | |
5492 | |
5493 /* When the file doesn't exist, try adding parts of | |
5494 * 'suffixesadd'. */ | |
794 | 5495 buf = suffixes; |
7 | 5496 for (;;) |
5497 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8174
diff
changeset
|
5498 if (mch_getperm(NameBuff) >= 0 |
1541 | 5499 && (find_what == FINDFILE_BOTH |
5500 || ((find_what == FINDFILE_DIR) | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8174
diff
changeset
|
5501 == mch_isdir(NameBuff)))) |
7 | 5502 { |
5503 file_name = vim_strsave(NameBuff); | |
5504 goto theend; | |
5505 } | |
5506 if (*buf == NUL) | |
5507 break; | |
5508 copy_option_part(&buf, NameBuff + l, MAXPATHL - l, ","); | |
5509 } | |
5510 } | |
5511 } | |
5512 } | |
5513 else | |
5514 { | |
5515 /* | |
5516 * Loop over all paths in the 'path' or 'cdpath' option. | |
5517 * When "first" is set, first setup to the start of the option. | |
5518 * Otherwise continue to find the next match. | |
5519 */ | |
5520 if (first == TRUE) | |
5521 { | |
5522 /* vim_findfile_free_visited can handle a possible NULL pointer */ | |
359 | 5523 vim_findfile_free_visited(fdip_search_ctx); |
7 | 5524 dir = path_option; |
5525 did_findfile_init = FALSE; | |
5526 } | |
5527 | |
5528 for (;;) | |
5529 { | |
5530 if (did_findfile_init) | |
5531 { | |
359 | 5532 file_name = vim_findfile(fdip_search_ctx); |
7 | 5533 if (file_name != NULL) |
5534 break; | |
5535 | |
5536 did_findfile_init = FALSE; | |
5537 } | |
5538 else | |
5539 { | |
5540 char_u *r_ptr; | |
5541 | |
5542 if (dir == NULL || *dir == NUL) | |
5543 { | |
5544 /* We searched all paths of the option, now we can | |
5545 * free the search context. */ | |
359 | 5546 vim_findfile_cleanup(fdip_search_ctx); |
5547 fdip_search_ctx = NULL; | |
7 | 5548 break; |
5549 } | |
5550 | |
5551 if ((buf = alloc((int)(MAXPATHL))) == NULL) | |
5552 break; | |
5553 | |
5554 /* copy next path */ | |
5555 buf[0] = 0; | |
5556 copy_option_part(&dir, buf, MAXPATHL, " ,"); | |
5557 | |
5558 #ifdef FEAT_PATH_EXTRA | |
5559 /* get the stopdir string */ | |
5560 r_ptr = vim_findfile_stopdir(buf); | |
5561 #else | |
5562 r_ptr = NULL; | |
5563 #endif | |
359 | 5564 fdip_search_ctx = vim_findfile_init(buf, ff_file_to_find, |
1541 | 5565 r_ptr, 100, FALSE, find_what, |
359 | 5566 fdip_search_ctx, FALSE, rel_fname); |
5567 if (fdip_search_ctx != NULL) | |
7 | 5568 did_findfile_init = TRUE; |
5569 vim_free(buf); | |
5570 } | |
5571 } | |
5572 } | |
5573 if (file_name == NULL && (options & FNAME_MESS)) | |
5574 { | |
5575 if (first == TRUE) | |
5576 { | |
1541 | 5577 if (find_what == FINDFILE_DIR) |
7 | 5578 EMSG2(_("E344: Can't find directory \"%s\" in cdpath"), |
359 | 5579 ff_file_to_find); |
7 | 5580 else |
5581 EMSG2(_("E345: Can't find file \"%s\" in path"), | |
359 | 5582 ff_file_to_find); |
7 | 5583 } |
5584 else | |
5585 { | |
1541 | 5586 if (find_what == FINDFILE_DIR) |
7 | 5587 EMSG2(_("E346: No more directory \"%s\" found in cdpath"), |
359 | 5588 ff_file_to_find); |
7 | 5589 else |
5590 EMSG2(_("E347: No more file \"%s\" found in path"), | |
359 | 5591 ff_file_to_find); |
7 | 5592 } |
5593 } | |
5594 | |
5595 theend: | |
5596 #ifdef AMIGA | |
5597 proc->pr_WindowPtr = save_winptr; | |
5598 #endif | |
5599 return file_name; | |
5600 } | |
5601 | |
5602 #endif /* FEAT_SEARCHPATH */ | |
5603 | |
5604 /* | |
5605 * Change directory to "new_dir". If FEAT_SEARCHPATH is defined, search | |
5606 * 'cdpath' for relative directory names, otherwise just mch_chdir(). | |
5607 */ | |
5608 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5609 vim_chdir(char_u *new_dir) |
7 | 5610 { |
5611 #ifndef FEAT_SEARCHPATH | |
5612 return mch_chdir((char *)new_dir); | |
5613 #else | |
5614 char_u *dir_name; | |
5615 int r; | |
5616 | |
5617 dir_name = find_directory_in_path(new_dir, (int)STRLEN(new_dir), | |
5618 FNAME_MESS, curbuf->b_ffname); | |
5619 if (dir_name == NULL) | |
5620 return -1; | |
5621 r = mch_chdir((char *)dir_name); | |
5622 vim_free(dir_name); | |
5623 return r; | |
5624 #endif | |
5625 } | |
5626 | |
5627 /* | |
418 | 5628 * Get user name from machine-specific function. |
7 | 5629 * Returns the user name in "buf[len]". |
418 | 5630 * Some systems are quite slow in obtaining the user name (Windows NT), thus |
5631 * cache the result. | |
7 | 5632 * Returns OK or FAIL. |
5633 */ | |
5634 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5635 get_user_name(char_u *buf, int len) |
7 | 5636 { |
359 | 5637 if (username == NULL) |
7 | 5638 { |
5639 if (mch_get_user_name(buf, len) == FAIL) | |
5640 return FAIL; | |
359 | 5641 username = vim_strsave(buf); |
7 | 5642 } |
5643 else | |
418 | 5644 vim_strncpy(buf, username, len - 1); |
7 | 5645 return OK; |
5646 } | |
5647 | |
5648 #ifndef HAVE_QSORT | |
5649 /* | |
5650 * Our own qsort(), for systems that don't have it. | |
5651 * It's simple and slow. From the K&R C book. | |
5652 */ | |
5653 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5654 qsort( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5655 void *base, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5656 size_t elm_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5657 size_t elm_size, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5658 int (*cmp)(const void *, const void *)) |
7 | 5659 { |
5660 char_u *buf; | |
5661 char_u *p1; | |
5662 char_u *p2; | |
5663 int i, j; | |
5664 int gap; | |
5665 | |
5666 buf = alloc((unsigned)elm_size); | |
5667 if (buf == NULL) | |
5668 return; | |
5669 | |
5670 for (gap = elm_count / 2; gap > 0; gap /= 2) | |
5671 for (i = gap; i < elm_count; ++i) | |
5672 for (j = i - gap; j >= 0; j -= gap) | |
5673 { | |
5674 /* Compare the elements. */ | |
5675 p1 = (char_u *)base + j * elm_size; | |
5676 p2 = (char_u *)base + (j + gap) * elm_size; | |
5677 if ((*cmp)((void *)p1, (void *)p2) <= 0) | |
5678 break; | |
1993 | 5679 /* Exchange the elements. */ |
7 | 5680 mch_memmove(buf, p1, elm_size); |
5681 mch_memmove(p1, p2, elm_size); | |
5682 mch_memmove(p2, buf, elm_size); | |
5683 } | |
5684 | |
5685 vim_free(buf); | |
5686 } | |
5687 #endif | |
5688 | |
5689 /* | |
5690 * Sort an array of strings. | |
5691 */ | |
5692 static int | |
5693 #ifdef __BORLANDC__ | |
5694 _RTLENTRYF | |
5695 #endif | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
5696 sort_compare(const void *s1, const void *s2); |
7 | 5697 |
5698 static int | |
5699 #ifdef __BORLANDC__ | |
5700 _RTLENTRYF | |
5701 #endif | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5702 sort_compare(const void *s1, const void *s2) |
7 | 5703 { |
5704 return STRCMP(*(char **)s1, *(char **)s2); | |
5705 } | |
5706 | |
5707 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5708 sort_strings( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5709 char_u **files, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5710 int count) |
7 | 5711 { |
5712 qsort((void *)files, (size_t)count, sizeof(char_u *), sort_compare); | |
5713 } | |
5714 | |
5715 #if !defined(NO_EXPANDPATH) || defined(PROTO) | |
5716 /* | |
5717 * Compare path "p[]" to "q[]". | |
39 | 5718 * If "maxlen" >= 0 compare "p[maxlen]" to "q[maxlen]" |
7 | 5719 * Return value like strcmp(p, q), but consider path separators. |
5720 */ | |
5721 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5722 pathcmp(const char *p, const char *q, int maxlen) |
7 | 5723 { |
7044
7758d6245c3a
commit https://github.com/vim/vim/commit/f6470c288cb6f8efd60a507baf2c070f9d209ae6
Christian Brabandt <cb@256bit.org>
parents:
6929
diff
changeset
|
5724 int i, j; |
4276 | 5725 int c1, c2; |
41 | 5726 const char *s = NULL; |
7 | 5727 |
7044
7758d6245c3a
commit https://github.com/vim/vim/commit/f6470c288cb6f8efd60a507baf2c070f9d209ae6
Christian Brabandt <cb@256bit.org>
parents:
6929
diff
changeset
|
5728 for (i = 0, j = 0; maxlen < 0 || (i < maxlen && j < maxlen);) |
7 | 5729 { |
4276 | 5730 c1 = PTR2CHAR((char_u *)p + i); |
7044
7758d6245c3a
commit https://github.com/vim/vim/commit/f6470c288cb6f8efd60a507baf2c070f9d209ae6
Christian Brabandt <cb@256bit.org>
parents:
6929
diff
changeset
|
5731 c2 = PTR2CHAR((char_u *)q + j); |
4276 | 5732 |
7 | 5733 /* End of "p": check if "q" also ends or just has a slash. */ |
4276 | 5734 if (c1 == NUL) |
7 | 5735 { |
4276 | 5736 if (c2 == NUL) /* full match */ |
7 | 5737 return 0; |
5738 s = q; | |
7044
7758d6245c3a
commit https://github.com/vim/vim/commit/f6470c288cb6f8efd60a507baf2c070f9d209ae6
Christian Brabandt <cb@256bit.org>
parents:
6929
diff
changeset
|
5739 i = j; |
7 | 5740 break; |
5741 } | |
5742 | |
5743 /* End of "q": check if "p" just has a slash. */ | |
4276 | 5744 if (c2 == NUL) |
7 | 5745 { |
5746 s = p; | |
5747 break; | |
5748 } | |
5749 | |
4276 | 5750 if ((p_fic ? MB_TOUPPER(c1) != MB_TOUPPER(c2) : c1 != c2) |
7 | 5751 #ifdef BACKSLASH_IN_FILENAME |
5752 /* consider '/' and '\\' to be equal */ | |
4276 | 5753 && !((c1 == '/' && c2 == '\\') |
5754 || (c1 == '\\' && c2 == '/')) | |
7 | 5755 #endif |
5756 ) | |
5757 { | |
4276 | 5758 if (vim_ispathsep(c1)) |
7 | 5759 return -1; |
4276 | 5760 if (vim_ispathsep(c2)) |
7 | 5761 return 1; |
4276 | 5762 return p_fic ? MB_TOUPPER(c1) - MB_TOUPPER(c2) |
5763 : c1 - c2; /* no match */ | |
7 | 5764 } |
7044
7758d6245c3a
commit https://github.com/vim/vim/commit/f6470c288cb6f8efd60a507baf2c070f9d209ae6
Christian Brabandt <cb@256bit.org>
parents:
6929
diff
changeset
|
5765 |
7758d6245c3a
commit https://github.com/vim/vim/commit/f6470c288cb6f8efd60a507baf2c070f9d209ae6
Christian Brabandt <cb@256bit.org>
parents:
6929
diff
changeset
|
5766 i += MB_PTR2LEN((char_u *)p + i); |
7758d6245c3a
commit https://github.com/vim/vim/commit/f6470c288cb6f8efd60a507baf2c070f9d209ae6
Christian Brabandt <cb@256bit.org>
parents:
6929
diff
changeset
|
5767 j += MB_PTR2LEN((char_u *)q + j); |
7 | 5768 } |
7044
7758d6245c3a
commit https://github.com/vim/vim/commit/f6470c288cb6f8efd60a507baf2c070f9d209ae6
Christian Brabandt <cb@256bit.org>
parents:
6929
diff
changeset
|
5769 if (s == NULL) /* "i" or "j" ran into "maxlen" */ |
41 | 5770 return 0; |
7 | 5771 |
4276 | 5772 c1 = PTR2CHAR((char_u *)s + i); |
5773 c2 = PTR2CHAR((char_u *)s + i + MB_PTR2LEN((char_u *)s + i)); | |
7 | 5774 /* ignore a trailing slash, but not "//" or ":/" */ |
4276 | 5775 if (c2 == NUL |
41 | 5776 && i > 0 |
5777 && !after_pathsep((char_u *)s, (char_u *)s + i) | |
7 | 5778 #ifdef BACKSLASH_IN_FILENAME |
4276 | 5779 && (c1 == '/' || c1 == '\\') |
7 | 5780 #else |
4276 | 5781 && c1 == '/' |
7 | 5782 #endif |
41 | 5783 ) |
7 | 5784 return 0; /* match with trailing slash */ |
5785 if (s == q) | |
5786 return -1; /* no match */ | |
5787 return 1; | |
5788 } | |
5789 #endif | |
5790 | |
5791 /* | |
5792 * The putenv() implementation below comes from the "screen" program. | |
5793 * Included with permission from Juergen Weigert. | |
5794 * See pty.c for the copyright notice. | |
5795 */ | |
5796 | |
5797 /* | |
5798 * putenv -- put value into environment | |
5799 * | |
5800 * Usage: i = putenv (string) | |
5801 * int i; | |
5802 * char *string; | |
5803 * | |
5804 * where string is of the form <name>=<value>. | |
5805 * Putenv returns 0 normally, -1 on error (not enough core for malloc). | |
5806 * | |
5807 * Putenv may need to add a new name into the environment, or to | |
5808 * associate a value longer than the current value with a particular | |
5809 * name. So, to make life simpler, putenv() copies your entire | |
5810 * environment into the heap (i.e. malloc()) from the stack | |
5811 * (i.e. where it resides when your process is initiated) the first | |
5812 * time you call it. | |
5813 * | |
5814 * (history removed, not very interesting. See the "screen" sources.) | |
5815 */ | |
5816 | |
5817 #if !defined(HAVE_SETENV) && !defined(HAVE_PUTENV) | |
5818 | |
5819 #define EXTRASIZE 5 /* increment to add to env. size */ | |
5820 | |
5821 static int envsize = -1; /* current size of environment */ | |
5822 #ifndef MACOS_CLASSIC | |
5823 extern | |
5824 #endif | |
5825 char **environ; /* the global which is your env. */ | |
5826 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
5827 static int findenv(char *name); /* look for a name in the env. */ |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
5828 static int newenv(void); /* copy env. from stack to heap */ |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
5829 static int moreenv(void); /* incr. size of env. */ |
7 | 5830 |
5831 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5832 putenv(const char *string) |
7 | 5833 { |
5834 int i; | |
5835 char *p; | |
5836 | |
5837 if (envsize < 0) | |
5838 { /* first time putenv called */ | |
5839 if (newenv() < 0) /* copy env. to heap */ | |
5840 return -1; | |
5841 } | |
5842 | |
5843 i = findenv((char *)string); /* look for name in environment */ | |
5844 | |
5845 if (i < 0) | |
5846 { /* name must be added */ | |
5847 for (i = 0; environ[i]; i++); | |
5848 if (i >= (envsize - 1)) | |
5849 { /* need new slot */ | |
5850 if (moreenv() < 0) | |
5851 return -1; | |
5852 } | |
5853 p = (char *)alloc((unsigned)(strlen(string) + 1)); | |
5854 if (p == NULL) /* not enough core */ | |
5855 return -1; | |
5856 environ[i + 1] = 0; /* new end of env. */ | |
5857 } | |
5858 else | |
5859 { /* name already in env. */ | |
5860 p = vim_realloc(environ[i], strlen(string) + 1); | |
5861 if (p == NULL) | |
5862 return -1; | |
5863 } | |
5864 sprintf(p, "%s", string); /* copy into env. */ | |
5865 environ[i] = p; | |
5866 | |
5867 return 0; | |
5868 } | |
5869 | |
5870 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5871 findenv(char *name) |
7 | 5872 { |
5873 char *namechar, *envchar; | |
5874 int i, found; | |
5875 | |
5876 found = 0; | |
5877 for (i = 0; environ[i] && !found; i++) | |
5878 { | |
5879 envchar = environ[i]; | |
5880 namechar = name; | |
5881 while (*namechar && *namechar != '=' && (*namechar == *envchar)) | |
5882 { | |
5883 namechar++; | |
5884 envchar++; | |
5885 } | |
5886 found = ((*namechar == '\0' || *namechar == '=') && *envchar == '='); | |
5887 } | |
5888 return found ? i - 1 : -1; | |
5889 } | |
5890 | |
5891 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5892 newenv(void) |
7 | 5893 { |
5894 char **env, *elem; | |
5895 int i, esize; | |
5896 | |
5897 #ifdef MACOS | |
5898 /* for Mac a new, empty environment is created */ | |
5899 i = 0; | |
5900 #else | |
5901 for (i = 0; environ[i]; i++) | |
5902 ; | |
5903 #endif | |
5904 esize = i + EXTRASIZE + 1; | |
5905 env = (char **)alloc((unsigned)(esize * sizeof (elem))); | |
5906 if (env == NULL) | |
5907 return -1; | |
5908 | |
5909 #ifndef MACOS | |
5910 for (i = 0; environ[i]; i++) | |
5911 { | |
5912 elem = (char *)alloc((unsigned)(strlen(environ[i]) + 1)); | |
5913 if (elem == NULL) | |
5914 return -1; | |
5915 env[i] = elem; | |
5916 strcpy(elem, environ[i]); | |
5917 } | |
5918 #endif | |
5919 | |
5920 env[i] = 0; | |
5921 environ = env; | |
5922 envsize = esize; | |
5923 return 0; | |
5924 } | |
5925 | |
5926 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5927 moreenv(void) |
7 | 5928 { |
5929 int esize; | |
5930 char **env; | |
5931 | |
5932 esize = envsize + EXTRASIZE; | |
5933 env = (char **)vim_realloc((char *)environ, esize * sizeof (*env)); | |
5934 if (env == 0) | |
5935 return -1; | |
5936 environ = env; | |
5937 envsize = esize; | |
5938 return 0; | |
5939 } | |
5940 | |
5941 # ifdef USE_VIMPTY_GETENV | |
5942 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5943 vimpty_getenv(const char_u *string) |
7 | 5944 { |
5945 int i; | |
5946 char_u *p; | |
5947 | |
5948 if (envsize < 0) | |
5949 return NULL; | |
5950 | |
5951 i = findenv((char *)string); | |
5952 | |
5953 if (i < 0) | |
5954 return NULL; | |
5955 | |
5956 p = vim_strchr((char_u *)environ[i], '='); | |
5957 return (p + 1); | |
5958 } | |
5959 # endif | |
5960 | |
5961 #endif /* !defined(HAVE_SETENV) && !defined(HAVE_PUTENV) */ | |
313 | 5962 |
741 | 5963 #if defined(FEAT_EVAL) || defined(FEAT_SPELL) || defined(PROTO) |
313 | 5964 /* |
5965 * Return 0 for not writable, 1 for writable file, 2 for a dir which we have | |
5966 * rights to write into. | |
5967 */ | |
5968 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5969 filewritable(char_u *fname) |
313 | 5970 { |
5971 int retval = 0; | |
5972 #if defined(UNIX) || defined(VMS) | |
5973 int perm = 0; | |
5974 #endif | |
5975 | |
5976 #if defined(UNIX) || defined(VMS) | |
5977 perm = mch_getperm(fname); | |
5978 #endif | |
5979 #ifndef MACOS_CLASSIC /* TODO: get either mch_writable or mch_access */ | |
5980 if ( | |
5981 # ifdef WIN3264 | |
5982 mch_writable(fname) && | |
5983 # else | |
5984 # if defined(UNIX) || defined(VMS) | |
5985 (perm & 0222) && | |
5986 # endif | |
5987 # endif | |
5988 mch_access((char *)fname, W_OK) == 0 | |
5989 ) | |
5990 #endif | |
5991 { | |
5992 ++retval; | |
5993 if (mch_isdir(fname)) | |
5994 ++retval; | |
5995 } | |
5996 return retval; | |
5997 } | |
5998 #endif | |
332 | 5999 |
6000 /* | |
6001 * Print an error message with one or two "%s" and one or two string arguments. | |
6002 * This is not in message.c to avoid a warning for prototypes. | |
6003 */ | |
6004 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6005 emsg3(char_u *s, char_u *a1, char_u *a2) |
332 | 6006 { |
840 | 6007 if (emsg_not_now()) |
332 | 6008 return TRUE; /* no error messages at the moment */ |
1438 | 6009 vim_snprintf((char *)IObuff, IOSIZE, (char *)s, a1, a2); |
332 | 6010 return emsg(IObuff); |
6011 } | |
6012 | |
6013 /* | |
6014 * Print an error message with one "%ld" and one long int argument. | |
6015 * This is not in message.c to avoid a warning for prototypes. | |
6016 */ | |
6017 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6018 emsgn(char_u *s, long n) |
332 | 6019 { |
840 | 6020 if (emsg_not_now()) |
332 | 6021 return TRUE; /* no error messages at the moment */ |
6022 vim_snprintf((char *)IObuff, IOSIZE, (char *)s, n); | |
6023 return emsg(IObuff); | |
6024 } | |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6025 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6026 #if defined(FEAT_SPELL) || defined(FEAT_PERSISTENT_UNDO) || defined(PROTO) |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6027 /* |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6028 * Read 2 bytes from "fd" and turn them into an int, MSB first. |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6029 */ |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6030 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6031 get2c(FILE *fd) |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6032 { |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
6033 int n; |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6034 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6035 n = getc(fd); |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6036 n = (n << 8) + getc(fd); |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6037 return n; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6038 } |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6039 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6040 /* |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6041 * Read 3 bytes from "fd" and turn them into an int, MSB first. |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6042 */ |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6043 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6044 get3c(FILE *fd) |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6045 { |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
6046 int n; |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6047 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6048 n = getc(fd); |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6049 n = (n << 8) + getc(fd); |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6050 n = (n << 8) + getc(fd); |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6051 return n; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6052 } |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6053 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6054 /* |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6055 * Read 4 bytes from "fd" and turn them into an int, MSB first. |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6056 */ |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6057 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6058 get4c(FILE *fd) |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6059 { |
5347 | 6060 /* Use unsigned rather than int otherwise result is undefined |
6061 * when left-shift sets the MSB. */ | |
6062 unsigned n; | |
6063 | |
6064 n = (unsigned)getc(fd); | |
6065 n = (n << 8) + (unsigned)getc(fd); | |
6066 n = (n << 8) + (unsigned)getc(fd); | |
6067 n = (n << 8) + (unsigned)getc(fd); | |
6068 return (int)n; | |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6069 } |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6070 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6071 /* |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6072 * Read 8 bytes from "fd" and turn them into a time_t, MSB first. |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6073 */ |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6074 time_t |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6075 get8ctime(FILE *fd) |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6076 { |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6077 time_t n = 0; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6078 int i; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6079 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6080 for (i = 0; i < 8; ++i) |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6081 n = (n << 8) + getc(fd); |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6082 return n; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6083 } |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6084 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6085 /* |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6086 * Read a string of length "cnt" from "fd" into allocated memory. |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6087 * Returns NULL when out of memory or unable to read that many bytes. |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6088 */ |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6089 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6090 read_string(FILE *fd, int cnt) |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6091 { |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6092 char_u *str; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6093 int i; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6094 int c; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6095 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6096 /* allocate memory */ |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6097 str = alloc((unsigned)cnt + 1); |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6098 if (str != NULL) |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6099 { |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6100 /* Read the string. Quit when running into the EOF. */ |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6101 for (i = 0; i < cnt; ++i) |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6102 { |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6103 c = getc(fd); |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6104 if (c == EOF) |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6105 { |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6106 vim_free(str); |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6107 return NULL; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6108 } |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6109 str[i] = c; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6110 } |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6111 str[i] = NUL; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6112 } |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6113 return str; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6114 } |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6115 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6116 /* |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6117 * Write a number to file "fd", MSB first, in "len" bytes. |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6118 */ |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6119 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6120 put_bytes(FILE *fd, long_u nr, int len) |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6121 { |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6122 int i; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6123 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6124 for (i = len - 1; i >= 0; --i) |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6125 if (putc((int)(nr >> (i * 8)), fd) == EOF) |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6126 return FAIL; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6127 return OK; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6128 } |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6129 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6130 #ifdef _MSC_VER |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6131 # if (_MSC_VER <= 1200) |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6132 /* This line is required for VC6 without the service pack. Also see the |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6133 * matching #pragma below. */ |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6134 # pragma optimize("", off) |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6135 # endif |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6136 #endif |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6137 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6138 /* |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6139 * Write time_t to file "fd" in 8 bytes. |
7519
98fede2c9574
commit https://github.com/vim/vim/commit/285bf84b4b9aca828828a8729b04cd59ab333dac
Christian Brabandt <cb@256bit.org>
parents:
7513
diff
changeset
|
6140 * Returns FAIL when the write failed. |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6141 */ |
7519
98fede2c9574
commit https://github.com/vim/vim/commit/285bf84b4b9aca828828a8729b04cd59ab333dac
Christian Brabandt <cb@256bit.org>
parents:
7513
diff
changeset
|
6142 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6143 put_time(FILE *fd, time_t the_time) |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6144 { |
6122 | 6145 char_u buf[8]; |
6146 | |
6147 time_to_bytes(the_time, buf); | |
7519
98fede2c9574
commit https://github.com/vim/vim/commit/285bf84b4b9aca828828a8729b04cd59ab333dac
Christian Brabandt <cb@256bit.org>
parents:
7513
diff
changeset
|
6148 return fwrite(buf, (size_t)8, (size_t)1, fd) == 1 ? OK : FAIL; |
6122 | 6149 } |
6150 | |
6151 /* | |
6152 * Write time_t to "buf[8]". | |
6153 */ | |
6154 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6155 time_to_bytes(time_t the_time, char_u *buf) |
6122 | 6156 { |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6157 int c; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6158 int i; |
6122 | 6159 int bi = 0; |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6160 time_t wtime = the_time; |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6161 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6162 /* time_t can be up to 8 bytes in size, more than long_u, thus we |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6163 * can't use put_bytes() here. |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6164 * Another problem is that ">>" may do an arithmetic shift that keeps the |
2232
2e6906bbc5f4
A few more fixes for undo file. Split test in two parts so that it doesn't
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
6165 * sign. This happens for large values of wtime. A cast to long_u may |
2e6906bbc5f4
A few more fixes for undo file. Split test in two parts so that it doesn't
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
6166 * truncate if time_t is 8 bytes. So only use a cast when it is 4 bytes, |
2e6906bbc5f4
A few more fixes for undo file. Split test in two parts so that it doesn't
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
6167 * it's safe to assume that long_u is 4 bytes or more and when using 8 |
2e6906bbc5f4
A few more fixes for undo file. Split test in two parts so that it doesn't
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
6168 * bytes the top bit won't be set. */ |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6169 for (i = 7; i >= 0; --i) |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6170 { |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6171 if (i + 1 > (int)sizeof(time_t)) |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6172 /* ">>" doesn't work well when shifting more bits than avail */ |
6122 | 6173 buf[bi++] = 0; |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6174 else |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6175 { |
2232
2e6906bbc5f4
A few more fixes for undo file. Split test in two parts so that it doesn't
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
6176 #if defined(SIZEOF_TIME_T) && SIZEOF_TIME_T > 4 |
2245
4e0124f5aee2
Optimize the blowfish crypt/decrypt code a bit more.
Bram Moolenaar <bram@vim.org>
parents:
2244
diff
changeset
|
6177 c = (int)(wtime >> (i * 8)); |
2232
2e6906bbc5f4
A few more fixes for undo file. Split test in two parts so that it doesn't
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
6178 #else |
2245
4e0124f5aee2
Optimize the blowfish crypt/decrypt code a bit more.
Bram Moolenaar <bram@vim.org>
parents:
2244
diff
changeset
|
6179 c = (int)((long_u)wtime >> (i * 8)); |
2232
2e6906bbc5f4
A few more fixes for undo file. Split test in two parts so that it doesn't
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
6180 #endif |
6122 | 6181 buf[bi++] = c; |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6182 } |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6183 } |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6184 } |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6185 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6186 #ifdef _MSC_VER |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6187 # if (_MSC_VER <= 1200) |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6188 # pragma optimize("", on) |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6189 # endif |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6190 #endif |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6191 |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6192 #endif |
3257 | 6193 |
6194 #if (defined(FEAT_MBYTE) && defined(FEAT_QUICKFIX)) \ | |
6195 || defined(FEAT_SPELL) || defined(PROTO) | |
6196 /* | |
6197 * Return TRUE if string "s" contains a non-ASCII character (128 or higher). | |
6198 * When "s" is NULL FALSE is returned. | |
6199 */ | |
6200 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6201 has_non_ascii(char_u *s) |
3257 | 6202 { |
6203 char_u *p; | |
6204 | |
6205 if (s != NULL) | |
6206 for (p = s; *p != NUL; ++p) | |
6207 if (*p >= 128) | |
6208 return TRUE; | |
6209 return FALSE; | |
6210 } | |
6211 #endif | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6212 |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6213 #if defined(MESSAGE_QUEUE) || defined(PROTO) |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6214 /* |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6215 * Process messages that have been queued for netbeans or clientserver. |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6216 * These functions can call arbitrary vimscript and should only be called when |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6217 * it is safe to do so. |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6218 */ |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6219 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6220 parse_queued_messages(void) |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6221 { |
8172
db5c79d93eee
commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents:
8140
diff
changeset
|
6222 /* For Win32 mch_breakcheck() does not check for input, do it here. */ |
db5c79d93eee
commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents:
8140
diff
changeset
|
6223 # if defined(WIN32) && defined(FEAT_CHANNEL) |
db5c79d93eee
commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents:
8140
diff
changeset
|
6224 channel_handle_events(); |
db5c79d93eee
commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents:
8140
diff
changeset
|
6225 # endif |
db5c79d93eee
commit https://github.com/vim/vim/commit/b7522a2f0ca6c970df37241c9e70024465d8596b
Christian Brabandt <cb@256bit.org>
parents:
8140
diff
changeset
|
6226 |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6227 # ifdef FEAT_NETBEANS_INTG |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6228 /* Process the queued netbeans messages. */ |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6229 netbeans_parse_messages(); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6230 # endif |
7840
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7838
diff
changeset
|
6231 # ifdef FEAT_CHANNEL |
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7838
diff
changeset
|
6232 /* Process the messages queued on channels. */ |
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7838
diff
changeset
|
6233 channel_parse_messages(); |
28f569c7dab9
commit https://github.com/vim/vim/commit/20fb9f346497daca4d19402fdfa5de7958642477
Christian Brabandt <cb@256bit.org>
parents:
7838
diff
changeset
|
6234 # endif |
7111
57c354f0115c
commit https://github.com/vim/vim/commit/9534680731ea342c2fed01a812559958923480da
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
6235 # if defined(FEAT_CLIENTSERVER) && defined(FEAT_X11) |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6236 /* Process the queued clientserver messages. */ |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6237 server_parse_messages(); |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6238 # endif |
8174
f2286ff0c102
commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
6239 # ifdef FEAT_JOB |
f2286ff0c102
commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
6240 /* Check if any jobs have ended. */ |
f2286ff0c102
commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
6241 job_check_ended(); |
f2286ff0c102
commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents:
8172
diff
changeset
|
6242 # endif |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6243 } |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7062
diff
changeset
|
6244 #endif |