Mercurial > vim
comparison src/misc2.c @ 18931:80b40bd5ec1a v8.2.0026
patch 8.2.0026: still some /* */ comments
Commit: https://github.com/vim/vim/commit/85a2002adb0eda9a9309c2fab4a79edaa91fb834
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Dec 21 18:25:54 2019 +0100
patch 8.2.0026: still some /* */ comments
Problem: Still some /* */ comments.
Solution: Convert to // comments.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 21 Dec 2019 18:30:05 +0100 |
parents | 050f5eaa9e50 |
children | a961efb326e5 |
comparison
equal
deleted
inserted
replaced
18930:394f34c5c683 | 18931:80b40bd5ec1a |
---|---|
10 /* | 10 /* |
11 * misc2.c: Various functions. | 11 * misc2.c: Various functions. |
12 */ | 12 */ |
13 #include "vim.h" | 13 #include "vim.h" |
14 | 14 |
15 static char_u *username = NULL; /* cached result of mch_get_user_name() */ | 15 static char_u *username = NULL; // cached result of mch_get_user_name() |
16 | 16 |
17 static int coladvance2(pos_T *pos, int addspaces, int finetune, colnr_T wcol); | 17 static int coladvance2(pos_T *pos, int addspaces, int finetune, colnr_T wcol); |
18 | 18 |
19 /* | 19 /* |
20 * Return TRUE if in the current mode we need to use virtual. | 20 * Return TRUE if in the current mode we need to use virtual. |
21 */ | 21 */ |
22 int | 22 int |
23 virtual_active(void) | 23 virtual_active(void) |
24 { | 24 { |
25 /* While an operator is being executed we return "virtual_op", because | 25 // While an operator is being executed we return "virtual_op", because |
26 * VIsual_active has already been reset, thus we can't check for "block" | 26 // VIsual_active has already been reset, thus we can't check for "block" |
27 * being used. */ | 27 // being used. |
28 if (virtual_op != MAYBE) | 28 if (virtual_op != MAYBE) |
29 return virtual_op; | 29 return virtual_op; |
30 return (ve_flags == VE_ALL | 30 return (ve_flags == VE_ALL |
31 || ((ve_flags & VE_BLOCK) && VIsual_active && VIsual_mode == Ctrl_V) | 31 || ((ve_flags & VE_BLOCK) && VIsual_active && VIsual_mode == Ctrl_V) |
32 || ((ve_flags & VE_INSERT) && (State & INSERT))); | 32 || ((ve_flags & VE_INSERT) && (State & INSERT))); |
56 | 56 |
57 if (wcol == MAXCOL) | 57 if (wcol == MAXCOL) |
58 curwin->w_valid &= ~VALID_VIRTCOL; | 58 curwin->w_valid &= ~VALID_VIRTCOL; |
59 else | 59 else |
60 { | 60 { |
61 /* Virtcol is valid */ | 61 // Virtcol is valid |
62 curwin->w_valid |= VALID_VIRTCOL; | 62 curwin->w_valid |= VALID_VIRTCOL; |
63 curwin->w_virtcol = wcol; | 63 curwin->w_virtcol = wcol; |
64 } | 64 } |
65 return rc; | 65 return rc; |
66 } | 66 } |
97 | 97 |
98 if (wcol == MAXCOL || rc == FAIL) | 98 if (wcol == MAXCOL || rc == FAIL) |
99 curwin->w_valid &= ~VALID_VIRTCOL; | 99 curwin->w_valid &= ~VALID_VIRTCOL; |
100 else if (*ml_get_cursor() != TAB) | 100 else if (*ml_get_cursor() != TAB) |
101 { | 101 { |
102 /* Virtcol is valid when not on a TAB */ | 102 // Virtcol is valid when not on a TAB |
103 curwin->w_valid |= VALID_VIRTCOL; | 103 curwin->w_valid |= VALID_VIRTCOL; |
104 curwin->w_virtcol = wcol; | 104 curwin->w_virtcol = wcol; |
105 } | 105 } |
106 return rc; | 106 return rc; |
107 } | 107 } |
166 csize--; | 166 csize--; |
167 | 167 |
168 if (wcol / width > (colnr_T)csize / width | 168 if (wcol / width > (colnr_T)csize / width |
169 && ((State & INSERT) == 0 || (int)wcol > csize + 1)) | 169 && ((State & INSERT) == 0 || (int)wcol > csize + 1)) |
170 { | 170 { |
171 /* In case of line wrapping don't move the cursor beyond the | 171 // In case of line wrapping don't move the cursor beyond the |
172 * right screen edge. In Insert mode allow going just beyond | 172 // right screen edge. In Insert mode allow going just beyond |
173 * the last character (like what happens when typing and | 173 // the last character (like what happens when typing and |
174 * reaching the right window edge). */ | 174 // reaching the right window edge). |
175 wcol = (csize / width + 1) * width - 1; | 175 wcol = (csize / width + 1) * width - 1; |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 ptr = line; | 179 ptr = line; |
180 while (col <= wcol && *ptr != NUL) | 180 while (col <= wcol && *ptr != NUL) |
181 { | 181 { |
182 /* Count a tab for what it's worth (if list mode not on) */ | 182 // Count a tab for what it's worth (if list mode not on) |
183 #ifdef FEAT_LINEBREAK | 183 #ifdef FEAT_LINEBREAK |
184 csize = win_lbr_chartabsize(curwin, line, ptr, col, &head); | 184 csize = win_lbr_chartabsize(curwin, line, ptr, col, &head); |
185 MB_PTR_ADV(ptr); | 185 MB_PTR_ADV(ptr); |
186 #else | 186 #else |
187 csize = lbr_chartabsize_adv(line, &ptr, col); | 187 csize = lbr_chartabsize_adv(line, &ptr, col); |
197 */ | 197 */ |
198 if (col > wcol || (!virtual_active() && one_more == 0)) | 198 if (col > wcol || (!virtual_active() && one_more == 0)) |
199 { | 199 { |
200 idx -= 1; | 200 idx -= 1; |
201 # ifdef FEAT_LINEBREAK | 201 # ifdef FEAT_LINEBREAK |
202 /* Don't count the chars from 'showbreak'. */ | 202 // Don't count the chars from 'showbreak'. |
203 csize -= head; | 203 csize -= head; |
204 # endif | 204 # endif |
205 col -= csize; | 205 col -= csize; |
206 } | 206 } |
207 | 207 |
208 if (virtual_active() | 208 if (virtual_active() |
209 && addspaces | 209 && addspaces |
210 && wcol >= 0 | 210 && wcol >= 0 |
211 && ((col != wcol && col != wcol + 1) || csize > 1)) | 211 && ((col != wcol && col != wcol + 1) || csize > 1)) |
212 { | 212 { |
213 /* 'virtualedit' is set: The difference between wcol and col is | 213 // 'virtualedit' is set: The difference between wcol and col is |
214 * filled with spaces. */ | 214 // filled with spaces. |
215 | 215 |
216 if (line[idx] == NUL) | 216 if (line[idx] == NUL) |
217 { | 217 { |
218 /* Append spaces */ | 218 // Append spaces |
219 int correct = wcol - col; | 219 int correct = wcol - col; |
220 char_u *newline = alloc(idx + correct + 1); | 220 char_u *newline = alloc(idx + correct + 1); |
221 int t; | 221 int t; |
222 | 222 |
223 if (newline == NULL) | 223 if (newline == NULL) |
236 idx += correct; | 236 idx += correct; |
237 col = wcol; | 237 col = wcol; |
238 } | 238 } |
239 else | 239 else |
240 { | 240 { |
241 /* Break a tab */ | 241 // Break a tab |
242 int linelen = (int)STRLEN(line); | 242 int linelen = (int)STRLEN(line); |
243 int correct = wcol - col - csize + 1; /* negative!! */ | 243 int correct = wcol - col - csize + 1; // negative!! |
244 char_u *newline; | 244 char_u *newline; |
245 int t, s = 0; | 245 int t, s = 0; |
246 int v; | 246 int v; |
247 | 247 |
248 if (-correct > csize) | 248 if (-correct > csize) |
280 | 280 |
281 if (finetune) | 281 if (finetune) |
282 { | 282 { |
283 if (wcol == MAXCOL) | 283 if (wcol == MAXCOL) |
284 { | 284 { |
285 /* The width of the last character is used to set coladd. */ | 285 // The width of the last character is used to set coladd. |
286 if (!one_more) | 286 if (!one_more) |
287 { | 287 { |
288 colnr_T scol, ecol; | 288 colnr_T scol, ecol; |
289 | 289 |
290 getvcol(curwin, pos, &scol, NULL, &ecol); | 290 getvcol(curwin, pos, &scol, NULL, &ecol); |
293 } | 293 } |
294 else | 294 else |
295 { | 295 { |
296 int b = (int)wcol - (int)col; | 296 int b = (int)wcol - (int)col; |
297 | 297 |
298 /* The difference between wcol and col is used to set coladd. */ | 298 // The difference between wcol and col is used to set coladd. |
299 if (b > 0 && b < (MAXCOL - 2 * curwin->w_width)) | 299 if (b > 0 && b < (MAXCOL - 2 * curwin->w_width)) |
300 pos->coladd = b; | 300 pos->coladd = b; |
301 | 301 |
302 col += b; | 302 col += b; |
303 } | 303 } |
304 } | 304 } |
305 | 305 |
306 /* prevent from moving onto a trail byte */ | 306 // prevent from moving onto a trail byte |
307 if (has_mbyte) | 307 if (has_mbyte) |
308 mb_adjustpos(curbuf, pos); | 308 mb_adjustpos(curbuf, pos); |
309 | 309 |
310 if (wcol < 0 || col < wcol) | 310 if (wcol < 0 || col < wcol) |
311 return FAIL; | 311 return FAIL; |
331 int | 331 int |
332 inc(pos_T *lp) | 332 inc(pos_T *lp) |
333 { | 333 { |
334 char_u *p; | 334 char_u *p; |
335 | 335 |
336 /* when searching position may be set to end of a line */ | 336 // when searching position may be set to end of a line |
337 if (lp->col != MAXCOL) | 337 if (lp->col != MAXCOL) |
338 { | 338 { |
339 p = ml_get_pos(lp); | 339 p = ml_get_pos(lp); |
340 if (*p != NUL) /* still within line, move to next char (may be NUL) */ | 340 if (*p != NUL) // still within line, move to next char (may be NUL) |
341 { | 341 { |
342 if (has_mbyte) | 342 if (has_mbyte) |
343 { | 343 { |
344 int l = (*mb_ptr2len)(p); | 344 int l = (*mb_ptr2len)(p); |
345 | 345 |
349 lp->col++; | 349 lp->col++; |
350 lp->coladd = 0; | 350 lp->coladd = 0; |
351 return ((p[1] != NUL) ? 0 : 2); | 351 return ((p[1] != NUL) ? 0 : 2); |
352 } | 352 } |
353 } | 353 } |
354 if (lp->lnum != curbuf->b_ml.ml_line_count) /* there is a next line */ | 354 if (lp->lnum != curbuf->b_ml.ml_line_count) // there is a next line |
355 { | 355 { |
356 lp->col = 0; | 356 lp->col = 0; |
357 lp->lnum++; | 357 lp->lnum++; |
358 lp->coladd = 0; | 358 lp->coladd = 0; |
359 return 1; | 359 return 1; |
392 char_u *p; | 392 char_u *p; |
393 | 393 |
394 lp->coladd = 0; | 394 lp->coladd = 0; |
395 if (lp->col == MAXCOL) | 395 if (lp->col == MAXCOL) |
396 { | 396 { |
397 /* past end of line */ | 397 // past end of line |
398 p = ml_get(lp->lnum); | 398 p = ml_get(lp->lnum); |
399 lp->col = (colnr_T)STRLEN(p); | 399 lp->col = (colnr_T)STRLEN(p); |
400 if (has_mbyte) | 400 if (has_mbyte) |
401 lp->col -= (*mb_head_off)(p, p + lp->col); | 401 lp->col -= (*mb_head_off)(p, p + lp->col); |
402 return 0; | 402 return 0; |
403 } | 403 } |
404 | 404 |
405 if (lp->col > 0) | 405 if (lp->col > 0) |
406 { | 406 { |
407 /* still within line */ | 407 // still within line |
408 lp->col--; | 408 lp->col--; |
409 if (has_mbyte) | 409 if (has_mbyte) |
410 { | 410 { |
411 p = ml_get(lp->lnum); | 411 p = ml_get(lp->lnum); |
412 lp->col -= (*mb_head_off)(p, p + lp->col); | 412 lp->col -= (*mb_head_off)(p, p + lp->col); |
414 return 0; | 414 return 0; |
415 } | 415 } |
416 | 416 |
417 if (lp->lnum > 1) | 417 if (lp->lnum > 1) |
418 { | 418 { |
419 /* there is a prior line */ | 419 // there is a prior line |
420 lp->lnum--; | 420 lp->lnum--; |
421 p = ml_get(lp->lnum); | 421 p = ml_get(lp->lnum); |
422 lp->col = (colnr_T)STRLEN(p); | 422 lp->col = (colnr_T)STRLEN(p); |
423 if (has_mbyte) | 423 if (has_mbyte) |
424 lp->col -= (*mb_head_off)(p, p + lp->col); | 424 lp->col -= (*mb_head_off)(p, p + lp->col); |
425 return 1; | 425 return 1; |
426 } | 426 } |
427 | 427 |
428 /* at start of file */ | 428 // at start of file |
429 return -1; | 429 return -1; |
430 } | 430 } |
431 | 431 |
432 /* | 432 /* |
433 * decl(lp): same as dec(), but skip the NUL at the end of non-empty lines | 433 * decl(lp): same as dec(), but skip the NUL at the end of non-empty lines |
448 * can be visible, folded lines don't count. | 448 * can be visible, folded lines don't count. |
449 */ | 449 */ |
450 linenr_T | 450 linenr_T |
451 get_cursor_rel_lnum( | 451 get_cursor_rel_lnum( |
452 win_T *wp, | 452 win_T *wp, |
453 linenr_T lnum) /* line number to get the result for */ | 453 linenr_T lnum) // line number to get the result for |
454 { | 454 { |
455 linenr_T cursor = wp->w_cursor.lnum; | 455 linenr_T cursor = wp->w_cursor.lnum; |
456 linenr_T retval = 0; | 456 linenr_T retval = 0; |
457 | 457 |
458 #ifdef FEAT_FOLDING | 458 #ifdef FEAT_FOLDING |
461 if (lnum > cursor) | 461 if (lnum > cursor) |
462 { | 462 { |
463 while (lnum > cursor) | 463 while (lnum > cursor) |
464 { | 464 { |
465 (void)hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL); | 465 (void)hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL); |
466 /* if lnum and cursor are in the same fold, | 466 // if lnum and cursor are in the same fold, |
467 * now lnum <= cursor */ | 467 // now lnum <= cursor |
468 if (lnum > cursor) | 468 if (lnum > cursor) |
469 retval++; | 469 retval++; |
470 lnum--; | 470 lnum--; |
471 } | 471 } |
472 } | 472 } |
473 else if (lnum < cursor) | 473 else if (lnum < cursor) |
474 { | 474 { |
475 while (lnum < cursor) | 475 while (lnum < cursor) |
476 { | 476 { |
477 (void)hasFoldingWin(wp, lnum, NULL, &lnum, TRUE, NULL); | 477 (void)hasFoldingWin(wp, lnum, NULL, &lnum, TRUE, NULL); |
478 /* if lnum and cursor are in the same fold, | 478 // if lnum and cursor are in the same fold, |
479 * now lnum >= cursor */ | 479 // now lnum >= cursor |
480 if (lnum < cursor) | 480 if (lnum < cursor) |
481 retval--; | 481 retval--; |
482 lnum++; | 482 lnum++; |
483 } | 483 } |
484 } | 484 } |
485 /* else if (lnum == cursor) | 485 // else if (lnum == cursor) |
486 * retval = 0; | 486 // retval = 0; |
487 */ | |
488 } | 487 } |
489 else | 488 else |
490 #endif | 489 #endif |
491 retval = lnum - cursor; | 490 retval = lnum - cursor; |
492 | 491 |
522 check_cursor_lnum(void) | 521 check_cursor_lnum(void) |
523 { | 522 { |
524 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | 523 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
525 { | 524 { |
526 #ifdef FEAT_FOLDING | 525 #ifdef FEAT_FOLDING |
527 /* If there is a closed fold at the end of the file, put the cursor in | 526 // If there is a closed fold at the end of the file, put the cursor in |
528 * its first line. Otherwise in the last line. */ | 527 // its first line. Otherwise in the last line. |
529 if (!hasFolding(curbuf->b_ml.ml_line_count, | 528 if (!hasFolding(curbuf->b_ml.ml_line_count, |
530 &curwin->w_cursor.lnum, NULL)) | 529 &curwin->w_cursor.lnum, NULL)) |
531 #endif | 530 #endif |
532 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | 531 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
533 } | 532 } |
557 len = (colnr_T)STRLEN(ml_get_buf(win->w_buffer, win->w_cursor.lnum, FALSE)); | 556 len = (colnr_T)STRLEN(ml_get_buf(win->w_buffer, win->w_cursor.lnum, FALSE)); |
558 if (len == 0) | 557 if (len == 0) |
559 win->w_cursor.col = 0; | 558 win->w_cursor.col = 0; |
560 else if (win->w_cursor.col >= len) | 559 else if (win->w_cursor.col >= len) |
561 { | 560 { |
562 /* Allow cursor past end-of-line when: | 561 // Allow cursor past end-of-line when: |
563 * - in Insert mode or restarting Insert mode | 562 // - in Insert mode or restarting Insert mode |
564 * - in Visual mode and 'selection' isn't "old" | 563 // - in Visual mode and 'selection' isn't "old" |
565 * - 'virtualedit' is set */ | 564 // - 'virtualedit' is set |
566 if ((State & INSERT) || restart_edit | 565 if ((State & INSERT) || restart_edit |
567 || (VIsual_active && *p_sel != 'o') | 566 || (VIsual_active && *p_sel != 'o') |
568 || (ve_flags & VE_ONEMORE) | 567 || (ve_flags & VE_ONEMORE) |
569 || virtual_active()) | 568 || virtual_active()) |
570 win->w_cursor.col = len; | 569 win->w_cursor.col = len; |
571 else | 570 else |
572 { | 571 { |
573 win->w_cursor.col = len - 1; | 572 win->w_cursor.col = len - 1; |
574 /* Move the cursor to the head byte. */ | 573 // Move the cursor to the head byte. |
575 if (has_mbyte) | 574 if (has_mbyte) |
576 mb_adjustpos(win->w_buffer, &win->w_cursor); | 575 mb_adjustpos(win->w_buffer, &win->w_cursor); |
577 } | 576 } |
578 } | 577 } |
579 else if (win->w_cursor.col < 0) | 578 else if (win->w_cursor.col < 0) |
580 win->w_cursor.col = 0; | 579 win->w_cursor.col = 0; |
581 | 580 |
582 /* If virtual editing is on, we can leave the cursor on the old position, | 581 // If virtual editing is on, we can leave the cursor on the old position, |
583 * only we must set it to virtual. But don't do it when at the end of the | 582 // only we must set it to virtual. But don't do it when at the end of the |
584 * line. */ | 583 // line. |
585 if (oldcol == MAXCOL) | 584 if (oldcol == MAXCOL) |
586 win->w_cursor.coladd = 0; | 585 win->w_cursor.coladd = 0; |
587 else if (ve_flags == VE_ALL) | 586 else if (ve_flags == VE_ALL) |
588 { | 587 { |
589 if (oldcoladd > win->w_cursor.col) | 588 if (oldcoladd > win->w_cursor.col) |
590 { | 589 { |
591 win->w_cursor.coladd = oldcoladd - win->w_cursor.col; | 590 win->w_cursor.coladd = oldcoladd - win->w_cursor.col; |
592 | 591 |
593 /* Make sure that coladd is not more than the char width. | 592 // Make sure that coladd is not more than the char width. |
594 * Not for the last character, coladd is then used when the cursor | 593 // Not for the last character, coladd is then used when the cursor |
595 * is actually after the last character. */ | 594 // is actually after the last character. |
596 if (win->w_cursor.col + 1 < len && win->w_cursor.coladd > 0) | 595 if (win->w_cursor.col + 1 < len && win->w_cursor.coladd > 0) |
597 { | 596 { |
598 int cs, ce; | 597 int cs, ce; |
599 | 598 |
600 getvcol(win, &win->w_cursor, &cs, NULL, &ce); | 599 getvcol(win, &win->w_cursor, &cs, NULL, &ce); |
601 if (win->w_cursor.coladd > ce - cs) | 600 if (win->w_cursor.coladd > ce - cs) |
602 win->w_cursor.coladd = ce - cs; | 601 win->w_cursor.coladd = ce - cs; |
603 } | 602 } |
604 } | 603 } |
605 else | 604 else |
606 /* avoid weird number when there is a miscalculation or overflow */ | 605 // avoid weird number when there is a miscalculation or overflow |
607 win->w_cursor.coladd = 0; | 606 win->w_cursor.coladd = 0; |
608 } | 607 } |
609 } | 608 } |
610 | 609 |
611 /* | 610 /* |
676 coladvance(s - 1); | 675 coladvance(s - 1); |
677 } | 676 } |
678 else if (s < curwin->w_leftcol) | 677 else if (s < curwin->w_leftcol) |
679 { | 678 { |
680 retval = TRUE; | 679 retval = TRUE; |
681 if (coladvance(e + 1) == FAIL) /* there isn't another character */ | 680 if (coladvance(e + 1) == FAIL) // there isn't another character |
682 { | 681 { |
683 curwin->w_leftcol = s; /* adjust w_leftcol instead */ | 682 curwin->w_leftcol = s; // adjust w_leftcol instead |
684 changed_cline_bef_curs(); | 683 changed_cline_bef_curs(); |
685 } | 684 } |
686 } | 685 } |
687 | 686 |
688 if (retval) | 687 if (retval) |
792 mem_allocated, mem_freed, mem_allocated - mem_freed, mem_peak); | 791 mem_allocated, mem_freed, mem_allocated - mem_freed, mem_peak); |
793 printf(_("[calls] total re/malloc()'s %lu, total free()'s %lu\n\n"), | 792 printf(_("[calls] total re/malloc()'s %lu, total free()'s %lu\n\n"), |
794 num_alloc, num_freed); | 793 num_alloc, num_freed); |
795 } | 794 } |
796 | 795 |
797 #endif /* MEM_PROFILE */ | 796 #endif // MEM_PROFILE |
798 | 797 |
799 #ifdef FEAT_EVAL | 798 #ifdef FEAT_EVAL |
800 int | 799 int |
801 alloc_does_fail(size_t size) | 800 alloc_does_fail(size_t size) |
802 { | 801 { |
888 * This is used often, KEEP IT FAST! | 887 * This is used often, KEEP IT FAST! |
889 */ | 888 */ |
890 void * | 889 void * |
891 lalloc(size_t size, int message) | 890 lalloc(size_t size, int message) |
892 { | 891 { |
893 void *p; /* pointer to new storage space */ | 892 void *p; // pointer to new storage space |
894 static int releasing = FALSE; /* don't do mf_release_all() recursive */ | 893 static int releasing = FALSE; // don't do mf_release_all() recursive |
895 int try_again; | 894 int try_again; |
896 #if defined(HAVE_AVAIL_MEM) | 895 #if defined(HAVE_AVAIL_MEM) |
897 static size_t allocated = 0; /* allocated since last avail check */ | 896 static size_t allocated = 0; // allocated since last avail check |
898 #endif | 897 #endif |
899 | 898 |
900 // Safety check for allocating zero bytes | 899 // Safety check for allocating zero bytes |
901 if (size == 0) | 900 if (size == 0) |
902 { | 901 { |
924 * 3. Strict check for available memory: call mch_avail_mem() | 923 * 3. Strict check for available memory: call mch_avail_mem() |
925 */ | 924 */ |
926 if ((p = malloc(size)) != NULL) | 925 if ((p = malloc(size)) != NULL) |
927 { | 926 { |
928 #ifndef HAVE_AVAIL_MEM | 927 #ifndef HAVE_AVAIL_MEM |
929 /* 1. No check for available memory: Just return. */ | 928 // 1. No check for available memory: Just return. |
930 goto theend; | 929 goto theend; |
931 #else | 930 #else |
932 /* 2. Slow check for available memory: call mch_avail_mem() after | 931 // 2. Slow check for available memory: call mch_avail_mem() after |
933 * allocating (KEEP_ROOM / 2) amount of memory. */ | 932 // allocating (KEEP_ROOM / 2) amount of memory. |
934 allocated += size; | 933 allocated += size; |
935 if (allocated < KEEP_ROOM / 2) | 934 if (allocated < KEEP_ROOM / 2) |
936 goto theend; | 935 goto theend; |
937 allocated = 0; | 936 allocated = 0; |
938 | 937 |
939 /* 3. check for available memory: call mch_avail_mem() */ | 938 // 3. check for available memory: call mch_avail_mem() |
940 if (mch_avail_mem(TRUE) < KEEP_ROOM_KB && !releasing) | 939 if (mch_avail_mem(TRUE) < KEEP_ROOM_KB && !releasing) |
941 { | 940 { |
942 free(p); /* System is low... no go! */ | 941 free(p); // System is low... no go! |
943 p = NULL; | 942 p = NULL; |
944 } | 943 } |
945 else | 944 else |
946 goto theend; | 945 goto theend; |
947 #endif | 946 #endif |
952 */ | 951 */ |
953 if (releasing) | 952 if (releasing) |
954 break; | 953 break; |
955 releasing = TRUE; | 954 releasing = TRUE; |
956 | 955 |
957 clear_sb_text(TRUE); /* free any scrollback text */ | 956 clear_sb_text(TRUE); // free any scrollback text |
958 try_again = mf_release_all(); /* release as many blocks as possible */ | 957 try_again = mf_release_all(); // release as many blocks as possible |
959 | 958 |
960 releasing = FALSE; | 959 releasing = FALSE; |
961 if (!try_again) | 960 if (!try_again) |
962 break; | 961 break; |
963 } | 962 } |
1044 void | 1043 void |
1045 free_all_mem(void) | 1044 free_all_mem(void) |
1046 { | 1045 { |
1047 buf_T *buf, *nextbuf; | 1046 buf_T *buf, *nextbuf; |
1048 | 1047 |
1049 /* When we cause a crash here it is caught and Vim tries to exit cleanly. | 1048 // When we cause a crash here it is caught and Vim tries to exit cleanly. |
1050 * Don't try freeing everything again. */ | 1049 // Don't try freeing everything again. |
1051 if (entered_free_all_mem) | 1050 if (entered_free_all_mem) |
1052 return; | 1051 return; |
1053 entered_free_all_mem = TRUE; | 1052 entered_free_all_mem = TRUE; |
1054 | 1053 |
1055 /* Don't want to trigger autocommands from here on. */ | 1054 // Don't want to trigger autocommands from here on. |
1056 block_autocmds(); | 1055 block_autocmds(); |
1057 | 1056 |
1058 /* Close all tabs and windows. Reset 'equalalways' to avoid redraws. */ | 1057 // Close all tabs and windows. Reset 'equalalways' to avoid redraws. |
1059 p_ea = FALSE; | 1058 p_ea = FALSE; |
1060 if (first_tabpage != NULL && first_tabpage->tp_next != NULL) | 1059 if (first_tabpage != NULL && first_tabpage->tp_next != NULL) |
1061 do_cmdline_cmd((char_u *)"tabonly!"); | 1060 do_cmdline_cmd((char_u *)"tabonly!"); |
1062 if (!ONE_WINDOW) | 1061 if (!ONE_WINDOW) |
1063 do_cmdline_cmd((char_u *)"only!"); | 1062 do_cmdline_cmd((char_u *)"only!"); |
1064 | 1063 |
1065 # if defined(FEAT_SPELL) | 1064 # if defined(FEAT_SPELL) |
1066 /* Free all spell info. */ | 1065 // Free all spell info. |
1067 spell_free_all(); | 1066 spell_free_all(); |
1068 # endif | 1067 # endif |
1069 | 1068 |
1070 # if defined(FEAT_BEVAL_TERM) | 1069 # if defined(FEAT_BEVAL_TERM) |
1071 ui_remove_balloon(); | 1070 ui_remove_balloon(); |
1107 # endif | 1106 # endif |
1108 # if defined(FEAT_SEARCHPATH) | 1107 # if defined(FEAT_SEARCHPATH) |
1109 free_findfile(); | 1108 free_findfile(); |
1110 # endif | 1109 # endif |
1111 | 1110 |
1112 /* Obviously named calls. */ | 1111 // Obviously named calls. |
1113 free_all_autocmds(); | 1112 free_all_autocmds(); |
1114 clear_termcodes(); | 1113 clear_termcodes(); |
1115 free_all_marks(); | 1114 free_all_marks(); |
1116 alist_clear(&global_alist); | 1115 alist_clear(&global_alist); |
1117 free_homedir(); | 1116 free_homedir(); |
1132 # endif | 1131 # endif |
1133 # ifdef FEAT_DIFF | 1132 # ifdef FEAT_DIFF |
1134 if (curtab != NULL) | 1133 if (curtab != NULL) |
1135 diff_clear(curtab); | 1134 diff_clear(curtab); |
1136 # endif | 1135 # endif |
1137 clear_sb_text(TRUE); /* free any scrollback text */ | 1136 clear_sb_text(TRUE); // free any scrollback text |
1138 | 1137 |
1139 /* Free some global vars. */ | 1138 // Free some global vars. |
1140 vim_free(username); | 1139 vim_free(username); |
1141 # ifdef FEAT_CLIPBOARD | 1140 # ifdef FEAT_CLIPBOARD |
1142 vim_regfree(clip_exclude_prog); | 1141 vim_regfree(clip_exclude_prog); |
1143 # endif | 1142 # endif |
1144 vim_free(last_cmdline); | 1143 vim_free(last_cmdline); |
1145 vim_free(new_last_cmdline); | 1144 vim_free(new_last_cmdline); |
1146 set_keep_msg(NULL, 0); | 1145 set_keep_msg(NULL, 0); |
1147 | 1146 |
1148 /* Clear cmdline history. */ | 1147 // Clear cmdline history. |
1149 p_hi = 0; | 1148 p_hi = 0; |
1150 init_history(); | 1149 init_history(); |
1151 # ifdef FEAT_PROP_POPUP | 1150 # ifdef FEAT_PROP_POPUP |
1152 clear_global_prop_types(); | 1151 clear_global_prop_types(); |
1153 # endif | 1152 # endif |
1169 | 1168 |
1170 if (curwin != NULL) | 1169 if (curwin != NULL) |
1171 // Destroy all windows. Must come before freeing buffers. | 1170 // Destroy all windows. Must come before freeing buffers. |
1172 win_free_all(); | 1171 win_free_all(); |
1173 | 1172 |
1174 /* Free all option values. Must come after closing windows. */ | 1173 // Free all option values. Must come after closing windows. |
1175 free_all_options(); | 1174 free_all_options(); |
1176 | 1175 |
1177 /* Free all buffers. Reset 'autochdir' to avoid accessing things that | 1176 // Free all buffers. Reset 'autochdir' to avoid accessing things that |
1178 * were freed already. */ | 1177 // were freed already. |
1179 # ifdef FEAT_AUTOCHDIR | 1178 # ifdef FEAT_AUTOCHDIR |
1180 p_acd = FALSE; | 1179 p_acd = FALSE; |
1181 # endif | 1180 # endif |
1182 for (buf = firstbuf; buf != NULL; ) | 1181 for (buf = firstbuf; buf != NULL; ) |
1183 { | 1182 { |
1185 | 1184 |
1186 set_bufref(&bufref, buf); | 1185 set_bufref(&bufref, buf); |
1187 nextbuf = buf->b_next; | 1186 nextbuf = buf->b_next; |
1188 close_buffer(NULL, buf, DOBUF_WIPE, FALSE, FALSE); | 1187 close_buffer(NULL, buf, DOBUF_WIPE, FALSE, FALSE); |
1189 if (bufref_valid(&bufref)) | 1188 if (bufref_valid(&bufref)) |
1190 buf = nextbuf; /* didn't work, try next one */ | 1189 buf = nextbuf; // didn't work, try next one |
1191 else | 1190 else |
1192 buf = firstbuf; | 1191 buf = firstbuf; |
1193 } | 1192 } |
1194 | 1193 |
1195 # ifdef FEAT_ARABIC | 1194 # ifdef FEAT_ARABIC |
1196 free_arshape_buf(); | 1195 free_arshape_buf(); |
1197 # endif | 1196 # endif |
1198 | 1197 |
1199 /* Clear registers. */ | 1198 // Clear registers. |
1200 clear_registers(); | 1199 clear_registers(); |
1201 ResetRedobuff(); | 1200 ResetRedobuff(); |
1202 ResetRedobuff(); | 1201 ResetRedobuff(); |
1203 | 1202 |
1204 # if defined(FEAT_CLIENTSERVER) && defined(FEAT_X11) | 1203 # if defined(FEAT_CLIENTSERVER) && defined(FEAT_X11) |
1205 vim_free(serverDelayedStartName); | 1204 vim_free(serverDelayedStartName); |
1206 # endif | 1205 # endif |
1207 | 1206 |
1208 /* highlight info */ | 1207 // highlight info |
1209 free_highlight(); | 1208 free_highlight(); |
1210 | 1209 |
1211 reset_last_sourcing(); | 1210 reset_last_sourcing(); |
1212 | 1211 |
1213 if (first_tabpage != NULL) | 1212 if (first_tabpage != NULL) |
1215 free_tabpage(first_tabpage); | 1214 free_tabpage(first_tabpage); |
1216 first_tabpage = NULL; | 1215 first_tabpage = NULL; |
1217 } | 1216 } |
1218 | 1217 |
1219 # ifdef UNIX | 1218 # ifdef UNIX |
1220 /* Machine-specific free. */ | 1219 // Machine-specific free. |
1221 mch_free_mem(); | 1220 mch_free_mem(); |
1222 # endif | 1221 # endif |
1223 | 1222 |
1224 /* message history */ | 1223 // message history |
1225 for (;;) | 1224 for (;;) |
1226 if (delete_first_msg() == FAIL) | 1225 if (delete_first_msg() == FAIL) |
1227 break; | 1226 break; |
1228 | 1227 |
1229 # ifdef FEAT_JOB_CHANNEL | 1228 # ifdef FEAT_JOB_CHANNEL |
1231 # endif | 1230 # endif |
1232 # ifdef FEAT_TIMERS | 1231 # ifdef FEAT_TIMERS |
1233 timer_free_all(); | 1232 timer_free_all(); |
1234 # endif | 1233 # endif |
1235 # ifdef FEAT_EVAL | 1234 # ifdef FEAT_EVAL |
1236 /* must be after channel_free_all() with unrefs partials */ | 1235 // must be after channel_free_all() with unrefs partials |
1237 eval_clear(); | 1236 eval_clear(); |
1238 # endif | 1237 # endif |
1239 # ifdef FEAT_JOB_CHANNEL | 1238 # ifdef FEAT_JOB_CHANNEL |
1240 /* must be after eval_clear() with unrefs jobs */ | 1239 // must be after eval_clear() with unrefs jobs |
1241 job_free_all(); | 1240 job_free_all(); |
1242 # endif | 1241 # endif |
1243 | 1242 |
1244 free_termoptions(); | 1243 free_termoptions(); |
1245 | 1244 |
1246 /* screenlines (can't display anything now!) */ | 1245 // screenlines (can't display anything now!) |
1247 free_screenlines(); | 1246 free_screenlines(); |
1248 | 1247 |
1249 # if defined(FEAT_SOUND) | 1248 # if defined(FEAT_SOUND) |
1250 sound_free(); | 1249 sound_free(); |
1251 # endif | 1250 # endif |
1345 | 1344 |
1346 /* | 1345 /* |
1347 * First count the number of backslashes required. | 1346 * First count the number of backslashes required. |
1348 * Then allocate the memory and insert them. | 1347 * Then allocate the memory and insert them. |
1349 */ | 1348 */ |
1350 length = 1; /* count the trailing NUL */ | 1349 length = 1; // count the trailing NUL |
1351 for (p = string; *p; p++) | 1350 for (p = string; *p; p++) |
1352 { | 1351 { |
1353 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) | 1352 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
1354 { | 1353 { |
1355 length += l; /* count a multibyte char */ | 1354 length += l; // count a multibyte char |
1356 p += l - 1; | 1355 p += l - 1; |
1357 continue; | 1356 continue; |
1358 } | 1357 } |
1359 if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p))) | 1358 if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p))) |
1360 ++length; /* count a backslash */ | 1359 ++length; // count a backslash |
1361 ++length; /* count an ordinary char */ | 1360 ++length; // count an ordinary char |
1362 } | 1361 } |
1363 escaped_string = alloc(length); | 1362 escaped_string = alloc(length); |
1364 if (escaped_string != NULL) | 1363 if (escaped_string != NULL) |
1365 { | 1364 { |
1366 p2 = escaped_string; | 1365 p2 = escaped_string; |
1368 { | 1367 { |
1369 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) | 1368 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
1370 { | 1369 { |
1371 mch_memmove(p2, p, (size_t)l); | 1370 mch_memmove(p2, p, (size_t)l); |
1372 p2 += l; | 1371 p2 += l; |
1373 p += l - 1; /* skip multibyte char */ | 1372 p += l - 1; // skip multibyte char |
1374 continue; | 1373 continue; |
1375 } | 1374 } |
1376 if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p))) | 1375 if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p))) |
1377 *p2++ = cc; | 1376 *p2++ = cc; |
1378 *p2++ = *p; | 1377 *p2++ = *p; |
1409 char_u *d; | 1408 char_u *d; |
1410 char_u *escaped_string; | 1409 char_u *escaped_string; |
1411 int l; | 1410 int l; |
1412 int csh_like; | 1411 int csh_like; |
1413 | 1412 |
1414 /* Only csh and similar shells expand '!' within single quotes. For sh and | 1413 // Only csh and similar shells expand '!' within single quotes. For sh and |
1415 * the like we must not put a backslash before it, it will be taken | 1414 // the like we must not put a backslash before it, it will be taken |
1416 * literally. If do_special is set the '!' will be escaped twice. | 1415 // literally. If do_special is set the '!' will be escaped twice. |
1417 * Csh also needs to have "\n" escaped twice when do_special is set. */ | 1416 // Csh also needs to have "\n" escaped twice when do_special is set. |
1418 csh_like = csh_like_shell(); | 1417 csh_like = csh_like_shell(); |
1419 | 1418 |
1420 /* First count the number of extra bytes required. */ | 1419 // First count the number of extra bytes required. |
1421 length = (unsigned)STRLEN(string) + 3; /* two quotes and a trailing NUL */ | 1420 length = (unsigned)STRLEN(string) + 3; // two quotes and a trailing NUL |
1422 for (p = string; *p != NUL; MB_PTR_ADV(p)) | 1421 for (p = string; *p != NUL; MB_PTR_ADV(p)) |
1423 { | 1422 { |
1424 # ifdef MSWIN | 1423 # ifdef MSWIN |
1425 if (!p_ssl) | 1424 if (!p_ssl) |
1426 { | 1425 { |
1427 if (*p == '"') | 1426 if (*p == '"') |
1428 ++length; /* " -> "" */ | 1427 ++length; // " -> "" |
1429 } | 1428 } |
1430 else | 1429 else |
1431 # endif | 1430 # endif |
1432 if (*p == '\'') | 1431 if (*p == '\'') |
1433 length += 3; /* ' => '\'' */ | 1432 length += 3; // ' => '\'' |
1434 if ((*p == '\n' && (csh_like || do_newline)) | 1433 if ((*p == '\n' && (csh_like || do_newline)) |
1435 || (*p == '!' && (csh_like || do_special))) | 1434 || (*p == '!' && (csh_like || do_special))) |
1436 { | 1435 { |
1437 ++length; /* insert backslash */ | 1436 ++length; // insert backslash |
1438 if (csh_like && do_special) | 1437 if (csh_like && do_special) |
1439 ++length; /* insert backslash */ | 1438 ++length; // insert backslash |
1440 } | 1439 } |
1441 if (do_special && find_cmdline_var(p, &l) >= 0) | 1440 if (do_special && find_cmdline_var(p, &l) >= 0) |
1442 { | 1441 { |
1443 ++length; /* insert backslash */ | 1442 ++length; // insert backslash |
1444 p += l - 1; | 1443 p += l - 1; |
1445 } | 1444 } |
1446 } | 1445 } |
1447 | 1446 |
1448 /* Allocate memory for the result and fill it. */ | 1447 // Allocate memory for the result and fill it. |
1449 escaped_string = alloc(length); | 1448 escaped_string = alloc(length); |
1450 if (escaped_string != NULL) | 1449 if (escaped_string != NULL) |
1451 { | 1450 { |
1452 d = escaped_string; | 1451 d = escaped_string; |
1453 | 1452 |
1454 /* add opening quote */ | 1453 // add opening quote |
1455 # ifdef MSWIN | 1454 # ifdef MSWIN |
1456 if (!p_ssl) | 1455 if (!p_ssl) |
1457 *d++ = '"'; | 1456 *d++ = '"'; |
1458 else | 1457 else |
1459 # endif | 1458 # endif |
1492 *d++ = *p++; | 1491 *d++ = *p++; |
1493 continue; | 1492 continue; |
1494 } | 1493 } |
1495 if (do_special && find_cmdline_var(p, &l) >= 0) | 1494 if (do_special && find_cmdline_var(p, &l) >= 0) |
1496 { | 1495 { |
1497 *d++ = '\\'; /* insert backslash */ | 1496 *d++ = '\\'; // insert backslash |
1498 while (--l >= 0) /* copy the var */ | 1497 while (--l >= 0) // copy the var |
1499 *d++ = *p++; | 1498 *d++ = *p++; |
1500 continue; | 1499 continue; |
1501 } | 1500 } |
1502 | 1501 |
1503 MB_COPY_CHAR(p, d); | 1502 MB_COPY_CHAR(p, d); |
1504 } | 1503 } |
1505 | 1504 |
1506 /* add terminating quote and finish with a NUL */ | 1505 // add terminating quote and finish with a NUL |
1507 # ifdef MSWIN | 1506 # ifdef MSWIN |
1508 if (!p_ssl) | 1507 if (!p_ssl) |
1509 *d++ = '"'; | 1508 *d++ = '"'; |
1510 else | 1509 else |
1511 # endif | 1510 # endif |
1593 | 1592 |
1594 c = utf_ptr2char(p); | 1593 c = utf_ptr2char(p); |
1595 l = utf_ptr2len(p); | 1594 l = utf_ptr2len(p); |
1596 if (c == 0) | 1595 if (c == 0) |
1597 { | 1596 { |
1598 /* overlong sequence, use only the first byte */ | 1597 // overlong sequence, use only the first byte |
1599 c = *p; | 1598 c = *p; |
1600 l = 1; | 1599 l = 1; |
1601 } | 1600 } |
1602 uc = utf_toupper(c); | 1601 uc = utf_toupper(c); |
1603 | 1602 |
1604 /* Reallocate string when byte count changes. This is rare, | 1603 // Reallocate string when byte count changes. This is rare, |
1605 * thus it's OK to do another malloc()/free(). */ | 1604 // thus it's OK to do another malloc()/free(). |
1606 newl = utf_char2len(uc); | 1605 newl = utf_char2len(uc); |
1607 if (newl != l) | 1606 if (newl != l) |
1608 { | 1607 { |
1609 s = alloc(STRLEN(res) + 1 + newl - l); | 1608 s = alloc(STRLEN(res) + 1 + newl - l); |
1610 if (s == NULL) | 1609 if (s == NULL) |
1621 | 1620 |
1622 utf_char2bytes(uc, p); | 1621 utf_char2bytes(uc, p); |
1623 p += newl; | 1622 p += newl; |
1624 } | 1623 } |
1625 else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) | 1624 else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
1626 p += l; /* skip multi-byte character */ | 1625 p += l; // skip multi-byte character |
1627 else | 1626 else |
1628 { | 1627 { |
1629 *p = TOUPPER_LOC(*p); /* note that toupper() can be a macro */ | 1628 *p = TOUPPER_LOC(*p); // note that toupper() can be a macro |
1630 p++; | 1629 p++; |
1631 } | 1630 } |
1632 } | 1631 } |
1633 | 1632 |
1634 return res; | 1633 return res; |
1660 | 1659 |
1661 c = utf_ptr2char(p); | 1660 c = utf_ptr2char(p); |
1662 l = utf_ptr2len(p); | 1661 l = utf_ptr2len(p); |
1663 if (c == 0) | 1662 if (c == 0) |
1664 { | 1663 { |
1665 /* overlong sequence, use only the first byte */ | 1664 // overlong sequence, use only the first byte |
1666 c = *p; | 1665 c = *p; |
1667 l = 1; | 1666 l = 1; |
1668 } | 1667 } |
1669 lc = utf_tolower(c); | 1668 lc = utf_tolower(c); |
1670 | 1669 |
1671 /* Reallocate string when byte count changes. This is rare, | 1670 // Reallocate string when byte count changes. This is rare, |
1672 * thus it's OK to do another malloc()/free(). */ | 1671 // thus it's OK to do another malloc()/free(). |
1673 newl = utf_char2len(lc); | 1672 newl = utf_char2len(lc); |
1674 if (newl != l) | 1673 if (newl != l) |
1675 { | 1674 { |
1676 s = alloc(STRLEN(res) + 1 + newl - l); | 1675 s = alloc(STRLEN(res) + 1 + newl - l); |
1677 if (s == NULL) | 1676 if (s == NULL) |
1688 | 1687 |
1689 utf_char2bytes(lc, p); | 1688 utf_char2bytes(lc, p); |
1690 p += newl; | 1689 p += newl; |
1691 } | 1690 } |
1692 else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) | 1691 else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
1693 p += l; /* skip multi-byte character */ | 1692 p += l; // skip multi-byte character |
1694 else | 1693 else |
1695 { | 1694 { |
1696 *p = TOLOWER_LOC(*p); /* note that tolower() can be a macro */ | 1695 *p = TOLOWER_LOC(*p); // note that tolower() can be a macro |
1697 p++; | 1696 p++; |
1698 } | 1697 } |
1699 } | 1698 } |
1700 | 1699 |
1701 return res; | 1700 return res; |
1760 char *sep_chars) | 1759 char *sep_chars) |
1761 { | 1760 { |
1762 int len = 0; | 1761 int len = 0; |
1763 char_u *p = *option; | 1762 char_u *p = *option; |
1764 | 1763 |
1765 /* skip '.' at start of option part, for 'suffixes' */ | 1764 // skip '.' at start of option part, for 'suffixes' |
1766 if (*p == '.') | 1765 if (*p == '.') |
1767 buf[len++] = *p++; | 1766 buf[len++] = *p++; |
1768 while (*p != NUL && vim_strchr((char_u *)sep_chars, *p) == NULL) | 1767 while (*p != NUL && vim_strchr((char_u *)sep_chars, *p) == NULL) |
1769 { | 1768 { |
1770 /* | 1769 /* |
1776 buf[len++] = *p; | 1775 buf[len++] = *p; |
1777 ++p; | 1776 ++p; |
1778 } | 1777 } |
1779 buf[len] = NUL; | 1778 buf[len] = NUL; |
1780 | 1779 |
1781 if (*p != NUL && *p != ',') /* skip non-standard separator */ | 1780 if (*p != NUL && *p != ',') // skip non-standard separator |
1782 ++p; | 1781 ++p; |
1783 p = skip_to_option_part(p); /* p points to next file name */ | 1782 p = skip_to_option_part(p); // p points to next file name |
1784 | 1783 |
1785 *option = p; | 1784 *option = p; |
1786 return len; | 1785 return len; |
1787 } | 1786 } |
1788 | 1787 |
1830 | 1829 |
1831 for (;;) | 1830 for (;;) |
1832 { | 1831 { |
1833 i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2); | 1832 i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2); |
1834 if (i != 0) | 1833 if (i != 0) |
1835 return i; /* this character different */ | 1834 return i; // this character different |
1836 if (*s1 == NUL) | 1835 if (*s1 == NUL) |
1837 break; /* strings match until NUL */ | 1836 break; // strings match until NUL |
1838 ++s1; | 1837 ++s1; |
1839 ++s2; | 1838 ++s2; |
1840 } | 1839 } |
1841 return 0; /* strings match */ | 1840 return 0; // strings match |
1842 } | 1841 } |
1843 #endif | 1842 #endif |
1844 | 1843 |
1845 #if (!defined(HAVE_STRNCASECMP) && !defined(HAVE_STRNICMP)) || defined(PROTO) | 1844 #if (!defined(HAVE_STRNCASECMP) && !defined(HAVE_STRNICMP)) || defined(PROTO) |
1846 /* | 1845 /* |
1855 | 1854 |
1856 while (len > 0) | 1855 while (len > 0) |
1857 { | 1856 { |
1858 i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2); | 1857 i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2); |
1859 if (i != 0) | 1858 if (i != 0) |
1860 return i; /* this character different */ | 1859 return i; // this character different |
1861 if (*s1 == NUL) | 1860 if (*s1 == NUL) |
1862 break; /* strings match until NUL */ | 1861 break; // strings match until NUL |
1863 ++s1; | 1862 ++s1; |
1864 ++s2; | 1863 ++s2; |
1865 --len; | 1864 --len; |
1866 } | 1865 } |
1867 return 0; /* strings match */ | 1866 return 0; // strings match |
1868 } | 1867 } |
1869 #endif | 1868 #endif |
1870 | 1869 |
1871 /* | 1870 /* |
1872 * Version of strchr() and strrchr() that handle unsigned char strings | 1871 * Version of strchr() and strrchr() that handle unsigned char strings |
1884 { | 1883 { |
1885 while (*p != NUL) | 1884 while (*p != NUL) |
1886 { | 1885 { |
1887 int l = utfc_ptr2len(p); | 1886 int l = utfc_ptr2len(p); |
1888 | 1887 |
1889 /* Avoid matching an illegal byte here. */ | 1888 // Avoid matching an illegal byte here. |
1890 if (utf_ptr2char(p) == c && l > 1) | 1889 if (utf_ptr2char(p) == c && l > 1) |
1891 return p; | 1890 return p; |
1892 p += l; | 1891 p += l; |
1893 } | 1892 } |
1894 return NULL; | 1893 return NULL; |
2175 * Append the text in "gap" below the cursor line and clear "gap". | 2174 * Append the text in "gap" below the cursor line and clear "gap". |
2176 */ | 2175 */ |
2177 void | 2176 void |
2178 append_ga_line(garray_T *gap) | 2177 append_ga_line(garray_T *gap) |
2179 { | 2178 { |
2180 /* Remove trailing CR. */ | 2179 // Remove trailing CR. |
2181 if (gap->ga_len > 0 | 2180 if (gap->ga_len > 0 |
2182 && !curbuf->b_p_bin | 2181 && !curbuf->b_p_bin |
2183 && ((char_u *)gap->ga_data)[gap->ga_len - 1] == CAR) | 2182 && ((char_u *)gap->ga_data)[gap->ga_len - 1] == CAR) |
2184 --gap->ga_len; | 2183 --gap->ga_len; |
2185 ga_append(gap, NUL); | 2184 ga_append(gap, NUL); |
2197 * Some useful tables. | 2196 * Some useful tables. |
2198 */ | 2197 */ |
2199 | 2198 |
2200 static struct modmasktable | 2199 static struct modmasktable |
2201 { | 2200 { |
2202 short mod_mask; /* Bit-mask for particular key modifier */ | 2201 short mod_mask; // Bit-mask for particular key modifier |
2203 short mod_flag; /* Bit(s) for particular key modifier */ | 2202 short mod_flag; // Bit(s) for particular key modifier |
2204 char_u name; /* Single letter name of modifier */ | 2203 char_u name; // Single letter name of modifier |
2205 } mod_mask_table[] = | 2204 } mod_mask_table[] = |
2206 { | 2205 { |
2207 {MOD_MASK_ALT, MOD_MASK_ALT, (char_u)'M'}, | 2206 {MOD_MASK_ALT, MOD_MASK_ALT, (char_u)'M'}, |
2208 {MOD_MASK_META, MOD_MASK_META, (char_u)'T'}, | 2207 {MOD_MASK_META, MOD_MASK_META, (char_u)'T'}, |
2209 {MOD_MASK_CTRL, MOD_MASK_CTRL, (char_u)'C'}, | 2208 {MOD_MASK_CTRL, MOD_MASK_CTRL, (char_u)'C'}, |
2212 {MOD_MASK_MULTI_CLICK, MOD_MASK_3CLICK, (char_u)'3'}, | 2211 {MOD_MASK_MULTI_CLICK, MOD_MASK_3CLICK, (char_u)'3'}, |
2213 {MOD_MASK_MULTI_CLICK, MOD_MASK_4CLICK, (char_u)'4'}, | 2212 {MOD_MASK_MULTI_CLICK, MOD_MASK_4CLICK, (char_u)'4'}, |
2214 #ifdef MACOS_X | 2213 #ifdef MACOS_X |
2215 {MOD_MASK_CMD, MOD_MASK_CMD, (char_u)'D'}, | 2214 {MOD_MASK_CMD, MOD_MASK_CMD, (char_u)'D'}, |
2216 #endif | 2215 #endif |
2217 /* 'A' must be the last one */ | 2216 // 'A' must be the last one |
2218 {MOD_MASK_ALT, MOD_MASK_ALT, (char_u)'A'}, | 2217 {MOD_MASK_ALT, MOD_MASK_ALT, (char_u)'A'}, |
2219 {0, 0, NUL} | 2218 {0, 0, NUL} |
2220 /* NOTE: when adding an entry, update MAX_KEY_NAME_LEN! */ | 2219 // NOTE: when adding an entry, update MAX_KEY_NAME_LEN! |
2221 }; | 2220 }; |
2222 | 2221 |
2223 /* | 2222 /* |
2224 * Shifted key terminal codes and their unshifted equivalent. | 2223 * Shifted key terminal codes and their unshifted equivalent. |
2225 * Don't add mouse codes here, they are handled separately! | 2224 * Don't add mouse codes here, they are handled separately! |
2226 */ | 2225 */ |
2227 #define MOD_KEYS_ENTRY_SIZE 5 | 2226 #define MOD_KEYS_ENTRY_SIZE 5 |
2228 | 2227 |
2229 static char_u modifier_keys_table[] = | 2228 static char_u modifier_keys_table[] = |
2230 { | 2229 { |
2231 /* mod mask with modifier without modifier */ | 2230 // mod mask with modifier without modifier |
2232 MOD_MASK_SHIFT, '&', '9', '@', '1', /* begin */ | 2231 MOD_MASK_SHIFT, '&', '9', '@', '1', // begin |
2233 MOD_MASK_SHIFT, '&', '0', '@', '2', /* cancel */ | 2232 MOD_MASK_SHIFT, '&', '0', '@', '2', // cancel |
2234 MOD_MASK_SHIFT, '*', '1', '@', '4', /* command */ | 2233 MOD_MASK_SHIFT, '*', '1', '@', '4', // command |
2235 MOD_MASK_SHIFT, '*', '2', '@', '5', /* copy */ | 2234 MOD_MASK_SHIFT, '*', '2', '@', '5', // copy |
2236 MOD_MASK_SHIFT, '*', '3', '@', '6', /* create */ | 2235 MOD_MASK_SHIFT, '*', '3', '@', '6', // create |
2237 MOD_MASK_SHIFT, '*', '4', 'k', 'D', /* delete char */ | 2236 MOD_MASK_SHIFT, '*', '4', 'k', 'D', // delete char |
2238 MOD_MASK_SHIFT, '*', '5', 'k', 'L', /* delete line */ | 2237 MOD_MASK_SHIFT, '*', '5', 'k', 'L', // delete line |
2239 MOD_MASK_SHIFT, '*', '7', '@', '7', /* end */ | 2238 MOD_MASK_SHIFT, '*', '7', '@', '7', // end |
2240 MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_END, '@', '7', /* end */ | 2239 MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_END, '@', '7', // end |
2241 MOD_MASK_SHIFT, '*', '9', '@', '9', /* exit */ | 2240 MOD_MASK_SHIFT, '*', '9', '@', '9', // exit |
2242 MOD_MASK_SHIFT, '*', '0', '@', '0', /* find */ | 2241 MOD_MASK_SHIFT, '*', '0', '@', '0', // find |
2243 MOD_MASK_SHIFT, '#', '1', '%', '1', /* help */ | 2242 MOD_MASK_SHIFT, '#', '1', '%', '1', // help |
2244 MOD_MASK_SHIFT, '#', '2', 'k', 'h', /* home */ | 2243 MOD_MASK_SHIFT, '#', '2', 'k', 'h', // home |
2245 MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_HOME, 'k', 'h', /* home */ | 2244 MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_HOME, 'k', 'h', // home |
2246 MOD_MASK_SHIFT, '#', '3', 'k', 'I', /* insert */ | 2245 MOD_MASK_SHIFT, '#', '3', 'k', 'I', // insert |
2247 MOD_MASK_SHIFT, '#', '4', 'k', 'l', /* left arrow */ | 2246 MOD_MASK_SHIFT, '#', '4', 'k', 'l', // left arrow |
2248 MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_LEFT, 'k', 'l', /* left arrow */ | 2247 MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_LEFT, 'k', 'l', // left arrow |
2249 MOD_MASK_SHIFT, '%', 'a', '%', '3', /* message */ | 2248 MOD_MASK_SHIFT, '%', 'a', '%', '3', // message |
2250 MOD_MASK_SHIFT, '%', 'b', '%', '4', /* move */ | 2249 MOD_MASK_SHIFT, '%', 'b', '%', '4', // move |
2251 MOD_MASK_SHIFT, '%', 'c', '%', '5', /* next */ | 2250 MOD_MASK_SHIFT, '%', 'c', '%', '5', // next |
2252 MOD_MASK_SHIFT, '%', 'd', '%', '7', /* options */ | 2251 MOD_MASK_SHIFT, '%', 'd', '%', '7', // options |
2253 MOD_MASK_SHIFT, '%', 'e', '%', '8', /* previous */ | 2252 MOD_MASK_SHIFT, '%', 'e', '%', '8', // previous |
2254 MOD_MASK_SHIFT, '%', 'f', '%', '9', /* print */ | 2253 MOD_MASK_SHIFT, '%', 'f', '%', '9', // print |
2255 MOD_MASK_SHIFT, '%', 'g', '%', '0', /* redo */ | 2254 MOD_MASK_SHIFT, '%', 'g', '%', '0', // redo |
2256 MOD_MASK_SHIFT, '%', 'h', '&', '3', /* replace */ | 2255 MOD_MASK_SHIFT, '%', 'h', '&', '3', // replace |
2257 MOD_MASK_SHIFT, '%', 'i', 'k', 'r', /* right arr. */ | 2256 MOD_MASK_SHIFT, '%', 'i', 'k', 'r', // right arr. |
2258 MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_RIGHT, 'k', 'r', /* right arr. */ | 2257 MOD_MASK_CTRL, KS_EXTRA, (int)KE_C_RIGHT, 'k', 'r', // right arr. |
2259 MOD_MASK_SHIFT, '%', 'j', '&', '5', /* resume */ | 2258 MOD_MASK_SHIFT, '%', 'j', '&', '5', // resume |
2260 MOD_MASK_SHIFT, '!', '1', '&', '6', /* save */ | 2259 MOD_MASK_SHIFT, '!', '1', '&', '6', // save |
2261 MOD_MASK_SHIFT, '!', '2', '&', '7', /* suspend */ | 2260 MOD_MASK_SHIFT, '!', '2', '&', '7', // suspend |
2262 MOD_MASK_SHIFT, '!', '3', '&', '8', /* undo */ | 2261 MOD_MASK_SHIFT, '!', '3', '&', '8', // undo |
2263 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_UP, 'k', 'u', /* up arrow */ | 2262 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_UP, 'k', 'u', // up arrow |
2264 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_DOWN, 'k', 'd', /* down arrow */ | 2263 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_DOWN, 'k', 'd', // down arrow |
2265 | 2264 |
2266 /* vt100 F1 */ | 2265 // vt100 F1 |
2267 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF1, KS_EXTRA, (int)KE_XF1, | 2266 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF1, KS_EXTRA, (int)KE_XF1, |
2268 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF2, KS_EXTRA, (int)KE_XF2, | 2267 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF2, KS_EXTRA, (int)KE_XF2, |
2269 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF3, KS_EXTRA, (int)KE_XF3, | 2268 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF3, KS_EXTRA, (int)KE_XF3, |
2270 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF4, KS_EXTRA, (int)KE_XF4, | 2269 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_XF4, KS_EXTRA, (int)KE_XF4, |
2271 | 2270 |
2272 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F1, 'k', '1', /* F1 */ | 2271 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F1, 'k', '1', // F1 |
2273 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F2, 'k', '2', | 2272 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F2, 'k', '2', |
2274 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F3, 'k', '3', | 2273 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F3, 'k', '3', |
2275 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F4, 'k', '4', | 2274 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F4, 'k', '4', |
2276 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F5, 'k', '5', | 2275 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F5, 'k', '5', |
2277 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F6, 'k', '6', | 2276 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F6, 'k', '6', |
2278 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F7, 'k', '7', | 2277 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F7, 'k', '7', |
2279 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F8, 'k', '8', | 2278 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F8, 'k', '8', |
2280 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F9, 'k', '9', | 2279 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F9, 'k', '9', |
2281 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F10, 'k', ';', /* F10 */ | 2280 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F10, 'k', ';', // F10 |
2282 | 2281 |
2283 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F11, 'F', '1', | 2282 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F11, 'F', '1', |
2284 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F12, 'F', '2', | 2283 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F12, 'F', '2', |
2285 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F13, 'F', '3', | 2284 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F13, 'F', '3', |
2286 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F14, 'F', '4', | 2285 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F14, 'F', '4', |
2308 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F34, 'F', 'O', | 2307 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F34, 'F', 'O', |
2309 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F35, 'F', 'P', | 2308 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F35, 'F', 'P', |
2310 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F36, 'F', 'Q', | 2309 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F36, 'F', 'Q', |
2311 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F37, 'F', 'R', | 2310 MOD_MASK_SHIFT, KS_EXTRA, (int)KE_S_F37, 'F', 'R', |
2312 | 2311 |
2313 /* TAB pseudo code*/ | 2312 // TAB pseudo code |
2314 MOD_MASK_SHIFT, 'k', 'B', KS_EXTRA, (int)KE_TAB, | 2313 MOD_MASK_SHIFT, 'k', 'B', KS_EXTRA, (int)KE_TAB, |
2315 | 2314 |
2316 NUL | 2315 NUL |
2317 }; | 2316 }; |
2318 | 2317 |
2319 static struct key_name_entry | 2318 static struct key_name_entry |
2320 { | 2319 { |
2321 int key; /* Special key code or ascii value */ | 2320 int key; // Special key code or ascii value |
2322 char_u *name; /* Name of key */ | 2321 char_u *name; // Name of key |
2323 } key_names_table[] = | 2322 } key_names_table[] = |
2324 { | 2323 { |
2325 {' ', (char_u *)"Space"}, | 2324 {' ', (char_u *)"Space"}, |
2326 {TAB, (char_u *)"Tab"}, | 2325 {TAB, (char_u *)"Tab"}, |
2327 {K_TAB, (char_u *)"Tab"}, | 2326 {K_TAB, (char_u *)"Tab"}, |
2328 {NL, (char_u *)"NL"}, | 2327 {NL, (char_u *)"NL"}, |
2329 {NL, (char_u *)"NewLine"}, /* Alternative name */ | 2328 {NL, (char_u *)"NewLine"}, // Alternative name |
2330 {NL, (char_u *)"LineFeed"}, /* Alternative name */ | 2329 {NL, (char_u *)"LineFeed"}, // Alternative name |
2331 {NL, (char_u *)"LF"}, /* Alternative name */ | 2330 {NL, (char_u *)"LF"}, // Alternative name |
2332 {CAR, (char_u *)"CR"}, | 2331 {CAR, (char_u *)"CR"}, |
2333 {CAR, (char_u *)"Return"}, /* Alternative name */ | 2332 {CAR, (char_u *)"Return"}, // Alternative name |
2334 {CAR, (char_u *)"Enter"}, /* Alternative name */ | 2333 {CAR, (char_u *)"Enter"}, // Alternative name |
2335 {K_BS, (char_u *)"BS"}, | 2334 {K_BS, (char_u *)"BS"}, |
2336 {K_BS, (char_u *)"BackSpace"}, /* Alternative name */ | 2335 {K_BS, (char_u *)"BackSpace"}, // Alternative name |
2337 {ESC, (char_u *)"Esc"}, | 2336 {ESC, (char_u *)"Esc"}, |
2338 {CSI, (char_u *)"CSI"}, | 2337 {CSI, (char_u *)"CSI"}, |
2339 {K_CSI, (char_u *)"xCSI"}, | 2338 {K_CSI, (char_u *)"xCSI"}, |
2340 {'|', (char_u *)"Bar"}, | 2339 {'|', (char_u *)"Bar"}, |
2341 {'\\', (char_u *)"Bslash"}, | 2340 {'\\', (char_u *)"Bslash"}, |
2342 {K_DEL, (char_u *)"Del"}, | 2341 {K_DEL, (char_u *)"Del"}, |
2343 {K_DEL, (char_u *)"Delete"}, /* Alternative name */ | 2342 {K_DEL, (char_u *)"Delete"}, // Alternative name |
2344 {K_KDEL, (char_u *)"kDel"}, | 2343 {K_KDEL, (char_u *)"kDel"}, |
2345 {K_UP, (char_u *)"Up"}, | 2344 {K_UP, (char_u *)"Up"}, |
2346 {K_DOWN, (char_u *)"Down"}, | 2345 {K_DOWN, (char_u *)"Down"}, |
2347 {K_LEFT, (char_u *)"Left"}, | 2346 {K_LEFT, (char_u *)"Left"}, |
2348 {K_RIGHT, (char_u *)"Right"}, | 2347 {K_RIGHT, (char_u *)"Right"}, |
2400 {K_XF4, (char_u *)"xF4"}, | 2399 {K_XF4, (char_u *)"xF4"}, |
2401 | 2400 |
2402 {K_HELP, (char_u *)"Help"}, | 2401 {K_HELP, (char_u *)"Help"}, |
2403 {K_UNDO, (char_u *)"Undo"}, | 2402 {K_UNDO, (char_u *)"Undo"}, |
2404 {K_INS, (char_u *)"Insert"}, | 2403 {K_INS, (char_u *)"Insert"}, |
2405 {K_INS, (char_u *)"Ins"}, /* Alternative name */ | 2404 {K_INS, (char_u *)"Ins"}, // Alternative name |
2406 {K_KINS, (char_u *)"kInsert"}, | 2405 {K_KINS, (char_u *)"kInsert"}, |
2407 {K_HOME, (char_u *)"Home"}, | 2406 {K_HOME, (char_u *)"Home"}, |
2408 {K_KHOME, (char_u *)"kHome"}, | 2407 {K_KHOME, (char_u *)"kHome"}, |
2409 {K_XHOME, (char_u *)"xHome"}, | 2408 {K_XHOME, (char_u *)"xHome"}, |
2410 {K_ZHOME, (char_u *)"zHome"}, | 2409 {K_ZHOME, (char_u *)"zHome"}, |
2469 {K_RIGHTRELEASE, (char_u *)"RightRelease"}, | 2468 {K_RIGHTRELEASE, (char_u *)"RightRelease"}, |
2470 {K_MOUSEDOWN, (char_u *)"ScrollWheelUp"}, | 2469 {K_MOUSEDOWN, (char_u *)"ScrollWheelUp"}, |
2471 {K_MOUSEUP, (char_u *)"ScrollWheelDown"}, | 2470 {K_MOUSEUP, (char_u *)"ScrollWheelDown"}, |
2472 {K_MOUSELEFT, (char_u *)"ScrollWheelRight"}, | 2471 {K_MOUSELEFT, (char_u *)"ScrollWheelRight"}, |
2473 {K_MOUSERIGHT, (char_u *)"ScrollWheelLeft"}, | 2472 {K_MOUSERIGHT, (char_u *)"ScrollWheelLeft"}, |
2474 {K_MOUSEDOWN, (char_u *)"MouseDown"}, /* OBSOLETE: Use */ | 2473 {K_MOUSEDOWN, (char_u *)"MouseDown"}, // OBSOLETE: Use |
2475 {K_MOUSEUP, (char_u *)"MouseUp"}, /* ScrollWheelXXX instead */ | 2474 {K_MOUSEUP, (char_u *)"MouseUp"}, // ScrollWheelXXX instead |
2476 {K_X1MOUSE, (char_u *)"X1Mouse"}, | 2475 {K_X1MOUSE, (char_u *)"X1Mouse"}, |
2477 {K_X1DRAG, (char_u *)"X1Drag"}, | 2476 {K_X1DRAG, (char_u *)"X1Drag"}, |
2478 {K_X1RELEASE, (char_u *)"X1Release"}, | 2477 {K_X1RELEASE, (char_u *)"X1Release"}, |
2479 {K_X2MOUSE, (char_u *)"X2Mouse"}, | 2478 {K_X2MOUSE, (char_u *)"X2Mouse"}, |
2480 {K_X2DRAG, (char_u *)"X2Drag"}, | 2479 {K_X2DRAG, (char_u *)"X2Drag"}, |
2486 #endif | 2485 #endif |
2487 {K_PLUG, (char_u *)"Plug"}, | 2486 {K_PLUG, (char_u *)"Plug"}, |
2488 {K_CURSORHOLD, (char_u *)"CursorHold"}, | 2487 {K_CURSORHOLD, (char_u *)"CursorHold"}, |
2489 {K_IGNORE, (char_u *)"Ignore"}, | 2488 {K_IGNORE, (char_u *)"Ignore"}, |
2490 {0, NULL} | 2489 {0, NULL} |
2491 /* NOTE: When adding a long name update MAX_KEY_NAME_LEN. */ | 2490 // NOTE: When adding a long name update MAX_KEY_NAME_LEN. |
2492 }; | 2491 }; |
2493 | 2492 |
2494 #define KEY_NAMES_TABLE_LEN (sizeof(key_names_table) / sizeof(struct key_name_entry)) | 2493 #define KEY_NAMES_TABLE_LEN (sizeof(key_names_table) / sizeof(struct key_name_entry)) |
2495 | 2494 |
2496 /* | 2495 /* |
2520 int key0; | 2519 int key0; |
2521 int key1; | 2520 int key1; |
2522 | 2521 |
2523 if (*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT)) | 2522 if (*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT)) |
2524 { | 2523 { |
2525 /* TAB is a special case */ | 2524 // TAB is a special case |
2526 if (key == TAB && (*modifiers & MOD_MASK_SHIFT)) | 2525 if (key == TAB && (*modifiers & MOD_MASK_SHIFT)) |
2527 { | 2526 { |
2528 *modifiers &= ~MOD_MASK_SHIFT; | 2527 *modifiers &= ~MOD_MASK_SHIFT; |
2529 return K_S_TAB; | 2528 return K_S_TAB; |
2530 } | 2529 } |
2585 char_u *s; | 2584 char_u *s; |
2586 | 2585 |
2587 string[0] = '<'; | 2586 string[0] = '<'; |
2588 idx = 1; | 2587 idx = 1; |
2589 | 2588 |
2590 /* Key that stands for a normal character. */ | 2589 // Key that stands for a normal character. |
2591 if (IS_SPECIAL(c) && KEY2TERMCAP0(c) == KS_KEY) | 2590 if (IS_SPECIAL(c) && KEY2TERMCAP0(c) == KS_KEY) |
2592 c = KEY2TERMCAP1(c); | 2591 c = KEY2TERMCAP1(c); |
2593 | 2592 |
2594 /* | 2593 /* |
2595 * Translate shifted special keys into unshifted keys and set modifier. | 2594 * Translate shifted special keys into unshifted keys and set modifier. |
2606 modifier_keys_table[i + 4]); | 2605 modifier_keys_table[i + 4]); |
2607 break; | 2606 break; |
2608 } | 2607 } |
2609 } | 2608 } |
2610 | 2609 |
2611 /* try to find the key in the special key table */ | 2610 // try to find the key in the special key table |
2612 table_idx = find_special_key_in_table(c); | 2611 table_idx = find_special_key_in_table(c); |
2613 | 2612 |
2614 /* | 2613 /* |
2615 * When not a known special key, and not a printable character, try to | 2614 * When not a known special key, and not a printable character, try to |
2616 * extract modifiers. | 2615 * extract modifiers. |
2621 && (!vim_isprintc(c) || (c & 0x7f) == ' ') | 2620 && (!vim_isprintc(c) || (c & 0x7f) == ' ') |
2622 && (c & 0x80)) | 2621 && (c & 0x80)) |
2623 { | 2622 { |
2624 c &= 0x7f; | 2623 c &= 0x7f; |
2625 modifiers |= MOD_MASK_ALT; | 2624 modifiers |= MOD_MASK_ALT; |
2626 /* try again, to find the un-alted key in the special key table */ | 2625 // try again, to find the un-alted key in the special key table |
2627 table_idx = find_special_key_in_table(c); | 2626 table_idx = find_special_key_in_table(c); |
2628 } | 2627 } |
2629 if (table_idx < 0 && !vim_isprintc(c) && c < ' ') | 2628 if (table_idx < 0 && !vim_isprintc(c) && c < ' ') |
2630 { | 2629 { |
2631 #ifdef EBCDIC | 2630 #ifdef EBCDIC |
2635 #endif | 2634 #endif |
2636 modifiers |= MOD_MASK_CTRL; | 2635 modifiers |= MOD_MASK_CTRL; |
2637 } | 2636 } |
2638 } | 2637 } |
2639 | 2638 |
2640 /* translate the modifier into a string */ | 2639 // translate the modifier into a string |
2641 for (i = 0; mod_mask_table[i].name != 'A'; i++) | 2640 for (i = 0; mod_mask_table[i].name != 'A'; i++) |
2642 if ((modifiers & mod_mask_table[i].mod_mask) | 2641 if ((modifiers & mod_mask_table[i].mod_mask) |
2643 == mod_mask_table[i].mod_flag) | 2642 == mod_mask_table[i].mod_flag) |
2644 { | 2643 { |
2645 string[idx++] = mod_mask_table[i].name; | 2644 string[idx++] = mod_mask_table[i].name; |
2646 string[idx++] = (char_u)'-'; | 2645 string[idx++] = (char_u)'-'; |
2647 } | 2646 } |
2648 | 2647 |
2649 if (table_idx < 0) /* unknown special key, may output t_xx */ | 2648 if (table_idx < 0) // unknown special key, may output t_xx |
2650 { | 2649 { |
2651 if (IS_SPECIAL(c)) | 2650 if (IS_SPECIAL(c)) |
2652 { | 2651 { |
2653 string[idx++] = 't'; | 2652 string[idx++] = 't'; |
2654 string[idx++] = '_'; | 2653 string[idx++] = '_'; |
2655 string[idx++] = KEY2TERMCAP0(c); | 2654 string[idx++] = KEY2TERMCAP0(c); |
2656 string[idx++] = KEY2TERMCAP1(c); | 2655 string[idx++] = KEY2TERMCAP1(c); |
2657 } | 2656 } |
2658 /* Not a special key, only modifiers, output directly */ | 2657 // Not a special key, only modifiers, output directly |
2659 else | 2658 else |
2660 { | 2659 { |
2661 if (has_mbyte && (*mb_char2len)(c) > 1) | 2660 if (has_mbyte && (*mb_char2len)(c) > 1) |
2662 idx += (*mb_char2bytes)(c, string + idx); | 2661 idx += (*mb_char2bytes)(c, string + idx); |
2663 else if (vim_isprintc(c)) | 2662 else if (vim_isprintc(c)) |
2668 while (*s) | 2667 while (*s) |
2669 string[idx++] = *s++; | 2668 string[idx++] = *s++; |
2670 } | 2669 } |
2671 } | 2670 } |
2672 } | 2671 } |
2673 else /* use name of special key */ | 2672 else // use name of special key |
2674 { | 2673 { |
2675 size_t len = STRLEN(key_names_table[table_idx].name); | 2674 size_t len = STRLEN(key_names_table[table_idx].name); |
2676 | 2675 |
2677 if (len + idx + 2 <= MAX_KEY_NAME_LEN) | 2676 if (len + idx + 2 <= MAX_KEY_NAME_LEN) |
2678 { | 2677 { |
2721 int | 2720 int |
2722 special_to_buf(int key, int modifiers, int keycode, char_u *dst) | 2721 special_to_buf(int key, int modifiers, int keycode, char_u *dst) |
2723 { | 2722 { |
2724 int dlen = 0; | 2723 int dlen = 0; |
2725 | 2724 |
2726 /* Put the appropriate modifier in a string */ | 2725 // Put the appropriate modifier in a string |
2727 if (modifiers != 0) | 2726 if (modifiers != 0) |
2728 { | 2727 { |
2729 dst[dlen++] = K_SPECIAL; | 2728 dst[dlen++] = K_SPECIAL; |
2730 dst[dlen++] = KS_MODIFIER; | 2729 dst[dlen++] = KS_MODIFIER; |
2731 dst[dlen++] = modifiers; | 2730 dst[dlen++] = modifiers; |
2774 | 2773 |
2775 src = *srcp; | 2774 src = *srcp; |
2776 if (src[0] != '<') | 2775 if (src[0] != '<') |
2777 return 0; | 2776 return 0; |
2778 | 2777 |
2779 /* Find end of modifier list */ | 2778 // Find end of modifier list |
2780 last_dash = src; | 2779 last_dash = src; |
2781 for (bp = src + 1; *bp == '-' || vim_isIDc(*bp); bp++) | 2780 for (bp = src + 1; *bp == '-' || vim_isIDc(*bp); bp++) |
2782 { | 2781 { |
2783 if (*bp == '-') | 2782 if (*bp == '-') |
2784 { | 2783 { |
2798 && bp[3] == '>') | 2797 && bp[3] == '>') |
2799 bp += 2; | 2798 bp += 2; |
2800 } | 2799 } |
2801 } | 2800 } |
2802 if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3]) | 2801 if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3]) |
2803 bp += 3; /* skip t_xx, xx may be '-' or '>' */ | 2802 bp += 3; // skip t_xx, xx may be '-' or '>' |
2804 else if (STRNICMP(bp, "char-", 5) == 0) | 2803 else if (STRNICMP(bp, "char-", 5) == 0) |
2805 { | 2804 { |
2806 vim_str2nr(bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0, TRUE); | 2805 vim_str2nr(bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0, TRUE); |
2807 if (l == 0) | 2806 if (l == 0) |
2808 { | 2807 { |
2812 bp += l + 5; | 2811 bp += l + 5; |
2813 break; | 2812 break; |
2814 } | 2813 } |
2815 } | 2814 } |
2816 | 2815 |
2817 if (*bp == '>') /* found matching '>' */ | 2816 if (*bp == '>') // found matching '>' |
2818 { | 2817 { |
2819 end_of_name = bp + 1; | 2818 end_of_name = bp + 1; |
2820 | 2819 |
2821 /* Which modifiers are given? */ | 2820 // Which modifiers are given? |
2822 modifiers = 0x0; | 2821 modifiers = 0x0; |
2823 for (bp = src + 1; bp < last_dash; bp++) | 2822 for (bp = src + 1; bp < last_dash; bp++) |
2824 { | 2823 { |
2825 if (*bp != '-') | 2824 if (*bp != '-') |
2826 { | 2825 { |
2827 bit = name_to_mod_mask(*bp); | 2826 bit = name_to_mod_mask(*bp); |
2828 if (bit == 0x0) | 2827 if (bit == 0x0) |
2829 break; /* Illegal modifier name */ | 2828 break; // Illegal modifier name |
2830 modifiers |= bit; | 2829 modifiers |= bit; |
2831 } | 2830 } |
2832 } | 2831 } |
2833 | 2832 |
2834 /* | 2833 /* |
2837 if (bp >= last_dash) | 2836 if (bp >= last_dash) |
2838 { | 2837 { |
2839 if (STRNICMP(last_dash + 1, "char-", 5) == 0 | 2838 if (STRNICMP(last_dash + 1, "char-", 5) == 0 |
2840 && VIM_ISDIGIT(last_dash[6])) | 2839 && VIM_ISDIGIT(last_dash[6])) |
2841 { | 2840 { |
2842 /* <Char-123> or <Char-033> or <Char-0x33> */ | 2841 // <Char-123> or <Char-033> or <Char-0x33> |
2843 vim_str2nr(last_dash + 6, NULL, &l, STR2NR_ALL, NULL, | 2842 vim_str2nr(last_dash + 6, NULL, &l, STR2NR_ALL, NULL, |
2844 &n, 0, TRUE); | 2843 &n, 0, TRUE); |
2845 if (l == 0) | 2844 if (l == 0) |
2846 { | 2845 { |
2847 emsg(_(e_invarg)); | 2846 emsg(_(e_invarg)); |
2851 } | 2850 } |
2852 else | 2851 else |
2853 { | 2852 { |
2854 int off = 1; | 2853 int off = 1; |
2855 | 2854 |
2856 /* Modifier with single letter, or special key name. */ | 2855 // Modifier with single letter, or special key name. |
2857 if (in_string && last_dash[1] == '\\' && last_dash[2] == '"') | 2856 if (in_string && last_dash[1] == '\\' && last_dash[2] == '"') |
2858 off = 2; | 2857 off = 2; |
2859 if (has_mbyte) | 2858 if (has_mbyte) |
2860 l = mb_ptr2len(last_dash + off); | 2859 l = mb_ptr2len(last_dash + off); |
2861 else | 2860 else |
2882 */ | 2881 */ |
2883 key = simplify_key(key, &modifiers); | 2882 key = simplify_key(key, &modifiers); |
2884 | 2883 |
2885 if (!keycode) | 2884 if (!keycode) |
2886 { | 2885 { |
2887 /* don't want keycode, use single byte code */ | 2886 // don't want keycode, use single byte code |
2888 if (key == K_BS) | 2887 if (key == K_BS) |
2889 key = BS; | 2888 key = BS; |
2890 else if (key == K_DEL || key == K_KDEL) | 2889 else if (key == K_DEL || key == K_KDEL) |
2891 key = DEL; | 2890 key = DEL; |
2892 } | 2891 } |
2946 #endif | 2945 #endif |
2947 ) | 2946 ) |
2948 { | 2947 { |
2949 key = Ctrl_chr(key); | 2948 key = Ctrl_chr(key); |
2950 modifiers &= ~MOD_MASK_CTRL; | 2949 modifiers &= ~MOD_MASK_CTRL; |
2951 /* <C-@> is <Nul> */ | 2950 // <C-@> is <Nul> |
2952 if (key == 0) | 2951 if (key == 0) |
2953 key = K_ZERO; | 2952 key = K_ZERO; |
2954 if (did_simplify != NULL) | 2953 if (did_simplify != NULL) |
2955 *did_simplify = TRUE; | 2954 *did_simplify = TRUE; |
2956 } | 2955 } |
2957 | 2956 |
2958 #ifdef MACOS_X | 2957 #ifdef MACOS_X |
2959 /* Command-key really special, no fancynest */ | 2958 // Command-key really special, no fancynest |
2960 if (!(modifiers & MOD_MASK_CMD)) | 2959 if (!(modifiers & MOD_MASK_CMD)) |
2961 #endif | 2960 #endif |
2962 if (simplify && (modifiers & MOD_MASK_ALT) && key < 0x80 | 2961 if (simplify && (modifiers & MOD_MASK_ALT) && key < 0x80 |
2963 && !enc_dbcs) // avoid creating a lead byte | 2962 && !enc_dbcs) // avoid creating a lead byte |
2964 { | 2963 { |
2965 key |= 0x80; | 2964 key |= 0x80; |
2966 modifiers &= ~MOD_MASK_ALT; /* remove the META modifier */ | 2965 modifiers &= ~MOD_MASK_ALT; // remove the META modifier |
2967 if (did_simplify != NULL) | 2966 if (did_simplify != NULL) |
2968 *did_simplify = TRUE; | 2967 *did_simplify = TRUE; |
2969 } | 2968 } |
2970 | 2969 |
2971 *modp = modifiers; | 2970 *modp = modifiers; |
3055 * argument. | 3054 * argument. |
3056 */ | 3055 */ |
3057 int | 3056 int |
3058 get_fileformat_force( | 3057 get_fileformat_force( |
3059 buf_T *buf, | 3058 buf_T *buf, |
3060 exarg_T *eap) /* can be NULL! */ | 3059 exarg_T *eap) // can be NULL! |
3061 { | 3060 { |
3062 int c; | 3061 int c; |
3063 | 3062 |
3064 if (eap != NULL && eap->force_ff != 0) | 3063 if (eap != NULL && eap->force_ff != 0) |
3065 c = eap->force_ff; | 3064 c = eap->force_ff; |
3083 * Note: Does _not_ set global value of 'textmode'! | 3082 * Note: Does _not_ set global value of 'textmode'! |
3084 */ | 3083 */ |
3085 void | 3084 void |
3086 set_fileformat( | 3085 set_fileformat( |
3087 int t, | 3086 int t, |
3088 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */ | 3087 int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
3089 { | 3088 { |
3090 char *p = NULL; | 3089 char *p = NULL; |
3091 | 3090 |
3092 switch (t) | 3091 switch (t) |
3093 { | 3092 { |
3106 } | 3105 } |
3107 if (p != NULL) | 3106 if (p != NULL) |
3108 set_string_option_direct((char_u *)"ff", -1, (char_u *)p, | 3107 set_string_option_direct((char_u *)"ff", -1, (char_u *)p, |
3109 OPT_FREE | opt_flags, 0); | 3108 OPT_FREE | opt_flags, 0); |
3110 | 3109 |
3111 /* This may cause the buffer to become (un)modified. */ | 3110 // This may cause the buffer to become (un)modified. |
3112 check_status(curbuf); | 3111 check_status(curbuf); |
3113 redraw_tabline = TRUE; | 3112 redraw_tabline = TRUE; |
3114 #ifdef FEAT_TITLE | 3113 #ifdef FEAT_TITLE |
3115 need_maketitle = TRUE; /* set window title later */ | 3114 need_maketitle = TRUE; // set window title later |
3116 #endif | 3115 #endif |
3117 } | 3116 } |
3118 | 3117 |
3119 /* | 3118 /* |
3120 * Return the default fileformat from 'fileformats'. | 3119 * Return the default fileformat from 'fileformats'. |
3163 retval = -1; | 3162 retval = -1; |
3164 } | 3163 } |
3165 else | 3164 else |
3166 { | 3165 { |
3167 #ifdef FEAT_GUI_MSWIN | 3166 #ifdef FEAT_GUI_MSWIN |
3168 /* Don't hide the pointer while executing a shell command. */ | 3167 // Don't hide the pointer while executing a shell command. |
3169 gui_mch_mousehide(FALSE); | 3168 gui_mch_mousehide(FALSE); |
3170 #endif | 3169 #endif |
3171 #ifdef FEAT_GUI | 3170 #ifdef FEAT_GUI |
3172 ++hold_gui_events; | 3171 ++hold_gui_events; |
3173 #endif | 3172 #endif |
3174 /* The external command may update a tags file, clear cached tags. */ | 3173 // The external command may update a tags file, clear cached tags. |
3175 tag_freematch(); | 3174 tag_freematch(); |
3176 | 3175 |
3177 if (cmd == NULL || *p_sxq == NUL) | 3176 if (cmd == NULL || *p_sxq == NUL) |
3178 retval = mch_call_shell(cmd, opt); | 3177 retval = mch_call_shell(cmd, opt); |
3179 else | 3178 else |
3267 { | 3266 { |
3268 char_u ffname[MAXPATHL]; | 3267 char_u ffname[MAXPATHL]; |
3269 char_u *t1; | 3268 char_u *t1; |
3270 char_u *t2; | 3269 char_u *t2; |
3271 | 3270 |
3272 /* safety check */ | 3271 // safety check |
3273 if (f1 == NULL || f2 == NULL) | 3272 if (f1 == NULL || f2 == NULL) |
3274 return FALSE; | 3273 return FALSE; |
3275 | 3274 |
3276 (void)vim_FullName(f1, ffname, MAXPATHL, FALSE); | 3275 (void)vim_FullName(f1, ffname, MAXPATHL, FALSE); |
3277 t1 = gettail_sep(ffname); | 3276 t1 = gettail_sep(ffname); |
3325 */ | 3324 */ |
3326 static int | 3325 static int |
3327 illegal_slash(const char *name) | 3326 illegal_slash(const char *name) |
3328 { | 3327 { |
3329 if (name[0] == NUL) | 3328 if (name[0] == NUL) |
3330 return FALSE; /* no file name is not illegal */ | 3329 return FALSE; // no file name is not illegal |
3331 if (name[strlen(name) - 1] != '/') | 3330 if (name[strlen(name) - 1] != '/') |
3332 return FALSE; /* no trailing slash */ | 3331 return FALSE; // no trailing slash |
3333 if (mch_isdir((char_u *)name)) | 3332 if (mch_isdir((char_u *)name)) |
3334 return FALSE; /* trailing slash for a directory */ | 3333 return FALSE; // trailing slash for a directory |
3335 return TRUE; | 3334 return TRUE; |
3336 } | 3335 } |
3337 | 3336 |
3338 /* | 3337 /* |
3339 * Special implementation of mch_stat() for Solaris. | 3338 * Special implementation of mch_stat() for Solaris. |
3340 */ | 3339 */ |
3341 int | 3340 int |
3342 vim_stat(const char *name, stat_T *stp) | 3341 vim_stat(const char *name, stat_T *stp) |
3343 { | 3342 { |
3344 /* On Solaris stat() accepts "file/" as if it was "file". Return -1 if | 3343 // On Solaris stat() accepts "file/" as if it was "file". Return -1 if |
3345 * the name ends in "/" and it's not a directory. */ | 3344 // the name ends in "/" and it's not a directory. |
3346 return illegal_slash(name) ? -1 : stat(name, stp); | 3345 return illegal_slash(name) ? -1 : stat(name, stp); |
3347 } | 3346 } |
3348 #endif | 3347 #endif |
3349 | 3348 |
3350 #if defined(CURSOR_SHAPE) || defined(PROTO) | 3349 #if defined(CURSOR_SHAPE) || defined(PROTO) |
3353 * Handling of cursor and mouse pointer shapes in various modes. | 3352 * Handling of cursor and mouse pointer shapes in various modes. |
3354 */ | 3353 */ |
3355 | 3354 |
3356 cursorentry_T shape_table[SHAPE_IDX_COUNT] = | 3355 cursorentry_T shape_table[SHAPE_IDX_COUNT] = |
3357 { | 3356 { |
3358 /* The values will be filled in from the 'guicursor' and 'mouseshape' | 3357 // The values will be filled in from the 'guicursor' and 'mouseshape' |
3359 * defaults when Vim starts. | 3358 // defaults when Vim starts. |
3360 * Adjust the SHAPE_IDX_ defines when making changes! */ | 3359 // Adjust the SHAPE_IDX_ defines when making changes! |
3361 {0, 0, 0, 700L, 400L, 250L, 0, 0, "n", SHAPE_CURSOR+SHAPE_MOUSE}, | 3360 {0, 0, 0, 700L, 400L, 250L, 0, 0, "n", SHAPE_CURSOR+SHAPE_MOUSE}, |
3362 {0, 0, 0, 700L, 400L, 250L, 0, 0, "v", SHAPE_CURSOR+SHAPE_MOUSE}, | 3361 {0, 0, 0, 700L, 400L, 250L, 0, 0, "v", SHAPE_CURSOR+SHAPE_MOUSE}, |
3363 {0, 0, 0, 700L, 400L, 250L, 0, 0, "i", SHAPE_CURSOR+SHAPE_MOUSE}, | 3362 {0, 0, 0, 700L, 400L, 250L, 0, 0, "i", SHAPE_CURSOR+SHAPE_MOUSE}, |
3364 {0, 0, 0, 700L, 400L, 250L, 0, 0, "r", SHAPE_CURSOR+SHAPE_MOUSE}, | 3363 {0, 0, 0, 700L, 400L, 250L, 0, 0, "r", SHAPE_CURSOR+SHAPE_MOUSE}, |
3365 {0, 0, 0, 700L, 400L, 250L, 0, 0, "c", SHAPE_CURSOR+SHAPE_MOUSE}, | 3364 {0, 0, 0, 700L, 400L, 250L, 0, 0, "c", SHAPE_CURSOR+SHAPE_MOUSE}, |
3382 * Table with names for mouse shapes. Keep in sync with all the tables for | 3381 * Table with names for mouse shapes. Keep in sync with all the tables for |
3383 * mch_set_mouse_shape()!. | 3382 * mch_set_mouse_shape()!. |
3384 */ | 3383 */ |
3385 static char * mshape_names[] = | 3384 static char * mshape_names[] = |
3386 { | 3385 { |
3387 "arrow", /* default, must be the first one */ | 3386 "arrow", // default, must be the first one |
3388 "blank", /* hidden */ | 3387 "blank", // hidden |
3389 "beam", | 3388 "beam", |
3390 "updown", | 3389 "updown", |
3391 "udsizing", | 3390 "udsizing", |
3392 "leftright", | 3391 "leftright", |
3393 "lrsizing", | 3392 "lrsizing", |
3415 char_u *modep; | 3414 char_u *modep; |
3416 char_u *colonp; | 3415 char_u *colonp; |
3417 char_u *commap; | 3416 char_u *commap; |
3418 char_u *slashp; | 3417 char_u *slashp; |
3419 char_u *p, *endp; | 3418 char_u *p, *endp; |
3420 int idx = 0; /* init for GCC */ | 3419 int idx = 0; // init for GCC |
3421 int all_idx; | 3420 int all_idx; |
3422 int len; | 3421 int len; |
3423 int i; | 3422 int i; |
3424 long n; | 3423 long n; |
3425 int found_ve = FALSE; /* found "ve" flag */ | 3424 int found_ve = FALSE; // found "ve" flag |
3426 int round; | 3425 int round; |
3427 | 3426 |
3428 /* | 3427 /* |
3429 * First round: check for errors; second round: do it for real. | 3428 * First round: check for errors; second round: do it for real. |
3430 */ | 3429 */ |
3456 all_idx = -1; | 3455 all_idx = -1; |
3457 while (modep < colonp || all_idx >= 0) | 3456 while (modep < colonp || all_idx >= 0) |
3458 { | 3457 { |
3459 if (all_idx < 0) | 3458 if (all_idx < 0) |
3460 { | 3459 { |
3461 /* Find the mode. */ | 3460 // Find the mode. |
3462 if (modep[1] == '-' || modep[1] == ':') | 3461 if (modep[1] == '-' || modep[1] == ':') |
3463 len = 1; | 3462 len = 1; |
3464 else | 3463 else |
3465 len = 2; | 3464 len = 2; |
3466 if (len == 1 && TOLOWER_ASC(modep[0]) == 'a') | 3465 if (len == 1 && TOLOWER_ASC(modep[0]) == 'a') |
3485 else if (round == 2) | 3484 else if (round == 2) |
3486 { | 3485 { |
3487 #ifdef FEAT_MOUSESHAPE | 3486 #ifdef FEAT_MOUSESHAPE |
3488 if (what == SHAPE_MOUSE) | 3487 if (what == SHAPE_MOUSE) |
3489 { | 3488 { |
3490 /* Set the default, for the missing parts */ | 3489 // Set the default, for the missing parts |
3491 shape_table[idx].mshape = 0; | 3490 shape_table[idx].mshape = 0; |
3492 } | 3491 } |
3493 else | 3492 else |
3494 #endif | 3493 #endif |
3495 { | 3494 { |
3496 /* Set the defaults, for the missing parts */ | 3495 // Set the defaults, for the missing parts |
3497 shape_table[idx].shape = SHAPE_BLOCK; | 3496 shape_table[idx].shape = SHAPE_BLOCK; |
3498 shape_table[idx].blinkwait = 700L; | 3497 shape_table[idx].blinkwait = 700L; |
3499 shape_table[idx].blinkon = 400L; | 3498 shape_table[idx].blinkon = 400L; |
3500 shape_table[idx].blinkoff = 250L; | 3499 shape_table[idx].blinkoff = 250L; |
3501 } | 3500 } |
3502 } | 3501 } |
3503 | 3502 |
3504 /* Parse the part after the colon */ | 3503 // Parse the part after the colon |
3505 for (p = colonp + 1; *p && *p != ','; ) | 3504 for (p = colonp + 1; *p && *p != ','; ) |
3506 { | 3505 { |
3507 #ifdef FEAT_MOUSESHAPE | 3506 #ifdef FEAT_MOUSESHAPE |
3508 if (what == SHAPE_MOUSE) | 3507 if (what == SHAPE_MOUSE) |
3509 { | 3508 { |
3528 p += len; | 3527 p += len; |
3529 break; | 3528 break; |
3530 } | 3529 } |
3531 } | 3530 } |
3532 } | 3531 } |
3533 else /* if (what == SHAPE_MOUSE) */ | 3532 else // if (what == SHAPE_MOUSE) |
3534 #endif | 3533 #endif |
3535 { | 3534 { |
3536 /* | 3535 /* |
3537 * First handle the ones with a number argument. | 3536 * First handle the ones with a number argument. |
3538 */ | 3537 */ |
3552 { | 3551 { |
3553 p += len; | 3552 p += len; |
3554 if (!VIM_ISDIGIT(*p)) | 3553 if (!VIM_ISDIGIT(*p)) |
3555 return N_("E548: digit expected"); | 3554 return N_("E548: digit expected"); |
3556 n = getdigits(&p); | 3555 n = getdigits(&p); |
3557 if (len == 3) /* "ver" or "hor" */ | 3556 if (len == 3) // "ver" or "hor" |
3558 { | 3557 { |
3559 if (n == 0) | 3558 if (n == 0) |
3560 return N_("E549: Illegal percentage"); | 3559 return N_("E549: Illegal percentage"); |
3561 if (round == 2) | 3560 if (round == 2) |
3562 { | 3561 { |
3581 { | 3580 { |
3582 if (round == 2) | 3581 if (round == 2) |
3583 shape_table[idx].shape = SHAPE_BLOCK; | 3582 shape_table[idx].shape = SHAPE_BLOCK; |
3584 p += 5; | 3583 p += 5; |
3585 } | 3584 } |
3586 else /* must be a highlight group name then */ | 3585 else // must be a highlight group name then |
3587 { | 3586 { |
3588 endp = vim_strchr(p, '-'); | 3587 endp = vim_strchr(p, '-'); |
3589 if (commap == NULL) /* last part */ | 3588 if (commap == NULL) // last part |
3590 { | 3589 { |
3591 if (endp == NULL) | 3590 if (endp == NULL) |
3592 endp = p + STRLEN(p); /* find end of part */ | 3591 endp = p + STRLEN(p); // find end of part |
3593 } | 3592 } |
3594 else if (endp > commap || endp == NULL) | 3593 else if (endp > commap || endp == NULL) |
3595 endp = commap; | 3594 endp = commap; |
3596 slashp = vim_strchr(p, '/'); | 3595 slashp = vim_strchr(p, '/'); |
3597 if (slashp != NULL && slashp < endp) | 3596 if (slashp != NULL && slashp < endp) |
3598 { | 3597 { |
3599 /* "group/langmap_group" */ | 3598 // "group/langmap_group" |
3600 i = syn_check_group(p, (int)(slashp - p)); | 3599 i = syn_check_group(p, (int)(slashp - p)); |
3601 p = slashp + 1; | 3600 p = slashp + 1; |
3602 } | 3601 } |
3603 if (round == 2) | 3602 if (round == 2) |
3604 { | 3603 { |
3608 if (slashp != NULL && slashp < endp) | 3607 if (slashp != NULL && slashp < endp) |
3609 shape_table[idx].id = i; | 3608 shape_table[idx].id = i; |
3610 } | 3609 } |
3611 p = endp; | 3610 p = endp; |
3612 } | 3611 } |
3613 } /* if (what != SHAPE_MOUSE) */ | 3612 } // if (what != SHAPE_MOUSE) |
3614 | 3613 |
3615 if (*p == '-') | 3614 if (*p == '-') |
3616 ++p; | 3615 ++p; |
3617 } | 3616 } |
3618 } | 3617 } |
3620 if (*modep == ',') | 3619 if (*modep == ',') |
3621 ++modep; | 3620 ++modep; |
3622 } | 3621 } |
3623 } | 3622 } |
3624 | 3623 |
3625 /* If the 's' flag is not given, use the 'v' cursor for 's' */ | 3624 // If the 's' flag is not given, use the 'v' cursor for 's' |
3626 if (!found_ve) | 3625 if (!found_ve) |
3627 { | 3626 { |
3628 #ifdef FEAT_MOUSESHAPE | 3627 #ifdef FEAT_MOUSESHAPE |
3629 if (what == SHAPE_MOUSE) | 3628 if (what == SHAPE_MOUSE) |
3630 { | 3629 { |
3717 void | 3716 void |
3718 update_mouseshape(int shape_idx) | 3717 update_mouseshape(int shape_idx) |
3719 { | 3718 { |
3720 int new_mouse_shape; | 3719 int new_mouse_shape; |
3721 | 3720 |
3722 /* Only works in GUI mode. */ | 3721 // Only works in GUI mode. |
3723 if (!gui.in_use || gui.starting) | 3722 if (!gui.in_use || gui.starting) |
3724 return; | 3723 return; |
3725 | 3724 |
3726 /* Postpone the updating when more is to come. Speeds up executing of | 3725 // Postpone the updating when more is to come. Speeds up executing of |
3727 * mappings. */ | 3726 // mappings. |
3728 if (shape_idx == -1 && char_avail()) | 3727 if (shape_idx == -1 && char_avail()) |
3729 { | 3728 { |
3730 postponed_mouseshape = TRUE; | 3729 postponed_mouseshape = TRUE; |
3731 return; | 3730 return; |
3732 } | 3731 } |
3733 | 3732 |
3734 /* When ignoring the mouse don't change shape on the statusline. */ | 3733 // When ignoring the mouse don't change shape on the statusline. |
3735 if (*p_mouse == NUL | 3734 if (*p_mouse == NUL |
3736 && (shape_idx == SHAPE_IDX_CLINE | 3735 && (shape_idx == SHAPE_IDX_CLINE |
3737 || shape_idx == SHAPE_IDX_STATUS | 3736 || shape_idx == SHAPE_IDX_STATUS |
3738 || shape_idx == SHAPE_IDX_VSEP)) | 3737 || shape_idx == SHAPE_IDX_VSEP)) |
3739 shape_idx = -2; | 3738 shape_idx = -2; |
3754 } | 3753 } |
3755 postponed_mouseshape = FALSE; | 3754 postponed_mouseshape = FALSE; |
3756 } | 3755 } |
3757 # endif | 3756 # endif |
3758 | 3757 |
3759 #endif /* CURSOR_SHAPE */ | 3758 #endif // CURSOR_SHAPE |
3760 | 3759 |
3761 | 3760 |
3762 /* | 3761 /* |
3763 * Change directory to "new_dir". If FEAT_SEARCHPATH is defined, search | 3762 * Change directory to "new_dir". If FEAT_SEARCHPATH is defined, search |
3764 * 'cdpath' for relative directory names, otherwise just mch_chdir(). | 3763 * 'cdpath' for relative directory names, otherwise just mch_chdir(). |
3827 | 3826 |
3828 for (gap = elm_count / 2; gap > 0; gap /= 2) | 3827 for (gap = elm_count / 2; gap > 0; gap /= 2) |
3829 for (i = gap; i < elm_count; ++i) | 3828 for (i = gap; i < elm_count; ++i) |
3830 for (j = i - gap; j >= 0; j -= gap) | 3829 for (j = i - gap; j >= 0; j -= gap) |
3831 { | 3830 { |
3832 /* Compare the elements. */ | 3831 // Compare the elements. |
3833 p1 = (char_u *)base + j * elm_size; | 3832 p1 = (char_u *)base + j * elm_size; |
3834 p2 = (char_u *)base + (j + gap) * elm_size; | 3833 p2 = (char_u *)base + (j + gap) * elm_size; |
3835 if ((*cmp)((void *)p1, (void *)p2) <= 0) | 3834 if ((*cmp)((void *)p1, (void *)p2) <= 0) |
3836 break; | 3835 break; |
3837 /* Exchange the elements. */ | 3836 // Exchange the elements. |
3838 mch_memmove(buf, p1, elm_size); | 3837 mch_memmove(buf, p1, elm_size); |
3839 mch_memmove(p1, p2, elm_size); | 3838 mch_memmove(p1, p2, elm_size); |
3840 mch_memmove(p2, buf, elm_size); | 3839 mch_memmove(p2, buf, elm_size); |
3841 } | 3840 } |
3842 | 3841 |
3889 * (history removed, not very interesting. See the "screen" sources.) | 3888 * (history removed, not very interesting. See the "screen" sources.) |
3890 */ | 3889 */ |
3891 | 3890 |
3892 #if !defined(HAVE_SETENV) && !defined(HAVE_PUTENV) | 3891 #if !defined(HAVE_SETENV) && !defined(HAVE_PUTENV) |
3893 | 3892 |
3894 #define EXTRASIZE 5 /* increment to add to env. size */ | 3893 #define EXTRASIZE 5 // increment to add to env. size |
3895 | 3894 |
3896 static int envsize = -1; /* current size of environment */ | 3895 static int envsize = -1; // current size of environment |
3897 extern char **environ; /* the global which is your env. */ | 3896 extern char **environ; // the global which is your env. |
3898 | 3897 |
3899 static int findenv(char *name); /* look for a name in the env. */ | 3898 static int findenv(char *name); // look for a name in the env. |
3900 static int newenv(void); /* copy env. from stack to heap */ | 3899 static int newenv(void); // copy env. from stack to heap |
3901 static int moreenv(void); /* incr. size of env. */ | 3900 static int moreenv(void); // incr. size of env. |
3902 | 3901 |
3903 int | 3902 int |
3904 putenv(const char *string) | 3903 putenv(const char *string) |
3905 { | 3904 { |
3906 int i; | 3905 int i; |
3907 char *p; | 3906 char *p; |
3908 | 3907 |
3909 if (envsize < 0) | 3908 if (envsize < 0) |
3910 { /* first time putenv called */ | 3909 { // first time putenv called |
3911 if (newenv() < 0) /* copy env. to heap */ | 3910 if (newenv() < 0) // copy env. to heap |
3912 return -1; | 3911 return -1; |
3913 } | 3912 } |
3914 | 3913 |
3915 i = findenv((char *)string); /* look for name in environment */ | 3914 i = findenv((char *)string); // look for name in environment |
3916 | 3915 |
3917 if (i < 0) | 3916 if (i < 0) |
3918 { /* name must be added */ | 3917 { // name must be added |
3919 for (i = 0; environ[i]; i++); | 3918 for (i = 0; environ[i]; i++); |
3920 if (i >= (envsize - 1)) | 3919 if (i >= (envsize - 1)) |
3921 { /* need new slot */ | 3920 { // need new slot |
3922 if (moreenv() < 0) | 3921 if (moreenv() < 0) |
3923 return -1; | 3922 return -1; |
3924 } | 3923 } |
3925 p = alloc(strlen(string) + 1); | 3924 p = alloc(strlen(string) + 1); |
3926 if (p == NULL) /* not enough core */ | 3925 if (p == NULL) // not enough core |
3927 return -1; | 3926 return -1; |
3928 environ[i + 1] = 0; /* new end of env. */ | 3927 environ[i + 1] = 0; // new end of env. |
3929 } | 3928 } |
3930 else | 3929 else |
3931 { /* name already in env. */ | 3930 { // name already in env. |
3932 p = vim_realloc(environ[i], strlen(string) + 1); | 3931 p = vim_realloc(environ[i], strlen(string) + 1); |
3933 if (p == NULL) | 3932 if (p == NULL) |
3934 return -1; | 3933 return -1; |
3935 } | 3934 } |
3936 sprintf(p, "%s", string); /* copy into env. */ | 3935 sprintf(p, "%s", string); // copy into env. |
3937 environ[i] = p; | 3936 environ[i] = p; |
3938 | 3937 |
3939 return 0; | 3938 return 0; |
3940 } | 3939 } |
3941 | 3940 |
4025 p = vim_strchr((char_u *)environ[i], '='); | 4024 p = vim_strchr((char_u *)environ[i], '='); |
4026 return (p + 1); | 4025 return (p + 1); |
4027 } | 4026 } |
4028 # endif | 4027 # endif |
4029 | 4028 |
4030 #endif /* !defined(HAVE_SETENV) && !defined(HAVE_PUTENV) */ | 4029 #endif // !defined(HAVE_SETENV) && !defined(HAVE_PUTENV) |
4031 | 4030 |
4032 #if defined(FEAT_EVAL) || defined(FEAT_SPELL) || defined(PROTO) | 4031 #if defined(FEAT_EVAL) || defined(FEAT_SPELL) || defined(PROTO) |
4033 /* | 4032 /* |
4034 * Return 0 for not writable, 1 for writable file, 2 for a dir which we have | 4033 * Return 0 for not writable, 1 for writable file, 2 for a dir which we have |
4035 * rights to write into. | 4034 * rights to write into. |
4106 */ | 4105 */ |
4107 int | 4106 int |
4108 get4c(FILE *fd) | 4107 get4c(FILE *fd) |
4109 { | 4108 { |
4110 int c; | 4109 int c; |
4111 /* Use unsigned rather than int otherwise result is undefined | 4110 // Use unsigned rather than int otherwise result is undefined |
4112 * when left-shift sets the MSB. */ | 4111 // when left-shift sets the MSB. |
4113 unsigned n; | 4112 unsigned n; |
4114 | 4113 |
4115 c = getc(fd); | 4114 c = getc(fd); |
4116 if (c == EOF) return -1; | 4115 if (c == EOF) return -1; |
4117 n = (unsigned)c; | 4116 n = (unsigned)c; |
4156 { | 4155 { |
4157 char_u *str; | 4156 char_u *str; |
4158 int i; | 4157 int i; |
4159 int c; | 4158 int c; |
4160 | 4159 |
4161 /* allocate memory */ | 4160 // allocate memory |
4162 str = alloc(cnt + 1); | 4161 str = alloc(cnt + 1); |
4163 if (str != NULL) | 4162 if (str != NULL) |
4164 { | 4163 { |
4165 /* Read the string. Quit when running into the EOF. */ | 4164 // Read the string. Quit when running into the EOF. |
4166 for (i = 0; i < cnt; ++i) | 4165 for (i = 0; i < cnt; ++i) |
4167 { | 4166 { |
4168 c = getc(fd); | 4167 c = getc(fd); |
4169 if (c == EOF) | 4168 if (c == EOF) |
4170 { | 4169 { |
4192 return OK; | 4191 return OK; |
4193 } | 4192 } |
4194 | 4193 |
4195 #ifdef _MSC_VER | 4194 #ifdef _MSC_VER |
4196 # if (_MSC_VER <= 1200) | 4195 # if (_MSC_VER <= 1200) |
4197 /* This line is required for VC6 without the service pack. Also see the | 4196 // This line is required for VC6 without the service pack. Also see the |
4198 * matching #pragma below. */ | 4197 // matching #pragma below. |
4199 # pragma optimize("", off) | 4198 # pragma optimize("", off) |
4200 # endif | 4199 # endif |
4201 #endif | 4200 #endif |
4202 | 4201 |
4203 /* | 4202 /* |
4222 int c; | 4221 int c; |
4223 int i; | 4222 int i; |
4224 int bi = 0; | 4223 int bi = 0; |
4225 time_T wtime = the_time; | 4224 time_T wtime = the_time; |
4226 | 4225 |
4227 /* time_T can be up to 8 bytes in size, more than long_u, thus we | 4226 // time_T can be up to 8 bytes in size, more than long_u, thus we |
4228 * can't use put_bytes() here. | 4227 // can't use put_bytes() here. |
4229 * Another problem is that ">>" may do an arithmetic shift that keeps the | 4228 // Another problem is that ">>" may do an arithmetic shift that keeps the |
4230 * sign. This happens for large values of wtime. A cast to long_u may | 4229 // sign. This happens for large values of wtime. A cast to long_u may |
4231 * truncate if time_T is 8 bytes. So only use a cast when it is 4 bytes, | 4230 // truncate if time_T is 8 bytes. So only use a cast when it is 4 bytes, |
4232 * it's safe to assume that long_u is 4 bytes or more and when using 8 | 4231 // it's safe to assume that long_u is 4 bytes or more and when using 8 |
4233 * bytes the top bit won't be set. */ | 4232 // bytes the top bit won't be set. |
4234 for (i = 7; i >= 0; --i) | 4233 for (i = 7; i >= 0; --i) |
4235 { | 4234 { |
4236 if (i + 1 > (int)sizeof(time_T)) | 4235 if (i + 1 > (int)sizeof(time_T)) |
4237 /* ">>" doesn't work well when shifting more bits than avail */ | 4236 // ">>" doesn't work well when shifting more bits than avail |
4238 buf[bi++] = 0; | 4237 buf[bi++] = 0; |
4239 else | 4238 else |
4240 { | 4239 { |
4241 #if defined(SIZEOF_TIME_T) && SIZEOF_TIME_T > 4 | 4240 #if defined(SIZEOF_TIME_T) && SIZEOF_TIME_T > 4 |
4242 c = (int)(wtime >> (i * 8)); | 4241 c = (int)(wtime >> (i * 8)); |
4272 return TRUE; | 4271 return TRUE; |
4273 return FALSE; | 4272 return FALSE; |
4274 } | 4273 } |
4275 #endif | 4274 #endif |
4276 | 4275 |
4277 #ifndef PROTO /* proto is defined in vim.h */ | 4276 #ifndef PROTO // proto is defined in vim.h |
4278 # ifdef ELAPSED_TIMEVAL | 4277 # ifdef ELAPSED_TIMEVAL |
4279 /* | 4278 /* |
4280 * Return time in msec since "start_tv". | 4279 * Return time in msec since "start_tv". |
4281 */ | 4280 */ |
4282 long | 4281 long |
4366 } | 4365 } |
4367 if (*argv == NULL) | 4366 if (*argv == NULL) |
4368 { | 4367 { |
4369 if (use_shcf) | 4368 if (use_shcf) |
4370 { | 4369 { |
4371 /* Account for possible multiple args in p_shcf. */ | 4370 // Account for possible multiple args in p_shcf. |
4372 p = p_shcf; | 4371 p = p_shcf; |
4373 for (;;) | 4372 for (;;) |
4374 { | 4373 { |
4375 p = skiptowhite(p); | 4374 p = skiptowhite(p); |
4376 if (*p == NUL) | 4375 if (*p == NUL) |
4379 p = skipwhite(p); | 4378 p = skipwhite(p); |
4380 } | 4379 } |
4381 } | 4380 } |
4382 | 4381 |
4383 *argv = ALLOC_MULT(char *, *argc + 4); | 4382 *argv = ALLOC_MULT(char *, *argc + 4); |
4384 if (*argv == NULL) /* out of memory */ | 4383 if (*argv == NULL) // out of memory |
4385 return FAIL; | 4384 return FAIL; |
4386 } | 4385 } |
4387 } | 4386 } |
4388 return OK; | 4387 return OK; |
4389 } | 4388 } |
4398 build_argv_from_string(char_u *cmd, char ***argv, int *argc) | 4397 build_argv_from_string(char_u *cmd, char ***argv, int *argc) |
4399 { | 4398 { |
4400 char_u *cmd_copy; | 4399 char_u *cmd_copy; |
4401 int i; | 4400 int i; |
4402 | 4401 |
4403 /* Make a copy, parsing will modify "cmd". */ | 4402 // Make a copy, parsing will modify "cmd". |
4404 cmd_copy = vim_strsave(cmd); | 4403 cmd_copy = vim_strsave(cmd); |
4405 if (cmd_copy == NULL | 4404 if (cmd_copy == NULL |
4406 || mch_parse_cmd(cmd_copy, FALSE, argv, argc) == FAIL) | 4405 || mch_parse_cmd(cmd_copy, FALSE, argv, argc) == FAIL) |
4407 { | 4406 { |
4408 vim_free(cmd_copy); | 4407 vim_free(cmd_copy); |
4424 build_argv_from_list(list_T *l, char ***argv, int *argc) | 4423 build_argv_from_list(list_T *l, char ***argv, int *argc) |
4425 { | 4424 { |
4426 listitem_T *li; | 4425 listitem_T *li; |
4427 char_u *s; | 4426 char_u *s; |
4428 | 4427 |
4429 /* Pass argv[] to mch_call_shell(). */ | 4428 // Pass argv[] to mch_call_shell(). |
4430 *argv = ALLOC_MULT(char *, l->lv_len + 1); | 4429 *argv = ALLOC_MULT(char *, l->lv_len + 1); |
4431 if (*argv == NULL) | 4430 if (*argv == NULL) |
4432 return FAIL; | 4431 return FAIL; |
4433 *argc = 0; | 4432 *argc = 0; |
4434 for (li = l->lv_first; li != NULL; li = li->li_next) | 4433 for (li = l->lv_first; li != NULL; li = li->li_next) |