1 /* vi:set ts=8 sts=4 sw=4: 2 * 3 * VIM - Vi IMproved by Bram Moolenaar 4 * 5 * Do ":help uganda" in Vim to read copying and usage conditions. 6 * Do ":help credits" in Vim to see a list of people who contributed. 7 * See README.txt for an overview of the Vim source code. 8 */ 9 10 /* 11 * quickfix.c: functions for quickfix mode, using a file with error messages 12 */ 13 14 #include "vim.h" 15 16 #if defined(FEAT_QUICKFIX) || defined(PROTO) 17 18 struct dir_stack_T 19 { 20 struct dir_stack_T *next; 21 char_u *dirname; 22 }; 23 24 static struct dir_stack_T *dir_stack = NULL; 25 26 /* 27 * for each error the next struct is allocated and linked in a list 28 */ 29 struct qf_line 30 { 31 struct qf_line *qf_next; /* pointer to next error in the list */ 32 struct qf_line *qf_prev; /* pointer to previous error in the list */ 33 linenr_T qf_lnum; /* line number where the error occurred */ 34 int qf_fnum; /* file number for the line */ 35 int qf_col; /* column where the error occurred */ 36 int qf_nr; /* error number */ 37 char_u *qf_text; /* description of the error */ 38 char_u qf_viscol; /* set to TRUE if qf_col is screen column */ 39 char_u qf_cleared;/* set to TRUE if line has been deleted */ 40 char_u qf_type; /* type of the error (mostly 'E'); 1 for 41 :helpgrep */ 42 char_u qf_valid; /* valid error message detected */ 43 }; 44 45 /* 46 * There is a stack of error lists. 47 */ 48 #define LISTCOUNT 10 49 50 struct qf_list 51 { 52 struct qf_line *qf_start; /* pointer to the first error */ 53 struct qf_line *qf_ptr; /* pointer to the current error */ 54 int qf_count; /* number of errors (0 means no error list) */ 55 int qf_index; /* current index in the error list */ 56 int qf_nonevalid; /* TRUE if not a single valid entry found */ 57 } qf_lists[LISTCOUNT]; 58 59 static int qf_curlist = 0; /* current error list */ 60 static int qf_listcount = 0; /* current number of lists */ 61 62 #define FMT_PATTERNS 9 /* maximum number of % recognized */ 63 64 /* 65 * Structure used to hold the info of one part of 'errorformat' 66 */ 67 struct eformat 68 { 69 regprog_T *prog; /* pre-formatted part of 'errorformat' */ 70 struct eformat *next; /* pointer to next (NULL if last) */ 71 char_u addr[FMT_PATTERNS]; /* indices of used % patterns */ 72 char_u prefix; /* prefix of this format line: */ 73 /* 'D' enter directory */ 74 /* 'X' leave directory */ 75 /* 'A' start of multi-line message */ 76 /* 'E' error message */ 77 /* 'W' warning message */ 78 /* 'I' informational message */ 79 /* 'C' continuation line */ 80 /* 'Z' end of multi-line message */ 81 /* 'G' general, unspecific message */ 82 /* 'P' push file (partial) message */ 83 /* 'Q' pop/quit file (partial) message */ 84 /* 'O' overread (partial) message */ 85 char_u flags; /* additional flags given in prefix */ 86 /* '-' do not include this line */ 87 }; 88 89 static int qf_init_ext __ARGS((char_u *efile, buf_T *buf, char_u *errorformat, int newlist, linenr_T lnumfirst, linenr_T lnumlast)); 90 static void qf_new_list __ARGS((void)); 91 static int qf_add_entry __ARGS((struct qf_line **prevp, char_u *dir, char_u *fname, char_u *mesg, long lnum, int col, int vis_col, int nr, int type, int valid)); 92 static void qf_msg __ARGS((void)); 93 static void qf_free __ARGS((int idx)); 94 static char_u *qf_types __ARGS((int, int)); 95 static int qf_get_fnum __ARGS((char_u *, char_u *)); 96 static char_u *qf_push_dir __ARGS((char_u *, struct dir_stack_T **)); 97 static char_u *qf_pop_dir __ARGS((struct dir_stack_T **)); 98 static char_u *qf_guess_filepath __ARGS((char_u *)); 99 static void qf_fmt_text __ARGS((char_u *text, char_u *buf, int bufsize)); 100 static void qf_clean_dir_stack __ARGS((struct dir_stack_T **)); 101 #ifdef FEAT_WINDOWS 102 static int qf_win_pos_update __ARGS((int old_qf_index)); 103 static buf_T *qf_find_buf __ARGS((void)); 104 static void qf_update_buffer __ARGS((void)); 105 static void qf_fill_buffer __ARGS((void)); 106 #endif 107 static char_u *get_mef_name __ARGS((void)); 108 static buf_T *load_dummy_buffer __ARGS((char_u *fname)); 109 static void wipe_dummy_buffer __ARGS((buf_T *buf)); 110 static void unload_dummy_buffer __ARGS((buf_T *buf)); 111 112 /* 113 * Read the errorfile "efile" into memory, line by line, building the error 114 * list. 115 * Return -1 for error, number of errors for success. 116 */ 117 int 118 qf_init(efile, errorformat, newlist) 119 char_u *efile; 120 char_u *errorformat; 121 int newlist; /* TRUE: start a new error list */ 122 { 123 if (efile == NULL) 124 return FAIL; 125 return qf_init_ext(efile, curbuf, errorformat, newlist, 126 (linenr_T)0, (linenr_T)0); 127 } 128 129 /* 130 * Read the errorfile "efile" into memory, line by line, building the error 131 * list. 132 * Alternative: when "efile" is null read errors from buffer "buf". 133 * Always use 'errorformat' from "buf" if there is a local value. 134 * Then lnumfirst and lnumlast specify the range of lines to use. 135 * Return -1 for error, number of errors for success. 136 */ 137 static int 138 qf_init_ext(efile, buf, errorformat, newlist, lnumfirst, lnumlast) 139 char_u *efile; 140 buf_T *buf; 141 char_u *errorformat; 142 int newlist; /* TRUE: start a new error list */ 143 linenr_T lnumfirst; /* first line number to use */ 144 linenr_T lnumlast; /* last line number to use */ 145 { 146 char_u *namebuf; 147 char_u *errmsg; 148 char_u *fmtstr = NULL; 149 int col = 0; 150 char_u use_viscol = FALSE; 151 int type = 0; 152 int valid; 153 linenr_T buflnum = lnumfirst; 154 long lnum = 0L; 155 int enr = 0; 156 FILE *fd = NULL; 157 struct qf_line *qfprev = NULL; /* init to make SASC shut up */ 158 char_u *efmp; 159 struct eformat *fmt_first = NULL; 160 struct eformat *fmt_last = NULL; 161 struct eformat *fmt_ptr; 162 char_u *efm; 163 char_u *ptr; 164 char_u *srcptr; 165 int len; 166 int i; 167 int round; 168 int idx = 0; 169 int multiline = FALSE; 170 int multiignore = FALSE; 171 int multiscan = FALSE; 172 int retval = -1; /* default: return error flag */ 173 char_u *directory = NULL; 174 char_u *currfile = NULL; 175 char_u *tail = NULL; 176 struct dir_stack_T *file_stack = NULL; 177 regmatch_T regmatch; 178 static struct fmtpattern 179 { 180 char_u convchar; 181 char *pattern; 182 } fmt_pat[FMT_PATTERNS] = 183 { 184 {'f', "\\f\\+"}, 185 {'n', "\\d\\+"}, 186 {'l', "\\d\\+"}, 187 {'c', "\\d\\+"}, 188 {'t', "."}, 189 {'m', ".\\+"}, 190 {'r', ".*"}, 191 {'p', "[- .]*"}, 192 {'v', "\\d\\+"} 193 }; 194 195 namebuf = alloc(CMDBUFFSIZE + 1); 196 errmsg = alloc(CMDBUFFSIZE + 1); 197 if (namebuf == NULL || errmsg == NULL) 198 goto qf_init_end; 199 200 if (efile != NULL && (fd = mch_fopen((char *)efile, "r")) == NULL) 201 { 202 EMSG2(_(e_openerrf), efile); 203 goto qf_init_end; 204 } 205 206 if (newlist || qf_curlist == qf_listcount) 207 /* make place for a new list */ 208 qf_new_list(); 209 else if (qf_lists[qf_curlist].qf_count > 0) 210 /* Adding to existing list, find last entry. */ 211 for (qfprev = qf_lists[qf_curlist].qf_start; 212 qfprev->qf_next != qfprev; qfprev = qfprev->qf_next) 213 ; 214 215 /* 216 * Each part of the format string is copied and modified from errorformat to 217 * regex prog. Only a few % characters are allowed. 218 */ 219 /* Use the local value of 'errorformat' if it's set. */ 220 if (errorformat == p_efm && *buf->b_p_efm != NUL) 221 efm = buf->b_p_efm; 222 else 223 efm = errorformat; 224 /* 225 * Get some space to modify the format string into. 226 */ 227 i = (FMT_PATTERNS * 3) + ((int)STRLEN(efm) << 2); 228 for (round = FMT_PATTERNS; round > 0; ) 229 i += (int)STRLEN(fmt_pat[--round].pattern); 230 #ifdef COLON_IN_FILENAME 231 i += 12; /* "%f" can become twelve chars longer */ 232 #else 233 i += 2; /* "%f" can become two chars longer */ 234 #endif 235 if ((fmtstr = alloc(i)) == NULL) 236 goto error2; 237 238 while (efm[0]) 239 { 240 /* 241 * Allocate a new eformat structure and put it at the end of the list 242 */ 243 fmt_ptr = (struct eformat *)alloc((unsigned)sizeof(struct eformat)); 244 if (fmt_ptr == NULL) 245 goto error2; 246 if (fmt_first == NULL) /* first one */ 247 fmt_first = fmt_ptr; 248 else 249 fmt_last->next = fmt_ptr; 250 fmt_last = fmt_ptr; 251 fmt_ptr->prefix = NUL; 252 fmt_ptr->flags = NUL; 253 fmt_ptr->next = NULL; 254 fmt_ptr->prog = NULL; 255 for (round = FMT_PATTERNS; round > 0; ) 256 fmt_ptr->addr[--round] = NUL; 257 /* round is 0 now */ 258 259 /* 260 * Isolate one part in the 'errorformat' option 261 */ 262 for (len = 0; efm[len] != NUL && efm[len] != ','; ++len) 263 if (efm[len] == '\\' && efm[len + 1] != NUL) 264 ++len; 265 266 /* 267 * Build regexp pattern from current 'errorformat' option 268 */ 269 ptr = fmtstr; 270 *ptr++ = '^'; 271 for (efmp = efm; efmp < efm + len; ++efmp) 272 { 273 if (*efmp == '%') 274 { 275 ++efmp; 276 for (idx = 0; idx < FMT_PATTERNS; ++idx) 277 if (fmt_pat[idx].convchar == *efmp) 278 break; 279 if (idx < FMT_PATTERNS) 280 { 281 if (fmt_ptr->addr[idx]) 282 { 283 sprintf((char *)errmsg, 284 _("E372: Too many %%%c in format string"), *efmp); 285 EMSG(errmsg); 286 goto error2; 287 } 288 if ((idx 289 && idx < 6 290 && vim_strchr((char_u *)"DXOPQ", 291 fmt_ptr->prefix) != NULL) 292 || (idx == 6 293 && vim_strchr((char_u *)"OPQ", 294 fmt_ptr->prefix) == NULL)) 295 { 296 sprintf((char *)errmsg, 297 _("E373: Unexpected %%%c in format string"), *efmp); 298 EMSG(errmsg); 299 goto error2; 300 } 301 fmt_ptr->addr[idx] = (char_u)++round; 302 *ptr++ = '\\'; 303 *ptr++ = '('; 304 #ifdef BACKSLASH_IN_FILENAME 305 if (*efmp == 'f') 306 { 307 /* Also match "c:" in the file name, even when 308 * checking for a colon next: "%f:". 309 * "\%(\a:\)\=" */ 310 STRCPY(ptr, "\\%(\\a:\\)\\="); 311 ptr += 10; 312 } 313 #endif 314 if (*efmp == 'f' && efmp[1] != NUL 315 && efmp[1] != '\\' && efmp[1] != '%') 316 { 317 /* A file name may contain spaces, but this isn't in 318 * "\f". use "[^x]\+" instead (x is next character) */ 319 *ptr++ = '['; 320 *ptr++ = '^'; 321 *ptr++ = efmp[1]; 322 *ptr++ = ']'; 323 *ptr++ = '\\'; 324 *ptr++ = '+'; 325 } 326 else 327 { 328 srcptr = (char_u *)fmt_pat[idx].pattern; 329 while ((*ptr = *srcptr++) != NUL) 330 ++ptr; 331 } 332 *ptr++ = '\\'; 333 *ptr++ = ')'; 334 } 335 else if (*efmp == '*') 336 { 337 if (*++efmp == '[' || *efmp == '\\') 338 { 339 if ((*ptr++ = *efmp) == '[') /* %*[^a-z0-9] etc. */ 340 { 341 if (efmp[1] == '^') 342 *ptr++ = *++efmp; 343 if (efmp < efm + len) 344 { 345 *ptr++ = *++efmp; /* could be ']' */ 346 while (efmp < efm + len 347 && (*ptr++ = *++efmp) != ']') 348 /* skip */; 349 if (efmp == efm + len) 350 { 351 EMSG(_("E374: Missing ] in format string")); 352 goto error2; 353 } 354 } 355 } 356 else if (efmp < efm + len) /* %*\D, %*\s etc. */ 357 *ptr++ = *++efmp; 358 *ptr++ = '\\'; 359 *ptr++ = '+'; 360 } 361 else 362 { 363 /* TODO: scanf()-like: %*ud, %*3c, %*f, ... ? */ 364 sprintf((char *)errmsg, 365 _("E375: Unsupported %%%c in format string"), *efmp); 366 EMSG(errmsg); 367 goto error2; 368 } 369 } 370 else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL) 371 *ptr++ = *efmp; /* regexp magic characters */ 372 else if (*efmp == '#') 373 *ptr++ = '*'; 374 else if (efmp == efm + 1) /* analyse prefix */ 375 { 376 if (vim_strchr((char_u *)"+-", *efmp) != NULL) 377 fmt_ptr->flags = *efmp++; 378 if (vim_strchr((char_u *)"DXAEWICZGOPQ", *efmp) != NULL) 379 fmt_ptr->prefix = *efmp; 380 else 381 { 382 sprintf((char *)errmsg, 383 _("E376: Invalid %%%c in format string prefix"), *efmp); 384 EMSG(errmsg); 385 goto error2; 386 } 387 } 388 else 389 { 390 sprintf((char *)errmsg, 391 _("E377: Invalid %%%c in format string"), *efmp); 392 EMSG(errmsg); 393 goto error2; 394 } 395 } 396 else /* copy normal character */ 397 { 398 if (*efmp == '\\' && efmp + 1 < efm + len) 399 ++efmp; 400 else if (vim_strchr((char_u *)".*^$~[", *efmp) != NULL) 401 *ptr++ = '\\'; /* escape regexp atoms */ 402 if (*efmp) 403 *ptr++ = *efmp; 404 } 405 } 406 *ptr++ = '$'; 407 *ptr = NUL; 408 if ((fmt_ptr->prog = vim_regcomp(fmtstr, RE_MAGIC + RE_STRING)) == NULL) 409 goto error2; 410 /* 411 * Advance to next part 412 */ 413 efm = skip_to_option_part(efm + len); /* skip comma and spaces */ 414 } 415 if (fmt_first == NULL) /* nothing found */ 416 { 417 EMSG(_("E378: 'errorformat' contains no pattern")); 418 goto error2; 419 } 420 421 /* 422 * got_int is reset here, because it was probably set when killing the 423 * ":make" command, but we still want to read the errorfile then. 424 */ 425 got_int = FALSE; 426 427 /* Always ignore case when looking for a matching error. */ 428 regmatch.rm_ic = TRUE; 429 430 /* 431 * Read the lines in the error file one by one. 432 * Try to recognize one of the error formats in each line. 433 */ 434 while (!got_int) 435 { 436 /* Get the next line. */ 437 if (fd == NULL) 438 { 439 if (buflnum > lnumlast) 440 break; 441 STRNCPY(IObuff, ml_get_buf(buf, buflnum++, FALSE), CMDBUFFSIZE - 2); 442 } 443 else if (fgets((char *)IObuff, CMDBUFFSIZE - 2, fd) == NULL) 444 break; 445 446 IObuff[CMDBUFFSIZE - 2] = NUL; /* for very long lines */ 447 if ((efmp = vim_strrchr(IObuff, '\n')) != NULL) 448 *efmp = NUL; 449 #ifdef USE_CRNL 450 if ((efmp = vim_strrchr(IObuff, '\r')) != NULL) 451 *efmp = NUL; 452 #endif 453 454 /* 455 * Try to match each part of 'errorformat' until we find a complete 456 * match or no match. 457 */ 458 valid = TRUE; 459 restofline: 460 for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next) 461 { 462 idx = fmt_ptr->prefix; 463 if (multiscan && vim_strchr((char_u *)"OPQ", idx) == NULL) 464 continue; 465 namebuf[0] = NUL; 466 if (!multiscan) 467 errmsg[0] = NUL; 468 lnum = 0; 469 col = 0; 470 use_viscol = FALSE; 471 enr = -1; 472 type = 0; 473 tail = NULL; 474 475 regmatch.regprog = fmt_ptr->prog; 476 if (vim_regexec(®match, IObuff, (colnr_T)0)) 477 { 478 if ((idx == 'C' || idx == 'Z') && !multiline) 479 continue; 480 if (vim_strchr((char_u *)"EWI", idx) != NULL) 481 type = idx; 482 else 483 type = 0; 484 /* 485 * Extract error message data from matched line 486 */ 487 if ((i = (int)fmt_ptr->addr[0]) > 0) /* %f */ 488 { 489 len = (int)(regmatch.endp[i] - regmatch.startp[i]); 490 STRNCPY(namebuf, regmatch.startp[i], len); 491 namebuf[len] = NUL; 492 if (vim_strchr((char_u *)"OPQ", idx) != NULL 493 && mch_getperm(namebuf) == -1) 494 continue; 495 } 496 if ((i = (int)fmt_ptr->addr[1]) > 0) /* %n */ 497 enr = (int)atol((char *)regmatch.startp[i]); 498 if ((i = (int)fmt_ptr->addr[2]) > 0) /* %l */ 499 lnum = atol((char *)regmatch.startp[i]); 500 if ((i = (int)fmt_ptr->addr[3]) > 0) /* %c */ 501 col = (int)atol((char *)regmatch.startp[i]); 502 if ((i = (int)fmt_ptr->addr[4]) > 0) /* %t */ 503 type = *regmatch.startp[i]; 504 if (fmt_ptr->flags == '+' && !multiscan) /* %+ */ 505 STRCPY(errmsg, IObuff); 506 else if ((i = (int)fmt_ptr->addr[5]) > 0) /* %m */ 507 { 508 len = (int)(regmatch.endp[i] - regmatch.startp[i]); 509 STRNCPY(errmsg, regmatch.startp[i], len); 510 errmsg[len] = NUL; 511 } 512 if ((i = (int)fmt_ptr->addr[6]) > 0) /* %r */ 513 tail = regmatch.startp[i]; 514 if ((i = (int)fmt_ptr->addr[7]) > 0) /* %p */ 515 { 516 col = (int)(regmatch.endp[i] - regmatch.startp[i] + 1); 517 if (*((char_u *)regmatch.startp[i]) != TAB) 518 use_viscol = TRUE; 519 } 520 if ((i = (int)fmt_ptr->addr[8]) > 0) /* %v */ 521 { 522 col = (int)atol((char *)regmatch.startp[i]); 523 use_viscol = TRUE; 524 } 525 break; 526 } 527 } 528 multiscan = FALSE; 529 if (!fmt_ptr || idx == 'D' || idx == 'X') 530 { 531 if (fmt_ptr) 532 { 533 if (idx == 'D') /* enter directory */ 534 { 535 if (*namebuf == NUL) 536 { 537 EMSG(_("E379: Missing or empty directory name")); 538 goto error2; 539 } 540 if ((directory = qf_push_dir(namebuf, &dir_stack)) == NULL) 541 goto error2; 542 } 543 else if (idx == 'X') /* leave directory */ 544 directory = qf_pop_dir(&dir_stack); 545 } 546 namebuf[0] = NUL; /* no match found, remove file name */ 547 lnum = 0; /* don't jump to this line */ 548 valid = FALSE; 549 STRCPY(errmsg, IObuff); /* copy whole line to error message */ 550 if (!fmt_ptr) 551 multiline = multiignore = FALSE; 552 } 553 else if (fmt_ptr) 554 { 555 if (vim_strchr((char_u *)"AEWI", idx) != NULL) 556 multiline = TRUE; /* start of a multi-line message */ 557 else if (vim_strchr((char_u *)"CZ", idx) != NULL) 558 { /* continuation of multi-line msg */ 559 if (qfprev == NULL) 560 goto error2; 561 if (*errmsg && !multiignore) 562 { 563 len = (int)STRLEN(qfprev->qf_text); 564 if ((ptr = alloc((unsigned)(len + STRLEN(errmsg) + 2))) 565 == NULL) 566 goto error2; 567 STRCPY(ptr, qfprev->qf_text); 568 vim_free(qfprev->qf_text); 569 qfprev->qf_text = ptr; 570 *(ptr += len) = '\n'; 571 STRCPY(++ptr, errmsg); 572 } 573 if (qfprev->qf_nr == -1) 574 qfprev->qf_nr = enr; 575 if (vim_isprintc(type) && !qfprev->qf_type) 576 qfprev->qf_type = type; /* only printable chars allowed */ 577 if (!qfprev->qf_lnum) 578 qfprev->qf_lnum = lnum; 579 if (!qfprev->qf_col) 580 qfprev->qf_col = col; 581 qfprev->qf_viscol = use_viscol; 582 if (!qfprev->qf_fnum) 583 qfprev->qf_fnum = qf_get_fnum(directory, 584 *namebuf || directory ? namebuf 585 : currfile && valid ? currfile : 0); 586 if (idx == 'Z') 587 multiline = multiignore = FALSE; 588 line_breakcheck(); 589 continue; 590 } 591 else if (vim_strchr((char_u *)"OPQ", idx) != NULL) 592 { 593 /* global file names */ 594 valid = FALSE; 595 if (*namebuf == NUL || mch_getperm(namebuf) >= 0) 596 { 597 if (*namebuf && idx == 'P') 598 currfile = qf_push_dir(namebuf, &file_stack); 599 else if (idx == 'Q') 600 currfile = qf_pop_dir(&file_stack); 601 *namebuf = NUL; 602 if (tail && *tail) 603 { 604 STRCPY(IObuff, skipwhite(tail)); 605 multiscan = TRUE; 606 goto restofline; 607 } 608 } 609 } 610 if (fmt_ptr->flags == '-') /* generally exclude this line */ 611 { 612 if (multiline) 613 multiignore = TRUE; /* also exclude continuation lines */ 614 continue; 615 } 616 } 617 618 if (qf_add_entry(&qfprev, 619 directory, 620 (*namebuf || directory) 621 ? namebuf 622 : ((currfile && valid) ? currfile : (char_u *)NULL), 623 errmsg, 624 lnum, 625 col, 626 use_viscol, 627 enr, 628 type, 629 valid) == FAIL) 630 goto error2; 631 line_breakcheck(); 632 } 633 if (fd == NULL || !ferror(fd)) 634 { 635 if (qf_lists[qf_curlist].qf_index == 0) /* no valid entry found */ 636 { 637 qf_lists[qf_curlist].qf_ptr = qf_lists[qf_curlist].qf_start; 638 qf_lists[qf_curlist].qf_index = 1; 639 qf_lists[qf_curlist].qf_nonevalid = TRUE; 640 } 641 else 642 { 643 qf_lists[qf_curlist].qf_nonevalid = FALSE; 644 if (qf_lists[qf_curlist].qf_ptr == NULL) 645 qf_lists[qf_curlist].qf_ptr = qf_lists[qf_curlist].qf_start; 646 } 647 retval = qf_lists[qf_curlist].qf_count; /* return number of matches */ 648 goto qf_init_ok; 649 } 650 EMSG(_(e_readerrf)); 651 error2: 652 qf_free(qf_curlist); 653 qf_listcount--; 654 if (qf_curlist > 0) 655 --qf_curlist; 656 qf_init_ok: 657 if (fd != NULL) 658 fclose(fd); 659 for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_first) 660 { 661 fmt_first = fmt_ptr->next; 662 vim_free(fmt_ptr->prog); 663 vim_free(fmt_ptr); 664 } 665 qf_clean_dir_stack(&dir_stack); 666 qf_clean_dir_stack(&file_stack); 667 qf_init_end: 668 vim_free(namebuf); 669 vim_free(errmsg); 670 vim_free(fmtstr); 671 672 #ifdef FEAT_WINDOWS 673 qf_update_buffer(); 674 #endif 675 676 return retval; 677 } 678 679 /* 680 * Prepare for adding a new quickfix list. 681 */ 682 static void 683 qf_new_list() 684 { 685 int i; 686 687 /* 688 * If the current entry is not the last entry, delete entries below 689 * the current entry. This makes it possible to browse in a tree-like 690 * way with ":grep'. 691 */ 692 while (qf_listcount > qf_curlist + 1) 693 qf_free(--qf_listcount); 694 695 /* 696 * When the stack is full, remove to oldest entry 697 * Otherwise, add a new entry. 698 */ 699 if (qf_listcount == LISTCOUNT) 700 { 701 qf_free(0); 702 for (i = 1; i < LISTCOUNT; ++i) 703 qf_lists[i - 1] = qf_lists[i]; 704 qf_curlist = LISTCOUNT - 1; 705 } 706 else 707 qf_curlist = qf_listcount++; 708 qf_lists[qf_curlist].qf_index = 0; 709 qf_lists[qf_curlist].qf_count = 0; 710 } 711 712 /* 713 * Add an entry to the end of the list of errors. 714 * Returns OK or FAIL. 715 */ 716 static int 717 qf_add_entry(prevp, dir, fname, mesg, lnum, col, vis_col, nr, type, valid) 718 struct qf_line **prevp; /* pointer to previously added entry or NULL */ 719 char_u *dir; /* optional directory name */ 720 char_u *fname; /* file name or NULL */ 721 char_u *mesg; /* message */ 722 long lnum; /* line number */ 723 int col; /* column */ 724 int vis_col; /* using visual column */ 725 int nr; /* error number */ 726 int type; /* type character */ 727 int valid; /* valid entry */ 728 { 729 struct qf_line *qfp; 730 731 if ((qfp = (struct qf_line *)alloc((unsigned)sizeof(struct qf_line))) 732 == NULL) 733 return FAIL; 734 qfp->qf_fnum = qf_get_fnum(dir, fname); 735 if ((qfp->qf_text = vim_strsave(mesg)) == NULL) 736 { 737 vim_free(qfp); 738 return FAIL; 739 } 740 qfp->qf_lnum = lnum; 741 qfp->qf_col = col; 742 qfp->qf_viscol = vis_col; 743 qfp->qf_nr = nr; 744 if (type != 1 && !vim_isprintc(type)) /* only printable chars allowed */ 745 type = 0; 746 qfp->qf_type = type; 747 qfp->qf_valid = valid; 748 749 if (qf_lists[qf_curlist].qf_count == 0) /* first element in the list */ 750 { 751 qf_lists[qf_curlist].qf_start = qfp; 752 qfp->qf_prev = qfp; /* first element points to itself */ 753 } 754 else 755 { 756 qfp->qf_prev = *prevp; 757 (*prevp)->qf_next = qfp; 758 } 759 qfp->qf_next = qfp; /* last element points to itself */ 760 qfp->qf_cleared = FALSE; 761 *prevp = qfp; 762 ++qf_lists[qf_curlist].qf_count; 763 if (qf_lists[qf_curlist].qf_index == 0 && qfp->qf_valid) 764 /* first valid entry */ 765 { 766 qf_lists[qf_curlist].qf_index = qf_lists[qf_curlist].qf_count; 767 qf_lists[qf_curlist].qf_ptr = qfp; 768 } 769 770 return OK; 771 } 772 773 /* 774 * get buffer number for file "dir.name" 775 */ 776 static int 777 qf_get_fnum(directory, fname) 778 char_u *directory; 779 char_u *fname; 780 { 781 if (fname == NULL || *fname == NUL) /* no file name */ 782 return 0; 783 { 784 #ifdef RISCOS 785 /* Name is reported as `main.c', but file is `c.main' */ 786 return ro_buflist_add(fname); 787 #else 788 char_u *ptr; 789 int fnum; 790 791 # ifdef VMS 792 vms_remove_version(fname); 793 # endif 794 # ifdef BACKSLASH_IN_FILENAME 795 if (directory != NULL) 796 slash_adjust(directory); 797 slash_adjust(fname); 798 # endif 799 if (directory != NULL && !vim_isAbsName(fname) 800 && (ptr = concat_fnames(directory, fname, TRUE)) != NULL) 801 { 802 /* 803 * Here we check if the file really exists. 804 * This should normally be true, but if make works without 805 * "leaving directory"-messages we might have missed a 806 * directory change. 807 */ 808 if (mch_getperm(ptr) < 0) 809 { 810 vim_free(ptr); 811 directory = qf_guess_filepath(fname); 812 if (directory) 813 ptr = concat_fnames(directory, fname, TRUE); 814 else 815 ptr = vim_strsave(fname); 816 } 817 /* Use concatenated directory name and file name */ 818 fnum = buflist_add(ptr, 0); 819 vim_free(ptr); 820 return fnum; 821 } 822 return buflist_add(fname, 0); 823 #endif 824 } 825 } 826 827 /* 828 * push dirbuf onto the directory stack and return pointer to actual dir or 829 * NULL on error 830 */ 831 static char_u * 832 qf_push_dir(dirbuf, stackptr) 833 char_u *dirbuf; 834 struct dir_stack_T **stackptr; 835 { 836 struct dir_stack_T *ds_new; 837 struct dir_stack_T *ds_ptr; 838 839 /* allocate new stack element and hook it in */ 840 ds_new = (struct dir_stack_T *)alloc((unsigned)sizeof(struct dir_stack_T)); 841 if (ds_new == NULL) 842 return NULL; 843 844 ds_new->next = *stackptr; 845 *stackptr = ds_new; 846 847 /* store directory on the stack */ 848 if (vim_isAbsName(dirbuf) 849 || (*stackptr)->next == NULL 850 || (*stackptr && dir_stack != *stackptr)) 851 (*stackptr)->dirname = vim_strsave(dirbuf); 852 else 853 { 854 /* Okay we don't have an absolute path. 855 * dirbuf must be a subdir of one of the directories on the stack. 856 * Let's search... 857 */ 858 ds_new = (*stackptr)->next; 859 (*stackptr)->dirname = NULL; 860 while (ds_new) 861 { 862 vim_free((*stackptr)->dirname); 863 (*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf, 864 TRUE); 865 if (mch_isdir((*stackptr)->dirname) == TRUE) 866 break; 867 868 ds_new = ds_new->next; 869 } 870 871 /* clean up all dirs we already left */ 872 while ((*stackptr)->next != ds_new) 873 { 874 ds_ptr = (*stackptr)->next; 875 (*stackptr)->next = (*stackptr)->next->next; 876 vim_free(ds_ptr->dirname); 877 vim_free(ds_ptr); 878 } 879 880 /* Nothing found -> it must be on top level */ 881 if (ds_new == NULL) 882 { 883 vim_free((*stackptr)->dirname); 884 (*stackptr)->dirname = vim_strsave(dirbuf); 885 } 886 } 887 888 if ((*stackptr)->dirname != NULL) 889 return (*stackptr)->dirname; 890 else 891 { 892 ds_ptr = *stackptr; 893 *stackptr = (*stackptr)->next; 894 vim_free(ds_ptr); 895 return NULL; 896 } 897 } 898 899 900 /* 901 * pop dirbuf from the directory stack and return previous directory or NULL if 902 * stack is empty 903 */ 904 static char_u * 905 qf_pop_dir(stackptr) 906 struct dir_stack_T **stackptr; 907 { 908 struct dir_stack_T *ds_ptr; 909 910 /* TODO: Should we check if dirbuf is the directory on top of the stack? 911 * What to do if it isn't? */ 912 913 /* pop top element and free it */ 914 if (*stackptr != NULL) 915 { 916 ds_ptr = *stackptr; 917 *stackptr = (*stackptr)->next; 918 vim_free(ds_ptr->dirname); 919 vim_free(ds_ptr); 920 } 921 922 /* return NEW top element as current dir or NULL if stack is empty*/ 923 return *stackptr ? (*stackptr)->dirname : NULL; 924 } 925 926 /* 927 * clean up directory stack 928 */ 929 static void 930 qf_clean_dir_stack(stackptr) 931 struct dir_stack_T **stackptr; 932 { 933 struct dir_stack_T *ds_ptr; 934 935 while ((ds_ptr = *stackptr) != NULL) 936 { 937 *stackptr = (*stackptr)->next; 938 vim_free(ds_ptr->dirname); 939 vim_free(ds_ptr); 940 } 941 } 942 943 /* 944 * Check in which directory of the directory stack the given file can be 945 * found. 946 * Returns a pointer to the directory name or NULL if not found 947 * Cleans up intermediate directory entries. 948 * 949 * TODO: How to solve the following problem? 950 * If we have the this directory tree: 951 * ./ 952 * ./aa 953 * ./aa/bb 954 * ./bb 955 * ./bb/x.c 956 * and make says: 957 * making all in aa 958 * making all in bb 959 * x.c:9: Error 960 * Then qf_push_dir thinks we are in ./aa/bb, but we are in ./bb. 961 * qf_guess_filepath will return NULL. 962 */ 963 static char_u * 964 qf_guess_filepath(filename) 965 char_u *filename; 966 { 967 struct dir_stack_T *ds_ptr; 968 struct dir_stack_T *ds_tmp; 969 char_u *fullname; 970 971 /* no dirs on the stack - there's nothing we can do */ 972 if (dir_stack == NULL) 973 return NULL; 974 975 ds_ptr = dir_stack->next; 976 fullname = NULL; 977 while (ds_ptr) 978 { 979 vim_free(fullname); 980 fullname = concat_fnames(ds_ptr->dirname, filename, TRUE); 981 982 /* If concat_fnames failed, just go on. The worst thing that can happen 983 * is that we delete the entire stack. 984 */ 985 if ((fullname != NULL) && (mch_getperm(fullname) >= 0)) 986 break; 987 988 ds_ptr = ds_ptr->next; 989 } 990 991 vim_free(fullname); 992 993 /* clean up all dirs we already left */ 994 while (dir_stack->next != ds_ptr) 995 { 996 ds_tmp = dir_stack->next; 997 dir_stack->next = dir_stack->next->next; 998 vim_free(ds_tmp->dirname); 999 vim_free(ds_tmp); 1000 } 1001 1002 return ds_ptr==NULL? NULL: ds_ptr->dirname; 1003 1004 } 1005 1006 /* 1007 * jump to a quickfix line 1008 * if dir == FORWARD go "errornr" valid entries forward 1009 * if dir == BACKWARD go "errornr" valid entries backward 1010 * if dir == FORWARD_FILE go "errornr" valid entries files backward 1011 * if dir == BACKWARD_FILE go "errornr" valid entries files backward 1012 * else if "errornr" is zero, redisplay the same line 1013 * else go to entry "errornr" 1014 */ 1015 void 1016 qf_jump(dir, errornr, forceit) 1017 int dir; 1018 int errornr; 1019 int forceit; 1020 { 1021 struct qf_line *qf_ptr; 1022 struct qf_line *old_qf_ptr; 1023 int qf_index; 1024 int old_qf_fnum; 1025 int old_qf_index; 1026 int prev_index; 1027 static char_u *e_no_more_items = (char_u *)N_("E553: No more items"); 1028 char_u *err = e_no_more_items; 1029 linenr_T i; 1030 buf_T *old_curbuf; 1031 linenr_T old_lnum; 1032 char_u *old_swb = p_swb; 1033 colnr_T screen_col; 1034 colnr_T char_col; 1035 char_u *line; 1036 #ifdef FEAT_WINDOWS 1037 int opened_window = FALSE; 1038 win_T *win; 1039 win_T *altwin; 1040 #endif 1041 int print_message = TRUE; 1042 int len; 1043 #ifdef FEAT_FOLDING 1044 int old_KeyTyped = KeyTyped; /* getting file may reset it */ 1045 #endif 1046 int ok = OK; 1047 1048 if (qf_curlist >= qf_listcount || qf_lists[qf_curlist].qf_count == 0) 1049 { 1050 EMSG(_(e_quickfix)); 1051 return; 1052 } 1053 1054 qf_ptr = qf_lists[qf_curlist].qf_ptr; 1055 old_qf_ptr = qf_ptr; 1056 qf_index = qf_lists[qf_curlist].qf_index; 1057 old_qf_index = qf_index; 1058 if (dir == FORWARD || dir == FORWARD_FILE) /* next valid entry */ 1059 { 1060 while (errornr--) 1061 { 1062 old_qf_ptr = qf_ptr; 1063 prev_index = qf_index; 1064 old_qf_fnum = qf_ptr->qf_fnum; 1065 do 1066 { 1067 if (qf_index == qf_lists[qf_curlist].qf_count 1068 || qf_ptr->qf_next == NULL) 1069 { 1070 qf_ptr = old_qf_ptr; 1071 qf_index = prev_index; 1072 if (err != NULL) 1073 { 1074 EMSG(_(err)); 1075 goto theend; 1076 } 1077 errornr = 0; 1078 break; 1079 } 1080 ++qf_index; 1081 qf_ptr = qf_ptr->qf_next; 1082 } while ((!qf_lists[qf_curlist].qf_nonevalid && !qf_ptr->qf_valid) 1083 || (dir == FORWARD_FILE && qf_ptr->qf_fnum == old_qf_fnum)); 1084 err = NULL; 1085 } 1086 } 1087 else if (dir == BACKWARD || dir == BACKWARD_FILE) /* prev. valid entry */ 1088 { 1089 while (errornr--) 1090 { 1091 old_qf_ptr = qf_ptr; 1092 prev_index = qf_index; 1093 old_qf_fnum = qf_ptr->qf_fnum; 1094 do 1095 { 1096 if (qf_index == 1 || qf_ptr->qf_prev == NULL) 1097 { 1098 qf_ptr = old_qf_ptr; 1099 qf_index = prev_index; 1100 if (err != NULL) 1101 { 1102 EMSG(_(err)); 1103 goto theend; 1104 } 1105 errornr = 0; 1106 break; 1107 } 1108 --qf_index; 1109 qf_ptr = qf_ptr->qf_prev; 1110 } while ((!qf_lists[qf_curlist].qf_nonevalid && !qf_ptr->qf_valid) 1111 || (dir == BACKWARD_FILE && qf_ptr->qf_fnum == old_qf_fnum)); 1112 err = NULL; 1113 } 1114 } 1115 else if (errornr != 0) /* go to specified number */ 1116 { 1117 while (errornr < qf_index && qf_index > 1 && qf_ptr->qf_prev != NULL) 1118 { 1119 --qf_index; 1120 qf_ptr = qf_ptr->qf_prev; 1121 } 1122 while (errornr > qf_index && qf_index < qf_lists[qf_curlist].qf_count 1123 && qf_ptr->qf_next != NULL) 1124 { 1125 ++qf_index; 1126 qf_ptr = qf_ptr->qf_next; 1127 } 1128 } 1129 1130 #ifdef FEAT_WINDOWS 1131 qf_lists[qf_curlist].qf_index = qf_index; 1132 if (qf_win_pos_update(old_qf_index)) 1133 /* No need to print the error message if it's visible in the error 1134 * window */ 1135 print_message = FALSE; 1136 1137 /* 1138 * For ":helpgrep" find a help window or open one. 1139 */ 1140 if (qf_ptr->qf_type == 1 && !curwin->w_buffer->b_help) 1141 { 1142 win_T *wp; 1143 int n; 1144 1145 for (wp = firstwin; wp != NULL; wp = wp->w_next) 1146 if (wp->w_buffer != NULL && wp->w_buffer->b_help) 1147 break; 1148 if (wp != NULL && wp->w_buffer->b_nwindows > 0) 1149 win_enter(wp, TRUE); 1150 else 1151 { 1152 /* 1153 * Split off help window; put it at far top if no position 1154 * specified, the current window is vertically split and narrow. 1155 */ 1156 n = WSP_HELP; 1157 # ifdef FEAT_VERTSPLIT 1158 if (cmdmod.split == 0 && curwin->w_width != Columns 1159 && curwin->w_width < 80) 1160 n |= WSP_TOP; 1161 # endif 1162 if (win_split(0, n) == FAIL) 1163 goto theend; 1164 opened_window = TRUE; /* close it when fail */ 1165 1166 if (curwin->w_height < p_hh) 1167 win_setheight((int)p_hh); 1168 } 1169 1170 if (!p_im) 1171 restart_edit = 0; /* don't want insert mode in help file */ 1172 } 1173 1174 /* 1175 * If currently in the quickfix window, find another window to show the 1176 * file in. 1177 */ 1178 if (bt_quickfix(curbuf) && !opened_window) 1179 { 1180 /* 1181 * If there is no file specified, we don't know where to go. 1182 * But do advance, otherwise ":cn" gets stuck. 1183 */ 1184 if (qf_ptr->qf_fnum == 0) 1185 goto theend; 1186 1187 /* 1188 * If there is only one window, create a new one above the quickfix 1189 * window. 1190 */ 1191 if (firstwin == lastwin) 1192 { 1193 if (win_split(0, WSP_ABOVE) == FAIL) 1194 goto failed; /* not enough room for window */ 1195 opened_window = TRUE; /* close it when fail */ 1196 p_swb = empty_option; /* don't split again */ 1197 # ifdef FEAT_SCROLLBIND 1198 curwin->w_p_scb = FALSE; 1199 # endif 1200 } 1201 else 1202 { 1203 /* 1204 * Try to find a window that shows the right buffer. 1205 * Default to the window just above the quickfix buffer. 1206 */ 1207 win = curwin; 1208 altwin = NULL; 1209 for (;;) 1210 { 1211 if (win->w_buffer->b_fnum == qf_ptr->qf_fnum) 1212 break; 1213 if (win->w_prev == NULL) 1214 win = lastwin; /* wrap around the top */ 1215 else 1216 win = win->w_prev; /* go to previous window */ 1217 1218 if (bt_quickfix(win->w_buffer)) 1219 { 1220 /* Didn't find it, go to the window before the quickfix 1221 * window. */ 1222 if (altwin != NULL) 1223 win = altwin; 1224 else if (curwin->w_prev != NULL) 1225 win = curwin->w_prev; 1226 else 1227 win = curwin->w_next; 1228 break; 1229 } 1230 1231 /* Remember a usable window. */ 1232 if (altwin == NULL && !win->w_p_pvw 1233 && win->w_buffer->b_p_bt[0] == NUL) 1234 altwin = win; 1235 } 1236 1237 win_goto(win); 1238 } 1239 } 1240 #endif 1241 1242 /* 1243 * If there is a file name, 1244 * read the wanted file if needed, and check autowrite etc. 1245 */ 1246 old_curbuf = curbuf; 1247 old_lnum = curwin->w_cursor.lnum; 1248 1249 if (qf_ptr->qf_fnum != 0) 1250 { 1251 if (qf_ptr->qf_type == 1) 1252 { 1253 /* Open help file (do_ecmd() will set b_help flag, readfile() will 1254 * set b_p_ro flag). */ 1255 if (!can_abandon(curbuf, forceit)) 1256 { 1257 EMSG(_(e_nowrtmsg)); 1258 ok = FALSE; 1259 } 1260 else 1261 ok = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1, 1262 ECMD_HIDE + ECMD_SET_HELP); 1263 } 1264 else 1265 ok = buflist_getfile(qf_ptr->qf_fnum, 1266 (linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit); 1267 } 1268 1269 if (ok == OK) 1270 { 1271 /* When not switched to another buffer, still need to set pc mark */ 1272 if (curbuf == old_curbuf) 1273 setpcmark(); 1274 1275 /* 1276 * Go to line with error, unless qf_lnum is 0. 1277 */ 1278 i = qf_ptr->qf_lnum; 1279 if (i > 0) 1280 { 1281 if (i > curbuf->b_ml.ml_line_count) 1282 i = curbuf->b_ml.ml_line_count; 1283 curwin->w_cursor.lnum = i; 1284 } 1285 if (qf_ptr->qf_col > 0) 1286 { 1287 curwin->w_cursor.col = qf_ptr->qf_col - 1; 1288 if (qf_ptr->qf_viscol == TRUE) 1289 { 1290 /* 1291 * Check each character from the beginning of the error 1292 * line up to the error column. For each tab character 1293 * found, reduce the error column value by the length of 1294 * a tab character. 1295 */ 1296 line = ml_get_curline(); 1297 screen_col = 0; 1298 for (char_col = 0; char_col < curwin->w_cursor.col; ++char_col) 1299 { 1300 if (*line == NUL) 1301 break; 1302 if (*line++ == '\t') 1303 { 1304 curwin->w_cursor.col -= 7 - (screen_col % 8); 1305 screen_col += 8 - (screen_col % 8); 1306 } 1307 else 1308 ++screen_col; 1309 } 1310 } 1311 check_cursor(); 1312 } 1313 else 1314 beginline(BL_WHITE | BL_FIX); 1315 1316 #ifdef FEAT_FOLDING 1317 if ((fdo_flags & FDO_QUICKFIX) && old_KeyTyped) 1318 foldOpenCursor(); 1319 #endif 1320 if (print_message) 1321 { 1322 /* Update the screen before showing the message */ 1323 update_topline_redraw(); 1324 sprintf((char *)IObuff, _("(%d of %d)%s%s: "), qf_index, 1325 qf_lists[qf_curlist].qf_count, 1326 qf_ptr->qf_cleared ? _(" (line deleted)") : "", 1327 (char *)qf_types(qf_ptr->qf_type, qf_ptr->qf_nr)); 1328 /* Add the message, skipping leading whitespace and newlines. */ 1329 len = (int)STRLEN(IObuff); 1330 qf_fmt_text(skipwhite(qf_ptr->qf_text), IObuff + len, IOSIZE - len); 1331 1332 /* Output the message. Overwrite to avoid scrolling when the 'O' 1333 * flag is present in 'shortmess'; But when not jumping, print the 1334 * whole message. */ 1335 i = msg_scroll; 1336 if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum) 1337 msg_scroll = TRUE; 1338 else if (!msg_scrolled && shortmess(SHM_OVERALL)) 1339 msg_scroll = FALSE; 1340 msg_attr_keep(IObuff, 0, TRUE); 1341 msg_scroll = i; 1342 } 1343 } 1344 else 1345 { 1346 #ifdef FEAT_WINDOWS 1347 if (opened_window) 1348 win_close(curwin, TRUE); /* Close opened window */ 1349 #endif 1350 if (qf_ptr->qf_fnum != 0) 1351 { 1352 /* 1353 * Couldn't open file, so put index back where it was. This could 1354 * happen if the file was readonly and we changed something. 1355 */ 1356 #ifdef FEAT_WINDOWS 1357 failed: 1358 #endif 1359 qf_ptr = old_qf_ptr; 1360 qf_index = old_qf_index; 1361 } 1362 } 1363 theend: 1364 qf_lists[qf_curlist].qf_ptr = qf_ptr; 1365 qf_lists[qf_curlist].qf_index = qf_index; 1366 #ifdef FEAT_WINDOWS 1367 if (p_swb != old_swb && opened_window) 1368 { 1369 /* Restore old 'switchbuf' value, but not when an autocommand or 1370 * modeline has changed the value. */ 1371 if (p_swb == empty_option) 1372 p_swb = old_swb; 1373 else 1374 free_string_option(old_swb); 1375 } 1376 #endif 1377 } 1378 1379 /* 1380 * ":clist": list all errors 1381 */ 1382 void 1383 qf_list(eap) 1384 exarg_T *eap; 1385 { 1386 buf_T *buf; 1387 char_u *fname; 1388 struct qf_line *qfp; 1389 int i; 1390 int idx1 = 1; 1391 int idx2 = -1; 1392 int need_return = TRUE; 1393 int last_printed = 1; 1394 char_u *arg = eap->arg; 1395 int all = eap->forceit; /* if not :cl!, only show 1396 recognised errors */ 1397 1398 if (qf_curlist >= qf_listcount || qf_lists[qf_curlist].qf_count == 0) 1399 { 1400 EMSG(_(e_quickfix)); 1401 return; 1402 } 1403 if (!get_list_range(&arg, &idx1, &idx2) || *arg != NUL) 1404 { 1405 EMSG(_(e_trailing)); 1406 return; 1407 } 1408 i = qf_lists[qf_curlist].qf_count; 1409 if (idx1 < 0) 1410 idx1 = (-idx1 > i) ? 0 : idx1 + i + 1; 1411 if (idx2 < 0) 1412 idx2 = (-idx2 > i) ? 0 : idx2 + i + 1; 1413 1414 more_back_used = TRUE; 1415 if (qf_lists[qf_curlist].qf_nonevalid) 1416 all = TRUE; 1417 qfp = qf_lists[qf_curlist].qf_start; 1418 for (i = 1; !got_int && i <= qf_lists[qf_curlist].qf_count; ) 1419 { 1420 if ((qfp->qf_valid || all) && idx1 <= i && i <= idx2) 1421 { 1422 if (need_return) 1423 { 1424 msg_putchar('\n'); 1425 need_return = FALSE; 1426 } 1427 if (more_back == 0) 1428 { 1429 fname = NULL; 1430 if (qfp->qf_fnum != 0 1431 && (buf = buflist_findnr(qfp->qf_fnum)) != NULL) 1432 { 1433 fname = buf->b_fname; 1434 if (qfp->qf_type == 1) /* :helpgrep */ 1435 fname = gettail(fname); 1436 } 1437 if (fname == NULL) 1438 sprintf((char *)IObuff, "%2d", i); 1439 else 1440 sprintf((char *)IObuff, "%2d %s", i, (char *)fname); 1441 msg_outtrans_attr(IObuff, i == qf_lists[qf_curlist].qf_index 1442 ? hl_attr(HLF_L) : hl_attr(HLF_D)); 1443 if (qfp->qf_lnum == 0) 1444 IObuff[0] = NUL; 1445 else if (qfp->qf_col == 0) 1446 sprintf((char *)IObuff, ":%ld", qfp->qf_lnum); 1447 else 1448 sprintf((char *)IObuff, ":%ld col %d", 1449 qfp->qf_lnum, qfp->qf_col); 1450 sprintf((char *)IObuff + STRLEN(IObuff), "%s: ", 1451 (char *)qf_types(qfp->qf_type, qfp->qf_nr)); 1452 msg_puts_attr(IObuff, hl_attr(HLF_N)); 1453 /* Remove newlines and leading whitespace from the text. 1454 * For an unrecognized line keep the indent, the compiler may 1455 * mark a word with ^^^^. */ 1456 qf_fmt_text((fname != NULL || qfp->qf_lnum != 0) 1457 ? skipwhite(qfp->qf_text) : qfp->qf_text, 1458 IObuff, IOSIZE); 1459 msg_prt_line(IObuff, FALSE); 1460 out_flush(); /* show one line at a time */ 1461 need_return = TRUE; 1462 last_printed = i; 1463 } 1464 } 1465 if (more_back) 1466 { 1467 /* scrolling backwards from the more-prompt */ 1468 /* TODO: compute the number of items from the screen lines */ 1469 more_back = more_back * 2 - 1; 1470 while (i > last_printed - more_back && i > idx1) 1471 { 1472 do 1473 { 1474 qfp = qfp->qf_prev; 1475 --i; 1476 } 1477 while (i > idx1 && !qfp->qf_valid && !all); 1478 } 1479 more_back = 0; 1480 } 1481 else 1482 { 1483 qfp = qfp->qf_next; 1484 ++i; 1485 } 1486 ui_breakcheck(); 1487 } 1488 more_back_used = FALSE; 1489 } 1490 1491 /* 1492 * Remove newlines and leading whitespace from an error message. 1493 * Put the result in "buf[bufsize]". 1494 */ 1495 static void 1496 qf_fmt_text(text, buf, bufsize) 1497 char_u *text; 1498 char_u *buf; 1499 int bufsize; 1500 { 1501 int i; 1502 char_u *p = text; 1503 1504 for (i = 0; *p != NUL && i < bufsize - 1; ++i) 1505 { 1506 if (*p == '\n') 1507 { 1508 buf[i] = ' '; 1509 while (*++p != NUL) 1510 if (!vim_iswhite(*p) && *p != '\n') 1511 break; 1512 } 1513 else 1514 buf[i] = *p++; 1515 } 1516 buf[i] = NUL; 1517 } 1518 1519 /* 1520 * ":colder [count]": Up in the quickfix stack. 1521 * ":cnewer [count]": Down in the quickfix stack. 1522 */ 1523 void 1524 qf_age(eap) 1525 exarg_T *eap; 1526 { 1527 int count; 1528 1529 if (eap->addr_count != 0) 1530 count = eap->line2; 1531 else 1532 count = 1; 1533 while (count--) 1534 { 1535 if (eap->cmdidx == CMD_colder) 1536 { 1537 if (qf_curlist == 0) 1538 { 1539 EMSG(_("E380: At bottom of quickfix stack")); 1540 return; 1541 } 1542 --qf_curlist; 1543 } 1544 else 1545 { 1546 if (qf_curlist >= qf_listcount - 1) 1547 { 1548 EMSG(_("E381: At top of quickfix stack")); 1549 return; 1550 } 1551 ++qf_curlist; 1552 } 1553 } 1554 qf_msg(); 1555 } 1556 1557 static void 1558 qf_msg() 1559 { 1560 smsg((char_u *)_("error list %d of %d; %d errors"), 1561 qf_curlist + 1, qf_listcount, qf_lists[qf_curlist].qf_count); 1562 #ifdef FEAT_WINDOWS 1563 qf_update_buffer(); 1564 #endif 1565 } 1566 1567 /* 1568 * free the error list 1569 */ 1570 static void 1571 qf_free(idx) 1572 int idx; 1573 { 1574 struct qf_line *qfp; 1575 1576 while (qf_lists[idx].qf_count) 1577 { 1578 qfp = qf_lists[idx].qf_start->qf_next; 1579 vim_free(qf_lists[idx].qf_start->qf_text); 1580 vim_free(qf_lists[idx].qf_start); 1581 qf_lists[idx].qf_start = qfp; 1582 --qf_lists[idx].qf_count; 1583 } 1584 } 1585 1586 /* 1587 * qf_mark_adjust: adjust marks 1588 */ 1589 void 1590 qf_mark_adjust(line1, line2, amount, amount_after) 1591 linenr_T line1; 1592 linenr_T line2; 1593 long amount; 1594 long amount_after; 1595 { 1596 int i; 1597 struct qf_line *qfp; 1598 int idx; 1599 1600 for (idx = 0; idx < qf_listcount; ++idx) 1601 if (qf_lists[idx].qf_count) 1602 for (i = 0, qfp = qf_lists[idx].qf_start; 1603 i < qf_lists[idx].qf_count; ++i, qfp = qfp->qf_next) 1604 if (qfp->qf_fnum == curbuf->b_fnum) 1605 { 1606 if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2) 1607 { 1608 if (amount == MAXLNUM) 1609 qfp->qf_cleared = TRUE; 1610 else 1611 qfp->qf_lnum += amount; 1612 } 1613 else if (amount_after && qfp->qf_lnum > line2) 1614 qfp->qf_lnum += amount_after; 1615 } 1616 } 1617 1618 /* 1619 * Make a nice message out of the error character and the error number: 1620 * char number message 1621 * e or E 0 " error" 1622 * w or W 0 " warning" 1623 * i or I 0 " info" 1624 * 0 0 "" 1625 * other 0 " c" 1626 * e or E n " error n" 1627 * w or W n " warning n" 1628 * i or I n " info n" 1629 * 0 n " error n" 1630 * other n " c n" 1631 * 1 x "" :helpgrep 1632 */ 1633 static char_u * 1634 qf_types(c, nr) 1635 int c, nr; 1636 { 1637 static char_u buf[20]; 1638 static char_u cc[3]; 1639 char_u *p; 1640 1641 if (c == 'W' || c == 'w') 1642 p = (char_u *)" warning"; 1643 else if (c == 'I' || c == 'i') 1644 p = (char_u *)" info"; 1645 else if (c == 'E' || c == 'e' || (c == 0 && nr > 0)) 1646 p = (char_u *)" error"; 1647 else if (c == 0 || c == 1) 1648 p = (char_u *)""; 1649 else 1650 { 1651 cc[0] = ' '; 1652 cc[1] = c; 1653 cc[2] = NUL; 1654 p = cc; 1655 } 1656 1657 if (nr <= 0) 1658 return p; 1659 1660 sprintf((char *)buf, "%s %3d", (char *)p, nr); 1661 return buf; 1662 } 1663 1664 #if defined(FEAT_WINDOWS) || defined(PROTO) 1665 /* 1666 * ":cwindow": open the quickfix window if we have errors to display, 1667 * close it if not. 1668 */ 1669 void 1670 ex_cwindow(eap) 1671 exarg_T *eap; 1672 { 1673 win_T *win; 1674 1675 /* 1676 * Look for an existing quickfix window. 1677 */ 1678 for (win = firstwin; win != NULL; win = win->w_next) 1679 if (bt_quickfix(win->w_buffer)) 1680 break; 1681 1682 /* 1683 * If a quickfix window is open but we have no errors to display, 1684 * close the window. If a quickfix window is not open, then open 1685 * it if we have errors; otherwise, leave it closed. 1686 */ 1687 if (qf_lists[qf_curlist].qf_nonevalid || qf_curlist >= qf_listcount) 1688 { 1689 if (win != NULL) 1690 ex_cclose(eap); 1691 } 1692 else if (win == NULL) 1693 ex_copen(eap); 1694 } 1695 1696 /* 1697 * ":cclose": close the window showing the list of errors. 1698 */ 1699 /*ARGSUSED*/ 1700 void 1701 ex_cclose(eap) 1702 exarg_T *eap; 1703 { 1704 win_T *win; 1705 1706 /* 1707 * Find existing quickfix window and close it. 1708 */ 1709 for (win = firstwin; win != NULL; win = win->w_next) 1710 if (bt_quickfix(win->w_buffer)) 1711 break; 1712 1713 if (win != NULL) 1714 win_close(win, FALSE); 1715 } 1716 1717 /* 1718 * ":copen": open a window that shows the list of errors. 1719 */ 1720 void 1721 ex_copen(eap) 1722 exarg_T *eap; 1723 { 1724 int height; 1725 buf_T *buf; 1726 win_T *win; 1727 1728 if (eap->addr_count != 0) 1729 height = eap->line2; 1730 else 1731 height = QF_WINHEIGHT; 1732 1733 #ifdef FEAT_VISUAL 1734 reset_VIsual_and_resel(); /* stop Visual mode */ 1735 #endif 1736 #ifdef FEAT_GUI 1737 need_mouse_correct = TRUE; 1738 #endif 1739 1740 /* 1741 * Find existing quickfix window, or open a new one. 1742 */ 1743 for (win = firstwin; win != NULL; win = win->w_next) 1744 if (bt_quickfix(win->w_buffer)) 1745 break; 1746 if (win != NULL) 1747 win_goto(win); 1748 else 1749 { 1750 /* The current window becomes the previous window afterwards. */ 1751 win = curwin; 1752 1753 /* Create the new window at the very bottom. */ 1754 win_goto(lastwin); 1755 if (win_split(height, WSP_BELOW) == FAIL) 1756 return; /* not enough room for window */ 1757 #ifdef FEAT_SCROLLBIND 1758 curwin->w_p_scb = FALSE; 1759 #endif 1760 1761 /* 1762 * Find existing quickfix buffer, or create a new one. 1763 */ 1764 buf = qf_find_buf(); 1765 if (buf == NULL) 1766 { 1767 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE); 1768 /* switch off 'swapfile' */ 1769 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); 1770 set_option_value((char_u *)"bt", 0L, (char_u *)"quickfix", 1771 OPT_LOCAL); 1772 set_option_value((char_u *)"bh", 0L, (char_u *)"delete", OPT_LOCAL); 1773 set_option_value((char_u *)"diff", 0L, (char_u *)"", OPT_LOCAL); 1774 } 1775 else if (buf != curbuf) 1776 set_curbuf(buf, DOBUF_GOTO); 1777 1778 #ifdef FEAT_VERTSPLIT 1779 /* Only set the height when there is no window to the side. */ 1780 if (curwin->w_width == Columns) 1781 #endif 1782 win_setheight(height); 1783 curwin->w_p_wfh = TRUE; /* set 'winfixheight' */ 1784 if (win_valid(win)) 1785 prevwin = win; 1786 } 1787 1788 /* 1789 * Fill the buffer with the quickfix list. 1790 */ 1791 qf_fill_buffer(); 1792 1793 curwin->w_cursor.lnum = qf_lists[qf_curlist].qf_index; 1794 curwin->w_cursor.col = 0; 1795 check_cursor(); 1796 update_topline(); /* scroll to show the line */ 1797 } 1798 1799 /* 1800 * Return the number of the current entry (line number in the quickfix 1801 * window). 1802 */ 1803 linenr_T 1804 qf_current_entry() 1805 { 1806 return qf_lists[qf_curlist].qf_index; 1807 } 1808 1809 /* 1810 * Update the cursor position in the quickfix window to the current error. 1811 * Return TRUE if there is a quickfix window. 1812 */ 1813 static int 1814 qf_win_pos_update(old_qf_index) 1815 int old_qf_index; /* previous qf_index or zero */ 1816 { 1817 win_T *win; 1818 int qf_index = qf_lists[qf_curlist].qf_index; 1819 1820 /* 1821 * Put the cursor on the current error in the quickfix window, so that 1822 * it's viewable. 1823 */ 1824 for (win = firstwin; win != NULL; win = win->w_next) 1825 if (bt_quickfix(win->w_buffer)) 1826 break; 1827 if (win != NULL 1828 && qf_index <= win->w_buffer->b_ml.ml_line_count 1829 && old_qf_index != qf_index) 1830 { 1831 win_T *old_curwin = curwin; 1832 1833 curwin = win; 1834 curbuf = win->w_buffer; 1835 if (qf_index > old_qf_index) 1836 { 1837 curwin->w_redraw_top = old_qf_index; 1838 curwin->w_redraw_bot = qf_index; 1839 } 1840 else 1841 { 1842 curwin->w_redraw_top = qf_index; 1843 curwin->w_redraw_bot = old_qf_index; 1844 } 1845 curwin->w_cursor.lnum = qf_index; 1846 curwin->w_cursor.col = 0; 1847 update_topline(); /* scroll to show the line */ 1848 redraw_later(VALID); 1849 curwin->w_redr_status = TRUE; /* update ruler */ 1850 curwin = old_curwin; 1851 curbuf = curwin->w_buffer; 1852 } 1853 return win != NULL; 1854 } 1855 1856 /* 1857 * Find quickfix buffer. 1858 */ 1859 static buf_T * 1860 qf_find_buf() 1861 { 1862 buf_T *buf; 1863 1864 for (buf = firstbuf; buf != NULL; buf = buf->b_next) 1865 if (bt_quickfix(buf)) 1866 break; 1867 return buf; 1868 } 1869 1870 /* 1871 * Find the quickfix buffer. If it exists, update the contents. 1872 */ 1873 static void 1874 qf_update_buffer() 1875 { 1876 buf_T *buf; 1877 #ifdef FEAT_AUTOCMD 1878 aco_save_T aco; 1879 #else 1880 buf_T *save_curbuf; 1881 #endif 1882 1883 /* Check if a buffer for the quickfix list exists. Update it. */ 1884 buf = qf_find_buf(); 1885 if (buf != NULL) 1886 { 1887 #ifdef FEAT_AUTOCMD 1888 /* set curwin/curbuf to buf and save a few things */ 1889 aucmd_prepbuf(&aco, buf); 1890 #else 1891 save_curbuf = curbuf; 1892 curbuf = buf; 1893 #endif 1894 1895 qf_fill_buffer(); 1896 1897 #ifdef FEAT_AUTOCMD 1898 /* restore curwin/curbuf and a few other things */ 1899 aucmd_restbuf(&aco); 1900 #else 1901 curbuf = save_curbuf; 1902 #endif 1903 1904 (void)qf_win_pos_update(0); 1905 } 1906 } 1907 1908 /* 1909 * Fill current buffer with quickfix errors, replacing any previous contents. 1910 * curbuf must be the quickfix buffer! 1911 */ 1912 static void 1913 qf_fill_buffer() 1914 { 1915 linenr_T lnum; 1916 struct qf_line *qfp; 1917 buf_T *errbuf; 1918 int len; 1919 int old_KeyTyped = KeyTyped; 1920 1921 /* delete all existing lines */ 1922 while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0) 1923 (void)ml_delete((linenr_T)1, FALSE); 1924 1925 /* Check if there is anything to display */ 1926 if (qf_curlist < qf_listcount) 1927 { 1928 /* Add one line for each error */ 1929 qfp = qf_lists[qf_curlist].qf_start; 1930 for (lnum = 0; lnum < qf_lists[qf_curlist].qf_count; ++lnum) 1931 { 1932 if (qfp->qf_fnum != 0 1933 && (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL 1934 && errbuf->b_fname != NULL) 1935 { 1936 if (qfp->qf_type == 1) /* :helpgrep */ 1937 STRCPY(IObuff, gettail(errbuf->b_fname)); 1938 else 1939 STRCPY(IObuff, errbuf->b_fname); 1940 len = (int)STRLEN(IObuff); 1941 } 1942 else 1943 len = 0; 1944 IObuff[len++] = '|'; 1945 1946 if (qfp->qf_lnum > 0) 1947 { 1948 sprintf((char *)IObuff + len, "%ld", qfp->qf_lnum); 1949 len += (int)STRLEN(IObuff + len); 1950 1951 if (qfp->qf_col > 0) 1952 { 1953 sprintf((char *)IObuff + len, " col %d", qfp->qf_col); 1954 len += (int)STRLEN(IObuff + len); 1955 } 1956 1957 sprintf((char *)IObuff + len, "%s", 1958 (char *)qf_types(qfp->qf_type, qfp->qf_nr)); 1959 len += (int)STRLEN(IObuff + len); 1960 } 1961 IObuff[len++] = '|'; 1962 IObuff[len++] = ' '; 1963 1964 /* Remove newlines and leading whitespace from the text. 1965 * For an unrecognized line keep the indent, the compiler may 1966 * mark a word with ^^^^. */ 1967 qf_fmt_text(len > 3 ? skipwhite(qfp->qf_text) : qfp->qf_text, 1968 IObuff + len, IOSIZE - len); 1969 1970 if (ml_append(lnum, IObuff, (colnr_T)STRLEN(IObuff) + 1, FALSE) 1971 == FAIL) 1972 break; 1973 qfp = qfp->qf_next; 1974 } 1975 /* Delete the empty line which is now at the end */ 1976 (void)ml_delete(lnum + 1, FALSE); 1977 } 1978 1979 /* correct cursor position */ 1980 check_lnums(TRUE); 1981 1982 /* Set the 'filetype' to "qf" each time after filling the buffer. This 1983 * resembles reading a file into a buffer, it's more logical when using 1984 * autocommands. */ 1985 set_option_value((char_u *)"ft", 0L, (char_u *)"qf", OPT_LOCAL); 1986 curbuf->b_p_ma = FALSE; 1987 1988 #ifdef FEAT_AUTOCMD 1989 apply_autocmds(EVENT_BUFREADPOST, (char_u *)"quickfix", NULL, 1990 FALSE, curbuf); 1991 apply_autocmds(EVENT_BUFWINENTER, (char_u *)"quickfix", NULL, 1992 FALSE, curbuf); 1993 #endif 1994 1995 /* make sure it will be redrawn */ 1996 redraw_curbuf_later(NOT_VALID); 1997 1998 /* Restore KeyTyped, setting 'filetype' may reset it. */ 1999 KeyTyped = old_KeyTyped; 2000 } 2001 2002 #endif /* FEAT_WINDOWS */ 2003 2004 /* 2005 * Return TRUE if "buf" is the quickfix buffer. 2006 */ 2007 int 2008 bt_quickfix(buf) 2009 buf_T *buf; 2010 { 2011 return (buf->b_p_bt[0] == 'q'); 2012 } 2013 2014 /* 2015 * Return TRUE if "buf" is a "nofile" or "acwrite" buffer. 2016 * This means the buffer name is not a file name. 2017 */ 2018 int 2019 bt_nofile(buf) 2020 buf_T *buf; 2021 { 2022 return (buf->b_p_bt[0] == 'n' && buf->b_p_bt[2] == 'f') 2023 || buf->b_p_bt[0] == 'a'; 2024 } 2025 2026 /* 2027 * Return TRUE if "buf" is a "nowrite" or "nofile" buffer. 2028 */ 2029 int 2030 bt_dontwrite(buf) 2031 buf_T *buf; 2032 { 2033 return (buf->b_p_bt[0] == 'n'); 2034 } 2035 2036 int 2037 bt_dontwrite_msg(buf) 2038 buf_T *buf; 2039 { 2040 if (bt_dontwrite(buf)) 2041 { 2042 EMSG(_("E382: Cannot write, 'buftype' option is set")); 2043 return TRUE; 2044 } 2045 return FALSE; 2046 } 2047 2048 /* 2049 * Return TRUE if the buffer should be hidden, according to 'hidden', ":hide" 2050 * and 'bufhidden'. 2051 */ 2052 int 2053 buf_hide(buf) 2054 buf_T *buf; 2055 { 2056 /* 'bufhidden' overrules 'hidden' and ":hide", check it first */ 2057 switch (buf->b_p_bh[0]) 2058 { 2059 case 'u': /* "unload" */ 2060 case 'w': /* "wipe" */ 2061 case 'd': return FALSE; /* "delete" */ 2062 case 'h': return TRUE; /* "hide" */ 2063 } 2064 return (p_hid || cmdmod.hide); 2065 } 2066 2067 /* 2068 * Return TRUE when using ":vimgrep" for ":grep". 2069 */ 2070 int 2071 grep_internal(cmdidx) 2072 cmdidx_T cmdidx; 2073 { 2074 return ((cmdidx == CMD_grep || cmdidx == CMD_grepadd) 2075 && STRCMP("internal", 2076 *curbuf->b_p_gp == NUL ? p_gp : curbuf->b_p_gp) == 0); 2077 } 2078 2079 /* 2080 * Used for ":make", ":grep" and ":grepadd". 2081 */ 2082 void 2083 ex_make(eap) 2084 exarg_T *eap; 2085 { 2086 char_u *fname; 2087 char_u *cmd; 2088 unsigned len; 2089 #ifdef FEAT_AUTOCMD 2090 char_u *au_name = NULL; 2091 2092 switch (eap->cmdidx) 2093 { 2094 case CMD_make: au_name = (char_u *)"make"; break; 2095 case CMD_grep: au_name = (char_u *)"grep"; break; 2096 case CMD_grepadd: au_name = (char_u *)"grepadd"; break; 2097 default: break; 2098 } 2099 if (au_name != NULL) 2100 { 2101 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, 2102 curbuf->b_fname, TRUE, curbuf); 2103 if (did_throw || force_abort) 2104 return; 2105 } 2106 #endif 2107 2108 /* Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". */ 2109 if (grep_internal(eap->cmdidx)) 2110 { 2111 ex_vimgrep(eap); 2112 return; 2113 } 2114 2115 autowrite_all(); 2116 fname = get_mef_name(); 2117 if (fname == NULL) 2118 return; 2119 mch_remove(fname); /* in case it's not unique */ 2120 2121 /* 2122 * If 'shellpipe' empty: don't redirect to 'errorfile'. 2123 */ 2124 len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(eap->arg) + 1; 2125 if (*p_sp != NUL) 2126 len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3; 2127 cmd = alloc(len); 2128 if (cmd == NULL) 2129 return; 2130 sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg, 2131 (char *)p_shq); 2132 if (*p_sp != NUL) 2133 append_redir(cmd, p_sp, fname); 2134 /* 2135 * Output a newline if there's something else than the :make command that 2136 * was typed (in which case the cursor is in column 0). 2137 */ 2138 if (msg_col == 0) 2139 msg_didout = FALSE; 2140 msg_start(); 2141 MSG_PUTS(":!"); 2142 msg_outtrans(cmd); /* show what we are doing */ 2143 2144 /* let the shell know if we are redirecting output or not */ 2145 do_shell(cmd, *p_sp != NUL ? SHELL_DOOUT : 0); 2146 2147 #ifdef AMIGA 2148 out_flush(); 2149 /* read window status report and redraw before message */ 2150 (void)char_avail(); 2151 #endif 2152 2153 if (qf_init(fname, eap->cmdidx != CMD_make ? p_gefm : p_efm, 2154 eap->cmdidx != CMD_grepadd) > 0 2155 && !eap->forceit) 2156 qf_jump(0, 0, FALSE); /* display first error */ 2157 2158 mch_remove(fname); 2159 vim_free(fname); 2160 vim_free(cmd); 2161 2162 #ifdef FEAT_AUTOCMD 2163 if (au_name != NULL) 2164 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, 2165 curbuf->b_fname, TRUE, curbuf); 2166 #endif 2167 } 2168 2169 /* 2170 * Return the name for the errorfile, in allocated memory. 2171 * Find a new unique name when 'makeef' contains "##". 2172 * Returns NULL for error. 2173 */ 2174 static char_u * 2175 get_mef_name() 2176 { 2177 char_u *p; 2178 char_u *name; 2179 static int start = -1; 2180 static int off = 0; 2181 #ifdef HAVE_LSTAT 2182 struct stat sb; 2183 #endif 2184 2185 if (*p_mef == NUL) 2186 { 2187 name = vim_tempname('e'); 2188 if (name == NULL) 2189 EMSG(_(e_notmp)); 2190 return name; 2191 } 2192 2193 for (p = p_mef; *p; ++p) 2194 if (p[0] == '#' && p[1] == '#') 2195 break; 2196 2197 if (*p == NUL) 2198 return vim_strsave(p_mef); 2199 2200 /* Keep trying until the name doesn't exist yet. */ 2201 for (;;) 2202 { 2203 if (start == -1) 2204 start = mch_get_pid(); 2205 else 2206 off += 19; 2207 2208 name = alloc((unsigned)STRLEN(p_mef) + 30); 2209 if (name == NULL) 2210 break; 2211 STRCPY(name, p_mef); 2212 sprintf((char *)name + (p - p_mef), "%d%d", start, off); 2213 STRCAT(name, p + 2); 2214 if (mch_getperm(name) < 0 2215 #ifdef HAVE_LSTAT 2216 /* Don't accept a symbolic link, its a security risk. */ 2217 && mch_lstat((char *)name, &sb) < 0 2218 #endif 2219 ) 2220 break; 2221 vim_free(name); 2222 } 2223 return name; 2224 } 2225 2226 /* 2227 * ":cc", ":crewind", ":cfirst" and ":clast". 2228 */ 2229 void 2230 ex_cc(eap) 2231 exarg_T *eap; 2232 { 2233 qf_jump(0, 2234 eap->addr_count > 0 2235 ? (int)eap->line2 2236 : eap->cmdidx == CMD_cc 2237 ? 0 2238 : (eap->cmdidx == CMD_crewind || eap->cmdidx == CMD_cfirst) 2239 ? 1 2240 : 32767, 2241 eap->forceit); 2242 } 2243 2244 /* 2245 * ":cnext", ":cnfile", ":cNext" and ":cprevious". 2246 */ 2247 void 2248 ex_cnext(eap) 2249 exarg_T *eap; 2250 { 2251 qf_jump(eap->cmdidx == CMD_cnext 2252 ? FORWARD 2253 : eap->cmdidx == CMD_cnfile 2254 ? FORWARD_FILE 2255 : (eap->cmdidx == CMD_cpfile || eap->cmdidx == CMD_cNfile) 2256 ? BACKWARD_FILE 2257 : BACKWARD, 2258 eap->addr_count > 0 ? (int)eap->line2 : 1, eap->forceit); 2259 } 2260 2261 /* 2262 * ":cfile" command. 2263 */ 2264 void 2265 ex_cfile(eap) 2266 exarg_T *eap; 2267 { 2268 if (*eap->arg != NUL) 2269 set_string_option_direct((char_u *)"ef", -1, eap->arg, OPT_FREE); 2270 if (qf_init(p_ef, p_efm, TRUE) > 0 && eap->cmdidx == CMD_cfile) 2271 qf_jump(0, 0, eap->forceit); /* display first error */ 2272 } 2273 2274 /* 2275 * ":vimgrep {pattern} file(s)" 2276 */ 2277 void 2278 ex_vimgrep(eap) 2279 exarg_T *eap; 2280 { 2281 regmmatch_T regmatch; 2282 int fcount; 2283 char_u **fnames; 2284 char_u *s; 2285 char_u *p; 2286 int i; 2287 int fi; 2288 struct qf_line *prevp = NULL; 2289 long lnum; 2290 garray_T ga; 2291 buf_T *buf; 2292 int duplicate_name = FALSE; 2293 int using_dummy; 2294 int found_match; 2295 buf_T *first_match_buf = NULL; 2296 time_t seconds = 0; 2297 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) 2298 char_u *save_ei = NULL; 2299 aco_save_T aco; 2300 #endif 2301 #ifdef FEAT_AUTOCMD 2302 char_u *au_name = NULL; 2303 int flags = 0; 2304 colnr_T col; 2305 2306 switch (eap->cmdidx) 2307 { 2308 case CMD_vimgrep: au_name = (char_u *)"vimgrep"; break; 2309 case CMD_vimgrepadd: au_name = (char_u *)"vimgrepadd"; break; 2310 default: break; 2311 } 2312 if (au_name != NULL) 2313 { 2314 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, 2315 curbuf->b_fname, TRUE, curbuf); 2316 if (did_throw || force_abort) 2317 return; 2318 } 2319 #endif 2320 2321 /* Get the search pattern: either white-separated or enclosed in // */ 2322 regmatch.regprog = NULL; 2323 p = skip_vimgrep_pat(eap->arg, &s, &flags); 2324 if (p == NULL) 2325 { 2326 EMSG(_("E682: Invalid search pattern or delimiter")); 2327 goto theend; 2328 } 2329 regmatch.regprog = vim_regcomp(s, RE_MAGIC); 2330 if (regmatch.regprog == NULL) 2331 goto theend; 2332 regmatch.rmm_ic = p_ic; 2333 2334 p = skipwhite(p); 2335 if (*p == NUL) 2336 { 2337 EMSG(_("E683: File name missing or invalid pattern")); 2338 goto theend; 2339 } 2340 2341 if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_vimgrepadd) 2342 || qf_curlist == qf_listcount) 2343 /* make place for a new list */ 2344 qf_new_list(); 2345 else if (qf_lists[qf_curlist].qf_count > 0) 2346 /* Adding to existing list, find last entry. */ 2347 for (prevp = qf_lists[qf_curlist].qf_start; 2348 prevp->qf_next != prevp; prevp = prevp->qf_next) 2349 ; 2350 2351 /* parse the list of arguments */ 2352 if (get_arglist(&ga, p) == FAIL) 2353 goto theend; 2354 i = gen_expand_wildcards(ga.ga_len, (char_u **)ga.ga_data, 2355 &fcount, &fnames, EW_FILE|EW_NOTFOUND); 2356 ga_clear(&ga); 2357 if (i == FAIL) 2358 goto theend; 2359 if (fcount == 0) 2360 { 2361 EMSG(_(e_nomatch)); 2362 goto theend; 2363 } 2364 2365 seconds = (time_t)0; 2366 for (fi = 0; fi < fcount && !got_int; ++fi) 2367 { 2368 if (time(NULL) > seconds) 2369 { 2370 /* Display the file name every second or so. */ 2371 seconds = time(NULL); 2372 msg_start(); 2373 p = msg_strtrunc(fnames[fi]); 2374 if (p == NULL) 2375 msg_outtrans(fnames[fi]); 2376 else 2377 { 2378 msg_outtrans(p); 2379 vim_free(p); 2380 } 2381 msg_clr_eos(); 2382 msg_didout = FALSE; /* overwrite this message */ 2383 msg_nowait = TRUE; /* don't wait for this message */ 2384 msg_col = 0; 2385 out_flush(); 2386 } 2387 2388 buf = buflist_findname_exp(fnames[fi]); 2389 if (buf == NULL || buf->b_ml.ml_mfp == NULL) 2390 { 2391 /* Remember that a buffer with this name already exists. */ 2392 duplicate_name = (buf != NULL); 2393 using_dummy = TRUE; 2394 2395 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) 2396 /* Don't do Filetype autocommands to avoid loading syntax and 2397 * indent scripts, a great speed improvement. */ 2398 save_ei = au_event_disable(",Filetype"); 2399 #endif 2400 2401 /* Load file into a buffer, so that 'fileencoding' is detected, 2402 * autocommands applied, etc. */ 2403 buf = load_dummy_buffer(fnames[fi]); 2404 2405 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) 2406 au_event_restore(save_ei); 2407 #endif 2408 } 2409 else 2410 /* Use existing, loaded buffer. */ 2411 using_dummy = FALSE; 2412 2413 if (buf == NULL) 2414 { 2415 if (!got_int) 2416 smsg((char_u *)_("Cannot open file \"%s\""), fnames[fi]); 2417 } 2418 else 2419 { 2420 found_match = FALSE; 2421 #ifdef HAVE_SETJMP_H 2422 /* 2423 * Matching with a regexp may cause a very deep recursive call of 2424 * regmatch(). Vim will crash when running out of stack space. 2425 * Catch this here if the system supports it. 2426 * It's a bit slow, thus do it outside of the loop. 2427 */ 2428 mch_startjmp(); 2429 if (SETJMP(lc_jump_env) != 0) 2430 { 2431 mch_didjmp(); 2432 # ifdef SIGHASARG 2433 if (lc_signal != SIGINT) 2434 # endif 2435 EMSG(_(e_complex)); 2436 got_int = TRUE; 2437 goto jumpend; 2438 } 2439 #endif 2440 /* Try for a match in all lines of the buffer. */ 2441 for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum) 2442 { 2443 /* For ":1vimgrep" look for multiple matches. */ 2444 col = 0; 2445 while (vim_regexec_multi(®match, curwin, buf, lnum, 2446 col) > 0) 2447 { 2448 if (qf_add_entry(&prevp, 2449 NULL, /* dir */ 2450 fnames[fi], 2451 ml_get_buf(buf, 2452 regmatch.startpos[0].lnum + lnum, FALSE), 2453 regmatch.startpos[0].lnum + lnum, 2454 regmatch.startpos[0].col + 1, 2455 FALSE, /* vis_col */ 2456 0, /* nr */ 2457 0, /* type */ 2458 TRUE /* valid */ 2459 ) == FAIL) 2460 { 2461 got_int = TRUE; 2462 break; 2463 } 2464 else 2465 found_match = TRUE; 2466 if ((flags & VGR_GLOBAL) == 0 2467 || regmatch.endpos[0].lnum > 0) 2468 break; 2469 col = regmatch.endpos[0].col 2470 + (col == regmatch.endpos[0].col); 2471 if (col > STRLEN(ml_get_buf(buf, lnum, FALSE))) 2472 break; 2473 } 2474 line_breakcheck(); 2475 if (got_int) 2476 break; 2477 } 2478 #ifdef HAVE_SETJMP_H 2479 jumpend: 2480 mch_endjmp(); 2481 #endif 2482 2483 if (using_dummy) 2484 { 2485 if (found_match && first_match_buf == NULL) 2486 first_match_buf = buf; 2487 if (duplicate_name) 2488 { 2489 /* Never keep a dummy buffer if there is another buffer 2490 * with the same name. */ 2491 wipe_dummy_buffer(buf); 2492 buf = NULL; 2493 } 2494 else if (!buf_hide(buf)) 2495 { 2496 /* When not hiding the buffer and no match was found we 2497 * don't need to remember the buffer, wipe it out. If 2498 * there was a match and it wasn't the first one or we 2499 * won't jump there: only unload the buffer. */ 2500 if (!found_match) 2501 { 2502 wipe_dummy_buffer(buf); 2503 buf = NULL; 2504 } 2505 else if (buf != first_match_buf || (flags & VGR_NOJUMP)) 2506 { 2507 unload_dummy_buffer(buf); 2508 buf = NULL; 2509 } 2510 } 2511 2512 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) 2513 if (buf != NULL) 2514 { 2515 /* The buffer is still loaded, the Filetype autocommands 2516 * need to be done now, in that buffer. And then the 2517 * modelines need to be done (again). */ 2518 aucmd_prepbuf(&aco, buf); 2519 apply_autocmds(EVENT_FILETYPE, buf->b_p_ft, 2520 buf->b_fname, TRUE, buf); 2521 do_modelines(FALSE); 2522 aucmd_restbuf(&aco); 2523 } 2524 #endif 2525 } 2526 } 2527 } 2528 2529 FreeWild(fcount, fnames); 2530 2531 qf_lists[qf_curlist].qf_nonevalid = FALSE; 2532 qf_lists[qf_curlist].qf_ptr = qf_lists[qf_curlist].qf_start; 2533 qf_lists[qf_curlist].qf_index = 1; 2534 2535 #ifdef FEAT_WINDOWS 2536 qf_update_buffer(); 2537 #endif 2538 2539 /* Jump to first match. */ 2540 if (qf_lists[qf_curlist].qf_count > 0) 2541 { 2542 if ((flags & VGR_NOJUMP) == 0) 2543 qf_jump(0, 0, eap->forceit); 2544 } 2545 else 2546 EMSG2(_(e_nomatch2), s); 2547 2548 #ifdef FEAT_AUTOCMD 2549 if (au_name != NULL) 2550 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, 2551 curbuf->b_fname, TRUE, curbuf); 2552 #endif 2553 2554 theend: 2555 vim_free(regmatch.regprog); 2556 } 2557 2558 /* 2559 * Skip over the pattern argument of ":vimgrep /pat/[g][j]". 2560 * Put the start of the pattern in "*s", unless "s" is NULL. 2561 * If "flags" is not NULL put the flags in it: VGR_GLOBAL, VGR_NOJUMP. 2562 * If "s" is not NULL terminate the pattern with a NUL. 2563 * Return a pointer to the char just past the pattern plus flags. 2564 */ 2565 char_u * 2566 skip_vimgrep_pat(p, s, flags) 2567 char_u *p; 2568 char_u **s; 2569 int *flags; 2570 { 2571 int c; 2572 2573 if (vim_isIDc(*p)) 2574 { 2575 /* ":vimgrep pattern fname" */ 2576 if (s != NULL) 2577 *s = p; 2578 p = skiptowhite(p); 2579 if (s != NULL && *p != NUL) 2580 *p++ = NUL; 2581 } 2582 else 2583 { 2584 /* ":vimgrep /pattern/[g][j] fname" */ 2585 if (s != NULL) 2586 *s = p + 1; 2587 c = *p; 2588 p = skip_regexp(p + 1, c, TRUE, NULL); 2589 if (*p != c) 2590 return NULL; 2591 2592 /* Truncate the pattern. */ 2593 if (s != NULL) 2594 *p = NUL; 2595 ++p; 2596 2597 /* Find the flags */ 2598 while (*p == 'g' || *p == 'j') 2599 { 2600 if (flags != NULL) 2601 { 2602 if (*p == 'g') 2603 *flags |= VGR_GLOBAL; 2604 else 2605 *flags |= VGR_NOJUMP; 2606 } 2607 ++p; 2608 } 2609 } 2610 return p; 2611 } 2612 2613 /* 2614 * Load file "fname" into a dummy buffer and return the buffer pointer. 2615 * Returns NULL if it fails. 2616 * Must call unload_dummy_buffer() or wipe_dummy_buffer() later! 2617 */ 2618 static buf_T * 2619 load_dummy_buffer(fname) 2620 char_u *fname; 2621 { 2622 buf_T *newbuf; 2623 int failed = TRUE; 2624 #ifdef FEAT_AUTOCMD 2625 aco_save_T aco; 2626 #else 2627 buf_T *old_curbuf = curbuf; 2628 #endif 2629 2630 /* Allocate a buffer without putting it in the buffer list. */ 2631 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); 2632 if (newbuf == NULL) 2633 return NULL; 2634 2635 /* Init the options. */ 2636 buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP); 2637 2638 #ifdef FEAT_AUTOCMD 2639 /* set curwin/curbuf to buf and save a few things */ 2640 aucmd_prepbuf(&aco, newbuf); 2641 #else 2642 curbuf = newbuf; 2643 curwin->w_buffer = newbuf; 2644 #endif 2645 2646 /* Need to set the filename for autocommands. */ 2647 (void)setfname(curbuf, fname, NULL, FALSE); 2648 2649 if (ml_open() == OK) 2650 { 2651 /* Create swap file now to avoid the ATTENTION message. */ 2652 check_need_swap(TRUE); 2653 2654 /* Remove the "dummy" flag, otherwise autocommands may not 2655 * work. */ 2656 curbuf->b_flags &= ~BF_DUMMY; 2657 2658 if (readfile(fname, NULL, 2659 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, 2660 NULL, READ_NEW | READ_DUMMY) == OK 2661 && !(curbuf->b_flags & BF_NEW)) 2662 { 2663 failed = FALSE; 2664 if (curbuf != newbuf) 2665 { 2666 /* Bloody autocommands changed the buffer! */ 2667 if (buf_valid(newbuf)) 2668 wipe_buffer(newbuf, FALSE); 2669 newbuf = curbuf; 2670 } 2671 } 2672 } 2673 2674 #ifdef FEAT_AUTOCMD 2675 /* restore curwin/curbuf and a few other things */ 2676 aucmd_restbuf(&aco); 2677 #else 2678 curbuf = old_curbuf; 2679 curwin->w_buffer = old_curbuf; 2680 #endif 2681 2682 if (!buf_valid(newbuf)) 2683 return NULL; 2684 if (failed) 2685 { 2686 wipe_dummy_buffer(newbuf); 2687 return NULL; 2688 } 2689 return newbuf; 2690 } 2691 2692 /* 2693 * Wipe out the dummy buffer that load_dummy_buffer() created. 2694 */ 2695 static void 2696 wipe_dummy_buffer(buf) 2697 buf_T *buf; 2698 { 2699 if (curbuf != buf) /* safety check */ 2700 wipe_buffer(buf, FALSE); 2701 } 2702 2703 /* 2704 * Unload the dummy buffer that load_dummy_buffer() created. 2705 */ 2706 static void 2707 unload_dummy_buffer(buf) 2708 buf_T *buf; 2709 { 2710 if (curbuf != buf) /* safety check */ 2711 close_buffer(NULL, buf, DOBUF_UNLOAD); 2712 } 2713 2714 #if defined(FEAT_EVAL) || defined(PROTO) 2715 /* 2716 * Add each quickfix error to list "list" as a dictionary. 2717 */ 2718 int 2719 get_errorlist(list) 2720 list_T *list; 2721 { 2722 dict_T *dict; 2723 char_u buf[2]; 2724 struct qf_line *qfp; 2725 int i; 2726 2727 if (qf_curlist >= qf_listcount || qf_lists[qf_curlist].qf_count == 0) 2728 { 2729 EMSG(_(e_quickfix)); 2730 return FAIL; 2731 } 2732 2733 qfp = qf_lists[qf_curlist].qf_start; 2734 for (i = 1; !got_int && i <= qf_lists[qf_curlist].qf_count; ++i) 2735 { 2736 if ((dict = dict_alloc()) == NULL) 2737 return FAIL; 2738 if (list_append_dict(list, dict) == FAIL) 2739 return FAIL; 2740 2741 buf[0] = qfp->qf_type; 2742 buf[1] = NUL; 2743 if ( dict_add_nr_str(dict, "bufnr", (long)qfp->qf_fnum, NULL) == FAIL 2744 || dict_add_nr_str(dict, "lnum", (long)qfp->qf_lnum, NULL) == FAIL 2745 || dict_add_nr_str(dict, "col", (long)qfp->qf_col, NULL) == FAIL 2746 || dict_add_nr_str(dict, "vcol", (long)qfp->qf_viscol, NULL) == FAIL 2747 || dict_add_nr_str(dict, "nr", (long)qfp->qf_nr, NULL) == FAIL 2748 || dict_add_nr_str(dict, "text", 0L, qfp->qf_text) == FAIL 2749 || dict_add_nr_str(dict, "type", 0L, buf) == FAIL 2750 || dict_add_nr_str(dict, "valid", (long)qfp->qf_valid, NULL) == FAIL) 2751 return FAIL; 2752 2753 qfp = qfp->qf_next; 2754 } 2755 return OK; 2756 } 2757 #endif 2758 2759 /* 2760 * ":[range]cbuffer [bufnr]" command. 2761 */ 2762 void 2763 ex_cbuffer(eap) 2764 exarg_T *eap; 2765 { 2766 buf_T *buf = NULL; 2767 2768 if (*eap->arg == NUL) 2769 buf = curbuf; 2770 else if (*skipwhite(skipdigits(eap->arg)) == NUL) 2771 buf = buflist_findnr(atoi((char *)eap->arg)); 2772 if (buf == NULL) 2773 EMSG(_(e_invarg)); 2774 else if (buf->b_ml.ml_mfp == NULL) 2775 EMSG(_("E681: Buffer is not loaded")); 2776 else 2777 { 2778 if (eap->addr_count == 0) 2779 { 2780 eap->line1 = 1; 2781 eap->line2 = buf->b_ml.ml_line_count; 2782 } 2783 if (eap->line1 < 1 || eap->line1 > buf->b_ml.ml_line_count 2784 || eap->line2 < 1 || eap->line2 > buf->b_ml.ml_line_count) 2785 EMSG(_(e_invrange)); 2786 else 2787 qf_init_ext(NULL, buf, p_efm, TRUE, eap->line1, eap->line2); 2788 } 2789 } 2790 2791 /* 2792 * ":helpgrep {pattern}" 2793 */ 2794 void 2795 ex_helpgrep(eap) 2796 exarg_T *eap; 2797 { 2798 regmatch_T regmatch; 2799 char_u *save_cpo; 2800 char_u *p; 2801 int fcount; 2802 char_u **fnames; 2803 FILE *fd; 2804 int fi; 2805 struct qf_line *prevp = NULL; 2806 long lnum; 2807 #ifdef FEAT_MULTI_LANG 2808 char_u *lang; 2809 #endif 2810 2811 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ 2812 save_cpo = p_cpo; 2813 p_cpo = (char_u *)""; 2814 2815 #ifdef FEAT_MULTI_LANG 2816 /* Check for a specified language */ 2817 lang = check_help_lang(eap->arg); 2818 #endif 2819 2820 regmatch.regprog = vim_regcomp(eap->arg, RE_MAGIC + RE_STRING); 2821 regmatch.rm_ic = FALSE; 2822 if (regmatch.regprog != NULL) 2823 { 2824 /* create a new quickfix list */ 2825 qf_new_list(); 2826 2827 /* Go through all directories in 'runtimepath' */ 2828 p = p_rtp; 2829 while (*p != NUL && !got_int) 2830 { 2831 copy_option_part(&p, NameBuff, MAXPATHL, ","); 2832 2833 /* Find all "*.txt" and "*.??x" files in the "doc" directory. */ 2834 add_pathsep(NameBuff); 2835 STRCAT(NameBuff, "doc/*.\\(txt\\|??x\\)"); 2836 if (gen_expand_wildcards(1, &NameBuff, &fcount, 2837 &fnames, EW_FILE|EW_SILENT) == OK 2838 && fcount > 0) 2839 { 2840 for (fi = 0; fi < fcount && !got_int; ++fi) 2841 { 2842 #ifdef FEAT_MULTI_LANG 2843 /* Skip files for a different language. */ 2844 if (lang != NULL 2845 && STRNICMP(lang, fnames[fi] 2846 + STRLEN(fnames[fi]) - 3, 2) != 0 2847 && !(STRNICMP(lang, "en", 2) == 0 2848 && STRNICMP("txt", fnames[fi] 2849 + STRLEN(fnames[fi]) - 3, 3) == 0)) 2850 continue; 2851 #endif 2852 fd = fopen((char *)fnames[fi], "r"); 2853 if (fd != NULL) 2854 { 2855 lnum = 1; 2856 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) 2857 { 2858 if (vim_regexec(®match, IObuff, (colnr_T)0)) 2859 { 2860 int l = STRLEN(IObuff); 2861 2862 /* remove trailing CR, LF, spaces, etc. */ 2863 while (l > 0 && IObuff[l - 1] <= ' ') 2864 IObuff[--l] = NUL; 2865 2866 if (qf_add_entry(&prevp, 2867 NULL, /* dir */ 2868 fnames[fi], 2869 IObuff, 2870 lnum, 2871 (int)(regmatch.startp[0] - IObuff) 2872 + 1, /* col */ 2873 FALSE, /* vis_col */ 2874 0, /* nr */ 2875 1, /* type */ 2876 TRUE /* valid */ 2877 ) == FAIL) 2878 { 2879 got_int = TRUE; 2880 break; 2881 } 2882 } 2883 ++lnum; 2884 line_breakcheck(); 2885 } 2886 fclose(fd); 2887 } 2888 } 2889 FreeWild(fcount, fnames); 2890 } 2891 } 2892 vim_free(regmatch.regprog); 2893 2894 qf_lists[qf_curlist].qf_nonevalid = FALSE; 2895 qf_lists[qf_curlist].qf_ptr = qf_lists[qf_curlist].qf_start; 2896 qf_lists[qf_curlist].qf_index = 1; 2897 } 2898 2899 p_cpo = save_cpo; 2900 2901 #ifdef FEAT_WINDOWS 2902 qf_update_buffer(); 2903 #endif 2904 2905 /* Jump to first match. */ 2906 if (qf_lists[qf_curlist].qf_count > 0) 2907 qf_jump(0, 0, FALSE); 2908 else 2909 EMSG2(_(e_nomatch2), eap->arg); 2910 } 2911 2912 #endif /* FEAT_QUICKFIX */ 2913