Mercurial > vim
comparison src/misc1.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 | 6ad15a9b7c89 |
children | 94eda51ba9ba |
comparison
equal
deleted
inserted
replaced
18930:394f34c5c683 | 18931:80b40bd5ec1a |
---|---|
16 | 16 |
17 #if defined(MSWIN) | 17 #if defined(MSWIN) |
18 # include <lm.h> | 18 # include <lm.h> |
19 #endif | 19 #endif |
20 | 20 |
21 #define URL_SLASH 1 /* path_is_url() has found "://" */ | 21 #define URL_SLASH 1 // path_is_url() has found "://" |
22 #define URL_BACKSLASH 2 /* path_is_url() has found ":\\" */ | 22 #define URL_BACKSLASH 2 // path_is_url() has found ":\\" |
23 | 23 |
24 // All user names (for ~user completion as done by shell). | 24 // All user names (for ~user completion as done by shell). |
25 static garray_T ga_users; | 25 static garray_T ga_users; |
26 | 26 |
27 /* | 27 /* |
43 { | 43 { |
44 int i, j; | 44 int i, j; |
45 int result; | 45 int result; |
46 int got_com = FALSE; | 46 int got_com = FALSE; |
47 int found_one; | 47 int found_one; |
48 char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */ | 48 char_u part_buf[COM_MAX_LEN]; // buffer for one option part |
49 char_u *string; /* pointer to comment string */ | 49 char_u *string; // pointer to comment string |
50 char_u *list; | 50 char_u *list; |
51 int middle_match_len = 0; | 51 int middle_match_len = 0; |
52 char_u *prev_list; | 52 char_u *prev_list; |
53 char_u *saved_flags = NULL; | 53 char_u *saved_flags = NULL; |
54 | 54 |
55 result = i = 0; | 55 result = i = 0; |
56 while (VIM_ISWHITE(line[i])) /* leading white space is ignored */ | 56 while (VIM_ISWHITE(line[i])) // leading white space is ignored |
57 ++i; | 57 ++i; |
58 | 58 |
59 /* | 59 /* |
60 * Repeat to match several nested comment strings. | 60 * Repeat to match several nested comment strings. |
61 */ | 61 */ |
65 * scan through the 'comments' option for a match | 65 * scan through the 'comments' option for a match |
66 */ | 66 */ |
67 found_one = FALSE; | 67 found_one = FALSE; |
68 for (list = curbuf->b_p_com; *list; ) | 68 for (list = curbuf->b_p_com; *list; ) |
69 { | 69 { |
70 /* Get one option part into part_buf[]. Advance "list" to next | 70 // Get one option part into part_buf[]. Advance "list" to next |
71 * one. Put "string" at start of string. */ | 71 // one. Put "string" at start of string. |
72 if (!got_com && flags != NULL) | 72 if (!got_com && flags != NULL) |
73 *flags = list; /* remember where flags started */ | 73 *flags = list; // remember where flags started |
74 prev_list = list; | 74 prev_list = list; |
75 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); | 75 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); |
76 string = vim_strchr(part_buf, ':'); | 76 string = vim_strchr(part_buf, ':'); |
77 if (string == NULL) /* missing ':', ignore this part */ | 77 if (string == NULL) // missing ':', ignore this part |
78 continue; | 78 continue; |
79 *string++ = NUL; /* isolate flags from string */ | 79 *string++ = NUL; // isolate flags from string |
80 | 80 |
81 /* If we found a middle match previously, use that match when this | 81 // If we found a middle match previously, use that match when this |
82 * is not a middle or end. */ | 82 // is not a middle or end. |
83 if (middle_match_len != 0 | 83 if (middle_match_len != 0 |
84 && vim_strchr(part_buf, COM_MIDDLE) == NULL | 84 && vim_strchr(part_buf, COM_MIDDLE) == NULL |
85 && vim_strchr(part_buf, COM_END) == NULL) | 85 && vim_strchr(part_buf, COM_END) == NULL) |
86 break; | 86 break; |
87 | 87 |
88 /* When we already found a nested comment, only accept further | 88 // When we already found a nested comment, only accept further |
89 * nested comments. */ | 89 // nested comments. |
90 if (got_com && vim_strchr(part_buf, COM_NEST) == NULL) | 90 if (got_com && vim_strchr(part_buf, COM_NEST) == NULL) |
91 continue; | 91 continue; |
92 | 92 |
93 /* When 'O' flag present and using "O" command skip this one. */ | 93 // When 'O' flag present and using "O" command skip this one. |
94 if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL) | 94 if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL) |
95 continue; | 95 continue; |
96 | 96 |
97 /* Line contents and string must match. | 97 // Line contents and string must match. |
98 * When string starts with white space, must have some white space | 98 // When string starts with white space, must have some white space |
99 * (but the amount does not need to match, there might be a mix of | 99 // (but the amount does not need to match, there might be a mix of |
100 * TABs and spaces). */ | 100 // TABs and spaces). |
101 if (VIM_ISWHITE(string[0])) | 101 if (VIM_ISWHITE(string[0])) |
102 { | 102 { |
103 if (i == 0 || !VIM_ISWHITE(line[i - 1])) | 103 if (i == 0 || !VIM_ISWHITE(line[i - 1])) |
104 continue; /* missing white space */ | 104 continue; // missing white space |
105 while (VIM_ISWHITE(string[0])) | 105 while (VIM_ISWHITE(string[0])) |
106 ++string; | 106 ++string; |
107 } | 107 } |
108 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) | 108 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) |
109 ; | 109 ; |
110 if (string[j] != NUL) | 110 if (string[j] != NUL) |
111 continue; /* string doesn't match */ | 111 continue; // string doesn't match |
112 | 112 |
113 /* When 'b' flag used, there must be white space or an | 113 // When 'b' flag used, there must be white space or an |
114 * end-of-line after the string in the line. */ | 114 // end-of-line after the string in the line. |
115 if (vim_strchr(part_buf, COM_BLANK) != NULL | 115 if (vim_strchr(part_buf, COM_BLANK) != NULL |
116 && !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL) | 116 && !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL) |
117 continue; | 117 continue; |
118 | 118 |
119 /* We have found a match, stop searching unless this is a middle | 119 // We have found a match, stop searching unless this is a middle |
120 * comment. The middle comment can be a substring of the end | 120 // comment. The middle comment can be a substring of the end |
121 * comment in which case it's better to return the length of the | 121 // comment in which case it's better to return the length of the |
122 * end comment and its flags. Thus we keep searching with middle | 122 // end comment and its flags. Thus we keep searching with middle |
123 * and end matches and use an end match if it matches better. */ | 123 // and end matches and use an end match if it matches better. |
124 if (vim_strchr(part_buf, COM_MIDDLE) != NULL) | 124 if (vim_strchr(part_buf, COM_MIDDLE) != NULL) |
125 { | 125 { |
126 if (middle_match_len == 0) | 126 if (middle_match_len == 0) |
127 { | 127 { |
128 middle_match_len = j; | 128 middle_match_len = j; |
129 saved_flags = prev_list; | 129 saved_flags = prev_list; |
130 } | 130 } |
131 continue; | 131 continue; |
132 } | 132 } |
133 if (middle_match_len != 0 && j > middle_match_len) | 133 if (middle_match_len != 0 && j > middle_match_len) |
134 /* Use this match instead of the middle match, since it's a | 134 // Use this match instead of the middle match, since it's a |
135 * longer thus better match. */ | 135 // longer thus better match. |
136 middle_match_len = 0; | 136 middle_match_len = 0; |
137 | 137 |
138 if (middle_match_len == 0) | 138 if (middle_match_len == 0) |
139 i += j; | 139 i += j; |
140 found_one = TRUE; | 140 found_one = TRUE; |
141 break; | 141 break; |
142 } | 142 } |
143 | 143 |
144 if (middle_match_len != 0) | 144 if (middle_match_len != 0) |
145 { | 145 { |
146 /* Use the previously found middle match after failing to find a | 146 // Use the previously found middle match after failing to find a |
147 * match with an end. */ | 147 // match with an end. |
148 if (!got_com && flags != NULL) | 148 if (!got_com && flags != NULL) |
149 *flags = saved_flags; | 149 *flags = saved_flags; |
150 i += middle_match_len; | 150 i += middle_match_len; |
151 found_one = TRUE; | 151 found_one = TRUE; |
152 } | 152 } |
153 | 153 |
154 /* No match found, stop scanning. */ | 154 // No match found, stop scanning. |
155 if (!found_one) | 155 if (!found_one) |
156 break; | 156 break; |
157 | 157 |
158 result = i; | 158 result = i; |
159 | 159 |
160 /* Include any trailing white space. */ | 160 // Include any trailing white space. |
161 while (VIM_ISWHITE(line[i])) | 161 while (VIM_ISWHITE(line[i])) |
162 ++i; | 162 ++i; |
163 | 163 |
164 if (include_space) | 164 if (include_space) |
165 result = i; | 165 result = i; |
166 | 166 |
167 /* If this comment doesn't nest, stop here. */ | 167 // If this comment doesn't nest, stop here. |
168 got_com = TRUE; | 168 got_com = TRUE; |
169 if (vim_strchr(part_buf, COM_NEST) == NULL) | 169 if (vim_strchr(part_buf, COM_NEST) == NULL) |
170 break; | 170 break; |
171 } | 171 } |
172 return result; | 172 return result; |
188 char_u *string; | 188 char_u *string; |
189 char_u *com_leader; | 189 char_u *com_leader; |
190 char_u *com_flags; | 190 char_u *com_flags; |
191 char_u *list; | 191 char_u *list; |
192 int found_one; | 192 int found_one; |
193 char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */ | 193 char_u part_buf[COM_MAX_LEN]; // buffer for one option part |
194 | 194 |
195 /* | 195 /* |
196 * Repeat to match several nested comment strings. | 196 * Repeat to match several nested comment strings. |
197 */ | 197 */ |
198 i = (int)STRLEN(line); | 198 i = (int)STRLEN(line); |
210 * Get one option part into part_buf[]. Advance list to next one. | 210 * Get one option part into part_buf[]. Advance list to next one. |
211 * put string at start of string. | 211 * put string at start of string. |
212 */ | 212 */ |
213 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); | 213 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); |
214 string = vim_strchr(part_buf, ':'); | 214 string = vim_strchr(part_buf, ':'); |
215 if (string == NULL) /* If everything is fine, this cannot actually | 215 if (string == NULL) // If everything is fine, this cannot actually |
216 * happen. */ | 216 // happen. |
217 continue; | 217 continue; |
218 *string++ = NUL; /* Isolate flags from string. */ | 218 *string++ = NUL; // Isolate flags from string. |
219 com_leader = string; | 219 com_leader = string; |
220 | 220 |
221 /* | 221 /* |
222 * Line contents and string must match. | 222 * Line contents and string must match. |
223 * When string starts with white space, must have some white space | 223 * When string starts with white space, must have some white space |
269 break; | 269 break; |
270 } | 270 } |
271 | 271 |
272 if (found_one) | 272 if (found_one) |
273 { | 273 { |
274 char_u part_buf2[COM_MAX_LEN]; /* buffer for one option part */ | 274 char_u part_buf2[COM_MAX_LEN]; // buffer for one option part |
275 int len1, len2, off; | 275 int len1, len2, off; |
276 | 276 |
277 result = i; | 277 result = i; |
278 /* | 278 /* |
279 * If this comment nests, continue searching. | 279 * If this comment nests, continue searching. |
281 if (vim_strchr(part_buf, COM_NEST) != NULL) | 281 if (vim_strchr(part_buf, COM_NEST) != NULL) |
282 continue; | 282 continue; |
283 | 283 |
284 lower_check_bound = i; | 284 lower_check_bound = i; |
285 | 285 |
286 /* Let's verify whether the comment leader found is a substring | 286 // Let's verify whether the comment leader found is a substring |
287 * of other comment leaders. If it is, let's adjust the | 287 // of other comment leaders. If it is, let's adjust the |
288 * lower_check_bound so that we make sure that we have determined | 288 // lower_check_bound so that we make sure that we have determined |
289 * the comment leader correctly. | 289 // the comment leader correctly. |
290 */ | |
291 | 290 |
292 while (VIM_ISWHITE(*com_leader)) | 291 while (VIM_ISWHITE(*com_leader)) |
293 ++com_leader; | 292 ++com_leader; |
294 len1 = (int)STRLEN(com_leader); | 293 len1 = (int)STRLEN(com_leader); |
295 | 294 |
306 ++string; | 305 ++string; |
307 len2 = (int)STRLEN(string); | 306 len2 = (int)STRLEN(string); |
308 if (len2 == 0) | 307 if (len2 == 0) |
309 continue; | 308 continue; |
310 | 309 |
311 /* Now we have to verify whether string ends with a substring | 310 // Now we have to verify whether string ends with a substring |
312 * beginning the com_leader. */ | 311 // beginning the com_leader. |
313 for (off = (len2 > i ? i : len2); off > 0 && off + len1 > len2;) | 312 for (off = (len2 > i ? i : len2); off > 0 && off + len1 > len2;) |
314 { | 313 { |
315 --off; | 314 --off; |
316 if (!STRNCMP(string + off, com_leader, len2 - off)) | 315 if (!STRNCMP(string + off, com_leader, len2 - off)) |
317 { | 316 { |
336 | 335 |
337 int | 336 int |
338 plines_win( | 337 plines_win( |
339 win_T *wp, | 338 win_T *wp, |
340 linenr_T lnum, | 339 linenr_T lnum, |
341 int winheight) /* when TRUE limit to window height */ | 340 int winheight) // when TRUE limit to window height |
342 { | 341 { |
343 #if defined(FEAT_DIFF) || defined(PROTO) | 342 #if defined(FEAT_DIFF) || defined(PROTO) |
344 /* Check for filler lines above this buffer line. When folded the result | 343 // Check for filler lines above this buffer line. When folded the result |
345 * is one line anyway. */ | 344 // is one line anyway. |
346 return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum); | 345 return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum); |
347 } | 346 } |
348 | 347 |
349 int | 348 int |
350 plines_nofill(linenr_T lnum) | 349 plines_nofill(linenr_T lnum) |
354 | 353 |
355 int | 354 int |
356 plines_win_nofill( | 355 plines_win_nofill( |
357 win_T *wp, | 356 win_T *wp, |
358 linenr_T lnum, | 357 linenr_T lnum, |
359 int winheight) /* when TRUE limit to window height */ | 358 int winheight) // when TRUE limit to window height |
360 { | 359 { |
361 #endif | 360 #endif |
362 int lines; | 361 int lines; |
363 | 362 |
364 if (!wp->w_p_wrap) | 363 if (!wp->w_p_wrap) |
366 | 365 |
367 if (wp->w_width == 0) | 366 if (wp->w_width == 0) |
368 return 1; | 367 return 1; |
369 | 368 |
370 #ifdef FEAT_FOLDING | 369 #ifdef FEAT_FOLDING |
371 /* A folded lines is handled just like an empty line. */ | 370 // A folded lines is handled just like an empty line. |
372 /* NOTE: Caller must handle lines that are MAYBE folded. */ | 371 // NOTE: Caller must handle lines that are MAYBE folded. |
373 if (lineFolded(wp, lnum) == TRUE) | 372 if (lineFolded(wp, lnum) == TRUE) |
374 return 1; | 373 return 1; |
375 #endif | 374 #endif |
376 | 375 |
377 lines = plines_win_nofold(wp, lnum); | 376 lines = plines_win_nofold(wp, lnum); |
390 char_u *s; | 389 char_u *s; |
391 long col; | 390 long col; |
392 int width; | 391 int width; |
393 | 392 |
394 s = ml_get_buf(wp->w_buffer, lnum, FALSE); | 393 s = ml_get_buf(wp->w_buffer, lnum, FALSE); |
395 if (*s == NUL) /* empty line */ | 394 if (*s == NUL) // empty line |
396 return 1; | 395 return 1; |
397 col = win_linetabsize(wp, s, (colnr_T)MAXCOL); | 396 col = win_linetabsize(wp, s, (colnr_T)MAXCOL); |
398 | 397 |
399 /* | 398 /* |
400 * If list mode is on, then the '$' at the end of the line may take up one | 399 * If list mode is on, then the '$' at the end of the line may take up one |
428 int lines = 0; | 427 int lines = 0; |
429 int width; | 428 int width; |
430 char_u *line; | 429 char_u *line; |
431 | 430 |
432 #ifdef FEAT_DIFF | 431 #ifdef FEAT_DIFF |
433 /* Check for filler lines above this buffer line. When folded the result | 432 // Check for filler lines above this buffer line. When folded the result |
434 * is one line anyway. */ | 433 // is one line anyway. |
435 lines = diff_check_fill(wp, lnum); | 434 lines = diff_check_fill(wp, lnum); |
436 #endif | 435 #endif |
437 | 436 |
438 if (!wp->w_p_wrap) | 437 if (!wp->w_p_wrap) |
439 return lines + 1; | 438 return lines + 1; |
481 while (first <= last) | 480 while (first <= last) |
482 { | 481 { |
483 #ifdef FEAT_FOLDING | 482 #ifdef FEAT_FOLDING |
484 int x; | 483 int x; |
485 | 484 |
486 /* Check if there are any really folded lines, but also included lines | 485 // Check if there are any really folded lines, but also included lines |
487 * that are maybe folded. */ | 486 // that are maybe folded. |
488 x = foldedCount(wp, first, NULL); | 487 x = foldedCount(wp, first, NULL); |
489 if (x > 0) | 488 if (x > 0) |
490 { | 489 { |
491 ++count; /* count 1 for "+-- folded" line */ | 490 ++count; // count 1 for "+-- folded" line |
492 first += x; | 491 first += x; |
493 } | 492 } |
494 else | 493 else |
495 #endif | 494 #endif |
496 { | 495 { |
509 int | 508 int |
510 gchar_pos(pos_T *pos) | 509 gchar_pos(pos_T *pos) |
511 { | 510 { |
512 char_u *ptr; | 511 char_u *ptr; |
513 | 512 |
514 /* When searching columns is sometimes put at the end of a line. */ | 513 // When searching columns is sometimes put at the end of a line. |
515 if (pos->col == MAXCOL) | 514 if (pos->col == MAXCOL) |
516 return NUL; | 515 return NUL; |
517 ptr = ml_get_pos(pos); | 516 ptr = ml_get_pos(pos); |
518 if (has_mbyte) | 517 if (has_mbyte) |
519 return (*mb_ptr2char)(ptr); | 518 return (*mb_ptr2char)(ptr); |
583 ask_yesno(char_u *str, int direct) | 582 ask_yesno(char_u *str, int direct) |
584 { | 583 { |
585 int r = ' '; | 584 int r = ' '; |
586 int save_State = State; | 585 int save_State = State; |
587 | 586 |
588 if (exiting) /* put terminal in raw mode for this question */ | 587 if (exiting) // put terminal in raw mode for this question |
589 settmode(TMODE_RAW); | 588 settmode(TMODE_RAW); |
590 ++no_wait_return; | 589 ++no_wait_return; |
591 #ifdef USE_ON_FLY_SCROLL | 590 #ifdef USE_ON_FLY_SCROLL |
592 dont_scroll = TRUE; // disallow scrolling here | 591 dont_scroll = TRUE; // disallow scrolling here |
593 #endif | 592 #endif |
596 ++no_mapping; | 595 ++no_mapping; |
597 ++allow_keys; // no mapping here, but recognize keys | 596 ++allow_keys; // no mapping here, but recognize keys |
598 | 597 |
599 while (r != 'y' && r != 'n') | 598 while (r != 'y' && r != 'n') |
600 { | 599 { |
601 /* same highlighting as for wait_return */ | 600 // same highlighting as for wait_return |
602 smsg_attr(HL_ATTR(HLF_R), "%s (y/n)?", str); | 601 smsg_attr(HL_ATTR(HLF_R), "%s (y/n)?", str); |
603 if (direct) | 602 if (direct) |
604 r = get_keystroke(); | 603 r = get_keystroke(); |
605 else | 604 else |
606 r = plain_vgetc(); | 605 r = plain_vgetc(); |
607 if (r == Ctrl_C || r == ESC) | 606 if (r == Ctrl_C || r == ESC) |
608 r = 'n'; | 607 r = 'n'; |
609 msg_putchar(r); /* show what you typed */ | 608 msg_putchar(r); // show what you typed |
610 out_flush(); | 609 out_flush(); |
611 } | 610 } |
612 --no_wait_return; | 611 --no_wait_return; |
613 State = save_State; | 612 State = save_State; |
614 setmouse(); | 613 setmouse(); |
630 | 629 |
631 vim_memset(buf, 0, sizeof(buf)); | 630 vim_memset(buf, 0, sizeof(buf)); |
632 | 631 |
633 if (time_for_testing == 93784) | 632 if (time_for_testing == 93784) |
634 { | 633 { |
635 /* Testing the two-character code. */ | 634 // Testing the two-character code. |
636 buf[0] = 'x'; | 635 buf[0] = 'x'; |
637 buf[1] = '!'; | 636 buf[1] = '!'; |
638 } | 637 } |
639 #ifdef FEAT_TERMINAL | 638 #ifdef FEAT_TERMINAL |
640 else if (term_use_loop()) | 639 else if (term_use_loop()) |
700 buf[1] = 'i'; | 699 buf[1] = 'i'; |
701 buf[2] = restart_edit; | 700 buf[2] = restart_edit; |
702 } | 701 } |
703 } | 702 } |
704 | 703 |
705 /* Clear out the minor mode when the argument is not a non-zero number or | 704 // Clear out the minor mode when the argument is not a non-zero number or |
706 * non-empty string. */ | 705 // non-empty string. |
707 if (!non_zero_arg(&argvars[0])) | 706 if (!non_zero_arg(&argvars[0])) |
708 buf[1] = NUL; | 707 buf[1] = NUL; |
709 | 708 |
710 rettv->vval.v_string = vim_strsave(buf); | 709 rettv->vval.v_string = vim_strsave(buf); |
711 rettv->v_type = VAR_STRING; | 710 rettv->v_type = VAR_STRING; |
775 int len = 0; | 774 int len = 0; |
776 int n; | 775 int n; |
777 int save_mapped_ctrl_c = mapped_ctrl_c; | 776 int save_mapped_ctrl_c = mapped_ctrl_c; |
778 int waited = 0; | 777 int waited = 0; |
779 | 778 |
780 mapped_ctrl_c = FALSE; /* mappings are not used here */ | 779 mapped_ctrl_c = FALSE; // mappings are not used here |
781 for (;;) | 780 for (;;) |
782 { | 781 { |
783 cursor_on(); | 782 cursor_on(); |
784 out_flush(); | 783 out_flush(); |
785 | 784 |
786 /* Leave some room for check_termcode() to insert a key code into (max | 785 // Leave some room for check_termcode() to insert a key code into (max |
787 * 5 chars plus NUL). And fix_input_buffer() can triple the number of | 786 // 5 chars plus NUL). And fix_input_buffer() can triple the number of |
788 * bytes. */ | 787 // bytes. |
789 maxlen = (buflen - 6 - len) / 3; | 788 maxlen = (buflen - 6 - len) / 3; |
790 if (buf == NULL) | 789 if (buf == NULL) |
791 buf = alloc(buflen); | 790 buf = alloc(buflen); |
792 else if (maxlen < 10) | 791 else if (maxlen < 10) |
793 { | 792 { |
794 char_u *t_buf = buf; | 793 char_u *t_buf = buf; |
795 | 794 |
796 /* Need some more space. This might happen when receiving a long | 795 // Need some more space. This might happen when receiving a long |
797 * escape sequence. */ | 796 // escape sequence. |
798 buflen += 100; | 797 buflen += 100; |
799 buf = vim_realloc(buf, buflen); | 798 buf = vim_realloc(buf, buflen); |
800 if (buf == NULL) | 799 if (buf == NULL) |
801 vim_free(t_buf); | 800 vim_free(t_buf); |
802 maxlen = (buflen - 6 - len) / 3; | 801 maxlen = (buflen - 6 - len) / 3; |
803 } | 802 } |
804 if (buf == NULL) | 803 if (buf == NULL) |
805 { | 804 { |
806 do_outofmem_msg((long_u)buflen); | 805 do_outofmem_msg((long_u)buflen); |
807 return ESC; /* panic! */ | 806 return ESC; // panic! |
808 } | 807 } |
809 | 808 |
810 /* First time: blocking wait. Second time: wait up to 100ms for a | 809 // First time: blocking wait. Second time: wait up to 100ms for a |
811 * terminal code to complete. */ | 810 // terminal code to complete. |
812 n = ui_inchar(buf + len, maxlen, len == 0 ? -1L : 100L, 0); | 811 n = ui_inchar(buf + len, maxlen, len == 0 ? -1L : 100L, 0); |
813 if (n > 0) | 812 if (n > 0) |
814 { | 813 { |
815 /* Replace zero and CSI by a special key code. */ | 814 // Replace zero and CSI by a special key code. |
816 n = fix_input_buffer(buf + len, n); | 815 n = fix_input_buffer(buf + len, n); |
817 len += n; | 816 len += n; |
818 waited = 0; | 817 waited = 0; |
819 } | 818 } |
820 else if (len > 0) | 819 else if (len > 0) |
821 ++waited; /* keep track of the waiting time */ | 820 ++waited; // keep track of the waiting time |
822 | 821 |
823 /* Incomplete termcode and not timed out yet: get more characters */ | 822 // Incomplete termcode and not timed out yet: get more characters |
824 if ((n = check_termcode(1, buf, buflen, &len)) < 0 | 823 if ((n = check_termcode(1, buf, buflen, &len)) < 0 |
825 && (!p_ttimeout || waited * 100L < (p_ttm < 0 ? p_tm : p_ttm))) | 824 && (!p_ttimeout || waited * 100L < (p_ttm < 0 ? p_tm : p_ttm))) |
826 continue; | 825 continue; |
827 | 826 |
828 if (n == KEYLEN_REMOVED) /* key code removed */ | 827 if (n == KEYLEN_REMOVED) // key code removed |
829 { | 828 { |
830 if (must_redraw != 0 && !need_wait_return && (State & CMDLINE) == 0) | 829 if (must_redraw != 0 && !need_wait_return && (State & CMDLINE) == 0) |
831 { | 830 { |
832 /* Redrawing was postponed, do it now. */ | 831 // Redrawing was postponed, do it now. |
833 update_screen(0); | 832 update_screen(0); |
834 setcursor(); /* put cursor back where it belongs */ | 833 setcursor(); // put cursor back where it belongs |
835 } | 834 } |
836 continue; | 835 continue; |
837 } | 836 } |
838 if (n > 0) /* found a termcode: adjust length */ | 837 if (n > 0) // found a termcode: adjust length |
839 len = n; | 838 len = n; |
840 if (len == 0) /* nothing typed yet */ | 839 if (len == 0) // nothing typed yet |
841 continue; | 840 continue; |
842 | 841 |
843 /* Handle modifier and/or special key code. */ | 842 // Handle modifier and/or special key code. |
844 n = buf[0]; | 843 n = buf[0]; |
845 if (n == K_SPECIAL) | 844 if (n == K_SPECIAL) |
846 { | 845 { |
847 n = TO_SPECIAL(buf[1], buf[2]); | 846 n = TO_SPECIAL(buf[1], buf[2]); |
848 if (buf[1] == KS_MODIFIER | 847 if (buf[1] == KS_MODIFIER |
864 break; | 863 break; |
865 } | 864 } |
866 if (has_mbyte) | 865 if (has_mbyte) |
867 { | 866 { |
868 if (MB_BYTE2LEN(n) > len) | 867 if (MB_BYTE2LEN(n) > len) |
869 continue; /* more bytes to get */ | 868 continue; // more bytes to get |
870 buf[len >= buflen ? buflen - 1 : len] = NUL; | 869 buf[len >= buflen ? buflen - 1 : len] = NUL; |
871 n = (*mb_ptr2char)(buf); | 870 n = (*mb_ptr2char)(buf); |
872 } | 871 } |
873 #ifdef UNIX | 872 #ifdef UNIX |
874 if (n == intr_char) | 873 if (n == intr_char) |
886 * Get a number from the user. | 885 * Get a number from the user. |
887 * When "mouse_used" is not NULL allow using the mouse. | 886 * When "mouse_used" is not NULL allow using the mouse. |
888 */ | 887 */ |
889 int | 888 int |
890 get_number( | 889 get_number( |
891 int colon, /* allow colon to abort */ | 890 int colon, // allow colon to abort |
892 int *mouse_used) | 891 int *mouse_used) |
893 { | 892 { |
894 int n = 0; | 893 int n = 0; |
895 int c; | 894 int c; |
896 int typed = 0; | 895 int typed = 0; |
897 | 896 |
898 if (mouse_used != NULL) | 897 if (mouse_used != NULL) |
899 *mouse_used = FALSE; | 898 *mouse_used = FALSE; |
900 | 899 |
901 /* When not printing messages, the user won't know what to type, return a | 900 // When not printing messages, the user won't know what to type, return a |
902 * zero (as if CR was hit). */ | 901 // zero (as if CR was hit). |
903 if (msg_silent != 0) | 902 if (msg_silent != 0) |
904 return 0; | 903 return 0; |
905 | 904 |
906 #ifdef USE_ON_FLY_SCROLL | 905 #ifdef USE_ON_FLY_SCROLL |
907 dont_scroll = TRUE; /* disallow scrolling here */ | 906 dont_scroll = TRUE; // disallow scrolling here |
908 #endif | 907 #endif |
909 ++no_mapping; | 908 ++no_mapping; |
910 ++allow_keys; /* no mapping here, but recognize keys */ | 909 ++allow_keys; // no mapping here, but recognize keys |
911 for (;;) | 910 for (;;) |
912 { | 911 { |
913 windgoto(msg_row, msg_col); | 912 windgoto(msg_row, msg_col); |
914 c = safe_vgetc(); | 913 c = safe_vgetc(); |
915 if (VIM_ISDIGIT(c)) | 914 if (VIM_ISDIGIT(c)) |
936 else if (n == 0 && c == ':' && colon) | 935 else if (n == 0 && c == ':' && colon) |
937 { | 936 { |
938 stuffcharReadbuff(':'); | 937 stuffcharReadbuff(':'); |
939 if (!exmode_active) | 938 if (!exmode_active) |
940 cmdline_row = msg_row; | 939 cmdline_row = msg_row; |
941 skip_redraw = TRUE; /* skip redraw once */ | 940 skip_redraw = TRUE; // skip redraw once |
942 do_redraw = FALSE; | 941 do_redraw = FALSE; |
943 break; | 942 break; |
944 } | 943 } |
945 else if (c == CAR || c == NL || c == Ctrl_C || c == ESC) | 944 else if (c == CAR || c == NL || c == Ctrl_C || c == ESC) |
946 break; | 945 break; |
960 { | 959 { |
961 int i; | 960 int i; |
962 int save_cmdline_row; | 961 int save_cmdline_row; |
963 int save_State; | 962 int save_State; |
964 | 963 |
965 /* When using ":silent" assume that <CR> was entered. */ | 964 // When using ":silent" assume that <CR> was entered. |
966 if (mouse_used != NULL) | 965 if (mouse_used != NULL) |
967 msg_puts(_("Type number and <Enter> or click with mouse (empty cancels): ")); | 966 msg_puts(_("Type number and <Enter> or click with mouse (empty cancels): ")); |
968 else | 967 else |
969 msg_puts(_("Type number and <Enter> (empty cancels): ")); | 968 msg_puts(_("Type number and <Enter> (empty cancels): ")); |
970 | 969 |
1000 void | 999 void |
1001 msgmore(long n) | 1000 msgmore(long n) |
1002 { | 1001 { |
1003 long pn; | 1002 long pn; |
1004 | 1003 |
1005 if (global_busy /* no messages now, wait until global is finished */ | 1004 if (global_busy // no messages now, wait until global is finished |
1006 || !messaging()) /* 'lazyredraw' set, don't do messages now */ | 1005 || !messaging()) // 'lazyredraw' set, don't do messages now |
1007 return; | 1006 return; |
1008 | 1007 |
1009 /* We don't want to overwrite another important message, but do overwrite | 1008 // We don't want to overwrite another important message, but do overwrite |
1010 * a previous "more lines" or "fewer lines" message, so that "5dd" and | 1009 // a previous "more lines" or "fewer lines" message, so that "5dd" and |
1011 * then "put" reports the last action. */ | 1010 // then "put" reports the last action. |
1012 if (keep_msg != NULL && !keep_msg_more) | 1011 if (keep_msg != NULL && !keep_msg_more) |
1013 return; | 1012 return; |
1014 | 1013 |
1015 if (n > 0) | 1014 if (n > 0) |
1016 pn = n; | 1015 pn = n; |
1052 /* | 1051 /* |
1053 * Give a warning for an error. | 1052 * Give a warning for an error. |
1054 */ | 1053 */ |
1055 void | 1054 void |
1056 vim_beep( | 1055 vim_beep( |
1057 unsigned val) /* one of the BO_ values, e.g., BO_OPER */ | 1056 unsigned val) // one of the BO_ values, e.g., BO_OPER |
1058 { | 1057 { |
1059 #ifdef FEAT_EVAL | 1058 #ifdef FEAT_EVAL |
1060 called_vim_beep = TRUE; | 1059 called_vim_beep = TRUE; |
1061 #endif | 1060 #endif |
1062 | 1061 |
1066 { | 1065 { |
1067 #ifdef ELAPSED_FUNC | 1066 #ifdef ELAPSED_FUNC |
1068 static int did_init = FALSE; | 1067 static int did_init = FALSE; |
1069 static elapsed_T start_tv; | 1068 static elapsed_T start_tv; |
1070 | 1069 |
1071 /* Only beep once per half a second, otherwise a sequence of beeps | 1070 // Only beep once per half a second, otherwise a sequence of beeps |
1072 * would freeze Vim. */ | 1071 // would freeze Vim. |
1073 if (!did_init || ELAPSED_FUNC(start_tv) > 500) | 1072 if (!did_init || ELAPSED_FUNC(start_tv) > 500) |
1074 { | 1073 { |
1075 did_init = TRUE; | 1074 did_init = TRUE; |
1076 ELAPSED_INIT(start_tv); | 1075 ELAPSED_INIT(start_tv); |
1077 #endif | 1076 #endif |
1078 if (p_vb | 1077 if (p_vb |
1079 #ifdef FEAT_GUI | 1078 #ifdef FEAT_GUI |
1080 /* While the GUI is starting up the termcap is set for | 1079 // While the GUI is starting up the termcap is set for |
1081 * the GUI but the output still goes to a terminal. */ | 1080 // the GUI but the output still goes to a terminal. |
1082 && !(gui.in_use && gui.starting) | 1081 && !(gui.in_use && gui.starting) |
1083 #endif | 1082 #endif |
1084 ) | 1083 ) |
1085 { | 1084 { |
1086 out_str_cf(T_VB); | 1085 out_str_cf(T_VB); |
1087 #ifdef FEAT_VTP | 1086 #ifdef FEAT_VTP |
1088 /* No restore color information, refresh the screen. */ | 1087 // No restore color information, refresh the screen. |
1089 if (has_vtp_working() != 0 | 1088 if (has_vtp_working() != 0 |
1090 # ifdef FEAT_TERMGUICOLORS | 1089 # ifdef FEAT_TERMGUICOLORS |
1091 && (p_tgc || (!p_tgc && t_colors >= 256)) | 1090 && (p_tgc || (!p_tgc && t_colors >= 256)) |
1092 # endif | 1091 # endif |
1093 ) | 1092 ) |
1103 #ifdef ELAPSED_FUNC | 1102 #ifdef ELAPSED_FUNC |
1104 } | 1103 } |
1105 #endif | 1104 #endif |
1106 } | 1105 } |
1107 | 1106 |
1108 /* When 'debug' contains "beep" produce a message. If we are sourcing | 1107 // When 'debug' contains "beep" produce a message. If we are sourcing |
1109 * a script or executing a function give the user a hint where the beep | 1108 // a script or executing a function give the user a hint where the beep |
1110 * comes from. */ | 1109 // comes from. |
1111 if (vim_strchr(p_debug, 'e') != NULL) | 1110 if (vim_strchr(p_debug, 'e') != NULL) |
1112 { | 1111 { |
1113 msg_source(HL_ATTR(HLF_W)); | 1112 msg_source(HL_ATTR(HLF_W)); |
1114 msg_attr(_("Beep!"), HL_ATTR(HLF_W)); | 1113 msg_attr(_("Beep!"), HL_ATTR(HLF_W)); |
1115 } | 1114 } |
1130 void | 1129 void |
1131 init_homedir(void) | 1130 init_homedir(void) |
1132 { | 1131 { |
1133 char_u *var; | 1132 char_u *var; |
1134 | 1133 |
1135 /* In case we are called a second time (when 'encoding' changes). */ | 1134 // In case we are called a second time (when 'encoding' changes). |
1136 VIM_CLEAR(homedir); | 1135 VIM_CLEAR(homedir); |
1137 | 1136 |
1138 #ifdef VMS | 1137 #ifdef VMS |
1139 var = mch_getenv((char_u *)"SYS$LOGIN"); | 1138 var = mch_getenv((char_u *)"SYS$LOGIN"); |
1140 #else | 1139 #else |
1190 var = NameBuff; | 1189 var = NameBuff; |
1191 } | 1190 } |
1192 } | 1191 } |
1193 } | 1192 } |
1194 | 1193 |
1195 if (var != NULL && *var == NUL) /* empty is same as not set */ | 1194 if (var != NULL && *var == NUL) // empty is same as not set |
1196 var = NULL; | 1195 var = NULL; |
1197 | 1196 |
1198 if (enc_utf8 && var != NULL) | 1197 if (enc_utf8 && var != NULL) |
1199 { | 1198 { |
1200 int len; | 1199 int len; |
1201 char_u *pp = NULL; | 1200 char_u *pp = NULL; |
1202 | 1201 |
1203 /* Convert from active codepage to UTF-8. Other conversions are | 1202 // Convert from active codepage to UTF-8. Other conversions are |
1204 * not done, because they would fail for non-ASCII characters. */ | 1203 // not done, because they would fail for non-ASCII characters. |
1205 acp_to_enc(var, (int)STRLEN(var), &pp, &len); | 1204 acp_to_enc(var, (int)STRLEN(var), &pp, &len); |
1206 if (pp != NULL) | 1205 if (pp != NULL) |
1207 { | 1206 { |
1208 homedir = pp; | 1207 homedir = pp; |
1209 return; | 1208 return; |
1284 * Skips over "\ ", "\~" and "\$" (not for Win32 though). | 1283 * Skips over "\ ", "\~" and "\$" (not for Win32 though). |
1285 * If anything fails no expansion is done and dst equals src. | 1284 * If anything fails no expansion is done and dst equals src. |
1286 */ | 1285 */ |
1287 void | 1286 void |
1288 expand_env( | 1287 expand_env( |
1289 char_u *src, /* input string e.g. "$HOME/vim.hlp" */ | 1288 char_u *src, // input string e.g. "$HOME/vim.hlp" |
1290 char_u *dst, /* where to put the result */ | 1289 char_u *dst, // where to put the result |
1291 int dstlen) /* maximum length of the result */ | 1290 int dstlen) // maximum length of the result |
1292 { | 1291 { |
1293 expand_env_esc(src, dst, dstlen, FALSE, FALSE, NULL); | 1292 expand_env_esc(src, dst, dstlen, FALSE, FALSE, NULL); |
1294 } | 1293 } |
1295 | 1294 |
1296 void | 1295 void |
1297 expand_env_esc( | 1296 expand_env_esc( |
1298 char_u *srcp, /* input string e.g. "$HOME/vim.hlp" */ | 1297 char_u *srcp, // input string e.g. "$HOME/vim.hlp" |
1299 char_u *dst, /* where to put the result */ | 1298 char_u *dst, // where to put the result |
1300 int dstlen, /* maximum length of the result */ | 1299 int dstlen, // maximum length of the result |
1301 int esc, /* escape spaces in expanded variables */ | 1300 int esc, // escape spaces in expanded variables |
1302 int one, /* "srcp" is one file name */ | 1301 int one, // "srcp" is one file name |
1303 char_u *startstr) /* start again after this (can be NULL) */ | 1302 char_u *startstr) // start again after this (can be NULL) |
1304 { | 1303 { |
1305 char_u *src; | 1304 char_u *src; |
1306 char_u *tail; | 1305 char_u *tail; |
1307 int c; | 1306 int c; |
1308 char_u *var; | 1307 char_u *var; |
1309 int copy_char; | 1308 int copy_char; |
1310 int mustfree; /* var was allocated, need to free it later */ | 1309 int mustfree; // var was allocated, need to free it later |
1311 int at_start = TRUE; /* at start of a name */ | 1310 int at_start = TRUE; // at start of a name |
1312 int startstr_len = 0; | 1311 int startstr_len = 0; |
1313 | 1312 |
1314 if (startstr != NULL) | 1313 if (startstr != NULL) |
1315 startstr_len = (int)STRLEN(startstr); | 1314 startstr_len = (int)STRLEN(startstr); |
1316 | 1315 |
1317 src = skipwhite(srcp); | 1316 src = skipwhite(srcp); |
1318 --dstlen; /* leave one char space for "\," */ | 1317 --dstlen; // leave one char space for "\," |
1319 while (*src && dstlen > 0) | 1318 while (*src && dstlen > 0) |
1320 { | 1319 { |
1321 #ifdef FEAT_EVAL | 1320 #ifdef FEAT_EVAL |
1322 /* Skip over `=expr`. */ | 1321 // Skip over `=expr`. |
1323 if (src[0] == '`' && src[1] == '=') | 1322 if (src[0] == '`' && src[1] == '=') |
1324 { | 1323 { |
1325 size_t len; | 1324 size_t len; |
1326 | 1325 |
1327 var = src; | 1326 var = src; |
1353 | 1352 |
1354 /* | 1353 /* |
1355 * The variable name is copied into dst temporarily, because it may | 1354 * The variable name is copied into dst temporarily, because it may |
1356 * be a string in read-only memory and a NUL needs to be appended. | 1355 * be a string in read-only memory and a NUL needs to be appended. |
1357 */ | 1356 */ |
1358 if (*src != '~') /* environment var */ | 1357 if (*src != '~') // environment var |
1359 { | 1358 { |
1360 tail = src + 1; | 1359 tail = src + 1; |
1361 var = dst; | 1360 var = dst; |
1362 c = dstlen - 1; | 1361 c = dstlen - 1; |
1363 | 1362 |
1364 #ifdef UNIX | 1363 #ifdef UNIX |
1365 /* Unix has ${var-name} type environment vars */ | 1364 // Unix has ${var-name} type environment vars |
1366 if (*tail == '{' && !vim_isIDc('{')) | 1365 if (*tail == '{' && !vim_isIDc('{')) |
1367 { | 1366 { |
1368 tail++; /* ignore '{' */ | 1367 tail++; // ignore '{' |
1369 while (c-- > 0 && *tail && *tail != '}') | 1368 while (c-- > 0 && *tail && *tail != '}') |
1370 *var++ = *tail++; | 1369 *var++ = *tail++; |
1371 } | 1370 } |
1372 else | 1371 else |
1373 #endif | 1372 #endif |
1400 var = vim_getenv(dst, &mustfree); | 1399 var = vim_getenv(dst, &mustfree); |
1401 #if defined(MSWIN) || defined(UNIX) | 1400 #if defined(MSWIN) || defined(UNIX) |
1402 } | 1401 } |
1403 #endif | 1402 #endif |
1404 } | 1403 } |
1405 /* home directory */ | 1404 // home directory |
1406 else if ( src[1] == NUL | 1405 else if ( src[1] == NUL |
1407 || vim_ispathsep(src[1]) | 1406 || vim_ispathsep(src[1]) |
1408 || vim_strchr((char_u *)" ,\t\n", src[1]) != NULL) | 1407 || vim_strchr((char_u *)" ,\t\n", src[1]) != NULL) |
1409 { | 1408 { |
1410 var = homedir; | 1409 var = homedir; |
1411 tail = src + 1; | 1410 tail = src + 1; |
1412 } | 1411 } |
1413 else /* user directory */ | 1412 else // user directory |
1414 { | 1413 { |
1415 #if defined(UNIX) || (defined(VMS) && defined(USER_HOME)) | 1414 #if defined(UNIX) || (defined(VMS) && defined(USER_HOME)) |
1416 /* | 1415 /* |
1417 * Copy ~user to dst[], so we can put a NUL after it. | 1416 * Copy ~user to dst[], so we can put a NUL after it. |
1418 */ | 1417 */ |
1432 * expand ~user. This is slower and may fail if the shell | 1431 * expand ~user. This is slower and may fail if the shell |
1433 * does not support ~user (old versions of /bin/sh). | 1432 * does not support ~user (old versions of /bin/sh). |
1434 */ | 1433 */ |
1435 # if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H) | 1434 # if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H) |
1436 { | 1435 { |
1437 /* Note: memory allocated by getpwnam() is never freed. | 1436 // Note: memory allocated by getpwnam() is never freed. |
1438 * Calling endpwent() apparently doesn't help. */ | 1437 // Calling endpwent() apparently doesn't help. |
1439 struct passwd *pw = (*dst == NUL) | 1438 struct passwd *pw = (*dst == NUL) |
1440 ? NULL : getpwnam((char *)dst + 1); | 1439 ? NULL : getpwnam((char *)dst + 1); |
1441 | 1440 |
1442 var = (pw == NULL) ? NULL : (char_u *)pw->pw_dir; | 1441 var = (pw == NULL) ? NULL : (char_u *)pw->pw_dir; |
1443 } | 1442 } |
1451 var = ExpandOne(&xpc, dst, NULL, | 1450 var = ExpandOne(&xpc, dst, NULL, |
1452 WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE); | 1451 WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE); |
1453 mustfree = TRUE; | 1452 mustfree = TRUE; |
1454 } | 1453 } |
1455 | 1454 |
1456 # else /* !UNIX, thus VMS */ | 1455 # else // !UNIX, thus VMS |
1457 /* | 1456 /* |
1458 * USER_HOME is a comma-separated list of | 1457 * USER_HOME is a comma-separated list of |
1459 * directories to search for the user account in. | 1458 * directories to search for the user account in. |
1460 */ | 1459 */ |
1461 { | 1460 { |
1481 mustfree = TRUE; | 1480 mustfree = TRUE; |
1482 break; | 1481 break; |
1483 } | 1482 } |
1484 } | 1483 } |
1485 } | 1484 } |
1486 # endif /* UNIX */ | 1485 # endif // UNIX |
1487 #else | 1486 #else |
1488 /* cannot expand user's home directory, so don't try */ | 1487 // cannot expand user's home directory, so don't try |
1489 var = NULL; | 1488 var = NULL; |
1490 tail = (char_u *)""; /* for gcc */ | 1489 tail = (char_u *)""; // for gcc |
1491 #endif /* UNIX || VMS */ | 1490 #endif // UNIX || VMS |
1492 } | 1491 } |
1493 | 1492 |
1494 #ifdef BACKSLASH_IN_FILENAME | 1493 #ifdef BACKSLASH_IN_FILENAME |
1495 /* If 'shellslash' is set change backslashes to forward slashes. | 1494 // If 'shellslash' is set change backslashes to forward slashes. |
1496 * Can't use slash_adjust(), p_ssl may be set temporarily. */ | 1495 // Can't use slash_adjust(), p_ssl may be set temporarily. |
1497 if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL) | 1496 if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL) |
1498 { | 1497 { |
1499 char_u *p = vim_strsave(var); | 1498 char_u *p = vim_strsave(var); |
1500 | 1499 |
1501 if (p != NULL) | 1500 if (p != NULL) |
1507 forward_slash(var); | 1506 forward_slash(var); |
1508 } | 1507 } |
1509 } | 1508 } |
1510 #endif | 1509 #endif |
1511 | 1510 |
1512 /* If "var" contains white space, escape it with a backslash. | 1511 // If "var" contains white space, escape it with a backslash. |
1513 * Required for ":e ~/tt" when $HOME includes a space. */ | 1512 // Required for ":e ~/tt" when $HOME includes a space. |
1514 if (esc && var != NULL && vim_strpbrk(var, (char_u *)" \t") != NULL) | 1513 if (esc && var != NULL && vim_strpbrk(var, (char_u *)" \t") != NULL) |
1515 { | 1514 { |
1516 char_u *p = vim_strsave_escaped(var, (char_u *)" \t"); | 1515 char_u *p = vim_strsave_escaped(var, (char_u *)" \t"); |
1517 | 1516 |
1518 if (p != NULL) | 1517 if (p != NULL) |
1528 && (STRLEN(var) + STRLEN(tail) + 1 < (unsigned)dstlen)) | 1527 && (STRLEN(var) + STRLEN(tail) + 1 < (unsigned)dstlen)) |
1529 { | 1528 { |
1530 STRCPY(dst, var); | 1529 STRCPY(dst, var); |
1531 dstlen -= (int)STRLEN(var); | 1530 dstlen -= (int)STRLEN(var); |
1532 c = (int)STRLEN(var); | 1531 c = (int)STRLEN(var); |
1533 /* if var[] ends in a path separator and tail[] starts | 1532 // if var[] ends in a path separator and tail[] starts |
1534 * with it, skip a character */ | 1533 // with it, skip a character |
1535 if (*var != NUL && after_pathsep(dst, dst + c) | 1534 if (*var != NUL && after_pathsep(dst, dst + c) |
1536 #if defined(BACKSLASH_IN_FILENAME) || defined(AMIGA) | 1535 #if defined(BACKSLASH_IN_FILENAME) || defined(AMIGA) |
1537 && dst[-1] != ':' | 1536 && dst[-1] != ':' |
1538 #endif | 1537 #endif |
1539 && vim_ispathsep(*tail)) | 1538 && vim_ispathsep(*tail)) |
1544 } | 1543 } |
1545 if (mustfree) | 1544 if (mustfree) |
1546 vim_free(var); | 1545 vim_free(var); |
1547 } | 1546 } |
1548 | 1547 |
1549 if (copy_char) /* copy at least one char */ | 1548 if (copy_char) // copy at least one char |
1550 { | 1549 { |
1551 /* | 1550 /* |
1552 * Recognize the start of a new name, for '~'. | 1551 * Recognize the start of a new name, for '~'. |
1553 * Don't do this when "one" is TRUE, to avoid expanding "~" in | 1552 * Don't do this when "one" is TRUE, to avoid expanding "~" in |
1554 * ":edit foo ~ foo". | 1553 * ":edit foo ~ foo". |
1727 else | 1726 else |
1728 p = exe_name; | 1727 p = exe_name; |
1729 #endif | 1728 #endif |
1730 if (p != NULL) | 1729 if (p != NULL) |
1731 { | 1730 { |
1732 /* remove the file name */ | 1731 // remove the file name |
1733 pend = gettail(p); | 1732 pend = gettail(p); |
1734 | 1733 |
1735 /* remove "doc/" from 'helpfile', if present */ | 1734 // remove "doc/" from 'helpfile', if present |
1736 if (p == p_hf) | 1735 if (p == p_hf) |
1737 pend = remove_tail(p, pend, (char_u *)"doc"); | 1736 pend = remove_tail(p, pend, (char_u *)"doc"); |
1738 | 1737 |
1739 #ifdef USE_EXE_NAME | 1738 #ifdef USE_EXE_NAME |
1740 # ifdef MACOS_X | 1739 # ifdef MACOS_X |
1741 /* remove "MacOS" from exe_name and add "Resources/vim" */ | 1740 // remove "MacOS" from exe_name and add "Resources/vim" |
1742 if (p == exe_name) | 1741 if (p == exe_name) |
1743 { | 1742 { |
1744 char_u *pend1; | 1743 char_u *pend1; |
1745 char_u *pnew; | 1744 char_u *pnew; |
1746 | 1745 |
1756 pend = p + STRLEN(p); | 1755 pend = p + STRLEN(p); |
1757 } | 1756 } |
1758 } | 1757 } |
1759 } | 1758 } |
1760 # endif | 1759 # endif |
1761 /* remove "src/" from exe_name, if present */ | 1760 // remove "src/" from exe_name, if present |
1762 if (p == exe_name) | 1761 if (p == exe_name) |
1763 pend = remove_tail(p, pend, (char_u *)"src"); | 1762 pend = remove_tail(p, pend, (char_u *)"src"); |
1764 #endif | 1763 #endif |
1765 | 1764 |
1766 /* for $VIM, remove "runtime/" or "vim54/", if present */ | 1765 // for $VIM, remove "runtime/" or "vim54/", if present |
1767 if (!vimruntime) | 1766 if (!vimruntime) |
1768 { | 1767 { |
1769 pend = remove_tail(p, pend, (char_u *)RUNTIME_DIRNAME); | 1768 pend = remove_tail(p, pend, (char_u *)RUNTIME_DIRNAME); |
1770 pend = remove_tail(p, pend, (char_u *)VIM_VERSION_NODOT); | 1769 pend = remove_tail(p, pend, (char_u *)VIM_VERSION_NODOT); |
1771 } | 1770 } |
1772 | 1771 |
1773 /* remove trailing path separator */ | 1772 // remove trailing path separator |
1774 if (pend > p && after_pathsep(p, pend)) | 1773 if (pend > p && after_pathsep(p, pend)) |
1775 --pend; | 1774 --pend; |
1776 | 1775 |
1777 #ifdef MACOS_X | 1776 #ifdef MACOS_X |
1778 if (p == exe_name || p == p_hf) | 1777 if (p == exe_name || p == p_hf) |
1779 #endif | 1778 #endif |
1780 /* check that the result is a directory name */ | 1779 // check that the result is a directory name |
1781 p = vim_strnsave(p, (int)(pend - p)); | 1780 p = vim_strnsave(p, (int)(pend - p)); |
1782 | 1781 |
1783 if (p != NULL && !mch_isdir(p)) | 1782 if (p != NULL && !mch_isdir(p)) |
1784 VIM_CLEAR(p); | 1783 VIM_CLEAR(p); |
1785 else | 1784 else |
1786 { | 1785 { |
1787 #ifdef USE_EXE_NAME | 1786 #ifdef USE_EXE_NAME |
1788 /* may add "/vim54" or "/runtime" if it exists */ | 1787 // may add "/vim54" or "/runtime" if it exists |
1789 if (vimruntime && (pend = vim_version_dir(p)) != NULL) | 1788 if (vimruntime && (pend = vim_version_dir(p)) != NULL) |
1790 { | 1789 { |
1791 vim_free(p); | 1790 vim_free(p); |
1792 p = pend; | 1791 p = pend; |
1793 } | 1792 } |
1796 } | 1795 } |
1797 } | 1796 } |
1798 } | 1797 } |
1799 | 1798 |
1800 #ifdef HAVE_PATHDEF | 1799 #ifdef HAVE_PATHDEF |
1801 /* When there is a pathdef.c file we can use default_vim_dir and | 1800 // When there is a pathdef.c file we can use default_vim_dir and |
1802 * default_vimruntime_dir */ | 1801 // default_vimruntime_dir |
1803 if (p == NULL) | 1802 if (p == NULL) |
1804 { | 1803 { |
1805 /* Only use default_vimruntime_dir when it is not empty */ | 1804 // Only use default_vimruntime_dir when it is not empty |
1806 if (vimruntime && *default_vimruntime_dir != NUL) | 1805 if (vimruntime && *default_vimruntime_dir != NUL) |
1807 { | 1806 { |
1808 p = default_vimruntime_dir; | 1807 p = default_vimruntime_dir; |
1809 *mustfree = FALSE; | 1808 *mustfree = FALSE; |
1810 } | 1809 } |
1907 * No environ[] on the Amiga. | 1906 * No environ[] on the Amiga. |
1908 */ | 1907 */ |
1909 return NULL; | 1908 return NULL; |
1910 # else | 1909 # else |
1911 # ifndef __WIN32__ | 1910 # ifndef __WIN32__ |
1912 /* Borland C++ 5.2 has this in a header file. */ | 1911 // Borland C++ 5.2 has this in a header file. |
1913 extern char **environ; | 1912 extern char **environ; |
1914 # endif | 1913 # endif |
1915 # define ENVNAMELEN 100 | 1914 # define ENVNAMELEN 100 |
1916 static char_u name[ENVNAMELEN]; | 1915 static char_u name[ENVNAMELEN]; |
1917 char_u *str; | 1916 char_u *str; |
2051 | 2050 |
2052 init_users(); | 2051 init_users(); |
2053 for (i = 0; i < ga_users.ga_len; i++) | 2052 for (i = 0; i < ga_users.ga_len; i++) |
2054 { | 2053 { |
2055 if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0) | 2054 if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0) |
2056 return 2; /* full match */ | 2055 return 2; // full match |
2057 if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0) | 2056 if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0) |
2058 result = 1; /* partial match */ | 2057 result = 1; // partial match |
2059 } | 2058 } |
2060 return result; | 2059 return result; |
2061 } | 2060 } |
2062 | 2061 |
2063 /* | 2062 /* |
2081 | 2080 |
2082 static void | 2081 static void |
2083 prepare_to_exit(void) | 2082 prepare_to_exit(void) |
2084 { | 2083 { |
2085 #if defined(SIGHUP) && defined(SIG_IGN) | 2084 #if defined(SIGHUP) && defined(SIG_IGN) |
2086 /* Ignore SIGHUP, because a dropped connection causes a read error, which | 2085 // Ignore SIGHUP, because a dropped connection causes a read error, which |
2087 * makes Vim exit and then handling SIGHUP causes various reentrance | 2086 // makes Vim exit and then handling SIGHUP causes various reentrance |
2088 * problems. */ | 2087 // problems. |
2089 signal(SIGHUP, SIG_IGN); | 2088 signal(SIGHUP, SIG_IGN); |
2090 #endif | 2089 #endif |
2091 | 2090 |
2092 #ifdef FEAT_GUI | 2091 #ifdef FEAT_GUI |
2093 if (gui.in_use) | 2092 if (gui.in_use) |
2094 { | 2093 { |
2095 gui.dying = TRUE; | 2094 gui.dying = TRUE; |
2096 out_trash(); /* trash any pending output */ | 2095 out_trash(); // trash any pending output |
2097 } | 2096 } |
2098 else | 2097 else |
2099 #endif | 2098 #endif |
2100 { | 2099 { |
2101 windgoto((int)Rows - 1, 0); | 2100 windgoto((int)Rows - 1, 0); |
2121 { | 2120 { |
2122 buf_T *buf; | 2121 buf_T *buf; |
2123 | 2122 |
2124 prepare_to_exit(); | 2123 prepare_to_exit(); |
2125 | 2124 |
2126 /* Setting this will prevent free() calls. That avoids calling free() | 2125 // Setting this will prevent free() calls. That avoids calling free() |
2127 * recursively when free() was invoked with a bad pointer. */ | 2126 // recursively when free() was invoked with a bad pointer. |
2128 really_exiting = TRUE; | 2127 really_exiting = TRUE; |
2129 | 2128 |
2130 out_str(IObuff); | 2129 out_str(IObuff); |
2131 screen_start(); /* don't know where cursor is now */ | 2130 screen_start(); // don't know where cursor is now |
2132 out_flush(); | 2131 out_flush(); |
2133 | 2132 |
2134 ml_close_notmod(); /* close all not-modified buffers */ | 2133 ml_close_notmod(); // close all not-modified buffers |
2135 | 2134 |
2136 FOR_ALL_BUFFERS(buf) | 2135 FOR_ALL_BUFFERS(buf) |
2137 { | 2136 { |
2138 if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) | 2137 if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) |
2139 { | 2138 { |
2140 OUT_STR("Vim: preserving files...\n"); | 2139 OUT_STR("Vim: preserving files...\n"); |
2141 screen_start(); /* don't know where cursor is now */ | 2140 screen_start(); // don't know where cursor is now |
2142 out_flush(); | 2141 out_flush(); |
2143 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | 2142 ml_sync_all(FALSE, FALSE); // preserve all swap files |
2144 break; | 2143 break; |
2145 } | 2144 } |
2146 } | 2145 } |
2147 | 2146 |
2148 ml_close_all(FALSE); /* close all memfiles, without deleting */ | 2147 ml_close_all(FALSE); // close all memfiles, without deleting |
2149 | 2148 |
2150 OUT_STR("Vim: Finished.\n"); | 2149 OUT_STR("Vim: Finished.\n"); |
2151 | 2150 |
2152 getout(1); | 2151 getout(1); |
2153 } | 2152 } |
2206 * Returns an allocated string, or NULL for error. | 2205 * Returns an allocated string, or NULL for error. |
2207 */ | 2206 */ |
2208 char_u * | 2207 char_u * |
2209 get_cmd_output( | 2208 get_cmd_output( |
2210 char_u *cmd, | 2209 char_u *cmd, |
2211 char_u *infile, /* optional input file name */ | 2210 char_u *infile, // optional input file name |
2212 int flags, /* can be SHELL_SILENT */ | 2211 int flags, // can be SHELL_SILENT |
2213 int *ret_len) | 2212 int *ret_len) |
2214 { | 2213 { |
2215 char_u *tempname; | 2214 char_u *tempname; |
2216 char_u *command; | 2215 char_u *command; |
2217 char_u *buffer = NULL; | 2216 char_u *buffer = NULL; |
2220 FILE *fd; | 2219 FILE *fd; |
2221 | 2220 |
2222 if (check_restricted() || check_secure()) | 2221 if (check_restricted() || check_secure()) |
2223 return NULL; | 2222 return NULL; |
2224 | 2223 |
2225 /* get a name for the temp file */ | 2224 // get a name for the temp file |
2226 if ((tempname = vim_tempname('o', FALSE)) == NULL) | 2225 if ((tempname = vim_tempname('o', FALSE)) == NULL) |
2227 { | 2226 { |
2228 emsg(_(e_notmp)); | 2227 emsg(_(e_notmp)); |
2229 return NULL; | 2228 return NULL; |
2230 } | 2229 } |
2231 | 2230 |
2232 /* Add the redirection stuff */ | 2231 // Add the redirection stuff |
2233 command = make_filter_cmd(cmd, infile, tempname); | 2232 command = make_filter_cmd(cmd, infile, tempname); |
2234 if (command == NULL) | 2233 if (command == NULL) |
2235 goto done; | 2234 goto done; |
2236 | 2235 |
2237 /* | 2236 /* |
2246 | 2245 |
2247 /* | 2246 /* |
2248 * read the names from the file into memory | 2247 * read the names from the file into memory |
2249 */ | 2248 */ |
2250 # ifdef VMS | 2249 # ifdef VMS |
2251 /* created temporary file is not always readable as binary */ | 2250 // created temporary file is not always readable as binary |
2252 fd = mch_fopen((char *)tempname, "r"); | 2251 fd = mch_fopen((char *)tempname, "r"); |
2253 # else | 2252 # else |
2254 fd = mch_fopen((char *)tempname, READBIN); | 2253 fd = mch_fopen((char *)tempname, READBIN); |
2255 # endif | 2254 # endif |
2256 | 2255 |
2259 semsg(_(e_notopen), tempname); | 2258 semsg(_(e_notopen), tempname); |
2260 goto done; | 2259 goto done; |
2261 } | 2260 } |
2262 | 2261 |
2263 fseek(fd, 0L, SEEK_END); | 2262 fseek(fd, 0L, SEEK_END); |
2264 len = ftell(fd); /* get size of temp file */ | 2263 len = ftell(fd); // get size of temp file |
2265 fseek(fd, 0L, SEEK_SET); | 2264 fseek(fd, 0L, SEEK_SET); |
2266 | 2265 |
2267 buffer = alloc(len + 1); | 2266 buffer = alloc(len + 1); |
2268 if (buffer != NULL) | 2267 if (buffer != NULL) |
2269 i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd); | 2268 i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd); |
2270 fclose(fd); | 2269 fclose(fd); |
2271 mch_remove(tempname); | 2270 mch_remove(tempname); |
2272 if (buffer == NULL) | 2271 if (buffer == NULL) |
2273 goto done; | 2272 goto done; |
2274 #ifdef VMS | 2273 #ifdef VMS |
2275 len = i; /* VMS doesn't give us what we asked for... */ | 2274 len = i; // VMS doesn't give us what we asked for... |
2276 #endif | 2275 #endif |
2277 if (i != len) | 2276 if (i != len) |
2278 { | 2277 { |
2279 semsg(_(e_notread), tempname); | 2278 semsg(_(e_notread), tempname); |
2280 VIM_CLEAR(buffer); | 2279 VIM_CLEAR(buffer); |
2281 } | 2280 } |
2282 else if (ret_len == NULL) | 2281 else if (ret_len == NULL) |
2283 { | 2282 { |
2284 /* Change NUL into SOH, otherwise the string is truncated. */ | 2283 // Change NUL into SOH, otherwise the string is truncated. |
2285 for (i = 0; i < len; ++i) | 2284 for (i = 0; i < len; ++i) |
2286 if (buffer[i] == NUL) | 2285 if (buffer[i] == NUL) |
2287 buffer[i] = 1; | 2286 buffer[i] = 1; |
2288 | 2287 |
2289 buffer[len] = NUL; /* make sure the buffer is terminated */ | 2288 buffer[len] = NUL; // make sure the buffer is terminated |
2290 } | 2289 } |
2291 else | 2290 else |
2292 *ret_len = len; | 2291 *ret_len = len; |
2293 | 2292 |
2294 done: | 2293 done: |
2375 | 2374 |
2376 p = tv_get_string_buf_chk(&argvars[1], buf); | 2375 p = tv_get_string_buf_chk(&argvars[1], buf); |
2377 if (p == NULL) | 2376 if (p == NULL) |
2378 { | 2377 { |
2379 fclose(fd); | 2378 fclose(fd); |
2380 goto errret; /* type error; errmsg already given */ | 2379 goto errret; // type error; errmsg already given |
2381 } | 2380 } |
2382 len = STRLEN(p); | 2381 len = STRLEN(p); |
2383 if (len > 0 && fwrite(p, len, 1, fd) != 1) | 2382 if (len > 0 && fwrite(p, len, 1, fd) != 1) |
2384 err = TRUE; | 2383 err = TRUE; |
2385 } | 2384 } |
2390 emsg(_("E677: Error writing temp file")); | 2389 emsg(_("E677: Error writing temp file")); |
2391 goto errret; | 2390 goto errret; |
2392 } | 2391 } |
2393 } | 2392 } |
2394 | 2393 |
2395 /* Omit SHELL_COOKED when invoked with ":silent". Avoids that the shell | 2394 // Omit SHELL_COOKED when invoked with ":silent". Avoids that the shell |
2396 * echoes typeahead, that messes up the display. */ | 2395 // echoes typeahead, that messes up the display. |
2397 if (!msg_silent) | 2396 if (!msg_silent) |
2398 flags += SHELL_COOKED; | 2397 flags += SHELL_COOKED; |
2399 | 2398 |
2400 if (retlist) | 2399 if (retlist) |
2401 { | 2400 { |
2446 } | 2445 } |
2447 else | 2446 else |
2448 { | 2447 { |
2449 res = get_cmd_output(tv_get_string(&argvars[0]), infile, flags, NULL); | 2448 res = get_cmd_output(tv_get_string(&argvars[0]), infile, flags, NULL); |
2450 #ifdef USE_CRNL | 2449 #ifdef USE_CRNL |
2451 /* translate <CR><NL> into <NL> */ | 2450 // translate <CR><NL> into <NL> |
2452 if (res != NULL) | 2451 if (res != NULL) |
2453 { | 2452 { |
2454 char_u *s, *d; | 2453 char_u *s, *d; |
2455 | 2454 |
2456 d = res; | 2455 d = res; |
2529 p = vim_strnsave(p, (int)(skiptowhite(p) - p)); | 2528 p = vim_strnsave(p, (int)(skiptowhite(p) - p)); |
2530 #else | 2529 #else |
2531 p = skiptowhite(p_sh); | 2530 p = skiptowhite(p_sh); |
2532 if (*p == NUL) | 2531 if (*p == NUL) |
2533 { | 2532 { |
2534 /* No white space, use the tail. */ | 2533 // No white space, use the tail. |
2535 p = vim_strsave(gettail(p_sh)); | 2534 p = vim_strsave(gettail(p_sh)); |
2536 } | 2535 } |
2537 else | 2536 else |
2538 { | 2537 { |
2539 char_u *p1, *p2; | 2538 char_u *p1, *p2; |
2540 | 2539 |
2541 /* Find the last path separator before the space. */ | 2540 // Find the last path separator before the space. |
2542 p1 = p_sh; | 2541 p1 = p_sh; |
2543 for (p2 = p_sh; p2 < p; MB_PTR_ADV(p2)) | 2542 for (p2 = p_sh; p2 < p; MB_PTR_ADV(p2)) |
2544 if (vim_ispathsep(*p2)) | 2543 if (vim_ispathsep(*p2)) |
2545 p1 = p2 + 1; | 2544 p1 = p2 + 1; |
2546 p = vim_strnsave(p1, (int)(p - p1)); | 2545 p = vim_strnsave(p1, (int)(p - p1)); |
2591 | 2590 |
2592 if (vim_time() - tt >= 100) | 2591 if (vim_time() - tt >= 100) |
2593 { | 2592 { |
2594 curtime = vim_localtime(&tt, &tmval); | 2593 curtime = vim_localtime(&tt, &tmval); |
2595 if (vim_time() - tt < (60L * 60L * 12L)) | 2594 if (vim_time() - tt < (60L * 60L * 12L)) |
2596 /* within 12 hours */ | 2595 // within 12 hours |
2597 (void)strftime((char *)buf, buflen, "%H:%M:%S", curtime); | 2596 (void)strftime((char *)buf, buflen, "%H:%M:%S", curtime); |
2598 else | 2597 else |
2599 /* longer ago */ | 2598 // longer ago |
2600 (void)strftime((char *)buf, buflen, "%Y/%m/%d %H:%M:%S", curtime); | 2599 (void)strftime((char *)buf, buflen, "%Y/%m/%d %H:%M:%S", curtime); |
2601 } | 2600 } |
2602 else | 2601 else |
2603 #endif | 2602 #endif |
2604 { | 2603 { |