~ubuntu-branches/debian/sid/neovim/sid

« back to all changes in this revision

Viewing changes to src/nvim/quickfix.c

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2016-04-18 21:42:19 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20160418214219-1e6d4o1fwqarzk46
Tags: 0.1.3-1
* New upstream release.  (Closes: #820562)
* debian/control:
  + Remove unnecessary luarocks Build-Depends
  + Add libkvm-dev Build-Depends for kfreebsd-*
  + Add python(3)-neovim to Recommends.  (Closes: #812737)
  + Declare compiance with policy 3.9.8, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
200
200
  char_u          *pattern;
201
201
  char_u          *fmtstr = NULL;
202
202
  int col = 0;
203
 
  char_u use_viscol = FALSE;
204
 
  int type = 0;
205
 
  int valid;
 
203
  bool use_viscol = false;
 
204
  char_u type = 0;
206
205
  linenr_T buflnum = lnumfirst;
207
206
  long lnum = 0L;
208
207
  int enr = 0;
220
219
  int i;
221
220
  int round;
222
221
  int idx = 0;
223
 
  int multiline = FALSE;
224
 
  int multiignore = FALSE;
225
 
  int multiscan = FALSE;
226
 
  int retval = -1;                      /* default: return error flag */
227
 
  char_u          *directory = NULL;
228
 
  char_u          *currfile = NULL;
229
 
  char_u          *tail = NULL;
230
 
  char_u          *p_str = NULL;
231
 
  listitem_T      *p_li = NULL;
232
 
  struct dir_stack_T  *file_stack = NULL;
 
222
  bool multiline = false;
 
223
  bool multiignore = false;
 
224
  bool multiscan = false;
 
225
  int retval = -1;                      // default: return error flag
 
226
  char_u *directory = NULL;
 
227
  char_u *currfile = NULL;
 
228
  char_u *tail = NULL;
 
229
  char_u *p_str = NULL;
 
230
  listitem_T *p_li = NULL;
 
231
  struct dir_stack_T *file_stack = NULL;
233
232
  regmatch_T regmatch;
234
233
  static struct fmtpattern {
235
234
    char_u convchar;
278
277
  /*
279
278
   * Get some space to modify the format string into.
280
279
   */
281
 
  i = 3 * FMT_PATTERNS + 4 * (int)STRLEN(efm);
282
 
  for (round = FMT_PATTERNS; round > 0; )
283
 
    i += (int)STRLEN(fmt_pat[--round].pattern);
 
280
  size_t fmtstr_size = 3 * FMT_PATTERNS + 4 * STRLEN(efm);
 
281
  for (round = FMT_PATTERNS; round > 0; ) {
 
282
    fmtstr_size += STRLEN(fmt_pat[--round].pattern);
 
283
  }
284
284
#ifdef COLON_IN_FILENAME
285
 
  i += 12;   /* "%f" can become twelve chars longer */
 
285
  fmtstr_size += 12;  // "%f" can become twelve chars longer
286
286
#else
287
 
  i += 2;   /* "%f" can become two chars longer */
 
287
  fmtstr_size += 2;   // "%f" can become two chars longer
288
288
#endif
289
 
  fmtstr = xmalloc(i);
 
289
  fmtstr = xmalloc(fmtstr_size);
290
290
 
291
291
  while (efm[0] != NUL) {
292
292
    /*
530
530
      fmt_start = NULL;
531
531
    }
532
532
 
533
 
    /*
534
 
     * Try to match each part of 'errorformat' until we find a complete
535
 
     * match or no match.
536
 
     */
537
 
    valid = TRUE;
 
533
    // Try to match each part of 'errorformat' until we find a complete
 
534
    // match or no match.
 
535
    bool valid = true;
538
536
restofline:
539
537
    for (; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next) {
540
538
      idx = fmt_ptr->prefix;
546
544
        errmsg[0] = NUL;
547
545
      lnum = 0;
548
546
      col = 0;
549
 
      use_viscol = FALSE;
 
547
      use_viscol = false;
550
548
      enr = -1;
551
549
      type = 0;
552
550
      tail = NULL;
555
553
      int r = vim_regexec(&regmatch, IObuff, (colnr_T)0);
556
554
      fmt_ptr->prog = regmatch.regprog;
557
555
      if (r) {
558
 
        if ((idx == 'C' || idx == 'Z') && !multiline)
 
556
        if ((idx == 'C' || idx == 'Z') && !multiline) {
559
557
          continue;
560
 
        if (vim_strchr((char_u *)"EWI", idx) != NULL)
561
 
          type = idx;
562
 
        else
 
558
        }
 
559
        if (vim_strchr((char_u *)"EWI", idx) != NULL) {
 
560
          type = (char_u)idx;
 
561
        } else {
563
562
          type = 0;
564
 
        /*
565
 
         * Extract error message data from matched line.
566
 
         * We check for an actual submatch, because "\[" and "\]" in
567
 
         * the 'errorformat' may cause the wrong submatch to be used.
568
 
         */
569
 
        if ((i = (int)fmt_ptr->addr[0]) > 0) {                  /* %f */
570
 
          int c;
571
 
 
572
 
          if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL)
 
563
        }
 
564
        // Extract error message data from matched line.
 
565
        // We check for an actual submatch, because "\[" and "\]" in
 
566
        // the 'errorformat' may cause the wrong submatch to be used.
 
567
        if ((i = (int)fmt_ptr->addr[0]) > 0) {  // %f
 
568
          if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) {
573
569
            continue;
574
 
 
575
 
          /* Expand ~/file and $HOME/file to full path. */
576
 
          c = *regmatch.endp[i];
 
570
          }
 
571
          // Expand ~/file and $HOME/file to full path.
 
572
          char_u c = *regmatch.endp[i];
577
573
          *regmatch.endp[i] = NUL;
578
574
          expand_env(regmatch.startp[i], namebuf, CMDBUFFSIZE);
579
575
          *regmatch.endp[i] = c;
629
625
              col -= col % 8;
630
626
            }
631
627
          }
632
 
          ++col;
633
 
          use_viscol = TRUE;
 
628
          col++;
 
629
          use_viscol = true;
634
630
        }
635
631
        if ((i = (int)fmt_ptr->addr[8]) > 0) {                  /* %v */
636
632
          if (regmatch.startp[i] == NULL)
637
633
            continue;
638
634
          col = (int)atol((char *)regmatch.startp[i]);
639
 
          use_viscol = TRUE;
 
635
          use_viscol = true;
640
636
        }
641
637
        if ((i = (int)fmt_ptr->addr[9]) > 0) {                  /* %s */
642
638
          if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL)
653
649
        break;
654
650
      }
655
651
    }
656
 
    multiscan = FALSE;
 
652
    multiscan = false;
657
653
 
658
654
    if (fmt_ptr == NULL || idx == 'D' || idx == 'X') {
659
655
      if (fmt_ptr != NULL) {
667
663
        } else if (idx == 'X')                          /* leave directory */
668
664
          directory = qf_pop_dir(&dir_stack);
669
665
      }
670
 
      namebuf[0] = NUL;                 /* no match found, remove file name */
671
 
      lnum = 0;                         /* don't jump to this line */
672
 
      valid = FALSE;
673
 
      STRCPY(errmsg, IObuff);           /* copy whole line to error message */
674
 
      if (fmt_ptr == NULL)
675
 
        multiline = multiignore = FALSE;
 
666
      namebuf[0] = NUL;                 // no match found, remove file name
 
667
      lnum = 0;                         // don't jump to this line
 
668
      valid = false;
 
669
      STRCPY(errmsg, IObuff);           // copy whole line to error message
 
670
      if (fmt_ptr == NULL) {
 
671
        multiline = multiignore = false;
 
672
      }
676
673
    } else if (fmt_ptr != NULL) {
677
674
      /* honor %> item */
678
675
      if (fmt_ptr->conthere)
679
676
        fmt_start = fmt_ptr;
680
677
 
681
678
      if (vim_strchr((char_u *)"AEWI", idx) != NULL) {
682
 
        multiline = TRUE;    /* start of a multi-line message */
683
 
        multiignore = FALSE; /* reset continuation */
 
679
        multiline = true;     // start of a multi-line message
 
680
        multiignore = false;  // reset continuation
684
681
      } else if (vim_strchr((char_u *)"CZ", idx)
685
682
                 != NULL) { /* continuation of multi-line msg */
686
683
        if (qfprev == NULL)
702
699
        qfprev->qf_viscol = use_viscol;
703
700
        if (!qfprev->qf_fnum)
704
701
          qfprev->qf_fnum = qf_get_fnum(directory,
705
 
              *namebuf || directory ? namebuf
706
 
              : currfile && valid ? currfile : 0);
707
 
        if (idx == 'Z')
708
 
          multiline = multiignore = FALSE;
 
702
                                        *namebuf
 
703
                                        || directory ? namebuf : currfile
 
704
                                        && valid ? currfile : 0);
 
705
        if (idx == 'Z') {
 
706
          multiline = multiignore = false;
 
707
        }
709
708
        line_breakcheck();
710
709
        continue;
711
710
      } else if (vim_strchr((char_u *)"OPQ", idx) != NULL) {
712
 
        /* global file names */
713
 
        valid = FALSE;
 
711
        // global file names
 
712
        valid = false;
714
713
        if (*namebuf == NUL || os_file_exists(namebuf)) {
715
714
          if (*namebuf && idx == 'P')
716
715
            currfile = qf_push_dir(namebuf, &file_stack);
719
718
          *namebuf = NUL;
720
719
          if (tail && *tail) {
721
720
            STRMOVE(IObuff, skipwhite(tail));
722
 
            multiscan = TRUE;
 
721
            multiscan = true;
723
722
            goto restofline;
724
723
          }
725
724
        }
726
725
      }
727
 
      if (fmt_ptr->flags == '-') {      /* generally exclude this line */
728
 
        if (multiline)
729
 
          multiignore = TRUE;           /* also exclude continuation lines */
 
726
      if (fmt_ptr->flags == '-') {  // generally exclude this line
 
727
        if (multiline) {
 
728
          multiignore = true;       // also exclude continuation lines
 
729
        }
730
730
        continue;
731
731
      }
732
732
    }
867
867
      qf_free(qi, i);
868
868
}
869
869
 
870
 
/*
871
 
 * Add an entry to the end of the list of errors.
872
 
 * Returns OK or FAIL.
873
 
 */
874
 
static int 
875
 
qf_add_entry (
876
 
    qf_info_T *qi,                /* quickfix list */
877
 
    qfline_T **prevp,            /* nonnull pointer (to previously added entry or NULL) */
878
 
    char_u *dir,               /* optional directory name */
879
 
    char_u *fname,             /* file name or NULL */
880
 
    int bufnum,                     /* buffer number or zero */
881
 
    char_u *mesg,              /* message */
882
 
    long lnum,                      /* line number */
883
 
    int col,                        /* column */
884
 
    int vis_col,                    /* using visual column */
885
 
    char_u *pattern,           /* search pattern */
886
 
    int nr,                         /* error number */
887
 
    int type,                       /* type character */
888
 
    int valid                      /* valid entry */
889
 
)
 
870
/// Add an entry to the end of the list of errors.
 
871
///
 
872
/// @param  qi       quickfix list
 
873
/// @param  prevp    nonnull pointer (to previously added entry or NULL)
 
874
/// @param  dir      optional directory name
 
875
/// @param  fname    file name or NULL
 
876
/// @param  bufnum   buffer number or zero
 
877
/// @param  mesg     message
 
878
/// @param  lnum     line number
 
879
/// @param  col      column
 
880
/// @param  vis_col  using visual column
 
881
/// @param  pattern  search pattern
 
882
/// @param  nr       error number
 
883
/// @param  type     type character
 
884
/// @param  valid    valid entry
 
885
///
 
886
/// @returns OK or FAIL.
 
887
static int qf_add_entry(qf_info_T *qi, qfline_T **prevp, char_u *dir,
 
888
                        char_u *fname, int bufnum, char_u *mesg, long lnum,
 
889
                        int col, char_u vis_col, char_u *pattern, int nr,
 
890
                        char_u type, char_u valid)
890
891
{
891
892
  qfline_T *qfp = xmalloc(sizeof(qfline_T));
892
893
 
1657
1658
       * flag is present in 'shortmess'; But when not jumping, print the
1658
1659
       * whole message. */
1659
1660
      i = msg_scroll;
1660
 
      if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum)
1661
 
        msg_scroll = TRUE;
1662
 
      else if (!msg_scrolled && shortmess(SHM_OVERALL))
1663
 
        msg_scroll = FALSE;
1664
 
      msg_attr_keep(IObuff, 0, TRUE);
1665
 
      msg_scroll = i;
 
1661
      if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum) {
 
1662
        msg_scroll = true;
 
1663
      } else if (!msg_scrolled && shortmess(SHM_OVERALL)) {
 
1664
        msg_scroll = false;
 
1665
      }
 
1666
      msg_attr_keep(IObuff, 0, true);
 
1667
      msg_scroll = (int)i;
1666
1668
    }
1667
1669
  } else {
1668
1670
    if (opened_window)
1827
1829
    }
1828
1830
  }
1829
1831
 
1830
 
  if (eap->addr_count != 0)
1831
 
    count = eap->line2;
1832
 
  else
 
1832
  if (eap->addr_count != 0) {
 
1833
    assert(eap->line2 <= INT_MAX);
 
1834
    count = (int)eap->line2;
 
1835
  } else {
1833
1836
    count = 1;
 
1837
  }
1834
1838
  while (count--) {
1835
1839
    if (eap->cmdidx == CMD_colder || eap->cmdidx == CMD_lolder) {
1836
1840
      if (qi->qf_curlist == 0) {
1882
1886
    --qi->qf_lists[idx].qf_count;
1883
1887
  }
1884
1888
  xfree(qi->qf_lists[idx].qf_title);
 
1889
  qi->qf_lists[idx].qf_start = NULL;
 
1890
  qi->qf_lists[idx].qf_ptr = NULL;
1885
1891
  qi->qf_lists[idx].qf_title = NULL;
1886
1892
  qi->qf_lists[idx].qf_index = 0;
1887
1893
}
1948
1954
    p = (char_u *)"";
1949
1955
  else {
1950
1956
    cc[0] = ' ';
1951
 
    cc[1] = c;
 
1957
    cc[1] = (char_u)c;
1952
1958
    cc[2] = NUL;
1953
1959
    p = cc;
1954
1960
  }
2036
2042
    }
2037
2043
  }
2038
2044
 
2039
 
  if (eap->addr_count != 0)
2040
 
    height = eap->line2;
2041
 
  else
 
2045
  if (eap->addr_count != 0) {
 
2046
    assert(eap->line2 <= INT_MAX);
 
2047
    height = (int)eap->line2;
 
2048
  } else {
2042
2049
    height = QF_WINHEIGHT;
2043
 
 
2044
 
  reset_VIsual_and_resel();                     /* stop Visual mode */
 
2050
  }
 
2051
  reset_VIsual_and_resel();  // stop Visual mode
2045
2052
 
2046
2053
  /*
2047
2054
   * Find existing quickfix window, or open a new one.
2299
2306
      if (qfp->qf_fnum != 0
2300
2307
          && (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL
2301
2308
          && errbuf->b_fname != NULL) {
2302
 
        if (qfp->qf_type == 1)          /* :helpgrep */
2303
 
          STRCPY(IObuff, path_tail(errbuf->b_fname));
2304
 
        else
2305
 
          STRCPY(IObuff, errbuf->b_fname);
 
2309
        if (qfp->qf_type == 1) {  // :helpgrep
 
2310
          STRLCPY(IObuff, path_tail(errbuf->b_fname), sizeof(IObuff));
 
2311
        } else {
 
2312
          STRLCPY(IObuff, errbuf->b_fname, sizeof(IObuff));
 
2313
        }
2306
2314
        len = (int)STRLEN(IObuff);
2307
 
      } else
 
2315
      } else {
2308
2316
        len = 0;
 
2317
      }
2309
2318
      IObuff[len++] = '|';
2310
2319
 
2311
2320
      if (qfp->qf_lnum > 0) {
2432
2441
{
2433
2442
  char_u      *fname;
2434
2443
  char_u      *cmd;
2435
 
  unsigned len;
 
2444
  size_t len;
2436
2445
  win_T       *wp = NULL;
2437
2446
  qf_info_T   *qi = &ql_info;
2438
2447
  int res;
2473
2482
  /*
2474
2483
   * If 'shellpipe' empty: don't redirect to 'errorfile'.
2475
2484
   */
2476
 
  len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(eap->arg) + 1;
2477
 
  if (*p_sp != NUL)
2478
 
    len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3;
 
2485
  len = STRLEN(p_shq) * 2 + STRLEN(eap->arg) + 1;
 
2486
  if (*p_sp != NUL) {
 
2487
    len += STRLEN(p_sp) + STRLEN(fname) + 3;
 
2488
  }
2479
2489
  cmd = xmalloc(len);
2480
2490
  sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg,
2481
2491
      (char *)p_shq);
2546
2556
 
2547
2557
  /* Keep trying until the name doesn't exist yet. */
2548
2558
  for (;; ) {
2549
 
    if (start == -1)
2550
 
      start = os_get_pid();
2551
 
    else
 
2559
    if (start == -1) {
 
2560
      start = (int)os_get_pid();
 
2561
    } else {
2552
2562
      off += 19;
2553
 
 
 
2563
    }
2554
2564
    name = xmalloc(STRLEN(p_mef) + 30);
2555
2565
    STRCPY(name, p_mef);
2556
2566
    sprintf((char *)name + (p - p_mef), "%d%d", start, off);
2897
2907
  int found_match;
2898
2908
  buf_T       *first_match_buf = NULL;
2899
2909
  time_t seconds = 0;
2900
 
  int save_mls;
 
2910
  long save_mls;
2901
2911
  char_u      *save_ei = NULL;
2902
2912
  aco_save_T aco;
2903
2913
  int flags = 0;
3454
3464
 */
3455
3465
int set_errorlist(win_T *wp, list_T *list, int action, char_u *title)
3456
3466
{
3457
 
  listitem_T  *li;
3458
 
  dict_T      *d;
3459
 
  char_u      *filename, *pattern, *text, *type;
3460
 
  int bufnum;
3461
 
  long lnum;
3462
 
  int col, nr;
3463
 
  int vcol;
3464
 
  qfline_T    *prevp = NULL;
3465
 
  int valid, status;
 
3467
  listitem_T *li;
 
3468
  dict_T *d;
 
3469
  qfline_T *prevp = NULL;
3466
3470
  int retval = OK;
3467
 
  qf_info_T   *qi = &ql_info;
3468
 
  int did_bufnr_emsg = FALSE;
 
3471
  qf_info_T *qi = &ql_info;
 
3472
  bool did_bufnr_emsg = false;
3469
3473
 
3470
3474
  if (wp != NULL) {
3471
3475
    qi = ll_get_or_alloc_list(wp);
3492
3496
    if (d == NULL)
3493
3497
      continue;
3494
3498
 
3495
 
    filename = get_dict_string(d, (char_u *)"filename", TRUE);
3496
 
    bufnum = get_dict_number(d, (char_u *)"bufnr");
3497
 
    lnum = get_dict_number(d, (char_u *)"lnum");
3498
 
    col = get_dict_number(d, (char_u *)"col");
3499
 
    vcol = get_dict_number(d, (char_u *)"vcol");
3500
 
    nr = get_dict_number(d, (char_u *)"nr");
3501
 
    type = get_dict_string(d, (char_u *)"type", TRUE);
3502
 
    pattern = get_dict_string(d, (char_u *)"pattern", TRUE);
3503
 
    text = get_dict_string(d, (char_u *)"text", TRUE);
3504
 
    if (text == NULL)
 
3499
    char_u *filename = get_dict_string(d, (char_u *)"filename", true);
 
3500
    int bufnum = (int)get_dict_number(d, (char_u *)"bufnr");
 
3501
    long lnum = get_dict_number(d, (char_u *)"lnum");
 
3502
    int col = (int)get_dict_number(d, (char_u *)"col");
 
3503
    char_u vcol = (char_u)get_dict_number(d, (char_u *)"vcol");
 
3504
    int nr = (int)get_dict_number(d, (char_u *)"nr");
 
3505
    char_u *type = get_dict_string(d, (char_u *)"type", true);
 
3506
    char_u *pattern = get_dict_string(d, (char_u *)"pattern", true);
 
3507
    char_u *text = get_dict_string(d, (char_u *)"text", true);
 
3508
    if (text == NULL) {
3505
3509
      text = vim_strsave((char_u *)"");
3506
 
 
3507
 
    valid = TRUE;
3508
 
    if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL))
3509
 
      valid = FALSE;
 
3510
    }
 
3511
    bool valid = true;
 
3512
    if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL)) {
 
3513
      valid = false;
 
3514
    }
3510
3515
 
3511
3516
    /* Mark entries with non-existing buffer number as not valid. Give the
3512
3517
     * error message only once. */
3515
3520
        did_bufnr_emsg = TRUE;
3516
3521
        EMSGN(_("E92: Buffer %" PRId64 " not found"), bufnum);
3517
3522
      }
3518
 
      valid = FALSE;
 
3523
      valid = false;
3519
3524
      bufnum = 0;
3520
3525
    }
3521
3526
 
3522
 
    status =  qf_add_entry(qi, &prevp,
3523
 
        NULL,                               /* dir */
3524
 
        filename,
3525
 
        bufnum,
3526
 
        text,
3527
 
        lnum,
3528
 
        col,
3529
 
        vcol,                               /* vis_col */
3530
 
        pattern,                            /* search pattern */
3531
 
        nr,
3532
 
        type == NULL ? NUL : *type,
3533
 
        valid);
 
3527
    int status = qf_add_entry(qi,
 
3528
                              &prevp,
 
3529
                              NULL,      // dir
 
3530
                              filename,
 
3531
                              bufnum,
 
3532
                              text,
 
3533
                              lnum,
 
3534
                              col,
 
3535
                              vcol,      // vis_col
 
3536
                              pattern,   // search pattern
 
3537
                              nr,
 
3538
                              (char_u)(type == NULL ? NUL : *type),
 
3539
                              valid);
3534
3540
 
3535
3541
    xfree(filename);
3536
3542
    xfree(pattern);