comparison src/quickfix.c @ 14899:e35d98651e56 v8.1.0461

patch 8.1.0461: quickfix code uses too many /* */ comments commit https://github.com/vim/vim/commit/00bf8cd2115be7c14258aee48c0a7568147c9cd7 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Oct 7 20:26:20 2018 +0200 patch 8.1.0461: quickfix code uses too many /* */ comments Problem: Quickfix code uses too many /* */ comments. Solution: Change to // comments. (Yegappan Lakshmanan)
author Bram Moolenaar <Bram@vim.org>
date Sun, 07 Oct 2018 20:30:07 +0200
parents 863bdbc8465b
children f508bb2fb808
comparison
equal deleted inserted replaced
14898:732f1b2f4cc0 14899:e35d98651e56
25 * For each error the next struct is allocated and linked in a list. 25 * For each error the next struct is allocated and linked in a list.
26 */ 26 */
27 typedef struct qfline_S qfline_T; 27 typedef struct qfline_S qfline_T;
28 struct qfline_S 28 struct qfline_S
29 { 29 {
30 qfline_T *qf_next; /* pointer to next error in the list */ 30 qfline_T *qf_next; // pointer to next error in the list
31 qfline_T *qf_prev; /* pointer to previous error in the list */ 31 qfline_T *qf_prev; // pointer to previous error in the list
32 linenr_T qf_lnum; /* line number where the error occurred */ 32 linenr_T qf_lnum; // line number where the error occurred
33 int qf_fnum; /* file number for the line */ 33 int qf_fnum; // file number for the line
34 int qf_col; /* column where the error occurred */ 34 int qf_col; // column where the error occurred
35 int qf_nr; /* error number */ 35 int qf_nr; // error number
36 char_u *qf_module; /* module name for this error */ 36 char_u *qf_module; // module name for this error
37 char_u *qf_pattern; /* search pattern for the error */ 37 char_u *qf_pattern; // search pattern for the error
38 char_u *qf_text; /* description of the error */ 38 char_u *qf_text; // description of the error
39 char_u qf_viscol; /* set to TRUE if qf_col is screen column */ 39 char_u qf_viscol; // set to TRUE if qf_col is screen column
40 char_u qf_cleared; /* set to TRUE if line has been deleted */ 40 char_u qf_cleared; // set to TRUE if line has been deleted
41 char_u qf_type; /* type of the error (mostly 'E'); 1 for 41 char_u qf_type; // type of the error (mostly 'E'); 1 for
42 :helpgrep */ 42 // :helpgrep
43 char_u qf_valid; /* valid error message detected */ 43 char_u qf_valid; // valid error message detected
44 }; 44 };
45 45
46 /* 46 /*
47 * There is a stack of error lists. 47 * There is a stack of error lists.
48 */ 48 */
58 * created using setqflist()/setloclist() with a title and/or user context 58 * created using setqflist()/setloclist() with a title and/or user context
59 * information and entries can be added later using setqflist()/setloclist(). 59 * information and entries can be added later using setqflist()/setloclist().
60 */ 60 */
61 typedef struct qf_list_S 61 typedef struct qf_list_S
62 { 62 {
63 int_u qf_id; /* Unique identifier for this list */ 63 int_u qf_id; // Unique identifier for this list
64 qfline_T *qf_start; /* pointer to the first error */ 64 qfline_T *qf_start; // pointer to the first error
65 qfline_T *qf_last; /* pointer to the last error */ 65 qfline_T *qf_last; // pointer to the last error
66 qfline_T *qf_ptr; /* pointer to the current error */ 66 qfline_T *qf_ptr; // pointer to the current error
67 int qf_count; /* number of errors (0 means empty list) */ 67 int qf_count; // number of errors (0 means empty list)
68 int qf_index; /* current index in the error list */ 68 int qf_index; // current index in the error list
69 int qf_nonevalid; /* TRUE if not a single valid entry found */ 69 int qf_nonevalid; // TRUE if not a single valid entry found
70 char_u *qf_title; /* title derived from the command that created 70 char_u *qf_title; // title derived from the command that created
71 * the error list or set by setqflist */ 71 // the error list or set by setqflist
72 typval_T *qf_ctx; /* context set by setqflist/setloclist */ 72 typval_T *qf_ctx; // context set by setqflist/setloclist
73 73
74 struct dir_stack_T *qf_dir_stack; 74 struct dir_stack_T *qf_dir_stack;
75 char_u *qf_directory; 75 char_u *qf_directory;
76 struct dir_stack_T *qf_file_stack; 76 struct dir_stack_T *qf_file_stack;
77 char_u *qf_currfile; 77 char_u *qf_currfile;
85 * Quickfix/Location list stack definition 85 * Quickfix/Location list stack definition
86 * Contains a list of quickfix/location lists (qf_list_T) 86 * Contains a list of quickfix/location lists (qf_list_T)
87 */ 87 */
88 struct qf_info_S 88 struct qf_info_S
89 { 89 {
90 /* 90 // Count of references to this list. Used only for location lists.
91 * Count of references to this list. Used only for location lists. 91 // When a location list window reference this list, qf_refcount
92 * When a location list window reference this list, qf_refcount 92 // will be 2. Otherwise, qf_refcount will be 1. When qf_refcount
93 * will be 2. Otherwise, qf_refcount will be 1. When qf_refcount 93 // reaches 0, the list is freed.
94 * reaches 0, the list is freed.
95 */
96 int qf_refcount; 94 int qf_refcount;
97 int qf_listcount; /* current number of lists */ 95 int qf_listcount; // current number of lists
98 int qf_curlist; /* current error list */ 96 int qf_curlist; // current error list
99 qf_list_T qf_lists[LISTCOUNT]; 97 qf_list_T qf_lists[LISTCOUNT];
100 }; 98 };
101 99
102 static qf_info_T ql_info; /* global quickfix list */ 100 static qf_info_T ql_info; // global quickfix list
103 static int_u last_qf_id = 0; /* Last used quickfix list id */ 101 static int_u last_qf_id = 0; // Last used quickfix list id
104 102
105 #define FMT_PATTERNS 11 /* maximum number of % recognized */ 103 #define FMT_PATTERNS 11 // maximum number of % recognized
106 104
107 /* 105 /*
108 * Structure used to hold the info of one part of 'errorformat' 106 * Structure used to hold the info of one part of 'errorformat'
109 */ 107 */
110 typedef struct efm_S efm_T; 108 typedef struct efm_S efm_T;
111 struct efm_S 109 struct efm_S
112 { 110 {
113 regprog_T *prog; /* pre-formatted part of 'errorformat' */ 111 regprog_T *prog; // pre-formatted part of 'errorformat'
114 efm_T *next; /* pointer to next (NULL if last) */ 112 efm_T *next; // pointer to next (NULL if last)
115 char_u addr[FMT_PATTERNS]; /* indices of used % patterns */ 113 char_u addr[FMT_PATTERNS]; // indices of used % patterns
116 char_u prefix; /* prefix of this format line: */ 114 char_u prefix; // prefix of this format line:
117 /* 'D' enter directory */ 115 // 'D' enter directory
118 /* 'X' leave directory */ 116 // 'X' leave directory
119 /* 'A' start of multi-line message */ 117 // 'A' start of multi-line message
120 /* 'E' error message */ 118 // 'E' error message
121 /* 'W' warning message */ 119 // 'W' warning message
122 /* 'I' informational message */ 120 // 'I' informational message
123 /* 'C' continuation line */ 121 // 'C' continuation line
124 /* 'Z' end of multi-line message */ 122 // 'Z' end of multi-line message
125 /* 'G' general, unspecific message */ 123 // 'G' general, unspecific message
126 /* 'P' push file (partial) message */ 124 // 'P' push file (partial) message
127 /* 'Q' pop/quit file (partial) message */ 125 // 'Q' pop/quit file (partial) message
128 /* 'O' overread (partial) message */ 126 // 'O' overread (partial) message
129 char_u flags; /* additional flags given in prefix */ 127 char_u flags; // additional flags given in prefix
130 /* '-' do not include this line */ 128 // '-' do not include this line
131 /* '+' include whole line in message */ 129 // '+' include whole line in message
132 int conthere; /* %> used */ 130 int conthere; // %> used
133 }; 131 };
134 132
135 static efm_T *fmt_start = NULL; /* cached across qf_parse_line() calls */ 133 static efm_T *fmt_start = NULL; // cached across qf_parse_line() calls
136 134
137 static void qf_new_list(qf_info_T *qi, char_u *qf_title); 135 static void qf_new_list(qf_info_T *qi, char_u *qf_title);
138 static int qf_add_entry(qf_info_T *qi, int qf_idx, char_u *dir, char_u *fname, char_u *module, int bufnum, char_u *mesg, long lnum, int col, int vis_col, char_u *pattern, int nr, int type, int valid); 136 static int qf_add_entry(qf_info_T *qi, int qf_idx, char_u *dir, char_u *fname, char_u *module, int bufnum, char_u *mesg, long lnum, int col, int vis_col, char_u *pattern, int nr, int type, int valid);
139 static void qf_free(qf_list_T *qfl); 137 static void qf_free(qf_list_T *qfl);
140 static char_u *qf_types(int, int); 138 static char_u *qf_types(int, int);
151 static buf_T *load_dummy_buffer(char_u *fname, char_u *dirname_start, char_u *resulting_dir); 149 static buf_T *load_dummy_buffer(char_u *fname, char_u *dirname_start, char_u *resulting_dir);
152 static void wipe_dummy_buffer(buf_T *buf, char_u *dirname_start); 150 static void wipe_dummy_buffer(buf_T *buf, char_u *dirname_start);
153 static void unload_dummy_buffer(buf_T *buf, char_u *dirname_start); 151 static void unload_dummy_buffer(buf_T *buf, char_u *dirname_start);
154 static qf_info_T *ll_get_or_alloc_list(win_T *); 152 static qf_info_T *ll_get_or_alloc_list(win_T *);
155 153
156 /* Quickfix window check helper macro */ 154 // Quickfix window check helper macro
157 #define IS_QF_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref == NULL) 155 #define IS_QF_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref == NULL)
158 /* Location list window check helper macro */ 156 // Location list window check helper macro
159 #define IS_LL_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL) 157 #define IS_LL_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL)
160 158
161 // Quickfix and location list stack check helper macros 159 // Quickfix and location list stack check helper macros
162 #define IS_QF_STACK(qi) (qi == &ql_info) 160 #define IS_QF_STACK(qi) (qi == &ql_info)
163 #define IS_LL_STACK(qi) (qi != &ql_info) 161 #define IS_LL_STACK(qi) (qi != &ql_info)
187 { 185 {
188 char_u convchar; 186 char_u convchar;
189 char *pattern; 187 char *pattern;
190 } fmt_pat[FMT_PATTERNS] = 188 } fmt_pat[FMT_PATTERNS] =
191 { 189 {
192 {'f', ".\\+"}, /* only used when at end */ 190 {'f', ".\\+"}, // only used when at end
193 {'n', "\\d\\+"}, 191 {'n', "\\d\\+"},
194 {'l', "\\d\\+"}, 192 {'l', "\\d\\+"},
195 {'c', "\\d\\+"}, 193 {'c', "\\d\\+"},
196 {'t', "."}, 194 {'t', "."},
197 {'m', ".\\+"}, 195 {'m', ".\\+"},
219 { 217 {
220 char_u *srcptr; 218 char_u *srcptr;
221 219
222 if (efminfo->addr[idx]) 220 if (efminfo->addr[idx])
223 { 221 {
224 /* Each errorformat pattern can occur only once */ 222 // Each errorformat pattern can occur only once
225 sprintf((char *)errmsg, 223 sprintf((char *)errmsg,
226 _("E372: Too many %%%c in format string"), *efmpat); 224 _("E372: Too many %%%c in format string"), *efmpat);
227 EMSG(errmsg); 225 EMSG(errmsg);
228 return NULL; 226 return NULL;
229 } 227 }
241 *regpat++ = '\\'; 239 *regpat++ = '\\';
242 *regpat++ = '('; 240 *regpat++ = '(';
243 #ifdef BACKSLASH_IN_FILENAME 241 #ifdef BACKSLASH_IN_FILENAME
244 if (*efmpat == 'f') 242 if (*efmpat == 'f')
245 { 243 {
246 /* Also match "c:" in the file name, even when 244 // Also match "c:" in the file name, even when
247 * checking for a colon next: "%f:". 245 // checking for a colon next: "%f:".
248 * "\%(\a:\)\=" */ 246 // "\%(\a:\)\="
249 STRCPY(regpat, "\\%(\\a:\\)\\="); 247 STRCPY(regpat, "\\%(\\a:\\)\\=");
250 regpat += 10; 248 regpat += 10;
251 } 249 }
252 #endif 250 #endif
253 if (*efmpat == 'f' && efmpat[1] != NUL) 251 if (*efmpat == 'f' && efmpat[1] != NUL)
254 { 252 {
255 if (efmpat[1] != '\\' && efmpat[1] != '%') 253 if (efmpat[1] != '\\' && efmpat[1] != '%')
256 { 254 {
257 /* A file name may contain spaces, but this isn't 255 // A file name may contain spaces, but this isn't
258 * in "\f". For "%f:%l:%m" there may be a ":" in 256 // in "\f". For "%f:%l:%m" there may be a ":" in
259 * the file name. Use ".\{-1,}x" instead (x is 257 // the file name. Use ".\{-1,}x" instead (x is
260 * the next character), the requirement that :999: 258 // the next character), the requirement that :999:
261 * follows should work. */ 259 // follows should work.
262 STRCPY(regpat, ".\\{-1,}"); 260 STRCPY(regpat, ".\\{-1,}");
263 regpat += 7; 261 regpat += 7;
264 } 262 }
265 else 263 else
266 { 264 {
267 /* File name followed by '\\' or '%': include as 265 // File name followed by '\\' or '%': include as
268 * many file name chars as possible. */ 266 // many file name chars as possible.
269 STRCPY(regpat, "\\f\\+"); 267 STRCPY(regpat, "\\f\\+");
270 regpat += 4; 268 regpat += 4;
271 } 269 }
272 } 270 }
273 else 271 else
296 { 294 {
297 char_u *efmp = *pefmp; 295 char_u *efmp = *pefmp;
298 296
299 if (*efmp == '[' || *efmp == '\\') 297 if (*efmp == '[' || *efmp == '\\')
300 { 298 {
301 if ((*regpat++ = *efmp) == '[') /* %*[^a-z0-9] etc. */ 299 if ((*regpat++ = *efmp) == '[') // %*[^a-z0-9] etc.
302 { 300 {
303 if (efmp[1] == '^') 301 if (efmp[1] == '^')
304 *regpat++ = *++efmp; 302 *regpat++ = *++efmp;
305 if (efmp < efm + len) 303 if (efmp < efm + len)
306 { 304 {
307 *regpat++ = *++efmp; /* could be ']' */ 305 *regpat++ = *++efmp; // could be ']'
308 while (efmp < efm + len 306 while (efmp < efm + len
309 && (*regpat++ = *++efmp) != ']') 307 && (*regpat++ = *++efmp) != ']')
310 /* skip */; 308 // skip ;
311 if (efmp == efm + len) 309 if (efmp == efm + len)
312 { 310 {
313 EMSG(_("E374: Missing ] in format string")); 311 EMSG(_("E374: Missing ] in format string"));
314 return NULL; 312 return NULL;
315 } 313 }
316 } 314 }
317 } 315 }
318 else if (efmp < efm + len) /* %*\D, %*\s etc. */ 316 else if (efmp < efm + len) // %*\D, %*\s etc.
319 *regpat++ = *++efmp; 317 *regpat++ = *++efmp;
320 *regpat++ = '\\'; 318 *regpat++ = '\\';
321 *regpat++ = '+'; 319 *regpat++ = '+';
322 } 320 }
323 else 321 else
324 { 322 {
325 /* TODO: scanf()-like: %*ud, %*3c, %*f, ... ? */ 323 // TODO: scanf()-like: %*ud, %*3c, %*f, ... ?
326 sprintf((char *)errmsg, 324 sprintf((char *)errmsg,
327 _("E375: Unsupported %%%c in format string"), *efmp); 325 _("E375: Unsupported %%%c in format string"), *efmp);
328 EMSG(errmsg); 326 EMSG(errmsg);
329 return NULL; 327 return NULL;
330 } 328 }
372 char_u *ptr; 370 char_u *ptr;
373 char_u *efmp; 371 char_u *efmp;
374 int round; 372 int round;
375 int idx = 0; 373 int idx = 0;
376 374
377 /* 375 // Build a regexp pattern for a 'errorformat' option part
378 * Build a regexp pattern for a 'errorformat' option part
379 */
380 ptr = regpat; 376 ptr = regpat;
381 *ptr++ = '^'; 377 *ptr++ = '^';
382 round = 0; 378 round = 0;
383 for (efmp = efm; efmp < efm + len; ++efmp) 379 for (efmp = efm; efmp < efm + len; ++efmp)
384 { 380 {
402 ptr = scanf_fmt_to_regpat(&efmp, efm, len, ptr, errmsg); 398 ptr = scanf_fmt_to_regpat(&efmp, efm, len, ptr, errmsg);
403 if (ptr == NULL) 399 if (ptr == NULL)
404 return FAIL; 400 return FAIL;
405 } 401 }
406 else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL) 402 else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL)
407 *ptr++ = *efmp; /* regexp magic characters */ 403 *ptr++ = *efmp; // regexp magic characters
408 else if (*efmp == '#') 404 else if (*efmp == '#')
409 *ptr++ = '*'; 405 *ptr++ = '*';
410 else if (*efmp == '>') 406 else if (*efmp == '>')
411 fmt_ptr->conthere = TRUE; 407 fmt_ptr->conthere = TRUE;
412 else if (efmp == efm + 1) /* analyse prefix */ 408 else if (efmp == efm + 1) // analyse prefix
413 { 409 {
414 /* 410 // prefix is allowed only at the beginning of the errorformat
415 * prefix is allowed only at the beginning of the errorformat 411 // option part
416 * option part
417 */
418 efmp = efm_analyze_prefix(efmp, fmt_ptr, errmsg); 412 efmp = efm_analyze_prefix(efmp, fmt_ptr, errmsg);
419 if (efmp == NULL) 413 if (efmp == NULL)
420 return FAIL; 414 return FAIL;
421 } 415 }
422 else 416 else
425 _("E377: Invalid %%%c in format string"), *efmp); 419 _("E377: Invalid %%%c in format string"), *efmp);
426 EMSG(errmsg); 420 EMSG(errmsg);
427 return FAIL; 421 return FAIL;
428 } 422 }
429 } 423 }
430 else /* copy normal character */ 424 else // copy normal character
431 { 425 {
432 if (*efmp == '\\' && efmp + 1 < efm + len) 426 if (*efmp == '\\' && efmp + 1 < efm + len)
433 ++efmp; 427 ++efmp;
434 else if (vim_strchr((char_u *)".*^$~[", *efmp) != NULL) 428 else if (vim_strchr((char_u *)".*^$~[", *efmp) != NULL)
435 *ptr++ = '\\'; /* escape regexp atoms */ 429 *ptr++ = '\\'; // escape regexp atoms
436 if (*efmp) 430 if (*efmp)
437 *ptr++ = *efmp; 431 *ptr++ = *efmp;
438 } 432 }
439 } 433 }
440 *ptr++ = '$'; 434 *ptr++ = '$';
472 466
473 sz = (FMT_PATTERNS * 3) + ((int)STRLEN(efm) << 2); 467 sz = (FMT_PATTERNS * 3) + ((int)STRLEN(efm) << 2);
474 for (i = FMT_PATTERNS; i > 0; ) 468 for (i = FMT_PATTERNS; i > 0; )
475 sz += (int)STRLEN(fmt_pat[--i].pattern); 469 sz += (int)STRLEN(fmt_pat[--i].pattern);
476 #ifdef BACKSLASH_IN_FILENAME 470 #ifdef BACKSLASH_IN_FILENAME
477 sz += 12; /* "%f" can become twelve chars longer (see efm_to_regpat) */ 471 sz += 12; // "%f" can become twelve chars longer (see efm_to_regpat)
478 #else 472 #else
479 sz += 2; /* "%f" can become two chars longer */ 473 sz += 2; // "%f" can become two chars longer
480 #endif 474 #endif
481 475
482 return sz; 476 return sz;
483 } 477 }
484 478
517 errmsglen = CMDBUFFSIZE + 1; 511 errmsglen = CMDBUFFSIZE + 1;
518 errmsg = alloc_id(errmsglen, aid_qf_errmsg); 512 errmsg = alloc_id(errmsglen, aid_qf_errmsg);
519 if (errmsg == NULL) 513 if (errmsg == NULL)
520 goto parse_efm_end; 514 goto parse_efm_end;
521 515
522 /* 516 // Each part of the format string is copied and modified from errorformat
523 * Each part of the format string is copied and modified from errorformat 517 // to regex prog. Only a few % characters are allowed.
524 * to regex prog. Only a few % characters are allowed. 518
525 */ 519 // Get some space to modify the format string into.
526
527 /*
528 * Get some space to modify the format string into.
529 */
530 sz = efm_regpat_bufsz(efm); 520 sz = efm_regpat_bufsz(efm);
531 if ((fmtstr = alloc(sz)) == NULL) 521 if ((fmtstr = alloc(sz)) == NULL)
532 goto parse_efm_error; 522 goto parse_efm_error;
533 523
534 while (efm[0] != NUL) 524 while (efm[0] != NUL)
535 { 525 {
536 /* 526 // Allocate a new eformat structure and put it at the end of the list
537 * Allocate a new eformat structure and put it at the end of the list
538 */
539 fmt_ptr = (efm_T *)alloc_clear((unsigned)sizeof(efm_T)); 527 fmt_ptr = (efm_T *)alloc_clear((unsigned)sizeof(efm_T));
540 if (fmt_ptr == NULL) 528 if (fmt_ptr == NULL)
541 goto parse_efm_error; 529 goto parse_efm_error;
542 if (fmt_first == NULL) /* first one */ 530 if (fmt_first == NULL) // first one
543 fmt_first = fmt_ptr; 531 fmt_first = fmt_ptr;
544 else 532 else
545 fmt_last->next = fmt_ptr; 533 fmt_last->next = fmt_ptr;
546 fmt_last = fmt_ptr; 534 fmt_last = fmt_ptr;
547 535
548 /* 536 // Isolate one part in the 'errorformat' option
549 * Isolate one part in the 'errorformat' option
550 */
551 len = efm_option_part_len(efm); 537 len = efm_option_part_len(efm);
552 538
553 if (efm_to_regpat(efm, len, fmt_ptr, fmtstr, errmsg) == FAIL) 539 if (efm_to_regpat(efm, len, fmt_ptr, fmtstr, errmsg) == FAIL)
554 goto parse_efm_error; 540 goto parse_efm_error;
555 if ((fmt_ptr->prog = vim_regcomp(fmtstr, RE_MAGIC + RE_STRING)) == NULL) 541 if ((fmt_ptr->prog = vim_regcomp(fmtstr, RE_MAGIC + RE_STRING)) == NULL)
556 goto parse_efm_error; 542 goto parse_efm_error;
557 /* 543 // Advance to next part
558 * Advance to next part 544 efm = skip_to_option_part(efm + len); // skip comma and spaces
559 */ 545 }
560 efm = skip_to_option_part(efm + len); /* skip comma and spaces */ 546
561 } 547 if (fmt_first == NULL) // nothing found
562
563 if (fmt_first == NULL) /* nothing found */
564 EMSG(_("E378: 'errorformat' contains no pattern")); 548 EMSG(_("E378: 'errorformat' contains no pattern"));
565 549
566 goto parse_efm_end; 550 goto parse_efm_end;
567 551
568 parse_efm_error: 552 parse_efm_error:
609 static char_u * 593 static char_u *
610 qf_grow_linebuf(qfstate_T *state, int newsz) 594 qf_grow_linebuf(qfstate_T *state, int newsz)
611 { 595 {
612 char_u *p; 596 char_u *p;
613 597
614 /* 598 // If the line exceeds LINE_MAXLEN exclude the last
615 * If the line exceeds LINE_MAXLEN exclude the last 599 // byte since it's not a NL character.
616 * byte since it's not a NL character.
617 */
618 state->linelen = newsz > LINE_MAXLEN ? LINE_MAXLEN - 1 : newsz; 600 state->linelen = newsz > LINE_MAXLEN ? LINE_MAXLEN - 1 : newsz;
619 if (state->growbuf == NULL) 601 if (state->growbuf == NULL)
620 { 602 {
621 state->growbuf = alloc(state->linelen + 1); 603 state->growbuf = alloc(state->linelen + 1);
622 if (state->growbuf == NULL) 604 if (state->growbuf == NULL)
637 * Get the next string (separated by newline) from state->p_str. 619 * Get the next string (separated by newline) from state->p_str.
638 */ 620 */
639 static int 621 static int
640 qf_get_next_str_line(qfstate_T *state) 622 qf_get_next_str_line(qfstate_T *state)
641 { 623 {
642 /* Get the next line from the supplied string */ 624 // Get the next line from the supplied string
643 char_u *p_str = state->p_str; 625 char_u *p_str = state->p_str;
644 char_u *p; 626 char_u *p;
645 int len; 627 int len;
646 628
647 if (*p_str == NUL) /* Reached the end of the string */ 629 if (*p_str == NUL) // Reached the end of the string
648 return QF_END_OF_INPUT; 630 return QF_END_OF_INPUT;
649 631
650 p = vim_strchr(p_str, '\n'); 632 p = vim_strchr(p_str, '\n');
651 if (p != NULL) 633 if (p != NULL)
652 len = (int)(p - p_str) + 1; 634 len = (int)(p - p_str) + 1;
664 state->linebuf = IObuff; 646 state->linebuf = IObuff;
665 state->linelen = len; 647 state->linelen = len;
666 } 648 }
667 vim_strncpy(state->linebuf, p_str, state->linelen); 649 vim_strncpy(state->linebuf, p_str, state->linelen);
668 650
669 /* 651 // Increment using len in order to discard the rest of the
670 * Increment using len in order to discard the rest of the 652 // line if it exceeds LINE_MAXLEN.
671 * line if it exceeds LINE_MAXLEN.
672 */
673 p_str += len; 653 p_str += len;
674 state->p_str = p_str; 654 state->p_str = p_str;
675 655
676 return QF_OK; 656 return QF_OK;
677 } 657 }
686 int len; 666 int len;
687 667
688 while (p_li != NULL 668 while (p_li != NULL
689 && (p_li->li_tv.v_type != VAR_STRING 669 && (p_li->li_tv.v_type != VAR_STRING
690 || p_li->li_tv.vval.v_string == NULL)) 670 || p_li->li_tv.vval.v_string == NULL))
691 p_li = p_li->li_next; /* Skip non-string items */ 671 p_li = p_li->li_next; // Skip non-string items
692 672
693 if (p_li == NULL) /* End of the list */ 673 if (p_li == NULL) // End of the list
694 { 674 {
695 state->p_li = NULL; 675 state->p_li = NULL;
696 return QF_END_OF_INPUT; 676 return QF_END_OF_INPUT;
697 } 677 }
698 678
709 state->linelen = len; 689 state->linelen = len;
710 } 690 }
711 691
712 vim_strncpy(state->linebuf, p_li->li_tv.vval.v_string, state->linelen); 692 vim_strncpy(state->linebuf, p_li->li_tv.vval.v_string, state->linelen);
713 693
714 state->p_li = p_li->li_next; /* next item */ 694 state->p_li = p_li->li_next; // next item
715 return QF_OK; 695 return QF_OK;
716 } 696 }
717 697
718 /* 698 /*
719 * Get the next string from state->buf. 699 * Get the next string from state->buf.
722 qf_get_next_buf_line(qfstate_T *state) 702 qf_get_next_buf_line(qfstate_T *state)
723 { 703 {
724 char_u *p_buf = NULL; 704 char_u *p_buf = NULL;
725 int len; 705 int len;
726 706
727 /* Get the next line from the supplied buffer */ 707 // Get the next line from the supplied buffer
728 if (state->buflnum > state->lnumlast) 708 if (state->buflnum > state->lnumlast)
729 return QF_END_OF_INPUT; 709 return QF_END_OF_INPUT;
730 710
731 p_buf = ml_get_buf(state->buf, state->buflnum, FALSE); 711 p_buf = ml_get_buf(state->buf, state->buflnum, FALSE);
732 state->buflnum += 1; 712 state->buflnum += 1;
762 742
763 discard = FALSE; 743 discard = FALSE;
764 state->linelen = (int)STRLEN(IObuff); 744 state->linelen = (int)STRLEN(IObuff);
765 if (state->linelen == IOSIZE - 1 && !(IObuff[state->linelen - 1] == '\n')) 745 if (state->linelen == IOSIZE - 1 && !(IObuff[state->linelen - 1] == '\n'))
766 { 746 {
767 /* 747 // The current line exceeds IObuff, continue reading using
768 * The current line exceeds IObuff, continue reading using 748 // growbuf until EOL or LINE_MAXLEN bytes is read.
769 * growbuf until EOL or LINE_MAXLEN bytes is read.
770 */
771 if (state->growbuf == NULL) 749 if (state->growbuf == NULL)
772 { 750 {
773 state->growbufsiz = 2 * (IOSIZE - 1); 751 state->growbufsiz = 2 * (IOSIZE - 1);
774 state->growbuf = alloc(state->growbufsiz); 752 state->growbuf = alloc(state->growbufsiz);
775 if (state->growbuf == NULL) 753 if (state->growbuf == NULL)
776 return QF_NOMEM; 754 return QF_NOMEM;
777 } 755 }
778 756
779 /* Copy the read part of the line, excluding null-terminator */ 757 // Copy the read part of the line, excluding null-terminator
780 memcpy(state->growbuf, IObuff, IOSIZE - 1); 758 memcpy(state->growbuf, IObuff, IOSIZE - 1);
781 growbuflen = state->linelen; 759 growbuflen = state->linelen;
782 760
783 for (;;) 761 for (;;)
784 { 762 {
804 state->growbuf = p; 782 state->growbuf = p;
805 } 783 }
806 784
807 while (discard) 785 while (discard)
808 { 786 {
809 /* 787 // The current line is longer than LINE_MAXLEN, continue
810 * The current line is longer than LINE_MAXLEN, continue 788 // reading but discard everything until EOL or EOF is
811 * reading but discard everything until EOL or EOF is 789 // reached.
812 * reached.
813 */
814 if (fgets((char *)IObuff, IOSIZE, state->fd) == NULL 790 if (fgets((char *)IObuff, IOSIZE, state->fd) == NULL
815 || (int)STRLEN(IObuff) < IOSIZE - 1 791 || (int)STRLEN(IObuff) < IOSIZE - 1
816 || IObuff[IOSIZE - 1] == '\n') 792 || IObuff[IOSIZE - 1] == '\n')
817 break; 793 break;
818 } 794 }
822 } 798 }
823 else 799 else
824 state->linebuf = IObuff; 800 state->linebuf = IObuff;
825 801
826 #ifdef FEAT_MBYTE 802 #ifdef FEAT_MBYTE
827 /* Convert a line if it contains a non-ASCII character. */ 803 // Convert a line if it contains a non-ASCII character.
828 if (state->vc.vc_type != CONV_NONE && has_non_ascii(state->linebuf)) 804 if (state->vc.vc_type != CONV_NONE && has_non_ascii(state->linebuf))
829 { 805 {
830 char_u *line; 806 char_u *line;
831 807
832 line = string_convert(&state->vc, state->linebuf, &state->linelen); 808 line = string_convert(&state->vc, state->linebuf, &state->linelen);
862 if (state->fd == NULL) 838 if (state->fd == NULL)
863 { 839 {
864 if (state->tv != NULL) 840 if (state->tv != NULL)
865 { 841 {
866 if (state->tv->v_type == VAR_STRING) 842 if (state->tv->v_type == VAR_STRING)
867 /* Get the next line from the supplied string */ 843 // Get the next line from the supplied string
868 status = qf_get_next_str_line(state); 844 status = qf_get_next_str_line(state);
869 else if (state->tv->v_type == VAR_LIST) 845 else if (state->tv->v_type == VAR_LIST)
870 /* Get the next line from the supplied list */ 846 // Get the next line from the supplied list
871 status = qf_get_next_list_line(state); 847 status = qf_get_next_list_line(state);
872 } 848 }
873 else 849 else
874 /* Get the next line from the supplied buffer */ 850 // Get the next line from the supplied buffer
875 status = qf_get_next_buf_line(state); 851 status = qf_get_next_buf_line(state);
876 } 852 }
877 else 853 else
878 /* Get the next line from the supplied file */ 854 // Get the next line from the supplied file
879 status = qf_get_next_file_line(state); 855 status = qf_get_next_file_line(state);
880 856
881 if (status != QF_OK) 857 if (status != QF_OK)
882 return status; 858 return status;
883 859
884 /* remove newline/CR from the line */ 860 // remove newline/CR from the line
885 if (state->linelen > 0 && state->linebuf[state->linelen - 1] == '\n') 861 if (state->linelen > 0 && state->linebuf[state->linelen - 1] == '\n')
886 { 862 {
887 state->linebuf[state->linelen - 1] = NUL; 863 state->linebuf[state->linelen - 1] = NUL;
888 #ifdef USE_CRNL 864 #ifdef USE_CRNL
889 if (state->linelen > 1 && state->linebuf[state->linelen - 2] == '\r') 865 if (state->linelen > 1 && state->linebuf[state->linelen - 2] == '\r')
922 int c; 898 int c;
923 899
924 if (rmp->startp[midx] == NULL || rmp->endp[midx] == NULL) 900 if (rmp->startp[midx] == NULL || rmp->endp[midx] == NULL)
925 return QF_FAIL; 901 return QF_FAIL;
926 902
927 /* Expand ~/file and $HOME/file to full path. */ 903 // Expand ~/file and $HOME/file to full path.
928 c = *rmp->endp[midx]; 904 c = *rmp->endp[midx];
929 *rmp->endp[midx] = NUL; 905 *rmp->endp[midx] = NUL;
930 expand_env(rmp->startp[midx], fields->namebuf, CMDBUFFSIZE); 906 expand_env(rmp->startp[midx], fields->namebuf, CMDBUFFSIZE);
931 *rmp->endp[midx] = c; 907 *rmp->endp[midx] = c;
932 908
933 /* 909 // For separate filename patterns (%O, %P and %Q), the specified file
934 * For separate filename patterns (%O, %P and %Q), the specified file 910 // should exist.
935 * should exist.
936 */
937 if (vim_strchr((char_u *)"OPQ", prefix) != NULL 911 if (vim_strchr((char_u *)"OPQ", prefix) != NULL
938 && mch_getperm(fields->namebuf) == -1) 912 && mch_getperm(fields->namebuf) == -1)
939 return QF_FAIL; 913 return QF_FAIL;
940 914
941 return QF_OK; 915 return QF_OK;
1002 { 976 {
1003 char_u *p; 977 char_u *p;
1004 978
1005 if (linelen >= fields->errmsglen) 979 if (linelen >= fields->errmsglen)
1006 { 980 {
1007 /* linelen + null terminator */ 981 // linelen + null terminator
1008 if ((p = vim_realloc(fields->errmsg, linelen + 1)) == NULL) 982 if ((p = vim_realloc(fields->errmsg, linelen + 1)) == NULL)
1009 return QF_NOMEM; 983 return QF_NOMEM;
1010 fields->errmsg = p; 984 fields->errmsg = p;
1011 fields->errmsglen = linelen + 1; 985 fields->errmsglen = linelen + 1;
1012 } 986 }
1027 if (rmp->startp[midx] == NULL || rmp->endp[midx] == NULL) 1001 if (rmp->startp[midx] == NULL || rmp->endp[midx] == NULL)
1028 return QF_FAIL; 1002 return QF_FAIL;
1029 len = (int)(rmp->endp[midx] - rmp->startp[midx]); 1003 len = (int)(rmp->endp[midx] - rmp->startp[midx]);
1030 if (len >= fields->errmsglen) 1004 if (len >= fields->errmsglen)
1031 { 1005 {
1032 /* len + null terminator */ 1006 // len + null terminator
1033 if ((p = vim_realloc(fields->errmsg, len + 1)) == NULL) 1007 if ((p = vim_realloc(fields->errmsg, len + 1)) == NULL)
1034 return QF_NOMEM; 1008 return QF_NOMEM;
1035 fields->errmsg = p; 1009 fields->errmsg = p;
1036 fields->errmsglen = len + 1; 1010 fields->errmsglen = len + 1;
1037 } 1011 }
1179 return QF_FAIL; 1153 return QF_FAIL;
1180 if (vim_strchr((char_u *)"EWI", idx) != NULL) 1154 if (vim_strchr((char_u *)"EWI", idx) != NULL)
1181 fields->type = idx; 1155 fields->type = idx;
1182 else 1156 else
1183 fields->type = 0; 1157 fields->type = 0;
1184 /* 1158
1185 * Extract error message data from matched line. 1159 // Extract error message data from matched line.
1186 * We check for an actual submatch, because "\[" and "\]" in 1160 // We check for an actual submatch, because "\[" and "\]" in
1187 * the 'errorformat' may cause the wrong submatch to be used. 1161 // the 'errorformat' may cause the wrong submatch to be used.
1188 */
1189 for (i = 0; i < FMT_PATTERNS; i++) 1162 for (i = 0; i < FMT_PATTERNS; i++)
1190 { 1163 {
1191 status = QF_OK; 1164 status = QF_OK;
1192 midx = (int)fmt_ptr->addr[i]; 1165 midx = (int)fmt_ptr->addr[i];
1193 if (i == 0 && midx > 0) /* %f */ 1166 if (i == 0 && midx > 0) // %f
1194 status = qf_parse_fmt_f(regmatch, midx, fields, idx); 1167 status = qf_parse_fmt_f(regmatch, midx, fields, idx);
1195 else if (i == 5) 1168 else if (i == 5)
1196 { 1169 {
1197 if (fmt_ptr->flags == '+' && !qf_multiscan) /* %+ */ 1170 if (fmt_ptr->flags == '+' && !qf_multiscan) // %+
1198 status = qf_parse_fmt_plus(linebuf, linelen, fields); 1171 status = qf_parse_fmt_plus(linebuf, linelen, fields);
1199 else if (midx > 0) /* %m */ 1172 else if (midx > 0) // %m
1200 status = qf_parse_fmt_m(regmatch, midx, fields); 1173 status = qf_parse_fmt_m(regmatch, midx, fields);
1201 } 1174 }
1202 else if (i == 6 && midx > 0) /* %r */ 1175 else if (i == 6 && midx > 0) // %r
1203 status = qf_parse_fmt_r(regmatch, midx, tail); 1176 status = qf_parse_fmt_r(regmatch, midx, tail);
1204 else if (midx > 0) /* others */ 1177 else if (midx > 0) // others
1205 status = (qf_parse_fmt[i])(regmatch, midx, fields); 1178 status = (qf_parse_fmt[i])(regmatch, midx, fields);
1206 1179
1207 if (status != QF_OK) 1180 if (status != QF_OK)
1208 return status; 1181 return status;
1209 } 1182 }
1245 fields->use_viscol = FALSE; 1218 fields->use_viscol = FALSE;
1246 fields->enr = -1; 1219 fields->enr = -1;
1247 fields->type = 0; 1220 fields->type = 0;
1248 *tail = NULL; 1221 *tail = NULL;
1249 1222
1250 /* Always ignore case when looking for a matching error. */ 1223 // Always ignore case when looking for a matching error.
1251 regmatch.rm_ic = TRUE; 1224 regmatch.rm_ic = TRUE;
1252 regmatch.regprog = fmt_ptr->prog; 1225 regmatch.regprog = fmt_ptr->prog;
1253 r = vim_regexec(&regmatch, linebuf, (colnr_T)0); 1226 r = vim_regexec(&regmatch, linebuf, (colnr_T)0);
1254 fmt_ptr->prog = regmatch.regprog; 1227 fmt_ptr->prog = regmatch.regprog;
1255 if (r) 1228 if (r)
1265 * names. 1238 * names.
1266 */ 1239 */
1267 static int 1240 static int
1268 qf_parse_dir_pfx(int idx, qffields_T *fields, qf_list_T *qfl) 1241 qf_parse_dir_pfx(int idx, qffields_T *fields, qf_list_T *qfl)
1269 { 1242 {
1270 if (idx == 'D') /* enter directory */ 1243 if (idx == 'D') // enter directory
1271 { 1244 {
1272 if (*fields->namebuf == NUL) 1245 if (*fields->namebuf == NUL)
1273 { 1246 {
1274 EMSG(_("E379: Missing or empty directory name")); 1247 EMSG(_("E379: Missing or empty directory name"));
1275 return QF_FAIL; 1248 return QF_FAIL;
1277 qfl->qf_directory = 1250 qfl->qf_directory =
1278 qf_push_dir(fields->namebuf, &qfl->qf_dir_stack, FALSE); 1251 qf_push_dir(fields->namebuf, &qfl->qf_dir_stack, FALSE);
1279 if (qfl->qf_directory == NULL) 1252 if (qfl->qf_directory == NULL)
1280 return QF_FAIL; 1253 return QF_FAIL;
1281 } 1254 }
1282 else if (idx == 'X') /* leave directory */ 1255 else if (idx == 'X') // leave directory
1283 qfl->qf_directory = qf_pop_dir(&qfl->qf_dir_stack); 1256 qfl->qf_directory = qf_pop_dir(&qfl->qf_dir_stack);
1284 1257
1285 return QF_OK; 1258 return QF_OK;
1286 } 1259 }
1287 1260
1322 static int 1295 static int
1323 qf_parse_line_nomatch(char_u *linebuf, int linelen, qffields_T *fields) 1296 qf_parse_line_nomatch(char_u *linebuf, int linelen, qffields_T *fields)
1324 { 1297 {
1325 char_u *p; 1298 char_u *p;
1326 1299
1327 fields->namebuf[0] = NUL; /* no match found, remove file name */ 1300 fields->namebuf[0] = NUL; // no match found, remove file name
1328 fields->lnum = 0; /* don't jump to this line */ 1301 fields->lnum = 0; // don't jump to this line
1329 fields->valid = FALSE; 1302 fields->valid = FALSE;
1330 if (linelen >= fields->errmsglen) 1303 if (linelen >= fields->errmsglen)
1331 { 1304 {
1332 /* linelen + null terminator */ 1305 // linelen + null terminator
1333 if ((p = vim_realloc(fields->errmsg, linelen + 1)) == NULL) 1306 if ((p = vim_realloc(fields->errmsg, linelen + 1)) == NULL)
1334 return QF_NOMEM; 1307 return QF_NOMEM;
1335 fields->errmsg = p; 1308 fields->errmsg = p;
1336 fields->errmsglen = linelen + 1; 1309 fields->errmsglen = linelen + 1;
1337 } 1310 }
1338 /* copy whole line to error message */ 1311 // copy whole line to error message
1339 vim_strncpy(fields->errmsg, linebuf, linelen); 1312 vim_strncpy(fields->errmsg, linebuf, linelen);
1340 1313
1341 return QF_OK; 1314 return QF_OK;
1342 } 1315 }
1343 1316
1374 STRCPY(++ptr, fields->errmsg); 1347 STRCPY(++ptr, fields->errmsg);
1375 } 1348 }
1376 if (qfprev->qf_nr == -1) 1349 if (qfprev->qf_nr == -1)
1377 qfprev->qf_nr = fields->enr; 1350 qfprev->qf_nr = fields->enr;
1378 if (vim_isprintc(fields->type) && !qfprev->qf_type) 1351 if (vim_isprintc(fields->type) && !qfprev->qf_type)
1379 /* only printable chars allowed */ 1352 // only printable chars allowed
1380 qfprev->qf_type = fields->type; 1353 qfprev->qf_type = fields->type;
1381 1354
1382 if (!qfprev->qf_lnum) 1355 if (!qfprev->qf_lnum)
1383 qfprev->qf_lnum = fields->lnum; 1356 qfprev->qf_lnum = fields->lnum;
1384 if (!qfprev->qf_col) 1357 if (!qfprev->qf_col)
1417 char_u *tail = NULL; 1390 char_u *tail = NULL;
1418 qf_list_T *qfl = &qi->qf_lists[qf_idx]; 1391 qf_list_T *qfl = &qi->qf_lists[qf_idx];
1419 int status; 1392 int status;
1420 1393
1421 restofline: 1394 restofline:
1422 /* If there was no %> item start at the first pattern */ 1395 // If there was no %> item start at the first pattern
1423 if (fmt_start == NULL) 1396 if (fmt_start == NULL)
1424 fmt_ptr = fmt_first; 1397 fmt_ptr = fmt_first;
1425 else 1398 else
1426 { 1399 {
1427 /* Otherwise start from the last used pattern */ 1400 // Otherwise start from the last used pattern
1428 fmt_ptr = fmt_start; 1401 fmt_ptr = fmt_start;
1429 fmt_start = NULL; 1402 fmt_start = NULL;
1430 } 1403 }
1431 1404
1432 /* 1405 // Try to match each part of 'errorformat' until we find a complete
1433 * Try to match each part of 'errorformat' until we find a complete 1406 // match or no match.
1434 * match or no match.
1435 */
1436 fields->valid = TRUE; 1407 fields->valid = TRUE;
1437 for ( ; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next) 1408 for ( ; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next)
1438 { 1409 {
1439 idx = fmt_ptr->prefix; 1410 idx = fmt_ptr->prefix;
1440 status = qf_parse_get_fields(linebuf, linelen, fmt_ptr, fields, 1411 status = qf_parse_get_fields(linebuf, linelen, fmt_ptr, fields,
1448 1419
1449 if (fmt_ptr == NULL || idx == 'D' || idx == 'X') 1420 if (fmt_ptr == NULL || idx == 'D' || idx == 'X')
1450 { 1421 {
1451 if (fmt_ptr != NULL) 1422 if (fmt_ptr != NULL)
1452 { 1423 {
1453 /* 'D' and 'X' directory specifiers */ 1424 // 'D' and 'X' directory specifiers
1454 status = qf_parse_dir_pfx(idx, fields, qfl); 1425 status = qf_parse_dir_pfx(idx, fields, qfl);
1455 if (status != QF_OK) 1426 if (status != QF_OK)
1456 return status; 1427 return status;
1457 } 1428 }
1458 1429
1463 if (fmt_ptr == NULL) 1434 if (fmt_ptr == NULL)
1464 qfl->qf_multiline = qfl->qf_multiignore = FALSE; 1435 qfl->qf_multiline = qfl->qf_multiignore = FALSE;
1465 } 1436 }
1466 else if (fmt_ptr != NULL) 1437 else if (fmt_ptr != NULL)
1467 { 1438 {
1468 /* honor %> item */ 1439 // honor %> item
1469 if (fmt_ptr->conthere) 1440 if (fmt_ptr->conthere)
1470 fmt_start = fmt_ptr; 1441 fmt_start = fmt_ptr;
1471 1442
1472 if (vim_strchr((char_u *)"AEWI", idx) != NULL) 1443 if (vim_strchr((char_u *)"AEWI", idx) != NULL)
1473 { 1444 {
1474 qfl->qf_multiline = TRUE; /* start of a multi-line message */ 1445 qfl->qf_multiline = TRUE; // start of a multi-line message
1475 qfl->qf_multiignore = FALSE;/* reset continuation */ 1446 qfl->qf_multiignore = FALSE;// reset continuation
1476 } 1447 }
1477 else if (vim_strchr((char_u *)"CZ", idx) != NULL) 1448 else if (vim_strchr((char_u *)"CZ", idx) != NULL)
1478 { /* continuation of multi-line msg */ 1449 { // continuation of multi-line msg
1479 status = qf_parse_multiline_pfx(qi, qf_idx, idx, qfl, fields); 1450 status = qf_parse_multiline_pfx(qi, qf_idx, idx, qfl, fields);
1480 if (status != QF_OK) 1451 if (status != QF_OK)
1481 return status; 1452 return status;
1482 } 1453 }
1483 else if (vim_strchr((char_u *)"OPQ", idx) != NULL) 1454 else if (vim_strchr((char_u *)"OPQ", idx) != NULL)
1484 { /* global file names */ 1455 { // global file names
1485 status = qf_parse_file_pfx(idx, fields, qfl, tail); 1456 status = qf_parse_file_pfx(idx, fields, qfl, tail);
1486 if (status == QF_MULTISCAN) 1457 if (status == QF_MULTISCAN)
1487 goto restofline; 1458 goto restofline;
1488 } 1459 }
1489 if (fmt_ptr->flags == '-') /* generally exclude this line */ 1460 if (fmt_ptr->flags == '-') // generally exclude this line
1490 { 1461 {
1491 if (qfl->qf_multiline) 1462 if (qfl->qf_multiline)
1492 /* also exclude continuation lines */ 1463 // also exclude continuation lines
1493 qfl->qf_multiignore = TRUE; 1464 qfl->qf_multiignore = TRUE;
1494 return QF_IGNORE_LINE; 1465 return QF_IGNORE_LINE;
1495 } 1466 }
1496 } 1467 }
1497 1468
1622 int qf_idx, 1593 int qf_idx,
1623 char_u *efile, 1594 char_u *efile,
1624 buf_T *buf, 1595 buf_T *buf,
1625 typval_T *tv, 1596 typval_T *tv,
1626 char_u *errorformat, 1597 char_u *errorformat,
1627 int newlist, /* TRUE: start a new error list */ 1598 int newlist, // TRUE: start a new error list
1628 linenr_T lnumfirst, /* first line number to use */ 1599 linenr_T lnumfirst, // first line number to use
1629 linenr_T lnumlast, /* last line number to use */ 1600 linenr_T lnumlast, // last line number to use
1630 char_u *qf_title, 1601 char_u *qf_title,
1631 char_u *enc) 1602 char_u *enc)
1632 { 1603 {
1633 qf_list_T *qfl; 1604 qf_list_T *qfl;
1634 qfstate_T state; 1605 qfstate_T state;
1636 qfline_T *old_last = NULL; 1607 qfline_T *old_last = NULL;
1637 int adding = FALSE; 1608 int adding = FALSE;
1638 static efm_T *fmt_first = NULL; 1609 static efm_T *fmt_first = NULL;
1639 char_u *efm; 1610 char_u *efm;
1640 static char_u *last_efm = NULL; 1611 static char_u *last_efm = NULL;
1641 int retval = -1; /* default: return error flag */ 1612 int retval = -1; // default: return error flag
1642 int status; 1613 int status;
1643 1614
1644 /* Do not used the cached buffer, it may have been wiped out. */ 1615 // Do not used the cached buffer, it may have been wiped out.
1645 VIM_CLEAR(qf_last_bufname); 1616 VIM_CLEAR(qf_last_bufname);
1646 1617
1647 vim_memset(&state, 0, sizeof(state)); 1618 vim_memset(&state, 0, sizeof(state));
1648 vim_memset(&fields, 0, sizeof(fields)); 1619 vim_memset(&fields, 0, sizeof(fields));
1649 if ((qf_alloc_fields(&fields) == FAIL) || 1620 if ((qf_alloc_fields(&fields) == FAIL) ||
1651 lnumfirst, lnumlast) == FAIL)) 1622 lnumfirst, lnumlast) == FAIL))
1652 goto qf_init_end; 1623 goto qf_init_end;
1653 1624
1654 if (newlist || qf_idx == qi->qf_listcount) 1625 if (newlist || qf_idx == qi->qf_listcount)
1655 { 1626 {
1656 /* make place for a new list */ 1627 // make place for a new list
1657 qf_new_list(qi, qf_title); 1628 qf_new_list(qi, qf_title);
1658 qf_idx = qi->qf_curlist; 1629 qf_idx = qi->qf_curlist;
1659 } 1630 }
1660 else 1631 else
1661 { 1632 {
1662 /* Adding to existing list, use last entry. */ 1633 // Adding to existing list, use last entry.
1663 adding = TRUE; 1634 adding = TRUE;
1664 if (!qf_list_empty(qi, qf_idx)) 1635 if (!qf_list_empty(qi, qf_idx))
1665 old_last = qi->qf_lists[qf_idx].qf_last; 1636 old_last = qi->qf_lists[qf_idx].qf_last;
1666 } 1637 }
1667 1638
1668 qfl = &qi->qf_lists[qf_idx]; 1639 qfl = &qi->qf_lists[qf_idx];
1669 1640
1670 /* Use the local value of 'errorformat' if it's set. */ 1641 // Use the local value of 'errorformat' if it's set.
1671 if (errorformat == p_efm && tv == NULL && *buf->b_p_efm != NUL) 1642 if (errorformat == p_efm && tv == NULL && *buf->b_p_efm != NUL)
1672 efm = buf->b_p_efm; 1643 efm = buf->b_p_efm;
1673 else 1644 else
1674 efm = errorformat; 1645 efm = errorformat;
1675 1646
1676 /* 1647 // If the errorformat didn't change between calls, then reuse the
1677 * If the errorformat didn't change between calls, then reuse the 1648 // previously parsed values.
1678 * previously parsed values.
1679 */
1680 if (last_efm == NULL || (STRCMP(last_efm, efm) != 0)) 1649 if (last_efm == NULL || (STRCMP(last_efm, efm) != 0))
1681 { 1650 {
1682 /* free the previously parsed data */ 1651 // free the previously parsed data
1683 VIM_CLEAR(last_efm); 1652 VIM_CLEAR(last_efm);
1684 free_efm_list(&fmt_first); 1653 free_efm_list(&fmt_first);
1685 1654
1686 /* parse the current 'efm' */ 1655 // parse the current 'efm'
1687 fmt_first = parse_efm_option(efm); 1656 fmt_first = parse_efm_option(efm);
1688 if (fmt_first != NULL) 1657 if (fmt_first != NULL)
1689 last_efm = vim_strsave(efm); 1658 last_efm = vim_strsave(efm);
1690 } 1659 }
1691 1660
1692 if (fmt_first == NULL) /* nothing found */ 1661 if (fmt_first == NULL) // nothing found
1693 goto error2; 1662 goto error2;
1694 1663
1695 /* 1664 // got_int is reset here, because it was probably set when killing the
1696 * got_int is reset here, because it was probably set when killing the 1665 // ":make" command, but we still want to read the errorfile then.
1697 * ":make" command, but we still want to read the errorfile then.
1698 */
1699 got_int = FALSE; 1666 got_int = FALSE;
1700 1667
1701 /* 1668 // Read the lines in the error file one by one.
1702 * Read the lines in the error file one by one. 1669 // Try to recognize one of the error formats in each line.
1703 * Try to recognize one of the error formats in each line.
1704 */
1705 while (!got_int) 1670 while (!got_int)
1706 { 1671 {
1707 /* Get the next line from a file/buffer/list/string */ 1672 // Get the next line from a file/buffer/list/string
1708 status = qf_get_nextline(&state); 1673 status = qf_get_nextline(&state);
1709 if (status == QF_NOMEM) /* memory alloc failure */ 1674 if (status == QF_NOMEM) // memory alloc failure
1710 goto qf_init_end; 1675 goto qf_init_end;
1711 if (status == QF_END_OF_INPUT) /* end of input */ 1676 if (status == QF_END_OF_INPUT) // end of input
1712 break; 1677 break;
1713 1678
1714 status = qf_parse_line(qi, qf_idx, state.linebuf, state.linelen, 1679 status = qf_parse_line(qi, qf_idx, state.linebuf, state.linelen,
1715 fmt_first, &fields); 1680 fmt_first, &fields);
1716 if (status == QF_FAIL) 1681 if (status == QF_FAIL)
1742 } 1707 }
1743 if (state.fd == NULL || !ferror(state.fd)) 1708 if (state.fd == NULL || !ferror(state.fd))
1744 { 1709 {
1745 if (qfl->qf_index == 0) 1710 if (qfl->qf_index == 0)
1746 { 1711 {
1747 /* no valid entry found */ 1712 // no valid entry found
1748 qfl->qf_ptr = qfl->qf_start; 1713 qfl->qf_ptr = qfl->qf_start;
1749 qfl->qf_index = 1; 1714 qfl->qf_index = 1;
1750 qfl->qf_nonevalid = TRUE; 1715 qfl->qf_nonevalid = TRUE;
1751 } 1716 }
1752 else 1717 else
1753 { 1718 {
1754 qfl->qf_nonevalid = FALSE; 1719 qfl->qf_nonevalid = FALSE;
1755 if (qfl->qf_ptr == NULL) 1720 if (qfl->qf_ptr == NULL)
1756 qfl->qf_ptr = qfl->qf_start; 1721 qfl->qf_ptr = qfl->qf_start;
1757 } 1722 }
1758 /* return number of matches */ 1723 // return number of matches
1759 retval = qfl->qf_count; 1724 retval = qfl->qf_count;
1760 goto qf_init_end; 1725 goto qf_init_end;
1761 } 1726 }
1762 EMSG(_(e_readerrf)); 1727 EMSG(_(e_readerrf));
1763 error2: 1728 error2:
1764 if (!adding) 1729 if (!adding)
1765 { 1730 {
1766 /* Error when creating a new list. Free the new list */ 1731 // Error when creating a new list. Free the new list
1767 qf_free(&qi->qf_lists[qi->qf_curlist]); 1732 qf_free(&qi->qf_lists[qi->qf_curlist]);
1768 qi->qf_listcount--; 1733 qi->qf_listcount--;
1769 if (qi->qf_curlist > 0) 1734 if (qi->qf_curlist > 0)
1770 --qi->qf_curlist; 1735 --qi->qf_curlist;
1771 } 1736 }
1785 */ 1750 */
1786 int 1751 int
1787 qf_init(win_T *wp, 1752 qf_init(win_T *wp,
1788 char_u *efile, 1753 char_u *efile,
1789 char_u *errorformat, 1754 char_u *errorformat,
1790 int newlist, /* TRUE: start a new error list */ 1755 int newlist, // TRUE: start a new error list
1791 char_u *qf_title, 1756 char_u *qf_title,
1792 char_u *enc) 1757 char_u *enc)
1793 { 1758 {
1794 qf_info_T *qi = &ql_info; 1759 qf_info_T *qi = &ql_info;
1795 1760
1846 static void 1811 static void
1847 qf_new_list(qf_info_T *qi, char_u *qf_title) 1812 qf_new_list(qf_info_T *qi, char_u *qf_title)
1848 { 1813 {
1849 int i; 1814 int i;
1850 1815
1851 /* 1816 // If the current entry is not the last entry, delete entries beyond
1852 * If the current entry is not the last entry, delete entries beyond 1817 // the current entry. This makes it possible to browse in a tree-like
1853 * the current entry. This makes it possible to browse in a tree-like 1818 // way with ":grep'.
1854 * way with ":grep'.
1855 */
1856 while (qi->qf_listcount > qi->qf_curlist + 1) 1819 while (qi->qf_listcount > qi->qf_curlist + 1)
1857 qf_free(&qi->qf_lists[--qi->qf_listcount]); 1820 qf_free(&qi->qf_lists[--qi->qf_listcount]);
1858 1821
1859 /* 1822 // When the stack is full, remove to oldest entry
1860 * When the stack is full, remove to oldest entry 1823 // Otherwise, add a new entry.
1861 * Otherwise, add a new entry.
1862 */
1863 if (qi->qf_listcount == LISTCOUNT) 1824 if (qi->qf_listcount == LISTCOUNT)
1864 { 1825 {
1865 qf_free(&qi->qf_lists[0]); 1826 qf_free(&qi->qf_lists[0]);
1866 for (i = 1; i < LISTCOUNT; ++i) 1827 for (i = 1; i < LISTCOUNT; ++i)
1867 qi->qf_lists[i - 1] = qi->qf_lists[i]; 1828 qi->qf_lists[i - 1] = qi->qf_lists[i];
1884 qf_info_T *qi; 1845 qf_info_T *qi;
1885 1846
1886 qi = *pqi; 1847 qi = *pqi;
1887 if (qi == NULL) 1848 if (qi == NULL)
1888 return; 1849 return;
1889 *pqi = NULL; /* Remove reference to this list */ 1850 *pqi = NULL; // Remove reference to this list
1890 1851
1891 qi->qf_refcount--; 1852 qi->qf_refcount--;
1892 if (qi->qf_refcount < 1) 1853 if (qi->qf_refcount < 1)
1893 { 1854 {
1894 /* No references to this location list */ 1855 // No references to this location list
1895 for (i = 0; i < qi->qf_listcount; ++i) 1856 for (i = 0; i < qi->qf_listcount; ++i)
1896 qf_free(&qi->qf_lists[i]); 1857 qf_free(&qi->qf_lists[i]);
1897 vim_free(qi); 1858 vim_free(qi);
1898 } 1859 }
1899 } 1860 }
1907 int i; 1868 int i;
1908 qf_info_T *qi = &ql_info; 1869 qf_info_T *qi = &ql_info;
1909 1870
1910 if (wp != NULL) 1871 if (wp != NULL)
1911 { 1872 {
1912 /* location list */ 1873 // location list
1913 ll_free_all(&wp->w_llist); 1874 ll_free_all(&wp->w_llist);
1914 ll_free_all(&wp->w_llist_ref); 1875 ll_free_all(&wp->w_llist_ref);
1915 } 1876 }
1916 else 1877 else
1917 /* quickfix list */ 1878 // quickfix list
1918 for (i = 0; i < qi->qf_listcount; ++i) 1879 for (i = 0; i < qi->qf_listcount; ++i)
1919 qf_free(&qi->qf_lists[i]); 1880 qf_free(&qi->qf_lists[i]);
1920 } 1881 }
1921 1882
1922 /* 1883 /*
1923 * Add an entry to the end of the list of errors. 1884 * Add an entry to the end of the list of errors.
1924 * Returns OK or FAIL. 1885 * Returns OK or FAIL.
1925 */ 1886 */
1926 static int 1887 static int
1927 qf_add_entry( 1888 qf_add_entry(
1928 qf_info_T *qi, /* quickfix list */ 1889 qf_info_T *qi, // quickfix list
1929 int qf_idx, /* list index */ 1890 int qf_idx, // list index
1930 char_u *dir, /* optional directory name */ 1891 char_u *dir, // optional directory name
1931 char_u *fname, /* file name or NULL */ 1892 char_u *fname, // file name or NULL
1932 char_u *module, /* module name or NULL */ 1893 char_u *module, // module name or NULL
1933 int bufnum, /* buffer number or zero */ 1894 int bufnum, // buffer number or zero
1934 char_u *mesg, /* message */ 1895 char_u *mesg, // message
1935 long lnum, /* line number */ 1896 long lnum, // line number
1936 int col, /* column */ 1897 int col, // column
1937 int vis_col, /* using visual column */ 1898 int vis_col, // using visual column
1938 char_u *pattern, /* search pattern */ 1899 char_u *pattern, // search pattern
1939 int nr, /* error number */ 1900 int nr, // error number
1940 int type, /* type character */ 1901 int type, // type character
1941 int valid) /* valid entry */ 1902 int valid) // valid entry
1942 { 1903 {
1943 qf_list_T *qfl = &qi->qf_lists[qf_idx]; 1904 qf_list_T *qfl = &qi->qf_lists[qf_idx];
1944 qfline_T *qfp; 1905 qfline_T *qfp;
1945 qfline_T **lastp; /* pointer to qf_last or NULL */ 1906 qfline_T **lastp; // pointer to qf_last or NULL
1946 1907
1947 if ((qfp = (qfline_T *)alloc((unsigned)sizeof(qfline_T))) == NULL) 1908 if ((qfp = (qfline_T *)alloc((unsigned)sizeof(qfline_T))) == NULL)
1948 return FAIL; 1909 return FAIL;
1949 if (bufnum != 0) 1910 if (bufnum != 0)
1950 { 1911 {
1981 vim_free(qfp->qf_pattern); 1942 vim_free(qfp->qf_pattern);
1982 vim_free(qfp); 1943 vim_free(qfp);
1983 return FAIL; 1944 return FAIL;
1984 } 1945 }
1985 qfp->qf_nr = nr; 1946 qfp->qf_nr = nr;
1986 if (type != 1 && !vim_isprintc(type)) /* only printable chars allowed */ 1947 if (type != 1 && !vim_isprintc(type)) // only printable chars allowed
1987 type = 0; 1948 type = 0;
1988 qfp->qf_type = type; 1949 qfp->qf_type = type;
1989 qfp->qf_valid = valid; 1950 qfp->qf_valid = valid;
1990 1951
1991 lastp = &qfl->qf_last; 1952 lastp = &qfl->qf_last;
1992 if (qf_list_empty(qi, qf_idx)) /* first element in the list */ 1953 if (qf_list_empty(qi, qf_idx)) // first element in the list
1993 { 1954 {
1994 qfl->qf_start = qfp; 1955 qfl->qf_start = qfp;
1995 qfl->qf_ptr = qfp; 1956 qfl->qf_ptr = qfp;
1996 qfl->qf_index = 0; 1957 qfl->qf_index = 0;
1997 qfp->qf_prev = NULL; 1958 qfp->qf_prev = NULL;
2003 } 1964 }
2004 qfp->qf_next = NULL; 1965 qfp->qf_next = NULL;
2005 qfp->qf_cleared = FALSE; 1966 qfp->qf_cleared = FALSE;
2006 *lastp = qfp; 1967 *lastp = qfp;
2007 ++qfl->qf_count; 1968 ++qfl->qf_count;
2008 if (qfl->qf_index == 0 && qfp->qf_valid) 1969 if (qfl->qf_index == 0 && qfp->qf_valid) // first valid entry
2009 /* first valid entry */
2010 { 1970 {
2011 qfl->qf_index = qfl->qf_count; 1971 qfl->qf_index = qfl->qf_count;
2012 qfl->qf_ptr = qfp; 1972 qfl->qf_ptr = qfp;
2013 } 1973 }
2014 1974
2035 */ 1995 */
2036 static qf_info_T * 1996 static qf_info_T *
2037 ll_get_or_alloc_list(win_T *wp) 1997 ll_get_or_alloc_list(win_T *wp)
2038 { 1998 {
2039 if (IS_LL_WINDOW(wp)) 1999 if (IS_LL_WINDOW(wp))
2040 /* For a location list window, use the referenced location list */ 2000 // For a location list window, use the referenced location list
2041 return wp->w_llist_ref; 2001 return wp->w_llist_ref;
2042 2002
2043 /* 2003 // For a non-location list window, w_llist_ref should not point to a
2044 * For a non-location list window, w_llist_ref should not point to a 2004 // location list.
2045 * location list.
2046 */
2047 ll_free_all(&wp->w_llist_ref); 2005 ll_free_all(&wp->w_llist_ref);
2048 2006
2049 if (wp->w_llist == NULL) 2007 if (wp->w_llist == NULL)
2050 wp->w_llist = ll_new_list(); /* new location list */ 2008 wp->w_llist = ll_new_list(); // new location list
2051 return wp->w_llist; 2009 return wp->w_llist;
2052 } 2010 }
2053 2011
2054 /* 2012 /*
2055 * Copy location list entries from 'from_qfl' to 'to_qfl'. 2013 * Copy location list entries from 'from_qfl' to 'to_qfl'.
2193 { 2151 {
2194 char_u *ptr = NULL; 2152 char_u *ptr = NULL;
2195 buf_T *buf; 2153 buf_T *buf;
2196 char_u *bufname; 2154 char_u *bufname;
2197 2155
2198 if (fname == NULL || *fname == NUL) /* no file name */ 2156 if (fname == NULL || *fname == NUL) // no file name
2199 return 0; 2157 return 0;
2200 2158
2201 #ifdef VMS 2159 #ifdef VMS
2202 vms_remove_version(fname); 2160 vms_remove_version(fname);
2203 #endif 2161 #endif
2207 slash_adjust(fname); 2165 slash_adjust(fname);
2208 #endif 2166 #endif
2209 if (directory != NULL && !vim_isAbsName(fname) 2167 if (directory != NULL && !vim_isAbsName(fname)
2210 && (ptr = concat_fnames(directory, fname, TRUE)) != NULL) 2168 && (ptr = concat_fnames(directory, fname, TRUE)) != NULL)
2211 { 2169 {
2212 /* 2170 // Here we check if the file really exists.
2213 * Here we check if the file really exists. 2171 // This should normally be true, but if make works without
2214 * This should normally be true, but if make works without 2172 // "leaving directory"-messages we might have missed a
2215 * "leaving directory"-messages we might have missed a 2173 // directory change.
2216 * directory change.
2217 */
2218 if (mch_getperm(ptr) < 0) 2174 if (mch_getperm(ptr) < 0)
2219 { 2175 {
2220 vim_free(ptr); 2176 vim_free(ptr);
2221 directory = qf_guess_filepath(&qi->qf_lists[qf_idx], fname); 2177 directory = qf_guess_filepath(&qi->qf_lists[qf_idx], fname);
2222 if (directory) 2178 if (directory)
2223 ptr = concat_fnames(directory, fname, TRUE); 2179 ptr = concat_fnames(directory, fname, TRUE);
2224 else 2180 else
2225 ptr = vim_strsave(fname); 2181 ptr = vim_strsave(fname);
2226 } 2182 }
2227 /* Use concatenated directory name and file name */ 2183 // Use concatenated directory name and file name
2228 bufname = ptr; 2184 bufname = ptr;
2229 } 2185 }
2230 else 2186 else
2231 bufname = fname; 2187 bufname = fname;
2232 2188
2262 qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr, int is_file_stack) 2218 qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr, int is_file_stack)
2263 { 2219 {
2264 struct dir_stack_T *ds_new; 2220 struct dir_stack_T *ds_new;
2265 struct dir_stack_T *ds_ptr; 2221 struct dir_stack_T *ds_ptr;
2266 2222
2267 /* allocate new stack element and hook it in */ 2223 // allocate new stack element and hook it in
2268 ds_new = (struct dir_stack_T *)alloc((unsigned)sizeof(struct dir_stack_T)); 2224 ds_new = (struct dir_stack_T *)alloc((unsigned)sizeof(struct dir_stack_T));
2269 if (ds_new == NULL) 2225 if (ds_new == NULL)
2270 return NULL; 2226 return NULL;
2271 2227
2272 ds_new->next = *stackptr; 2228 ds_new->next = *stackptr;
2273 *stackptr = ds_new; 2229 *stackptr = ds_new;
2274 2230
2275 /* store directory on the stack */ 2231 // store directory on the stack
2276 if (vim_isAbsName(dirbuf) 2232 if (vim_isAbsName(dirbuf)
2277 || (*stackptr)->next == NULL 2233 || (*stackptr)->next == NULL
2278 || (*stackptr && is_file_stack)) 2234 || (*stackptr && is_file_stack))
2279 (*stackptr)->dirname = vim_strsave(dirbuf); 2235 (*stackptr)->dirname = vim_strsave(dirbuf);
2280 else 2236 else
2281 { 2237 {
2282 /* Okay we don't have an absolute path. 2238 // Okay we don't have an absolute path.
2283 * dirbuf must be a subdir of one of the directories on the stack. 2239 // dirbuf must be a subdir of one of the directories on the stack.
2284 * Let's search... 2240 // Let's search...
2285 */
2286 ds_new = (*stackptr)->next; 2241 ds_new = (*stackptr)->next;
2287 (*stackptr)->dirname = NULL; 2242 (*stackptr)->dirname = NULL;
2288 while (ds_new) 2243 while (ds_new)
2289 { 2244 {
2290 vim_free((*stackptr)->dirname); 2245 vim_free((*stackptr)->dirname);
2294 break; 2249 break;
2295 2250
2296 ds_new = ds_new->next; 2251 ds_new = ds_new->next;
2297 } 2252 }
2298 2253
2299 /* clean up all dirs we already left */ 2254 // clean up all dirs we already left
2300 while ((*stackptr)->next != ds_new) 2255 while ((*stackptr)->next != ds_new)
2301 { 2256 {
2302 ds_ptr = (*stackptr)->next; 2257 ds_ptr = (*stackptr)->next;
2303 (*stackptr)->next = (*stackptr)->next->next; 2258 (*stackptr)->next = (*stackptr)->next->next;
2304 vim_free(ds_ptr->dirname); 2259 vim_free(ds_ptr->dirname);
2305 vim_free(ds_ptr); 2260 vim_free(ds_ptr);
2306 } 2261 }
2307 2262
2308 /* Nothing found -> it must be on top level */ 2263 // Nothing found -> it must be on top level
2309 if (ds_new == NULL) 2264 if (ds_new == NULL)
2310 { 2265 {
2311 vim_free((*stackptr)->dirname); 2266 vim_free((*stackptr)->dirname);
2312 (*stackptr)->dirname = vim_strsave(dirbuf); 2267 (*stackptr)->dirname = vim_strsave(dirbuf);
2313 } 2268 }
2331 static char_u * 2286 static char_u *
2332 qf_pop_dir(struct dir_stack_T **stackptr) 2287 qf_pop_dir(struct dir_stack_T **stackptr)
2333 { 2288 {
2334 struct dir_stack_T *ds_ptr; 2289 struct dir_stack_T *ds_ptr;
2335 2290
2336 /* TODO: Should we check if dirbuf is the directory on top of the stack? 2291 // TODO: Should we check if dirbuf is the directory on top of the stack?
2337 * What to do if it isn't? */ 2292 // What to do if it isn't?
2338 2293
2339 /* pop top element and free it */ 2294 // pop top element and free it
2340 if (*stackptr != NULL) 2295 if (*stackptr != NULL)
2341 { 2296 {
2342 ds_ptr = *stackptr; 2297 ds_ptr = *stackptr;
2343 *stackptr = (*stackptr)->next; 2298 *stackptr = (*stackptr)->next;
2344 vim_free(ds_ptr->dirname); 2299 vim_free(ds_ptr->dirname);
2345 vim_free(ds_ptr); 2300 vim_free(ds_ptr);
2346 } 2301 }
2347 2302
2348 /* return NEW top element as current dir or NULL if stack is empty*/ 2303 // return NEW top element as current dir or NULL if stack is empty
2349 return *stackptr ? (*stackptr)->dirname : NULL; 2304 return *stackptr ? (*stackptr)->dirname : NULL;
2350 } 2305 }
2351 2306
2352 /* 2307 /*
2353 * clean up directory stack 2308 * clean up directory stack
2390 { 2345 {
2391 struct dir_stack_T *ds_ptr; 2346 struct dir_stack_T *ds_ptr;
2392 struct dir_stack_T *ds_tmp; 2347 struct dir_stack_T *ds_tmp;
2393 char_u *fullname; 2348 char_u *fullname;
2394 2349
2395 /* no dirs on the stack - there's nothing we can do */ 2350 // no dirs on the stack - there's nothing we can do
2396 if (qfl->qf_dir_stack == NULL) 2351 if (qfl->qf_dir_stack == NULL)
2397 return NULL; 2352 return NULL;
2398 2353
2399 ds_ptr = qfl->qf_dir_stack->next; 2354 ds_ptr = qfl->qf_dir_stack->next;
2400 fullname = NULL; 2355 fullname = NULL;
2401 while (ds_ptr) 2356 while (ds_ptr)
2402 { 2357 {
2403 vim_free(fullname); 2358 vim_free(fullname);
2404 fullname = concat_fnames(ds_ptr->dirname, filename, TRUE); 2359 fullname = concat_fnames(ds_ptr->dirname, filename, TRUE);
2405 2360
2406 /* If concat_fnames failed, just go on. The worst thing that can happen 2361 // If concat_fnames failed, just go on. The worst thing that can happen
2407 * is that we delete the entire stack. 2362 // is that we delete the entire stack.
2408 */
2409 if ((fullname != NULL) && (mch_getperm(fullname) >= 0)) 2363 if ((fullname != NULL) && (mch_getperm(fullname) >= 0))
2410 break; 2364 break;
2411 2365
2412 ds_ptr = ds_ptr->next; 2366 ds_ptr = ds_ptr->next;
2413 } 2367 }
2414 2368
2415 vim_free(fullname); 2369 vim_free(fullname);
2416 2370
2417 /* clean up all dirs we already left */ 2371 // clean up all dirs we already left
2418 while (qfl->qf_dir_stack->next != ds_ptr) 2372 while (qfl->qf_dir_stack->next != ds_ptr)
2419 { 2373 {
2420 ds_tmp = qfl->qf_dir_stack->next; 2374 ds_tmp = qfl->qf_dir_stack->next;
2421 qfl->qf_dir_stack->next = qfl->qf_dir_stack->next->next; 2375 qfl->qf_dir_stack->next = qfl->qf_dir_stack->next->next;
2422 vim_free(ds_tmp->dirname); 2376 vim_free(ds_tmp->dirname);
2435 qf_info_T *qi = &ql_info; 2389 qf_info_T *qi = &ql_info;
2436 int i; 2390 int i;
2437 2391
2438 if (wp != NULL) 2392 if (wp != NULL)
2439 { 2393 {
2440 qi = GET_LOC_LIST(wp); /* Location list */ 2394 qi = GET_LOC_LIST(wp); // Location list
2441 if (qi == NULL) 2395 if (qi == NULL)
2442 return FALSE; 2396 return FALSE;
2443 } 2397 }
2444 2398
2445 for (i = 0; i < qi->qf_listcount; ++i) 2399 for (i = 0; i < qi->qf_listcount; ++i)
2459 is_qf_entry_present(qf_list_T *qfl, qfline_T *qf_ptr) 2413 is_qf_entry_present(qf_list_T *qfl, qfline_T *qf_ptr)
2460 { 2414 {
2461 qfline_T *qfp; 2415 qfline_T *qfp;
2462 int i; 2416 int i;
2463 2417
2464 /* Search for the entry in the current list */ 2418 // Search for the entry in the current list
2465 for (i = 0, qfp = qfl->qf_start; i < qfl->qf_count; 2419 for (i = 0, qfp = qfl->qf_start; i < qfl->qf_count;
2466 ++i, qfp = qfp->qf_next) 2420 ++i, qfp = qfp->qf_next)
2467 if (qfp == NULL || qfp == qf_ptr) 2421 if (qfp == NULL || qfp == qf_ptr)
2468 break; 2422 break;
2469 2423
2470 if (i == qfl->qf_count) /* Entry is not found */ 2424 if (i == qfl->qf_count) // Entry is not found
2471 return FALSE; 2425 return FALSE;
2472 2426
2473 return TRUE; 2427 return TRUE;
2474 } 2428 }
2475 2429
2665 wp = qf_find_help_win(); 2619 wp = qf_find_help_win();
2666 if (wp != NULL && wp->w_buffer->b_nwindows > 0) 2620 if (wp != NULL && wp->w_buffer->b_nwindows > 0)
2667 win_enter(wp, TRUE); 2621 win_enter(wp, TRUE);
2668 else 2622 else
2669 { 2623 {
2670 /* 2624 // Split off help window; put it at far top if no position
2671 * Split off help window; put it at far top if no position 2625 // specified, the current window is vertically split and narrow.
2672 * specified, the current window is vertically split and narrow.
2673 */
2674 flags = WSP_HELP; 2626 flags = WSP_HELP;
2675 if (cmdmod.split == 0 && curwin->w_width != Columns 2627 if (cmdmod.split == 0 && curwin->w_width != Columns
2676 && curwin->w_width < 80) 2628 && curwin->w_width < 80)
2677 flags |= WSP_TOP; 2629 flags |= WSP_TOP;
2678 if (IS_LL_STACK(qi)) 2630 if (IS_LL_STACK(qi))
2679 flags |= WSP_NEWLOC; /* don't copy the location list */ 2631 flags |= WSP_NEWLOC; // don't copy the location list
2680 2632
2681 if (win_split(0, flags) == FAIL) 2633 if (win_split(0, flags) == FAIL)
2682 return FAIL; 2634 return FAIL;
2683 2635
2684 *opened_window = TRUE; 2636 *opened_window = TRUE;
2686 if (curwin->w_height < p_hh) 2638 if (curwin->w_height < p_hh)
2687 win_setheight((int)p_hh); 2639 win_setheight((int)p_hh);
2688 2640
2689 if (IS_LL_STACK(qi)) // not a quickfix list 2641 if (IS_LL_STACK(qi)) // not a quickfix list
2690 { 2642 {
2691 /* The new window should use the supplied location list */ 2643 // The new window should use the supplied location list
2692 curwin->w_llist = qi; 2644 curwin->w_llist = qi;
2693 qi->qf_refcount++; 2645 qi->qf_refcount++;
2694 } 2646 }
2695 } 2647 }
2696 2648
2697 if (!p_im) 2649 if (!p_im)
2698 restart_edit = 0; /* don't want insert mode in help file */ 2650 restart_edit = 0; // don't want insert mode in help file
2699 2651
2700 return OK; 2652 return OK;
2701 } 2653 }
2702 2654
2703 /* 2655 /*
2762 2714
2763 flags = WSP_ABOVE; 2715 flags = WSP_ABOVE;
2764 if (ll_ref != NULL) 2716 if (ll_ref != NULL)
2765 flags |= WSP_NEWLOC; 2717 flags |= WSP_NEWLOC;
2766 if (win_split(0, flags) == FAIL) 2718 if (win_split(0, flags) == FAIL)
2767 return FAIL; /* not enough room for window */ 2719 return FAIL; // not enough room for window
2768 p_swb = empty_option; /* don't split again */ 2720 p_swb = empty_option; // don't split again
2769 swb_flags = 0; 2721 swb_flags = 0;
2770 RESET_BINDING(curwin); 2722 RESET_BINDING(curwin);
2771 if (ll_ref != NULL) 2723 if (ll_ref != NULL)
2772 { 2724 {
2773 /* The new window should use the location list from the 2725 // The new window should use the location list from the
2774 * location list window */ 2726 // location list window
2775 curwin->w_llist = ll_ref; 2727 curwin->w_llist = ll_ref;
2776 ll_ref->qf_refcount++; 2728 ll_ref->qf_refcount++;
2777 } 2729 }
2778 return OK; 2730 return OK;
2779 } 2731 }
2789 { 2741 {
2790 win_T *win = use_win; 2742 win_T *win = use_win;
2791 2743
2792 if (win == NULL) 2744 if (win == NULL)
2793 { 2745 {
2794 /* Find the window showing the selected file */ 2746 // Find the window showing the selected file
2795 FOR_ALL_WINDOWS(win) 2747 FOR_ALL_WINDOWS(win)
2796 if (win->w_buffer->b_fnum == qf_fnum) 2748 if (win->w_buffer->b_fnum == qf_fnum)
2797 break; 2749 break;
2798 if (win == NULL) 2750 if (win == NULL)
2799 { 2751 {
2800 /* Find a previous usable window */ 2752 // Find a previous usable window
2801 win = curwin; 2753 win = curwin;
2802 do 2754 do
2803 { 2755 {
2804 if (bt_normal(win->w_buffer)) 2756 if (bt_normal(win->w_buffer))
2805 break; 2757 break;
2806 if (win->w_prev == NULL) 2758 if (win->w_prev == NULL)
2807 win = lastwin; /* wrap around the top */ 2759 win = lastwin; // wrap around the top
2808 else 2760 else
2809 win = win->w_prev; /* go to previous window */ 2761 win = win->w_prev; // go to previous window
2810 } while (win != curwin); 2762 } while (win != curwin);
2811 } 2763 }
2812 } 2764 }
2813 win_goto(win); 2765 win_goto(win);
2814 2766
2815 /* If the location list for the window is not set, then set it 2767 // If the location list for the window is not set, then set it
2816 * to the location list from the location window */ 2768 // to the location list from the location window
2817 if (win->w_llist == NULL) 2769 if (win->w_llist == NULL)
2818 { 2770 {
2819 win->w_llist = ll_ref; 2771 win->w_llist = ll_ref;
2820 if (ll_ref != NULL) 2772 if (ll_ref != NULL)
2821 ll_ref->qf_refcount++; 2773 ll_ref->qf_refcount++;
2839 for (;;) 2791 for (;;)
2840 { 2792 {
2841 if (win->w_buffer->b_fnum == qf_fnum) 2793 if (win->w_buffer->b_fnum == qf_fnum)
2842 break; 2794 break;
2843 if (win->w_prev == NULL) 2795 if (win->w_prev == NULL)
2844 win = lastwin; /* wrap around the top */ 2796 win = lastwin; // wrap around the top
2845 else 2797 else
2846 win = win->w_prev; /* go to previous window */ 2798 win = win->w_prev; // go to previous window
2847 2799
2848 if (IS_QF_WINDOW(win)) 2800 if (IS_QF_WINDOW(win))
2849 { 2801 {
2850 /* Didn't find it, go to the window before the quickfix 2802 // Didn't find it, go to the window before the quickfix
2851 * window. */ 2803 // window.
2852 if (altwin != NULL) 2804 if (altwin != NULL)
2853 win = altwin; 2805 win = altwin;
2854 else if (curwin->w_prev != NULL) 2806 else if (curwin->w_prev != NULL)
2855 win = curwin->w_prev; 2807 win = curwin->w_prev;
2856 else 2808 else
2857 win = curwin->w_next; 2809 win = curwin->w_next;
2858 break; 2810 break;
2859 } 2811 }
2860 2812
2861 /* Remember a usable window. */ 2813 // Remember a usable window.
2862 if (altwin == NULL && !win->w_p_pvw && bt_normal(win->w_buffer)) 2814 if (altwin == NULL && !win->w_p_pvw && bt_normal(win->w_buffer))
2863 altwin = win; 2815 altwin = win;
2864 } 2816 }
2865 2817
2866 win_goto(win); 2818 win_goto(win);
2883 usable_win = 0; 2835 usable_win = 0;
2884 2836
2885 ll_ref = curwin->w_llist_ref; 2837 ll_ref = curwin->w_llist_ref;
2886 if (ll_ref != NULL) 2838 if (ll_ref != NULL)
2887 { 2839 {
2888 /* Find a non-quickfix window with this location list */ 2840 // Find a non-quickfix window with this location list
2889 usable_win_ptr = qf_find_win_with_loclist(ll_ref); 2841 usable_win_ptr = qf_find_win_with_loclist(ll_ref);
2890 if (usable_win_ptr != NULL) 2842 if (usable_win_ptr != NULL)
2891 usable_win = 1; 2843 usable_win = 1;
2892 } 2844 }
2893 2845
2894 if (!usable_win) 2846 if (!usable_win)
2895 { 2847 {
2896 /* Locate a window showing a normal buffer */ 2848 // Locate a window showing a normal buffer
2897 win = qf_find_win_with_normal_buf(); 2849 win = qf_find_win_with_normal_buf();
2898 if (win != NULL) 2850 if (win != NULL)
2899 usable_win = 1; 2851 usable_win = 1;
2900 } 2852 }
2901 2853
2902 /* 2854 // If no usable window is found and 'switchbuf' contains "usetab"
2903 * If no usable window is found and 'switchbuf' contains "usetab" 2855 // then search in other tabs.
2904 * then search in other tabs.
2905 */
2906 if (!usable_win && (swb_flags & SWB_USETAB)) 2856 if (!usable_win && (swb_flags & SWB_USETAB))
2907 usable_win = qf_goto_tabwin_with_file(qf_fnum); 2857 usable_win = qf_goto_tabwin_with_file(qf_fnum);
2908 2858
2909 /* 2859 // If there is only one window and it is the quickfix window, create a
2910 * If there is only one window and it is the quickfix window, create a 2860 // new one above the quickfix window.
2911 * new one above the quickfix window.
2912 */
2913 if ((ONE_WINDOW && bt_quickfix(curbuf)) || !usable_win) 2861 if ((ONE_WINDOW && bt_quickfix(curbuf)) || !usable_win)
2914 { 2862 {
2915 if (qf_open_new_file_win(ll_ref) != OK) 2863 if (qf_open_new_file_win(ll_ref) != OK)
2916 return FAIL; 2864 return FAIL;
2917 *opened_window = TRUE; /* close it when fail */ 2865 *opened_window = TRUE; // close it when fail
2918 } 2866 }
2919 else 2867 else
2920 { 2868 {
2921 if (curwin->w_llist_ref != NULL) /* In a location window */ 2869 if (curwin->w_llist_ref != NULL) // In a location window
2922 qf_goto_win_with_ll_file(usable_win_ptr, qf_fnum, ll_ref); 2870 qf_goto_win_with_ll_file(usable_win_ptr, qf_fnum, ll_ref);
2923 else /* In a quickfix window */ 2871 else // In a quickfix window
2924 qf_goto_win_with_qfl_file(qf_fnum); 2872 qf_goto_win_with_qfl_file(qf_fnum);
2925 } 2873 }
2926 2874
2927 return OK; 2875 return OK;
2928 } 2876 }
2944 qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist]; 2892 qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist];
2945 int retval = OK; 2893 int retval = OK;
2946 2894
2947 if (qf_ptr->qf_type == 1) 2895 if (qf_ptr->qf_type == 1)
2948 { 2896 {
2949 /* Open help file (do_ecmd() will set b_help flag, readfile() will 2897 // Open help file (do_ecmd() will set b_help flag, readfile() will
2950 * set b_p_ro flag). */ 2898 // set b_p_ro flag).
2951 if (!can_abandon(curbuf, forceit)) 2899 if (!can_abandon(curbuf, forceit))
2952 { 2900 {
2953 no_write_message(); 2901 no_write_message();
2954 retval = FAIL; 2902 retval = FAIL;
2955 } 2903 }
2966 retval = buflist_getfile(qf_ptr->qf_fnum, 2914 retval = buflist_getfile(qf_ptr->qf_fnum,
2967 (linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit); 2915 (linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit);
2968 2916
2969 if (IS_LL_STACK(qi)) 2917 if (IS_LL_STACK(qi))
2970 { 2918 {
2971 /* 2919 // Location list. Check whether the associated window is still
2972 * Location list. Check whether the associated window is still 2920 // present and the list is still valid.
2973 * present and the list is still valid.
2974 */
2975 if (!win_valid_any_tab(oldwin)) 2921 if (!win_valid_any_tab(oldwin))
2976 { 2922 {
2977 EMSG(_("E924: Current window was closed")); 2923 EMSG(_("E924: Current window was closed"));
2978 *opened_window = FALSE; 2924 *opened_window = FALSE;
2979 return NOTDONE; 2925 return NOTDONE;
3014 colnr_T screen_col; 2960 colnr_T screen_col;
3015 colnr_T char_col; 2961 colnr_T char_col;
3016 2962
3017 if (qf_pattern == NULL) 2963 if (qf_pattern == NULL)
3018 { 2964 {
3019 /* 2965 // Go to line with error, unless qf_lnum is 0.
3020 * Go to line with error, unless qf_lnum is 0.
3021 */
3022 i = qf_lnum; 2966 i = qf_lnum;
3023 if (i > 0) 2967 if (i > 0)
3024 { 2968 {
3025 if (i > curbuf->b_ml.ml_line_count) 2969 if (i > curbuf->b_ml.ml_line_count)
3026 i = curbuf->b_ml.ml_line_count; 2970 i = curbuf->b_ml.ml_line_count;
3032 #ifdef FEAT_VIRTUALEDIT 2976 #ifdef FEAT_VIRTUALEDIT
3033 curwin->w_cursor.coladd = 0; 2977 curwin->w_cursor.coladd = 0;
3034 #endif 2978 #endif
3035 if (qf_viscol == TRUE) 2979 if (qf_viscol == TRUE)
3036 { 2980 {
3037 /* 2981 // Check each character from the beginning of the error
3038 * Check each character from the beginning of the error 2982 // line up to the error column. For each tab character
3039 * line up to the error column. For each tab character 2983 // found, reduce the error column value by the length of
3040 * found, reduce the error column value by the length of 2984 // a tab character.
3041 * a tab character.
3042 */
3043 line = ml_get_curline(); 2985 line = ml_get_curline();
3044 screen_col = 0; 2986 screen_col = 0;
3045 for (char_col = 0; char_col < curwin->w_cursor.col; ++char_col) 2987 for (char_col = 0; char_col < curwin->w_cursor.col; ++char_col)
3046 { 2988 {
3047 if (*line == NUL) 2989 if (*line == NUL)
3063 } 3005 }
3064 else 3006 else
3065 { 3007 {
3066 pos_T save_cursor; 3008 pos_T save_cursor;
3067 3009
3068 /* Move the cursor to the first line in the buffer */ 3010 // Move the cursor to the first line in the buffer
3069 save_cursor = curwin->w_cursor; 3011 save_cursor = curwin->w_cursor;
3070 curwin->w_cursor.lnum = 0; 3012 curwin->w_cursor.lnum = 0;
3071 if (!do_search(NULL, '/', qf_pattern, (long)1, 3013 if (!do_search(NULL, '/', qf_pattern, (long)1,
3072 SEARCH_KEEP, NULL, NULL)) 3014 SEARCH_KEEP, NULL, NULL))
3073 curwin->w_cursor = save_cursor; 3015 curwin->w_cursor = save_cursor;
3086 linenr_T old_lnum) 3028 linenr_T old_lnum)
3087 { 3029 {
3088 linenr_T i; 3030 linenr_T i;
3089 int len; 3031 int len;
3090 3032
3091 /* Update the screen before showing the message, unless the screen 3033 // Update the screen before showing the message, unless the screen
3092 * scrolled up. */ 3034 // scrolled up.
3093 if (!msg_scrolled) 3035 if (!msg_scrolled)
3094 update_topline_redraw(); 3036 update_topline_redraw();
3095 sprintf((char *)IObuff, _("(%d of %d)%s%s: "), qf_index, 3037 sprintf((char *)IObuff, _("(%d of %d)%s%s: "), qf_index,
3096 qi->qf_lists[qi->qf_curlist].qf_count, 3038 qi->qf_lists[qi->qf_curlist].qf_count,
3097 qf_ptr->qf_cleared ? _(" (line deleted)") : "", 3039 qf_ptr->qf_cleared ? _(" (line deleted)") : "",
3098 (char *)qf_types(qf_ptr->qf_type, qf_ptr->qf_nr)); 3040 (char *)qf_types(qf_ptr->qf_type, qf_ptr->qf_nr));
3099 /* Add the message, skipping leading whitespace and newlines. */ 3041 // Add the message, skipping leading whitespace and newlines.
3100 len = (int)STRLEN(IObuff); 3042 len = (int)STRLEN(IObuff);
3101 qf_fmt_text(skipwhite(qf_ptr->qf_text), IObuff + len, IOSIZE - len); 3043 qf_fmt_text(skipwhite(qf_ptr->qf_text), IObuff + len, IOSIZE - len);
3102 3044
3103 /* Output the message. Overwrite to avoid scrolling when the 'O' 3045 // Output the message. Overwrite to avoid scrolling when the 'O'
3104 * flag is present in 'shortmess'; But when not jumping, print the 3046 // flag is present in 'shortmess'; But when not jumping, print the
3105 * whole message. */ 3047 // whole message.
3106 i = msg_scroll; 3048 i = msg_scroll;
3107 if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum) 3049 if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum)
3108 msg_scroll = TRUE; 3050 msg_scroll = TRUE;
3109 else if (!msg_scrolled && shortmess(SHM_OVERALL)) 3051 else if (!msg_scrolled && shortmess(SHM_OVERALL))
3110 msg_scroll = FALSE; 3052 msg_scroll = FALSE;
3302 else 3244 else
3303 free_string_option(old_swb); 3245 free_string_option(old_swb);
3304 } 3246 }
3305 } 3247 }
3306 3248
3307 /* 3249 // Highlight attributes used for displaying entries from the quickfix list.
3308 * Highlight attributes used for displaying entries from the quickfix list.
3309 */
3310 static int qfFileAttr; 3250 static int qfFileAttr;
3311 static int qfSepAttr; 3251 static int qfSepAttr;
3312 static int qfLineAttr; 3252 static int qfLineAttr;
3313 3253
3314 /* 3254 /*
3331 else { 3271 else {
3332 if (qfp->qf_fnum != 0 3272 if (qfp->qf_fnum != 0
3333 && (buf = buflist_findnr(qfp->qf_fnum)) != NULL) 3273 && (buf = buflist_findnr(qfp->qf_fnum)) != NULL)
3334 { 3274 {
3335 fname = buf->b_fname; 3275 fname = buf->b_fname;
3336 if (qfp->qf_type == 1) /* :helpgrep */ 3276 if (qfp->qf_type == 1) // :helpgrep
3337 fname = gettail(fname); 3277 fname = gettail(fname);
3338 } 3278 }
3339 if (fname == NULL) 3279 if (fname == NULL)
3340 sprintf((char *)IObuff, "%2d", qf_idx); 3280 sprintf((char *)IObuff, "%2d", qf_idx);
3341 else 3281 else
3380 msg_puts(IObuff); 3320 msg_puts(IObuff);
3381 msg_puts_attr((char_u *)":", qfSepAttr); 3321 msg_puts_attr((char_u *)":", qfSepAttr);
3382 } 3322 }
3383 msg_puts((char_u *)" "); 3323 msg_puts((char_u *)" ");
3384 3324
3385 /* Remove newlines and leading whitespace from the text. For an 3325 // Remove newlines and leading whitespace from the text. For an
3386 * unrecognized line keep the indent, the compiler may mark a word 3326 // unrecognized line keep the indent, the compiler may mark a word
3387 * with ^^^^. */ 3327 // with ^^^^.
3388 qf_fmt_text((fname != NULL || qfp->qf_lnum != 0) 3328 qf_fmt_text((fname != NULL || qfp->qf_lnum != 0)
3389 ? skipwhite(qfp->qf_text) : qfp->qf_text, 3329 ? skipwhite(qfp->qf_text) : qfp->qf_text,
3390 IObuff, IOSIZE); 3330 IObuff, IOSIZE);
3391 msg_prt_line(IObuff, FALSE); 3331 msg_prt_line(IObuff, FALSE);
3392 out_flush(); /* show one line at a time */ 3332 out_flush(); // show one line at a time
3393 } 3333 }
3394 3334
3395 /* 3335 /*
3396 * ":clist": list all errors 3336 * ":clist": list all errors
3397 * ":llist": list all locations 3337 * ":llist": list all locations
3404 int i; 3344 int i;
3405 int idx1 = 1; 3345 int idx1 = 1;
3406 int idx2 = -1; 3346 int idx2 = -1;
3407 char_u *arg = eap->arg; 3347 char_u *arg = eap->arg;
3408 int plus = FALSE; 3348 int plus = FALSE;
3409 int all = eap->forceit; /* if not :cl!, only show 3349 int all = eap->forceit; // if not :cl!, only show
3410 recognised errors */ 3350 // recognised errors
3411 qf_info_T *qi = &ql_info; 3351 qf_info_T *qi = &ql_info;
3412 3352
3413 if (is_loclist_cmd(eap->cmdidx)) 3353 if (is_loclist_cmd(eap->cmdidx))
3414 { 3354 {
3415 qi = GET_LOC_LIST(curwin); 3355 qi = GET_LOC_LIST(curwin);
3449 idx1 = (-idx1 > i) ? 0 : idx1 + i + 1; 3389 idx1 = (-idx1 > i) ? 0 : idx1 + i + 1;
3450 if (idx2 < 0) 3390 if (idx2 < 0)
3451 idx2 = (-idx2 > i) ? 0 : idx2 + i + 1; 3391 idx2 = (-idx2 > i) ? 0 : idx2 + i + 1;
3452 } 3392 }
3453 3393
3454 /* Shorten all the file names, so that it is easy to read */ 3394 // Shorten all the file names, so that it is easy to read
3455 shorten_fnames(FALSE); 3395 shorten_fnames(FALSE);
3456 3396
3457 /* 3397 // Get the attributes for the different quickfix highlight items. Note
3458 * Get the attributes for the different quickfix highlight items. Note 3398 // that this depends on syntax items defined in the qf.vim syntax file
3459 * that this depends on syntax items defined in the qf.vim syntax file
3460 */
3461 qfFileAttr = syn_name2attr((char_u *)"qfFileName"); 3399 qfFileAttr = syn_name2attr((char_u *)"qfFileName");
3462 if (qfFileAttr == 0) 3400 if (qfFileAttr == 0)
3463 qfFileAttr = HL_ATTR(HLF_D); 3401 qfFileAttr = HL_ATTR(HLF_D);
3464 qfSepAttr = syn_name2attr((char_u *)"qfSeparator"); 3402 qfSepAttr = syn_name2attr((char_u *)"qfSeparator");
3465 if (qfSepAttr == 0) 3403 if (qfSepAttr == 0)
3636 vim_free(qfp->qf_text); 3574 vim_free(qfp->qf_text);
3637 vim_free(qfp->qf_pattern); 3575 vim_free(qfp->qf_pattern);
3638 stop = (qfp == qfpnext); 3576 stop = (qfp == qfpnext);
3639 vim_free(qfp); 3577 vim_free(qfp);
3640 if (stop) 3578 if (stop)
3641 /* Somehow qf_count may have an incorrect value, set it to 1 3579 // Somehow qf_count may have an incorrect value, set it to 1
3642 * to avoid crashing when it's wrong. 3580 // to avoid crashing when it's wrong.
3643 * TODO: Avoid qf_count being incorrect. */ 3581 // TODO: Avoid qf_count being incorrect.
3644 qfl->qf_count = 1; 3582 qfl->qf_count = 1;
3645 } 3583 }
3646 qfl->qf_start = qfpnext; 3584 qfl->qf_start = qfpnext;
3647 --qfl->qf_count; 3585 --qfl->qf_count;
3648 } 3586 }
3826 qi = GET_LOC_LIST(curwin); 3764 qi = GET_LOC_LIST(curwin);
3827 if (qi == NULL) 3765 if (qi == NULL)
3828 return; 3766 return;
3829 } 3767 }
3830 3768
3831 /* Look for an existing quickfix window. */ 3769 // Look for an existing quickfix window.
3832 win = qf_find_win(qi); 3770 win = qf_find_win(qi);
3833 3771
3834 /* 3772 // If a quickfix window is open but we have no errors to display,
3835 * If a quickfix window is open but we have no errors to display, 3773 // close the window. If a quickfix window is not open, then open
3836 * close the window. If a quickfix window is not open, then open 3774 // it if we have errors; otherwise, leave it closed.
3837 * it if we have errors; otherwise, leave it closed.
3838 */
3839 if (qf_stack_empty(qi) 3775 if (qf_stack_empty(qi)
3840 || qi->qf_lists[qi->qf_curlist].qf_nonevalid 3776 || qi->qf_lists[qi->qf_curlist].qf_nonevalid
3841 || qf_list_empty(qi, qi->qf_curlist)) 3777 || qf_list_empty(qi, qi->qf_curlist))
3842 { 3778 {
3843 if (win != NULL) 3779 if (win != NULL)
3862 qi = GET_LOC_LIST(curwin); 3798 qi = GET_LOC_LIST(curwin);
3863 if (qi == NULL) 3799 if (qi == NULL)
3864 return; 3800 return;
3865 } 3801 }
3866 3802
3867 /* Find existing quickfix window and close it. */ 3803 // Find existing quickfix window and close it.
3868 win = qf_find_win(qi); 3804 win = qf_find_win(qi);
3869 if (win != NULL) 3805 if (win != NULL)
3870 win_close(win, FALSE); 3806 win_close(win, FALSE);
3871 } 3807 }
3872 3808
4050 curwin->w_cursor.col = 0; 3986 curwin->w_cursor.col = 0;
4051 #ifdef FEAT_VIRTUALEDIT 3987 #ifdef FEAT_VIRTUALEDIT
4052 curwin->w_cursor.coladd = 0; 3988 curwin->w_cursor.coladd = 0;
4053 #endif 3989 #endif
4054 curwin->w_curswant = 0; 3990 curwin->w_curswant = 0;
4055 update_topline(); /* scroll to show the line */ 3991 update_topline(); // scroll to show the line
4056 redraw_later(VALID); 3992 redraw_later(VALID);
4057 curwin->w_redr_status = TRUE; /* update ruler */ 3993 curwin->w_redr_status = TRUE; // update ruler
4058 curwin = old_curwin; 3994 curwin = old_curwin;
4059 curbuf = curwin->w_buffer; 3995 curbuf = curwin->w_buffer;
4060 } 3996 }
4061 3997
4062 /* 3998 /*
4091 qf_current_entry(win_T *wp) 4027 qf_current_entry(win_T *wp)
4092 { 4028 {
4093 qf_info_T *qi = &ql_info; 4029 qf_info_T *qi = &ql_info;
4094 4030
4095 if (IS_LL_WINDOW(wp)) 4031 if (IS_LL_WINDOW(wp))
4096 /* In the location list window, use the referenced location list */ 4032 // In the location list window, use the referenced location list
4097 qi = wp->w_llist_ref; 4033 qi = wp->w_llist_ref;
4098 4034
4099 return qi->qf_lists[qi->qf_curlist].qf_index; 4035 return qi->qf_lists[qi->qf_curlist].qf_index;
4100 } 4036 }
4101 4037
4104 * Return TRUE if there is a quickfix window. 4040 * Return TRUE if there is a quickfix window.
4105 */ 4041 */
4106 static int 4042 static int
4107 qf_win_pos_update( 4043 qf_win_pos_update(
4108 qf_info_T *qi, 4044 qf_info_T *qi,
4109 int old_qf_index) /* previous qf_index or zero */ 4045 int old_qf_index) // previous qf_index or zero
4110 { 4046 {
4111 win_T *win; 4047 win_T *win;
4112 int qf_index = qi->qf_lists[qi->qf_curlist].qf_index; 4048 int qf_index = qi->qf_lists[qi->qf_curlist].qf_index;
4113 4049
4114 /* 4050 // Put the cursor on the current error in the quickfix window, so that
4115 * Put the cursor on the current error in the quickfix window, so that 4051 // it's viewable.
4116 * it's viewable.
4117 */
4118 win = qf_find_win(qi); 4052 win = qf_find_win(qi);
4119 if (win != NULL 4053 if (win != NULL
4120 && qf_index <= win->w_buffer->b_ml.ml_line_count 4054 && qf_index <= win->w_buffer->b_ml.ml_line_count
4121 && old_qf_index != qf_index) 4055 && old_qf_index != qf_index)
4122 { 4056 {
4140 * stack. 4074 * stack.
4141 */ 4075 */
4142 static int 4076 static int
4143 is_qf_win(win_T *win, qf_info_T *qi) 4077 is_qf_win(win_T *win, qf_info_T *qi)
4144 { 4078 {
4145 /* 4079 // A window displaying the quickfix buffer will have the w_llist_ref field
4146 * A window displaying the quickfix buffer will have the w_llist_ref field 4080 // set to NULL.
4147 * set to NULL. 4081 // A window displaying a location list buffer will have the w_llist_ref
4148 * A window displaying a location list buffer will have the w_llist_ref 4082 // pointing to the location list.
4149 * pointing to the location list.
4150 */
4151 if (bt_quickfix(win->w_buffer)) 4083 if (bt_quickfix(win->w_buffer))
4152 if ((IS_QF_STACK(qi) && win->w_llist_ref == NULL) 4084 if ((IS_QF_STACK(qi) && win->w_llist_ref == NULL)
4153 || (IS_LL_STACK(qi) && win->w_llist_ref == qi)) 4085 || (IS_LL_STACK(qi) && win->w_llist_ref == qi))
4154 return TRUE; 4086 return TRUE;
4155 4087
4214 { 4146 {
4215 buf_T *buf; 4147 buf_T *buf;
4216 win_T *win; 4148 win_T *win;
4217 aco_save_T aco; 4149 aco_save_T aco;
4218 4150
4219 /* Check if a buffer for the quickfix list exists. Update it. */ 4151 // Check if a buffer for the quickfix list exists. Update it.
4220 buf = qf_find_buf(qi); 4152 buf = qf_find_buf(qi);
4221 if (buf != NULL) 4153 if (buf != NULL)
4222 { 4154 {
4223 linenr_T old_line_count = buf->b_ml.ml_line_count; 4155 linenr_T old_line_count = buf->b_ml.ml_line_count;
4224 4156
4225 if (old_last == NULL) 4157 if (old_last == NULL)
4226 /* set curwin/curbuf to buf and save a few things */ 4158 // set curwin/curbuf to buf and save a few things
4227 aucmd_prepbuf(&aco, buf); 4159 aucmd_prepbuf(&aco, buf);
4228 4160
4229 qf_update_win_titlevar(qi); 4161 qf_update_win_titlevar(qi);
4230 4162
4231 qf_fill_buffer(qi, buf, old_last); 4163 qf_fill_buffer(qi, buf, old_last);
4233 4165
4234 if (old_last == NULL) 4166 if (old_last == NULL)
4235 { 4167 {
4236 (void)qf_win_pos_update(qi, 0); 4168 (void)qf_win_pos_update(qi, 0);
4237 4169
4238 /* restore curwin/curbuf and a few other things */ 4170 // restore curwin/curbuf and a few other things
4239 aucmd_restbuf(&aco); 4171 aucmd_restbuf(&aco);
4240 } 4172 }
4241 4173
4242 /* Only redraw when added lines are visible. This avoids flickering 4174 // Only redraw when added lines are visible. This avoids flickering
4243 * when the added lines are not visible. */ 4175 // when the added lines are not visible.
4244 if ((win = qf_find_win(qi)) != NULL && old_line_count < win->w_botline) 4176 if ((win = qf_find_win(qi)) != NULL && old_line_count < win->w_botline)
4245 redraw_buf_later(buf, NOT_VALID); 4177 redraw_buf_later(buf, NOT_VALID);
4246 } 4178 }
4247 } 4179 }
4248 4180
4262 } 4194 }
4263 else if (qfp->qf_fnum != 0 4195 else if (qfp->qf_fnum != 0
4264 && (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL 4196 && (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL
4265 && errbuf->b_fname != NULL) 4197 && errbuf->b_fname != NULL)
4266 { 4198 {
4267 if (qfp->qf_type == 1) /* :helpgrep */ 4199 if (qfp->qf_type == 1) // :helpgrep
4268 STRCPY(IObuff, gettail(errbuf->b_fname)); 4200 STRCPY(IObuff, gettail(errbuf->b_fname));
4269 else 4201 else
4270 { 4202 {
4271 /* shorten the file name if not done already */ 4203 // shorten the file name if not done already
4272 if (errbuf->b_sfname == NULL 4204 if (errbuf->b_sfname == NULL
4273 || mch_isFullName(errbuf->b_sfname)) 4205 || mch_isFullName(errbuf->b_sfname))
4274 { 4206 {
4275 if (*dirname == NUL) 4207 if (*dirname == NUL)
4276 mch_dirname(dirname, MAXPATHL); 4208 mch_dirname(dirname, MAXPATHL);
4305 len += (int)STRLEN(IObuff + len); 4237 len += (int)STRLEN(IObuff + len);
4306 } 4238 }
4307 IObuff[len++] = '|'; 4239 IObuff[len++] = '|';
4308 IObuff[len++] = ' '; 4240 IObuff[len++] = ' ';
4309 4241
4310 /* Remove newlines and leading whitespace from the text. 4242 // Remove newlines and leading whitespace from the text.
4311 * For an unrecognized line keep the indent, the compiler may 4243 // For an unrecognized line keep the indent, the compiler may
4312 * mark a word with ^^^^. */ 4244 // mark a word with ^^^^.
4313 qf_fmt_text(len > 3 ? skipwhite(qfp->qf_text) : qfp->qf_text, 4245 qf_fmt_text(len > 3 ? skipwhite(qfp->qf_text) : qfp->qf_text,
4314 IObuff + len, IOSIZE - len); 4246 IObuff + len, IOSIZE - len);
4315 4247
4316 if (ml_append_buf(buf, lnum, IObuff, 4248 if (ml_append_buf(buf, lnum, IObuff,
4317 (colnr_T)STRLEN(IObuff) + 1, FALSE) == FAIL) 4249 (colnr_T)STRLEN(IObuff) + 1, FALSE) == FAIL)
4340 { 4272 {
4341 internal_error("qf_fill_buffer()"); 4273 internal_error("qf_fill_buffer()");
4342 return; 4274 return;
4343 } 4275 }
4344 4276
4345 /* delete all existing lines */ 4277 // delete all existing lines
4346 while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0) 4278 while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0)
4347 (void)ml_delete((linenr_T)1, FALSE); 4279 (void)ml_delete((linenr_T)1, FALSE);
4348 } 4280 }
4349 4281
4350 /* Check if there is anything to display */ 4282 // Check if there is anything to display
4351 if (!qf_stack_empty(qi)) 4283 if (!qf_stack_empty(qi))
4352 { 4284 {
4353 char_u dirname[MAXPATHL]; 4285 char_u dirname[MAXPATHL];
4354 4286
4355 *dirname = NUL; 4287 *dirname = NUL;
4356 4288
4357 /* Add one line for each error */ 4289 // Add one line for each error
4358 if (old_last == NULL) 4290 if (old_last == NULL)
4359 { 4291 {
4360 qfp = qi->qf_lists[qi->qf_curlist].qf_start; 4292 qfp = qi->qf_lists[qi->qf_curlist].qf_start;
4361 lnum = 0; 4293 lnum = 0;
4362 } 4294 }
4375 if (qfp == NULL) 4307 if (qfp == NULL)
4376 break; 4308 break;
4377 } 4309 }
4378 4310
4379 if (old_last == NULL) 4311 if (old_last == NULL)
4380 /* Delete the empty line which is now at the end */ 4312 // Delete the empty line which is now at the end
4381 (void)ml_delete(lnum + 1, FALSE); 4313 (void)ml_delete(lnum + 1, FALSE);
4382 } 4314 }
4383 4315
4384 /* correct cursor position */ 4316 // correct cursor position
4385 check_lnums(TRUE); 4317 check_lnums(TRUE);
4386 4318
4387 if (old_last == NULL) 4319 if (old_last == NULL)
4388 { 4320 {
4389 /* Set the 'filetype' to "qf" each time after filling the buffer. 4321 // Set the 'filetype' to "qf" each time after filling the buffer.
4390 * This resembles reading a file into a buffer, it's more logical when 4322 // This resembles reading a file into a buffer, it's more logical when
4391 * using autocommands. */ 4323 // using autocommands.
4392 ++curbuf_lock; 4324 ++curbuf_lock;
4393 set_option_value((char_u *)"ft", 0L, (char_u *)"qf", OPT_LOCAL); 4325 set_option_value((char_u *)"ft", 0L, (char_u *)"qf", OPT_LOCAL);
4394 curbuf->b_p_ma = FALSE; 4326 curbuf->b_p_ma = FALSE;
4395 4327
4396 keep_filetype = TRUE; /* don't detect 'filetype' */ 4328 keep_filetype = TRUE; // don't detect 'filetype'
4397 apply_autocmds(EVENT_BUFREADPOST, (char_u *)"quickfix", NULL, 4329 apply_autocmds(EVENT_BUFREADPOST, (char_u *)"quickfix", NULL,
4398 FALSE, curbuf); 4330 FALSE, curbuf);
4399 apply_autocmds(EVENT_BUFWINENTER, (char_u *)"quickfix", NULL, 4331 apply_autocmds(EVENT_BUFWINENTER, (char_u *)"quickfix", NULL,
4400 FALSE, curbuf); 4332 FALSE, curbuf);
4401 keep_filetype = FALSE; 4333 keep_filetype = FALSE;
4402 --curbuf_lock; 4334 --curbuf_lock;
4403 4335
4404 /* make sure it will be redrawn */ 4336 // make sure it will be redrawn
4405 redraw_curbuf_later(NOT_VALID); 4337 redraw_curbuf_later(NOT_VALID);
4406 } 4338 }
4407 4339
4408 /* Restore KeyTyped, setting 'filetype' may reset it. */ 4340 // Restore KeyTyped, setting 'filetype' may reset it.
4409 KeyTyped = old_KeyTyped; 4341 KeyTyped = old_KeyTyped;
4410 } 4342 }
4411 4343
4412 /* 4344 /*
4413 * For every change made to the quickfix list, update the changed tick. 4345 * For every change made to the quickfix list, update the changed tick.
4692 int i, sz = 0; 4624 int i, sz = 0;
4693 int prev_fnum = 0; 4625 int prev_fnum = 0;
4694 4626
4695 if (is_loclist_cmd(eap->cmdidx)) 4627 if (is_loclist_cmd(eap->cmdidx))
4696 { 4628 {
4697 /* Location list */ 4629 // Location list
4698 qi = GET_LOC_LIST(curwin); 4630 qi = GET_LOC_LIST(curwin);
4699 if (qi == NULL) 4631 if (qi == NULL)
4700 return 0; 4632 return 0;
4701 } 4633 }
4702 4634
4705 ++i, qfp = qfp->qf_next) 4637 ++i, qfp = qfp->qf_next)
4706 { 4638 {
4707 if (qfp->qf_valid) 4639 if (qfp->qf_valid)
4708 { 4640 {
4709 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo) 4641 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo)
4710 sz++; /* Count all valid entries */ 4642 sz++; // Count all valid entries
4711 else if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum) 4643 else if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum)
4712 { 4644 {
4713 /* Count the number of files */ 4645 // Count the number of files
4714 sz++; 4646 sz++;
4715 prev_fnum = qfp->qf_fnum; 4647 prev_fnum = qfp->qf_fnum;
4716 } 4648 }
4717 } 4649 }
4718 } 4650 }
4729 { 4661 {
4730 qf_info_T *qi = &ql_info; 4662 qf_info_T *qi = &ql_info;
4731 4663
4732 if (is_loclist_cmd(eap->cmdidx)) 4664 if (is_loclist_cmd(eap->cmdidx))
4733 { 4665 {
4734 /* Location list */ 4666 // Location list
4735 qi = GET_LOC_LIST(curwin); 4667 qi = GET_LOC_LIST(curwin);
4736 if (qi == NULL) 4668 if (qi == NULL)
4737 return 0; 4669 return 0;
4738 } 4670 }
4739 4671
4753 int i, eidx = 0; 4685 int i, eidx = 0;
4754 int prev_fnum = 0; 4686 int prev_fnum = 0;
4755 4687
4756 if (is_loclist_cmd(eap->cmdidx)) 4688 if (is_loclist_cmd(eap->cmdidx))
4757 { 4689 {
4758 /* Location list */ 4690 // Location list
4759 qi = GET_LOC_LIST(curwin); 4691 qi = GET_LOC_LIST(curwin);
4760 if (qi == NULL) 4692 if (qi == NULL)
4761 return 1; 4693 return 1;
4762 } 4694 }
4763 4695
4764 qfl = &qi->qf_lists[qi->qf_curlist]; 4696 qfl = &qi->qf_lists[qi->qf_curlist];
4765 qfp = qfl->qf_start; 4697 qfp = qfl->qf_start;
4766 4698
4767 /* check if the list has valid errors */ 4699 // check if the list has valid errors
4768 if (qfl->qf_count <= 0 || qfl->qf_nonevalid) 4700 if (qfl->qf_count <= 0 || qfl->qf_nonevalid)
4769 return 1; 4701 return 1;
4770 4702
4771 for (i = 1; i <= qfl->qf_index && qfp!= NULL; i++, qfp = qfp->qf_next) 4703 for (i = 1; i <= qfl->qf_index && qfp!= NULL; i++, qfp = qfp->qf_next)
4772 { 4704 {
4774 { 4706 {
4775 if (eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) 4707 if (eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo)
4776 { 4708 {
4777 if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum) 4709 if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum)
4778 { 4710 {
4779 /* Count the number of files */ 4711 // Count the number of files
4780 eidx++; 4712 eidx++;
4781 prev_fnum = qfp->qf_fnum; 4713 prev_fnum = qfp->qf_fnum;
4782 } 4714 }
4783 } 4715 }
4784 else 4716 else
4800 { 4732 {
4801 qfline_T *qfp = qfl->qf_start; 4733 qfline_T *qfp = qfl->qf_start;
4802 int i, eidx; 4734 int i, eidx;
4803 int prev_fnum = 0; 4735 int prev_fnum = 0;
4804 4736
4805 /* check if the list has valid errors */ 4737 // check if the list has valid errors
4806 if (qfl->qf_count <= 0 || qfl->qf_nonevalid) 4738 if (qfl->qf_count <= 0 || qfl->qf_nonevalid)
4807 return 1; 4739 return 1;
4808 4740
4809 for (i = 1, eidx = 0; i <= qfl->qf_count && qfp != NULL; 4741 for (i = 1, eidx = 0; i <= qfl->qf_count && qfp != NULL;
4810 i++, qfp = qfp->qf_next) 4742 i++, qfp = qfp->qf_next)
4813 { 4745 {
4814 if (fdo) 4746 if (fdo)
4815 { 4747 {
4816 if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum) 4748 if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum)
4817 { 4749 {
4818 /* Count the number of files */ 4750 // Count the number of files
4819 eidx++; 4751 eidx++;
4820 prev_fnum = qfp->qf_fnum; 4752 prev_fnum = qfp->qf_fnum;
4821 } 4753 }
4822 } 4754 }
4823 else 4755 else
4871 default: 4803 default:
4872 errornr = 32767; 4804 errornr = 32767;
4873 } 4805 }
4874 } 4806 }
4875 4807
4876 /* For cdo and ldo commands, jump to the nth valid error. 4808 // For cdo and ldo commands, jump to the nth valid error.
4877 * For cfdo and lfdo commands, jump to the nth valid file entry. 4809 // For cfdo and lfdo commands, jump to the nth valid file entry.
4878 */
4879 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo 4810 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo
4880 || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) 4811 || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo)
4881 errornr = qf_get_nth_valid_entry(&qi->qf_lists[qi->qf_curlist], 4812 errornr = qf_get_nth_valid_entry(&qi->qf_lists[qi->qf_curlist],
4882 eap->addr_count > 0 ? (int)eap->line1 : 1, 4813 eap->addr_count > 0 ? (int)eap->line1 : 1,
4883 eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo); 4814 eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo);
4947 { 4878 {
4948 char_u *enc = NULL; 4879 char_u *enc = NULL;
4949 win_T *wp = NULL; 4880 win_T *wp = NULL;
4950 qf_info_T *qi = &ql_info; 4881 qf_info_T *qi = &ql_info;
4951 char_u *au_name = NULL; 4882 char_u *au_name = NULL;
4952 int_u save_qfid = 0; /* init for gcc */ 4883 int_u save_qfid = 0; // init for gcc
4953 int res; 4884 int res;
4954 4885
4955 switch (eap->cmdidx) 4886 switch (eap->cmdidx)
4956 { 4887 {
4957 case CMD_cfile: au_name = (char_u *)"cfile"; break; 4888 case CMD_cfile: au_name = (char_u *)"cfile"; break;
4984 set_string_option_direct((char_u *)"ef", -1, eap->arg, OPT_FREE, 0); 4915 set_string_option_direct((char_u *)"ef", -1, eap->arg, OPT_FREE, 0);
4985 4916
4986 if (is_loclist_cmd(eap->cmdidx)) 4917 if (is_loclist_cmd(eap->cmdidx))
4987 wp = curwin; 4918 wp = curwin;
4988 4919
4989 /* 4920 // This function is used by the :cfile, :cgetfile and :caddfile
4990 * This function is used by the :cfile, :cgetfile and :caddfile 4921 // commands.
4991 * commands. 4922 // :cfile always creates a new quickfix list and jumps to the
4992 * :cfile always creates a new quickfix list and jumps to the 4923 // first error.
4993 * first error. 4924 // :cgetfile creates a new quickfix list but doesn't jump to the
4994 * :cgetfile creates a new quickfix list but doesn't jump to the 4925 // first error.
4995 * first error. 4926 // :caddfile adds to an existing quickfix list. If there is no
4996 * :caddfile adds to an existing quickfix list. If there is no 4927 // quickfix list then a new list is created.
4997 * quickfix list then a new list is created.
4998 */
4999 res = qf_init(wp, p_ef, p_efm, (eap->cmdidx != CMD_caddfile 4928 res = qf_init(wp, p_ef, p_efm, (eap->cmdidx != CMD_caddfile
5000 && eap->cmdidx != CMD_laddfile), 4929 && eap->cmdidx != CMD_laddfile),
5001 qf_cmdtitle(*eap->cmdlinep), enc); 4930 qf_cmdtitle(*eap->cmdlinep), enc);
5002 if (wp != NULL) 4931 if (wp != NULL)
5003 { 4932 {
5043 * Initialize the regmatch used by vimgrep for pattern "s". 4972 * Initialize the regmatch used by vimgrep for pattern "s".
5044 */ 4973 */
5045 static void 4974 static void
5046 vgr_init_regmatch(regmmatch_T *regmatch, char_u *s) 4975 vgr_init_regmatch(regmmatch_T *regmatch, char_u *s)
5047 { 4976 {
5048 /* Get the search pattern: either white-separated or enclosed in // */ 4977 // Get the search pattern: either white-separated or enclosed in //
5049 regmatch->regprog = NULL; 4978 regmatch->regprog = NULL;
5050 4979
5051 if (s == NULL || *s == NUL) 4980 if (s == NULL || *s == NUL)
5052 { 4981 {
5053 /* Pattern is empty, use last search pattern. */ 4982 // Pattern is empty, use last search pattern.
5054 if (last_search_pat() == NULL) 4983 if (last_search_pat() == NULL)
5055 { 4984 {
5056 EMSG(_(e_noprevre)); 4985 EMSG(_(e_noprevre));
5057 return; 4986 return;
5058 } 4987 }
5081 { 5010 {
5082 msg_outtrans(p); 5011 msg_outtrans(p);
5083 vim_free(p); 5012 vim_free(p);
5084 } 5013 }
5085 msg_clr_eos(); 5014 msg_clr_eos();
5086 msg_didout = FALSE; /* overwrite this message */ 5015 msg_didout = FALSE; // overwrite this message
5087 msg_nowait = TRUE; /* don't wait for this message */ 5016 msg_nowait = TRUE; // don't wait for this message
5088 msg_col = 0; 5017 msg_col = 0;
5089 out_flush(); 5018 out_flush();
5090 } 5019 }
5091 5020
5092 /* 5021 /*
5103 char_u *save_ei = NULL; 5032 char_u *save_ei = NULL;
5104 #endif 5033 #endif
5105 buf_T *buf; 5034 buf_T *buf;
5106 5035
5107 #if defined(FEAT_SYN_HL) 5036 #if defined(FEAT_SYN_HL)
5108 /* Don't do Filetype autocommands to avoid loading syntax and 5037 // Don't do Filetype autocommands to avoid loading syntax and
5109 * indent scripts, a great speed improvement. */ 5038 // indent scripts, a great speed improvement.
5110 save_ei = au_event_disable(",Filetype"); 5039 save_ei = au_event_disable(",Filetype");
5111 #endif 5040 #endif
5112 /* Don't use modelines here, it's useless. */ 5041 // Don't use modelines here, it's useless.
5113 save_mls = p_mls; 5042 save_mls = p_mls;
5114 p_mls = 0; 5043 p_mls = 0;
5115 5044
5116 /* Load file into a buffer, so that 'fileencoding' is detected, 5045 // Load file into a buffer, so that 'fileencoding' is detected,
5117 * autocommands applied, etc. */ 5046 // autocommands applied, etc.
5118 buf = load_dummy_buffer(fname, dirname_start, dirname_now); 5047 buf = load_dummy_buffer(fname, dirname_start, dirname_now);
5119 5048
5120 p_mls = save_mls; 5049 p_mls = save_mls;
5121 #if defined(FEAT_SYN_HL) 5050 #if defined(FEAT_SYN_HL)
5122 au_event_restore(save_ei); 5051 au_event_restore(save_ei);
5135 win_T *wp, 5064 win_T *wp,
5136 qf_info_T *qi, 5065 qf_info_T *qi,
5137 int_u qfid, 5066 int_u qfid,
5138 char_u *title) 5067 char_u *title)
5139 { 5068 {
5140 /* Verify that the quickfix/location list was not freed by an autocmd */ 5069 // Verify that the quickfix/location list was not freed by an autocmd
5141 if (!qflist_valid(wp, qfid)) 5070 if (!qflist_valid(wp, qfid))
5142 { 5071 {
5143 if (wp != NULL) 5072 if (wp != NULL)
5144 { 5073 {
5145 /* An autocmd has freed the location list. */ 5074 // An autocmd has freed the location list.
5146 EMSG(_(e_loc_list_changed)); 5075 EMSG(_(e_loc_list_changed));
5147 return FALSE; 5076 return FALSE;
5148 } 5077 }
5149 else 5078 else
5150 { 5079 {
5151 /* Quickfix list is not found, create a new one. */ 5080 // Quickfix list is not found, create a new one.
5152 qf_new_list(qi, title); 5081 qf_new_list(qi, title);
5153 return TRUE; 5082 return TRUE;
5154 } 5083 }
5155 } 5084 }
5156 5085
5182 { 5111 {
5183 col = 0; 5112 col = 0;
5184 while (vim_regexec_multi(regmatch, curwin, buf, lnum, 5113 while (vim_regexec_multi(regmatch, curwin, buf, lnum,
5185 col, NULL, NULL) > 0) 5114 col, NULL, NULL) > 0)
5186 { 5115 {
5187 /* Pass the buffer number so that it gets used even for a 5116 // Pass the buffer number so that it gets used even for a
5188 * dummy buffer, unless duplicate_name is set, then the 5117 // dummy buffer, unless duplicate_name is set, then the
5189 * buffer will be wiped out below. */ 5118 // buffer will be wiped out below.
5190 if (qf_add_entry(qi, 5119 if (qf_add_entry(qi,
5191 qi->qf_curlist, 5120 qi->qf_curlist,
5192 NULL, /* dir */ 5121 NULL, // dir
5193 fname, 5122 fname,
5194 NULL, 5123 NULL,
5195 duplicate_name ? 0 : buf->b_fnum, 5124 duplicate_name ? 0 : buf->b_fnum,
5196 ml_get_buf(buf, 5125 ml_get_buf(buf,
5197 regmatch->startpos[0].lnum + lnum, FALSE), 5126 regmatch->startpos[0].lnum + lnum, FALSE),
5198 regmatch->startpos[0].lnum + lnum, 5127 regmatch->startpos[0].lnum + lnum,
5199 regmatch->startpos[0].col + 1, 5128 regmatch->startpos[0].col + 1,
5200 FALSE, /* vis_col */ 5129 FALSE, // vis_col
5201 NULL, /* search pattern */ 5130 NULL, // search pattern
5202 0, /* nr */ 5131 0, // nr
5203 0, /* type */ 5132 0, // type
5204 TRUE /* valid */ 5133 TRUE // valid
5205 ) == FAIL) 5134 ) == FAIL)
5206 { 5135 {
5207 got_int = TRUE; 5136 got_int = TRUE;
5208 break; 5137 break;
5209 } 5138 }
5240 buf_T *buf; 5169 buf_T *buf;
5241 5170
5242 buf = curbuf; 5171 buf = curbuf;
5243 qf_jump(qi, 0, 0, forceit); 5172 qf_jump(qi, 0, 0, forceit);
5244 if (buf != curbuf) 5173 if (buf != curbuf)
5245 /* If we jumped to another buffer redrawing will already be 5174 // If we jumped to another buffer redrawing will already be
5246 * taken care of. */ 5175 // taken care of.
5247 *redraw_for_dummy = FALSE; 5176 *redraw_for_dummy = FALSE;
5248 5177
5249 /* Jump to the directory used after loading the buffer. */ 5178 // Jump to the directory used after loading the buffer.
5250 if (curbuf == first_match_buf && target_dir != NULL) 5179 if (curbuf == first_match_buf && target_dir != NULL)
5251 { 5180 {
5252 exarg_T ea; 5181 exarg_T ea;
5253 5182
5254 ea.arg = target_dir; 5183 ea.arg = target_dir;
5313 if (eap->addr_count > 0) 5242 if (eap->addr_count > 0)
5314 tomatch = eap->line2; 5243 tomatch = eap->line2;
5315 else 5244 else
5316 tomatch = MAXLNUM; 5245 tomatch = MAXLNUM;
5317 5246
5318 /* Get the search pattern: either white-separated or enclosed in // */ 5247 // Get the search pattern: either white-separated or enclosed in //
5319 regmatch.regprog = NULL; 5248 regmatch.regprog = NULL;
5320 title = vim_strsave(qf_cmdtitle(*eap->cmdlinep)); 5249 title = vim_strsave(qf_cmdtitle(*eap->cmdlinep));
5321 p = skip_vimgrep_pat(eap->arg, &s, &flags); 5250 p = skip_vimgrep_pat(eap->arg, &s, &flags);
5322 if (p == NULL) 5251 if (p == NULL)
5323 { 5252 {
5338 5267
5339 if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd 5268 if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd
5340 && eap->cmdidx != CMD_vimgrepadd 5269 && eap->cmdidx != CMD_vimgrepadd
5341 && eap->cmdidx != CMD_lvimgrepadd) 5270 && eap->cmdidx != CMD_lvimgrepadd)
5342 || qf_stack_empty(qi)) 5271 || qf_stack_empty(qi))
5343 /* make place for a new list */ 5272 // make place for a new list
5344 qf_new_list(qi, title != NULL ? title : qf_cmdtitle(*eap->cmdlinep)); 5273 qf_new_list(qi, title != NULL ? title : qf_cmdtitle(*eap->cmdlinep));
5345 5274
5346 /* parse the list of arguments */ 5275 // parse the list of arguments
5347 if (get_arglist_exp(p, &fcount, &fnames, TRUE) == FAIL) 5276 if (get_arglist_exp(p, &fcount, &fnames, TRUE) == FAIL)
5348 goto theend; 5277 goto theend;
5349 if (fcount == 0) 5278 if (fcount == 0)
5350 { 5279 {
5351 EMSG(_(e_nomatch)); 5280 EMSG(_(e_nomatch));
5358 { 5287 {
5359 FreeWild(fcount, fnames); 5288 FreeWild(fcount, fnames);
5360 goto theend; 5289 goto theend;
5361 } 5290 }
5362 5291
5363 /* Remember the current directory, because a BufRead autocommand that does 5292 // Remember the current directory, because a BufRead autocommand that does
5364 * ":lcd %:p:h" changes the meaning of short path names. */ 5293 // ":lcd %:p:h" changes the meaning of short path names.
5365 mch_dirname(dirname_start, MAXPATHL); 5294 mch_dirname(dirname_start, MAXPATHL);
5366 5295
5367 /* Remember the current quickfix list identifier, so that we can check for 5296 // Remember the current quickfix list identifier, so that we can check for
5368 * autocommands changing the current quickfix list. */ 5297 // autocommands changing the current quickfix list.
5369 save_qfid = qi->qf_lists[qi->qf_curlist].qf_id; 5298 save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
5370 5299
5371 seconds = (time_t)0; 5300 seconds = (time_t)0;
5372 for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) 5301 for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi)
5373 { 5302 {
5374 fname = shorten_fname1(fnames[fi]); 5303 fname = shorten_fname1(fnames[fi]);
5375 if (time(NULL) > seconds) 5304 if (time(NULL) > seconds)
5376 { 5305 {
5377 /* Display the file name every second or so, show the user we are 5306 // Display the file name every second or so, show the user we are
5378 * working on it. */ 5307 // working on it.
5379 seconds = time(NULL); 5308 seconds = time(NULL);
5380 vgr_display_fname(fname); 5309 vgr_display_fname(fname);
5381 } 5310 }
5382 5311
5383 buf = buflist_findname_exp(fnames[fi]); 5312 buf = buflist_findname_exp(fnames[fi]);
5384 if (buf == NULL || buf->b_ml.ml_mfp == NULL) 5313 if (buf == NULL || buf->b_ml.ml_mfp == NULL)
5385 { 5314 {
5386 /* Remember that a buffer with this name already exists. */ 5315 // Remember that a buffer with this name already exists.
5387 duplicate_name = (buf != NULL); 5316 duplicate_name = (buf != NULL);
5388 using_dummy = TRUE; 5317 using_dummy = TRUE;
5389 redraw_for_dummy = TRUE; 5318 redraw_for_dummy = TRUE;
5390 5319
5391 buf = vgr_load_dummy_buf(fname, dirname_start, dirname_now); 5320 buf = vgr_load_dummy_buf(fname, dirname_start, dirname_now);
5392 } 5321 }
5393 else 5322 else
5394 /* Use existing, loaded buffer. */ 5323 // Use existing, loaded buffer.
5395 using_dummy = FALSE; 5324 using_dummy = FALSE;
5396 5325
5397 /* Check whether the quickfix list is still valid. When loading a 5326 // Check whether the quickfix list is still valid. When loading a
5398 * buffer above, autocommands might have changed the quickfix list. */ 5327 // buffer above, autocommands might have changed the quickfix list.
5399 if (!vgr_qflist_valid(wp, qi, save_qfid, qf_cmdtitle(*eap->cmdlinep))) 5328 if (!vgr_qflist_valid(wp, qi, save_qfid, qf_cmdtitle(*eap->cmdlinep)))
5400 { 5329 {
5401 FreeWild(fcount, fnames); 5330 FreeWild(fcount, fnames);
5402 goto theend; 5331 goto theend;
5403 } 5332 }
5408 if (!got_int) 5337 if (!got_int)
5409 smsg((char_u *)_("Cannot open file \"%s\""), fname); 5338 smsg((char_u *)_("Cannot open file \"%s\""), fname);
5410 } 5339 }
5411 else 5340 else
5412 { 5341 {
5413 /* Try for a match in all lines of the buffer. 5342 // Try for a match in all lines of the buffer.
5414 * For ":1vimgrep" look for first match only. */ 5343 // For ":1vimgrep" look for first match only.
5415 found_match = vgr_match_buflines(qi, fname, buf, &regmatch, 5344 found_match = vgr_match_buflines(qi, fname, buf, &regmatch,
5416 tomatch, duplicate_name, flags); 5345 tomatch, duplicate_name, flags);
5417 5346
5418 if (using_dummy) 5347 if (using_dummy)
5419 { 5348 {
5420 if (found_match && first_match_buf == NULL) 5349 if (found_match && first_match_buf == NULL)
5421 first_match_buf = buf; 5350 first_match_buf = buf;
5422 if (duplicate_name) 5351 if (duplicate_name)
5423 { 5352 {
5424 /* Never keep a dummy buffer if there is another buffer 5353 // Never keep a dummy buffer if there is another buffer
5425 * with the same name. */ 5354 // with the same name.
5426 wipe_dummy_buffer(buf, dirname_start); 5355 wipe_dummy_buffer(buf, dirname_start);
5427 buf = NULL; 5356 buf = NULL;
5428 } 5357 }
5429 else if (!cmdmod.hide 5358 else if (!cmdmod.hide
5430 || buf->b_p_bh[0] == 'u' /* "unload" */ 5359 || buf->b_p_bh[0] == 'u' // "unload"
5431 || buf->b_p_bh[0] == 'w' /* "wipe" */ 5360 || buf->b_p_bh[0] == 'w' // "wipe"
5432 || buf->b_p_bh[0] == 'd') /* "delete" */ 5361 || buf->b_p_bh[0] == 'd') // "delete"
5433 { 5362 {
5434 /* When no match was found we don't need to remember the 5363 // When no match was found we don't need to remember the
5435 * buffer, wipe it out. If there was a match and it 5364 // buffer, wipe it out. If there was a match and it
5436 * wasn't the first one or we won't jump there: only 5365 // wasn't the first one or we won't jump there: only
5437 * unload the buffer. 5366 // unload the buffer.
5438 * Ignore 'hidden' here, because it may lead to having too 5367 // Ignore 'hidden' here, because it may lead to having too
5439 * many swap files. */ 5368 // many swap files.
5440 if (!found_match) 5369 if (!found_match)
5441 { 5370 {
5442 wipe_dummy_buffer(buf, dirname_start); 5371 wipe_dummy_buffer(buf, dirname_start);
5443 buf = NULL; 5372 buf = NULL;
5444 } 5373 }
5445 else if (buf != first_match_buf || (flags & VGR_NOJUMP)) 5374 else if (buf != first_match_buf || (flags & VGR_NOJUMP))
5446 { 5375 {
5447 unload_dummy_buffer(buf, dirname_start); 5376 unload_dummy_buffer(buf, dirname_start);
5448 /* Keeping the buffer, remove the dummy flag. */ 5377 // Keeping the buffer, remove the dummy flag.
5449 buf->b_flags &= ~BF_DUMMY; 5378 buf->b_flags &= ~BF_DUMMY;
5450 buf = NULL; 5379 buf = NULL;
5451 } 5380 }
5452 } 5381 }
5453 5382
5454 if (buf != NULL) 5383 if (buf != NULL)
5455 { 5384 {
5456 /* Keeping the buffer, remove the dummy flag. */ 5385 // Keeping the buffer, remove the dummy flag.
5457 buf->b_flags &= ~BF_DUMMY; 5386 buf->b_flags &= ~BF_DUMMY;
5458 5387
5459 /* If the buffer is still loaded we need to use the 5388 // If the buffer is still loaded we need to use the
5460 * directory we jumped to below. */ 5389 // directory we jumped to below.
5461 if (buf == first_match_buf 5390 if (buf == first_match_buf
5462 && target_dir == NULL 5391 && target_dir == NULL
5463 && STRCMP(dirname_start, dirname_now) != 0) 5392 && STRCMP(dirname_start, dirname_now) != 0)
5464 target_dir = vim_strsave(dirname_now); 5393 target_dir = vim_strsave(dirname_now);
5465 5394
5466 /* The buffer is still loaded, the Filetype autocommands 5395 // The buffer is still loaded, the Filetype autocommands
5467 * need to be done now, in that buffer. And the modelines 5396 // need to be done now, in that buffer. And the modelines
5468 * need to be done (again). But not the window-local 5397 // need to be done (again). But not the window-local
5469 * options! */ 5398 // options!
5470 aucmd_prepbuf(&aco, buf); 5399 aucmd_prepbuf(&aco, buf);
5471 #if defined(FEAT_SYN_HL) 5400 #if defined(FEAT_SYN_HL)
5472 apply_autocmds(EVENT_FILETYPE, buf->b_p_ft, 5401 apply_autocmds(EVENT_FILETYPE, buf->b_p_ft,
5473 buf->b_fname, TRUE, buf); 5402 buf->b_fname, TRUE, buf);
5474 #endif 5403 #endif
5489 qf_update_buffer(qi, NULL); 5418 qf_update_buffer(qi, NULL);
5490 5419
5491 if (au_name != NULL) 5420 if (au_name != NULL)
5492 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, 5421 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
5493 curbuf->b_fname, TRUE, curbuf); 5422 curbuf->b_fname, TRUE, curbuf);
5494 /* 5423 // The QuickFixCmdPost autocmd may free the quickfix list. Check the list
5495 * The QuickFixCmdPost autocmd may free the quickfix list. Check the list 5424 // is still valid.
5496 * is still valid.
5497 */
5498 if (!qflist_valid(wp, save_qfid)) 5425 if (!qflist_valid(wp, save_qfid))
5499 goto theend; 5426 goto theend;
5500 5427
5501 if (qf_restore_list(qi, save_qfid) == FAIL) 5428 if (qf_restore_list(qi, save_qfid) == FAIL)
5502 goto theend; 5429 goto theend;
5509 first_match_buf, target_dir); 5436 first_match_buf, target_dir);
5510 } 5437 }
5511 else 5438 else
5512 EMSG2(_(e_nomatch2), s); 5439 EMSG2(_(e_nomatch2), s);
5513 5440
5514 /* If we loaded a dummy buffer into the current window, the autocommands 5441 // If we loaded a dummy buffer into the current window, the autocommands
5515 * may have messed up things, need to redraw and recompute folds. */ 5442 // may have messed up things, need to redraw and recompute folds.
5516 if (redraw_for_dummy) 5443 if (redraw_for_dummy)
5517 { 5444 {
5518 #ifdef FEAT_FOLDING 5445 #ifdef FEAT_FOLDING
5519 foldUpdateAll(curwin); 5446 foldUpdateAll(curwin);
5520 #else 5447 #else
5542 if (NULL != dirname_now) 5469 if (NULL != dirname_now)
5543 { 5470 {
5544 mch_dirname(dirname_now, MAXPATHL); 5471 mch_dirname(dirname_now, MAXPATHL);
5545 if (STRCMP(dirname_start, dirname_now) != 0) 5472 if (STRCMP(dirname_start, dirname_now) != 0)
5546 { 5473 {
5547 /* If the directory has changed, change it back by building up an 5474 // If the directory has changed, change it back by building up an
5548 * appropriate ex command and executing it. */ 5475 // appropriate ex command and executing it.
5549 exarg_T ea; 5476 exarg_T ea;
5550 5477
5551 ea.arg = dirname_start; 5478 ea.arg = dirname_start;
5552 ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd; 5479 ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd;
5553 ex_cd(&ea); 5480 ex_cd(&ea);
5569 * Returns NULL if it fails. 5496 * Returns NULL if it fails.
5570 */ 5497 */
5571 static buf_T * 5498 static buf_T *
5572 load_dummy_buffer( 5499 load_dummy_buffer(
5573 char_u *fname, 5500 char_u *fname,
5574 char_u *dirname_start, /* in: old directory */ 5501 char_u *dirname_start, // in: old directory
5575 char_u *resulting_dir) /* out: new directory */ 5502 char_u *resulting_dir) // out: new directory
5576 { 5503 {
5577 buf_T *newbuf; 5504 buf_T *newbuf;
5578 bufref_T newbufref; 5505 bufref_T newbufref;
5579 bufref_T newbuf_to_wipe; 5506 bufref_T newbuf_to_wipe;
5580 int failed = TRUE; 5507 int failed = TRUE;
5581 aco_save_T aco; 5508 aco_save_T aco;
5582 int readfile_result; 5509 int readfile_result;
5583 5510
5584 /* Allocate a buffer without putting it in the buffer list. */ 5511 // Allocate a buffer without putting it in the buffer list.
5585 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); 5512 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
5586 if (newbuf == NULL) 5513 if (newbuf == NULL)
5587 return NULL; 5514 return NULL;
5588 set_bufref(&newbufref, newbuf); 5515 set_bufref(&newbufref, newbuf);
5589 5516
5590 /* Init the options. */ 5517 // Init the options.
5591 buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP); 5518 buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP);
5592 5519
5593 /* need to open the memfile before putting the buffer in a window */ 5520 // need to open the memfile before putting the buffer in a window
5594 if (ml_open(newbuf) == OK) 5521 if (ml_open(newbuf) == OK)
5595 { 5522 {
5596 /* Make sure this buffer isn't wiped out by autocommands. */ 5523 // Make sure this buffer isn't wiped out by autocommands.
5597 ++newbuf->b_locked; 5524 ++newbuf->b_locked;
5598 5525
5599 /* set curwin/curbuf to buf and save a few things */ 5526 // set curwin/curbuf to buf and save a few things
5600 aucmd_prepbuf(&aco, newbuf); 5527 aucmd_prepbuf(&aco, newbuf);
5601 5528
5602 /* Need to set the filename for autocommands. */ 5529 // Need to set the filename for autocommands.
5603 (void)setfname(curbuf, fname, NULL, FALSE); 5530 (void)setfname(curbuf, fname, NULL, FALSE);
5604 5531
5605 /* Create swap file now to avoid the ATTENTION message. */ 5532 // Create swap file now to avoid the ATTENTION message.
5606 check_need_swap(TRUE); 5533 check_need_swap(TRUE);
5607 5534
5608 /* Remove the "dummy" flag, otherwise autocommands may not 5535 // Remove the "dummy" flag, otherwise autocommands may not
5609 * work. */ 5536 // work.
5610 curbuf->b_flags &= ~BF_DUMMY; 5537 curbuf->b_flags &= ~BF_DUMMY;
5611 5538
5612 newbuf_to_wipe.br_buf = NULL; 5539 newbuf_to_wipe.br_buf = NULL;
5613 readfile_result = readfile(fname, NULL, 5540 readfile_result = readfile(fname, NULL,
5614 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, 5541 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM,
5619 && !(curbuf->b_flags & BF_NEW)) 5546 && !(curbuf->b_flags & BF_NEW))
5620 { 5547 {
5621 failed = FALSE; 5548 failed = FALSE;
5622 if (curbuf != newbuf) 5549 if (curbuf != newbuf)
5623 { 5550 {
5624 /* Bloody autocommands changed the buffer! Can happen when 5551 // Bloody autocommands changed the buffer! Can happen when
5625 * using netrw and editing a remote file. Use the current 5552 // using netrw and editing a remote file. Use the current
5626 * buffer instead, delete the dummy one after restoring the 5553 // buffer instead, delete the dummy one after restoring the
5627 * window stuff. */ 5554 // window stuff.
5628 set_bufref(&newbuf_to_wipe, newbuf); 5555 set_bufref(&newbuf_to_wipe, newbuf);
5629 newbuf = curbuf; 5556 newbuf = curbuf;
5630 } 5557 }
5631 } 5558 }
5632 5559
5633 /* restore curwin/curbuf and a few other things */ 5560 // restore curwin/curbuf and a few other things
5634 aucmd_restbuf(&aco); 5561 aucmd_restbuf(&aco);
5635 if (newbuf_to_wipe.br_buf != NULL && bufref_valid(&newbuf_to_wipe)) 5562 if (newbuf_to_wipe.br_buf != NULL && bufref_valid(&newbuf_to_wipe))
5636 wipe_buffer(newbuf_to_wipe.br_buf, FALSE); 5563 wipe_buffer(newbuf_to_wipe.br_buf, FALSE);
5637 5564
5638 /* Add back the "dummy" flag, otherwise buflist_findname_stat() won't 5565 // Add back the "dummy" flag, otherwise buflist_findname_stat() won't
5639 * skip it. */ 5566 // skip it.
5640 newbuf->b_flags |= BF_DUMMY; 5567 newbuf->b_flags |= BF_DUMMY;
5641 } 5568 }
5642 5569
5643 /* 5570 // When autocommands/'autochdir' option changed directory: go back.
5644 * When autocommands/'autochdir' option changed directory: go back. 5571 // Let the caller know what the resulting dir was first, in case it is
5645 * Let the caller know what the resulting dir was first, in case it is 5572 // important.
5646 * important.
5647 */
5648 mch_dirname(resulting_dir, MAXPATHL); 5573 mch_dirname(resulting_dir, MAXPATHL);
5649 restore_start_dir(dirname_start); 5574 restore_start_dir(dirname_start);
5650 5575
5651 if (!bufref_valid(&newbufref)) 5576 if (!bufref_valid(&newbufref))
5652 return NULL; 5577 return NULL;
5664 * 'autochdir' option have changed it. 5589 * 'autochdir' option have changed it.
5665 */ 5590 */
5666 static void 5591 static void
5667 wipe_dummy_buffer(buf_T *buf, char_u *dirname_start) 5592 wipe_dummy_buffer(buf_T *buf, char_u *dirname_start)
5668 { 5593 {
5669 if (curbuf != buf) /* safety check */ 5594 if (curbuf != buf) // safety check
5670 { 5595 {
5671 #if defined(FEAT_EVAL) 5596 #if defined(FEAT_EVAL)
5672 cleanup_T cs; 5597 cleanup_T cs;
5673 5598
5674 /* Reset the error/interrupt/exception state here so that aborting() 5599 // Reset the error/interrupt/exception state here so that aborting()
5675 * returns FALSE when wiping out the buffer. Otherwise it doesn't 5600 // returns FALSE when wiping out the buffer. Otherwise it doesn't
5676 * work when got_int is set. */ 5601 // work when got_int is set.
5677 enter_cleanup(&cs); 5602 enter_cleanup(&cs);
5678 #endif 5603 #endif
5679 5604
5680 wipe_buffer(buf, FALSE); 5605 wipe_buffer(buf, FALSE);
5681 5606
5682 #if defined(FEAT_EVAL) 5607 #if defined(FEAT_EVAL)
5683 /* Restore the error/interrupt/exception state if not discarded by a 5608 // Restore the error/interrupt/exception state if not discarded by a
5684 * new aborting error, interrupt, or uncaught exception. */ 5609 // new aborting error, interrupt, or uncaught exception.
5685 leave_cleanup(&cs); 5610 leave_cleanup(&cs);
5686 #endif 5611 #endif
5687 /* When autocommands/'autochdir' option changed directory: go back. */ 5612 // When autocommands/'autochdir' option changed directory: go back.
5688 restore_start_dir(dirname_start); 5613 restore_start_dir(dirname_start);
5689 } 5614 }
5690 } 5615 }
5691 5616
5692 /* 5617 /*
5695 * 'autochdir' option have changed it. 5620 * 'autochdir' option have changed it.
5696 */ 5621 */
5697 static void 5622 static void
5698 unload_dummy_buffer(buf_T *buf, char_u *dirname_start) 5623 unload_dummy_buffer(buf_T *buf, char_u *dirname_start)
5699 { 5624 {
5700 if (curbuf != buf) /* safety check */ 5625 if (curbuf != buf) // safety check
5701 { 5626 {
5702 close_buffer(NULL, buf, DOBUF_UNLOAD, FALSE); 5627 close_buffer(NULL, buf, DOBUF_UNLOAD, FALSE);
5703 5628
5704 /* When autocommands/'autochdir' option changed directory: go back. */ 5629 // When autocommands/'autochdir' option changed directory: go back.
5705 restore_start_dir(dirname_start); 5630 restore_start_dir(dirname_start);
5706 } 5631 }
5707 } 5632 }
5708 5633
5709 #if defined(FEAT_EVAL) || defined(PROTO) 5634 #if defined(FEAT_EVAL) || defined(PROTO)
5739 return FAIL; 5664 return FAIL;
5740 5665
5741 qfp = qi->qf_lists[qf_idx].qf_start; 5666 qfp = qi->qf_lists[qf_idx].qf_start;
5742 for (i = 1; !got_int && i <= qi->qf_lists[qf_idx].qf_count; ++i) 5667 for (i = 1; !got_int && i <= qi->qf_lists[qf_idx].qf_count; ++i)
5743 { 5668 {
5744 /* Handle entries with a non-existing buffer number. */ 5669 // Handle entries with a non-existing buffer number.
5745 bufnum = qfp->qf_fnum; 5670 bufnum = qfp->qf_fnum;
5746 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) 5671 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL))
5747 bufnum = 0; 5672 bufnum = 0;
5748 5673
5749 if ((dict = dict_alloc()) == NULL) 5674 if ((dict = dict_alloc()) == NULL)
5770 break; 5695 break;
5771 } 5696 }
5772 return OK; 5697 return OK;
5773 } 5698 }
5774 5699
5775 /* 5700 // Flags used by getqflist()/getloclist() to determine which fields to return.
5776 * Flags used by getqflist()/getloclist() to determine which fields to return.
5777 */
5778 enum { 5701 enum {
5779 QF_GETLIST_NONE = 0x0, 5702 QF_GETLIST_NONE = 0x0,
5780 QF_GETLIST_TITLE = 0x1, 5703 QF_GETLIST_TITLE = 0x1,
5781 QF_GETLIST_ITEMS = 0x2, 5704 QF_GETLIST_ITEMS = 0x2,
5782 QF_GETLIST_NR = 0x4, 5705 QF_GETLIST_NR = 0x4,
5801 qf_info_T *qi; 5724 qf_info_T *qi;
5802 char_u *errorformat = p_efm; 5725 char_u *errorformat = p_efm;
5803 dictitem_T *efm_di; 5726 dictitem_T *efm_di;
5804 list_T *l; 5727 list_T *l;
5805 5728
5806 /* Only a List value is supported */ 5729 // Only a List value is supported
5807 if (di->di_tv.v_type == VAR_LIST && di->di_tv.vval.v_list != NULL) 5730 if (di->di_tv.v_type == VAR_LIST && di->di_tv.vval.v_list != NULL)
5808 { 5731 {
5809 /* If errorformat is supplied then use it, otherwise use the 'efm' 5732 // If errorformat is supplied then use it, otherwise use the 'efm'
5810 * option setting 5733 // option setting
5811 */
5812 if ((efm_di = dict_find(what, (char_u *)"efm", -1)) != NULL) 5734 if ((efm_di = dict_find(what, (char_u *)"efm", -1)) != NULL)
5813 { 5735 {
5814 if (efm_di->di_tv.v_type != VAR_STRING || 5736 if (efm_di->di_tv.v_type != VAR_STRING ||
5815 efm_di->di_tv.vval.v_string == NULL) 5737 efm_di->di_tv.vval.v_string == NULL)
5816 return FAIL; 5738 return FAIL;
5845 static int 5767 static int
5846 qf_winid(qf_info_T *qi) 5768 qf_winid(qf_info_T *qi)
5847 { 5769 {
5848 win_T *win; 5770 win_T *win;
5849 5771
5850 /* The quickfix window can be opened even if the quickfix list is not set 5772 // The quickfix window can be opened even if the quickfix list is not set
5851 * using ":copen". This is not true for location lists. */ 5773 // using ":copen". This is not true for location lists.
5852 if (qi == NULL) 5774 if (qi == NULL)
5853 return 0; 5775 return 0;
5854 win = qf_find_win(qi); 5776 win = qf_find_win(qi);
5855 if (win != NULL) 5777 if (win != NULL)
5856 return win->w_id; 5778 return win->w_id;
5920 qf_getprop_qfidx(qf_info_T *qi, dict_T *what) 5842 qf_getprop_qfidx(qf_info_T *qi, dict_T *what)
5921 { 5843 {
5922 int qf_idx; 5844 int qf_idx;
5923 dictitem_T *di; 5845 dictitem_T *di;
5924 5846
5925 qf_idx = qi->qf_curlist; /* default is the current list */ 5847 qf_idx = qi->qf_curlist; // default is the current list
5926 if ((di = dict_find(what, (char_u *)"nr", -1)) != NULL) 5848 if ((di = dict_find(what, (char_u *)"nr", -1)) != NULL)
5927 { 5849 {
5928 /* Use the specified quickfix/location list */ 5850 // Use the specified quickfix/location list
5929 if (di->di_tv.v_type == VAR_NUMBER) 5851 if (di->di_tv.v_type == VAR_NUMBER)
5930 { 5852 {
5931 /* for zero use the current list */ 5853 // for zero use the current list
5932 if (di->di_tv.vval.v_number != 0) 5854 if (di->di_tv.vval.v_number != 0)
5933 { 5855 {
5934 qf_idx = di->di_tv.vval.v_number - 1; 5856 qf_idx = di->di_tv.vval.v_number - 1;
5935 if (qf_idx < 0 || qf_idx >= qi->qf_listcount) 5857 if (qf_idx < 0 || qf_idx >= qi->qf_listcount)
5936 qf_idx = INVALID_QFIDX; 5858 qf_idx = INVALID_QFIDX;
5937 } 5859 }
5938 } 5860 }
5939 else if (di->di_tv.v_type == VAR_STRING 5861 else if (di->di_tv.v_type == VAR_STRING
5940 && di->di_tv.vval.v_string != NULL 5862 && di->di_tv.vval.v_string != NULL
5941 && STRCMP(di->di_tv.vval.v_string, "$") == 0) 5863 && STRCMP(di->di_tv.vval.v_string, "$") == 0)
5942 /* Get the last quickfix list number */ 5864 // Get the last quickfix list number
5943 qf_idx = qi->qf_listcount - 1; 5865 qf_idx = qi->qf_listcount - 1;
5944 else 5866 else
5945 qf_idx = INVALID_QFIDX; 5867 qf_idx = INVALID_QFIDX;
5946 } 5868 }
5947 5869
5948 if ((di = dict_find(what, (char_u *)"id", -1)) != NULL) 5870 if ((di = dict_find(what, (char_u *)"id", -1)) != NULL)
5949 { 5871 {
5950 /* Look for a list with the specified id */ 5872 // Look for a list with the specified id
5951 if (di->di_tv.v_type == VAR_NUMBER) 5873 if (di->di_tv.v_type == VAR_NUMBER)
5952 { 5874 {
5953 /* 5875 // For zero, use the current list or the list specified by 'nr'
5954 * For zero, use the current list or the list specified by 'nr'
5955 */
5956 if (di->di_tv.vval.v_number != 0) 5876 if (di->di_tv.vval.v_number != 0)
5957 qf_idx = qf_id2nr(qi, di->di_tv.vval.v_number); 5877 qf_idx = qf_id2nr(qi, di->di_tv.vval.v_number);
5958 } 5878 }
5959 else 5879 else
5960 qf_idx = INVALID_QFIDX; 5880 qf_idx = INVALID_QFIDX;
6083 static int 6003 static int
6084 qf_getprop_idx(qf_info_T *qi, int qf_idx, dict_T *retdict) 6004 qf_getprop_idx(qf_info_T *qi, int qf_idx, dict_T *retdict)
6085 { 6005 {
6086 int idx = qi->qf_lists[qf_idx].qf_index; 6006 int idx = qi->qf_lists[qf_idx].qf_index;
6087 if (qf_list_empty(qi, qf_idx)) 6007 if (qf_list_empty(qi, qf_idx))
6088 /* For empty lists, qf_index is set to 1 */ 6008 // For empty lists, qf_index is set to 1
6089 idx = 0; 6009 idx = 0;
6090 return dict_add_number(retdict, "idx", idx); 6010 return dict_add_number(retdict, "idx", idx);
6091 } 6011 }
6092 6012
6093 /* 6013 /*
6114 flags = qf_getprop_keys2flags(what, (wp != NULL)); 6034 flags = qf_getprop_keys2flags(what, (wp != NULL));
6115 6035
6116 if (!qf_stack_empty(qi)) 6036 if (!qf_stack_empty(qi))
6117 qf_idx = qf_getprop_qfidx(qi, what); 6037 qf_idx = qf_getprop_qfidx(qi, what);
6118 6038
6119 /* List is not present or is empty */ 6039 // List is not present or is empty
6120 if (qf_stack_empty(qi) || qf_idx == INVALID_QFIDX) 6040 if (qf_stack_empty(qi) || qf_idx == INVALID_QFIDX)
6121 return qf_getprop_defaults(qi, flags, retdict); 6041 return qf_getprop_defaults(qi, flags, retdict);
6122 6042
6123 qfl = &qi->qf_lists[qf_idx]; 6043 qfl = &qi->qf_lists[qf_idx];
6124 6044
6241 qfline_T *old_last = NULL; 6161 qfline_T *old_last = NULL;
6242 int retval = OK; 6162 int retval = OK;
6243 6163
6244 if (action == ' ' || qf_idx == qi->qf_listcount) 6164 if (action == ' ' || qf_idx == qi->qf_listcount)
6245 { 6165 {
6246 /* make place for a new list */ 6166 // make place for a new list
6247 qf_new_list(qi, title); 6167 qf_new_list(qi, title);
6248 qf_idx = qi->qf_curlist; 6168 qf_idx = qi->qf_curlist;
6249 qfl = &qi->qf_lists[qf_idx]; 6169 qfl = &qi->qf_lists[qf_idx];
6250 } 6170 }
6251 else if (action == 'a' && !qf_list_empty(qi, qf_idx)) 6171 else if (action == 'a' && !qf_list_empty(qi, qf_idx))
6252 /* Adding to existing list, use last entry. */ 6172 // Adding to existing list, use last entry.
6253 old_last = qfl->qf_last; 6173 old_last = qfl->qf_last;
6254 else if (action == 'r') 6174 else if (action == 'r')
6255 { 6175 {
6256 qf_free_items(qfl); 6176 qf_free_items(qfl);
6257 qf_store_title(qfl, title); 6177 qf_store_title(qfl, title);
6258 } 6178 }
6259 6179
6260 for (li = list->lv_first; li != NULL; li = li->li_next) 6180 for (li = list->lv_first; li != NULL; li = li->li_next)
6261 { 6181 {
6262 if (li->li_tv.v_type != VAR_DICT) 6182 if (li->li_tv.v_type != VAR_DICT)
6263 continue; /* Skip non-dict items */ 6183 continue; // Skip non-dict items
6264 6184
6265 d = li->li_tv.vval.v_dict; 6185 d = li->li_tv.vval.v_dict;
6266 if (d == NULL) 6186 if (d == NULL)
6267 continue; 6187 continue;
6268 6188
6270 if (retval == FAIL) 6190 if (retval == FAIL)
6271 break; 6191 break;
6272 } 6192 }
6273 6193
6274 if (qfl->qf_index == 0) 6194 if (qfl->qf_index == 0)
6275 /* no valid entry */ 6195 // no valid entry
6276 qfl->qf_nonevalid = TRUE; 6196 qfl->qf_nonevalid = TRUE;
6277 else 6197 else
6278 qfl->qf_nonevalid = FALSE; 6198 qfl->qf_nonevalid = FALSE;
6279 if (action != 'a') 6199 if (action != 'a')
6280 { 6200 {
6281 qfl->qf_ptr = qfl->qf_start; 6201 qfl->qf_ptr = qfl->qf_start;
6282 if (!qf_list_empty(qi, qf_idx)) 6202 if (!qf_list_empty(qi, qf_idx))
6283 qfl->qf_index = 1; 6203 qfl->qf_index = 1;
6284 } 6204 }
6285 6205
6286 /* Don't update the cursor in quickfix window when appending entries */ 6206 // Don't update the cursor in quickfix window when appending entries
6287 qf_update_buffer(qi, old_last); 6207 qf_update_buffer(qi, old_last);
6288 6208
6289 return retval; 6209 return retval;
6290 } 6210 }
6291 6211
6298 dict_T *what, 6218 dict_T *what,
6299 int action, 6219 int action,
6300 int *newlist) 6220 int *newlist)
6301 { 6221 {
6302 dictitem_T *di; 6222 dictitem_T *di;
6303 int qf_idx = qi->qf_curlist; /* default is the current list */ 6223 int qf_idx = qi->qf_curlist; // default is the current list
6304 6224
6305 if ((di = dict_find(what, (char_u *)"nr", -1)) != NULL) 6225 if ((di = dict_find(what, (char_u *)"nr", -1)) != NULL)
6306 { 6226 {
6307 /* Use the specified quickfix/location list */ 6227 // Use the specified quickfix/location list
6308 if (di->di_tv.v_type == VAR_NUMBER) 6228 if (di->di_tv.v_type == VAR_NUMBER)
6309 { 6229 {
6310 /* for zero use the current list */ 6230 // for zero use the current list
6311 if (di->di_tv.vval.v_number != 0) 6231 if (di->di_tv.vval.v_number != 0)
6312 qf_idx = di->di_tv.vval.v_number - 1; 6232 qf_idx = di->di_tv.vval.v_number - 1;
6313 6233
6314 if ((action == ' ' || action == 'a') && qf_idx == qi->qf_listcount) 6234 if ((action == ' ' || action == 'a') && qf_idx == qi->qf_listcount)
6315 { 6235 {
6316 /* 6236 // When creating a new list, accept qf_idx pointing to the next
6317 * When creating a new list, accept qf_idx pointing to the next 6237 // non-available list and add the new list at the end of the
6318 * non-available list and add the new list at the end of the 6238 // stack.
6319 * stack.
6320 */
6321 *newlist = TRUE; 6239 *newlist = TRUE;
6322 qf_idx = qf_stack_empty(qi) ? 0 : qi->qf_listcount - 1; 6240 qf_idx = qf_stack_empty(qi) ? 0 : qi->qf_listcount - 1;
6323 } 6241 }
6324 else if (qf_idx < 0 || qf_idx >= qi->qf_listcount) 6242 else if (qf_idx < 0 || qf_idx >= qi->qf_listcount)
6325 return INVALID_QFIDX; 6243 return INVALID_QFIDX;
6326 else if (action != ' ') 6244 else if (action != ' ')
6327 *newlist = FALSE; /* use the specified list */ 6245 *newlist = FALSE; // use the specified list
6328 } 6246 }
6329 else if (di->di_tv.v_type == VAR_STRING 6247 else if (di->di_tv.v_type == VAR_STRING
6330 && di->di_tv.vval.v_string != NULL 6248 && di->di_tv.vval.v_string != NULL
6331 && STRCMP(di->di_tv.vval.v_string, "$") == 0) 6249 && STRCMP(di->di_tv.vval.v_string, "$") == 0)
6332 { 6250 {
6341 return INVALID_QFIDX; 6259 return INVALID_QFIDX;
6342 } 6260 }
6343 6261
6344 if (!*newlist && (di = dict_find(what, (char_u *)"id", -1)) != NULL) 6262 if (!*newlist && (di = dict_find(what, (char_u *)"id", -1)) != NULL)
6345 { 6263 {
6346 /* Use the quickfix/location list with the specified id */ 6264 // Use the quickfix/location list with the specified id
6347 if (di->di_tv.v_type != VAR_NUMBER) 6265 if (di->di_tv.v_type != VAR_NUMBER)
6348 return INVALID_QFIDX; 6266 return INVALID_QFIDX;
6349 6267
6350 return qf_id2nr(qi, di->di_tv.vval.v_number); 6268 return qf_id2nr(qi, di->di_tv.vval.v_number);
6351 } 6269 }
6404 { 6322 {
6405 char_u *errorformat = p_efm; 6323 char_u *errorformat = p_efm;
6406 dictitem_T *efm_di; 6324 dictitem_T *efm_di;
6407 int retval = FAIL; 6325 int retval = FAIL;
6408 6326
6409 /* Use the user supplied errorformat settings (if present) */ 6327 // Use the user supplied errorformat settings (if present)
6410 if ((efm_di = dict_find(what, (char_u *)"efm", -1)) != NULL) 6328 if ((efm_di = dict_find(what, (char_u *)"efm", -1)) != NULL)
6411 { 6329 {
6412 if (efm_di->di_tv.v_type != VAR_STRING || 6330 if (efm_di->di_tv.v_type != VAR_STRING ||
6413 efm_di->di_tv.vval.v_string == NULL) 6331 efm_di->di_tv.vval.v_string == NULL)
6414 return FAIL; 6332 return FAIL;
6415 errorformat = efm_di->di_tv.vval.v_string; 6333 errorformat = efm_di->di_tv.vval.v_string;
6416 } 6334 }
6417 6335
6418 /* Only a List value is supported */ 6336 // Only a List value is supported
6419 if (di->di_tv.v_type != VAR_LIST || di->di_tv.vval.v_list == NULL) 6337 if (di->di_tv.v_type != VAR_LIST || di->di_tv.vval.v_list == NULL)
6420 return FAIL; 6338 return FAIL;
6421 6339
6422 if (action == 'r') 6340 if (action == 'r')
6423 qf_free_items(&qi->qf_lists[qf_idx]); 6341 qf_free_items(&qi->qf_lists[qf_idx]);
6460 6378
6461 if (action == ' ' || qf_stack_empty(qi)) 6379 if (action == ' ' || qf_stack_empty(qi))
6462 newlist = TRUE; 6380 newlist = TRUE;
6463 6381
6464 qf_idx = qf_setprop_get_qfidx(qi, what, action, &newlist); 6382 qf_idx = qf_setprop_get_qfidx(qi, what, action, &newlist);
6465 if (qf_idx == INVALID_QFIDX) /* List not found */ 6383 if (qf_idx == INVALID_QFIDX) // List not found
6466 return FAIL; 6384 return FAIL;
6467 6385
6468 if (newlist) 6386 if (newlist)
6469 { 6387 {
6470 qi->qf_curlist = qf_idx; 6388 qi->qf_curlist = qf_idx;
6514 win_T *llwin = NULL; 6432 win_T *llwin = NULL;
6515 win_T *orig_wp = wp; 6433 win_T *orig_wp = wp;
6516 6434
6517 if (qfwin != NULL) 6435 if (qfwin != NULL)
6518 { 6436 {
6519 /* If the quickfix/location list window is open, then clear it */ 6437 // If the quickfix/location list window is open, then clear it
6520 if (qi->qf_curlist < qi->qf_listcount) 6438 if (qi->qf_curlist < qi->qf_listcount)
6521 qf_free(&qi->qf_lists[qi->qf_curlist]); 6439 qf_free(&qi->qf_lists[qi->qf_curlist]);
6522 qf_update_buffer(qi, NULL); 6440 qf_update_buffer(qi, NULL);
6523 } 6441 }
6524 6442
6525 if (wp != NULL && IS_LL_WINDOW(wp)) 6443 if (wp != NULL && IS_LL_WINDOW(wp))
6526 { 6444 {
6527 /* If in the location list window, then use the non-location list 6445 // If in the location list window, then use the non-location list
6528 * window with this location list (if present) 6446 // window with this location list (if present)
6529 */
6530 llwin = find_win_with_ll(qi); 6447 llwin = find_win_with_ll(qi);
6531 if (llwin != NULL) 6448 if (llwin != NULL)
6532 wp = llwin; 6449 wp = llwin;
6533 } 6450 }
6534 6451
6535 qf_free_all(wp); 6452 qf_free_all(wp);
6536 if (wp == NULL) 6453 if (wp == NULL)
6537 { 6454 {
6538 /* quickfix list */ 6455 // quickfix list
6539 qi->qf_curlist = 0; 6456 qi->qf_curlist = 0;
6540 qi->qf_listcount = 0; 6457 qi->qf_listcount = 0;
6541 } 6458 }
6542 else if (IS_LL_WINDOW(orig_wp)) 6459 else if (IS_LL_WINDOW(orig_wp))
6543 { 6460 {
6544 /* If the location list window is open, then create a new empty 6461 // If the location list window is open, then create a new empty
6545 * location list */ 6462 // location list
6546 qf_info_T *new_ll = ll_new_list(); 6463 qf_info_T *new_ll = ll_new_list();
6547 6464
6548 /* first free the list reference in the location list window */ 6465 // first free the list reference in the location list window
6549 ll_free_all(&orig_wp->w_llist_ref); 6466 ll_free_all(&orig_wp->w_llist_ref);
6550 6467
6551 orig_wp->w_llist_ref = new_ll; 6468 orig_wp->w_llist_ref = new_ll;
6552 if (llwin != NULL) 6469 if (llwin != NULL)
6553 { 6470 {
6580 return FAIL; 6497 return FAIL;
6581 } 6498 }
6582 6499
6583 if (action == 'f') 6500 if (action == 'f')
6584 { 6501 {
6585 /* Free the entire quickfix or location list stack */ 6502 // Free the entire quickfix or location list stack
6586 qf_free_stack(wp, qi); 6503 qf_free_stack(wp, qi);
6587 } 6504 }
6588 else if (what != NULL) 6505 else if (what != NULL)
6589 retval = qf_set_properties(qi, what, action, title); 6506 retval = qf_set_properties(qi, what, action, title);
6590 else 6507 else
6641 if (abort) 6558 if (abort)
6642 return abort; 6559 return abort;
6643 } 6560 }
6644 if (IS_LL_WINDOW(win) && (win->w_llist_ref->qf_refcount == 1)) 6561 if (IS_LL_WINDOW(win) && (win->w_llist_ref->qf_refcount == 1))
6645 { 6562 {
6646 /* In a location list window and none of the other windows is 6563 // In a location list window and none of the other windows is
6647 * referring to this location list. Mark the location list 6564 // referring to this location list. Mark the location list
6648 * context as still in use. 6565 // context as still in use.
6649 */
6650 abort = mark_quickfix_ctx(win->w_llist_ref, copyID); 6566 abort = mark_quickfix_ctx(win->w_llist_ref, copyID);
6651 if (abort) 6567 if (abort)
6652 return abort; 6568 return abort;
6653 } 6569 }
6654 } 6570 }
6692 if (aborting()) 6608 if (aborting())
6693 return; 6609 return;
6694 #endif 6610 #endif
6695 } 6611 }
6696 6612
6697 /* Must come after autocommands. */ 6613 // Must come after autocommands.
6698 if (is_loclist_cmd(eap->cmdidx)) 6614 if (is_loclist_cmd(eap->cmdidx))
6699 { 6615 {
6700 qi = ll_get_or_alloc_list(curwin); 6616 qi = ll_get_or_alloc_list(curwin);
6701 if (qi == NULL) 6617 if (qi == NULL)
6702 return; 6618 return;
6805 if (qi == NULL) 6721 if (qi == NULL)
6806 return; 6722 return;
6807 wp = curwin; 6723 wp = curwin;
6808 } 6724 }
6809 6725
6810 /* Evaluate the expression. When the result is a string or a list we can 6726 // Evaluate the expression. When the result is a string or a list we can
6811 * use it to fill the errorlist. */ 6727 // use it to fill the errorlist.
6812 tv = eval_expr(eap->arg, NULL); 6728 tv = eval_expr(eap->arg, NULL);
6813 if (tv != NULL) 6729 if (tv != NULL)
6814 { 6730 {
6815 if ((tv->v_type == VAR_STRING && tv->vval.v_string != NULL) 6731 if ((tv->v_type == VAR_STRING && tv->vval.v_string != NULL)
6816 || (tv->v_type == VAR_LIST && tv->vval.v_list != NULL)) 6732 || (tv->v_type == VAR_LIST && tv->vval.v_list != NULL))
6852 hgr_get_ll(int *new_ll) 6768 hgr_get_ll(int *new_ll)
6853 { 6769 {
6854 win_T *wp; 6770 win_T *wp;
6855 qf_info_T *qi; 6771 qf_info_T *qi;
6856 6772
6857 /* If the current window is a help window, then use it */ 6773 // If the current window is a help window, then use it
6858 if (bt_help(curwin->w_buffer)) 6774 if (bt_help(curwin->w_buffer))
6859 wp = curwin; 6775 wp = curwin;
6860 else 6776 else
6861 /* Find an existing help window */ 6777 // Find an existing help window
6862 wp = qf_find_help_win(); 6778 wp = qf_find_help_win();
6863 6779
6864 if (wp == NULL) /* Help window not found */ 6780 if (wp == NULL) // Help window not found
6865 qi = NULL; 6781 qi = NULL;
6866 else 6782 else
6867 qi = wp->w_llist; 6783 qi = wp->w_llist;
6868 6784
6869 if (qi == NULL) 6785 if (qi == NULL)
6870 { 6786 {
6871 /* Allocate a new location list for help text matches */ 6787 // Allocate a new location list for help text matches
6872 if ((qi = ll_new_list()) == NULL) 6788 if ((qi = ll_new_list()) == NULL)
6873 return NULL; 6789 return NULL;
6874 *new_ll = TRUE; 6790 *new_ll = TRUE;
6875 } 6791 }
6876 6792
6899 lnum = 1; 6815 lnum = 1;
6900 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) 6816 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int)
6901 { 6817 {
6902 char_u *line = IObuff; 6818 char_u *line = IObuff;
6903 #ifdef FEAT_MBYTE 6819 #ifdef FEAT_MBYTE
6904 /* Convert a line if 'encoding' is not utf-8 and 6820 // Convert a line if 'encoding' is not utf-8 and
6905 * the line contains a non-ASCII character. */ 6821 // the line contains a non-ASCII character.
6906 if (p_vc->vc_type != CONV_NONE 6822 if (p_vc->vc_type != CONV_NONE
6907 && has_non_ascii(IObuff)) 6823 && has_non_ascii(IObuff))
6908 { 6824 {
6909 line = string_convert(p_vc, IObuff, NULL); 6825 line = string_convert(p_vc, IObuff, NULL);
6910 if (line == NULL) 6826 if (line == NULL)
6914 6830
6915 if (vim_regexec(p_regmatch, line, (colnr_T)0)) 6831 if (vim_regexec(p_regmatch, line, (colnr_T)0))
6916 { 6832 {
6917 int l = (int)STRLEN(line); 6833 int l = (int)STRLEN(line);
6918 6834
6919 /* remove trailing CR, LF, spaces, etc. */ 6835 // remove trailing CR, LF, spaces, etc.
6920 while (l > 0 && line[l - 1] <= ' ') 6836 while (l > 0 && line[l - 1] <= ' ')
6921 line[--l] = NUL; 6837 line[--l] = NUL;
6922 6838
6923 if (qf_add_entry(qi, 6839 if (qf_add_entry(qi,
6924 qi->qf_curlist, 6840 qi->qf_curlist,
6925 NULL, /* dir */ 6841 NULL, // dir
6926 fname, 6842 fname,
6927 NULL, 6843 NULL,
6928 0, 6844 0,
6929 line, 6845 line,
6930 lnum, 6846 lnum,
6931 (int)(p_regmatch->startp[0] - line) 6847 (int)(p_regmatch->startp[0] - line)
6932 + 1, /* col */ 6848 + 1, // col
6933 FALSE, /* vis_col */ 6849 FALSE, // vis_col
6934 NULL, /* search pattern */ 6850 NULL, // search pattern
6935 0, /* nr */ 6851 0, // nr
6936 1, /* type */ 6852 1, // type
6937 TRUE /* valid */ 6853 TRUE // valid
6938 ) == FAIL) 6854 ) == FAIL)
6939 { 6855 {
6940 got_int = TRUE; 6856 got_int = TRUE;
6941 #ifdef FEAT_MBYTE 6857 #ifdef FEAT_MBYTE
6942 if (line != IObuff) 6858 if (line != IObuff)
6974 { 6890 {
6975 int fcount; 6891 int fcount;
6976 char_u **fnames; 6892 char_u **fnames;
6977 int fi; 6893 int fi;
6978 6894
6979 /* Find all "*.txt" and "*.??x" files in the "doc" directory. */ 6895 // Find all "*.txt" and "*.??x" files in the "doc" directory.
6980 add_pathsep(dirname); 6896 add_pathsep(dirname);
6981 STRCAT(dirname, "doc/*.\\(txt\\|??x\\)"); 6897 STRCAT(dirname, "doc/*.\\(txt\\|??x\\)");
6982 if (gen_expand_wildcards(1, &dirname, &fcount, 6898 if (gen_expand_wildcards(1, &dirname, &fcount,
6983 &fnames, EW_FILE|EW_SILENT) == OK 6899 &fnames, EW_FILE|EW_SILENT) == OK
6984 && fcount > 0) 6900 && fcount > 0)
6985 { 6901 {
6986 for (fi = 0; fi < fcount && !got_int; ++fi) 6902 for (fi = 0; fi < fcount && !got_int; ++fi)
6987 { 6903 {
6988 #ifdef FEAT_MULTI_LANG 6904 #ifdef FEAT_MULTI_LANG
6989 /* Skip files for a different language. */ 6905 // Skip files for a different language.
6990 if (lang != NULL 6906 if (lang != NULL
6991 && STRNICMP(lang, fnames[fi] 6907 && STRNICMP(lang, fnames[fi]
6992 + STRLEN(fnames[fi]) - 3, 2) != 0 6908 + STRLEN(fnames[fi]) - 3, 2) != 0
6993 && !(STRNICMP(lang, "en", 2) == 0 6909 && !(STRNICMP(lang, "en", 2) == 0
6994 && STRNICMP("txt", fnames[fi] 6910 && STRNICMP("txt", fnames[fi]
7018 char_u *p; 6934 char_u *p;
7019 6935
7020 #ifdef FEAT_MBYTE 6936 #ifdef FEAT_MBYTE
7021 vimconv_T vc; 6937 vimconv_T vc;
7022 6938
7023 /* Help files are in utf-8 or latin1, convert lines when 'encoding' 6939 // Help files are in utf-8 or latin1, convert lines when 'encoding'
7024 * differs. */ 6940 // differs.
7025 vc.vc_type = CONV_NONE; 6941 vc.vc_type = CONV_NONE;
7026 if (!enc_utf8) 6942 if (!enc_utf8)
7027 convert_setup(&vc, (char_u *)"utf-8", p_enc); 6943 convert_setup(&vc, (char_u *)"utf-8", p_enc);
7028 #endif 6944 #endif
7029 6945
7030 6946
7031 /* Go through all the directories in 'runtimepath' */ 6947 // Go through all the directories in 'runtimepath'
7032 p = p_rtp; 6948 p = p_rtp;
7033 while (*p != NUL && !got_int) 6949 while (*p != NUL && !got_int)
7034 { 6950 {
7035 copy_option_part(&p, NameBuff, MAXPATHL, ","); 6951 copy_option_part(&p, NameBuff, MAXPATHL, ",");
7036 6952
7122 if (au_name != NULL) 7038 if (au_name != NULL)
7123 { 7039 {
7124 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, 7040 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
7125 curbuf->b_fname, TRUE, curbuf); 7041 curbuf->b_fname, TRUE, curbuf);
7126 if (!new_qi && IS_LL_STACK(qi) && qf_find_buf(qi) == NULL) 7042 if (!new_qi && IS_LL_STACK(qi) && qf_find_buf(qi) == NULL)
7127 /* autocommands made "qi" invalid */ 7043 // autocommands made "qi" invalid
7128 return; 7044 return;
7129 } 7045 }
7130 7046
7131 /* Jump to first match. */ 7047 // Jump to first match.
7132 if (!qf_list_empty(qi, qi->qf_curlist)) 7048 if (!qf_list_empty(qi, qi->qf_curlist))
7133 qf_jump(qi, 0, 0, FALSE); 7049 qf_jump(qi, 0, 0, FALSE);
7134 else 7050 else
7135 EMSG2(_(e_nomatch2), eap->arg); 7051 EMSG2(_(e_nomatch2), eap->arg);
7136 7052