blob: fec27fa8b49c4eb95057cf5fd0fdc2a5b1109c1a [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* 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
18struct dir_stack_T
19{
20 struct dir_stack_T *next;
21 char_u *dirname;
22};
23
24static struct dir_stack_T *dir_stack = NULL;
25
26/*
Bram Moolenaar68b76a62005-03-25 21:53:48 +000027 * For each error the next struct is allocated and linked in a list.
Bram Moolenaar071d4272004-06-13 20:20:40 +000028 */
Bram Moolenaar68b76a62005-03-25 21:53:48 +000029typedef struct qfline_S qfline_T;
30struct qfline_S
Bram Moolenaar071d4272004-06-13 20:20:40 +000031{
Bram Moolenaar68b76a62005-03-25 21:53:48 +000032 qfline_T *qf_next; /* pointer to next error in the list */
33 qfline_T *qf_prev; /* pointer to previous error in the list */
34 linenr_T qf_lnum; /* line number where the error occurred */
35 int qf_fnum; /* file number for the line */
36 int qf_col; /* column where the error occurred */
37 int qf_nr; /* error number */
38 char_u *qf_pattern; /* search pattern for the error */
39 char_u *qf_text; /* description of the error */
40 char_u qf_viscol; /* set to TRUE if qf_col is screen column */
41 char_u qf_cleared; /* set to TRUE if line has been deleted */
42 char_u qf_type; /* type of the error (mostly 'E'); 1 for
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 :helpgrep */
Bram Moolenaar68b76a62005-03-25 21:53:48 +000044 char_u qf_valid; /* valid error message detected */
Bram Moolenaar071d4272004-06-13 20:20:40 +000045};
46
47/*
48 * There is a stack of error lists.
49 */
50#define LISTCOUNT 10
51
Bram Moolenaard12f5c12006-01-25 22:10:52 +000052typedef struct qf_list_S
Bram Moolenaar071d4272004-06-13 20:20:40 +000053{
Bram Moolenaar68b76a62005-03-25 21:53:48 +000054 qfline_T *qf_start; /* pointer to the first error */
55 qfline_T *qf_ptr; /* pointer to the current error */
56 int qf_count; /* number of errors (0 means no error list) */
57 int qf_index; /* current index in the error list */
58 int qf_nonevalid; /* TRUE if not a single valid entry found */
Bram Moolenaar7fd73202010-07-25 16:58:46 +020059 char_u *qf_title; /* title derived from the command that created
60 * the error list */
Bram Moolenaard12f5c12006-01-25 22:10:52 +000061} qf_list_T;
Bram Moolenaar071d4272004-06-13 20:20:40 +000062
Bram Moolenaard12f5c12006-01-25 22:10:52 +000063struct qf_info_S
64{
65 /*
66 * Count of references to this list. Used only for location lists.
67 * When a location list window reference this list, qf_refcount
68 * will be 2. Otherwise, qf_refcount will be 1. When qf_refcount
69 * reaches 0, the list is freed.
70 */
71 int qf_refcount;
72 int qf_listcount; /* current number of lists */
73 int qf_curlist; /* current error list */
74 qf_list_T qf_lists[LISTCOUNT];
75};
76
77static qf_info_T ql_info; /* global quickfix list */
Bram Moolenaar071d4272004-06-13 20:20:40 +000078
Bram Moolenaar68b76a62005-03-25 21:53:48 +000079#define FMT_PATTERNS 10 /* maximum number of % recognized */
Bram Moolenaar071d4272004-06-13 20:20:40 +000080
81/*
82 * Structure used to hold the info of one part of 'errorformat'
83 */
Bram Moolenaar01265852006-03-20 21:50:15 +000084typedef struct efm_S efm_T;
85struct efm_S
Bram Moolenaar071d4272004-06-13 20:20:40 +000086{
87 regprog_T *prog; /* pre-formatted part of 'errorformat' */
Bram Moolenaar01265852006-03-20 21:50:15 +000088 efm_T *next; /* pointer to next (NULL if last) */
Bram Moolenaar071d4272004-06-13 20:20:40 +000089 char_u addr[FMT_PATTERNS]; /* indices of used % patterns */
90 char_u prefix; /* prefix of this format line: */
91 /* 'D' enter directory */
92 /* 'X' leave directory */
93 /* 'A' start of multi-line message */
94 /* 'E' error message */
95 /* 'W' warning message */
96 /* 'I' informational message */
97 /* 'C' continuation line */
98 /* 'Z' end of multi-line message */
99 /* 'G' general, unspecific message */
100 /* 'P' push file (partial) message */
101 /* 'Q' pop/quit file (partial) message */
102 /* 'O' overread (partial) message */
103 char_u flags; /* additional flags given in prefix */
104 /* '-' do not include this line */
Bram Moolenaar4770d092006-01-12 23:22:24 +0000105 /* '+' include whole line in message */
Bram Moolenaar01265852006-03-20 21:50:15 +0000106 int conthere; /* %> used */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107};
108
Bram Moolenaar7fd73202010-07-25 16:58:46 +0200109static int qf_init_ext __ARGS((qf_info_T *qi, char_u *efile, buf_T *buf, typval_T *tv, char_u *errorformat, int newlist, linenr_T lnumfirst, linenr_T lnumlast, char_u *qf_title));
Bram Moolenaar41b884b2012-11-14 22:38:08 +0100110static void qf_new_list __ARGS((qf_info_T *qi, char_u *qf_title, win_T *wp));
Bram Moolenaard9ff7d52008-03-20 12:23:49 +0000111static void ll_free_all __ARGS((qf_info_T **pqi));
Bram Moolenaar48b66fb2007-02-04 01:58:18 +0000112static int qf_add_entry __ARGS((qf_info_T *qi, qfline_T **prevp, char_u *dir, char_u *fname, int bufnum, char_u *mesg, long lnum, int col, int vis_col, char_u *pattern, int nr, int type, int valid));
Bram Moolenaard9ff7d52008-03-20 12:23:49 +0000113static qf_info_T *ll_new_list __ARGS((void));
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000114static void qf_msg __ARGS((qf_info_T *qi));
115static void qf_free __ARGS((qf_info_T *qi, int idx));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116static char_u *qf_types __ARGS((int, int));
117static int qf_get_fnum __ARGS((char_u *, char_u *));
118static char_u *qf_push_dir __ARGS((char_u *, struct dir_stack_T **));
119static char_u *qf_pop_dir __ARGS((struct dir_stack_T **));
120static char_u *qf_guess_filepath __ARGS((char_u *));
121static void qf_fmt_text __ARGS((char_u *text, char_u *buf, int bufsize));
122static void qf_clean_dir_stack __ARGS((struct dir_stack_T **));
123#ifdef FEAT_WINDOWS
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000124static int qf_win_pos_update __ARGS((qf_info_T *qi, int old_qf_index));
Bram Moolenaar9c102382006-05-03 21:26:49 +0000125static int is_qf_win __ARGS((win_T *win, qf_info_T *qi));
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000126static win_T *qf_find_win __ARGS((qf_info_T *qi));
127static buf_T *qf_find_buf __ARGS((qf_info_T *qi));
128static void qf_update_buffer __ARGS((qf_info_T *qi));
Bram Moolenaarc95e3262011-08-10 18:36:54 +0200129static void qf_set_title __ARGS((qf_info_T *qi));
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000130static void qf_fill_buffer __ARGS((qf_info_T *qi));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131#endif
132static char_u *get_mef_name __ARGS((void));
Bram Moolenaar7f51a822012-04-25 18:57:21 +0200133static void restore_start_dir __ARGS((char_u *dirname_start));
134static buf_T *load_dummy_buffer __ARGS((char_u *fname, char_u *dirname_start, char_u *resulting_dir));
135static void wipe_dummy_buffer __ARGS((buf_T *buf, char_u *dirname_start));
136static void unload_dummy_buffer __ARGS((buf_T *buf, char_u *dirname_start));
Bram Moolenaarc7453f52006-02-10 23:20:28 +0000137static qf_info_T *ll_get_or_alloc_list __ARGS((win_T *));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000139/* Quickfix window check helper macro */
140#define IS_QF_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref == NULL)
141/* Location list window check helper macro */
142#define IS_LL_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL)
143/*
144 * Return location list for window 'wp'
145 * For location list window, return the referenced location list
146 */
147#define GET_LOC_LIST(wp) (IS_LL_WINDOW(wp) ? wp->w_llist_ref : wp->w_llist)
148
Bram Moolenaar071d4272004-06-13 20:20:40 +0000149/*
Bram Moolenaar86b68352004-12-27 21:59:20 +0000150 * Read the errorfile "efile" into memory, line by line, building the error
Bram Moolenaar7fd73202010-07-25 16:58:46 +0200151 * list. Set the error list's title to qf_title.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000152 * Return -1 for error, number of errors for success.
153 */
154 int
Bram Moolenaar7fd73202010-07-25 16:58:46 +0200155qf_init(wp, efile, errorformat, newlist, qf_title)
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000156 win_T *wp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157 char_u *efile;
158 char_u *errorformat;
159 int newlist; /* TRUE: start a new error list */
Bram Moolenaar7fd73202010-07-25 16:58:46 +0200160 char_u *qf_title;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000161{
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000162 qf_info_T *qi = &ql_info;
163
Bram Moolenaar86b68352004-12-27 21:59:20 +0000164 if (efile == NULL)
165 return FAIL;
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000166
167 if (wp != NULL)
Bram Moolenaarc7453f52006-02-10 23:20:28 +0000168 {
169 qi = ll_get_or_alloc_list(wp);
170 if (qi == NULL)
171 return FAIL;
172 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000173
174 return qf_init_ext(qi, efile, curbuf, NULL, errorformat, newlist,
Bram Moolenaar7fd73202010-07-25 16:58:46 +0200175 (linenr_T)0, (linenr_T)0,
176 qf_title);
Bram Moolenaar86b68352004-12-27 21:59:20 +0000177}
178
179/*
180 * Read the errorfile "efile" into memory, line by line, building the error
181 * list.
182 * Alternative: when "efile" is null read errors from buffer "buf".
183 * Always use 'errorformat' from "buf" if there is a local value.
Bram Moolenaar7fd73202010-07-25 16:58:46 +0200184 * Then "lnumfirst" and "lnumlast" specify the range of lines to use.
185 * Set the title of the list to "qf_title".
Bram Moolenaar86b68352004-12-27 21:59:20 +0000186 * Return -1 for error, number of errors for success.
187 */
188 static int
Bram Moolenaar7fd73202010-07-25 16:58:46 +0200189qf_init_ext(qi, efile, buf, tv, errorformat, newlist, lnumfirst, lnumlast,
190 qf_title)
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000191 qf_info_T *qi;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000192 char_u *efile;
193 buf_T *buf;
Bram Moolenaar87e25fd2005-07-27 21:13:01 +0000194 typval_T *tv;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000195 char_u *errorformat;
196 int newlist; /* TRUE: start a new error list */
197 linenr_T lnumfirst; /* first line number to use */
198 linenr_T lnumlast; /* last line number to use */
Bram Moolenaar7fd73202010-07-25 16:58:46 +0200199 char_u *qf_title;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000200{
Bram Moolenaar071d4272004-06-13 20:20:40 +0000201 char_u *namebuf;
202 char_u *errmsg;
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000203 char_u *pattern;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000204 char_u *fmtstr = NULL;
205 int col = 0;
Bram Moolenaar05159a02005-02-26 23:04:13 +0000206 char_u use_viscol = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000207 int type = 0;
208 int valid;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000209 linenr_T buflnum = lnumfirst;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000210 long lnum = 0L;
211 int enr = 0;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000212 FILE *fd = NULL;
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000213 qfline_T *qfprev = NULL; /* init to make SASC shut up */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000214 char_u *efmp;
Bram Moolenaar01265852006-03-20 21:50:15 +0000215 efm_T *fmt_first = NULL;
216 efm_T *fmt_last = NULL;
217 efm_T *fmt_ptr;
218 efm_T *fmt_start = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000219 char_u *efm;
220 char_u *ptr;
221 char_u *srcptr;
222 int len;
223 int i;
224 int round;
225 int idx = 0;
226 int multiline = FALSE;
227 int multiignore = FALSE;
228 int multiscan = FALSE;
229 int retval = -1; /* default: return error flag */
230 char_u *directory = NULL;
231 char_u *currfile = NULL;
232 char_u *tail = NULL;
Bram Moolenaar87e25fd2005-07-27 21:13:01 +0000233 char_u *p_str = NULL;
234 listitem_T *p_li = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000235 struct dir_stack_T *file_stack = NULL;
236 regmatch_T regmatch;
237 static struct fmtpattern
238 {
239 char_u convchar;
240 char *pattern;
241 } fmt_pat[FMT_PATTERNS] =
242 {
Bram Moolenaare344bea2005-09-01 20:46:49 +0000243 {'f', ".\\+"}, /* only used when at end */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000244 {'n', "\\d\\+"},
245 {'l', "\\d\\+"},
246 {'c', "\\d\\+"},
247 {'t', "."},
248 {'m', ".\\+"},
249 {'r', ".*"},
Bram Moolenaarf13de072012-06-01 18:34:41 +0200250 {'p', "[- .]*"},
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000251 {'v', "\\d\\+"},
252 {'s', ".\\+"}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000253 };
254
Bram Moolenaar071d4272004-06-13 20:20:40 +0000255 namebuf = alloc(CMDBUFFSIZE + 1);
256 errmsg = alloc(CMDBUFFSIZE + 1);
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000257 pattern = alloc(CMDBUFFSIZE + 1);
258 if (namebuf == NULL || errmsg == NULL || pattern == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259 goto qf_init_end;
260
Bram Moolenaar86b68352004-12-27 21:59:20 +0000261 if (efile != NULL && (fd = mch_fopen((char *)efile, "r")) == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262 {
263 EMSG2(_(e_openerrf), efile);
264 goto qf_init_end;
265 }
266
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000267 if (newlist || qi->qf_curlist == qi->qf_listcount)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000268 /* make place for a new list */
Bram Moolenaar41b884b2012-11-14 22:38:08 +0100269 qf_new_list(qi, qf_title, curwin);
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000270 else if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000271 /* Adding to existing list, find last entry. */
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000272 for (qfprev = qi->qf_lists[qi->qf_curlist].qf_start;
Bram Moolenaar7fd73202010-07-25 16:58:46 +0200273 qfprev->qf_next != qfprev; qfprev = qfprev->qf_next)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000274 ;
275
276/*
277 * Each part of the format string is copied and modified from errorformat to
278 * regex prog. Only a few % characters are allowed.
279 */
280 /* Use the local value of 'errorformat' if it's set. */
Bram Moolenaar87e25fd2005-07-27 21:13:01 +0000281 if (errorformat == p_efm && tv == NULL && *buf->b_p_efm != NUL)
Bram Moolenaar86b68352004-12-27 21:59:20 +0000282 efm = buf->b_p_efm;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283 else
284 efm = errorformat;
285 /*
286 * Get some space to modify the format string into.
287 */
288 i = (FMT_PATTERNS * 3) + ((int)STRLEN(efm) << 2);
289 for (round = FMT_PATTERNS; round > 0; )
290 i += (int)STRLEN(fmt_pat[--round].pattern);
291#ifdef COLON_IN_FILENAME
292 i += 12; /* "%f" can become twelve chars longer */
293#else
294 i += 2; /* "%f" can become two chars longer */
295#endif
296 if ((fmtstr = alloc(i)) == NULL)
297 goto error2;
298
Bram Moolenaar01265852006-03-20 21:50:15 +0000299 while (efm[0] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000300 {
301 /*
302 * Allocate a new eformat structure and put it at the end of the list
303 */
Bram Moolenaar01265852006-03-20 21:50:15 +0000304 fmt_ptr = (efm_T *)alloc_clear((unsigned)sizeof(efm_T));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000305 if (fmt_ptr == NULL)
306 goto error2;
307 if (fmt_first == NULL) /* first one */
308 fmt_first = fmt_ptr;
309 else
310 fmt_last->next = fmt_ptr;
311 fmt_last = fmt_ptr;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312
313 /*
314 * Isolate one part in the 'errorformat' option
315 */
316 for (len = 0; efm[len] != NUL && efm[len] != ','; ++len)
317 if (efm[len] == '\\' && efm[len + 1] != NUL)
318 ++len;
319
320 /*
321 * Build regexp pattern from current 'errorformat' option
322 */
323 ptr = fmtstr;
324 *ptr++ = '^';
Bram Moolenaar01265852006-03-20 21:50:15 +0000325 round = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000326 for (efmp = efm; efmp < efm + len; ++efmp)
327 {
328 if (*efmp == '%')
329 {
330 ++efmp;
331 for (idx = 0; idx < FMT_PATTERNS; ++idx)
332 if (fmt_pat[idx].convchar == *efmp)
333 break;
334 if (idx < FMT_PATTERNS)
335 {
336 if (fmt_ptr->addr[idx])
337 {
338 sprintf((char *)errmsg,
339 _("E372: Too many %%%c in format string"), *efmp);
340 EMSG(errmsg);
341 goto error2;
342 }
343 if ((idx
344 && idx < 6
345 && vim_strchr((char_u *)"DXOPQ",
346 fmt_ptr->prefix) != NULL)
347 || (idx == 6
348 && vim_strchr((char_u *)"OPQ",
349 fmt_ptr->prefix) == NULL))
350 {
351 sprintf((char *)errmsg,
352 _("E373: Unexpected %%%c in format string"), *efmp);
353 EMSG(errmsg);
354 goto error2;
355 }
356 fmt_ptr->addr[idx] = (char_u)++round;
357 *ptr++ = '\\';
358 *ptr++ = '(';
359#ifdef BACKSLASH_IN_FILENAME
360 if (*efmp == 'f')
361 {
362 /* Also match "c:" in the file name, even when
363 * checking for a colon next: "%f:".
364 * "\%(\a:\)\=" */
365 STRCPY(ptr, "\\%(\\a:\\)\\=");
366 ptr += 10;
367 }
368#endif
Bram Moolenaare344bea2005-09-01 20:46:49 +0000369 if (*efmp == 'f' && efmp[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370 {
Bram Moolenaare344bea2005-09-01 20:46:49 +0000371 if (efmp[1] != '\\' && efmp[1] != '%')
372 {
373 /* A file name may contain spaces, but this isn't
374 * in "\f". For "%f:%l:%m" there may be a ":" in
375 * the file name. Use ".\{-1,}x" instead (x is
376 * the next character), the requirement that :999:
377 * follows should work. */
378 STRCPY(ptr, ".\\{-1,}");
379 ptr += 7;
380 }
381 else
382 {
383 /* File name followed by '\\' or '%': include as
384 * many file name chars as possible. */
385 STRCPY(ptr, "\\f\\+");
386 ptr += 4;
387 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000388 }
389 else
390 {
391 srcptr = (char_u *)fmt_pat[idx].pattern;
392 while ((*ptr = *srcptr++) != NUL)
393 ++ptr;
394 }
395 *ptr++ = '\\';
396 *ptr++ = ')';
397 }
398 else if (*efmp == '*')
399 {
400 if (*++efmp == '[' || *efmp == '\\')
401 {
402 if ((*ptr++ = *efmp) == '[') /* %*[^a-z0-9] etc. */
403 {
404 if (efmp[1] == '^')
405 *ptr++ = *++efmp;
406 if (efmp < efm + len)
407 {
408 *ptr++ = *++efmp; /* could be ']' */
409 while (efmp < efm + len
410 && (*ptr++ = *++efmp) != ']')
411 /* skip */;
412 if (efmp == efm + len)
413 {
414 EMSG(_("E374: Missing ] in format string"));
415 goto error2;
416 }
417 }
418 }
419 else if (efmp < efm + len) /* %*\D, %*\s etc. */
420 *ptr++ = *++efmp;
421 *ptr++ = '\\';
422 *ptr++ = '+';
423 }
424 else
425 {
426 /* TODO: scanf()-like: %*ud, %*3c, %*f, ... ? */
427 sprintf((char *)errmsg,
428 _("E375: Unsupported %%%c in format string"), *efmp);
429 EMSG(errmsg);
430 goto error2;
431 }
432 }
433 else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL)
434 *ptr++ = *efmp; /* regexp magic characters */
435 else if (*efmp == '#')
436 *ptr++ = '*';
Bram Moolenaar01265852006-03-20 21:50:15 +0000437 else if (*efmp == '>')
438 fmt_ptr->conthere = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000439 else if (efmp == efm + 1) /* analyse prefix */
440 {
441 if (vim_strchr((char_u *)"+-", *efmp) != NULL)
442 fmt_ptr->flags = *efmp++;
443 if (vim_strchr((char_u *)"DXAEWICZGOPQ", *efmp) != NULL)
444 fmt_ptr->prefix = *efmp;
445 else
446 {
447 sprintf((char *)errmsg,
448 _("E376: Invalid %%%c in format string prefix"), *efmp);
449 EMSG(errmsg);
450 goto error2;
451 }
452 }
453 else
454 {
455 sprintf((char *)errmsg,
456 _("E377: Invalid %%%c in format string"), *efmp);
457 EMSG(errmsg);
458 goto error2;
459 }
460 }
461 else /* copy normal character */
462 {
463 if (*efmp == '\\' && efmp + 1 < efm + len)
464 ++efmp;
465 else if (vim_strchr((char_u *)".*^$~[", *efmp) != NULL)
466 *ptr++ = '\\'; /* escape regexp atoms */
467 if (*efmp)
468 *ptr++ = *efmp;
469 }
470 }
471 *ptr++ = '$';
472 *ptr = NUL;
473 if ((fmt_ptr->prog = vim_regcomp(fmtstr, RE_MAGIC + RE_STRING)) == NULL)
474 goto error2;
475 /*
476 * Advance to next part
477 */
478 efm = skip_to_option_part(efm + len); /* skip comma and spaces */
479 }
480 if (fmt_first == NULL) /* nothing found */
481 {
482 EMSG(_("E378: 'errorformat' contains no pattern"));
483 goto error2;
484 }
485
486 /*
487 * got_int is reset here, because it was probably set when killing the
488 * ":make" command, but we still want to read the errorfile then.
489 */
490 got_int = FALSE;
491
492 /* Always ignore case when looking for a matching error. */
493 regmatch.rm_ic = TRUE;
494
Bram Moolenaar87e25fd2005-07-27 21:13:01 +0000495 if (tv != NULL)
496 {
497 if (tv->v_type == VAR_STRING)
498 p_str = tv->vval.v_string;
499 else if (tv->v_type == VAR_LIST)
500 p_li = tv->vval.v_list->lv_first;
501 }
502
Bram Moolenaar071d4272004-06-13 20:20:40 +0000503 /*
504 * Read the lines in the error file one by one.
505 * Try to recognize one of the error formats in each line.
506 */
Bram Moolenaar86b68352004-12-27 21:59:20 +0000507 while (!got_int)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508 {
Bram Moolenaar86b68352004-12-27 21:59:20 +0000509 /* Get the next line. */
510 if (fd == NULL)
511 {
Bram Moolenaar87e25fd2005-07-27 21:13:01 +0000512 if (tv != NULL)
513 {
Bram Moolenaar87e25fd2005-07-27 21:13:01 +0000514 if (tv->v_type == VAR_STRING)
515 {
516 /* Get the next line from the supplied string */
517 char_u *p;
518
519 if (!*p_str) /* Reached the end of the string */
520 break;
521
522 p = vim_strchr(p_str, '\n');
523 if (p)
Bram Moolenaara93fa7e2006-04-17 22:14:47 +0000524 len = (int)(p - p_str + 1);
Bram Moolenaar87e25fd2005-07-27 21:13:01 +0000525 else
Bram Moolenaara93fa7e2006-04-17 22:14:47 +0000526 len = (int)STRLEN(p_str);
Bram Moolenaar87e25fd2005-07-27 21:13:01 +0000527
528 if (len > CMDBUFFSIZE - 2)
529 vim_strncpy(IObuff, p_str, CMDBUFFSIZE - 2);
530 else
531 vim_strncpy(IObuff, p_str, len);
532
533 p_str += len;
534 }
535 else if (tv->v_type == VAR_LIST)
536 {
537 /* Get the next line from the supplied list */
538 while (p_li && p_li->li_tv.v_type != VAR_STRING)
539 p_li = p_li->li_next; /* Skip non-string items */
540
541 if (!p_li) /* End of the list */
542 break;
543
Bram Moolenaara93fa7e2006-04-17 22:14:47 +0000544 len = (int)STRLEN(p_li->li_tv.vval.v_string);
Bram Moolenaar87e25fd2005-07-27 21:13:01 +0000545 if (len > CMDBUFFSIZE - 2)
546 len = CMDBUFFSIZE - 2;
547
548 vim_strncpy(IObuff, p_li->li_tv.vval.v_string, len);
549
550 p_li = p_li->li_next; /* next item */
551 }
552 }
553 else
554 {
555 /* Get the next line from the supplied buffer */
556 if (buflnum > lnumlast)
557 break;
558 vim_strncpy(IObuff, ml_get_buf(buf, buflnum++, FALSE),
559 CMDBUFFSIZE - 2);
560 }
Bram Moolenaar86b68352004-12-27 21:59:20 +0000561 }
562 else if (fgets((char *)IObuff, CMDBUFFSIZE - 2, fd) == NULL)
563 break;
564
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 IObuff[CMDBUFFSIZE - 2] = NUL; /* for very long lines */
Bram Moolenaar836082d2011-08-10 13:21:46 +0200566#ifdef FEAT_MBYTE
567 remove_bom(IObuff);
568#endif
569
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 if ((efmp = vim_strrchr(IObuff, '\n')) != NULL)
571 *efmp = NUL;
572#ifdef USE_CRNL
573 if ((efmp = vim_strrchr(IObuff, '\r')) != NULL)
574 *efmp = NUL;
575#endif
576
Bram Moolenaar01265852006-03-20 21:50:15 +0000577 /* If there was no %> item start at the first pattern */
578 if (fmt_start == NULL)
579 fmt_ptr = fmt_first;
580 else
581 {
582 fmt_ptr = fmt_start;
583 fmt_start = NULL;
584 }
585
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 /*
587 * Try to match each part of 'errorformat' until we find a complete
588 * match or no match.
589 */
590 valid = TRUE;
591restofline:
Bram Moolenaar01265852006-03-20 21:50:15 +0000592 for ( ; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 {
594 idx = fmt_ptr->prefix;
595 if (multiscan && vim_strchr((char_u *)"OPQ", idx) == NULL)
596 continue;
597 namebuf[0] = NUL;
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000598 pattern[0] = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599 if (!multiscan)
600 errmsg[0] = NUL;
601 lnum = 0;
602 col = 0;
Bram Moolenaar05159a02005-02-26 23:04:13 +0000603 use_viscol = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604 enr = -1;
605 type = 0;
606 tail = NULL;
607
608 regmatch.regprog = fmt_ptr->prog;
609 if (vim_regexec(&regmatch, IObuff, (colnr_T)0))
610 {
611 if ((idx == 'C' || idx == 'Z') && !multiline)
612 continue;
613 if (vim_strchr((char_u *)"EWI", idx) != NULL)
614 type = idx;
615 else
616 type = 0;
617 /*
Bram Moolenaar4169da72006-06-20 18:49:32 +0000618 * Extract error message data from matched line.
619 * We check for an actual submatch, because "\[" and "\]" in
620 * the 'errorformat' may cause the wrong submatch to be used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621 */
622 if ((i = (int)fmt_ptr->addr[0]) > 0) /* %f */
623 {
Bram Moolenaar4169da72006-06-20 18:49:32 +0000624 int c;
625
626 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL)
627 continue;
Bram Moolenaar35c54e52005-05-20 21:25:31 +0000628
629 /* Expand ~/file and $HOME/file to full path. */
Bram Moolenaar4169da72006-06-20 18:49:32 +0000630 c = *regmatch.endp[i];
Bram Moolenaar35c54e52005-05-20 21:25:31 +0000631 *regmatch.endp[i] = NUL;
632 expand_env(regmatch.startp[i], namebuf, CMDBUFFSIZE);
633 *regmatch.endp[i] = c;
634
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635 if (vim_strchr((char_u *)"OPQ", idx) != NULL
Bram Moolenaar35c54e52005-05-20 21:25:31 +0000636 && mch_getperm(namebuf) == -1)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000637 continue;
638 }
639 if ((i = (int)fmt_ptr->addr[1]) > 0) /* %n */
Bram Moolenaar4169da72006-06-20 18:49:32 +0000640 {
641 if (regmatch.startp[i] == NULL)
642 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000643 enr = (int)atol((char *)regmatch.startp[i]);
Bram Moolenaar4169da72006-06-20 18:49:32 +0000644 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000645 if ((i = (int)fmt_ptr->addr[2]) > 0) /* %l */
Bram Moolenaar4169da72006-06-20 18:49:32 +0000646 {
647 if (regmatch.startp[i] == NULL)
648 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649 lnum = atol((char *)regmatch.startp[i]);
Bram Moolenaar4169da72006-06-20 18:49:32 +0000650 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000651 if ((i = (int)fmt_ptr->addr[3]) > 0) /* %c */
Bram Moolenaar4169da72006-06-20 18:49:32 +0000652 {
653 if (regmatch.startp[i] == NULL)
654 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000655 col = (int)atol((char *)regmatch.startp[i]);
Bram Moolenaar4169da72006-06-20 18:49:32 +0000656 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000657 if ((i = (int)fmt_ptr->addr[4]) > 0) /* %t */
Bram Moolenaar4169da72006-06-20 18:49:32 +0000658 {
659 if (regmatch.startp[i] == NULL)
660 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661 type = *regmatch.startp[i];
Bram Moolenaar4169da72006-06-20 18:49:32 +0000662 }
Bram Moolenaar4770d092006-01-12 23:22:24 +0000663 if (fmt_ptr->flags == '+' && !multiscan) /* %+ */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 STRCPY(errmsg, IObuff);
665 else if ((i = (int)fmt_ptr->addr[5]) > 0) /* %m */
666 {
Bram Moolenaar4169da72006-06-20 18:49:32 +0000667 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL)
668 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 len = (int)(regmatch.endp[i] - regmatch.startp[i]);
Bram Moolenaarbbebc852005-07-18 21:47:53 +0000670 vim_strncpy(errmsg, regmatch.startp[i], len);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 }
672 if ((i = (int)fmt_ptr->addr[6]) > 0) /* %r */
Bram Moolenaar4169da72006-06-20 18:49:32 +0000673 {
674 if (regmatch.startp[i] == NULL)
675 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000676 tail = regmatch.startp[i];
Bram Moolenaar4169da72006-06-20 18:49:32 +0000677 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 if ((i = (int)fmt_ptr->addr[7]) > 0) /* %p */
679 {
Bram Moolenaarf13de072012-06-01 18:34:41 +0200680 char_u *match_ptr;
681
Bram Moolenaar4169da72006-06-20 18:49:32 +0000682 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL)
683 continue;
Bram Moolenaarf13de072012-06-01 18:34:41 +0200684 col = 0;
685 for (match_ptr = regmatch.startp[i];
686 match_ptr != regmatch.endp[i]; ++match_ptr)
687 {
688 ++col;
689 if (*match_ptr == TAB)
690 {
691 col += 7;
692 col -= col % 8;
693 }
694 }
695 ++col;
696 use_viscol = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000697 }
698 if ((i = (int)fmt_ptr->addr[8]) > 0) /* %v */
699 {
Bram Moolenaar4169da72006-06-20 18:49:32 +0000700 if (regmatch.startp[i] == NULL)
701 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000702 col = (int)atol((char *)regmatch.startp[i]);
Bram Moolenaar05159a02005-02-26 23:04:13 +0000703 use_viscol = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000704 }
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000705 if ((i = (int)fmt_ptr->addr[9]) > 0) /* %s */
706 {
Bram Moolenaar4169da72006-06-20 18:49:32 +0000707 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL)
708 continue;
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000709 len = (int)(regmatch.endp[i] - regmatch.startp[i]);
710 if (len > CMDBUFFSIZE - 5)
711 len = CMDBUFFSIZE - 5;
712 STRCPY(pattern, "^\\V");
713 STRNCAT(pattern, regmatch.startp[i], len);
714 pattern[len + 3] = '\\';
715 pattern[len + 4] = '$';
716 pattern[len + 5] = NUL;
717 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 break;
719 }
720 }
721 multiscan = FALSE;
Bram Moolenaar01265852006-03-20 21:50:15 +0000722
Bram Moolenaar4770d092006-01-12 23:22:24 +0000723 if (fmt_ptr == NULL || idx == 'D' || idx == 'X')
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724 {
Bram Moolenaar4770d092006-01-12 23:22:24 +0000725 if (fmt_ptr != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726 {
727 if (idx == 'D') /* enter directory */
728 {
729 if (*namebuf == NUL)
730 {
731 EMSG(_("E379: Missing or empty directory name"));
732 goto error2;
733 }
734 if ((directory = qf_push_dir(namebuf, &dir_stack)) == NULL)
735 goto error2;
736 }
737 else if (idx == 'X') /* leave directory */
738 directory = qf_pop_dir(&dir_stack);
739 }
740 namebuf[0] = NUL; /* no match found, remove file name */
741 lnum = 0; /* don't jump to this line */
742 valid = FALSE;
743 STRCPY(errmsg, IObuff); /* copy whole line to error message */
Bram Moolenaar4770d092006-01-12 23:22:24 +0000744 if (fmt_ptr == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000745 multiline = multiignore = FALSE;
746 }
Bram Moolenaar4770d092006-01-12 23:22:24 +0000747 else if (fmt_ptr != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748 {
Bram Moolenaar01265852006-03-20 21:50:15 +0000749 /* honor %> item */
750 if (fmt_ptr->conthere)
751 fmt_start = fmt_ptr;
752
Bram Moolenaar071d4272004-06-13 20:20:40 +0000753 if (vim_strchr((char_u *)"AEWI", idx) != NULL)
754 multiline = TRUE; /* start of a multi-line message */
755 else if (vim_strchr((char_u *)"CZ", idx) != NULL)
756 { /* continuation of multi-line msg */
757 if (qfprev == NULL)
758 goto error2;
759 if (*errmsg && !multiignore)
760 {
761 len = (int)STRLEN(qfprev->qf_text);
762 if ((ptr = alloc((unsigned)(len + STRLEN(errmsg) + 2)))
763 == NULL)
764 goto error2;
765 STRCPY(ptr, qfprev->qf_text);
766 vim_free(qfprev->qf_text);
767 qfprev->qf_text = ptr;
768 *(ptr += len) = '\n';
769 STRCPY(++ptr, errmsg);
770 }
771 if (qfprev->qf_nr == -1)
772 qfprev->qf_nr = enr;
773 if (vim_isprintc(type) && !qfprev->qf_type)
774 qfprev->qf_type = type; /* only printable chars allowed */
775 if (!qfprev->qf_lnum)
776 qfprev->qf_lnum = lnum;
777 if (!qfprev->qf_col)
778 qfprev->qf_col = col;
Bram Moolenaar05159a02005-02-26 23:04:13 +0000779 qfprev->qf_viscol = use_viscol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000780 if (!qfprev->qf_fnum)
781 qfprev->qf_fnum = qf_get_fnum(directory,
782 *namebuf || directory ? namebuf
783 : currfile && valid ? currfile : 0);
784 if (idx == 'Z')
785 multiline = multiignore = FALSE;
786 line_breakcheck();
787 continue;
788 }
789 else if (vim_strchr((char_u *)"OPQ", idx) != NULL)
790 {
791 /* global file names */
792 valid = FALSE;
793 if (*namebuf == NUL || mch_getperm(namebuf) >= 0)
794 {
795 if (*namebuf && idx == 'P')
796 currfile = qf_push_dir(namebuf, &file_stack);
797 else if (idx == 'Q')
798 currfile = qf_pop_dir(&file_stack);
799 *namebuf = NUL;
800 if (tail && *tail)
801 {
Bram Moolenaarc236c162008-07-13 17:41:49 +0000802 STRMOVE(IObuff, skipwhite(tail));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000803 multiscan = TRUE;
804 goto restofline;
805 }
806 }
807 }
808 if (fmt_ptr->flags == '-') /* generally exclude this line */
809 {
810 if (multiline)
811 multiignore = TRUE; /* also exclude continuation lines */
812 continue;
813 }
814 }
815
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000816 if (qf_add_entry(qi, &qfprev,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000817 directory,
Bram Moolenaar9d75c832005-01-25 21:57:23 +0000818 (*namebuf || directory)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819 ? namebuf
Bram Moolenaar9d75c832005-01-25 21:57:23 +0000820 : ((currfile && valid) ? currfile : (char_u *)NULL),
Bram Moolenaar48b66fb2007-02-04 01:58:18 +0000821 0,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822 errmsg,
823 lnum,
824 col,
Bram Moolenaar05159a02005-02-26 23:04:13 +0000825 use_viscol,
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000826 pattern,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000827 enr,
828 type,
829 valid) == FAIL)
830 goto error2;
831 line_breakcheck();
832 }
Bram Moolenaar86b68352004-12-27 21:59:20 +0000833 if (fd == NULL || !ferror(fd))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000834 {
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000835 if (qi->qf_lists[qi->qf_curlist].qf_index == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000836 {
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000837 /* no valid entry found */
838 qi->qf_lists[qi->qf_curlist].qf_ptr =
839 qi->qf_lists[qi->qf_curlist].qf_start;
840 qi->qf_lists[qi->qf_curlist].qf_index = 1;
841 qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000842 }
843 else
844 {
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000845 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE;
846 if (qi->qf_lists[qi->qf_curlist].qf_ptr == NULL)
847 qi->qf_lists[qi->qf_curlist].qf_ptr =
848 qi->qf_lists[qi->qf_curlist].qf_start;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000849 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000850 /* return number of matches */
851 retval = qi->qf_lists[qi->qf_curlist].qf_count;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000852 goto qf_init_ok;
853 }
854 EMSG(_(e_readerrf));
855error2:
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000856 qf_free(qi, qi->qf_curlist);
857 qi->qf_listcount--;
858 if (qi->qf_curlist > 0)
859 --qi->qf_curlist;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000860qf_init_ok:
Bram Moolenaar86b68352004-12-27 21:59:20 +0000861 if (fd != NULL)
862 fclose(fd);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000863 for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_first)
864 {
865 fmt_first = fmt_ptr->next;
866 vim_free(fmt_ptr->prog);
867 vim_free(fmt_ptr);
868 }
869 qf_clean_dir_stack(&dir_stack);
870 qf_clean_dir_stack(&file_stack);
871qf_init_end:
872 vim_free(namebuf);
873 vim_free(errmsg);
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000874 vim_free(pattern);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000875 vim_free(fmtstr);
876
877#ifdef FEAT_WINDOWS
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000878 qf_update_buffer(qi);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000879#endif
880
881 return retval;
882}
883
884/*
885 * Prepare for adding a new quickfix list.
886 */
887 static void
Bram Moolenaar41b884b2012-11-14 22:38:08 +0100888qf_new_list(qi, qf_title, wp)
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000889 qf_info_T *qi;
Bram Moolenaar7fd73202010-07-25 16:58:46 +0200890 char_u *qf_title;
Bram Moolenaar41b884b2012-11-14 22:38:08 +0100891 win_T *wp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000892{
893 int i;
894
895 /*
896 * If the current entry is not the last entry, delete entries below
897 * the current entry. This makes it possible to browse in a tree-like
898 * way with ":grep'.
899 */
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000900 while (qi->qf_listcount > qi->qf_curlist + 1)
Bram Moolenaar41b884b2012-11-14 22:38:08 +0100901 {
902 if (wp != NULL && wp->w_llist == qi)
903 wp->w_llist = NULL;
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000904 qf_free(qi, --qi->qf_listcount);
Bram Moolenaar41b884b2012-11-14 22:38:08 +0100905 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000906
907 /*
908 * When the stack is full, remove to oldest entry
909 * Otherwise, add a new entry.
910 */
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000911 if (qi->qf_listcount == LISTCOUNT)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {
Bram Moolenaar41b884b2012-11-14 22:38:08 +0100913 if (wp != NULL && wp->w_llist == qi)
914 wp->w_llist = NULL;
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000915 qf_free(qi, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916 for (i = 1; i < LISTCOUNT; ++i)
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000917 qi->qf_lists[i - 1] = qi->qf_lists[i];
918 qi->qf_curlist = LISTCOUNT - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919 }
920 else
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000921 qi->qf_curlist = qi->qf_listcount++;
Bram Moolenaara0f299b2012-01-10 17:13:52 +0100922 vim_memset(&qi->qf_lists[qi->qf_curlist], 0, (size_t)(sizeof(qf_list_T)));
Bram Moolenaar7fd73202010-07-25 16:58:46 +0200923 if (qf_title != NULL)
924 {
Bram Moolenaar5e109c42010-07-26 22:51:28 +0200925 char_u *p = alloc((int)STRLEN(qf_title) + 2);
Bram Moolenaar7fd73202010-07-25 16:58:46 +0200926
927 qi->qf_lists[qi->qf_curlist].qf_title = p;
928 if (p != NULL)
929 sprintf((char *)p, ":%s", (char *)qf_title);
930 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000931}
932
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000933/*
934 * Free a location list
935 */
936 static void
937ll_free_all(pqi)
938 qf_info_T **pqi;
Bram Moolenaarf461c8e2005-06-25 23:04:51 +0000939{
940 int i;
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000941 qf_info_T *qi;
Bram Moolenaarf461c8e2005-06-25 23:04:51 +0000942
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000943 qi = *pqi;
944 if (qi == NULL)
945 return;
946 *pqi = NULL; /* Remove reference to this list */
947
948 qi->qf_refcount--;
949 if (qi->qf_refcount < 1)
950 {
951 /* No references to this location list */
952 for (i = 0; i < qi->qf_listcount; ++i)
953 qf_free(qi, i);
954 vim_free(qi);
955 }
Bram Moolenaarf461c8e2005-06-25 23:04:51 +0000956}
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000957
958 void
959qf_free_all(wp)
960 win_T *wp;
961{
962 int i;
963 qf_info_T *qi = &ql_info;
964
965 if (wp != NULL)
966 {
967 /* location list */
968 ll_free_all(&wp->w_llist);
969 ll_free_all(&wp->w_llist_ref);
970 }
971 else
972 /* quickfix list */
973 for (i = 0; i < qi->qf_listcount; ++i)
974 qf_free(qi, i);
975}
Bram Moolenaarf461c8e2005-06-25 23:04:51 +0000976
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977/*
978 * Add an entry to the end of the list of errors.
979 * Returns OK or FAIL.
980 */
981 static int
Bram Moolenaar48b66fb2007-02-04 01:58:18 +0000982qf_add_entry(qi, prevp, dir, fname, bufnum, mesg, lnum, col, vis_col, pattern,
983 nr, type, valid)
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000984 qf_info_T *qi; /* quickfix list */
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000985 qfline_T **prevp; /* pointer to previously added entry or NULL */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000986 char_u *dir; /* optional directory name */
987 char_u *fname; /* file name or NULL */
Bram Moolenaar48b66fb2007-02-04 01:58:18 +0000988 int bufnum; /* buffer number or zero */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000989 char_u *mesg; /* message */
990 long lnum; /* line number */
991 int col; /* column */
Bram Moolenaar05159a02005-02-26 23:04:13 +0000992 int vis_col; /* using visual column */
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000993 char_u *pattern; /* search pattern */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994 int nr; /* error number */
995 int type; /* type character */
996 int valid; /* valid entry */
997{
Bram Moolenaar68b76a62005-03-25 21:53:48 +0000998 qfline_T *qfp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001000 if ((qfp = (qfline_T *)alloc((unsigned)sizeof(qfline_T))) == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001 return FAIL;
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00001002 if (bufnum != 0)
1003 qfp->qf_fnum = bufnum;
1004 else
1005 qfp->qf_fnum = qf_get_fnum(dir, fname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006 if ((qfp->qf_text = vim_strsave(mesg)) == NULL)
1007 {
1008 vim_free(qfp);
1009 return FAIL;
1010 }
1011 qfp->qf_lnum = lnum;
1012 qfp->qf_col = col;
Bram Moolenaar05159a02005-02-26 23:04:13 +00001013 qfp->qf_viscol = vis_col;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001014 if (pattern == NULL || *pattern == NUL)
1015 qfp->qf_pattern = NULL;
1016 else if ((qfp->qf_pattern = vim_strsave(pattern)) == NULL)
1017 {
1018 vim_free(qfp->qf_text);
1019 vim_free(qfp);
1020 return FAIL;
1021 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022 qfp->qf_nr = nr;
1023 if (type != 1 && !vim_isprintc(type)) /* only printable chars allowed */
1024 type = 0;
1025 qfp->qf_type = type;
1026 qfp->qf_valid = valid;
1027
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001028 if (qi->qf_lists[qi->qf_curlist].qf_count == 0)
1029 /* first element in the list */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 {
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001031 qi->qf_lists[qi->qf_curlist].qf_start = qfp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032 qfp->qf_prev = qfp; /* first element points to itself */
1033 }
1034 else
1035 {
1036 qfp->qf_prev = *prevp;
1037 (*prevp)->qf_next = qfp;
1038 }
1039 qfp->qf_next = qfp; /* last element points to itself */
1040 qfp->qf_cleared = FALSE;
1041 *prevp = qfp;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001042 ++qi->qf_lists[qi->qf_curlist].qf_count;
1043 if (qi->qf_lists[qi->qf_curlist].qf_index == 0 && qfp->qf_valid)
1044 /* first valid entry */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045 {
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001046 qi->qf_lists[qi->qf_curlist].qf_index =
1047 qi->qf_lists[qi->qf_curlist].qf_count;
1048 qi->qf_lists[qi->qf_curlist].qf_ptr = qfp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 }
1050
1051 return OK;
1052}
1053
1054/*
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001055 * Allocate a new location list
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001056 */
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001057 static qf_info_T *
1058ll_new_list()
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001059{
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001060 qf_info_T *qi;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001061
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001062 qi = (qf_info_T *)alloc((unsigned)sizeof(qf_info_T));
1063 if (qi != NULL)
1064 {
1065 vim_memset(qi, 0, (size_t)(sizeof(qf_info_T)));
1066 qi->qf_refcount++;
1067 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001068
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001069 return qi;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001070}
1071
1072/*
1073 * Return the location list for window 'wp'.
1074 * If not present, allocate a location list
1075 */
1076 static qf_info_T *
1077ll_get_or_alloc_list(wp)
1078 win_T *wp;
1079{
1080 if (IS_LL_WINDOW(wp))
1081 /* For a location list window, use the referenced location list */
1082 return wp->w_llist_ref;
1083
1084 /*
1085 * For a non-location list window, w_llist_ref should not point to a
1086 * location list.
1087 */
1088 ll_free_all(&wp->w_llist_ref);
1089
1090 if (wp->w_llist == NULL)
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001091 wp->w_llist = ll_new_list(); /* new location list */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001092 return wp->w_llist;
1093}
1094
1095/*
1096 * Copy the location list from window "from" to window "to".
1097 */
1098 void
1099copy_loclist(from, to)
1100 win_T *from;
1101 win_T *to;
1102{
1103 qf_info_T *qi;
1104 int idx;
1105 int i;
1106
1107 /*
1108 * When copying from a location list window, copy the referenced
1109 * location list. For other windows, copy the location list for
1110 * that window.
1111 */
1112 if (IS_LL_WINDOW(from))
1113 qi = from->w_llist_ref;
1114 else
1115 qi = from->w_llist;
1116
1117 if (qi == NULL) /* no location list to copy */
1118 return;
1119
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001120 /* allocate a new location list */
1121 if ((to->w_llist = ll_new_list()) == NULL)
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001122 return;
1123
1124 to->w_llist->qf_listcount = qi->qf_listcount;
1125
1126 /* Copy the location lists one at a time */
1127 for (idx = 0; idx < qi->qf_listcount; idx++)
1128 {
1129 qf_list_T *from_qfl;
1130 qf_list_T *to_qfl;
1131
1132 to->w_llist->qf_curlist = idx;
1133
1134 from_qfl = &qi->qf_lists[idx];
1135 to_qfl = &to->w_llist->qf_lists[idx];
1136
1137 /* Some of the fields are populated by qf_add_entry() */
1138 to_qfl->qf_nonevalid = from_qfl->qf_nonevalid;
1139 to_qfl->qf_count = 0;
1140 to_qfl->qf_index = 0;
1141 to_qfl->qf_start = NULL;
1142 to_qfl->qf_ptr = NULL;
Bram Moolenaar7fd73202010-07-25 16:58:46 +02001143 if (from_qfl->qf_title != NULL)
1144 to_qfl->qf_title = vim_strsave(from_qfl->qf_title);
1145 else
1146 to_qfl->qf_title = NULL;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001147
1148 if (from_qfl->qf_count)
1149 {
1150 qfline_T *from_qfp;
1151 qfline_T *prevp = NULL;
1152
1153 /* copy all the location entries in this list */
1154 for (i = 0, from_qfp = from_qfl->qf_start; i < from_qfl->qf_count;
1155 ++i, from_qfp = from_qfp->qf_next)
1156 {
1157 if (qf_add_entry(to->w_llist, &prevp,
1158 NULL,
1159 NULL,
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00001160 0,
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001161 from_qfp->qf_text,
1162 from_qfp->qf_lnum,
1163 from_qfp->qf_col,
1164 from_qfp->qf_viscol,
1165 from_qfp->qf_pattern,
1166 from_qfp->qf_nr,
1167 0,
1168 from_qfp->qf_valid) == FAIL)
1169 {
1170 qf_free_all(to);
1171 return;
1172 }
1173 /*
1174 * qf_add_entry() will not set the qf_num field, as the
1175 * directory and file names are not supplied. So the qf_fnum
1176 * field is copied here.
1177 */
1178 prevp->qf_fnum = from_qfp->qf_fnum; /* file number */
1179 prevp->qf_type = from_qfp->qf_type; /* error type */
1180 if (from_qfl->qf_ptr == from_qfp)
1181 to_qfl->qf_ptr = prevp; /* current location */
1182 }
1183 }
1184
1185 to_qfl->qf_index = from_qfl->qf_index; /* current index in the list */
1186
1187 /* When no valid entries are present in the list, qf_ptr points to
1188 * the first item in the list */
Bram Moolenaard236ac02011-05-05 17:14:14 +02001189 if (to_qfl->qf_nonevalid)
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001190 to_qfl->qf_ptr = to_qfl->qf_start;
1191 }
1192
1193 to->w_llist->qf_curlist = qi->qf_curlist; /* current list */
1194}
1195
1196/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001197 * get buffer number for file "dir.name"
1198 */
1199 static int
1200qf_get_fnum(directory, fname)
1201 char_u *directory;
1202 char_u *fname;
1203{
1204 if (fname == NULL || *fname == NUL) /* no file name */
1205 return 0;
1206 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 char_u *ptr;
1208 int fnum;
1209
Bram Moolenaare60acc12011-05-10 16:41:25 +02001210#ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 vms_remove_version(fname);
Bram Moolenaare60acc12011-05-10 16:41:25 +02001212#endif
1213#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 if (directory != NULL)
1215 slash_adjust(directory);
1216 slash_adjust(fname);
Bram Moolenaare60acc12011-05-10 16:41:25 +02001217#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 if (directory != NULL && !vim_isAbsName(fname)
1219 && (ptr = concat_fnames(directory, fname, TRUE)) != NULL)
1220 {
1221 /*
1222 * Here we check if the file really exists.
1223 * This should normally be true, but if make works without
1224 * "leaving directory"-messages we might have missed a
1225 * directory change.
1226 */
1227 if (mch_getperm(ptr) < 0)
1228 {
1229 vim_free(ptr);
1230 directory = qf_guess_filepath(fname);
1231 if (directory)
1232 ptr = concat_fnames(directory, fname, TRUE);
1233 else
1234 ptr = vim_strsave(fname);
1235 }
1236 /* Use concatenated directory name and file name */
1237 fnum = buflist_add(ptr, 0);
1238 vim_free(ptr);
1239 return fnum;
1240 }
1241 return buflist_add(fname, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001242 }
1243}
1244
1245/*
1246 * push dirbuf onto the directory stack and return pointer to actual dir or
1247 * NULL on error
1248 */
1249 static char_u *
1250qf_push_dir(dirbuf, stackptr)
1251 char_u *dirbuf;
1252 struct dir_stack_T **stackptr;
1253{
1254 struct dir_stack_T *ds_new;
1255 struct dir_stack_T *ds_ptr;
1256
1257 /* allocate new stack element and hook it in */
1258 ds_new = (struct dir_stack_T *)alloc((unsigned)sizeof(struct dir_stack_T));
1259 if (ds_new == NULL)
1260 return NULL;
1261
1262 ds_new->next = *stackptr;
1263 *stackptr = ds_new;
1264
1265 /* store directory on the stack */
1266 if (vim_isAbsName(dirbuf)
1267 || (*stackptr)->next == NULL
1268 || (*stackptr && dir_stack != *stackptr))
1269 (*stackptr)->dirname = vim_strsave(dirbuf);
1270 else
1271 {
1272 /* Okay we don't have an absolute path.
1273 * dirbuf must be a subdir of one of the directories on the stack.
1274 * Let's search...
1275 */
1276 ds_new = (*stackptr)->next;
1277 (*stackptr)->dirname = NULL;
1278 while (ds_new)
1279 {
1280 vim_free((*stackptr)->dirname);
1281 (*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf,
1282 TRUE);
1283 if (mch_isdir((*stackptr)->dirname) == TRUE)
1284 break;
1285
1286 ds_new = ds_new->next;
1287 }
1288
1289 /* clean up all dirs we already left */
1290 while ((*stackptr)->next != ds_new)
1291 {
1292 ds_ptr = (*stackptr)->next;
1293 (*stackptr)->next = (*stackptr)->next->next;
1294 vim_free(ds_ptr->dirname);
1295 vim_free(ds_ptr);
1296 }
1297
1298 /* Nothing found -> it must be on top level */
1299 if (ds_new == NULL)
1300 {
1301 vim_free((*stackptr)->dirname);
1302 (*stackptr)->dirname = vim_strsave(dirbuf);
1303 }
1304 }
1305
1306 if ((*stackptr)->dirname != NULL)
1307 return (*stackptr)->dirname;
1308 else
1309 {
1310 ds_ptr = *stackptr;
1311 *stackptr = (*stackptr)->next;
1312 vim_free(ds_ptr);
1313 return NULL;
1314 }
1315}
1316
1317
1318/*
1319 * pop dirbuf from the directory stack and return previous directory or NULL if
1320 * stack is empty
1321 */
1322 static char_u *
1323qf_pop_dir(stackptr)
1324 struct dir_stack_T **stackptr;
1325{
1326 struct dir_stack_T *ds_ptr;
1327
1328 /* TODO: Should we check if dirbuf is the directory on top of the stack?
1329 * What to do if it isn't? */
1330
1331 /* pop top element and free it */
1332 if (*stackptr != NULL)
1333 {
1334 ds_ptr = *stackptr;
1335 *stackptr = (*stackptr)->next;
1336 vim_free(ds_ptr->dirname);
1337 vim_free(ds_ptr);
1338 }
1339
1340 /* return NEW top element as current dir or NULL if stack is empty*/
1341 return *stackptr ? (*stackptr)->dirname : NULL;
1342}
1343
1344/*
1345 * clean up directory stack
1346 */
1347 static void
1348qf_clean_dir_stack(stackptr)
1349 struct dir_stack_T **stackptr;
1350{
1351 struct dir_stack_T *ds_ptr;
1352
1353 while ((ds_ptr = *stackptr) != NULL)
1354 {
1355 *stackptr = (*stackptr)->next;
1356 vim_free(ds_ptr->dirname);
1357 vim_free(ds_ptr);
1358 }
1359}
1360
1361/*
1362 * Check in which directory of the directory stack the given file can be
1363 * found.
1364 * Returns a pointer to the directory name or NULL if not found
1365 * Cleans up intermediate directory entries.
1366 *
1367 * TODO: How to solve the following problem?
1368 * If we have the this directory tree:
1369 * ./
1370 * ./aa
1371 * ./aa/bb
1372 * ./bb
1373 * ./bb/x.c
1374 * and make says:
1375 * making all in aa
1376 * making all in bb
1377 * x.c:9: Error
1378 * Then qf_push_dir thinks we are in ./aa/bb, but we are in ./bb.
1379 * qf_guess_filepath will return NULL.
1380 */
1381 static char_u *
1382qf_guess_filepath(filename)
1383 char_u *filename;
1384{
1385 struct dir_stack_T *ds_ptr;
1386 struct dir_stack_T *ds_tmp;
1387 char_u *fullname;
1388
1389 /* no dirs on the stack - there's nothing we can do */
1390 if (dir_stack == NULL)
1391 return NULL;
1392
1393 ds_ptr = dir_stack->next;
1394 fullname = NULL;
1395 while (ds_ptr)
1396 {
1397 vim_free(fullname);
1398 fullname = concat_fnames(ds_ptr->dirname, filename, TRUE);
1399
1400 /* If concat_fnames failed, just go on. The worst thing that can happen
1401 * is that we delete the entire stack.
1402 */
1403 if ((fullname != NULL) && (mch_getperm(fullname) >= 0))
1404 break;
1405
1406 ds_ptr = ds_ptr->next;
1407 }
1408
1409 vim_free(fullname);
1410
1411 /* clean up all dirs we already left */
1412 while (dir_stack->next != ds_ptr)
1413 {
1414 ds_tmp = dir_stack->next;
1415 dir_stack->next = dir_stack->next->next;
1416 vim_free(ds_tmp->dirname);
1417 vim_free(ds_tmp);
1418 }
1419
1420 return ds_ptr==NULL? NULL: ds_ptr->dirname;
1421
1422}
1423
1424/*
1425 * jump to a quickfix line
1426 * if dir == FORWARD go "errornr" valid entries forward
1427 * if dir == BACKWARD go "errornr" valid entries backward
1428 * if dir == FORWARD_FILE go "errornr" valid entries files backward
1429 * if dir == BACKWARD_FILE go "errornr" valid entries files backward
1430 * else if "errornr" is zero, redisplay the same line
1431 * else go to entry "errornr"
1432 */
1433 void
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001434qf_jump(qi, dir, errornr, forceit)
1435 qf_info_T *qi;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 int dir;
1437 int errornr;
1438 int forceit;
1439{
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001440 qf_info_T *ll_ref;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001441 qfline_T *qf_ptr;
1442 qfline_T *old_qf_ptr;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001443 int qf_index;
1444 int old_qf_fnum;
1445 int old_qf_index;
1446 int prev_index;
1447 static char_u *e_no_more_items = (char_u *)N_("E553: No more items");
1448 char_u *err = e_no_more_items;
1449 linenr_T i;
1450 buf_T *old_curbuf;
1451 linenr_T old_lnum;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 colnr_T screen_col;
1453 colnr_T char_col;
1454 char_u *line;
1455#ifdef FEAT_WINDOWS
Bram Moolenaar71fe80d2006-01-22 23:25:56 +00001456 char_u *old_swb = p_swb;
Bram Moolenaar446cb832008-06-24 21:56:24 +00001457 unsigned old_swb_flags = swb_flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 int opened_window = FALSE;
1459 win_T *win;
1460 win_T *altwin;
Bram Moolenaar884ae642009-02-22 01:37:59 +00001461 int flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462#endif
Bram Moolenaar701f7af2008-11-15 13:12:07 +00001463 win_T *oldwin = curwin;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464 int print_message = TRUE;
1465 int len;
1466#ifdef FEAT_FOLDING
1467 int old_KeyTyped = KeyTyped; /* getting file may reset it */
1468#endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001469 int ok = OK;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001470 int usable_win;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001472 if (qi == NULL)
1473 qi = &ql_info;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001474
1475 if (qi->qf_curlist >= qi->qf_listcount
1476 || qi->qf_lists[qi->qf_curlist].qf_count == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 {
1478 EMSG(_(e_quickfix));
1479 return;
1480 }
1481
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001482 qf_ptr = qi->qf_lists[qi->qf_curlist].qf_ptr;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483 old_qf_ptr = qf_ptr;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001484 qf_index = qi->qf_lists[qi->qf_curlist].qf_index;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485 old_qf_index = qf_index;
1486 if (dir == FORWARD || dir == FORWARD_FILE) /* next valid entry */
1487 {
1488 while (errornr--)
1489 {
1490 old_qf_ptr = qf_ptr;
1491 prev_index = qf_index;
1492 old_qf_fnum = qf_ptr->qf_fnum;
1493 do
1494 {
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001495 if (qf_index == qi->qf_lists[qi->qf_curlist].qf_count
Bram Moolenaar071d4272004-06-13 20:20:40 +00001496 || qf_ptr->qf_next == NULL)
1497 {
1498 qf_ptr = old_qf_ptr;
1499 qf_index = prev_index;
1500 if (err != NULL)
1501 {
1502 EMSG(_(err));
1503 goto theend;
1504 }
1505 errornr = 0;
1506 break;
1507 }
1508 ++qf_index;
1509 qf_ptr = qf_ptr->qf_next;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001510 } while ((!qi->qf_lists[qi->qf_curlist].qf_nonevalid
1511 && !qf_ptr->qf_valid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 || (dir == FORWARD_FILE && qf_ptr->qf_fnum == old_qf_fnum));
1513 err = NULL;
1514 }
1515 }
1516 else if (dir == BACKWARD || dir == BACKWARD_FILE) /* prev. valid entry */
1517 {
1518 while (errornr--)
1519 {
1520 old_qf_ptr = qf_ptr;
1521 prev_index = qf_index;
1522 old_qf_fnum = qf_ptr->qf_fnum;
1523 do
1524 {
1525 if (qf_index == 1 || qf_ptr->qf_prev == NULL)
1526 {
1527 qf_ptr = old_qf_ptr;
1528 qf_index = prev_index;
1529 if (err != NULL)
1530 {
1531 EMSG(_(err));
1532 goto theend;
1533 }
1534 errornr = 0;
1535 break;
1536 }
1537 --qf_index;
1538 qf_ptr = qf_ptr->qf_prev;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001539 } while ((!qi->qf_lists[qi->qf_curlist].qf_nonevalid
1540 && !qf_ptr->qf_valid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541 || (dir == BACKWARD_FILE && qf_ptr->qf_fnum == old_qf_fnum));
1542 err = NULL;
1543 }
1544 }
1545 else if (errornr != 0) /* go to specified number */
1546 {
1547 while (errornr < qf_index && qf_index > 1 && qf_ptr->qf_prev != NULL)
1548 {
1549 --qf_index;
1550 qf_ptr = qf_ptr->qf_prev;
1551 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001552 while (errornr > qf_index && qf_index <
1553 qi->qf_lists[qi->qf_curlist].qf_count
Bram Moolenaar071d4272004-06-13 20:20:40 +00001554 && qf_ptr->qf_next != NULL)
1555 {
1556 ++qf_index;
1557 qf_ptr = qf_ptr->qf_next;
1558 }
1559 }
1560
1561#ifdef FEAT_WINDOWS
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001562 qi->qf_lists[qi->qf_curlist].qf_index = qf_index;
1563 if (qf_win_pos_update(qi, old_qf_index))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 /* No need to print the error message if it's visible in the error
1565 * window */
1566 print_message = FALSE;
1567
1568 /*
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001569 * For ":helpgrep" find a help window or open one.
1570 */
Bram Moolenaar80a94a52006-02-23 21:26:58 +00001571 if (qf_ptr->qf_type == 1 && (!curwin->w_buffer->b_help || cmdmod.tab != 0))
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001572 {
1573 win_T *wp;
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001574
Bram Moolenaar80a94a52006-02-23 21:26:58 +00001575 if (cmdmod.tab != 0)
1576 wp = NULL;
1577 else
1578 for (wp = firstwin; wp != NULL; wp = wp->w_next)
1579 if (wp->w_buffer != NULL && wp->w_buffer->b_help)
1580 break;
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001581 if (wp != NULL && wp->w_buffer->b_nwindows > 0)
1582 win_enter(wp, TRUE);
1583 else
1584 {
1585 /*
1586 * Split off help window; put it at far top if no position
1587 * specified, the current window is vertically split and narrow.
1588 */
Bram Moolenaar884ae642009-02-22 01:37:59 +00001589 flags = WSP_HELP;
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001590# ifdef FEAT_VERTSPLIT
1591 if (cmdmod.split == 0 && curwin->w_width != Columns
1592 && curwin->w_width < 80)
Bram Moolenaar884ae642009-02-22 01:37:59 +00001593 flags |= WSP_TOP;
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001594# endif
Bram Moolenaar884ae642009-02-22 01:37:59 +00001595 if (qi != &ql_info)
1596 flags |= WSP_NEWLOC; /* don't copy the location list */
1597
1598 if (win_split(0, flags) == FAIL)
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001599 goto theend;
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001600 opened_window = TRUE; /* close it when fail */
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001601
1602 if (curwin->w_height < p_hh)
1603 win_setheight((int)p_hh);
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001604
1605 if (qi != &ql_info) /* not a quickfix list */
1606 {
1607 /* The new window should use the supplied location list */
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001608 curwin->w_llist = qi;
1609 qi->qf_refcount++;
1610 }
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001611 }
1612
1613 if (!p_im)
1614 restart_edit = 0; /* don't want insert mode in help file */
1615 }
1616
1617 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001618 * If currently in the quickfix window, find another window to show the
1619 * file in.
1620 */
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001621 if (bt_quickfix(curbuf) && !opened_window)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001622 {
1623 /*
1624 * If there is no file specified, we don't know where to go.
1625 * But do advance, otherwise ":cn" gets stuck.
1626 */
1627 if (qf_ptr->qf_fnum == 0)
1628 goto theend;
1629
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001630 /* Locate a window showing a normal buffer */
1631 usable_win = 0;
1632 FOR_ALL_WINDOWS(win)
1633 if (win->w_buffer->b_p_bt[0] == NUL)
1634 {
1635 usable_win = 1;
1636 break;
1637 }
1638
Bram Moolenaar071d4272004-06-13 20:20:40 +00001639 /*
Bram Moolenaar446cb832008-06-24 21:56:24 +00001640 * If no usable window is found and 'switchbuf' contains "usetab"
Bram Moolenaar38c0a6e2006-10-20 18:13:14 +00001641 * then search in other tabs.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001642 */
Bram Moolenaar446cb832008-06-24 21:56:24 +00001643 if (!usable_win && (swb_flags & SWB_USETAB))
Bram Moolenaar38c0a6e2006-10-20 18:13:14 +00001644 {
1645 tabpage_T *tp;
1646 win_T *wp;
1647
1648 FOR_ALL_TAB_WINDOWS(tp, wp)
1649 {
1650 if (wp->w_buffer->b_fnum == qf_ptr->qf_fnum)
1651 {
1652 goto_tabpage_win(tp, wp);
1653 usable_win = 1;
Bram Moolenaarbb9c7d12009-02-21 23:03:09 +00001654 goto win_found;
Bram Moolenaar38c0a6e2006-10-20 18:13:14 +00001655 }
1656 }
1657 }
Bram Moolenaarbb9c7d12009-02-21 23:03:09 +00001658win_found:
Bram Moolenaar38c0a6e2006-10-20 18:13:14 +00001659
1660 /*
Bram Moolenaar1042fa32007-09-16 11:27:42 +00001661 * If there is only one window and it is the quickfix window, create a
1662 * new one above the quickfix window.
Bram Moolenaar38c0a6e2006-10-20 18:13:14 +00001663 */
1664 if (((firstwin == lastwin) && bt_quickfix(curbuf)) || !usable_win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001666 ll_ref = curwin->w_llist_ref;
1667
Bram Moolenaar884ae642009-02-22 01:37:59 +00001668 flags = WSP_ABOVE;
1669 if (ll_ref != NULL)
1670 flags |= WSP_NEWLOC;
1671 if (win_split(0, flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 goto failed; /* not enough room for window */
1673 opened_window = TRUE; /* close it when fail */
1674 p_swb = empty_option; /* don't split again */
Bram Moolenaar446cb832008-06-24 21:56:24 +00001675 swb_flags = 0;
Bram Moolenaar3368ea22010-09-21 16:56:35 +02001676 RESET_BINDING(curwin);
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001677 if (ll_ref != NULL)
1678 {
1679 /* The new window should use the location list from the
1680 * location list window */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001681 curwin->w_llist = ll_ref;
1682 ll_ref->qf_refcount++;
1683 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001684 }
1685 else
1686 {
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001687 if (curwin->w_llist_ref != NULL)
1688 {
1689 /* In a location window */
1690 ll_ref = curwin->w_llist_ref;
1691
1692 /* Find the window with the same location list */
1693 FOR_ALL_WINDOWS(win)
1694 if (win->w_llist == ll_ref)
1695 break;
1696 if (win == NULL)
1697 {
1698 /* Find the window showing the selected file */
1699 FOR_ALL_WINDOWS(win)
1700 if (win->w_buffer->b_fnum == qf_ptr->qf_fnum)
1701 break;
1702 if (win == NULL)
1703 {
1704 /* Find a previous usable window */
1705 win = curwin;
1706 do
1707 {
1708 if (win->w_buffer->b_p_bt[0] == NUL)
1709 break;
1710 if (win->w_prev == NULL)
1711 win = lastwin; /* wrap around the top */
1712 else
1713 win = win->w_prev; /* go to previous window */
1714 } while (win != curwin);
1715 }
1716 }
1717 win_goto(win);
1718
1719 /* If the location list for the window is not set, then set it
1720 * to the location list from the location window */
1721 if (win->w_llist == NULL)
1722 {
1723 win->w_llist = ll_ref;
1724 ll_ref->qf_refcount++;
1725 }
1726 }
1727 else
1728 {
1729
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730 /*
1731 * Try to find a window that shows the right buffer.
1732 * Default to the window just above the quickfix buffer.
1733 */
1734 win = curwin;
1735 altwin = NULL;
1736 for (;;)
1737 {
1738 if (win->w_buffer->b_fnum == qf_ptr->qf_fnum)
1739 break;
1740 if (win->w_prev == NULL)
1741 win = lastwin; /* wrap around the top */
1742 else
1743 win = win->w_prev; /* go to previous window */
1744
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001745 if (IS_QF_WINDOW(win))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {
1747 /* Didn't find it, go to the window before the quickfix
1748 * window. */
1749 if (altwin != NULL)
1750 win = altwin;
1751 else if (curwin->w_prev != NULL)
1752 win = curwin->w_prev;
1753 else
1754 win = curwin->w_next;
1755 break;
1756 }
1757
1758 /* Remember a usable window. */
1759 if (altwin == NULL && !win->w_p_pvw
1760 && win->w_buffer->b_p_bt[0] == NUL)
1761 altwin = win;
1762 }
1763
1764 win_goto(win);
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001765 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 }
1767 }
1768#endif
1769
1770 /*
1771 * If there is a file name,
1772 * read the wanted file if needed, and check autowrite etc.
1773 */
1774 old_curbuf = curbuf;
1775 old_lnum = curwin->w_cursor.lnum;
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001776
1777 if (qf_ptr->qf_fnum != 0)
1778 {
1779 if (qf_ptr->qf_type == 1)
1780 {
1781 /* Open help file (do_ecmd() will set b_help flag, readfile() will
1782 * set b_p_ro flag). */
1783 if (!can_abandon(curbuf, forceit))
1784 {
1785 EMSG(_(e_nowrtmsg));
1786 ok = FALSE;
1787 }
1788 else
1789 ok = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1,
Bram Moolenaar701f7af2008-11-15 13:12:07 +00001790 ECMD_HIDE + ECMD_SET_HELP,
1791 oldwin == curwin ? curwin : NULL);
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001792 }
1793 else
1794 ok = buflist_getfile(qf_ptr->qf_fnum,
1795 (linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit);
1796 }
1797
1798 if (ok == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001799 {
1800 /* When not switched to another buffer, still need to set pc mark */
1801 if (curbuf == old_curbuf)
1802 setpcmark();
1803
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001804 if (qf_ptr->qf_pattern == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 {
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001806 /*
1807 * Go to line with error, unless qf_lnum is 0.
1808 */
1809 i = qf_ptr->qf_lnum;
1810 if (i > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811 {
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001812 if (i > curbuf->b_ml.ml_line_count)
1813 i = curbuf->b_ml.ml_line_count;
1814 curwin->w_cursor.lnum = i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 }
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001816 if (qf_ptr->qf_col > 0)
1817 {
1818 curwin->w_cursor.col = qf_ptr->qf_col - 1;
1819 if (qf_ptr->qf_viscol == TRUE)
1820 {
1821 /*
1822 * Check each character from the beginning of the error
1823 * line up to the error column. For each tab character
1824 * found, reduce the error column value by the length of
1825 * a tab character.
1826 */
1827 line = ml_get_curline();
1828 screen_col = 0;
1829 for (char_col = 0; char_col < curwin->w_cursor.col; ++char_col)
1830 {
1831 if (*line == NUL)
1832 break;
1833 if (*line++ == '\t')
1834 {
1835 curwin->w_cursor.col -= 7 - (screen_col % 8);
1836 screen_col += 8 - (screen_col % 8);
1837 }
1838 else
1839 ++screen_col;
1840 }
1841 }
1842 check_cursor();
1843 }
1844 else
1845 beginline(BL_WHITE | BL_FIX);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 }
1847 else
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001848 {
1849 pos_T save_cursor;
1850
1851 /* Move the cursor to the first line in the buffer */
1852 save_cursor = curwin->w_cursor;
1853 curwin->w_cursor.lnum = 0;
Bram Moolenaar91a4e822008-01-19 14:59:58 +00001854 if (!do_search(NULL, '/', qf_ptr->qf_pattern, (long)1,
1855 SEARCH_KEEP, NULL))
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001856 curwin->w_cursor = save_cursor;
1857 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858
1859#ifdef FEAT_FOLDING
1860 if ((fdo_flags & FDO_QUICKFIX) && old_KeyTyped)
1861 foldOpenCursor();
1862#endif
1863 if (print_message)
1864 {
Bram Moolenaar8f55d102012-01-20 13:28:34 +01001865 /* Update the screen before showing the message, unless the screen
1866 * scrolled up. */
1867 if (!msg_scrolled)
1868 update_topline_redraw();
Bram Moolenaar071d4272004-06-13 20:20:40 +00001869 sprintf((char *)IObuff, _("(%d of %d)%s%s: "), qf_index,
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001870 qi->qf_lists[qi->qf_curlist].qf_count,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 qf_ptr->qf_cleared ? _(" (line deleted)") : "",
1872 (char *)qf_types(qf_ptr->qf_type, qf_ptr->qf_nr));
1873 /* Add the message, skipping leading whitespace and newlines. */
1874 len = (int)STRLEN(IObuff);
1875 qf_fmt_text(skipwhite(qf_ptr->qf_text), IObuff + len, IOSIZE - len);
1876
1877 /* Output the message. Overwrite to avoid scrolling when the 'O'
1878 * flag is present in 'shortmess'; But when not jumping, print the
1879 * whole message. */
1880 i = msg_scroll;
1881 if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum)
1882 msg_scroll = TRUE;
1883 else if (!msg_scrolled && shortmess(SHM_OVERALL))
1884 msg_scroll = FALSE;
1885 msg_attr_keep(IObuff, 0, TRUE);
1886 msg_scroll = i;
1887 }
1888 }
1889 else
1890 {
1891#ifdef FEAT_WINDOWS
1892 if (opened_window)
1893 win_close(curwin, TRUE); /* Close opened window */
1894#endif
1895 if (qf_ptr->qf_fnum != 0)
1896 {
1897 /*
1898 * Couldn't open file, so put index back where it was. This could
1899 * happen if the file was readonly and we changed something.
1900 */
1901#ifdef FEAT_WINDOWS
1902failed:
1903#endif
1904 qf_ptr = old_qf_ptr;
1905 qf_index = old_qf_index;
1906 }
1907 }
1908theend:
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001909 qi->qf_lists[qi->qf_curlist].qf_ptr = qf_ptr;
1910 qi->qf_lists[qi->qf_curlist].qf_index = qf_index;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001911#ifdef FEAT_WINDOWS
1912 if (p_swb != old_swb && opened_window)
1913 {
1914 /* Restore old 'switchbuf' value, but not when an autocommand or
1915 * modeline has changed the value. */
1916 if (p_swb == empty_option)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001917 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 p_swb = old_swb;
Bram Moolenaar446cb832008-06-24 21:56:24 +00001919 swb_flags = old_swb_flags;
1920 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921 else
1922 free_string_option(old_swb);
1923 }
1924#endif
1925}
1926
1927/*
1928 * ":clist": list all errors
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001929 * ":llist": list all locations
Bram Moolenaar071d4272004-06-13 20:20:40 +00001930 */
1931 void
1932qf_list(eap)
1933 exarg_T *eap;
1934{
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001935 buf_T *buf;
1936 char_u *fname;
1937 qfline_T *qfp;
1938 int i;
1939 int idx1 = 1;
1940 int idx2 = -1;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001941 char_u *arg = eap->arg;
1942 int all = eap->forceit; /* if not :cl!, only show
Bram Moolenaar071d4272004-06-13 20:20:40 +00001943 recognised errors */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001944 qf_info_T *qi = &ql_info;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001946 if (eap->cmdidx == CMD_llist)
1947 {
1948 qi = GET_LOC_LIST(curwin);
1949 if (qi == NULL)
1950 {
1951 EMSG(_(e_loclist));
1952 return;
1953 }
1954 }
1955
1956 if (qi->qf_curlist >= qi->qf_listcount
1957 || qi->qf_lists[qi->qf_curlist].qf_count == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001958 {
1959 EMSG(_(e_quickfix));
1960 return;
1961 }
1962 if (!get_list_range(&arg, &idx1, &idx2) || *arg != NUL)
1963 {
1964 EMSG(_(e_trailing));
1965 return;
1966 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001967 i = qi->qf_lists[qi->qf_curlist].qf_count;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001968 if (idx1 < 0)
1969 idx1 = (-idx1 > i) ? 0 : idx1 + i + 1;
1970 if (idx2 < 0)
1971 idx2 = (-idx2 > i) ? 0 : idx2 + i + 1;
1972
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001973 if (qi->qf_lists[qi->qf_curlist].qf_nonevalid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001974 all = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001975 qfp = qi->qf_lists[qi->qf_curlist].qf_start;
1976 for (i = 1; !got_int && i <= qi->qf_lists[qi->qf_curlist].qf_count; )
Bram Moolenaar071d4272004-06-13 20:20:40 +00001977 {
1978 if ((qfp->qf_valid || all) && idx1 <= i && i <= idx2)
1979 {
Bram Moolenaar2660c0e2010-01-19 14:59:56 +01001980 msg_putchar('\n');
1981 if (got_int)
1982 break;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00001983
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00001984 fname = NULL;
1985 if (qfp->qf_fnum != 0
1986 && (buf = buflist_findnr(qfp->qf_fnum)) != NULL)
1987 {
1988 fname = buf->b_fname;
1989 if (qfp->qf_type == 1) /* :helpgrep */
1990 fname = gettail(fname);
1991 }
1992 if (fname == NULL)
1993 sprintf((char *)IObuff, "%2d", i);
1994 else
1995 vim_snprintf((char *)IObuff, IOSIZE, "%2d %s",
1996 i, (char *)fname);
Bram Moolenaard12f5c12006-01-25 22:10:52 +00001997 msg_outtrans_attr(IObuff, i == qi->qf_lists[qi->qf_curlist].qf_index
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00001998 ? hl_attr(HLF_L) : hl_attr(HLF_D));
1999 if (qfp->qf_lnum == 0)
2000 IObuff[0] = NUL;
2001 else if (qfp->qf_col == 0)
2002 sprintf((char *)IObuff, ":%ld", qfp->qf_lnum);
2003 else
2004 sprintf((char *)IObuff, ":%ld col %d",
2005 qfp->qf_lnum, qfp->qf_col);
2006 sprintf((char *)IObuff + STRLEN(IObuff), "%s:",
2007 (char *)qf_types(qfp->qf_type, qfp->qf_nr));
2008 msg_puts_attr(IObuff, hl_attr(HLF_N));
2009 if (qfp->qf_pattern != NULL)
2010 {
2011 qf_fmt_text(qfp->qf_pattern, IObuff, IOSIZE);
2012 STRCAT(IObuff, ":");
2013 msg_puts(IObuff);
2014 }
2015 msg_puts((char_u *)" ");
2016
2017 /* Remove newlines and leading whitespace from the text. For an
2018 * unrecognized line keep the indent, the compiler may mark a word
2019 * with ^^^^. */
2020 qf_fmt_text((fname != NULL || qfp->qf_lnum != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002021 ? skipwhite(qfp->qf_text) : qfp->qf_text,
2022 IObuff, IOSIZE);
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00002023 msg_prt_line(IObuff, FALSE);
2024 out_flush(); /* show one line at a time */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002025 }
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00002026
2027 qfp = qfp->qf_next;
2028 ++i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002029 ui_breakcheck();
2030 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031}
2032
2033/*
2034 * Remove newlines and leading whitespace from an error message.
2035 * Put the result in "buf[bufsize]".
2036 */
2037 static void
2038qf_fmt_text(text, buf, bufsize)
2039 char_u *text;
2040 char_u *buf;
2041 int bufsize;
2042{
2043 int i;
2044 char_u *p = text;
2045
2046 for (i = 0; *p != NUL && i < bufsize - 1; ++i)
2047 {
2048 if (*p == '\n')
2049 {
2050 buf[i] = ' ';
2051 while (*++p != NUL)
2052 if (!vim_iswhite(*p) && *p != '\n')
2053 break;
2054 }
2055 else
2056 buf[i] = *p++;
2057 }
2058 buf[i] = NUL;
2059}
2060
2061/*
2062 * ":colder [count]": Up in the quickfix stack.
2063 * ":cnewer [count]": Down in the quickfix stack.
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002064 * ":lolder [count]": Up in the location list stack.
2065 * ":lnewer [count]": Down in the location list stack.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002066 */
2067 void
2068qf_age(eap)
2069 exarg_T *eap;
2070{
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002071 qf_info_T *qi = &ql_info;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072 int count;
2073
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002074 if (eap->cmdidx == CMD_lolder || eap->cmdidx == CMD_lnewer)
2075 {
2076 qi = GET_LOC_LIST(curwin);
2077 if (qi == NULL)
2078 {
2079 EMSG(_(e_loclist));
2080 return;
2081 }
2082 }
2083
Bram Moolenaar071d4272004-06-13 20:20:40 +00002084 if (eap->addr_count != 0)
2085 count = eap->line2;
2086 else
2087 count = 1;
2088 while (count--)
2089 {
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002090 if (eap->cmdidx == CMD_colder || eap->cmdidx == CMD_lolder)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002091 {
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002092 if (qi->qf_curlist == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002093 {
2094 EMSG(_("E380: At bottom of quickfix stack"));
2095 return;
2096 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002097 --qi->qf_curlist;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 }
2099 else
2100 {
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002101 if (qi->qf_curlist >= qi->qf_listcount - 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 {
2103 EMSG(_("E381: At top of quickfix stack"));
2104 return;
2105 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002106 ++qi->qf_curlist;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002107 }
2108 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002109 qf_msg(qi);
2110
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111}
2112
2113 static void
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002114qf_msg(qi)
2115 qf_info_T *qi;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116{
2117 smsg((char_u *)_("error list %d of %d; %d errors"),
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002118 qi->qf_curlist + 1, qi->qf_listcount,
2119 qi->qf_lists[qi->qf_curlist].qf_count);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002120#ifdef FEAT_WINDOWS
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002121 qf_update_buffer(qi);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122#endif
2123}
2124
2125/*
Bram Moolenaar77197e42005-12-08 22:00:22 +00002126 * Free error list "idx".
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127 */
2128 static void
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002129qf_free(qi, idx)
2130 qf_info_T *qi;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 int idx;
2132{
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002133 qfline_T *qfp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002135 while (qi->qf_lists[idx].qf_count)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 {
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002137 qfp = qi->qf_lists[idx].qf_start->qf_next;
2138 vim_free(qi->qf_lists[idx].qf_start->qf_text);
2139 vim_free(qi->qf_lists[idx].qf_start->qf_pattern);
2140 vim_free(qi->qf_lists[idx].qf_start);
2141 qi->qf_lists[idx].qf_start = qfp;
2142 --qi->qf_lists[idx].qf_count;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002143 }
Bram Moolenaar7fd73202010-07-25 16:58:46 +02002144 vim_free(qi->qf_lists[idx].qf_title);
Bram Moolenaar832f80e2010-08-17 20:26:59 +02002145 qi->qf_lists[idx].qf_title = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146}
2147
2148/*
2149 * qf_mark_adjust: adjust marks
2150 */
2151 void
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002152qf_mark_adjust(wp, line1, line2, amount, amount_after)
2153 win_T *wp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154 linenr_T line1;
2155 linenr_T line2;
2156 long amount;
2157 long amount_after;
2158{
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002159 int i;
2160 qfline_T *qfp;
2161 int idx;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002162 qf_info_T *qi = &ql_info;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002163
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002164 if (wp != NULL)
2165 {
2166 if (wp->w_llist == NULL)
2167 return;
2168 qi = wp->w_llist;
2169 }
2170
2171 for (idx = 0; idx < qi->qf_listcount; ++idx)
2172 if (qi->qf_lists[idx].qf_count)
2173 for (i = 0, qfp = qi->qf_lists[idx].qf_start;
2174 i < qi->qf_lists[idx].qf_count; ++i, qfp = qfp->qf_next)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002175 if (qfp->qf_fnum == curbuf->b_fnum)
2176 {
2177 if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2)
2178 {
2179 if (amount == MAXLNUM)
2180 qfp->qf_cleared = TRUE;
2181 else
2182 qfp->qf_lnum += amount;
2183 }
2184 else if (amount_after && qfp->qf_lnum > line2)
2185 qfp->qf_lnum += amount_after;
2186 }
2187}
2188
2189/*
2190 * Make a nice message out of the error character and the error number:
2191 * char number message
2192 * e or E 0 " error"
2193 * w or W 0 " warning"
2194 * i or I 0 " info"
2195 * 0 0 ""
2196 * other 0 " c"
2197 * e or E n " error n"
2198 * w or W n " warning n"
2199 * i or I n " info n"
2200 * 0 n " error n"
2201 * other n " c n"
2202 * 1 x "" :helpgrep
2203 */
2204 static char_u *
2205qf_types(c, nr)
2206 int c, nr;
2207{
2208 static char_u buf[20];
2209 static char_u cc[3];
2210 char_u *p;
2211
2212 if (c == 'W' || c == 'w')
2213 p = (char_u *)" warning";
2214 else if (c == 'I' || c == 'i')
2215 p = (char_u *)" info";
2216 else if (c == 'E' || c == 'e' || (c == 0 && nr > 0))
2217 p = (char_u *)" error";
2218 else if (c == 0 || c == 1)
2219 p = (char_u *)"";
2220 else
2221 {
2222 cc[0] = ' ';
2223 cc[1] = c;
2224 cc[2] = NUL;
2225 p = cc;
2226 }
2227
2228 if (nr <= 0)
2229 return p;
2230
2231 sprintf((char *)buf, "%s %3d", (char *)p, nr);
2232 return buf;
2233}
2234
2235#if defined(FEAT_WINDOWS) || defined(PROTO)
2236/*
2237 * ":cwindow": open the quickfix window if we have errors to display,
2238 * close it if not.
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002239 * ":lwindow": open the location list window if we have locations to display,
2240 * close it if not.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002241 */
2242 void
2243ex_cwindow(eap)
2244 exarg_T *eap;
2245{
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002246 qf_info_T *qi = &ql_info;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 win_T *win;
2248
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002249 if (eap->cmdidx == CMD_lwindow)
2250 {
2251 qi = GET_LOC_LIST(curwin);
2252 if (qi == NULL)
2253 return;
2254 }
2255
2256 /* Look for an existing quickfix window. */
2257 win = qf_find_win(qi);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002258
2259 /*
2260 * If a quickfix window is open but we have no errors to display,
2261 * close the window. If a quickfix window is not open, then open
2262 * it if we have errors; otherwise, leave it closed.
2263 */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002264 if (qi->qf_lists[qi->qf_curlist].qf_nonevalid
Bram Moolenaard236ac02011-05-05 17:14:14 +02002265 || qi->qf_lists[qi->qf_curlist].qf_count == 0
Bram Moolenaard68071d2006-05-02 22:08:30 +00002266 || qi->qf_curlist >= qi->qf_listcount)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267 {
2268 if (win != NULL)
2269 ex_cclose(eap);
2270 }
2271 else if (win == NULL)
2272 ex_copen(eap);
2273}
2274
2275/*
2276 * ":cclose": close the window showing the list of errors.
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002277 * ":lclose": close the window showing the location list
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279 void
2280ex_cclose(eap)
2281 exarg_T *eap;
2282{
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002283 win_T *win = NULL;
2284 qf_info_T *qi = &ql_info;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002285
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002286 if (eap->cmdidx == CMD_lclose || eap->cmdidx == CMD_lwindow)
2287 {
2288 qi = GET_LOC_LIST(curwin);
2289 if (qi == NULL)
2290 return;
2291 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002292
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002293 /* Find existing quickfix window and close it. */
2294 win = qf_find_win(qi);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002295 if (win != NULL)
2296 win_close(win, FALSE);
2297}
2298
2299/*
2300 * ":copen": open a window that shows the list of errors.
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002301 * ":lopen": open a window that shows the location list.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 */
2303 void
2304ex_copen(eap)
2305 exarg_T *eap;
2306{
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002307 qf_info_T *qi = &ql_info;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 int height;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 win_T *win;
Bram Moolenaar80a94a52006-02-23 21:26:58 +00002310 tabpage_T *prevtab = curtab;
Bram Moolenaar9c102382006-05-03 21:26:49 +00002311 buf_T *qf_buf;
Bram Moolenaar701f7af2008-11-15 13:12:07 +00002312 win_T *oldwin = curwin;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002314 if (eap->cmdidx == CMD_lopen || eap->cmdidx == CMD_lwindow)
2315 {
2316 qi = GET_LOC_LIST(curwin);
2317 if (qi == NULL)
2318 {
2319 EMSG(_(e_loclist));
2320 return;
2321 }
2322 }
2323
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 if (eap->addr_count != 0)
2325 height = eap->line2;
2326 else
2327 height = QF_WINHEIGHT;
2328
2329#ifdef FEAT_VISUAL
2330 reset_VIsual_and_resel(); /* stop Visual mode */
2331#endif
2332#ifdef FEAT_GUI
2333 need_mouse_correct = TRUE;
2334#endif
2335
2336 /*
2337 * Find existing quickfix window, or open a new one.
2338 */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002339 win = qf_find_win(qi);
2340
Bram Moolenaar80a94a52006-02-23 21:26:58 +00002341 if (win != NULL && cmdmod.tab == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002342 win_goto(win);
2343 else
2344 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00002345 qf_buf = qf_find_buf(qi);
2346
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 /* The current window becomes the previous window afterwards. */
2348 win = curwin;
2349
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002350 if (eap->cmdidx == CMD_copen || eap->cmdidx == CMD_cwindow)
2351 /* Create the new window at the very bottom. */
2352 win_goto(lastwin);
Bram Moolenaar884ae642009-02-22 01:37:59 +00002353 if (win_split(height, WSP_BELOW | WSP_NEWLOC) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 return; /* not enough room for window */
Bram Moolenaar3368ea22010-09-21 16:56:35 +02002355 RESET_BINDING(curwin);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002357 if (eap->cmdidx == CMD_lopen || eap->cmdidx == CMD_lwindow)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002358 {
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002359 /*
2360 * For the location list window, create a reference to the
2361 * location list from the window 'win'.
2362 */
2363 curwin->w_llist_ref = win->w_llist;
2364 win->w_llist->qf_refcount++;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002366
Bram Moolenaar701f7af2008-11-15 13:12:07 +00002367 if (oldwin != curwin)
2368 oldwin = NULL; /* don't store info when in another window */
Bram Moolenaar9c102382006-05-03 21:26:49 +00002369 if (qf_buf != NULL)
2370 /* Use the existing quickfix buffer */
2371 (void)do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE,
Bram Moolenaar701f7af2008-11-15 13:12:07 +00002372 ECMD_HIDE + ECMD_OLDBUF, oldwin);
Bram Moolenaar9c102382006-05-03 21:26:49 +00002373 else
2374 {
2375 /* Create a new quickfix buffer */
Bram Moolenaar701f7af2008-11-15 13:12:07 +00002376 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin);
Bram Moolenaar9c102382006-05-03 21:26:49 +00002377 /* switch off 'swapfile' */
2378 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
2379 set_option_value((char_u *)"bt", 0L, (char_u *)"quickfix",
Bram Moolenaar838bb712006-03-11 21:24:08 +00002380 OPT_LOCAL);
Bram Moolenaar9c102382006-05-03 21:26:49 +00002381 set_option_value((char_u *)"bh", 0L, (char_u *)"wipe", OPT_LOCAL);
Bram Moolenaar4161dcc2010-12-02 15:33:21 +01002382 RESET_BINDING(curwin);
Bram Moolenaar04c0f8a2009-04-29 09:52:12 +00002383#ifdef FEAT_DIFF
2384 curwin->w_p_diff = FALSE;
2385#endif
2386#ifdef FEAT_FOLDING
2387 set_option_value((char_u *)"fdm", 0L, (char_u *)"manual",
2388 OPT_LOCAL);
2389#endif
Bram Moolenaar9c102382006-05-03 21:26:49 +00002390 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391
Bram Moolenaar80a94a52006-02-23 21:26:58 +00002392 /* Only set the height when still in the same tab page and there is no
2393 * window to the side. */
2394 if (curtab == prevtab
Bram Moolenaar383f9bc2005-01-19 22:18:32 +00002395#ifdef FEAT_VERTSPLIT
Bram Moolenaar80a94a52006-02-23 21:26:58 +00002396 && curwin->w_width == Columns
Bram Moolenaar383f9bc2005-01-19 22:18:32 +00002397#endif
Bram Moolenaar80a94a52006-02-23 21:26:58 +00002398 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00002399 win_setheight(height);
2400 curwin->w_p_wfh = TRUE; /* set 'winfixheight' */
2401 if (win_valid(win))
2402 prevwin = win;
2403 }
2404
2405 /*
2406 * Fill the buffer with the quickfix list.
2407 */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002408 qf_fill_buffer(qi);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409
Bram Moolenaar7fd73202010-07-25 16:58:46 +02002410 if (qi->qf_lists[qi->qf_curlist].qf_title != NULL)
Bram Moolenaarc95e3262011-08-10 18:36:54 +02002411 qf_set_title(qi);
Bram Moolenaar7fd73202010-07-25 16:58:46 +02002412
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002413 curwin->w_cursor.lnum = qi->qf_lists[qi->qf_curlist].qf_index;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 curwin->w_cursor.col = 0;
2415 check_cursor();
2416 update_topline(); /* scroll to show the line */
2417}
2418
2419/*
2420 * Return the number of the current entry (line number in the quickfix
2421 * window).
2422 */
2423 linenr_T
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002424qf_current_entry(wp)
2425 win_T *wp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426{
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002427 qf_info_T *qi = &ql_info;
2428
2429 if (IS_LL_WINDOW(wp))
2430 /* In the location list window, use the referenced location list */
2431 qi = wp->w_llist_ref;
2432
2433 return qi->qf_lists[qi->qf_curlist].qf_index;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434}
2435
2436/*
2437 * Update the cursor position in the quickfix window to the current error.
2438 * Return TRUE if there is a quickfix window.
2439 */
2440 static int
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002441qf_win_pos_update(qi, old_qf_index)
2442 qf_info_T *qi;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 int old_qf_index; /* previous qf_index or zero */
2444{
2445 win_T *win;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002446 int qf_index = qi->qf_lists[qi->qf_curlist].qf_index;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447
2448 /*
2449 * Put the cursor on the current error in the quickfix window, so that
2450 * it's viewable.
2451 */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002452 win = qf_find_win(qi);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453 if (win != NULL
2454 && qf_index <= win->w_buffer->b_ml.ml_line_count
2455 && old_qf_index != qf_index)
2456 {
2457 win_T *old_curwin = curwin;
2458
2459 curwin = win;
2460 curbuf = win->w_buffer;
2461 if (qf_index > old_qf_index)
2462 {
2463 curwin->w_redraw_top = old_qf_index;
2464 curwin->w_redraw_bot = qf_index;
2465 }
2466 else
2467 {
2468 curwin->w_redraw_top = qf_index;
2469 curwin->w_redraw_bot = old_qf_index;
2470 }
2471 curwin->w_cursor.lnum = qf_index;
2472 curwin->w_cursor.col = 0;
2473 update_topline(); /* scroll to show the line */
2474 redraw_later(VALID);
2475 curwin->w_redr_status = TRUE; /* update ruler */
2476 curwin = old_curwin;
2477 curbuf = curwin->w_buffer;
2478 }
2479 return win != NULL;
2480}
2481
2482/*
Bram Moolenaar9c102382006-05-03 21:26:49 +00002483 * Check whether the given window is displaying the specified quickfix/location
2484 * list buffer
2485 */
2486 static int
2487is_qf_win(win, qi)
2488 win_T *win;
2489 qf_info_T *qi;
2490{
2491 /*
2492 * A window displaying the quickfix buffer will have the w_llist_ref field
2493 * set to NULL.
2494 * A window displaying a location list buffer will have the w_llist_ref
2495 * pointing to the location list.
2496 */
2497 if (bt_quickfix(win->w_buffer))
2498 if ((qi == &ql_info && win->w_llist_ref == NULL)
2499 || (qi != &ql_info && win->w_llist_ref == qi))
2500 return TRUE;
2501
2502 return FALSE;
2503}
2504
2505/*
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002506 * Find a window displaying the quickfix/location list 'qi'
Bram Moolenaar9c102382006-05-03 21:26:49 +00002507 * Searches in only the windows opened in the current tab.
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002508 */
2509 static win_T *
2510qf_find_win(qi)
2511 qf_info_T *qi;
2512{
2513 win_T *win;
2514
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002515 FOR_ALL_WINDOWS(win)
Bram Moolenaar9c102382006-05-03 21:26:49 +00002516 if (is_qf_win(win, qi))
2517 break;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002518
2519 return win;
2520}
2521
2522/*
Bram Moolenaar9c102382006-05-03 21:26:49 +00002523 * Find a quickfix buffer.
2524 * Searches in windows opened in all the tabs.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525 */
2526 static buf_T *
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002527qf_find_buf(qi)
2528 qf_info_T *qi;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529{
Bram Moolenaar9c102382006-05-03 21:26:49 +00002530 tabpage_T *tp;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002531 win_T *win;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532
Bram Moolenaar9c102382006-05-03 21:26:49 +00002533 FOR_ALL_TAB_WINDOWS(tp, win)
2534 if (is_qf_win(win, qi))
2535 return win->w_buffer;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002536
Bram Moolenaar9c102382006-05-03 21:26:49 +00002537 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538}
2539
2540/*
2541 * Find the quickfix buffer. If it exists, update the contents.
2542 */
2543 static void
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002544qf_update_buffer(qi)
2545 qf_info_T *qi;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546{
2547 buf_T *buf;
Bram Moolenaarc95e3262011-08-10 18:36:54 +02002548 win_T *win;
2549 win_T *curwin_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 aco_save_T aco;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551
2552 /* Check if a buffer for the quickfix list exists. Update it. */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002553 buf = qf_find_buf(qi);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 if (buf != NULL)
2555 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 /* set curwin/curbuf to buf and save a few things */
2557 aucmd_prepbuf(&aco, buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002558
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002559 qf_fill_buffer(qi);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560
Bram Moolenaarc95e3262011-08-10 18:36:54 +02002561 if (qi->qf_lists[qi->qf_curlist].qf_title != NULL
2562 && (win = qf_find_win(qi)) != NULL)
2563 {
2564 curwin_save = curwin;
2565 curwin = win;
2566 qf_set_title(qi);
2567 curwin = curwin_save;
2568
2569 }
2570
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 /* restore curwin/curbuf and a few other things */
2572 aucmd_restbuf(&aco);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002574 (void)qf_win_pos_update(qi, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 }
2576}
2577
Bram Moolenaarc95e3262011-08-10 18:36:54 +02002578 static void
2579qf_set_title(qi)
2580 qf_info_T *qi;
2581{
2582 set_internal_string_var((char_u *)"w:quickfix_title",
2583 qi->qf_lists[qi->qf_curlist].qf_title);
2584}
2585
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586/*
2587 * Fill current buffer with quickfix errors, replacing any previous contents.
2588 * curbuf must be the quickfix buffer!
2589 */
2590 static void
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002591qf_fill_buffer(qi)
2592 qf_info_T *qi;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002593{
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002594 linenr_T lnum;
2595 qfline_T *qfp;
2596 buf_T *errbuf;
2597 int len;
2598 int old_KeyTyped = KeyTyped;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599
2600 /* delete all existing lines */
2601 while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0)
2602 (void)ml_delete((linenr_T)1, FALSE);
2603
2604 /* Check if there is anything to display */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002605 if (qi->qf_curlist < qi->qf_listcount)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606 {
2607 /* Add one line for each error */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002608 qfp = qi->qf_lists[qi->qf_curlist].qf_start;
2609 for (lnum = 0; lnum < qi->qf_lists[qi->qf_curlist].qf_count; ++lnum)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 {
2611 if (qfp->qf_fnum != 0
2612 && (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL
2613 && errbuf->b_fname != NULL)
2614 {
2615 if (qfp->qf_type == 1) /* :helpgrep */
2616 STRCPY(IObuff, gettail(errbuf->b_fname));
2617 else
2618 STRCPY(IObuff, errbuf->b_fname);
2619 len = (int)STRLEN(IObuff);
2620 }
2621 else
2622 len = 0;
2623 IObuff[len++] = '|';
2624
2625 if (qfp->qf_lnum > 0)
2626 {
2627 sprintf((char *)IObuff + len, "%ld", qfp->qf_lnum);
2628 len += (int)STRLEN(IObuff + len);
2629
2630 if (qfp->qf_col > 0)
2631 {
2632 sprintf((char *)IObuff + len, " col %d", qfp->qf_col);
2633 len += (int)STRLEN(IObuff + len);
2634 }
2635
2636 sprintf((char *)IObuff + len, "%s",
2637 (char *)qf_types(qfp->qf_type, qfp->qf_nr));
2638 len += (int)STRLEN(IObuff + len);
2639 }
Bram Moolenaar68b76a62005-03-25 21:53:48 +00002640 else if (qfp->qf_pattern != NULL)
2641 {
2642 qf_fmt_text(qfp->qf_pattern, IObuff + len, IOSIZE - len);
2643 len += (int)STRLEN(IObuff + len);
2644 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 IObuff[len++] = '|';
2646 IObuff[len++] = ' ';
2647
2648 /* Remove newlines and leading whitespace from the text.
2649 * For an unrecognized line keep the indent, the compiler may
2650 * mark a word with ^^^^. */
2651 qf_fmt_text(len > 3 ? skipwhite(qfp->qf_text) : qfp->qf_text,
2652 IObuff + len, IOSIZE - len);
2653
2654 if (ml_append(lnum, IObuff, (colnr_T)STRLEN(IObuff) + 1, FALSE)
2655 == FAIL)
2656 break;
2657 qfp = qfp->qf_next;
2658 }
2659 /* Delete the empty line which is now at the end */
2660 (void)ml_delete(lnum + 1, FALSE);
2661 }
2662
2663 /* correct cursor position */
2664 check_lnums(TRUE);
2665
2666 /* Set the 'filetype' to "qf" each time after filling the buffer. This
2667 * resembles reading a file into a buffer, it's more logical when using
2668 * autocommands. */
2669 set_option_value((char_u *)"ft", 0L, (char_u *)"qf", OPT_LOCAL);
2670 curbuf->b_p_ma = FALSE;
2671
2672#ifdef FEAT_AUTOCMD
Bram Moolenaar04c0f8a2009-04-29 09:52:12 +00002673 keep_filetype = TRUE; /* don't detect 'filetype' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674 apply_autocmds(EVENT_BUFREADPOST, (char_u *)"quickfix", NULL,
2675 FALSE, curbuf);
2676 apply_autocmds(EVENT_BUFWINENTER, (char_u *)"quickfix", NULL,
2677 FALSE, curbuf);
Bram Moolenaar04c0f8a2009-04-29 09:52:12 +00002678 keep_filetype = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679#endif
2680
2681 /* make sure it will be redrawn */
2682 redraw_curbuf_later(NOT_VALID);
2683
2684 /* Restore KeyTyped, setting 'filetype' may reset it. */
2685 KeyTyped = old_KeyTyped;
2686}
2687
2688#endif /* FEAT_WINDOWS */
2689
2690/*
2691 * Return TRUE if "buf" is the quickfix buffer.
2692 */
2693 int
2694bt_quickfix(buf)
2695 buf_T *buf;
2696{
Bram Moolenaarfc573802011-12-30 15:01:59 +01002697 return buf != NULL && buf->b_p_bt[0] == 'q';
Bram Moolenaar071d4272004-06-13 20:20:40 +00002698}
2699
2700/*
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002701 * Return TRUE if "buf" is a "nofile" or "acwrite" buffer.
2702 * This means the buffer name is not a file name.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002703 */
2704 int
2705bt_nofile(buf)
2706 buf_T *buf;
2707{
Bram Moolenaarfc573802011-12-30 15:01:59 +01002708 return buf != NULL && ((buf->b_p_bt[0] == 'n' && buf->b_p_bt[2] == 'f')
2709 || buf->b_p_bt[0] == 'a');
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710}
2711
2712/*
2713 * Return TRUE if "buf" is a "nowrite" or "nofile" buffer.
2714 */
2715 int
2716bt_dontwrite(buf)
2717 buf_T *buf;
2718{
Bram Moolenaarfc573802011-12-30 15:01:59 +01002719 return buf != NULL && buf->b_p_bt[0] == 'n';
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720}
2721
2722 int
2723bt_dontwrite_msg(buf)
2724 buf_T *buf;
2725{
2726 if (bt_dontwrite(buf))
2727 {
2728 EMSG(_("E382: Cannot write, 'buftype' option is set"));
2729 return TRUE;
2730 }
2731 return FALSE;
2732}
2733
2734/*
2735 * Return TRUE if the buffer should be hidden, according to 'hidden', ":hide"
2736 * and 'bufhidden'.
2737 */
2738 int
2739buf_hide(buf)
2740 buf_T *buf;
2741{
2742 /* 'bufhidden' overrules 'hidden' and ":hide", check it first */
2743 switch (buf->b_p_bh[0])
2744 {
2745 case 'u': /* "unload" */
2746 case 'w': /* "wipe" */
2747 case 'd': return FALSE; /* "delete" */
2748 case 'h': return TRUE; /* "hide" */
2749 }
2750 return (p_hid || cmdmod.hide);
2751}
2752
2753/*
Bram Moolenaar86b68352004-12-27 21:59:20 +00002754 * Return TRUE when using ":vimgrep" for ":grep".
2755 */
2756 int
Bram Moolenaar81695252004-12-29 20:58:21 +00002757grep_internal(cmdidx)
2758 cmdidx_T cmdidx;
Bram Moolenaar86b68352004-12-27 21:59:20 +00002759{
Bram Moolenaar754b5602006-02-09 23:53:20 +00002760 return ((cmdidx == CMD_grep
2761 || cmdidx == CMD_lgrep
2762 || cmdidx == CMD_grepadd
2763 || cmdidx == CMD_lgrepadd)
Bram Moolenaar86b68352004-12-27 21:59:20 +00002764 && STRCMP("internal",
2765 *curbuf->b_p_gp == NUL ? p_gp : curbuf->b_p_gp) == 0);
2766}
2767
2768/*
Bram Moolenaara6557602006-02-04 22:43:20 +00002769 * Used for ":make", ":lmake", ":grep", ":lgrep", ":grepadd", and ":lgrepadd"
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 */
2771 void
2772ex_make(eap)
2773 exarg_T *eap;
2774{
Bram Moolenaar7c626922005-02-07 22:01:03 +00002775 char_u *fname;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002776 char_u *cmd;
2777 unsigned len;
Bram Moolenaara6557602006-02-04 22:43:20 +00002778 win_T *wp = NULL;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00002779 qf_info_T *qi = &ql_info;
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00002780 int res;
Bram Moolenaar7c626922005-02-07 22:01:03 +00002781#ifdef FEAT_AUTOCMD
2782 char_u *au_name = NULL;
2783
Bram Moolenaard88e02d2011-04-28 17:27:09 +02002784 /* Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". */
2785 if (grep_internal(eap->cmdidx))
2786 {
2787 ex_vimgrep(eap);
2788 return;
2789 }
2790
Bram Moolenaar7c626922005-02-07 22:01:03 +00002791 switch (eap->cmdidx)
2792 {
Bram Moolenaar754b5602006-02-09 23:53:20 +00002793 case CMD_make: au_name = (char_u *)"make"; break;
2794 case CMD_lmake: au_name = (char_u *)"lmake"; break;
2795 case CMD_grep: au_name = (char_u *)"grep"; break;
2796 case CMD_lgrep: au_name = (char_u *)"lgrep"; break;
2797 case CMD_grepadd: au_name = (char_u *)"grepadd"; break;
2798 case CMD_lgrepadd: au_name = (char_u *)"lgrepadd"; break;
Bram Moolenaar7c626922005-02-07 22:01:03 +00002799 default: break;
2800 }
2801 if (au_name != NULL)
2802 {
2803 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name,
2804 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar1e015462005-09-25 22:16:38 +00002805# ifdef FEAT_EVAL
Bram Moolenaar7c626922005-02-07 22:01:03 +00002806 if (did_throw || force_abort)
2807 return;
Bram Moolenaar1e015462005-09-25 22:16:38 +00002808# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002809 }
2810#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811
Bram Moolenaara6557602006-02-04 22:43:20 +00002812 if (eap->cmdidx == CMD_lmake || eap->cmdidx == CMD_lgrep
2813 || eap->cmdidx == CMD_lgrepadd)
Bram Moolenaara6557602006-02-04 22:43:20 +00002814 wp = curwin;
Bram Moolenaara6557602006-02-04 22:43:20 +00002815
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816 autowrite_all();
Bram Moolenaar7c626922005-02-07 22:01:03 +00002817 fname = get_mef_name();
2818 if (fname == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002819 return;
Bram Moolenaar7c626922005-02-07 22:01:03 +00002820 mch_remove(fname); /* in case it's not unique */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821
2822 /*
2823 * If 'shellpipe' empty: don't redirect to 'errorfile'.
2824 */
2825 len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(eap->arg) + 1;
2826 if (*p_sp != NUL)
Bram Moolenaar7c626922005-02-07 22:01:03 +00002827 len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 cmd = alloc(len);
2829 if (cmd == NULL)
2830 return;
2831 sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg,
2832 (char *)p_shq);
2833 if (*p_sp != NUL)
Bram Moolenaar5fd0ca72009-05-13 16:56:33 +00002834 append_redir(cmd, len, p_sp, fname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 /*
2836 * Output a newline if there's something else than the :make command that
2837 * was typed (in which case the cursor is in column 0).
2838 */
2839 if (msg_col == 0)
2840 msg_didout = FALSE;
2841 msg_start();
2842 MSG_PUTS(":!");
2843 msg_outtrans(cmd); /* show what we are doing */
2844
2845 /* let the shell know if we are redirecting output or not */
2846 do_shell(cmd, *p_sp != NUL ? SHELL_DOOUT : 0);
2847
2848#ifdef AMIGA
2849 out_flush();
2850 /* read window status report and redraw before message */
2851 (void)char_avail();
2852#endif
2853
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00002854 res = qf_init(wp, fname, (eap->cmdidx != CMD_make
Bram Moolenaara6557602006-02-04 22:43:20 +00002855 && eap->cmdidx != CMD_lmake) ? p_gefm : p_efm,
2856 (eap->cmdidx != CMD_grepadd
Bram Moolenaar7fd73202010-07-25 16:58:46 +02002857 && eap->cmdidx != CMD_lgrepadd),
2858 *eap->cmdlinep);
Bram Moolenaarefa8e802011-05-19 17:42:59 +02002859 if (wp != NULL)
2860 qi = GET_LOC_LIST(wp);
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00002861#ifdef FEAT_AUTOCMD
2862 if (au_name != NULL)
Bram Moolenaarefa8e802011-05-19 17:42:59 +02002863 {
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00002864 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
2865 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaarefa8e802011-05-19 17:42:59 +02002866 if (qi->qf_curlist < qi->qf_listcount)
2867 res = qi->qf_lists[qi->qf_curlist].qf_count;
2868 else
2869 res = 0;
2870 }
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00002871#endif
2872 if (res > 0 && !eap->forceit)
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00002873 qf_jump(qi, 0, 0, FALSE); /* display first error */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874
Bram Moolenaar7c626922005-02-07 22:01:03 +00002875 mch_remove(fname);
2876 vim_free(fname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 vim_free(cmd);
2878}
2879
2880/*
2881 * Return the name for the errorfile, in allocated memory.
2882 * Find a new unique name when 'makeef' contains "##".
2883 * Returns NULL for error.
2884 */
2885 static char_u *
2886get_mef_name()
2887{
2888 char_u *p;
2889 char_u *name;
2890 static int start = -1;
2891 static int off = 0;
2892#ifdef HAVE_LSTAT
2893 struct stat sb;
2894#endif
2895
2896 if (*p_mef == NUL)
2897 {
2898 name = vim_tempname('e');
2899 if (name == NULL)
2900 EMSG(_(e_notmp));
2901 return name;
2902 }
2903
2904 for (p = p_mef; *p; ++p)
2905 if (p[0] == '#' && p[1] == '#')
2906 break;
2907
2908 if (*p == NUL)
2909 return vim_strsave(p_mef);
2910
2911 /* Keep trying until the name doesn't exist yet. */
2912 for (;;)
2913 {
2914 if (start == -1)
2915 start = mch_get_pid();
2916 else
2917 off += 19;
2918
2919 name = alloc((unsigned)STRLEN(p_mef) + 30);
2920 if (name == NULL)
2921 break;
2922 STRCPY(name, p_mef);
2923 sprintf((char *)name + (p - p_mef), "%d%d", start, off);
2924 STRCAT(name, p + 2);
2925 if (mch_getperm(name) < 0
2926#ifdef HAVE_LSTAT
2927 /* Don't accept a symbolic link, its a security risk. */
2928 && mch_lstat((char *)name, &sb) < 0
2929#endif
2930 )
2931 break;
2932 vim_free(name);
2933 }
2934 return name;
2935}
2936
2937/*
2938 * ":cc", ":crewind", ":cfirst" and ":clast".
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002939 * ":ll", ":lrewind", ":lfirst" and ":llast".
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940 */
2941 void
2942ex_cc(eap)
2943 exarg_T *eap;
2944{
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00002945 qf_info_T *qi = &ql_info;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002946
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00002947 if (eap->cmdidx == CMD_ll
2948 || eap->cmdidx == CMD_lrewind
2949 || eap->cmdidx == CMD_lfirst
2950 || eap->cmdidx == CMD_llast)
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002951 {
2952 qi = GET_LOC_LIST(curwin);
2953 if (qi == NULL)
2954 {
2955 EMSG(_(e_loclist));
2956 return;
2957 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002958 }
2959
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00002960 qf_jump(qi, 0,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961 eap->addr_count > 0
2962 ? (int)eap->line2
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002963 : (eap->cmdidx == CMD_cc || eap->cmdidx == CMD_ll)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964 ? 0
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002965 : (eap->cmdidx == CMD_crewind || eap->cmdidx == CMD_lrewind
2966 || eap->cmdidx == CMD_cfirst || eap->cmdidx == CMD_lfirst)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 ? 1
2968 : 32767,
2969 eap->forceit);
2970}
2971
2972/*
2973 * ":cnext", ":cnfile", ":cNext" and ":cprevious".
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002974 * ":lnext", ":lNext", ":lprevious", ":lnfile", ":lNfile" and ":lpfile".
Bram Moolenaar071d4272004-06-13 20:20:40 +00002975 */
2976 void
2977ex_cnext(eap)
2978 exarg_T *eap;
2979{
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00002980 qf_info_T *qi = &ql_info;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002981
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00002982 if (eap->cmdidx == CMD_lnext
2983 || eap->cmdidx == CMD_lNext
2984 || eap->cmdidx == CMD_lprevious
2985 || eap->cmdidx == CMD_lnfile
2986 || eap->cmdidx == CMD_lNfile
2987 || eap->cmdidx == CMD_lpfile)
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002988 {
2989 qi = GET_LOC_LIST(curwin);
2990 if (qi == NULL)
2991 {
2992 EMSG(_(e_loclist));
2993 return;
2994 }
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002995 }
2996
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00002997 qf_jump(qi, (eap->cmdidx == CMD_cnext || eap->cmdidx == CMD_lnext)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 ? FORWARD
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002999 : (eap->cmdidx == CMD_cnfile || eap->cmdidx == CMD_lnfile)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000 ? FORWARD_FILE
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003001 : (eap->cmdidx == CMD_cpfile || eap->cmdidx == CMD_lpfile
3002 || eap->cmdidx == CMD_cNfile || eap->cmdidx == CMD_lNfile)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 ? BACKWARD_FILE
3004 : BACKWARD,
3005 eap->addr_count > 0 ? (int)eap->line2 : 1, eap->forceit);
3006}
3007
3008/*
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00003009 * ":cfile"/":cgetfile"/":caddfile" commands.
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003010 * ":lfile"/":lgetfile"/":laddfile" commands.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 */
3012 void
3013ex_cfile(eap)
3014 exarg_T *eap;
3015{
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003016 win_T *wp = NULL;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00003017 qf_info_T *qi = &ql_info;
Bram Moolenaar8ec1f852012-03-07 20:13:49 +01003018#ifdef FEAT_AUTOCMD
3019 char_u *au_name = NULL;
3020#endif
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003021
3022 if (eap->cmdidx == CMD_lfile || eap->cmdidx == CMD_lgetfile
Bram Moolenaar8ec1f852012-03-07 20:13:49 +01003023 || eap->cmdidx == CMD_laddfile)
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003024 wp = curwin;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003025
Bram Moolenaar8ec1f852012-03-07 20:13:49 +01003026#ifdef FEAT_AUTOCMD
3027 switch (eap->cmdidx)
3028 {
3029 case CMD_cfile: au_name = (char_u *)"cfile"; break;
3030 case CMD_cgetfile: au_name = (char_u *)"cgetfile"; break;
3031 case CMD_caddfile: au_name = (char_u *)"caddfile"; break;
3032 case CMD_lfile: au_name = (char_u *)"lfile"; break;
3033 case CMD_lgetfile: au_name = (char_u *)"lgetfile"; break;
3034 case CMD_laddfile: au_name = (char_u *)"laddfile"; break;
3035 default: break;
3036 }
3037 if (au_name != NULL)
3038 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, NULL, FALSE, curbuf);
3039#endif
Bram Moolenaar9028b102010-07-11 16:58:51 +02003040#ifdef FEAT_BROWSE
3041 if (cmdmod.browse)
3042 {
3043 char_u *browse_file = do_browse(0, (char_u *)_("Error file"), eap->arg,
3044 NULL, NULL, BROWSE_FILTER_ALL_FILES, NULL);
3045 if (browse_file == NULL)
3046 return;
3047 set_string_option_direct((char_u *)"ef", -1, browse_file, OPT_FREE, 0);
3048 vim_free(browse_file);
3049 }
3050 else
3051#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 if (*eap->arg != NUL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003053 set_string_option_direct((char_u *)"ef", -1, eap->arg, OPT_FREE, 0);
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00003054
3055 /*
3056 * This function is used by the :cfile, :cgetfile and :caddfile
3057 * commands.
3058 * :cfile always creates a new quickfix list and jumps to the
3059 * first error.
3060 * :cgetfile creates a new quickfix list but doesn't jump to the
3061 * first error.
3062 * :caddfile adds to an existing quickfix list. If there is no
3063 * quickfix list then a new list is created.
3064 */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003065 if (qf_init(wp, p_ef, p_efm, (eap->cmdidx != CMD_caddfile
Bram Moolenaar7fd73202010-07-25 16:58:46 +02003066 && eap->cmdidx != CMD_laddfile),
3067 *eap->cmdlinep) > 0
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003068 && (eap->cmdidx == CMD_cfile
3069 || eap->cmdidx == CMD_lfile))
Bram Moolenaarc7453f52006-02-10 23:20:28 +00003070 {
Bram Moolenaar8ec1f852012-03-07 20:13:49 +01003071#ifdef FEAT_AUTOCMD
3072 if (au_name != NULL)
3073 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf);
3074#endif
Bram Moolenaarc7453f52006-02-10 23:20:28 +00003075 if (wp != NULL)
3076 qi = GET_LOC_LIST(wp);
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00003077 qf_jump(qi, 0, 0, eap->forceit); /* display first error */
Bram Moolenaarc7453f52006-02-10 23:20:28 +00003078 }
Bram Moolenaar8ec1f852012-03-07 20:13:49 +01003079
3080 else
3081 {
3082#ifdef FEAT_AUTOCMD
3083 if (au_name != NULL)
3084 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf);
3085#endif
3086 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087}
3088
3089/*
Bram Moolenaar86b68352004-12-27 21:59:20 +00003090 * ":vimgrep {pattern} file(s)"
Bram Moolenaara6557602006-02-04 22:43:20 +00003091 * ":vimgrepadd {pattern} file(s)"
3092 * ":lvimgrep {pattern} file(s)"
3093 * ":lvimgrepadd {pattern} file(s)"
Bram Moolenaar86b68352004-12-27 21:59:20 +00003094 */
3095 void
3096ex_vimgrep(eap)
3097 exarg_T *eap;
3098{
Bram Moolenaar81695252004-12-29 20:58:21 +00003099 regmmatch_T regmatch;
Bram Moolenaar748bf032005-02-02 23:04:36 +00003100 int fcount;
Bram Moolenaar86b68352004-12-27 21:59:20 +00003101 char_u **fnames;
Bram Moolenaard089d9b2007-09-30 12:02:55 +00003102 char_u *fname;
Bram Moolenaar748bf032005-02-02 23:04:36 +00003103 char_u *s;
3104 char_u *p;
Bram Moolenaar748bf032005-02-02 23:04:36 +00003105 int fi;
Bram Moolenaara6557602006-02-04 22:43:20 +00003106 qf_info_T *qi = &ql_info;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003107 qfline_T *prevp = NULL;
Bram Moolenaar86b68352004-12-27 21:59:20 +00003108 long lnum;
Bram Moolenaar81695252004-12-29 20:58:21 +00003109 buf_T *buf;
3110 int duplicate_name = FALSE;
3111 int using_dummy;
Bram Moolenaar1042fa32007-09-16 11:27:42 +00003112 int redraw_for_dummy = FALSE;
Bram Moolenaar81695252004-12-29 20:58:21 +00003113 int found_match;
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003114 buf_T *first_match_buf = NULL;
3115 time_t seconds = 0;
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003116 int save_mls;
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003117#if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
3118 char_u *save_ei = NULL;
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003119#endif
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003120 aco_save_T aco;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003121 int flags = 0;
3122 colnr_T col;
Bram Moolenaar1f35bf92006-03-07 22:38:47 +00003123 long tomatch;
Bram Moolenaard9462e32011-04-11 21:35:11 +02003124 char_u *dirname_start = NULL;
3125 char_u *dirname_now = NULL;
Bram Moolenaard089d9b2007-09-30 12:02:55 +00003126 char_u *target_dir = NULL;
Bram Moolenaar15bfa092008-07-24 16:45:38 +00003127#ifdef FEAT_AUTOCMD
3128 char_u *au_name = NULL;
Bram Moolenaar7c626922005-02-07 22:01:03 +00003129
3130 switch (eap->cmdidx)
3131 {
Bram Moolenaard88e02d2011-04-28 17:27:09 +02003132 case CMD_vimgrep: au_name = (char_u *)"vimgrep"; break;
3133 case CMD_lvimgrep: au_name = (char_u *)"lvimgrep"; break;
3134 case CMD_vimgrepadd: au_name = (char_u *)"vimgrepadd"; break;
Bram Moolenaara6557602006-02-04 22:43:20 +00003135 case CMD_lvimgrepadd: au_name = (char_u *)"lvimgrepadd"; break;
Bram Moolenaard88e02d2011-04-28 17:27:09 +02003136 case CMD_grep: au_name = (char_u *)"grep"; break;
3137 case CMD_lgrep: au_name = (char_u *)"lgrep"; break;
3138 case CMD_grepadd: au_name = (char_u *)"grepadd"; break;
3139 case CMD_lgrepadd: au_name = (char_u *)"lgrepadd"; break;
Bram Moolenaar7c626922005-02-07 22:01:03 +00003140 default: break;
3141 }
3142 if (au_name != NULL)
3143 {
3144 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name,
3145 curbuf->b_fname, TRUE, curbuf);
3146 if (did_throw || force_abort)
3147 return;
3148 }
3149#endif
Bram Moolenaar86b68352004-12-27 21:59:20 +00003150
Bram Moolenaar754b5602006-02-09 23:53:20 +00003151 if (eap->cmdidx == CMD_lgrep
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00003152 || eap->cmdidx == CMD_lvimgrep
3153 || eap->cmdidx == CMD_lgrepadd
3154 || eap->cmdidx == CMD_lvimgrepadd)
Bram Moolenaara6557602006-02-04 22:43:20 +00003155 {
3156 qi = ll_get_or_alloc_list(curwin);
3157 if (qi == NULL)
3158 return;
Bram Moolenaara6557602006-02-04 22:43:20 +00003159 }
3160
Bram Moolenaar1f35bf92006-03-07 22:38:47 +00003161 if (eap->addr_count > 0)
3162 tomatch = eap->line2;
3163 else
3164 tomatch = MAXLNUM;
3165
Bram Moolenaar81695252004-12-29 20:58:21 +00003166 /* Get the search pattern: either white-separated or enclosed in // */
Bram Moolenaar86b68352004-12-27 21:59:20 +00003167 regmatch.regprog = NULL;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003168 p = skip_vimgrep_pat(eap->arg, &s, &flags);
Bram Moolenaar748bf032005-02-02 23:04:36 +00003169 if (p == NULL)
Bram Moolenaar86b68352004-12-27 21:59:20 +00003170 {
Bram Moolenaar2389c3c2005-05-22 22:07:59 +00003171 EMSG(_(e_invalpat));
Bram Moolenaar748bf032005-02-02 23:04:36 +00003172 goto theend;
Bram Moolenaar81695252004-12-29 20:58:21 +00003173 }
Bram Moolenaar81695252004-12-29 20:58:21 +00003174 regmatch.regprog = vim_regcomp(s, RE_MAGIC);
Bram Moolenaar86b68352004-12-27 21:59:20 +00003175 if (regmatch.regprog == NULL)
3176 goto theend;
Bram Moolenaar5f2bb9f2005-01-11 21:29:04 +00003177 regmatch.rmm_ic = p_ic;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00003178 regmatch.rmm_maxcol = 0;
Bram Moolenaar86b68352004-12-27 21:59:20 +00003179
3180 p = skipwhite(p);
3181 if (*p == NUL)
3182 {
3183 EMSG(_("E683: File name missing or invalid pattern"));
3184 goto theend;
3185 }
3186
Bram Moolenaar754b5602006-02-09 23:53:20 +00003187 if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd &&
Bram Moolenaara6557602006-02-04 22:43:20 +00003188 eap->cmdidx != CMD_vimgrepadd && eap->cmdidx != CMD_lvimgrepadd)
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003189 || qi->qf_curlist == qi->qf_listcount)
Bram Moolenaar86b68352004-12-27 21:59:20 +00003190 /* make place for a new list */
Bram Moolenaar41b884b2012-11-14 22:38:08 +01003191 qf_new_list(qi, *eap->cmdlinep, curwin);
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003192 else if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
Bram Moolenaar86b68352004-12-27 21:59:20 +00003193 /* Adding to existing list, find last entry. */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003194 for (prevp = qi->qf_lists[qi->qf_curlist].qf_start;
Bram Moolenaar86b68352004-12-27 21:59:20 +00003195 prevp->qf_next != prevp; prevp = prevp->qf_next)
3196 ;
3197
3198 /* parse the list of arguments */
Bram Moolenaar8f5c6f02012-06-29 12:57:06 +02003199 if (get_arglist_exp(p, &fcount, &fnames, TRUE) == FAIL)
Bram Moolenaar86b68352004-12-27 21:59:20 +00003200 goto theend;
3201 if (fcount == 0)
3202 {
3203 EMSG(_(e_nomatch));
3204 goto theend;
3205 }
3206
Bram Moolenaard9462e32011-04-11 21:35:11 +02003207 dirname_start = alloc(MAXPATHL);
3208 dirname_now = alloc(MAXPATHL);
3209 if (dirname_start == NULL || dirname_now == NULL)
3210 goto theend;
3211
Bram Moolenaard089d9b2007-09-30 12:02:55 +00003212 /* Remember the current directory, because a BufRead autocommand that does
3213 * ":lcd %:p:h" changes the meaning of short path names. */
3214 mch_dirname(dirname_start, MAXPATHL);
3215
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003216 seconds = (time_t)0;
Bram Moolenaar1f35bf92006-03-07 22:38:47 +00003217 for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi)
Bram Moolenaar86b68352004-12-27 21:59:20 +00003218 {
Bram Moolenaard089d9b2007-09-30 12:02:55 +00003219 fname = shorten_fname1(fnames[fi]);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003220 if (time(NULL) > seconds)
3221 {
Bram Moolenaard089d9b2007-09-30 12:02:55 +00003222 /* Display the file name every second or so, show the user we are
3223 * working on it. */
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003224 seconds = time(NULL);
3225 msg_start();
Bram Moolenaard089d9b2007-09-30 12:02:55 +00003226 p = msg_strtrunc(fname, TRUE);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003227 if (p == NULL)
Bram Moolenaard089d9b2007-09-30 12:02:55 +00003228 msg_outtrans(fname);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003229 else
3230 {
3231 msg_outtrans(p);
3232 vim_free(p);
3233 }
3234 msg_clr_eos();
3235 msg_didout = FALSE; /* overwrite this message */
3236 msg_nowait = TRUE; /* don't wait for this message */
3237 msg_col = 0;
3238 out_flush();
3239 }
3240
Bram Moolenaar81695252004-12-29 20:58:21 +00003241 buf = buflist_findname_exp(fnames[fi]);
3242 if (buf == NULL || buf->b_ml.ml_mfp == NULL)
3243 {
3244 /* Remember that a buffer with this name already exists. */
3245 duplicate_name = (buf != NULL);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003246 using_dummy = TRUE;
Bram Moolenaar1042fa32007-09-16 11:27:42 +00003247 redraw_for_dummy = TRUE;
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003248
3249#if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
3250 /* Don't do Filetype autocommands to avoid loading syntax and
3251 * indent scripts, a great speed improvement. */
3252 save_ei = au_event_disable(",Filetype");
3253#endif
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003254 /* Don't use modelines here, it's useless. */
3255 save_mls = p_mls;
3256 p_mls = 0;
Bram Moolenaar81695252004-12-29 20:58:21 +00003257
3258 /* Load file into a buffer, so that 'fileencoding' is detected,
3259 * autocommands applied, etc. */
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003260 buf = load_dummy_buffer(fname, dirname_start, dirname_now);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003261
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003262 p_mls = save_mls;
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003263#if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
3264 au_event_restore(save_ei);
3265#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00003266 }
3267 else
3268 /* Use existing, loaded buffer. */
3269 using_dummy = FALSE;
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003270
Bram Moolenaar81695252004-12-29 20:58:21 +00003271 if (buf == NULL)
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003272 {
3273 if (!got_int)
Bram Moolenaard089d9b2007-09-30 12:02:55 +00003274 smsg((char_u *)_("Cannot open file \"%s\""), fname);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003275 }
Bram Moolenaar86b68352004-12-27 21:59:20 +00003276 else
3277 {
Bram Moolenaara3227e22006-03-08 21:32:40 +00003278 /* Try for a match in all lines of the buffer.
3279 * For ":1vimgrep" look for first match only. */
Bram Moolenaar81695252004-12-29 20:58:21 +00003280 found_match = FALSE;
Bram Moolenaar1f35bf92006-03-07 22:38:47 +00003281 for (lnum = 1; lnum <= buf->b_ml.ml_line_count && tomatch > 0;
3282 ++lnum)
Bram Moolenaar86b68352004-12-27 21:59:20 +00003283 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003284 col = 0;
3285 while (vim_regexec_multi(&regmatch, curwin, buf, lnum,
Bram Moolenaar91a4e822008-01-19 14:59:58 +00003286 col, NULL) > 0)
Bram Moolenaar86b68352004-12-27 21:59:20 +00003287 {
Bram Moolenaard089d9b2007-09-30 12:02:55 +00003288 ;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003289 if (qf_add_entry(qi, &prevp,
Bram Moolenaar86b68352004-12-27 21:59:20 +00003290 NULL, /* dir */
Bram Moolenaard089d9b2007-09-30 12:02:55 +00003291 fname,
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00003292 0,
Bram Moolenaar81695252004-12-29 20:58:21 +00003293 ml_get_buf(buf,
3294 regmatch.startpos[0].lnum + lnum, FALSE),
3295 regmatch.startpos[0].lnum + lnum,
3296 regmatch.startpos[0].col + 1,
Bram Moolenaar05159a02005-02-26 23:04:13 +00003297 FALSE, /* vis_col */
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003298 NULL, /* search pattern */
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00003299 0, /* nr */
3300 0, /* type */
3301 TRUE /* valid */
Bram Moolenaar86b68352004-12-27 21:59:20 +00003302 ) == FAIL)
3303 {
3304 got_int = TRUE;
3305 break;
3306 }
Bram Moolenaar1f35bf92006-03-07 22:38:47 +00003307 found_match = TRUE;
3308 if (--tomatch == 0)
3309 break;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003310 if ((flags & VGR_GLOBAL) == 0
3311 || regmatch.endpos[0].lnum > 0)
3312 break;
3313 col = regmatch.endpos[0].col
3314 + (col == regmatch.endpos[0].col);
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003315 if (col > (colnr_T)STRLEN(ml_get_buf(buf, lnum, FALSE)))
Bram Moolenaar05159a02005-02-26 23:04:13 +00003316 break;
Bram Moolenaar86b68352004-12-27 21:59:20 +00003317 }
Bram Moolenaar86b68352004-12-27 21:59:20 +00003318 line_breakcheck();
Bram Moolenaar81695252004-12-29 20:58:21 +00003319 if (got_int)
3320 break;
Bram Moolenaar86b68352004-12-27 21:59:20 +00003321 }
Bram Moolenaar81695252004-12-29 20:58:21 +00003322
3323 if (using_dummy)
3324 {
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003325 if (found_match && first_match_buf == NULL)
3326 first_match_buf = buf;
Bram Moolenaar81695252004-12-29 20:58:21 +00003327 if (duplicate_name)
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003328 {
Bram Moolenaar81695252004-12-29 20:58:21 +00003329 /* Never keep a dummy buffer if there is another buffer
3330 * with the same name. */
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003331 wipe_dummy_buffer(buf, dirname_start);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003332 buf = NULL;
3333 }
Bram Moolenaara3227e22006-03-08 21:32:40 +00003334 else if (!cmdmod.hide
3335 || buf->b_p_bh[0] == 'u' /* "unload" */
3336 || buf->b_p_bh[0] == 'w' /* "wipe" */
3337 || buf->b_p_bh[0] == 'd') /* "delete" */
Bram Moolenaar81695252004-12-29 20:58:21 +00003338 {
Bram Moolenaara3227e22006-03-08 21:32:40 +00003339 /* When no match was found we don't need to remember the
3340 * buffer, wipe it out. If there was a match and it
3341 * wasn't the first one or we won't jump there: only
3342 * unload the buffer.
3343 * Ignore 'hidden' here, because it may lead to having too
3344 * many swap files. */
Bram Moolenaar81695252004-12-29 20:58:21 +00003345 if (!found_match)
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003346 {
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003347 wipe_dummy_buffer(buf, dirname_start);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003348 buf = NULL;
3349 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003350 else if (buf != first_match_buf || (flags & VGR_NOJUMP))
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003351 {
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003352 unload_dummy_buffer(buf, dirname_start);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003353 buf = NULL;
3354 }
Bram Moolenaar81695252004-12-29 20:58:21 +00003355 }
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003356
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003357 if (buf != NULL)
3358 {
Bram Moolenaard089d9b2007-09-30 12:02:55 +00003359 /* If the buffer is still loaded we need to use the
3360 * directory we jumped to below. */
3361 if (buf == first_match_buf
3362 && target_dir == NULL
3363 && STRCMP(dirname_start, dirname_now) != 0)
3364 target_dir = vim_strsave(dirname_now);
3365
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003366 /* The buffer is still loaded, the Filetype autocommands
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003367 * need to be done now, in that buffer. And the modelines
Bram Moolenaara3227e22006-03-08 21:32:40 +00003368 * need to be done (again). But not the window-local
3369 * options! */
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003370 aucmd_prepbuf(&aco, buf);
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003371#if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003372 apply_autocmds(EVENT_FILETYPE, buf->b_p_ft,
3373 buf->b_fname, TRUE, buf);
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00003374#endif
Bram Moolenaara3227e22006-03-08 21:32:40 +00003375 do_modelines(OPT_NOWIN);
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003376 aucmd_restbuf(&aco);
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003377 }
Bram Moolenaar81695252004-12-29 20:58:21 +00003378 }
Bram Moolenaar86b68352004-12-27 21:59:20 +00003379 }
3380 }
3381
3382 FreeWild(fcount, fnames);
3383
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003384 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE;
3385 qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start;
3386 qi->qf_lists[qi->qf_curlist].qf_index = 1;
Bram Moolenaar86b68352004-12-27 21:59:20 +00003387
3388#ifdef FEAT_WINDOWS
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003389 qf_update_buffer(qi);
Bram Moolenaar86b68352004-12-27 21:59:20 +00003390#endif
3391
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00003392#ifdef FEAT_AUTOCMD
3393 if (au_name != NULL)
3394 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
3395 curbuf->b_fname, TRUE, curbuf);
3396#endif
3397
Bram Moolenaar86b68352004-12-27 21:59:20 +00003398 /* Jump to first match. */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003399 if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003400 {
3401 if ((flags & VGR_NOJUMP) == 0)
Bram Moolenaar1042fa32007-09-16 11:27:42 +00003402 {
3403 buf = curbuf;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00003404 qf_jump(qi, 0, 0, eap->forceit);
Bram Moolenaar1042fa32007-09-16 11:27:42 +00003405 if (buf != curbuf)
3406 /* If we jumped to another buffer redrawing will already be
3407 * taken care of. */
3408 redraw_for_dummy = FALSE;
Bram Moolenaard089d9b2007-09-30 12:02:55 +00003409
3410 /* Jump to the directory used after loading the buffer. */
3411 if (curbuf == first_match_buf && target_dir != NULL)
3412 {
3413 exarg_T ea;
3414
3415 ea.arg = target_dir;
3416 ea.cmdidx = CMD_lcd;
3417 ex_cd(&ea);
3418 }
Bram Moolenaar1042fa32007-09-16 11:27:42 +00003419 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003420 }
Bram Moolenaar81695252004-12-29 20:58:21 +00003421 else
3422 EMSG2(_(e_nomatch2), s);
Bram Moolenaar86b68352004-12-27 21:59:20 +00003423
Bram Moolenaar1042fa32007-09-16 11:27:42 +00003424 /* If we loaded a dummy buffer into the current window, the autocommands
3425 * may have messed up things, need to redraw and recompute folds. */
3426 if (redraw_for_dummy)
3427 {
3428#ifdef FEAT_FOLDING
3429 foldUpdateAll(curwin);
3430#else
3431 redraw_later(NOT_VALID);
3432#endif
3433 }
3434
Bram Moolenaar86b68352004-12-27 21:59:20 +00003435theend:
Bram Moolenaard9462e32011-04-11 21:35:11 +02003436 vim_free(dirname_now);
3437 vim_free(dirname_start);
Bram Moolenaard089d9b2007-09-30 12:02:55 +00003438 vim_free(target_dir);
Bram Moolenaar86b68352004-12-27 21:59:20 +00003439 vim_free(regmatch.regprog);
Bram Moolenaar86b68352004-12-27 21:59:20 +00003440}
3441
3442/*
Bram Moolenaar05159a02005-02-26 23:04:13 +00003443 * Skip over the pattern argument of ":vimgrep /pat/[g][j]".
Bram Moolenaar748bf032005-02-02 23:04:36 +00003444 * Put the start of the pattern in "*s", unless "s" is NULL.
Bram Moolenaar05159a02005-02-26 23:04:13 +00003445 * If "flags" is not NULL put the flags in it: VGR_GLOBAL, VGR_NOJUMP.
3446 * If "s" is not NULL terminate the pattern with a NUL.
3447 * Return a pointer to the char just past the pattern plus flags.
Bram Moolenaar748bf032005-02-02 23:04:36 +00003448 */
3449 char_u *
Bram Moolenaar05159a02005-02-26 23:04:13 +00003450skip_vimgrep_pat(p, s, flags)
3451 char_u *p;
3452 char_u **s;
3453 int *flags;
Bram Moolenaar748bf032005-02-02 23:04:36 +00003454{
3455 int c;
3456
3457 if (vim_isIDc(*p))
3458 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003459 /* ":vimgrep pattern fname" */
Bram Moolenaar748bf032005-02-02 23:04:36 +00003460 if (s != NULL)
3461 *s = p;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003462 p = skiptowhite(p);
3463 if (s != NULL && *p != NUL)
3464 *p++ = NUL;
Bram Moolenaar748bf032005-02-02 23:04:36 +00003465 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003466 else
3467 {
3468 /* ":vimgrep /pattern/[g][j] fname" */
3469 if (s != NULL)
3470 *s = p + 1;
3471 c = *p;
3472 p = skip_regexp(p + 1, c, TRUE, NULL);
3473 if (*p != c)
3474 return NULL;
3475
3476 /* Truncate the pattern. */
3477 if (s != NULL)
3478 *p = NUL;
3479 ++p;
3480
3481 /* Find the flags */
3482 while (*p == 'g' || *p == 'j')
3483 {
3484 if (flags != NULL)
3485 {
3486 if (*p == 'g')
3487 *flags |= VGR_GLOBAL;
3488 else
3489 *flags |= VGR_NOJUMP;
3490 }
3491 ++p;
3492 }
3493 }
Bram Moolenaar748bf032005-02-02 23:04:36 +00003494 return p;
3495}
3496
3497/*
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003498 * Restore current working directory to "dirname_start" if they differ, taking
3499 * into account whether it is set locally or globally.
3500 */
3501 static void
3502restore_start_dir(dirname_start)
3503 char_u *dirname_start;
3504{
3505 char_u *dirname_now = alloc(MAXPATHL);
3506
3507 if (NULL != dirname_now)
3508 {
3509 mch_dirname(dirname_now, MAXPATHL);
3510 if (STRCMP(dirname_start, dirname_now) != 0)
3511 {
3512 /* If the directory has changed, change it back by building up an
3513 * appropriate ex command and executing it. */
3514 exarg_T ea;
3515
3516 ea.arg = dirname_start;
3517 ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd;
3518 ex_cd(&ea);
3519 }
3520 }
3521}
3522
3523/*
3524 * Load file "fname" into a dummy buffer and return the buffer pointer,
3525 * placing the directory resulting from the buffer load into the
3526 * "resulting_dir" pointer. "resulting_dir" must be allocated by the caller
3527 * prior to calling this function. Restores directory to "dirname_start" prior
3528 * to returning, if autocmds or the 'autochdir' option have changed it.
3529 *
3530 * If creating the dummy buffer does not fail, must call unload_dummy_buffer()
3531 * or wipe_dummy_buffer() later!
3532 *
Bram Moolenaar81695252004-12-29 20:58:21 +00003533 * Returns NULL if it fails.
Bram Moolenaar81695252004-12-29 20:58:21 +00003534 */
3535 static buf_T *
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003536load_dummy_buffer(fname, dirname_start, resulting_dir)
Bram Moolenaar81695252004-12-29 20:58:21 +00003537 char_u *fname;
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003538 char_u *dirname_start; /* in: old directory */
3539 char_u *resulting_dir; /* out: new directory */
Bram Moolenaar81695252004-12-29 20:58:21 +00003540{
3541 buf_T *newbuf;
Bram Moolenaar0785ccf2010-11-24 16:32:05 +01003542 buf_T *newbuf_to_wipe = NULL;
Bram Moolenaar81695252004-12-29 20:58:21 +00003543 int failed = TRUE;
Bram Moolenaar81695252004-12-29 20:58:21 +00003544 aco_save_T aco;
Bram Moolenaar81695252004-12-29 20:58:21 +00003545
3546 /* Allocate a buffer without putting it in the buffer list. */
3547 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
3548 if (newbuf == NULL)
3549 return NULL;
3550
Bram Moolenaar8cd06ca2005-02-28 22:44:58 +00003551 /* Init the options. */
3552 buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP);
3553
Bram Moolenaarf061e0b2009-06-24 15:32:01 +00003554 /* need to open the memfile before putting the buffer in a window */
3555 if (ml_open(newbuf) == OK)
Bram Moolenaar81695252004-12-29 20:58:21 +00003556 {
Bram Moolenaarf061e0b2009-06-24 15:32:01 +00003557 /* set curwin/curbuf to buf and save a few things */
3558 aucmd_prepbuf(&aco, newbuf);
3559
3560 /* Need to set the filename for autocommands. */
3561 (void)setfname(curbuf, fname, NULL, FALSE);
3562
Bram Moolenaar81695252004-12-29 20:58:21 +00003563 /* Create swap file now to avoid the ATTENTION message. */
3564 check_need_swap(TRUE);
3565
3566 /* Remove the "dummy" flag, otherwise autocommands may not
3567 * work. */
3568 curbuf->b_flags &= ~BF_DUMMY;
3569
3570 if (readfile(fname, NULL,
3571 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM,
3572 NULL, READ_NEW | READ_DUMMY) == OK
Bram Moolenaard68071d2006-05-02 22:08:30 +00003573 && !got_int
Bram Moolenaar81695252004-12-29 20:58:21 +00003574 && !(curbuf->b_flags & BF_NEW))
3575 {
3576 failed = FALSE;
3577 if (curbuf != newbuf)
3578 {
Bram Moolenaar0785ccf2010-11-24 16:32:05 +01003579 /* Bloody autocommands changed the buffer! Can happen when
3580 * using netrw and editing a remote file. Use the current
3581 * buffer instead, delete the dummy one after restoring the
3582 * window stuff. */
3583 newbuf_to_wipe = newbuf;
Bram Moolenaar81695252004-12-29 20:58:21 +00003584 newbuf = curbuf;
3585 }
3586 }
Bram Moolenaar81695252004-12-29 20:58:21 +00003587
Bram Moolenaarf061e0b2009-06-24 15:32:01 +00003588 /* restore curwin/curbuf and a few other things */
3589 aucmd_restbuf(&aco);
Bram Moolenaar0785ccf2010-11-24 16:32:05 +01003590 if (newbuf_to_wipe != NULL && buf_valid(newbuf_to_wipe))
3591 wipe_buffer(newbuf_to_wipe, FALSE);
Bram Moolenaarf061e0b2009-06-24 15:32:01 +00003592 }
Bram Moolenaar81695252004-12-29 20:58:21 +00003593
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003594 /*
3595 * When autocommands/'autochdir' option changed directory: go back.
3596 * Let the caller know what the resulting dir was first, in case it is
3597 * important.
3598 */
3599 mch_dirname(resulting_dir, MAXPATHL);
3600 restore_start_dir(dirname_start);
3601
Bram Moolenaar81695252004-12-29 20:58:21 +00003602 if (!buf_valid(newbuf))
3603 return NULL;
3604 if (failed)
3605 {
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003606 wipe_dummy_buffer(newbuf, dirname_start);
Bram Moolenaar81695252004-12-29 20:58:21 +00003607 return NULL;
3608 }
3609 return newbuf;
3610}
3611
3612/*
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003613 * Wipe out the dummy buffer that load_dummy_buffer() created. Restores
3614 * directory to "dirname_start" prior to returning, if autocmds or the
3615 * 'autochdir' option have changed it.
Bram Moolenaar81695252004-12-29 20:58:21 +00003616 */
3617 static void
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003618wipe_dummy_buffer(buf, dirname_start)
Bram Moolenaar81695252004-12-29 20:58:21 +00003619 buf_T *buf;
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003620 char_u *dirname_start;
Bram Moolenaar81695252004-12-29 20:58:21 +00003621{
3622 if (curbuf != buf) /* safety check */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003623 {
3624#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
3625 cleanup_T cs;
3626
3627 /* Reset the error/interrupt/exception state here so that aborting()
3628 * returns FALSE when wiping out the buffer. Otherwise it doesn't
3629 * work when got_int is set. */
3630 enter_cleanup(&cs);
3631#endif
3632
Bram Moolenaar81695252004-12-29 20:58:21 +00003633 wipe_buffer(buf, FALSE);
Bram Moolenaard68071d2006-05-02 22:08:30 +00003634
3635#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
3636 /* Restore the error/interrupt/exception state if not discarded by a
3637 * new aborting error, interrupt, or uncaught exception. */
3638 leave_cleanup(&cs);
3639#endif
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003640 /* When autocommands/'autochdir' option changed directory: go back. */
3641 restore_start_dir(dirname_start);
Bram Moolenaard68071d2006-05-02 22:08:30 +00003642 }
Bram Moolenaar81695252004-12-29 20:58:21 +00003643}
3644
3645/*
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003646 * Unload the dummy buffer that load_dummy_buffer() created. Restores
3647 * directory to "dirname_start" prior to returning, if autocmds or the
3648 * 'autochdir' option have changed it.
Bram Moolenaar81695252004-12-29 20:58:21 +00003649 */
3650 static void
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003651unload_dummy_buffer(buf, dirname_start)
Bram Moolenaar81695252004-12-29 20:58:21 +00003652 buf_T *buf;
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003653 char_u *dirname_start;
Bram Moolenaar81695252004-12-29 20:58:21 +00003654{
3655 if (curbuf != buf) /* safety check */
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003656 {
Bram Moolenaar42ec6562012-02-22 14:58:37 +01003657 close_buffer(NULL, buf, DOBUF_UNLOAD, FALSE);
Bram Moolenaar7f51a822012-04-25 18:57:21 +02003658
3659 /* When autocommands/'autochdir' option changed directory: go back. */
3660 restore_start_dir(dirname_start);
3661 }
Bram Moolenaar81695252004-12-29 20:58:21 +00003662}
3663
Bram Moolenaar05159a02005-02-26 23:04:13 +00003664#if defined(FEAT_EVAL) || defined(PROTO)
3665/*
3666 * Add each quickfix error to list "list" as a dictionary.
3667 */
3668 int
Bram Moolenaar17c7c012006-01-26 22:25:15 +00003669get_errorlist(wp, list)
3670 win_T *wp;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003671 list_T *list;
3672{
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003673 qf_info_T *qi = &ql_info;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003674 dict_T *dict;
3675 char_u buf[2];
3676 qfline_T *qfp;
3677 int i;
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00003678 int bufnum;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003679
Bram Moolenaar17c7c012006-01-26 22:25:15 +00003680 if (wp != NULL)
3681 {
3682 qi = GET_LOC_LIST(wp);
3683 if (qi == NULL)
3684 return FAIL;
3685 }
3686
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003687 if (qi->qf_curlist >= qi->qf_listcount
Bram Moolenaar87b5ca52006-03-04 21:55:31 +00003688 || qi->qf_lists[qi->qf_curlist].qf_count == 0)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003689 return FAIL;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003690
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003691 qfp = qi->qf_lists[qi->qf_curlist].qf_start;
3692 for (i = 1; !got_int && i <= qi->qf_lists[qi->qf_curlist].qf_count; ++i)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003693 {
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00003694 /* Handle entries with a non-existing buffer number. */
3695 bufnum = qfp->qf_fnum;
3696 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL))
3697 bufnum = 0;
3698
Bram Moolenaar05159a02005-02-26 23:04:13 +00003699 if ((dict = dict_alloc()) == NULL)
3700 return FAIL;
3701 if (list_append_dict(list, dict) == FAIL)
3702 return FAIL;
3703
3704 buf[0] = qfp->qf_type;
3705 buf[1] = NUL;
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00003706 if ( dict_add_nr_str(dict, "bufnr", (long)bufnum, NULL) == FAIL
Bram Moolenaar05159a02005-02-26 23:04:13 +00003707 || dict_add_nr_str(dict, "lnum", (long)qfp->qf_lnum, NULL) == FAIL
3708 || dict_add_nr_str(dict, "col", (long)qfp->qf_col, NULL) == FAIL
3709 || dict_add_nr_str(dict, "vcol", (long)qfp->qf_viscol, NULL) == FAIL
3710 || dict_add_nr_str(dict, "nr", (long)qfp->qf_nr, NULL) == FAIL
Bram Moolenaar53ed1922006-09-05 13:37:47 +00003711 || dict_add_nr_str(dict, "pattern", 0L,
3712 qfp->qf_pattern == NULL ? (char_u *)"" : qfp->qf_pattern) == FAIL
3713 || dict_add_nr_str(dict, "text", 0L,
3714 qfp->qf_text == NULL ? (char_u *)"" : qfp->qf_text) == FAIL
Bram Moolenaar05159a02005-02-26 23:04:13 +00003715 || dict_add_nr_str(dict, "type", 0L, buf) == FAIL
3716 || dict_add_nr_str(dict, "valid", (long)qfp->qf_valid, NULL) == FAIL)
3717 return FAIL;
3718
3719 qfp = qfp->qf_next;
3720 }
3721 return OK;
3722}
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003723
3724/*
3725 * Populate the quickfix list with the items supplied in the list
Bram Moolenaarbc226b62010-08-09 22:14:48 +02003726 * of dictionaries. "title" will be copied to w:quickfix_title
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003727 */
3728 int
Bram Moolenaarbc226b62010-08-09 22:14:48 +02003729set_errorlist(wp, list, action, title)
Bram Moolenaar17c7c012006-01-26 22:25:15 +00003730 win_T *wp;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003731 list_T *list;
Bram Moolenaar35c54e52005-05-20 21:25:31 +00003732 int action;
Bram Moolenaarbc226b62010-08-09 22:14:48 +02003733 char_u *title;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003734{
3735 listitem_T *li;
3736 dict_T *d;
3737 char_u *filename, *pattern, *text, *type;
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00003738 int bufnum;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003739 long lnum;
3740 int col, nr;
3741 int vcol;
3742 qfline_T *prevp = NULL;
3743 int valid, status;
3744 int retval = OK;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003745 qf_info_T *qi = &ql_info;
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00003746 int did_bufnr_emsg = FALSE;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003747
Bram Moolenaar17c7c012006-01-26 22:25:15 +00003748 if (wp != NULL)
3749 {
Bram Moolenaar280f1262006-01-30 00:14:18 +00003750 qi = ll_get_or_alloc_list(wp);
Bram Moolenaar17c7c012006-01-26 22:25:15 +00003751 if (qi == NULL)
3752 return FAIL;
3753 }
3754
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003755 if (action == ' ' || qi->qf_curlist == qi->qf_listcount)
Bram Moolenaar35c54e52005-05-20 21:25:31 +00003756 /* make place for a new list */
Bram Moolenaar41b884b2012-11-14 22:38:08 +01003757 qf_new_list(qi, title, wp);
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003758 else if (action == 'a' && qi->qf_lists[qi->qf_curlist].qf_count > 0)
Bram Moolenaar35c54e52005-05-20 21:25:31 +00003759 /* Adding to existing list, find last entry. */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003760 for (prevp = qi->qf_lists[qi->qf_curlist].qf_start;
Bram Moolenaar35c54e52005-05-20 21:25:31 +00003761 prevp->qf_next != prevp; prevp = prevp->qf_next)
3762 ;
3763 else if (action == 'r')
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003764 qf_free(qi, qi->qf_curlist);
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003765
3766 for (li = list->lv_first; li != NULL; li = li->li_next)
3767 {
3768 if (li->li_tv.v_type != VAR_DICT)
3769 continue; /* Skip non-dict items */
3770
3771 d = li->li_tv.vval.v_dict;
3772 if (d == NULL)
3773 continue;
3774
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00003775 filename = get_dict_string(d, (char_u *)"filename", TRUE);
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00003776 bufnum = get_dict_number(d, (char_u *)"bufnr");
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003777 lnum = get_dict_number(d, (char_u *)"lnum");
3778 col = get_dict_number(d, (char_u *)"col");
3779 vcol = get_dict_number(d, (char_u *)"vcol");
3780 nr = get_dict_number(d, (char_u *)"nr");
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00003781 type = get_dict_string(d, (char_u *)"type", TRUE);
3782 pattern = get_dict_string(d, (char_u *)"pattern", TRUE);
3783 text = get_dict_string(d, (char_u *)"text", TRUE);
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003784 if (text == NULL)
3785 text = vim_strsave((char_u *)"");
3786
3787 valid = TRUE;
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00003788 if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL))
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003789 valid = FALSE;
3790
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00003791 /* Mark entries with non-existing buffer number as not valid. Give the
3792 * error message only once. */
3793 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL))
3794 {
3795 if (!did_bufnr_emsg)
3796 {
3797 did_bufnr_emsg = TRUE;
3798 EMSGN(_("E92: Buffer %ld not found"), bufnum);
3799 }
3800 valid = FALSE;
3801 bufnum = 0;
3802 }
3803
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003804 status = qf_add_entry(qi, &prevp,
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003805 NULL, /* dir */
3806 filename,
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00003807 bufnum,
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003808 text,
3809 lnum,
3810 col,
3811 vcol, /* vis_col */
3812 pattern, /* search pattern */
3813 nr,
3814 type == NULL ? NUL : *type,
3815 valid);
3816
3817 vim_free(filename);
3818 vim_free(pattern);
3819 vim_free(text);
3820 vim_free(type);
3821
3822 if (status == FAIL)
3823 {
3824 retval = FAIL;
3825 break;
3826 }
3827 }
3828
Bram Moolenaarf9ddb942010-05-14 18:10:27 +02003829 if (qi->qf_lists[qi->qf_curlist].qf_index == 0)
Bram Moolenaard236ac02011-05-05 17:14:14 +02003830 /* no valid entry */
Bram Moolenaarf9ddb942010-05-14 18:10:27 +02003831 qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE;
3832 else
3833 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003834 qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start;
3835 qi->qf_lists[qi->qf_curlist].qf_index = 1;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003836
3837#ifdef FEAT_WINDOWS
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003838 qf_update_buffer(qi);
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003839#endif
3840
3841 return retval;
3842}
Bram Moolenaar05159a02005-02-26 23:04:13 +00003843#endif
3844
Bram Moolenaar81695252004-12-29 20:58:21 +00003845/*
Bram Moolenaar86b68352004-12-27 21:59:20 +00003846 * ":[range]cbuffer [bufnr]" command.
Bram Moolenaara6557602006-02-04 22:43:20 +00003847 * ":[range]caddbuffer [bufnr]" command.
Bram Moolenaardb552d602006-03-23 22:59:57 +00003848 * ":[range]cgetbuffer [bufnr]" command.
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003849 * ":[range]lbuffer [bufnr]" command.
Bram Moolenaara6557602006-02-04 22:43:20 +00003850 * ":[range]laddbuffer [bufnr]" command.
Bram Moolenaardb552d602006-03-23 22:59:57 +00003851 * ":[range]lgetbuffer [bufnr]" command.
Bram Moolenaar86b68352004-12-27 21:59:20 +00003852 */
3853 void
3854ex_cbuffer(eap)
3855 exarg_T *eap;
3856{
3857 buf_T *buf = NULL;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003858 qf_info_T *qi = &ql_info;
3859
Bram Moolenaardb552d602006-03-23 22:59:57 +00003860 if (eap->cmdidx == CMD_lbuffer || eap->cmdidx == CMD_lgetbuffer
3861 || eap->cmdidx == CMD_laddbuffer)
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003862 {
3863 qi = ll_get_or_alloc_list(curwin);
3864 if (qi == NULL)
3865 return;
3866 }
Bram Moolenaar86b68352004-12-27 21:59:20 +00003867
3868 if (*eap->arg == NUL)
3869 buf = curbuf;
3870 else if (*skipwhite(skipdigits(eap->arg)) == NUL)
3871 buf = buflist_findnr(atoi((char *)eap->arg));
3872 if (buf == NULL)
3873 EMSG(_(e_invarg));
3874 else if (buf->b_ml.ml_mfp == NULL)
3875 EMSG(_("E681: Buffer is not loaded"));
3876 else
3877 {
3878 if (eap->addr_count == 0)
3879 {
3880 eap->line1 = 1;
3881 eap->line2 = buf->b_ml.ml_line_count;
3882 }
3883 if (eap->line1 < 1 || eap->line1 > buf->b_ml.ml_line_count
3884 || eap->line2 < 1 || eap->line2 > buf->b_ml.ml_line_count)
3885 EMSG(_(e_invrange));
3886 else
Bram Moolenaar754b5602006-02-09 23:53:20 +00003887 {
Bram Moolenaar7fd73202010-07-25 16:58:46 +02003888 char_u *qf_title = *eap->cmdlinep;
3889
3890 if (buf->b_sfname)
3891 {
3892 vim_snprintf((char *)IObuff, IOSIZE, "%s (%s)",
3893 (char *)qf_title, (char *)buf->b_sfname);
3894 qf_title = IObuff;
3895 }
3896
Bram Moolenaardb552d602006-03-23 22:59:57 +00003897 if (qf_init_ext(qi, NULL, buf, NULL, p_efm,
3898 (eap->cmdidx != CMD_caddbuffer
3899 && eap->cmdidx != CMD_laddbuffer),
Bram Moolenaar7fd73202010-07-25 16:58:46 +02003900 eap->line1, eap->line2,
3901 qf_title) > 0
Bram Moolenaardb552d602006-03-23 22:59:57 +00003902 && (eap->cmdidx == CMD_cbuffer
3903 || eap->cmdidx == CMD_lbuffer))
Bram Moolenaar754b5602006-02-09 23:53:20 +00003904 qf_jump(qi, 0, 0, eap->forceit); /* display first error */
3905 }
Bram Moolenaar86b68352004-12-27 21:59:20 +00003906 }
3907}
3908
Bram Moolenaar1e015462005-09-25 22:16:38 +00003909#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaar86b68352004-12-27 21:59:20 +00003910/*
Bram Moolenaardb552d602006-03-23 22:59:57 +00003911 * ":cexpr {expr}", ":cgetexpr {expr}", ":caddexpr {expr}" command.
3912 * ":lexpr {expr}", ":lgetexpr {expr}", ":laddexpr {expr}" command.
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00003913 */
3914 void
3915ex_cexpr(eap)
3916 exarg_T *eap;
3917{
3918 typval_T *tv;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003919 qf_info_T *qi = &ql_info;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003920
Bram Moolenaardb552d602006-03-23 22:59:57 +00003921 if (eap->cmdidx == CMD_lexpr || eap->cmdidx == CMD_lgetexpr
3922 || eap->cmdidx == CMD_laddexpr)
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003923 {
3924 qi = ll_get_or_alloc_list(curwin);
3925 if (qi == NULL)
3926 return;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003927 }
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00003928
Bram Moolenaar4770d092006-01-12 23:22:24 +00003929 /* Evaluate the expression. When the result is a string or a list we can
3930 * use it to fill the errorlist. */
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00003931 tv = eval_expr(eap->arg, NULL);
Bram Moolenaar4770d092006-01-12 23:22:24 +00003932 if (tv != NULL)
3933 {
3934 if ((tv->v_type == VAR_STRING && tv->vval.v_string != NULL)
3935 || (tv->v_type == VAR_LIST && tv->vval.v_list != NULL))
3936 {
Bram Moolenaardb552d602006-03-23 22:59:57 +00003937 if (qf_init_ext(qi, NULL, NULL, tv, p_efm,
3938 (eap->cmdidx != CMD_caddexpr
3939 && eap->cmdidx != CMD_laddexpr),
Bram Moolenaar7fd73202010-07-25 16:58:46 +02003940 (linenr_T)0, (linenr_T)0, *eap->cmdlinep) > 0
Bram Moolenaardb552d602006-03-23 22:59:57 +00003941 && (eap->cmdidx == CMD_cexpr
3942 || eap->cmdidx == CMD_lexpr))
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00003943 qf_jump(qi, 0, 0, eap->forceit); /* display first error */
Bram Moolenaar4770d092006-01-12 23:22:24 +00003944 }
3945 else
Bram Moolenaara40ceaf2006-01-13 22:35:40 +00003946 EMSG(_("E777: String or List expected"));
Bram Moolenaar4770d092006-01-12 23:22:24 +00003947 free_tv(tv);
3948 }
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00003949}
Bram Moolenaar1e015462005-09-25 22:16:38 +00003950#endif
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00003951
3952/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003953 * ":helpgrep {pattern}"
3954 */
3955 void
3956ex_helpgrep(eap)
3957 exarg_T *eap;
3958{
3959 regmatch_T regmatch;
3960 char_u *save_cpo;
3961 char_u *p;
3962 int fcount;
3963 char_u **fnames;
3964 FILE *fd;
3965 int fi;
Bram Moolenaar68b76a62005-03-25 21:53:48 +00003966 qfline_T *prevp = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003967 long lnum;
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003968#ifdef FEAT_MULTI_LANG
3969 char_u *lang;
3970#endif
Bram Moolenaard12f5c12006-01-25 22:10:52 +00003971 qf_info_T *qi = &ql_info;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00003972 int new_qi = FALSE;
3973 win_T *wp;
Bram Moolenaar73633f82012-01-20 13:39:07 +01003974#ifdef FEAT_AUTOCMD
3975 char_u *au_name = NULL;
3976#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003978#ifdef FEAT_MULTI_LANG
3979 /* Check for a specified language */
3980 lang = check_help_lang(eap->arg);
3981#endif
3982
Bram Moolenaar73633f82012-01-20 13:39:07 +01003983#ifdef FEAT_AUTOCMD
3984 switch (eap->cmdidx)
3985 {
3986 case CMD_helpgrep: au_name = (char_u *)"helpgrep"; break;
3987 case CMD_lhelpgrep: au_name = (char_u *)"lhelpgrep"; break;
3988 default: break;
3989 }
3990 if (au_name != NULL)
3991 {
3992 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name,
3993 curbuf->b_fname, TRUE, curbuf);
3994 if (did_throw || force_abort)
3995 return;
3996 }
3997#endif
3998
3999 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */
4000 save_cpo = p_cpo;
4001 p_cpo = empty_option;
4002
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00004003 if (eap->cmdidx == CMD_lhelpgrep)
4004 {
4005 /* Find an existing help window */
4006 FOR_ALL_WINDOWS(wp)
4007 if (wp->w_buffer != NULL && wp->w_buffer->b_help)
4008 break;
4009
4010 if (wp == NULL) /* Help window not found */
4011 qi = NULL;
4012 else
4013 qi = wp->w_llist;
4014
4015 if (qi == NULL)
4016 {
4017 /* Allocate a new location list for help text matches */
4018 if ((qi = ll_new_list()) == NULL)
4019 return;
4020 new_qi = TRUE;
4021 }
4022 }
4023
Bram Moolenaar071d4272004-06-13 20:20:40 +00004024 regmatch.regprog = vim_regcomp(eap->arg, RE_MAGIC + RE_STRING);
4025 regmatch.rm_ic = FALSE;
4026 if (regmatch.regprog != NULL)
4027 {
Bram Moolenaar10b7b392012-01-10 16:28:45 +01004028#ifdef FEAT_MBYTE
4029 vimconv_T vc;
4030
4031 /* Help files are in utf-8 or latin1, convert lines when 'encoding'
4032 * differs. */
4033 vc.vc_type = CONV_NONE;
4034 if (!enc_utf8)
4035 convert_setup(&vc, (char_u *)"utf-8", p_enc);
4036#endif
4037
Bram Moolenaar071d4272004-06-13 20:20:40 +00004038 /* create a new quickfix list */
Bram Moolenaar41b884b2012-11-14 22:38:08 +01004039 qf_new_list(qi, *eap->cmdlinep, wp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040
4041 /* Go through all directories in 'runtimepath' */
4042 p = p_rtp;
4043 while (*p != NUL && !got_int)
4044 {
4045 copy_option_part(&p, NameBuff, MAXPATHL, ",");
4046
4047 /* Find all "*.txt" and "*.??x" files in the "doc" directory. */
4048 add_pathsep(NameBuff);
4049 STRCAT(NameBuff, "doc/*.\\(txt\\|??x\\)");
4050 if (gen_expand_wildcards(1, &NameBuff, &fcount,
4051 &fnames, EW_FILE|EW_SILENT) == OK
4052 && fcount > 0)
4053 {
4054 for (fi = 0; fi < fcount && !got_int; ++fi)
4055 {
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004056#ifdef FEAT_MULTI_LANG
4057 /* Skip files for a different language. */
4058 if (lang != NULL
4059 && STRNICMP(lang, fnames[fi]
4060 + STRLEN(fnames[fi]) - 3, 2) != 0
4061 && !(STRNICMP(lang, "en", 2) == 0
4062 && STRNICMP("txt", fnames[fi]
4063 + STRLEN(fnames[fi]) - 3, 3) == 0))
4064 continue;
4065#endif
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00004066 fd = mch_fopen((char *)fnames[fi], "r");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 if (fd != NULL)
4068 {
4069 lnum = 1;
4070 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int)
4071 {
Bram Moolenaar10b7b392012-01-10 16:28:45 +01004072 char_u *line = IObuff;
4073#ifdef FEAT_MBYTE
4074 /* Convert a line if 'encoding' is not utf-8 and
4075 * the line contains a non-ASCII character. */
4076 if (vc.vc_type != CONV_NONE
4077 && has_non_ascii(IObuff)) {
4078 line = string_convert(&vc, IObuff, NULL);
4079 if (line == NULL)
4080 line = IObuff;
4081 }
4082#endif
4083
4084 if (vim_regexec(&regmatch, line, (colnr_T)0))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 {
Bram Moolenaar10b7b392012-01-10 16:28:45 +01004086 int l = (int)STRLEN(line);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087
4088 /* remove trailing CR, LF, spaces, etc. */
Bram Moolenaar10b7b392012-01-10 16:28:45 +01004089 while (l > 0 && line[l - 1] <= ' ')
4090 line[--l] = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091
Bram Moolenaard12f5c12006-01-25 22:10:52 +00004092 if (qf_add_entry(qi, &prevp,
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 NULL, /* dir */
4094 fnames[fi],
Bram Moolenaar48b66fb2007-02-04 01:58:18 +00004095 0,
Bram Moolenaar10b7b392012-01-10 16:28:45 +01004096 line,
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 lnum,
Bram Moolenaar10b7b392012-01-10 16:28:45 +01004098 (int)(regmatch.startp[0] - line)
Bram Moolenaar81695252004-12-29 20:58:21 +00004099 + 1, /* col */
Bram Moolenaar05159a02005-02-26 23:04:13 +00004100 FALSE, /* vis_col */
Bram Moolenaar68b76a62005-03-25 21:53:48 +00004101 NULL, /* search pattern */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 0, /* nr */
4103 1, /* type */
4104 TRUE /* valid */
4105 ) == FAIL)
4106 {
4107 got_int = TRUE;
Bram Moolenaar10b7b392012-01-10 16:28:45 +01004108#ifdef FEAT_MBYTE
4109 if (line != IObuff)
4110 vim_free(line);
4111#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 break;
4113 }
4114 }
Bram Moolenaar10b7b392012-01-10 16:28:45 +01004115#ifdef FEAT_MBYTE
4116 if (line != IObuff)
4117 vim_free(line);
4118#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004119 ++lnum;
4120 line_breakcheck();
4121 }
4122 fclose(fd);
4123 }
4124 }
4125 FreeWild(fcount, fnames);
4126 }
4127 }
Bram Moolenaar10b7b392012-01-10 16:28:45 +01004128
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 vim_free(regmatch.regprog);
Bram Moolenaar10b7b392012-01-10 16:28:45 +01004130#ifdef FEAT_MBYTE
4131 if (vc.vc_type != CONV_NONE)
4132 convert_setup(&vc, NULL, NULL);
4133#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134
Bram Moolenaard12f5c12006-01-25 22:10:52 +00004135 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE;
4136 qi->qf_lists[qi->qf_curlist].qf_ptr =
4137 qi->qf_lists[qi->qf_curlist].qf_start;
4138 qi->qf_lists[qi->qf_curlist].qf_index = 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 }
4140
Bram Moolenaar9c24ccc2008-07-14 21:05:15 +00004141 if (p_cpo == empty_option)
4142 p_cpo = save_cpo;
4143 else
4144 /* Darn, some plugin changed the value. */
4145 free_string_option(save_cpo);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146
4147#ifdef FEAT_WINDOWS
Bram Moolenaard12f5c12006-01-25 22:10:52 +00004148 qf_update_buffer(qi);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004149#endif
4150
Bram Moolenaar73633f82012-01-20 13:39:07 +01004151#ifdef FEAT_AUTOCMD
4152 if (au_name != NULL)
4153 {
4154 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
4155 curbuf->b_fname, TRUE, curbuf);
4156 if (!new_qi && qi != &ql_info && qf_find_buf(qi) == NULL)
4157 /* autocommands made "qi" invalid */
4158 return;
4159 }
4160#endif
4161
Bram Moolenaar071d4272004-06-13 20:20:40 +00004162 /* Jump to first match. */
Bram Moolenaard12f5c12006-01-25 22:10:52 +00004163 if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00004164 qf_jump(qi, 0, 0, FALSE);
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004165 else
4166 EMSG2(_(e_nomatch2), eap->arg);
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00004167
4168 if (eap->cmdidx == CMD_lhelpgrep)
4169 {
4170 /* If the help window is not opened or if it already points to the
Bram Moolenaar754b5602006-02-09 23:53:20 +00004171 * correct location list, then free the new location list. */
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00004172 if (!curwin->w_buffer->b_help || curwin->w_llist == qi)
4173 {
4174 if (new_qi)
4175 ll_free_all(&qi);
4176 }
4177 else if (curwin->w_llist == NULL)
4178 curwin->w_llist = qi;
4179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180}
4181
4182#endif /* FEAT_QUICKFIX */