Mercurial > vim
annotate src/quickfix.c @ 9056:19d2dfb3f5e2 v7.4.1813
commit https://github.com/vim/vim/commit/9b4ebc692d77ca8ef90d72517347f74c2474dd3d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 1 13:28:38 2016 +0200
patch 7.4.1813
Problem: Memory access error when running test_quickfix.
Solution: Allocate one more byte. (Yegappan Lakshmanan)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 01 May 2016 13:30:06 +0200 |
parents | 0536d1469b67 |
children | 616793d0412b |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * quickfix.c: functions for quickfix mode, using a file with error messages | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 #if defined(FEAT_QUICKFIX) || defined(PROTO) | |
17 | |
18 struct dir_stack_T | |
19 { | |
20 struct dir_stack_T *next; | |
21 char_u *dirname; | |
22 }; | |
23 | |
24 static struct dir_stack_T *dir_stack = NULL; | |
25 | |
26 /* | |
230 | 27 * For each error the next struct is allocated and linked in a list. |
7 | 28 */ |
230 | 29 typedef struct qfline_S qfline_T; |
30 struct qfline_S | |
7 | 31 { |
230 | 32 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 | |
7 | 43 :helpgrep */ |
230 | 44 char_u qf_valid; /* valid error message detected */ |
7 | 45 }; |
46 | |
47 /* | |
48 * There is a stack of error lists. | |
49 */ | |
50 #define LISTCOUNT 10 | |
51 | |
644 | 52 typedef struct qf_list_S |
7 | 53 { |
230 | 54 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 */ | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
59 char_u *qf_title; /* title derived from the command that created |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
60 * the error list */ |
644 | 61 } qf_list_T; |
62 | |
63 struct 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 | |
77 static qf_info_T ql_info; /* global quickfix list */ | |
7 | 78 |
230 | 79 #define FMT_PATTERNS 10 /* maximum number of % recognized */ |
7 | 80 |
81 /* | |
82 * Structure used to hold the info of one part of 'errorformat' | |
83 */ | |
789 | 84 typedef struct efm_S efm_T; |
85 struct efm_S | |
7 | 86 { |
87 regprog_T *prog; /* pre-formatted part of 'errorformat' */ | |
789 | 88 efm_T *next; /* pointer to next (NULL if last) */ |
7 | 89 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 */ | |
625 | 105 /* '+' include whole line in message */ |
789 | 106 int conthere; /* %> used */ |
7 | 107 }; |
108 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
109 static int qf_init_ext(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); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
110 static void qf_store_title(qf_info_T *qi, char_u *title); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
111 static void qf_new_list(qf_info_T *qi, char_u *qf_title); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
112 static void ll_free_all(qf_info_T **pqi); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
113 static int qf_add_entry(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); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
114 static qf_info_T *ll_new_list(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
115 static void qf_msg(qf_info_T *qi); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
116 static void qf_free(qf_info_T *qi, int idx); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
117 static char_u *qf_types(int, int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
118 static int qf_get_fnum(char_u *, char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
119 static char_u *qf_push_dir(char_u *, struct dir_stack_T **); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
120 static char_u *qf_pop_dir(struct dir_stack_T **); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
121 static char_u *qf_guess_filepath(char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
122 static void qf_fmt_text(char_u *text, char_u *buf, int bufsize); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
123 static void qf_clean_dir_stack(struct dir_stack_T **); |
7 | 124 #ifdef FEAT_WINDOWS |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
125 static int qf_win_pos_update(qf_info_T *qi, int old_qf_index); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
126 static int is_qf_win(win_T *win, qf_info_T *qi); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
127 static win_T *qf_find_win(qf_info_T *qi); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
128 static buf_T *qf_find_buf(qf_info_T *qi); |
8932
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
129 static void qf_update_buffer(qf_info_T *qi, int update_cursor); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
130 static void qf_set_title_var(qf_info_T *qi); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
131 static void qf_fill_buffer(qf_info_T *qi); |
7 | 132 #endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
133 static char_u *get_mef_name(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
134 static void restore_start_dir(char_u *dirname_start); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
135 static buf_T *load_dummy_buffer(char_u *fname, char_u *dirname_start, char_u *resulting_dir); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
136 static void wipe_dummy_buffer(buf_T *buf, char_u *dirname_start); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
137 static void unload_dummy_buffer(buf_T *buf, char_u *dirname_start); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
138 static qf_info_T *ll_get_or_alloc_list(win_T *); |
7 | 139 |
644 | 140 /* Quickfix window check helper macro */ |
141 #define IS_QF_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref == NULL) | |
142 /* Location list window check helper macro */ | |
143 #define IS_LL_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL) | |
144 /* | |
145 * Return location list for window 'wp' | |
146 * For location list window, return the referenced location list | |
147 */ | |
148 #define GET_LOC_LIST(wp) (IS_LL_WINDOW(wp) ? wp->w_llist_ref : wp->w_llist) | |
149 | |
7 | 150 /* |
41 | 151 * Read the errorfile "efile" into memory, line by line, building the error |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
152 * list. Set the error list's title to qf_title. |
7 | 153 * Return -1 for error, number of errors for success. |
154 */ | |
155 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
156 qf_init( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
157 win_T *wp, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
158 char_u *efile, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
159 char_u *errorformat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
160 int newlist, /* TRUE: start a new error list */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
161 char_u *qf_title) |
7 | 162 { |
644 | 163 qf_info_T *qi = &ql_info; |
164 | |
165 if (wp != NULL) | |
665 | 166 { |
167 qi = ll_get_or_alloc_list(wp); | |
168 if (qi == NULL) | |
169 return FAIL; | |
170 } | |
644 | 171 |
172 return qf_init_ext(qi, efile, curbuf, NULL, errorformat, newlist, | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
173 (linenr_T)0, (linenr_T)0, |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
174 qf_title); |
41 | 175 } |
176 | |
177 /* | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
178 * Maximum number of bytes allowed per line while reading a errorfile. |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
179 */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
180 #define LINE_MAXLEN 4096 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
181 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
182 /* |
41 | 183 * Read the errorfile "efile" into memory, line by line, building the error |
184 * list. | |
185 * Alternative: when "efile" is null read errors from buffer "buf". | |
186 * Always use 'errorformat' from "buf" if there is a local value. | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
187 * Then "lnumfirst" and "lnumlast" specify the range of lines to use. |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
188 * Set the title of the list to "qf_title". |
41 | 189 * Return -1 for error, number of errors for success. |
190 */ | |
191 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
192 qf_init_ext( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
193 qf_info_T *qi, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
194 char_u *efile, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
195 buf_T *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
196 typval_T *tv, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
197 char_u *errorformat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
198 int newlist, /* TRUE: start a new error list */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
199 linenr_T lnumfirst, /* first line number to use */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
200 linenr_T lnumlast, /* last line number to use */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
201 char_u *qf_title) |
41 | 202 { |
7 | 203 char_u *namebuf; |
204 char_u *errmsg; | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
205 int errmsglen; |
230 | 206 char_u *pattern; |
7 | 207 char_u *fmtstr = NULL; |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
208 char_u *growbuf = NULL; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
209 int growbuflen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
210 int growbufsiz; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
211 char_u *linebuf; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
212 int linelen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
213 int discard; |
7 | 214 int col = 0; |
170 | 215 char_u use_viscol = FALSE; |
7 | 216 int type = 0; |
217 int valid; | |
41 | 218 linenr_T buflnum = lnumfirst; |
7 | 219 long lnum = 0L; |
220 int enr = 0; | |
41 | 221 FILE *fd = NULL; |
230 | 222 qfline_T *qfprev = NULL; /* init to make SASC shut up */ |
7 | 223 char_u *efmp; |
789 | 224 efm_T *fmt_first = NULL; |
225 efm_T *fmt_last = NULL; | |
226 efm_T *fmt_ptr; | |
227 efm_T *fmt_start = NULL; | |
7 | 228 char_u *efm; |
229 char_u *ptr; | |
230 char_u *srcptr; | |
231 int len; | |
232 int i; | |
233 int round; | |
234 int idx = 0; | |
235 int multiline = FALSE; | |
236 int multiignore = FALSE; | |
237 int multiscan = FALSE; | |
238 int retval = -1; /* default: return error flag */ | |
239 char_u *directory = NULL; | |
240 char_u *currfile = NULL; | |
241 char_u *tail = NULL; | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
242 char_u *p_buf = NULL; |
446 | 243 char_u *p_str = NULL; |
244 listitem_T *p_li = NULL; | |
7 | 245 struct dir_stack_T *file_stack = NULL; |
246 regmatch_T regmatch; | |
247 static struct fmtpattern | |
248 { | |
249 char_u convchar; | |
250 char *pattern; | |
251 } fmt_pat[FMT_PATTERNS] = | |
252 { | |
502 | 253 {'f', ".\\+"}, /* only used when at end */ |
7 | 254 {'n', "\\d\\+"}, |
255 {'l', "\\d\\+"}, | |
256 {'c', "\\d\\+"}, | |
257 {'t', "."}, | |
258 {'m', ".\\+"}, | |
259 {'r', ".*"}, | |
3555 | 260 {'p', "[- .]*"}, |
230 | 261 {'v', "\\d\\+"}, |
262 {'s', ".\\+"} | |
7 | 263 }; |
264 | |
7558
9a4c9dccd603
commit https://github.com/vim/vim/commit/b86a343280b08d6701da68ee0651e960a0a7a61c
Christian Brabandt <cb@256bit.org>
parents:
7515
diff
changeset
|
265 namebuf = alloc_id(CMDBUFFSIZE + 1, aid_qf_namebuf); |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
266 errmsglen = CMDBUFFSIZE + 1; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
267 errmsg = alloc_id(errmsglen, aid_qf_errmsg); |
7558
9a4c9dccd603
commit https://github.com/vim/vim/commit/b86a343280b08d6701da68ee0651e960a0a7a61c
Christian Brabandt <cb@256bit.org>
parents:
7515
diff
changeset
|
268 pattern = alloc_id(CMDBUFFSIZE + 1, aid_qf_pattern); |
230 | 269 if (namebuf == NULL || errmsg == NULL || pattern == NULL) |
7 | 270 goto qf_init_end; |
271 | |
41 | 272 if (efile != NULL && (fd = mch_fopen((char *)efile, "r")) == NULL) |
7 | 273 { |
274 EMSG2(_(e_openerrf), efile); | |
275 goto qf_init_end; | |
276 } | |
277 | |
644 | 278 if (newlist || qi->qf_curlist == qi->qf_listcount) |
7 | 279 /* make place for a new list */ |
3965 | 280 qf_new_list(qi, qf_title); |
644 | 281 else if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
7 | 282 /* Adding to existing list, find last entry. */ |
644 | 283 for (qfprev = qi->qf_lists[qi->qf_curlist].qf_start; |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
284 qfprev->qf_next != qfprev; qfprev = qfprev->qf_next) |
7 | 285 ; |
286 | |
287 /* | |
288 * Each part of the format string is copied and modified from errorformat to | |
289 * regex prog. Only a few % characters are allowed. | |
290 */ | |
291 /* Use the local value of 'errorformat' if it's set. */ | |
446 | 292 if (errorformat == p_efm && tv == NULL && *buf->b_p_efm != NUL) |
41 | 293 efm = buf->b_p_efm; |
7 | 294 else |
295 efm = errorformat; | |
296 /* | |
297 * Get some space to modify the format string into. | |
298 */ | |
299 i = (FMT_PATTERNS * 3) + ((int)STRLEN(efm) << 2); | |
300 for (round = FMT_PATTERNS; round > 0; ) | |
301 i += (int)STRLEN(fmt_pat[--round].pattern); | |
302 #ifdef COLON_IN_FILENAME | |
303 i += 12; /* "%f" can become twelve chars longer */ | |
304 #else | |
305 i += 2; /* "%f" can become two chars longer */ | |
306 #endif | |
307 if ((fmtstr = alloc(i)) == NULL) | |
308 goto error2; | |
309 | |
789 | 310 while (efm[0] != NUL) |
7 | 311 { |
312 /* | |
313 * Allocate a new eformat structure and put it at the end of the list | |
314 */ | |
789 | 315 fmt_ptr = (efm_T *)alloc_clear((unsigned)sizeof(efm_T)); |
7 | 316 if (fmt_ptr == NULL) |
317 goto error2; | |
318 if (fmt_first == NULL) /* first one */ | |
319 fmt_first = fmt_ptr; | |
320 else | |
321 fmt_last->next = fmt_ptr; | |
322 fmt_last = fmt_ptr; | |
323 | |
324 /* | |
325 * Isolate one part in the 'errorformat' option | |
326 */ | |
327 for (len = 0; efm[len] != NUL && efm[len] != ','; ++len) | |
328 if (efm[len] == '\\' && efm[len + 1] != NUL) | |
329 ++len; | |
330 | |
331 /* | |
332 * Build regexp pattern from current 'errorformat' option | |
333 */ | |
334 ptr = fmtstr; | |
335 *ptr++ = '^'; | |
789 | 336 round = 0; |
7 | 337 for (efmp = efm; efmp < efm + len; ++efmp) |
338 { | |
339 if (*efmp == '%') | |
340 { | |
341 ++efmp; | |
342 for (idx = 0; idx < FMT_PATTERNS; ++idx) | |
343 if (fmt_pat[idx].convchar == *efmp) | |
344 break; | |
345 if (idx < FMT_PATTERNS) | |
346 { | |
347 if (fmt_ptr->addr[idx]) | |
348 { | |
349 sprintf((char *)errmsg, | |
350 _("E372: Too many %%%c in format string"), *efmp); | |
351 EMSG(errmsg); | |
352 goto error2; | |
353 } | |
354 if ((idx | |
355 && idx < 6 | |
356 && vim_strchr((char_u *)"DXOPQ", | |
357 fmt_ptr->prefix) != NULL) | |
358 || (idx == 6 | |
359 && vim_strchr((char_u *)"OPQ", | |
360 fmt_ptr->prefix) == NULL)) | |
361 { | |
362 sprintf((char *)errmsg, | |
363 _("E373: Unexpected %%%c in format string"), *efmp); | |
364 EMSG(errmsg); | |
365 goto error2; | |
366 } | |
367 fmt_ptr->addr[idx] = (char_u)++round; | |
368 *ptr++ = '\\'; | |
369 *ptr++ = '('; | |
370 #ifdef BACKSLASH_IN_FILENAME | |
371 if (*efmp == 'f') | |
372 { | |
373 /* Also match "c:" in the file name, even when | |
374 * checking for a colon next: "%f:". | |
375 * "\%(\a:\)\=" */ | |
376 STRCPY(ptr, "\\%(\\a:\\)\\="); | |
377 ptr += 10; | |
378 } | |
379 #endif | |
502 | 380 if (*efmp == 'f' && efmp[1] != NUL) |
7 | 381 { |
502 | 382 if (efmp[1] != '\\' && efmp[1] != '%') |
383 { | |
384 /* A file name may contain spaces, but this isn't | |
385 * in "\f". For "%f:%l:%m" there may be a ":" in | |
386 * the file name. Use ".\{-1,}x" instead (x is | |
387 * the next character), the requirement that :999: | |
388 * follows should work. */ | |
389 STRCPY(ptr, ".\\{-1,}"); | |
390 ptr += 7; | |
391 } | |
392 else | |
393 { | |
394 /* File name followed by '\\' or '%': include as | |
395 * many file name chars as possible. */ | |
396 STRCPY(ptr, "\\f\\+"); | |
397 ptr += 4; | |
398 } | |
7 | 399 } |
400 else | |
401 { | |
402 srcptr = (char_u *)fmt_pat[idx].pattern; | |
403 while ((*ptr = *srcptr++) != NUL) | |
404 ++ptr; | |
405 } | |
406 *ptr++ = '\\'; | |
407 *ptr++ = ')'; | |
408 } | |
409 else if (*efmp == '*') | |
410 { | |
411 if (*++efmp == '[' || *efmp == '\\') | |
412 { | |
413 if ((*ptr++ = *efmp) == '[') /* %*[^a-z0-9] etc. */ | |
414 { | |
415 if (efmp[1] == '^') | |
416 *ptr++ = *++efmp; | |
417 if (efmp < efm + len) | |
418 { | |
419 *ptr++ = *++efmp; /* could be ']' */ | |
420 while (efmp < efm + len | |
421 && (*ptr++ = *++efmp) != ']') | |
422 /* skip */; | |
423 if (efmp == efm + len) | |
424 { | |
425 EMSG(_("E374: Missing ] in format string")); | |
426 goto error2; | |
427 } | |
428 } | |
429 } | |
430 else if (efmp < efm + len) /* %*\D, %*\s etc. */ | |
431 *ptr++ = *++efmp; | |
432 *ptr++ = '\\'; | |
433 *ptr++ = '+'; | |
434 } | |
435 else | |
436 { | |
437 /* TODO: scanf()-like: %*ud, %*3c, %*f, ... ? */ | |
438 sprintf((char *)errmsg, | |
439 _("E375: Unsupported %%%c in format string"), *efmp); | |
440 EMSG(errmsg); | |
441 goto error2; | |
442 } | |
443 } | |
444 else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL) | |
445 *ptr++ = *efmp; /* regexp magic characters */ | |
446 else if (*efmp == '#') | |
447 *ptr++ = '*'; | |
789 | 448 else if (*efmp == '>') |
449 fmt_ptr->conthere = TRUE; | |
7 | 450 else if (efmp == efm + 1) /* analyse prefix */ |
451 { | |
452 if (vim_strchr((char_u *)"+-", *efmp) != NULL) | |
453 fmt_ptr->flags = *efmp++; | |
454 if (vim_strchr((char_u *)"DXAEWICZGOPQ", *efmp) != NULL) | |
455 fmt_ptr->prefix = *efmp; | |
456 else | |
457 { | |
458 sprintf((char *)errmsg, | |
459 _("E376: Invalid %%%c in format string prefix"), *efmp); | |
460 EMSG(errmsg); | |
461 goto error2; | |
462 } | |
463 } | |
464 else | |
465 { | |
466 sprintf((char *)errmsg, | |
467 _("E377: Invalid %%%c in format string"), *efmp); | |
468 EMSG(errmsg); | |
469 goto error2; | |
470 } | |
471 } | |
472 else /* copy normal character */ | |
473 { | |
474 if (*efmp == '\\' && efmp + 1 < efm + len) | |
475 ++efmp; | |
476 else if (vim_strchr((char_u *)".*^$~[", *efmp) != NULL) | |
477 *ptr++ = '\\'; /* escape regexp atoms */ | |
478 if (*efmp) | |
479 *ptr++ = *efmp; | |
480 } | |
481 } | |
482 *ptr++ = '$'; | |
483 *ptr = NUL; | |
484 if ((fmt_ptr->prog = vim_regcomp(fmtstr, RE_MAGIC + RE_STRING)) == NULL) | |
485 goto error2; | |
486 /* | |
487 * Advance to next part | |
488 */ | |
489 efm = skip_to_option_part(efm + len); /* skip comma and spaces */ | |
490 } | |
491 if (fmt_first == NULL) /* nothing found */ | |
492 { | |
493 EMSG(_("E378: 'errorformat' contains no pattern")); | |
494 goto error2; | |
495 } | |
496 | |
497 /* | |
498 * got_int is reset here, because it was probably set when killing the | |
499 * ":make" command, but we still want to read the errorfile then. | |
500 */ | |
501 got_int = FALSE; | |
502 | |
503 /* Always ignore case when looking for a matching error. */ | |
504 regmatch.rm_ic = TRUE; | |
505 | |
446 | 506 if (tv != NULL) |
507 { | |
508 if (tv->v_type == VAR_STRING) | |
509 p_str = tv->vval.v_string; | |
510 else if (tv->v_type == VAR_LIST) | |
511 p_li = tv->vval.v_list->lv_first; | |
512 } | |
513 | |
7 | 514 /* |
515 * Read the lines in the error file one by one. | |
516 * Try to recognize one of the error formats in each line. | |
517 */ | |
41 | 518 while (!got_int) |
7 | 519 { |
41 | 520 /* Get the next line. */ |
521 if (fd == NULL) | |
522 { | |
446 | 523 if (tv != NULL) |
524 { | |
525 if (tv->v_type == VAR_STRING) | |
526 { | |
527 /* Get the next line from the supplied string */ | |
528 char_u *p; | |
529 | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
530 if (*p_str == NUL) /* Reached the end of the string */ |
446 | 531 break; |
532 | |
533 p = vim_strchr(p_str, '\n'); | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
534 if (p != NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
535 len = (int)(p - p_str) + 1; |
446 | 536 else |
835 | 537 len = (int)STRLEN(p_str); |
446 | 538 |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
539 if (len > IOSIZE - 2) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
540 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
541 /* |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
542 * If the line exceeds LINE_MAXLEN exclude the last |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
543 * byte since it's not a NL character. |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
544 */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
545 linelen = len > LINE_MAXLEN ? LINE_MAXLEN - 1 : len; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
546 if (growbuf == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
547 { |
9056
19d2dfb3f5e2
commit https://github.com/vim/vim/commit/9b4ebc692d77ca8ef90d72517347f74c2474dd3d
Christian Brabandt <cb@256bit.org>
parents:
9033
diff
changeset
|
548 growbuf = alloc(linelen + 1); |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
549 growbufsiz = linelen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
550 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
551 else if (linelen > growbufsiz) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
552 { |
9056
19d2dfb3f5e2
commit https://github.com/vim/vim/commit/9b4ebc692d77ca8ef90d72517347f74c2474dd3d
Christian Brabandt <cb@256bit.org>
parents:
9033
diff
changeset
|
553 growbuf = vim_realloc(growbuf, linelen + 1); |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
554 if (growbuf == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
555 goto qf_init_end; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
556 growbufsiz = linelen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
557 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
558 linebuf = growbuf; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
559 } |
446 | 560 else |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
561 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
562 linebuf = IObuff; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
563 linelen = len; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
564 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
565 vim_strncpy(linebuf, p_str, linelen); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
566 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
567 /* |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
568 * Increment using len in order to discard the rest of the |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
569 * line if it exceeds LINE_MAXLEN. |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
570 */ |
446 | 571 p_str += len; |
572 } | |
573 else if (tv->v_type == VAR_LIST) | |
574 { | |
575 /* Get the next line from the supplied list */ | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
576 while (p_li != NULL |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
577 && (p_li->li_tv.v_type != VAR_STRING |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
578 || p_li->li_tv.vval.v_string == NULL)) |
446 | 579 p_li = p_li->li_next; /* Skip non-string items */ |
580 | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
581 if (p_li == NULL) /* End of the list */ |
446 | 582 break; |
583 | |
835 | 584 len = (int)STRLEN(p_li->li_tv.vval.v_string); |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
585 if (len > IOSIZE - 2) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
586 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
587 linelen = len; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
588 if (linelen > LINE_MAXLEN) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
589 linelen = LINE_MAXLEN - 1; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
590 if (growbuf == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
591 { |
9056
19d2dfb3f5e2
commit https://github.com/vim/vim/commit/9b4ebc692d77ca8ef90d72517347f74c2474dd3d
Christian Brabandt <cb@256bit.org>
parents:
9033
diff
changeset
|
592 growbuf = alloc(linelen + 1); |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
593 growbufsiz = linelen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
594 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
595 else if (linelen > growbufsiz) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
596 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
597 if ((growbuf = vim_realloc(growbuf, |
9056
19d2dfb3f5e2
commit https://github.com/vim/vim/commit/9b4ebc692d77ca8ef90d72517347f74c2474dd3d
Christian Brabandt <cb@256bit.org>
parents:
9033
diff
changeset
|
598 linelen + 1)) == NULL) |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
599 goto qf_init_end; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
600 growbufsiz = linelen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
601 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
602 linebuf = growbuf; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
603 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
604 else |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
605 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
606 linebuf = IObuff; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
607 linelen = len; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
608 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
609 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
610 vim_strncpy(linebuf, p_li->li_tv.vval.v_string, linelen); |
446 | 611 |
612 p_li = p_li->li_next; /* next item */ | |
613 } | |
614 } | |
615 else | |
616 { | |
617 /* Get the next line from the supplied buffer */ | |
618 if (buflnum > lnumlast) | |
619 break; | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
620 p_buf = ml_get_buf(buf, buflnum++, FALSE); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
621 linelen = (int)STRLEN(p_buf); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
622 if (linelen > IOSIZE - 2) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
623 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
624 if (growbuf == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
625 { |
9056
19d2dfb3f5e2
commit https://github.com/vim/vim/commit/9b4ebc692d77ca8ef90d72517347f74c2474dd3d
Christian Brabandt <cb@256bit.org>
parents:
9033
diff
changeset
|
626 growbuf = alloc(linelen + 1); |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
627 growbufsiz = linelen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
628 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
629 else if (linelen > growbufsiz) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
630 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
631 if (linelen > LINE_MAXLEN) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
632 linelen = LINE_MAXLEN - 1; |
9056
19d2dfb3f5e2
commit https://github.com/vim/vim/commit/9b4ebc692d77ca8ef90d72517347f74c2474dd3d
Christian Brabandt <cb@256bit.org>
parents:
9033
diff
changeset
|
633 if ((growbuf = vim_realloc(growbuf, linelen + 1)) == NULL) |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
634 goto qf_init_end; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
635 growbufsiz = linelen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
636 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
637 linebuf = growbuf; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
638 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
639 else |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
640 linebuf = IObuff; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
641 vim_strncpy(linebuf, p_buf, linelen); |
446 | 642 } |
41 | 643 } |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
644 else |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
645 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
646 if (fgets((char *)IObuff, IOSIZE, fd) == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
647 break; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
648 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
649 discard = FALSE; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
650 linelen = (int)STRLEN(IObuff); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
651 if (linelen == IOSIZE - 1 && (IObuff[linelen - 1] != '\n' |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
652 #ifdef USE_CRNL |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
653 || IObuff[linelen - 1] != '\r' |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
654 #endif |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
655 )) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
656 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
657 /* |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
658 * The current line exceeds IObuff, continue reading using |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
659 * growbuf until EOL or LINE_MAXLEN bytes is read. |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
660 */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
661 if (growbuf == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
662 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
663 growbufsiz = 2 * (IOSIZE - 1); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
664 growbuf = alloc(growbufsiz); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
665 if (growbuf == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
666 goto qf_init_end; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
667 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
668 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
669 /* Copy the read part of the line, excluding null-terminator */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
670 memcpy(growbuf, IObuff, IOSIZE - 1); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
671 growbuflen = linelen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
672 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
673 for (;;) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
674 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
675 if (fgets((char *)growbuf + growbuflen, |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
676 growbufsiz - growbuflen, fd) == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
677 break; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
678 linelen = STRLEN(growbuf + growbuflen); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
679 growbuflen += linelen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
680 if (growbuf[growbuflen - 1] == '\n' |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
681 #ifdef USE_CRNL |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
682 || growbuf[growbuflen - 1] == '\r' |
3002 | 683 #endif |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
684 ) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
685 break; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
686 if (growbufsiz == LINE_MAXLEN) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
687 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
688 discard = TRUE; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
689 break; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
690 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
691 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
692 growbufsiz = 2 * growbufsiz < LINE_MAXLEN |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
693 ? 2 * growbufsiz : LINE_MAXLEN; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
694 growbuf = vim_realloc(growbuf, 2 * growbufsiz); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
695 if (growbuf == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
696 goto qf_init_end; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
697 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
698 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
699 while (discard) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
700 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
701 /* |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
702 * The current line is longer than LINE_MAXLEN, continue |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
703 * reading but discard everything until EOL or EOF is |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
704 * reached. |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
705 */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
706 if (fgets((char *)IObuff, IOSIZE, fd) == NULL |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
707 || (int)STRLEN(IObuff) < IOSIZE - 1 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
708 || IObuff[IOSIZE - 1] == '\n' |
7 | 709 #ifdef USE_CRNL |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
710 || IObuff[IOSIZE - 1] == '\r' |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
711 #endif |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
712 ) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
713 break; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
714 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
715 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
716 linebuf = growbuf; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
717 linelen = growbuflen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
718 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
719 else |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
720 linebuf = IObuff; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
721 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
722 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
723 if (linelen > 0 && linebuf[linelen - 1] == '\n') |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
724 linebuf[linelen - 1] = NUL; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
725 #ifdef USE_CRNL |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
726 if (linelen > 0 && linebuf[linelen - 1] == '\r') |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
727 linebuf[linelen - 1] = NUL; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
728 #endif |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
729 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
730 #ifdef FEAT_MBYTE |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
731 remove_bom(linebuf); |
7 | 732 #endif |
733 | |
789 | 734 /* If there was no %> item start at the first pattern */ |
735 if (fmt_start == NULL) | |
736 fmt_ptr = fmt_first; | |
737 else | |
738 { | |
739 fmt_ptr = fmt_start; | |
740 fmt_start = NULL; | |
741 } | |
742 | |
7 | 743 /* |
744 * Try to match each part of 'errorformat' until we find a complete | |
745 * match or no match. | |
746 */ | |
747 valid = TRUE; | |
748 restofline: | |
789 | 749 for ( ; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next) |
7 | 750 { |
6450 | 751 int r; |
752 | |
7 | 753 idx = fmt_ptr->prefix; |
754 if (multiscan && vim_strchr((char_u *)"OPQ", idx) == NULL) | |
755 continue; | |
756 namebuf[0] = NUL; | |
230 | 757 pattern[0] = NUL; |
7 | 758 if (!multiscan) |
759 errmsg[0] = NUL; | |
760 lnum = 0; | |
761 col = 0; | |
170 | 762 use_viscol = FALSE; |
7 | 763 enr = -1; |
764 type = 0; | |
765 tail = NULL; | |
766 | |
767 regmatch.regprog = fmt_ptr->prog; | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
768 r = vim_regexec(®match, linebuf, (colnr_T)0); |
6450 | 769 fmt_ptr->prog = regmatch.regprog; |
770 if (r) | |
7 | 771 { |
772 if ((idx == 'C' || idx == 'Z') && !multiline) | |
773 continue; | |
774 if (vim_strchr((char_u *)"EWI", idx) != NULL) | |
775 type = idx; | |
776 else | |
777 type = 0; | |
778 /* | |
895 | 779 * Extract error message data from matched line. |
780 * We check for an actual submatch, because "\[" and "\]" in | |
781 * the 'errorformat' may cause the wrong submatch to be used. | |
7 | 782 */ |
783 if ((i = (int)fmt_ptr->addr[0]) > 0) /* %f */ | |
784 { | |
895 | 785 int c; |
786 | |
787 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) | |
788 continue; | |
277 | 789 |
790 /* Expand ~/file and $HOME/file to full path. */ | |
895 | 791 c = *regmatch.endp[i]; |
277 | 792 *regmatch.endp[i] = NUL; |
793 expand_env(regmatch.startp[i], namebuf, CMDBUFFSIZE); | |
794 *regmatch.endp[i] = c; | |
795 | |
7 | 796 if (vim_strchr((char_u *)"OPQ", idx) != NULL |
277 | 797 && mch_getperm(namebuf) == -1) |
7 | 798 continue; |
799 } | |
800 if ((i = (int)fmt_ptr->addr[1]) > 0) /* %n */ | |
895 | 801 { |
802 if (regmatch.startp[i] == NULL) | |
803 continue; | |
7 | 804 enr = (int)atol((char *)regmatch.startp[i]); |
895 | 805 } |
7 | 806 if ((i = (int)fmt_ptr->addr[2]) > 0) /* %l */ |
895 | 807 { |
808 if (regmatch.startp[i] == NULL) | |
809 continue; | |
7 | 810 lnum = atol((char *)regmatch.startp[i]); |
895 | 811 } |
7 | 812 if ((i = (int)fmt_ptr->addr[3]) > 0) /* %c */ |
895 | 813 { |
814 if (regmatch.startp[i] == NULL) | |
815 continue; | |
7 | 816 col = (int)atol((char *)regmatch.startp[i]); |
895 | 817 } |
7 | 818 if ((i = (int)fmt_ptr->addr[4]) > 0) /* %t */ |
895 | 819 { |
820 if (regmatch.startp[i] == NULL) | |
821 continue; | |
7 | 822 type = *regmatch.startp[i]; |
895 | 823 } |
625 | 824 if (fmt_ptr->flags == '+' && !multiscan) /* %+ */ |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
825 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
826 if (linelen > errmsglen) { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
827 /* linelen + null terminator */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
828 if ((errmsg = vim_realloc(errmsg, linelen + 1)) == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
829 goto qf_init_end; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
830 errmsglen = linelen + 1; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
831 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
832 vim_strncpy(errmsg, linebuf, linelen); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
833 } |
7 | 834 else if ((i = (int)fmt_ptr->addr[5]) > 0) /* %m */ |
835 { | |
895 | 836 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) |
837 continue; | |
7 | 838 len = (int)(regmatch.endp[i] - regmatch.startp[i]); |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
839 if (len > errmsglen) { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
840 /* len + null terminator */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
841 if ((errmsg = vim_realloc(errmsg, len + 1)) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
842 == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
843 goto qf_init_end; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
844 errmsglen = len + 1; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
845 } |
418 | 846 vim_strncpy(errmsg, regmatch.startp[i], len); |
7 | 847 } |
848 if ((i = (int)fmt_ptr->addr[6]) > 0) /* %r */ | |
895 | 849 { |
850 if (regmatch.startp[i] == NULL) | |
851 continue; | |
7 | 852 tail = regmatch.startp[i]; |
895 | 853 } |
7 | 854 if ((i = (int)fmt_ptr->addr[7]) > 0) /* %p */ |
855 { | |
3555 | 856 char_u *match_ptr; |
857 | |
895 | 858 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) |
859 continue; | |
3555 | 860 col = 0; |
861 for (match_ptr = regmatch.startp[i]; | |
862 match_ptr != regmatch.endp[i]; ++match_ptr) | |
863 { | |
864 ++col; | |
865 if (*match_ptr == TAB) | |
866 { | |
867 col += 7; | |
868 col -= col % 8; | |
869 } | |
870 } | |
871 ++col; | |
872 use_viscol = TRUE; | |
7 | 873 } |
874 if ((i = (int)fmt_ptr->addr[8]) > 0) /* %v */ | |
875 { | |
895 | 876 if (regmatch.startp[i] == NULL) |
877 continue; | |
7 | 878 col = (int)atol((char *)regmatch.startp[i]); |
170 | 879 use_viscol = TRUE; |
7 | 880 } |
230 | 881 if ((i = (int)fmt_ptr->addr[9]) > 0) /* %s */ |
882 { | |
895 | 883 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) |
884 continue; | |
230 | 885 len = (int)(regmatch.endp[i] - regmatch.startp[i]); |
886 if (len > CMDBUFFSIZE - 5) | |
887 len = CMDBUFFSIZE - 5; | |
888 STRCPY(pattern, "^\\V"); | |
889 STRNCAT(pattern, regmatch.startp[i], len); | |
890 pattern[len + 3] = '\\'; | |
891 pattern[len + 4] = '$'; | |
892 pattern[len + 5] = NUL; | |
893 } | |
7 | 894 break; |
895 } | |
896 } | |
897 multiscan = FALSE; | |
789 | 898 |
625 | 899 if (fmt_ptr == NULL || idx == 'D' || idx == 'X') |
7 | 900 { |
625 | 901 if (fmt_ptr != NULL) |
7 | 902 { |
903 if (idx == 'D') /* enter directory */ | |
904 { | |
905 if (*namebuf == NUL) | |
906 { | |
907 EMSG(_("E379: Missing or empty directory name")); | |
908 goto error2; | |
909 } | |
910 if ((directory = qf_push_dir(namebuf, &dir_stack)) == NULL) | |
911 goto error2; | |
912 } | |
913 else if (idx == 'X') /* leave directory */ | |
914 directory = qf_pop_dir(&dir_stack); | |
915 } | |
916 namebuf[0] = NUL; /* no match found, remove file name */ | |
917 lnum = 0; /* don't jump to this line */ | |
918 valid = FALSE; | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
919 if (linelen > errmsglen) { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
920 /* linelen + null terminator */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
921 if ((errmsg = vim_realloc(errmsg, linelen + 1)) == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
922 goto qf_init_end; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
923 errmsglen = linelen + 1; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
924 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
925 /* copy whole line to error message */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
926 vim_strncpy(errmsg, linebuf, linelen); |
625 | 927 if (fmt_ptr == NULL) |
7 | 928 multiline = multiignore = FALSE; |
929 } | |
625 | 930 else if (fmt_ptr != NULL) |
7 | 931 { |
789 | 932 /* honor %> item */ |
933 if (fmt_ptr->conthere) | |
934 fmt_start = fmt_ptr; | |
935 | |
7 | 936 if (vim_strchr((char_u *)"AEWI", idx) != NULL) |
5716 | 937 { |
7 | 938 multiline = TRUE; /* start of a multi-line message */ |
5716 | 939 multiignore = FALSE; /* reset continuation */ |
940 } | |
7 | 941 else if (vim_strchr((char_u *)"CZ", idx) != NULL) |
942 { /* continuation of multi-line msg */ | |
943 if (qfprev == NULL) | |
944 goto error2; | |
945 if (*errmsg && !multiignore) | |
946 { | |
947 len = (int)STRLEN(qfprev->qf_text); | |
948 if ((ptr = alloc((unsigned)(len + STRLEN(errmsg) + 2))) | |
949 == NULL) | |
950 goto error2; | |
951 STRCPY(ptr, qfprev->qf_text); | |
952 vim_free(qfprev->qf_text); | |
953 qfprev->qf_text = ptr; | |
954 *(ptr += len) = '\n'; | |
955 STRCPY(++ptr, errmsg); | |
956 } | |
957 if (qfprev->qf_nr == -1) | |
958 qfprev->qf_nr = enr; | |
959 if (vim_isprintc(type) && !qfprev->qf_type) | |
960 qfprev->qf_type = type; /* only printable chars allowed */ | |
961 if (!qfprev->qf_lnum) | |
962 qfprev->qf_lnum = lnum; | |
963 if (!qfprev->qf_col) | |
964 qfprev->qf_col = col; | |
170 | 965 qfprev->qf_viscol = use_viscol; |
7 | 966 if (!qfprev->qf_fnum) |
967 qfprev->qf_fnum = qf_get_fnum(directory, | |
968 *namebuf || directory ? namebuf | |
969 : currfile && valid ? currfile : 0); | |
970 if (idx == 'Z') | |
971 multiline = multiignore = FALSE; | |
972 line_breakcheck(); | |
973 continue; | |
974 } | |
975 else if (vim_strchr((char_u *)"OPQ", idx) != NULL) | |
976 { | |
977 /* global file names */ | |
978 valid = FALSE; | |
979 if (*namebuf == NUL || mch_getperm(namebuf) >= 0) | |
980 { | |
981 if (*namebuf && idx == 'P') | |
982 currfile = qf_push_dir(namebuf, &file_stack); | |
983 else if (idx == 'Q') | |
984 currfile = qf_pop_dir(&file_stack); | |
985 *namebuf = NUL; | |
986 if (tail && *tail) | |
987 { | |
1668 | 988 STRMOVE(IObuff, skipwhite(tail)); |
7 | 989 multiscan = TRUE; |
990 goto restofline; | |
991 } | |
992 } | |
993 } | |
994 if (fmt_ptr->flags == '-') /* generally exclude this line */ | |
995 { | |
996 if (multiline) | |
997 multiignore = TRUE; /* also exclude continuation lines */ | |
998 continue; | |
999 } | |
1000 } | |
1001 | |
644 | 1002 if (qf_add_entry(qi, &qfprev, |
7 | 1003 directory, |
129 | 1004 (*namebuf || directory) |
7 | 1005 ? namebuf |
129 | 1006 : ((currfile && valid) ? currfile : (char_u *)NULL), |
1065 | 1007 0, |
7 | 1008 errmsg, |
1009 lnum, | |
1010 col, | |
170 | 1011 use_viscol, |
230 | 1012 pattern, |
7 | 1013 enr, |
1014 type, | |
1015 valid) == FAIL) | |
1016 goto error2; | |
1017 line_breakcheck(); | |
1018 } | |
41 | 1019 if (fd == NULL || !ferror(fd)) |
7 | 1020 { |
644 | 1021 if (qi->qf_lists[qi->qf_curlist].qf_index == 0) |
7 | 1022 { |
644 | 1023 /* no valid entry found */ |
1024 qi->qf_lists[qi->qf_curlist].qf_ptr = | |
1025 qi->qf_lists[qi->qf_curlist].qf_start; | |
1026 qi->qf_lists[qi->qf_curlist].qf_index = 1; | |
1027 qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE; | |
7 | 1028 } |
1029 else | |
1030 { | |
644 | 1031 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; |
1032 if (qi->qf_lists[qi->qf_curlist].qf_ptr == NULL) | |
1033 qi->qf_lists[qi->qf_curlist].qf_ptr = | |
1034 qi->qf_lists[qi->qf_curlist].qf_start; | |
7 | 1035 } |
644 | 1036 /* return number of matches */ |
1037 retval = qi->qf_lists[qi->qf_curlist].qf_count; | |
7 | 1038 goto qf_init_ok; |
1039 } | |
1040 EMSG(_(e_readerrf)); | |
1041 error2: | |
644 | 1042 qf_free(qi, qi->qf_curlist); |
1043 qi->qf_listcount--; | |
1044 if (qi->qf_curlist > 0) | |
1045 --qi->qf_curlist; | |
7 | 1046 qf_init_ok: |
41 | 1047 if (fd != NULL) |
1048 fclose(fd); | |
7 | 1049 for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_first) |
1050 { | |
1051 fmt_first = fmt_ptr->next; | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4371
diff
changeset
|
1052 vim_regfree(fmt_ptr->prog); |
7 | 1053 vim_free(fmt_ptr); |
1054 } | |
1055 qf_clean_dir_stack(&dir_stack); | |
1056 qf_clean_dir_stack(&file_stack); | |
1057 qf_init_end: | |
1058 vim_free(namebuf); | |
1059 vim_free(errmsg); | |
230 | 1060 vim_free(pattern); |
7 | 1061 vim_free(fmtstr); |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
1062 vim_free(growbuf); |
7 | 1063 |
1064 #ifdef FEAT_WINDOWS | |
8932
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
1065 qf_update_buffer(qi, TRUE); |
7 | 1066 #endif |
1067 | |
1068 return retval; | |
1069 } | |
1070 | |
6079 | 1071 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1072 qf_store_title(qf_info_T *qi, char_u *title) |
6079 | 1073 { |
1074 if (title != NULL) | |
1075 { | |
1076 char_u *p = alloc((int)STRLEN(title) + 2); | |
1077 | |
1078 qi->qf_lists[qi->qf_curlist].qf_title = p; | |
1079 if (p != NULL) | |
1080 sprintf((char *)p, ":%s", (char *)title); | |
1081 } | |
1082 } | |
1083 | |
7 | 1084 /* |
1085 * Prepare for adding a new quickfix list. | |
1086 */ | |
1087 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1088 qf_new_list(qf_info_T *qi, char_u *qf_title) |
7 | 1089 { |
1090 int i; | |
1091 | |
1092 /* | |
6079 | 1093 * If the current entry is not the last entry, delete entries beyond |
7 | 1094 * the current entry. This makes it possible to browse in a tree-like |
1095 * way with ":grep'. | |
1096 */ | |
644 | 1097 while (qi->qf_listcount > qi->qf_curlist + 1) |
1098 qf_free(qi, --qi->qf_listcount); | |
7 | 1099 |
1100 /* | |
1101 * When the stack is full, remove to oldest entry | |
1102 * Otherwise, add a new entry. | |
1103 */ | |
644 | 1104 if (qi->qf_listcount == LISTCOUNT) |
7 | 1105 { |
644 | 1106 qf_free(qi, 0); |
7 | 1107 for (i = 1; i < LISTCOUNT; ++i) |
644 | 1108 qi->qf_lists[i - 1] = qi->qf_lists[i]; |
1109 qi->qf_curlist = LISTCOUNT - 1; | |
7 | 1110 } |
1111 else | |
644 | 1112 qi->qf_curlist = qi->qf_listcount++; |
3259 | 1113 vim_memset(&qi->qf_lists[qi->qf_curlist], 0, (size_t)(sizeof(qf_list_T))); |
6079 | 1114 qf_store_title(qi, qf_title); |
7 | 1115 } |
1116 | |
644 | 1117 /* |
1118 * Free a location list | |
1119 */ | |
1120 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1121 ll_free_all(qf_info_T **pqi) |
359 | 1122 { |
1123 int i; | |
644 | 1124 qf_info_T *qi; |
1125 | |
1126 qi = *pqi; | |
1127 if (qi == NULL) | |
1128 return; | |
1129 *pqi = NULL; /* Remove reference to this list */ | |
1130 | |
1131 qi->qf_refcount--; | |
1132 if (qi->qf_refcount < 1) | |
1133 { | |
1134 /* No references to this location list */ | |
1135 for (i = 0; i < qi->qf_listcount; ++i) | |
1136 qf_free(qi, i); | |
1137 vim_free(qi); | |
1138 } | |
359 | 1139 } |
644 | 1140 |
1141 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1142 qf_free_all(win_T *wp) |
644 | 1143 { |
1144 int i; | |
1145 qf_info_T *qi = &ql_info; | |
1146 | |
1147 if (wp != NULL) | |
1148 { | |
1149 /* location list */ | |
1150 ll_free_all(&wp->w_llist); | |
1151 ll_free_all(&wp->w_llist_ref); | |
1152 } | |
1153 else | |
1154 /* quickfix list */ | |
1155 for (i = 0; i < qi->qf_listcount; ++i) | |
1156 qf_free(qi, i); | |
1157 } | |
359 | 1158 |
7 | 1159 /* |
1160 * Add an entry to the end of the list of errors. | |
1161 * Returns OK or FAIL. | |
1162 */ | |
1163 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1164 qf_add_entry( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1165 qf_info_T *qi, /* quickfix list */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1166 qfline_T **prevp, /* pointer to previously added entry or NULL */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1167 char_u *dir, /* optional directory name */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1168 char_u *fname, /* file name or NULL */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1169 int bufnum, /* buffer number or zero */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1170 char_u *mesg, /* message */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1171 long lnum, /* line number */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1172 int col, /* column */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1173 int vis_col, /* using visual column */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1174 char_u *pattern, /* search pattern */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1175 int nr, /* error number */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1176 int type, /* type character */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1177 int valid) /* valid entry */ |
7 | 1178 { |
230 | 1179 qfline_T *qfp; |
7 | 1180 |
230 | 1181 if ((qfp = (qfline_T *)alloc((unsigned)sizeof(qfline_T))) == NULL) |
7 | 1182 return FAIL; |
1065 | 1183 if (bufnum != 0) |
1184 qfp->qf_fnum = bufnum; | |
1185 else | |
1186 qfp->qf_fnum = qf_get_fnum(dir, fname); | |
7 | 1187 if ((qfp->qf_text = vim_strsave(mesg)) == NULL) |
1188 { | |
1189 vim_free(qfp); | |
1190 return FAIL; | |
1191 } | |
1192 qfp->qf_lnum = lnum; | |
1193 qfp->qf_col = col; | |
170 | 1194 qfp->qf_viscol = vis_col; |
230 | 1195 if (pattern == NULL || *pattern == NUL) |
1196 qfp->qf_pattern = NULL; | |
1197 else if ((qfp->qf_pattern = vim_strsave(pattern)) == NULL) | |
1198 { | |
1199 vim_free(qfp->qf_text); | |
1200 vim_free(qfp); | |
1201 return FAIL; | |
1202 } | |
7 | 1203 qfp->qf_nr = nr; |
1204 if (type != 1 && !vim_isprintc(type)) /* only printable chars allowed */ | |
1205 type = 0; | |
1206 qfp->qf_type = type; | |
1207 qfp->qf_valid = valid; | |
1208 | |
644 | 1209 if (qi->qf_lists[qi->qf_curlist].qf_count == 0) |
1210 /* first element in the list */ | |
7 | 1211 { |
644 | 1212 qi->qf_lists[qi->qf_curlist].qf_start = qfp; |
8716
4ce26276caeb
commit https://github.com/vim/vim/commit/8b20179c657b4266dff115486ca68c6a50324071
Christian Brabandt <cb@256bit.org>
parents:
8702
diff
changeset
|
1213 qi->qf_lists[qi->qf_curlist].qf_ptr = qfp; |
4ce26276caeb
commit https://github.com/vim/vim/commit/8b20179c657b4266dff115486ca68c6a50324071
Christian Brabandt <cb@256bit.org>
parents:
8702
diff
changeset
|
1214 qi->qf_lists[qi->qf_curlist].qf_index = 0; |
7 | 1215 qfp->qf_prev = qfp; /* first element points to itself */ |
1216 } | |
1217 else | |
1218 { | |
1219 qfp->qf_prev = *prevp; | |
1220 (*prevp)->qf_next = qfp; | |
1221 } | |
1222 qfp->qf_next = qfp; /* last element points to itself */ | |
1223 qfp->qf_cleared = FALSE; | |
1224 *prevp = qfp; | |
644 | 1225 ++qi->qf_lists[qi->qf_curlist].qf_count; |
1226 if (qi->qf_lists[qi->qf_curlist].qf_index == 0 && qfp->qf_valid) | |
1227 /* first valid entry */ | |
7 | 1228 { |
644 | 1229 qi->qf_lists[qi->qf_curlist].qf_index = |
1230 qi->qf_lists[qi->qf_curlist].qf_count; | |
1231 qi->qf_lists[qi->qf_curlist].qf_ptr = qfp; | |
7 | 1232 } |
1233 | |
1234 return OK; | |
1235 } | |
1236 | |
1237 /* | |
659 | 1238 * Allocate a new location list |
644 | 1239 */ |
659 | 1240 static qf_info_T * |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1241 ll_new_list(void) |
644 | 1242 { |
659 | 1243 qf_info_T *qi; |
1244 | |
1245 qi = (qf_info_T *)alloc((unsigned)sizeof(qf_info_T)); | |
1246 if (qi != NULL) | |
1247 { | |
1248 vim_memset(qi, 0, (size_t)(sizeof(qf_info_T))); | |
1249 qi->qf_refcount++; | |
1250 } | |
1251 | |
1252 return qi; | |
644 | 1253 } |
1254 | |
1255 /* | |
1256 * Return the location list for window 'wp'. | |
1257 * If not present, allocate a location list | |
1258 */ | |
1259 static qf_info_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1260 ll_get_or_alloc_list(win_T *wp) |
644 | 1261 { |
1262 if (IS_LL_WINDOW(wp)) | |
1263 /* For a location list window, use the referenced location list */ | |
1264 return wp->w_llist_ref; | |
1265 | |
1266 /* | |
1267 * For a non-location list window, w_llist_ref should not point to a | |
1268 * location list. | |
1269 */ | |
1270 ll_free_all(&wp->w_llist_ref); | |
1271 | |
1272 if (wp->w_llist == NULL) | |
659 | 1273 wp->w_llist = ll_new_list(); /* new location list */ |
644 | 1274 return wp->w_llist; |
1275 } | |
1276 | |
1277 /* | |
1278 * Copy the location list from window "from" to window "to". | |
1279 */ | |
1280 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1281 copy_loclist(win_T *from, win_T *to) |
644 | 1282 { |
1283 qf_info_T *qi; | |
1284 int idx; | |
1285 int i; | |
1286 | |
1287 /* | |
1288 * When copying from a location list window, copy the referenced | |
1289 * location list. For other windows, copy the location list for | |
1290 * that window. | |
1291 */ | |
1292 if (IS_LL_WINDOW(from)) | |
1293 qi = from->w_llist_ref; | |
1294 else | |
1295 qi = from->w_llist; | |
1296 | |
1297 if (qi == NULL) /* no location list to copy */ | |
1298 return; | |
1299 | |
659 | 1300 /* allocate a new location list */ |
1301 if ((to->w_llist = ll_new_list()) == NULL) | |
644 | 1302 return; |
1303 | |
1304 to->w_llist->qf_listcount = qi->qf_listcount; | |
1305 | |
1306 /* Copy the location lists one at a time */ | |
1307 for (idx = 0; idx < qi->qf_listcount; idx++) | |
1308 { | |
1309 qf_list_T *from_qfl; | |
1310 qf_list_T *to_qfl; | |
1311 | |
1312 to->w_llist->qf_curlist = idx; | |
1313 | |
1314 from_qfl = &qi->qf_lists[idx]; | |
1315 to_qfl = &to->w_llist->qf_lists[idx]; | |
1316 | |
1317 /* Some of the fields are populated by qf_add_entry() */ | |
1318 to_qfl->qf_nonevalid = from_qfl->qf_nonevalid; | |
1319 to_qfl->qf_count = 0; | |
1320 to_qfl->qf_index = 0; | |
1321 to_qfl->qf_start = NULL; | |
1322 to_qfl->qf_ptr = NULL; | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
1323 if (from_qfl->qf_title != NULL) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
1324 to_qfl->qf_title = vim_strsave(from_qfl->qf_title); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
1325 else |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
1326 to_qfl->qf_title = NULL; |
644 | 1327 |
1328 if (from_qfl->qf_count) | |
1329 { | |
1330 qfline_T *from_qfp; | |
1331 qfline_T *prevp = NULL; | |
1332 | |
1333 /* copy all the location entries in this list */ | |
1334 for (i = 0, from_qfp = from_qfl->qf_start; i < from_qfl->qf_count; | |
1335 ++i, from_qfp = from_qfp->qf_next) | |
1336 { | |
1337 if (qf_add_entry(to->w_llist, &prevp, | |
1338 NULL, | |
1339 NULL, | |
1065 | 1340 0, |
644 | 1341 from_qfp->qf_text, |
1342 from_qfp->qf_lnum, | |
1343 from_qfp->qf_col, | |
1344 from_qfp->qf_viscol, | |
1345 from_qfp->qf_pattern, | |
1346 from_qfp->qf_nr, | |
1347 0, | |
1348 from_qfp->qf_valid) == FAIL) | |
1349 { | |
1350 qf_free_all(to); | |
1351 return; | |
1352 } | |
1353 /* | |
1354 * qf_add_entry() will not set the qf_num field, as the | |
1355 * directory and file names are not supplied. So the qf_fnum | |
1356 * field is copied here. | |
1357 */ | |
1358 prevp->qf_fnum = from_qfp->qf_fnum; /* file number */ | |
1359 prevp->qf_type = from_qfp->qf_type; /* error type */ | |
1360 if (from_qfl->qf_ptr == from_qfp) | |
1361 to_qfl->qf_ptr = prevp; /* current location */ | |
1362 } | |
1363 } | |
1364 | |
1365 to_qfl->qf_index = from_qfl->qf_index; /* current index in the list */ | |
1366 | |
1367 /* When no valid entries are present in the list, qf_ptr points to | |
1368 * the first item in the list */ | |
2795 | 1369 if (to_qfl->qf_nonevalid) |
5060
30910831e5b0
updated for version 7.3.1273
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1370 { |
644 | 1371 to_qfl->qf_ptr = to_qfl->qf_start; |
5060
30910831e5b0
updated for version 7.3.1273
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1372 to_qfl->qf_index = 1; |
30910831e5b0
updated for version 7.3.1273
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1373 } |
644 | 1374 } |
1375 | |
1376 to->w_llist->qf_curlist = qi->qf_curlist; /* current list */ | |
1377 } | |
1378 | |
1379 /* | |
7 | 1380 * get buffer number for file "dir.name" |
1381 */ | |
1382 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1383 qf_get_fnum(char_u *directory, char_u *fname) |
7 | 1384 { |
1385 if (fname == NULL || *fname == NUL) /* no file name */ | |
1386 return 0; | |
1387 { | |
1388 char_u *ptr; | |
1389 int fnum; | |
1390 | |
2823 | 1391 #ifdef VMS |
7 | 1392 vms_remove_version(fname); |
2823 | 1393 #endif |
1394 #ifdef BACKSLASH_IN_FILENAME | |
7 | 1395 if (directory != NULL) |
1396 slash_adjust(directory); | |
1397 slash_adjust(fname); | |
2823 | 1398 #endif |
7 | 1399 if (directory != NULL && !vim_isAbsName(fname) |
1400 && (ptr = concat_fnames(directory, fname, TRUE)) != NULL) | |
1401 { | |
1402 /* | |
1403 * Here we check if the file really exists. | |
1404 * This should normally be true, but if make works without | |
1405 * "leaving directory"-messages we might have missed a | |
1406 * directory change. | |
1407 */ | |
1408 if (mch_getperm(ptr) < 0) | |
1409 { | |
1410 vim_free(ptr); | |
1411 directory = qf_guess_filepath(fname); | |
1412 if (directory) | |
1413 ptr = concat_fnames(directory, fname, TRUE); | |
1414 else | |
1415 ptr = vim_strsave(fname); | |
1416 } | |
1417 /* Use concatenated directory name and file name */ | |
1418 fnum = buflist_add(ptr, 0); | |
1419 vim_free(ptr); | |
1420 return fnum; | |
1421 } | |
1422 return buflist_add(fname, 0); | |
1423 } | |
1424 } | |
1425 | |
1426 /* | |
1427 * push dirbuf onto the directory stack and return pointer to actual dir or | |
1428 * NULL on error | |
1429 */ | |
1430 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1431 qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr) |
7 | 1432 { |
1433 struct dir_stack_T *ds_new; | |
1434 struct dir_stack_T *ds_ptr; | |
1435 | |
1436 /* allocate new stack element and hook it in */ | |
1437 ds_new = (struct dir_stack_T *)alloc((unsigned)sizeof(struct dir_stack_T)); | |
1438 if (ds_new == NULL) | |
1439 return NULL; | |
1440 | |
1441 ds_new->next = *stackptr; | |
1442 *stackptr = ds_new; | |
1443 | |
1444 /* store directory on the stack */ | |
1445 if (vim_isAbsName(dirbuf) | |
1446 || (*stackptr)->next == NULL | |
1447 || (*stackptr && dir_stack != *stackptr)) | |
1448 (*stackptr)->dirname = vim_strsave(dirbuf); | |
1449 else | |
1450 { | |
1451 /* Okay we don't have an absolute path. | |
1452 * dirbuf must be a subdir of one of the directories on the stack. | |
1453 * Let's search... | |
1454 */ | |
1455 ds_new = (*stackptr)->next; | |
1456 (*stackptr)->dirname = NULL; | |
1457 while (ds_new) | |
1458 { | |
1459 vim_free((*stackptr)->dirname); | |
1460 (*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf, | |
1461 TRUE); | |
1462 if (mch_isdir((*stackptr)->dirname) == TRUE) | |
1463 break; | |
1464 | |
1465 ds_new = ds_new->next; | |
1466 } | |
1467 | |
1468 /* clean up all dirs we already left */ | |
1469 while ((*stackptr)->next != ds_new) | |
1470 { | |
1471 ds_ptr = (*stackptr)->next; | |
1472 (*stackptr)->next = (*stackptr)->next->next; | |
1473 vim_free(ds_ptr->dirname); | |
1474 vim_free(ds_ptr); | |
1475 } | |
1476 | |
1477 /* Nothing found -> it must be on top level */ | |
1478 if (ds_new == NULL) | |
1479 { | |
1480 vim_free((*stackptr)->dirname); | |
1481 (*stackptr)->dirname = vim_strsave(dirbuf); | |
1482 } | |
1483 } | |
1484 | |
1485 if ((*stackptr)->dirname != NULL) | |
1486 return (*stackptr)->dirname; | |
1487 else | |
1488 { | |
1489 ds_ptr = *stackptr; | |
1490 *stackptr = (*stackptr)->next; | |
1491 vim_free(ds_ptr); | |
1492 return NULL; | |
1493 } | |
1494 } | |
1495 | |
1496 | |
1497 /* | |
1498 * pop dirbuf from the directory stack and return previous directory or NULL if | |
1499 * stack is empty | |
1500 */ | |
1501 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1502 qf_pop_dir(struct dir_stack_T **stackptr) |
7 | 1503 { |
1504 struct dir_stack_T *ds_ptr; | |
1505 | |
1506 /* TODO: Should we check if dirbuf is the directory on top of the stack? | |
1507 * What to do if it isn't? */ | |
1508 | |
1509 /* pop top element and free it */ | |
1510 if (*stackptr != NULL) | |
1511 { | |
1512 ds_ptr = *stackptr; | |
1513 *stackptr = (*stackptr)->next; | |
1514 vim_free(ds_ptr->dirname); | |
1515 vim_free(ds_ptr); | |
1516 } | |
1517 | |
1518 /* return NEW top element as current dir or NULL if stack is empty*/ | |
1519 return *stackptr ? (*stackptr)->dirname : NULL; | |
1520 } | |
1521 | |
1522 /* | |
1523 * clean up directory stack | |
1524 */ | |
1525 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1526 qf_clean_dir_stack(struct dir_stack_T **stackptr) |
7 | 1527 { |
1528 struct dir_stack_T *ds_ptr; | |
1529 | |
1530 while ((ds_ptr = *stackptr) != NULL) | |
1531 { | |
1532 *stackptr = (*stackptr)->next; | |
1533 vim_free(ds_ptr->dirname); | |
1534 vim_free(ds_ptr); | |
1535 } | |
1536 } | |
1537 | |
1538 /* | |
1539 * Check in which directory of the directory stack the given file can be | |
1540 * found. | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
1541 * Returns a pointer to the directory name or NULL if not found. |
7 | 1542 * Cleans up intermediate directory entries. |
1543 * | |
1544 * TODO: How to solve the following problem? | |
1545 * If we have the this directory tree: | |
1546 * ./ | |
1547 * ./aa | |
1548 * ./aa/bb | |
1549 * ./bb | |
1550 * ./bb/x.c | |
1551 * and make says: | |
1552 * making all in aa | |
1553 * making all in bb | |
1554 * x.c:9: Error | |
1555 * Then qf_push_dir thinks we are in ./aa/bb, but we are in ./bb. | |
1556 * qf_guess_filepath will return NULL. | |
1557 */ | |
1558 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1559 qf_guess_filepath(char_u *filename) |
7 | 1560 { |
1561 struct dir_stack_T *ds_ptr; | |
1562 struct dir_stack_T *ds_tmp; | |
1563 char_u *fullname; | |
1564 | |
1565 /* no dirs on the stack - there's nothing we can do */ | |
1566 if (dir_stack == NULL) | |
1567 return NULL; | |
1568 | |
1569 ds_ptr = dir_stack->next; | |
1570 fullname = NULL; | |
1571 while (ds_ptr) | |
1572 { | |
1573 vim_free(fullname); | |
1574 fullname = concat_fnames(ds_ptr->dirname, filename, TRUE); | |
1575 | |
1576 /* If concat_fnames failed, just go on. The worst thing that can happen | |
1577 * is that we delete the entire stack. | |
1578 */ | |
1579 if ((fullname != NULL) && (mch_getperm(fullname) >= 0)) | |
1580 break; | |
1581 | |
1582 ds_ptr = ds_ptr->next; | |
1583 } | |
1584 | |
1585 vim_free(fullname); | |
1586 | |
1587 /* clean up all dirs we already left */ | |
1588 while (dir_stack->next != ds_ptr) | |
1589 { | |
1590 ds_tmp = dir_stack->next; | |
1591 dir_stack->next = dir_stack->next->next; | |
1592 vim_free(ds_tmp->dirname); | |
1593 vim_free(ds_tmp); | |
1594 } | |
1595 | |
1596 return ds_ptr==NULL? NULL: ds_ptr->dirname; | |
1597 | |
1598 } | |
1599 | |
1600 /* | |
8702
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1601 * When loading a file from the quickfix, the auto commands may modify it. |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1602 * This may invalidate the current quickfix entry. This function checks |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1603 * whether a entry is still present in the quickfix. |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1604 * Similar to location list. |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1605 */ |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1606 static int |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1607 is_qf_entry_present(qf_info_T *qi, qfline_T *qf_ptr) |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1608 { |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1609 qf_list_T *qfl; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1610 qfline_T *qfp; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1611 int i; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1612 |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1613 qfl = &qi->qf_lists[qi->qf_curlist]; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1614 |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1615 /* Search for the entry in the current list */ |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1616 for (i = 0, qfp = qfl->qf_start; i < qfl->qf_count; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1617 ++i, qfp = qfp->qf_next) |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1618 if (qfp == qf_ptr) |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1619 break; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1620 |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1621 if (i == qfl->qf_count) /* Entry is not found */ |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1622 return FALSE; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1623 |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1624 return TRUE; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1625 } |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1626 |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1627 /* |
7 | 1628 * jump to a quickfix line |
1629 * if dir == FORWARD go "errornr" valid entries forward | |
1630 * if dir == BACKWARD go "errornr" valid entries backward | |
1631 * if dir == FORWARD_FILE go "errornr" valid entries files backward | |
1632 * if dir == BACKWARD_FILE go "errornr" valid entries files backward | |
1633 * else if "errornr" is zero, redisplay the same line | |
1634 * else go to entry "errornr" | |
1635 */ | |
1636 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1637 qf_jump( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1638 qf_info_T *qi, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1639 int dir, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1640 int errornr, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1641 int forceit) |
7 | 1642 { |
644 | 1643 qf_info_T *ll_ref; |
230 | 1644 qfline_T *qf_ptr; |
1645 qfline_T *old_qf_ptr; | |
7 | 1646 int qf_index; |
1647 int old_qf_fnum; | |
1648 int old_qf_index; | |
1649 int prev_index; | |
1650 static char_u *e_no_more_items = (char_u *)N_("E553: No more items"); | |
1651 char_u *err = e_no_more_items; | |
1652 linenr_T i; | |
1653 buf_T *old_curbuf; | |
1654 linenr_T old_lnum; | |
1655 colnr_T screen_col; | |
1656 colnr_T char_col; | |
1657 char_u *line; | |
1658 #ifdef FEAT_WINDOWS | |
639 | 1659 char_u *old_swb = p_swb; |
1621 | 1660 unsigned old_swb_flags = swb_flags; |
7 | 1661 int opened_window = FALSE; |
1662 win_T *win; | |
1663 win_T *altwin; | |
1822 | 1664 int flags; |
7 | 1665 #endif |
1743 | 1666 win_T *oldwin = curwin; |
7 | 1667 int print_message = TRUE; |
1668 int len; | |
1669 #ifdef FEAT_FOLDING | |
1670 int old_KeyTyped = KeyTyped; /* getting file may reset it */ | |
1671 #endif | |
9 | 1672 int ok = OK; |
644 | 1673 int usable_win; |
1674 | |
659 | 1675 if (qi == NULL) |
1676 qi = &ql_info; | |
644 | 1677 |
1678 if (qi->qf_curlist >= qi->qf_listcount | |
1679 || qi->qf_lists[qi->qf_curlist].qf_count == 0) | |
7 | 1680 { |
1681 EMSG(_(e_quickfix)); | |
1682 return; | |
1683 } | |
1684 | |
644 | 1685 qf_ptr = qi->qf_lists[qi->qf_curlist].qf_ptr; |
7 | 1686 old_qf_ptr = qf_ptr; |
644 | 1687 qf_index = qi->qf_lists[qi->qf_curlist].qf_index; |
7 | 1688 old_qf_index = qf_index; |
1689 if (dir == FORWARD || dir == FORWARD_FILE) /* next valid entry */ | |
1690 { | |
1691 while (errornr--) | |
1692 { | |
1693 old_qf_ptr = qf_ptr; | |
1694 prev_index = qf_index; | |
1695 old_qf_fnum = qf_ptr->qf_fnum; | |
1696 do | |
1697 { | |
644 | 1698 if (qf_index == qi->qf_lists[qi->qf_curlist].qf_count |
7 | 1699 || qf_ptr->qf_next == NULL) |
1700 { | |
1701 qf_ptr = old_qf_ptr; | |
1702 qf_index = prev_index; | |
1703 if (err != NULL) | |
1704 { | |
1705 EMSG(_(err)); | |
1706 goto theend; | |
1707 } | |
1708 errornr = 0; | |
1709 break; | |
1710 } | |
1711 ++qf_index; | |
1712 qf_ptr = qf_ptr->qf_next; | |
644 | 1713 } while ((!qi->qf_lists[qi->qf_curlist].qf_nonevalid |
1714 && !qf_ptr->qf_valid) | |
7 | 1715 || (dir == FORWARD_FILE && qf_ptr->qf_fnum == old_qf_fnum)); |
1716 err = NULL; | |
1717 } | |
1718 } | |
1719 else if (dir == BACKWARD || dir == BACKWARD_FILE) /* prev. valid entry */ | |
1720 { | |
1721 while (errornr--) | |
1722 { | |
1723 old_qf_ptr = qf_ptr; | |
1724 prev_index = qf_index; | |
1725 old_qf_fnum = qf_ptr->qf_fnum; | |
1726 do | |
1727 { | |
1728 if (qf_index == 1 || qf_ptr->qf_prev == NULL) | |
1729 { | |
1730 qf_ptr = old_qf_ptr; | |
1731 qf_index = prev_index; | |
1732 if (err != NULL) | |
1733 { | |
1734 EMSG(_(err)); | |
1735 goto theend; | |
1736 } | |
1737 errornr = 0; | |
1738 break; | |
1739 } | |
1740 --qf_index; | |
1741 qf_ptr = qf_ptr->qf_prev; | |
644 | 1742 } while ((!qi->qf_lists[qi->qf_curlist].qf_nonevalid |
1743 && !qf_ptr->qf_valid) | |
7 | 1744 || (dir == BACKWARD_FILE && qf_ptr->qf_fnum == old_qf_fnum)); |
1745 err = NULL; | |
1746 } | |
1747 } | |
1748 else if (errornr != 0) /* go to specified number */ | |
1749 { | |
1750 while (errornr < qf_index && qf_index > 1 && qf_ptr->qf_prev != NULL) | |
1751 { | |
1752 --qf_index; | |
1753 qf_ptr = qf_ptr->qf_prev; | |
1754 } | |
644 | 1755 while (errornr > qf_index && qf_index < |
1756 qi->qf_lists[qi->qf_curlist].qf_count | |
7 | 1757 && qf_ptr->qf_next != NULL) |
1758 { | |
1759 ++qf_index; | |
1760 qf_ptr = qf_ptr->qf_next; | |
1761 } | |
1762 } | |
1763 | |
1764 #ifdef FEAT_WINDOWS | |
644 | 1765 qi->qf_lists[qi->qf_curlist].qf_index = qf_index; |
1766 if (qf_win_pos_update(qi, old_qf_index)) | |
7 | 1767 /* No need to print the error message if it's visible in the error |
1768 * window */ | |
1769 print_message = FALSE; | |
1770 | |
1771 /* | |
9 | 1772 * For ":helpgrep" find a help window or open one. |
1773 */ | |
682 | 1774 if (qf_ptr->qf_type == 1 && (!curwin->w_buffer->b_help || cmdmod.tab != 0)) |
9 | 1775 { |
1776 win_T *wp; | |
1777 | |
682 | 1778 if (cmdmod.tab != 0) |
1779 wp = NULL; | |
1780 else | |
1781 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
1782 if (wp->w_buffer != NULL && wp->w_buffer->b_help) | |
1783 break; | |
9 | 1784 if (wp != NULL && wp->w_buffer->b_nwindows > 0) |
1785 win_enter(wp, TRUE); | |
1786 else | |
1787 { | |
1788 /* | |
1789 * Split off help window; put it at far top if no position | |
1790 * specified, the current window is vertically split and narrow. | |
1791 */ | |
1822 | 1792 flags = WSP_HELP; |
9 | 1793 if (cmdmod.split == 0 && curwin->w_width != Columns |
1794 && curwin->w_width < 80) | |
1822 | 1795 flags |= WSP_TOP; |
1796 if (qi != &ql_info) | |
1797 flags |= WSP_NEWLOC; /* don't copy the location list */ | |
1798 | |
1799 if (win_split(0, flags) == FAIL) | |
9 | 1800 goto theend; |
26 | 1801 opened_window = TRUE; /* close it when fail */ |
9 | 1802 |
1803 if (curwin->w_height < p_hh) | |
1804 win_setheight((int)p_hh); | |
659 | 1805 |
1806 if (qi != &ql_info) /* not a quickfix list */ | |
1807 { | |
1808 /* The new window should use the supplied location list */ | |
1809 curwin->w_llist = qi; | |
1810 qi->qf_refcount++; | |
1811 } | |
9 | 1812 } |
1813 | |
1814 if (!p_im) | |
1815 restart_edit = 0; /* don't want insert mode in help file */ | |
1816 } | |
1817 | |
1818 /* | |
7 | 1819 * If currently in the quickfix window, find another window to show the |
1820 * file in. | |
1821 */ | |
26 | 1822 if (bt_quickfix(curbuf) && !opened_window) |
7 | 1823 { |
5062
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1824 win_T *usable_win_ptr = NULL; |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1825 |
7 | 1826 /* |
1827 * If there is no file specified, we don't know where to go. | |
1828 * But do advance, otherwise ":cn" gets stuck. | |
1829 */ | |
1830 if (qf_ptr->qf_fnum == 0) | |
1831 goto theend; | |
1832 | |
644 | 1833 usable_win = 0; |
5062
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1834 |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1835 ll_ref = curwin->w_llist_ref; |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1836 if (ll_ref != NULL) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1837 { |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1838 /* Find a window using the same location list that is not a |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1839 * quickfix window. */ |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1840 FOR_ALL_WINDOWS(usable_win_ptr) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1841 if (usable_win_ptr->w_llist == ll_ref |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1842 && usable_win_ptr->w_buffer->b_p_bt[0] != 'q') |
5084
14e7a115d54d
updated for version 7.3.1285
Bram Moolenaar <bram@vim.org>
parents:
5062
diff
changeset
|
1843 { |
14e7a115d54d
updated for version 7.3.1285
Bram Moolenaar <bram@vim.org>
parents:
5062
diff
changeset
|
1844 usable_win = 1; |
5062
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1845 break; |
5084
14e7a115d54d
updated for version 7.3.1285
Bram Moolenaar <bram@vim.org>
parents:
5062
diff
changeset
|
1846 } |
5062
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1847 } |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1848 |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1849 if (!usable_win) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1850 { |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1851 /* Locate a window showing a normal buffer */ |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1852 FOR_ALL_WINDOWS(win) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1853 if (win->w_buffer->b_p_bt[0] == NUL) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1854 { |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1855 usable_win = 1; |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1856 break; |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1857 } |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1858 } |
644 | 1859 |
7 | 1860 /* |
1621 | 1861 * If no usable window is found and 'switchbuf' contains "usetab" |
1020 | 1862 * then search in other tabs. |
7 | 1863 */ |
1621 | 1864 if (!usable_win && (swb_flags & SWB_USETAB)) |
1020 | 1865 { |
1866 tabpage_T *tp; | |
1867 win_T *wp; | |
1868 | |
1869 FOR_ALL_TAB_WINDOWS(tp, wp) | |
1870 { | |
1871 if (wp->w_buffer->b_fnum == qf_ptr->qf_fnum) | |
1872 { | |
1873 goto_tabpage_win(tp, wp); | |
1874 usable_win = 1; | |
1819 | 1875 goto win_found; |
1020 | 1876 } |
1877 } | |
1878 } | |
1819 | 1879 win_found: |
1020 | 1880 |
1881 /* | |
1396 | 1882 * If there is only one window and it is the quickfix window, create a |
1883 * new one above the quickfix window. | |
1020 | 1884 */ |
1885 if (((firstwin == lastwin) && bt_quickfix(curbuf)) || !usable_win) | |
7 | 1886 { |
1822 | 1887 flags = WSP_ABOVE; |
1888 if (ll_ref != NULL) | |
1889 flags |= WSP_NEWLOC; | |
1890 if (win_split(0, flags) == FAIL) | |
7 | 1891 goto failed; /* not enough room for window */ |
1892 opened_window = TRUE; /* close it when fail */ | |
1893 p_swb = empty_option; /* don't split again */ | |
1621 | 1894 swb_flags = 0; |
2583 | 1895 RESET_BINDING(curwin); |
644 | 1896 if (ll_ref != NULL) |
1897 { | |
1898 /* The new window should use the location list from the | |
1899 * location list window */ | |
1900 curwin->w_llist = ll_ref; | |
1901 ll_ref->qf_refcount++; | |
1902 } | |
7 | 1903 } |
1904 else | |
1905 { | |
644 | 1906 if (curwin->w_llist_ref != NULL) |
1907 { | |
1908 /* In a location window */ | |
5062
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1909 win = usable_win_ptr; |
644 | 1910 if (win == NULL) |
1911 { | |
1912 /* Find the window showing the selected file */ | |
1913 FOR_ALL_WINDOWS(win) | |
1914 if (win->w_buffer->b_fnum == qf_ptr->qf_fnum) | |
1915 break; | |
1916 if (win == NULL) | |
1917 { | |
1918 /* Find a previous usable window */ | |
1919 win = curwin; | |
1920 do | |
1921 { | |
1922 if (win->w_buffer->b_p_bt[0] == NUL) | |
1923 break; | |
1924 if (win->w_prev == NULL) | |
1925 win = lastwin; /* wrap around the top */ | |
1926 else | |
1927 win = win->w_prev; /* go to previous window */ | |
1928 } while (win != curwin); | |
1929 } | |
1930 } | |
1931 win_goto(win); | |
1932 | |
1933 /* If the location list for the window is not set, then set it | |
1934 * to the location list from the location window */ | |
1935 if (win->w_llist == NULL) | |
1936 { | |
1937 win->w_llist = ll_ref; | |
1938 ll_ref->qf_refcount++; | |
1939 } | |
1940 } | |
1941 else | |
1942 { | |
1943 | |
7 | 1944 /* |
1945 * Try to find a window that shows the right buffer. | |
1946 * Default to the window just above the quickfix buffer. | |
1947 */ | |
1948 win = curwin; | |
1949 altwin = NULL; | |
1950 for (;;) | |
1951 { | |
1952 if (win->w_buffer->b_fnum == qf_ptr->qf_fnum) | |
1953 break; | |
1954 if (win->w_prev == NULL) | |
1955 win = lastwin; /* wrap around the top */ | |
1956 else | |
1957 win = win->w_prev; /* go to previous window */ | |
1958 | |
644 | 1959 if (IS_QF_WINDOW(win)) |
7 | 1960 { |
1961 /* Didn't find it, go to the window before the quickfix | |
1962 * window. */ | |
1963 if (altwin != NULL) | |
1964 win = altwin; | |
1965 else if (curwin->w_prev != NULL) | |
1966 win = curwin->w_prev; | |
1967 else | |
1968 win = curwin->w_next; | |
1969 break; | |
1970 } | |
1971 | |
1972 /* Remember a usable window. */ | |
1973 if (altwin == NULL && !win->w_p_pvw | |
1974 && win->w_buffer->b_p_bt[0] == NUL) | |
1975 altwin = win; | |
1976 } | |
1977 | |
1978 win_goto(win); | |
644 | 1979 } |
7 | 1980 } |
1981 } | |
1982 #endif | |
1983 | |
1984 /* | |
1985 * If there is a file name, | |
1986 * read the wanted file if needed, and check autowrite etc. | |
1987 */ | |
1988 old_curbuf = curbuf; | |
1989 old_lnum = curwin->w_cursor.lnum; | |
9 | 1990 |
1991 if (qf_ptr->qf_fnum != 0) | |
1992 { | |
1993 if (qf_ptr->qf_type == 1) | |
1994 { | |
1995 /* Open help file (do_ecmd() will set b_help flag, readfile() will | |
1996 * set b_p_ro flag). */ | |
1997 if (!can_abandon(curbuf, forceit)) | |
1998 { | |
1999 EMSG(_(e_nowrtmsg)); | |
2000 ok = FALSE; | |
2001 } | |
2002 else | |
2003 ok = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1, | |
1743 | 2004 ECMD_HIDE + ECMD_SET_HELP, |
2005 oldwin == curwin ? curwin : NULL); | |
9 | 2006 } |
2007 else | |
8605
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2008 { |
8702
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2009 int old_qf_curlist = qi->qf_curlist; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2010 int is_abort = FALSE; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2011 |
9 | 2012 ok = buflist_getfile(qf_ptr->qf_fnum, |
2013 (linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit); | |
8605
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2014 if (qi != &ql_info && !win_valid(oldwin)) |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2015 { |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2016 EMSG(_("E924: Current window was closed")); |
8702
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2017 is_abort = TRUE; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2018 opened_window = FALSE; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2019 } |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2020 else if (old_qf_curlist != qi->qf_curlist |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2021 || !is_qf_entry_present(qi, qf_ptr)) |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2022 { |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2023 if (qi == &ql_info) |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2024 EMSG(_("E925: Current quickfix was changed")); |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2025 else |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2026 EMSG(_("E926: Current location list was changed")); |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2027 is_abort = TRUE; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2028 } |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2029 |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2030 if (is_abort) |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2031 { |
8605
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2032 ok = FALSE; |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2033 qi = NULL; |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2034 qf_ptr = NULL; |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2035 } |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2036 } |
9 | 2037 } |
2038 | |
2039 if (ok == OK) | |
7 | 2040 { |
2041 /* When not switched to another buffer, still need to set pc mark */ | |
2042 if (curbuf == old_curbuf) | |
2043 setpcmark(); | |
2044 | |
230 | 2045 if (qf_ptr->qf_pattern == NULL) |
7 | 2046 { |
230 | 2047 /* |
2048 * Go to line with error, unless qf_lnum is 0. | |
2049 */ | |
2050 i = qf_ptr->qf_lnum; | |
2051 if (i > 0) | |
2052 { | |
2053 if (i > curbuf->b_ml.ml_line_count) | |
2054 i = curbuf->b_ml.ml_line_count; | |
2055 curwin->w_cursor.lnum = i; | |
2056 } | |
2057 if (qf_ptr->qf_col > 0) | |
7 | 2058 { |
230 | 2059 curwin->w_cursor.col = qf_ptr->qf_col - 1; |
6853 | 2060 #ifdef FEAT_VIRTUALEDIT |
2061 curwin->w_cursor.coladd = 0; | |
2062 #endif | |
230 | 2063 if (qf_ptr->qf_viscol == TRUE) |
7 | 2064 { |
230 | 2065 /* |
2066 * Check each character from the beginning of the error | |
2067 * line up to the error column. For each tab character | |
2068 * found, reduce the error column value by the length of | |
2069 * a tab character. | |
2070 */ | |
2071 line = ml_get_curline(); | |
2072 screen_col = 0; | |
2073 for (char_col = 0; char_col < curwin->w_cursor.col; ++char_col) | |
7 | 2074 { |
230 | 2075 if (*line == NUL) |
2076 break; | |
2077 if (*line++ == '\t') | |
2078 { | |
2079 curwin->w_cursor.col -= 7 - (screen_col % 8); | |
2080 screen_col += 8 - (screen_col % 8); | |
2081 } | |
2082 else | |
2083 ++screen_col; | |
7 | 2084 } |
2085 } | |
230 | 2086 check_cursor(); |
7 | 2087 } |
230 | 2088 else |
2089 beginline(BL_WHITE | BL_FIX); | |
7 | 2090 } |
2091 else | |
230 | 2092 { |
2093 pos_T save_cursor; | |
2094 | |
2095 /* Move the cursor to the first line in the buffer */ | |
2096 save_cursor = curwin->w_cursor; | |
2097 curwin->w_cursor.lnum = 0; | |
1521 | 2098 if (!do_search(NULL, '/', qf_ptr->qf_pattern, (long)1, |
2099 SEARCH_KEEP, NULL)) | |
230 | 2100 curwin->w_cursor = save_cursor; |
2101 } | |
7 | 2102 |
2103 #ifdef FEAT_FOLDING | |
2104 if ((fdo_flags & FDO_QUICKFIX) && old_KeyTyped) | |
2105 foldOpenCursor(); | |
2106 #endif | |
2107 if (print_message) | |
2108 { | |
3267 | 2109 /* Update the screen before showing the message, unless the screen |
2110 * scrolled up. */ | |
2111 if (!msg_scrolled) | |
2112 update_topline_redraw(); | |
7 | 2113 sprintf((char *)IObuff, _("(%d of %d)%s%s: "), qf_index, |
644 | 2114 qi->qf_lists[qi->qf_curlist].qf_count, |
7 | 2115 qf_ptr->qf_cleared ? _(" (line deleted)") : "", |
2116 (char *)qf_types(qf_ptr->qf_type, qf_ptr->qf_nr)); | |
2117 /* Add the message, skipping leading whitespace and newlines. */ | |
2118 len = (int)STRLEN(IObuff); | |
2119 qf_fmt_text(skipwhite(qf_ptr->qf_text), IObuff + len, IOSIZE - len); | |
2120 | |
2121 /* Output the message. Overwrite to avoid scrolling when the 'O' | |
2122 * flag is present in 'shortmess'; But when not jumping, print the | |
2123 * whole message. */ | |
2124 i = msg_scroll; | |
2125 if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum) | |
2126 msg_scroll = TRUE; | |
2127 else if (!msg_scrolled && shortmess(SHM_OVERALL)) | |
2128 msg_scroll = FALSE; | |
2129 msg_attr_keep(IObuff, 0, TRUE); | |
2130 msg_scroll = i; | |
2131 } | |
2132 } | |
2133 else | |
2134 { | |
2135 #ifdef FEAT_WINDOWS | |
2136 if (opened_window) | |
2137 win_close(curwin, TRUE); /* Close opened window */ | |
2138 #endif | |
8605
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2139 if (qf_ptr != NULL && qf_ptr->qf_fnum != 0) |
7 | 2140 { |
2141 /* | |
2142 * Couldn't open file, so put index back where it was. This could | |
2143 * happen if the file was readonly and we changed something. | |
2144 */ | |
2145 #ifdef FEAT_WINDOWS | |
2146 failed: | |
2147 #endif | |
2148 qf_ptr = old_qf_ptr; | |
2149 qf_index = old_qf_index; | |
2150 } | |
2151 } | |
2152 theend: | |
8605
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2153 if (qi != NULL) |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2154 { |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2155 qi->qf_lists[qi->qf_curlist].qf_ptr = qf_ptr; |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2156 qi->qf_lists[qi->qf_curlist].qf_index = qf_index; |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2157 } |
7 | 2158 #ifdef FEAT_WINDOWS |
2159 if (p_swb != old_swb && opened_window) | |
2160 { | |
2161 /* Restore old 'switchbuf' value, but not when an autocommand or | |
2162 * modeline has changed the value. */ | |
2163 if (p_swb == empty_option) | |
1621 | 2164 { |
7 | 2165 p_swb = old_swb; |
1621 | 2166 swb_flags = old_swb_flags; |
2167 } | |
7 | 2168 else |
2169 free_string_option(old_swb); | |
2170 } | |
2171 #endif | |
2172 } | |
2173 | |
2174 /* | |
2175 * ":clist": list all errors | |
644 | 2176 * ":llist": list all locations |
7 | 2177 */ |
2178 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2179 qf_list(exarg_T *eap) |
7 | 2180 { |
230 | 2181 buf_T *buf; |
2182 char_u *fname; | |
2183 qfline_T *qfp; | |
2184 int i; | |
2185 int idx1 = 1; | |
2186 int idx2 = -1; | |
2187 char_u *arg = eap->arg; | |
2188 int all = eap->forceit; /* if not :cl!, only show | |
7 | 2189 recognised errors */ |
644 | 2190 qf_info_T *qi = &ql_info; |
2191 | |
2192 if (eap->cmdidx == CMD_llist) | |
2193 { | |
2194 qi = GET_LOC_LIST(curwin); | |
2195 if (qi == NULL) | |
2196 { | |
2197 EMSG(_(e_loclist)); | |
2198 return; | |
2199 } | |
2200 } | |
2201 | |
2202 if (qi->qf_curlist >= qi->qf_listcount | |
2203 || qi->qf_lists[qi->qf_curlist].qf_count == 0) | |
7 | 2204 { |
2205 EMSG(_(e_quickfix)); | |
2206 return; | |
2207 } | |
2208 if (!get_list_range(&arg, &idx1, &idx2) || *arg != NUL) | |
2209 { | |
2210 EMSG(_(e_trailing)); | |
2211 return; | |
2212 } | |
644 | 2213 i = qi->qf_lists[qi->qf_curlist].qf_count; |
7 | 2214 if (idx1 < 0) |
2215 idx1 = (-idx1 > i) ? 0 : idx1 + i + 1; | |
2216 if (idx2 < 0) | |
2217 idx2 = (-idx2 > i) ? 0 : idx2 + i + 1; | |
2218 | |
644 | 2219 if (qi->qf_lists[qi->qf_curlist].qf_nonevalid) |
7 | 2220 all = TRUE; |
644 | 2221 qfp = qi->qf_lists[qi->qf_curlist].qf_start; |
2222 for (i = 1; !got_int && i <= qi->qf_lists[qi->qf_curlist].qf_count; ) | |
7 | 2223 { |
2224 if ((qfp->qf_valid || all) && idx1 <= i && i <= idx2) | |
2225 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1918
diff
changeset
|
2226 msg_putchar('\n'); |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1918
diff
changeset
|
2227 if (got_int) |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1918
diff
changeset
|
2228 break; |
446 | 2229 |
2230 fname = NULL; | |
2231 if (qfp->qf_fnum != 0 | |
7 | 2232 && (buf = buflist_findnr(qfp->qf_fnum)) != NULL) |
446 | 2233 { |
2234 fname = buf->b_fname; | |
2235 if (qfp->qf_type == 1) /* :helpgrep */ | |
2236 fname = gettail(fname); | |
2237 } | |
2238 if (fname == NULL) | |
2239 sprintf((char *)IObuff, "%2d", i); | |
2240 else | |
2241 vim_snprintf((char *)IObuff, IOSIZE, "%2d %s", | |
273 | 2242 i, (char *)fname); |
644 | 2243 msg_outtrans_attr(IObuff, i == qi->qf_lists[qi->qf_curlist].qf_index |
446 | 2244 ? hl_attr(HLF_L) : hl_attr(HLF_D)); |
2245 if (qfp->qf_lnum == 0) | |
2246 IObuff[0] = NUL; | |
2247 else if (qfp->qf_col == 0) | |
2248 sprintf((char *)IObuff, ":%ld", qfp->qf_lnum); | |
2249 else | |
2250 sprintf((char *)IObuff, ":%ld col %d", | |
7 | 2251 qfp->qf_lnum, qfp->qf_col); |
446 | 2252 sprintf((char *)IObuff + STRLEN(IObuff), "%s:", |
7 | 2253 (char *)qf_types(qfp->qf_type, qfp->qf_nr)); |
446 | 2254 msg_puts_attr(IObuff, hl_attr(HLF_N)); |
2255 if (qfp->qf_pattern != NULL) | |
2256 { | |
2257 qf_fmt_text(qfp->qf_pattern, IObuff, IOSIZE); | |
2258 STRCAT(IObuff, ":"); | |
2259 msg_puts(IObuff); | |
2260 } | |
2261 msg_puts((char_u *)" "); | |
230 | 2262 |
446 | 2263 /* Remove newlines and leading whitespace from the text. For an |
2264 * unrecognized line keep the indent, the compiler may mark a word | |
2265 * with ^^^^. */ | |
2266 qf_fmt_text((fname != NULL || qfp->qf_lnum != 0) | |
7 | 2267 ? skipwhite(qfp->qf_text) : qfp->qf_text, |
2268 IObuff, IOSIZE); | |
446 | 2269 msg_prt_line(IObuff, FALSE); |
2270 out_flush(); /* show one line at a time */ | |
7 | 2271 } |
446 | 2272 |
2273 qfp = qfp->qf_next; | |
2274 ++i; | |
7 | 2275 ui_breakcheck(); |
2276 } | |
2277 } | |
2278 | |
2279 /* | |
2280 * Remove newlines and leading whitespace from an error message. | |
2281 * Put the result in "buf[bufsize]". | |
2282 */ | |
2283 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2284 qf_fmt_text(char_u *text, char_u *buf, int bufsize) |
7 | 2285 { |
2286 int i; | |
2287 char_u *p = text; | |
2288 | |
2289 for (i = 0; *p != NUL && i < bufsize - 1; ++i) | |
2290 { | |
2291 if (*p == '\n') | |
2292 { | |
2293 buf[i] = ' '; | |
2294 while (*++p != NUL) | |
2295 if (!vim_iswhite(*p) && *p != '\n') | |
2296 break; | |
2297 } | |
2298 else | |
2299 buf[i] = *p++; | |
2300 } | |
2301 buf[i] = NUL; | |
2302 } | |
2303 | |
2304 /* | |
2305 * ":colder [count]": Up in the quickfix stack. | |
2306 * ":cnewer [count]": Down in the quickfix stack. | |
644 | 2307 * ":lolder [count]": Up in the location list stack. |
2308 * ":lnewer [count]": Down in the location list stack. | |
7 | 2309 */ |
2310 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2311 qf_age(exarg_T *eap) |
7 | 2312 { |
644 | 2313 qf_info_T *qi = &ql_info; |
7 | 2314 int count; |
2315 | |
644 | 2316 if (eap->cmdidx == CMD_lolder || eap->cmdidx == CMD_lnewer) |
2317 { | |
2318 qi = GET_LOC_LIST(curwin); | |
2319 if (qi == NULL) | |
2320 { | |
2321 EMSG(_(e_loclist)); | |
2322 return; | |
2323 } | |
2324 } | |
2325 | |
7 | 2326 if (eap->addr_count != 0) |
2327 count = eap->line2; | |
2328 else | |
2329 count = 1; | |
2330 while (count--) | |
2331 { | |
644 | 2332 if (eap->cmdidx == CMD_colder || eap->cmdidx == CMD_lolder) |
7 | 2333 { |
644 | 2334 if (qi->qf_curlist == 0) |
7 | 2335 { |
2336 EMSG(_("E380: At bottom of quickfix stack")); | |
4371 | 2337 break; |
7 | 2338 } |
644 | 2339 --qi->qf_curlist; |
7 | 2340 } |
2341 else | |
2342 { | |
644 | 2343 if (qi->qf_curlist >= qi->qf_listcount - 1) |
7 | 2344 { |
2345 EMSG(_("E381: At top of quickfix stack")); | |
4371 | 2346 break; |
7 | 2347 } |
644 | 2348 ++qi->qf_curlist; |
7 | 2349 } |
2350 } | |
644 | 2351 qf_msg(qi); |
7 | 2352 } |
2353 | |
2354 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2355 qf_msg(qf_info_T *qi) |
7 | 2356 { |
2357 smsg((char_u *)_("error list %d of %d; %d errors"), | |
644 | 2358 qi->qf_curlist + 1, qi->qf_listcount, |
2359 qi->qf_lists[qi->qf_curlist].qf_count); | |
7 | 2360 #ifdef FEAT_WINDOWS |
8932
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
2361 qf_update_buffer(qi, TRUE); |
7 | 2362 #endif |
2363 } | |
2364 | |
2365 /* | |
581 | 2366 * Free error list "idx". |
7 | 2367 */ |
2368 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2369 qf_free(qf_info_T *qi, int idx) |
7 | 2370 { |
230 | 2371 qfline_T *qfp; |
3982 | 2372 int stop = FALSE; |
7 | 2373 |
644 | 2374 while (qi->qf_lists[idx].qf_count) |
7 | 2375 { |
644 | 2376 qfp = qi->qf_lists[idx].qf_start->qf_next; |
3982 | 2377 if (qi->qf_lists[idx].qf_title != NULL && !stop) |
3949 | 2378 { |
2379 vim_free(qi->qf_lists[idx].qf_start->qf_text); | |
3982 | 2380 stop = (qi->qf_lists[idx].qf_start == qfp); |
3949 | 2381 vim_free(qi->qf_lists[idx].qf_start->qf_pattern); |
2382 vim_free(qi->qf_lists[idx].qf_start); | |
3982 | 2383 if (stop) |
2384 /* Somehow qf_count may have an incorrect value, set it to 1 | |
2385 * to avoid crashing when it's wrong. | |
2386 * TODO: Avoid qf_count being incorrect. */ | |
2387 qi->qf_lists[idx].qf_count = 1; | |
3949 | 2388 } |
644 | 2389 qi->qf_lists[idx].qf_start = qfp; |
2390 --qi->qf_lists[idx].qf_count; | |
7 | 2391 } |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
2392 vim_free(qi->qf_lists[idx].qf_title); |
2576 | 2393 qi->qf_lists[idx].qf_title = NULL; |
6081 | 2394 qi->qf_lists[idx].qf_index = 0; |
7 | 2395 } |
2396 | |
2397 /* | |
2398 * qf_mark_adjust: adjust marks | |
2399 */ | |
2400 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2401 qf_mark_adjust( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2402 win_T *wp, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2403 linenr_T line1, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2404 linenr_T line2, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2405 long amount, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2406 long amount_after) |
7 | 2407 { |
230 | 2408 int i; |
2409 qfline_T *qfp; | |
2410 int idx; | |
644 | 2411 qf_info_T *qi = &ql_info; |
2412 | |
2413 if (wp != NULL) | |
2414 { | |
2415 if (wp->w_llist == NULL) | |
2416 return; | |
2417 qi = wp->w_llist; | |
2418 } | |
2419 | |
2420 for (idx = 0; idx < qi->qf_listcount; ++idx) | |
2421 if (qi->qf_lists[idx].qf_count) | |
2422 for (i = 0, qfp = qi->qf_lists[idx].qf_start; | |
2423 i < qi->qf_lists[idx].qf_count; ++i, qfp = qfp->qf_next) | |
7 | 2424 if (qfp->qf_fnum == curbuf->b_fnum) |
2425 { | |
2426 if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2) | |
2427 { | |
2428 if (amount == MAXLNUM) | |
2429 qfp->qf_cleared = TRUE; | |
2430 else | |
2431 qfp->qf_lnum += amount; | |
2432 } | |
2433 else if (amount_after && qfp->qf_lnum > line2) | |
2434 qfp->qf_lnum += amount_after; | |
2435 } | |
2436 } | |
2437 | |
2438 /* | |
2439 * Make a nice message out of the error character and the error number: | |
2440 * char number message | |
2441 * e or E 0 " error" | |
2442 * w or W 0 " warning" | |
2443 * i or I 0 " info" | |
2444 * 0 0 "" | |
2445 * other 0 " c" | |
2446 * e or E n " error n" | |
2447 * w or W n " warning n" | |
2448 * i or I n " info n" | |
2449 * 0 n " error n" | |
2450 * other n " c n" | |
2451 * 1 x "" :helpgrep | |
2452 */ | |
2453 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2454 qf_types(int c, int nr) |
7 | 2455 { |
2456 static char_u buf[20]; | |
2457 static char_u cc[3]; | |
2458 char_u *p; | |
2459 | |
2460 if (c == 'W' || c == 'w') | |
2461 p = (char_u *)" warning"; | |
2462 else if (c == 'I' || c == 'i') | |
2463 p = (char_u *)" info"; | |
2464 else if (c == 'E' || c == 'e' || (c == 0 && nr > 0)) | |
2465 p = (char_u *)" error"; | |
2466 else if (c == 0 || c == 1) | |
2467 p = (char_u *)""; | |
2468 else | |
2469 { | |
2470 cc[0] = ' '; | |
2471 cc[1] = c; | |
2472 cc[2] = NUL; | |
2473 p = cc; | |
2474 } | |
2475 | |
2476 if (nr <= 0) | |
2477 return p; | |
2478 | |
2479 sprintf((char *)buf, "%s %3d", (char *)p, nr); | |
2480 return buf; | |
2481 } | |
2482 | |
2483 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
2484 /* | |
2485 * ":cwindow": open the quickfix window if we have errors to display, | |
2486 * close it if not. | |
644 | 2487 * ":lwindow": open the location list window if we have locations to display, |
2488 * close it if not. | |
7 | 2489 */ |
2490 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2491 ex_cwindow(exarg_T *eap) |
7 | 2492 { |
644 | 2493 qf_info_T *qi = &ql_info; |
7 | 2494 win_T *win; |
2495 | |
644 | 2496 if (eap->cmdidx == CMD_lwindow) |
2497 { | |
2498 qi = GET_LOC_LIST(curwin); | |
2499 if (qi == NULL) | |
2500 return; | |
2501 } | |
2502 | |
2503 /* Look for an existing quickfix window. */ | |
2504 win = qf_find_win(qi); | |
7 | 2505 |
2506 /* | |
2507 * If a quickfix window is open but we have no errors to display, | |
2508 * close the window. If a quickfix window is not open, then open | |
2509 * it if we have errors; otherwise, leave it closed. | |
2510 */ | |
644 | 2511 if (qi->qf_lists[qi->qf_curlist].qf_nonevalid |
2795 | 2512 || qi->qf_lists[qi->qf_curlist].qf_count == 0 |
857 | 2513 || qi->qf_curlist >= qi->qf_listcount) |
7 | 2514 { |
2515 if (win != NULL) | |
2516 ex_cclose(eap); | |
2517 } | |
2518 else if (win == NULL) | |
2519 ex_copen(eap); | |
2520 } | |
2521 | |
2522 /* | |
2523 * ":cclose": close the window showing the list of errors. | |
644 | 2524 * ":lclose": close the window showing the location list |
7 | 2525 */ |
2526 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2527 ex_cclose(exarg_T *eap) |
7 | 2528 { |
644 | 2529 win_T *win = NULL; |
2530 qf_info_T *qi = &ql_info; | |
2531 | |
2532 if (eap->cmdidx == CMD_lclose || eap->cmdidx == CMD_lwindow) | |
2533 { | |
2534 qi = GET_LOC_LIST(curwin); | |
2535 if (qi == NULL) | |
2536 return; | |
2537 } | |
2538 | |
2539 /* Find existing quickfix window and close it. */ | |
2540 win = qf_find_win(qi); | |
7 | 2541 if (win != NULL) |
2542 win_close(win, FALSE); | |
2543 } | |
2544 | |
2545 /* | |
2546 * ":copen": open a window that shows the list of errors. | |
644 | 2547 * ":lopen": open a window that shows the location list. |
7 | 2548 */ |
2549 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2550 ex_copen(exarg_T *eap) |
7 | 2551 { |
644 | 2552 qf_info_T *qi = &ql_info; |
7 | 2553 int height; |
2554 win_T *win; | |
682 | 2555 tabpage_T *prevtab = curtab; |
859 | 2556 buf_T *qf_buf; |
1743 | 2557 win_T *oldwin = curwin; |
7 | 2558 |
644 | 2559 if (eap->cmdidx == CMD_lopen || eap->cmdidx == CMD_lwindow) |
2560 { | |
2561 qi = GET_LOC_LIST(curwin); | |
2562 if (qi == NULL) | |
2563 { | |
2564 EMSG(_(e_loclist)); | |
2565 return; | |
2566 } | |
2567 } | |
2568 | |
7 | 2569 if (eap->addr_count != 0) |
2570 height = eap->line2; | |
2571 else | |
2572 height = QF_WINHEIGHT; | |
2573 | |
2574 reset_VIsual_and_resel(); /* stop Visual mode */ | |
2575 #ifdef FEAT_GUI | |
2576 need_mouse_correct = TRUE; | |
2577 #endif | |
2578 | |
2579 /* | |
2580 * Find existing quickfix window, or open a new one. | |
2581 */ | |
644 | 2582 win = qf_find_win(qi); |
2583 | |
682 | 2584 if (win != NULL && cmdmod.tab == 0) |
5753 | 2585 { |
7 | 2586 win_goto(win); |
5753 | 2587 if (eap->addr_count != 0) |
2588 { | |
2589 if (cmdmod.split & WSP_VERT) | |
2590 { | |
2591 if (height != W_WIDTH(win)) | |
2592 win_setwidth(height); | |
2593 } | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8605
diff
changeset
|
2594 else if (height != win->w_height) |
5753 | 2595 win_setheight(height); |
2596 } | |
2597 } | |
7 | 2598 else |
2599 { | |
859 | 2600 qf_buf = qf_find_buf(qi); |
2601 | |
7 | 2602 /* The current window becomes the previous window afterwards. */ |
2603 win = curwin; | |
2604 | |
3939 | 2605 if ((eap->cmdidx == CMD_copen || eap->cmdidx == CMD_cwindow) |
2606 && cmdmod.split == 0) | |
2607 /* Create the new window at the very bottom, except when | |
2608 * :belowright or :aboveleft is used. */ | |
644 | 2609 win_goto(lastwin); |
1822 | 2610 if (win_split(height, WSP_BELOW | WSP_NEWLOC) == FAIL) |
7 | 2611 return; /* not enough room for window */ |
2583 | 2612 RESET_BINDING(curwin); |
7 | 2613 |
644 | 2614 if (eap->cmdidx == CMD_lopen || eap->cmdidx == CMD_lwindow) |
7 | 2615 { |
644 | 2616 /* |
2617 * For the location list window, create a reference to the | |
2618 * location list from the window 'win'. | |
2619 */ | |
2620 curwin->w_llist_ref = win->w_llist; | |
2621 win->w_llist->qf_refcount++; | |
7 | 2622 } |
644 | 2623 |
1743 | 2624 if (oldwin != curwin) |
2625 oldwin = NULL; /* don't store info when in another window */ | |
859 | 2626 if (qf_buf != NULL) |
2627 /* Use the existing quickfix buffer */ | |
2628 (void)do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE, | |
1743 | 2629 ECMD_HIDE + ECMD_OLDBUF, oldwin); |
859 | 2630 else |
2631 { | |
2632 /* Create a new quickfix buffer */ | |
1743 | 2633 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin); |
859 | 2634 /* switch off 'swapfile' */ |
2635 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); | |
2636 set_option_value((char_u *)"bt", 0L, (char_u *)"quickfix", | |
729 | 2637 OPT_LOCAL); |
859 | 2638 set_option_value((char_u *)"bh", 0L, (char_u *)"wipe", OPT_LOCAL); |
2651 | 2639 RESET_BINDING(curwin); |
1864 | 2640 #ifdef FEAT_DIFF |
2641 curwin->w_p_diff = FALSE; | |
2642 #endif | |
2643 #ifdef FEAT_FOLDING | |
2644 set_option_value((char_u *)"fdm", 0L, (char_u *)"manual", | |
2645 OPT_LOCAL); | |
2646 #endif | |
859 | 2647 } |
7 | 2648 |
682 | 2649 /* Only set the height when still in the same tab page and there is no |
2650 * window to the side. */ | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8605
diff
changeset
|
2651 if (curtab == prevtab && curwin->w_width == Columns) |
7 | 2652 win_setheight(height); |
2653 curwin->w_p_wfh = TRUE; /* set 'winfixheight' */ | |
2654 if (win_valid(win)) | |
2655 prevwin = win; | |
2656 } | |
2657 | |
6793 | 2658 qf_set_title_var(qi); |
2659 | |
7 | 2660 /* |
2661 * Fill the buffer with the quickfix list. | |
2662 */ | |
644 | 2663 qf_fill_buffer(qi); |
2664 | |
2665 curwin->w_cursor.lnum = qi->qf_lists[qi->qf_curlist].qf_index; | |
7 | 2666 curwin->w_cursor.col = 0; |
2667 check_cursor(); | |
2668 update_topline(); /* scroll to show the line */ | |
2669 } | |
2670 | |
2671 /* | |
2672 * Return the number of the current entry (line number in the quickfix | |
2673 * window). | |
2674 */ | |
2675 linenr_T | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2676 qf_current_entry(win_T *wp) |
7 | 2677 { |
644 | 2678 qf_info_T *qi = &ql_info; |
2679 | |
2680 if (IS_LL_WINDOW(wp)) | |
2681 /* In the location list window, use the referenced location list */ | |
2682 qi = wp->w_llist_ref; | |
2683 | |
2684 return qi->qf_lists[qi->qf_curlist].qf_index; | |
7 | 2685 } |
2686 | |
2687 /* | |
2688 * Update the cursor position in the quickfix window to the current error. | |
2689 * Return TRUE if there is a quickfix window. | |
2690 */ | |
2691 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2692 qf_win_pos_update( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2693 qf_info_T *qi, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2694 int old_qf_index) /* previous qf_index or zero */ |
7 | 2695 { |
2696 win_T *win; | |
644 | 2697 int qf_index = qi->qf_lists[qi->qf_curlist].qf_index; |
7 | 2698 |
2699 /* | |
2700 * Put the cursor on the current error in the quickfix window, so that | |
2701 * it's viewable. | |
2702 */ | |
644 | 2703 win = qf_find_win(qi); |
7 | 2704 if (win != NULL |
2705 && qf_index <= win->w_buffer->b_ml.ml_line_count | |
2706 && old_qf_index != qf_index) | |
2707 { | |
2708 win_T *old_curwin = curwin; | |
2709 | |
2710 curwin = win; | |
2711 curbuf = win->w_buffer; | |
2712 if (qf_index > old_qf_index) | |
2713 { | |
2714 curwin->w_redraw_top = old_qf_index; | |
2715 curwin->w_redraw_bot = qf_index; | |
2716 } | |
2717 else | |
2718 { | |
2719 curwin->w_redraw_top = qf_index; | |
2720 curwin->w_redraw_bot = old_qf_index; | |
2721 } | |
2722 curwin->w_cursor.lnum = qf_index; | |
2723 curwin->w_cursor.col = 0; | |
2724 update_topline(); /* scroll to show the line */ | |
2725 redraw_later(VALID); | |
2726 curwin->w_redr_status = TRUE; /* update ruler */ | |
2727 curwin = old_curwin; | |
2728 curbuf = curwin->w_buffer; | |
2729 } | |
2730 return win != NULL; | |
2731 } | |
2732 | |
2733 /* | |
859 | 2734 * Check whether the given window is displaying the specified quickfix/location |
2735 * list buffer | |
2736 */ | |
2737 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2738 is_qf_win(win_T *win, qf_info_T *qi) |
859 | 2739 { |
2740 /* | |
2741 * A window displaying the quickfix buffer will have the w_llist_ref field | |
2742 * set to NULL. | |
2743 * A window displaying a location list buffer will have the w_llist_ref | |
2744 * pointing to the location list. | |
2745 */ | |
2746 if (bt_quickfix(win->w_buffer)) | |
2747 if ((qi == &ql_info && win->w_llist_ref == NULL) | |
2748 || (qi != &ql_info && win->w_llist_ref == qi)) | |
2749 return TRUE; | |
2750 | |
2751 return FALSE; | |
2752 } | |
2753 | |
2754 /* | |
644 | 2755 * Find a window displaying the quickfix/location list 'qi' |
859 | 2756 * Searches in only the windows opened in the current tab. |
644 | 2757 */ |
2758 static win_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2759 qf_find_win(qf_info_T *qi) |
644 | 2760 { |
2761 win_T *win; | |
2762 | |
2763 FOR_ALL_WINDOWS(win) | |
859 | 2764 if (is_qf_win(win, qi)) |
2765 break; | |
644 | 2766 |
2767 return win; | |
2768 } | |
2769 | |
2770 /* | |
859 | 2771 * Find a quickfix buffer. |
2772 * Searches in windows opened in all the tabs. | |
7 | 2773 */ |
2774 static buf_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2775 qf_find_buf(qf_info_T *qi) |
7 | 2776 { |
859 | 2777 tabpage_T *tp; |
644 | 2778 win_T *win; |
2779 | |
859 | 2780 FOR_ALL_TAB_WINDOWS(tp, win) |
2781 if (is_qf_win(win, qi)) | |
2782 return win->w_buffer; | |
2783 | |
2784 return NULL; | |
7 | 2785 } |
2786 | |
2787 /* | |
2788 * Find the quickfix buffer. If it exists, update the contents. | |
2789 */ | |
2790 static void | |
8932
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
2791 qf_update_buffer(qf_info_T *qi, int update_cursor) |
7 | 2792 { |
2793 buf_T *buf; | |
3016 | 2794 win_T *win; |
2795 win_T *curwin_save; | |
7 | 2796 aco_save_T aco; |
2797 | |
2798 /* Check if a buffer for the quickfix list exists. Update it. */ | |
644 | 2799 buf = qf_find_buf(qi); |
7 | 2800 if (buf != NULL) |
2801 { | |
2802 /* set curwin/curbuf to buf and save a few things */ | |
2803 aucmd_prepbuf(&aco, buf); | |
2804 | |
6793 | 2805 if ((win = qf_find_win(qi)) != NULL) |
3016 | 2806 { |
2807 curwin_save = curwin; | |
2808 curwin = win; | |
6079 | 2809 qf_set_title_var(qi); |
3016 | 2810 curwin = curwin_save; |
2811 } | |
2812 | |
7710
bf58e9f8d52a
commit https://github.com/vim/vim/commit/6920c72d4d62c8dc5596e9f392e38204f561d7af
Christian Brabandt <cb@256bit.org>
parents:
7701
diff
changeset
|
2813 qf_fill_buffer(qi); |
bf58e9f8d52a
commit https://github.com/vim/vim/commit/6920c72d4d62c8dc5596e9f392e38204f561d7af
Christian Brabandt <cb@256bit.org>
parents:
7701
diff
changeset
|
2814 |
7 | 2815 /* restore curwin/curbuf and a few other things */ |
2816 aucmd_restbuf(&aco); | |
2817 | |
8932
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
2818 if (update_cursor) |
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
2819 (void)qf_win_pos_update(qi, 0); |
7 | 2820 } |
2821 } | |
2822 | |
6793 | 2823 /* |
2824 * Set "w:quickfix_title" if "qi" has a title. | |
2825 */ | |
3016 | 2826 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2827 qf_set_title_var(qf_info_T *qi) |
3016 | 2828 { |
6793 | 2829 if (qi->qf_lists[qi->qf_curlist].qf_title != NULL) |
2830 set_internal_string_var((char_u *)"w:quickfix_title", | |
3016 | 2831 qi->qf_lists[qi->qf_curlist].qf_title); |
2832 } | |
2833 | |
7 | 2834 /* |
2835 * Fill current buffer with quickfix errors, replacing any previous contents. | |
2836 * curbuf must be the quickfix buffer! | |
2837 */ | |
2838 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2839 qf_fill_buffer(qf_info_T *qi) |
7 | 2840 { |
230 | 2841 linenr_T lnum; |
2842 qfline_T *qfp; | |
2843 buf_T *errbuf; | |
2844 int len; | |
2845 int old_KeyTyped = KeyTyped; | |
7 | 2846 |
2847 /* delete all existing lines */ | |
2848 while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0) | |
2849 (void)ml_delete((linenr_T)1, FALSE); | |
2850 | |
2851 /* Check if there is anything to display */ | |
644 | 2852 if (qi->qf_curlist < qi->qf_listcount) |
7 | 2853 { |
2854 /* Add one line for each error */ | |
644 | 2855 qfp = qi->qf_lists[qi->qf_curlist].qf_start; |
2856 for (lnum = 0; lnum < qi->qf_lists[qi->qf_curlist].qf_count; ++lnum) | |
7 | 2857 { |
2858 if (qfp->qf_fnum != 0 | |
2859 && (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL | |
2860 && errbuf->b_fname != NULL) | |
2861 { | |
2862 if (qfp->qf_type == 1) /* :helpgrep */ | |
2863 STRCPY(IObuff, gettail(errbuf->b_fname)); | |
2864 else | |
2865 STRCPY(IObuff, errbuf->b_fname); | |
2866 len = (int)STRLEN(IObuff); | |
2867 } | |
2868 else | |
2869 len = 0; | |
2870 IObuff[len++] = '|'; | |
2871 | |
2872 if (qfp->qf_lnum > 0) | |
2873 { | |
2874 sprintf((char *)IObuff + len, "%ld", qfp->qf_lnum); | |
2875 len += (int)STRLEN(IObuff + len); | |
2876 | |
2877 if (qfp->qf_col > 0) | |
2878 { | |
2879 sprintf((char *)IObuff + len, " col %d", qfp->qf_col); | |
2880 len += (int)STRLEN(IObuff + len); | |
2881 } | |
2882 | |
2883 sprintf((char *)IObuff + len, "%s", | |
2884 (char *)qf_types(qfp->qf_type, qfp->qf_nr)); | |
2885 len += (int)STRLEN(IObuff + len); | |
2886 } | |
230 | 2887 else if (qfp->qf_pattern != NULL) |
2888 { | |
2889 qf_fmt_text(qfp->qf_pattern, IObuff + len, IOSIZE - len); | |
2890 len += (int)STRLEN(IObuff + len); | |
2891 } | |
7 | 2892 IObuff[len++] = '|'; |
2893 IObuff[len++] = ' '; | |
2894 | |
2895 /* Remove newlines and leading whitespace from the text. | |
2896 * For an unrecognized line keep the indent, the compiler may | |
2897 * mark a word with ^^^^. */ | |
2898 qf_fmt_text(len > 3 ? skipwhite(qfp->qf_text) : qfp->qf_text, | |
2899 IObuff + len, IOSIZE - len); | |
2900 | |
2901 if (ml_append(lnum, IObuff, (colnr_T)STRLEN(IObuff) + 1, FALSE) | |
2902 == FAIL) | |
2903 break; | |
2904 qfp = qfp->qf_next; | |
2905 } | |
2906 /* Delete the empty line which is now at the end */ | |
2907 (void)ml_delete(lnum + 1, FALSE); | |
2908 } | |
2909 | |
2910 /* correct cursor position */ | |
2911 check_lnums(TRUE); | |
2912 | |
2913 /* Set the 'filetype' to "qf" each time after filling the buffer. This | |
2914 * resembles reading a file into a buffer, it's more logical when using | |
2915 * autocommands. */ | |
2916 set_option_value((char_u *)"ft", 0L, (char_u *)"qf", OPT_LOCAL); | |
2917 curbuf->b_p_ma = FALSE; | |
2918 | |
2919 #ifdef FEAT_AUTOCMD | |
1864 | 2920 keep_filetype = TRUE; /* don't detect 'filetype' */ |
7 | 2921 apply_autocmds(EVENT_BUFREADPOST, (char_u *)"quickfix", NULL, |
2922 FALSE, curbuf); | |
2923 apply_autocmds(EVENT_BUFWINENTER, (char_u *)"quickfix", NULL, | |
2924 FALSE, curbuf); | |
1864 | 2925 keep_filetype = FALSE; |
7 | 2926 #endif |
2927 | |
2928 /* make sure it will be redrawn */ | |
2929 redraw_curbuf_later(NOT_VALID); | |
2930 | |
2931 /* Restore KeyTyped, setting 'filetype' may reset it. */ | |
2932 KeyTyped = old_KeyTyped; | |
2933 } | |
2934 | |
2935 #endif /* FEAT_WINDOWS */ | |
2936 | |
2937 /* | |
2938 * Return TRUE if "buf" is the quickfix buffer. | |
2939 */ | |
2940 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2941 bt_quickfix(buf_T *buf) |
7 | 2942 { |
3242 | 2943 return buf != NULL && buf->b_p_bt[0] == 'q'; |
7 | 2944 } |
2945 | |
2946 /* | |
17 | 2947 * Return TRUE if "buf" is a "nofile" or "acwrite" buffer. |
2948 * This means the buffer name is not a file name. | |
7 | 2949 */ |
2950 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2951 bt_nofile(buf_T *buf) |
7 | 2952 { |
3242 | 2953 return buf != NULL && ((buf->b_p_bt[0] == 'n' && buf->b_p_bt[2] == 'f') |
2954 || buf->b_p_bt[0] == 'a'); | |
7 | 2955 } |
2956 | |
2957 /* | |
2958 * Return TRUE if "buf" is a "nowrite" or "nofile" buffer. | |
2959 */ | |
2960 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2961 bt_dontwrite(buf_T *buf) |
7 | 2962 { |
3242 | 2963 return buf != NULL && buf->b_p_bt[0] == 'n'; |
7 | 2964 } |
2965 | |
2966 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2967 bt_dontwrite_msg(buf_T *buf) |
7 | 2968 { |
2969 if (bt_dontwrite(buf)) | |
2970 { | |
2971 EMSG(_("E382: Cannot write, 'buftype' option is set")); | |
2972 return TRUE; | |
2973 } | |
2974 return FALSE; | |
2975 } | |
2976 | |
2977 /* | |
2978 * Return TRUE if the buffer should be hidden, according to 'hidden', ":hide" | |
2979 * and 'bufhidden'. | |
2980 */ | |
2981 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2982 buf_hide(buf_T *buf) |
7 | 2983 { |
2984 /* 'bufhidden' overrules 'hidden' and ":hide", check it first */ | |
2985 switch (buf->b_p_bh[0]) | |
2986 { | |
2987 case 'u': /* "unload" */ | |
2988 case 'w': /* "wipe" */ | |
2989 case 'd': return FALSE; /* "delete" */ | |
2990 case 'h': return TRUE; /* "hide" */ | |
2991 } | |
2992 return (p_hid || cmdmod.hide); | |
2993 } | |
2994 | |
2995 /* | |
41 | 2996 * Return TRUE when using ":vimgrep" for ":grep". |
2997 */ | |
2998 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2999 grep_internal(cmdidx_T cmdidx) |
41 | 3000 { |
661 | 3001 return ((cmdidx == CMD_grep |
3002 || cmdidx == CMD_lgrep | |
3003 || cmdidx == CMD_grepadd | |
3004 || cmdidx == CMD_lgrepadd) | |
41 | 3005 && STRCMP("internal", |
3006 *curbuf->b_p_gp == NUL ? p_gp : curbuf->b_p_gp) == 0); | |
3007 } | |
3008 | |
3009 /* | |
657 | 3010 * Used for ":make", ":lmake", ":grep", ":lgrep", ":grepadd", and ":lgrepadd" |
7 | 3011 */ |
3012 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3013 ex_make(exarg_T *eap) |
7 | 3014 { |
161 | 3015 char_u *fname; |
7 | 3016 char_u *cmd; |
3017 unsigned len; | |
657 | 3018 win_T *wp = NULL; |
659 | 3019 qf_info_T *qi = &ql_info; |
842 | 3020 int res; |
161 | 3021 #ifdef FEAT_AUTOCMD |
3022 char_u *au_name = NULL; | |
3023 | |
2782 | 3024 /* Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". */ |
3025 if (grep_internal(eap->cmdidx)) | |
3026 { | |
3027 ex_vimgrep(eap); | |
3028 return; | |
3029 } | |
3030 | |
161 | 3031 switch (eap->cmdidx) |
3032 { | |
661 | 3033 case CMD_make: au_name = (char_u *)"make"; break; |
3034 case CMD_lmake: au_name = (char_u *)"lmake"; break; | |
3035 case CMD_grep: au_name = (char_u *)"grep"; break; | |
3036 case CMD_lgrep: au_name = (char_u *)"lgrep"; break; | |
3037 case CMD_grepadd: au_name = (char_u *)"grepadd"; break; | |
3038 case CMD_lgrepadd: au_name = (char_u *)"lgrepadd"; break; | |
161 | 3039 default: break; |
3040 } | |
3041 if (au_name != NULL) | |
3042 { | |
3043 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, | |
3044 curbuf->b_fname, TRUE, curbuf); | |
532 | 3045 # ifdef FEAT_EVAL |
161 | 3046 if (did_throw || force_abort) |
3047 return; | |
532 | 3048 # endif |
161 | 3049 } |
3050 #endif | |
7 | 3051 |
657 | 3052 if (eap->cmdidx == CMD_lmake || eap->cmdidx == CMD_lgrep |
3053 || eap->cmdidx == CMD_lgrepadd) | |
3054 wp = curwin; | |
3055 | |
7 | 3056 autowrite_all(); |
161 | 3057 fname = get_mef_name(); |
3058 if (fname == NULL) | |
7 | 3059 return; |
161 | 3060 mch_remove(fname); /* in case it's not unique */ |
7 | 3061 |
3062 /* | |
3063 * If 'shellpipe' empty: don't redirect to 'errorfile'. | |
3064 */ | |
3065 len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(eap->arg) + 1; | |
3066 if (*p_sp != NUL) | |
161 | 3067 len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3; |
7 | 3068 cmd = alloc(len); |
3069 if (cmd == NULL) | |
3070 return; | |
3071 sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg, | |
3072 (char *)p_shq); | |
3073 if (*p_sp != NUL) | |
1872 | 3074 append_redir(cmd, len, p_sp, fname); |
7 | 3075 /* |
3076 * Output a newline if there's something else than the :make command that | |
3077 * was typed (in which case the cursor is in column 0). | |
3078 */ | |
3079 if (msg_col == 0) | |
3080 msg_didout = FALSE; | |
3081 msg_start(); | |
3082 MSG_PUTS(":!"); | |
3083 msg_outtrans(cmd); /* show what we are doing */ | |
3084 | |
3085 /* let the shell know if we are redirecting output or not */ | |
3086 do_shell(cmd, *p_sp != NUL ? SHELL_DOOUT : 0); | |
3087 | |
3088 #ifdef AMIGA | |
3089 out_flush(); | |
3090 /* read window status report and redraw before message */ | |
3091 (void)char_avail(); | |
3092 #endif | |
3093 | |
842 | 3094 res = qf_init(wp, fname, (eap->cmdidx != CMD_make |
657 | 3095 && eap->cmdidx != CMD_lmake) ? p_gefm : p_efm, |
3096 (eap->cmdidx != CMD_grepadd | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3097 && eap->cmdidx != CMD_lgrepadd), |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3098 *eap->cmdlinep); |
2847 | 3099 if (wp != NULL) |
3100 qi = GET_LOC_LIST(wp); | |
842 | 3101 #ifdef FEAT_AUTOCMD |
3102 if (au_name != NULL) | |
2847 | 3103 { |
842 | 3104 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, |
3105 curbuf->b_fname, TRUE, curbuf); | |
2847 | 3106 if (qi->qf_curlist < qi->qf_listcount) |
3107 res = qi->qf_lists[qi->qf_curlist].qf_count; | |
3108 else | |
3109 res = 0; | |
3110 } | |
842 | 3111 #endif |
3112 if (res > 0 && !eap->forceit) | |
659 | 3113 qf_jump(qi, 0, 0, FALSE); /* display first error */ |
7 | 3114 |
161 | 3115 mch_remove(fname); |
3116 vim_free(fname); | |
7 | 3117 vim_free(cmd); |
3118 } | |
3119 | |
3120 /* | |
3121 * Return the name for the errorfile, in allocated memory. | |
3122 * Find a new unique name when 'makeef' contains "##". | |
3123 * Returns NULL for error. | |
3124 */ | |
3125 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3126 get_mef_name(void) |
7 | 3127 { |
3128 char_u *p; | |
3129 char_u *name; | |
3130 static int start = -1; | |
3131 static int off = 0; | |
3132 #ifdef HAVE_LSTAT | |
3133 struct stat sb; | |
3134 #endif | |
3135 | |
3136 if (*p_mef == NUL) | |
3137 { | |
6721 | 3138 name = vim_tempname('e', FALSE); |
7 | 3139 if (name == NULL) |
3140 EMSG(_(e_notmp)); | |
3141 return name; | |
3142 } | |
3143 | |
3144 for (p = p_mef; *p; ++p) | |
3145 if (p[0] == '#' && p[1] == '#') | |
3146 break; | |
3147 | |
3148 if (*p == NUL) | |
3149 return vim_strsave(p_mef); | |
3150 | |
3151 /* Keep trying until the name doesn't exist yet. */ | |
3152 for (;;) | |
3153 { | |
3154 if (start == -1) | |
3155 start = mch_get_pid(); | |
3156 else | |
3157 off += 19; | |
3158 | |
3159 name = alloc((unsigned)STRLEN(p_mef) + 30); | |
3160 if (name == NULL) | |
3161 break; | |
3162 STRCPY(name, p_mef); | |
3163 sprintf((char *)name + (p - p_mef), "%d%d", start, off); | |
3164 STRCAT(name, p + 2); | |
3165 if (mch_getperm(name) < 0 | |
3166 #ifdef HAVE_LSTAT | |
3167 /* Don't accept a symbolic link, its a security risk. */ | |
3168 && mch_lstat((char *)name, &sb) < 0 | |
3169 #endif | |
3170 ) | |
3171 break; | |
3172 vim_free(name); | |
3173 } | |
3174 return name; | |
3175 } | |
3176 | |
3177 /* | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3178 * Returns the number of valid entries in the current quickfix/location list. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3179 */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3180 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3181 qf_get_size(exarg_T *eap) |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3182 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3183 qf_info_T *qi = &ql_info; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3184 qfline_T *qfp; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3185 int i, sz = 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3186 int prev_fnum = 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3187 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3188 if (eap->cmdidx == CMD_ldo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3189 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3190 /* Location list */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3191 qi = GET_LOC_LIST(curwin); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3192 if (qi == NULL) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3193 return 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3194 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3195 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3196 for (i = 0, qfp = qi->qf_lists[qi->qf_curlist].qf_start; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3197 (i < qi->qf_lists[qi->qf_curlist].qf_count) && (qfp != NULL); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3198 ++i, qfp = qfp->qf_next) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3199 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3200 if (qfp->qf_valid) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3201 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3202 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3203 sz++; /* Count all valid entries */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3204 else if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3205 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3206 /* Count the number of files */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3207 sz++; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3208 prev_fnum = qfp->qf_fnum; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3209 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3210 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3211 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3212 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3213 return sz; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3214 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3215 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3216 /* |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3217 * Returns the current index of the quickfix/location list. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3218 * Returns 0 if there is an error. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3219 */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3220 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3221 qf_get_cur_idx(exarg_T *eap) |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3222 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3223 qf_info_T *qi = &ql_info; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3224 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3225 if (eap->cmdidx == CMD_ldo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3226 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3227 /* Location list */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3228 qi = GET_LOC_LIST(curwin); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3229 if (qi == NULL) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3230 return 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3231 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3232 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3233 return qi->qf_lists[qi->qf_curlist].qf_index; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3234 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3235 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3236 /* |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3237 * Returns the current index in the quickfix/location list (counting only valid |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3238 * entries). If no valid entries are in the list, then returns 1. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3239 */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3240 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3241 qf_get_cur_valid_idx(exarg_T *eap) |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3242 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3243 qf_info_T *qi = &ql_info; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3244 qf_list_T *qfl; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3245 qfline_T *qfp; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3246 int i, eidx = 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3247 int prev_fnum = 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3248 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3249 if (eap->cmdidx == CMD_ldo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3250 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3251 /* Location list */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3252 qi = GET_LOC_LIST(curwin); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3253 if (qi == NULL) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3254 return 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3255 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3256 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3257 qfl = &qi->qf_lists[qi->qf_curlist]; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3258 qfp = qfl->qf_start; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3259 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3260 /* check if the list has valid errors */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3261 if (qfl->qf_count <= 0 || qfl->qf_nonevalid) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3262 return 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3263 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3264 for (i = 1; i <= qfl->qf_index && qfp!= NULL; i++, qfp = qfp->qf_next) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3265 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3266 if (qfp->qf_valid) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3267 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3268 if (eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3269 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3270 if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3271 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3272 /* Count the number of files */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3273 eidx++; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3274 prev_fnum = qfp->qf_fnum; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3275 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3276 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3277 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3278 eidx++; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3279 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3280 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3281 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3282 return eidx ? eidx : 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3283 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3284 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3285 /* |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3286 * Get the 'n'th valid error entry in the quickfix or location list. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3287 * Used by :cdo, :ldo, :cfdo and :lfdo commands. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3288 * For :cdo and :ldo returns the 'n'th valid error entry. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3289 * For :cfdo and :lfdo returns the 'n'th valid file entry. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3290 */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3291 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3292 qf_get_nth_valid_entry(qf_info_T *qi, int n, int fdo) |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3293 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3294 qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist]; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3295 qfline_T *qfp = qfl->qf_start; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3296 int i, eidx; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3297 int prev_fnum = 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3298 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3299 /* check if the list has valid errors */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3300 if (qfl->qf_count <= 0 || qfl->qf_nonevalid) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3301 return 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3302 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3303 for (i = 1, eidx = 0; i <= qfl->qf_count && qfp!= NULL; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3304 i++, qfp = qfp->qf_next) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3305 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3306 if (qfp->qf_valid) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3307 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3308 if (fdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3309 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3310 if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3311 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3312 /* Count the number of files */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3313 eidx++; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3314 prev_fnum = qfp->qf_fnum; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3315 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3316 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3317 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3318 eidx++; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3319 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3320 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3321 if (eidx == n) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3322 break; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3323 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3324 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3325 if (i <= qfl->qf_count) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3326 return i; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3327 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3328 return 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3329 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3330 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3331 /* |
7 | 3332 * ":cc", ":crewind", ":cfirst" and ":clast". |
644 | 3333 * ":ll", ":lrewind", ":lfirst" and ":llast". |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3334 * ":cdo", ":ldo", ":cfdo" and ":lfdo" |
7 | 3335 */ |
3336 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3337 ex_cc(exarg_T *eap) |
7 | 3338 { |
659 | 3339 qf_info_T *qi = &ql_info; |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3340 int errornr; |
659 | 3341 |
3342 if (eap->cmdidx == CMD_ll | |
3343 || eap->cmdidx == CMD_lrewind | |
3344 || eap->cmdidx == CMD_lfirst | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3345 || eap->cmdidx == CMD_llast |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3346 || eap->cmdidx == CMD_ldo |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3347 || eap->cmdidx == CMD_lfdo) |
644 | 3348 { |
3349 qi = GET_LOC_LIST(curwin); | |
3350 if (qi == NULL) | |
3351 { | |
3352 EMSG(_(e_loclist)); | |
3353 return; | |
3354 } | |
3355 } | |
3356 | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3357 if (eap->addr_count > 0) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3358 errornr = (int)eap->line2; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3359 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3360 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3361 if (eap->cmdidx == CMD_cc || eap->cmdidx == CMD_ll) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3362 errornr = 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3363 else if (eap->cmdidx == CMD_crewind || eap->cmdidx == CMD_lrewind |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3364 || eap->cmdidx == CMD_cfirst || eap->cmdidx == CMD_lfirst) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3365 errornr = 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3366 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3367 errornr = 32767; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3368 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3369 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3370 /* For cdo and ldo commands, jump to the nth valid error. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3371 * For cfdo and lfdo commands, jump to the nth valid file entry. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3372 */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3373 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo || |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3374 eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3375 errornr = qf_get_nth_valid_entry(qi, |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3376 eap->addr_count > 0 ? (int)eap->line1 : 1, |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3377 eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3378 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3379 qf_jump(qi, 0, errornr, eap->forceit); |
7 | 3380 } |
3381 | |
3382 /* | |
3383 * ":cnext", ":cnfile", ":cNext" and ":cprevious". | |
644 | 3384 * ":lnext", ":lNext", ":lprevious", ":lnfile", ":lNfile" and ":lpfile". |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3385 * Also, used by ":cdo", ":ldo", ":cfdo" and ":lfdo" commands. |
7 | 3386 */ |
3387 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3388 ex_cnext(exarg_T *eap) |
7 | 3389 { |
659 | 3390 qf_info_T *qi = &ql_info; |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3391 int errornr; |
659 | 3392 |
3393 if (eap->cmdidx == CMD_lnext | |
3394 || eap->cmdidx == CMD_lNext | |
3395 || eap->cmdidx == CMD_lprevious | |
3396 || eap->cmdidx == CMD_lnfile | |
3397 || eap->cmdidx == CMD_lNfile | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3398 || eap->cmdidx == CMD_lpfile |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3399 || eap->cmdidx == CMD_ldo |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3400 || eap->cmdidx == CMD_lfdo) |
644 | 3401 { |
3402 qi = GET_LOC_LIST(curwin); | |
3403 if (qi == NULL) | |
3404 { | |
3405 EMSG(_(e_loclist)); | |
3406 return; | |
3407 } | |
3408 } | |
3409 | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3410 if (eap->addr_count > 0 && |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3411 (eap->cmdidx != CMD_cdo && eap->cmdidx != CMD_ldo && |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3412 eap->cmdidx != CMD_cfdo && eap->cmdidx != CMD_lfdo)) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3413 errornr = (int)eap->line2; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3414 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3415 errornr = 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3416 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3417 qf_jump(qi, (eap->cmdidx == CMD_cnext || eap->cmdidx == CMD_lnext |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3418 || eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo) |
7 | 3419 ? FORWARD |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3420 : (eap->cmdidx == CMD_cnfile || eap->cmdidx == CMD_lnfile |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3421 || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) |
7 | 3422 ? FORWARD_FILE |
644 | 3423 : (eap->cmdidx == CMD_cpfile || eap->cmdidx == CMD_lpfile |
3424 || eap->cmdidx == CMD_cNfile || eap->cmdidx == CMD_lNfile) | |
7 | 3425 ? BACKWARD_FILE |
3426 : BACKWARD, | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3427 errornr, eap->forceit); |
7 | 3428 } |
3429 | |
3430 /* | |
446 | 3431 * ":cfile"/":cgetfile"/":caddfile" commands. |
644 | 3432 * ":lfile"/":lgetfile"/":laddfile" commands. |
7 | 3433 */ |
3434 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3435 ex_cfile(exarg_T *eap) |
7 | 3436 { |
644 | 3437 win_T *wp = NULL; |
659 | 3438 qf_info_T *qi = &ql_info; |
3404 | 3439 #ifdef FEAT_AUTOCMD |
3440 char_u *au_name = NULL; | |
3441 #endif | |
644 | 3442 |
3443 if (eap->cmdidx == CMD_lfile || eap->cmdidx == CMD_lgetfile | |
3404 | 3444 || eap->cmdidx == CMD_laddfile) |
644 | 3445 wp = curwin; |
3446 | |
3404 | 3447 #ifdef FEAT_AUTOCMD |
3448 switch (eap->cmdidx) | |
3449 { | |
3450 case CMD_cfile: au_name = (char_u *)"cfile"; break; | |
3451 case CMD_cgetfile: au_name = (char_u *)"cgetfile"; break; | |
3452 case CMD_caddfile: au_name = (char_u *)"caddfile"; break; | |
3453 case CMD_lfile: au_name = (char_u *)"lfile"; break; | |
3454 case CMD_lgetfile: au_name = (char_u *)"lgetfile"; break; | |
3455 case CMD_laddfile: au_name = (char_u *)"laddfile"; break; | |
3456 default: break; | |
3457 } | |
3458 if (au_name != NULL) | |
3459 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, NULL, FALSE, curbuf); | |
3460 #endif | |
2296
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3461 #ifdef FEAT_BROWSE |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3462 if (cmdmod.browse) |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3463 { |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3464 char_u *browse_file = do_browse(0, (char_u *)_("Error file"), eap->arg, |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3465 NULL, NULL, BROWSE_FILTER_ALL_FILES, NULL); |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3466 if (browse_file == NULL) |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3467 return; |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3468 set_string_option_direct((char_u *)"ef", -1, browse_file, OPT_FREE, 0); |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3469 vim_free(browse_file); |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3470 } |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3471 else |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3472 #endif |
7 | 3473 if (*eap->arg != NUL) |
694 | 3474 set_string_option_direct((char_u *)"ef", -1, eap->arg, OPT_FREE, 0); |
446 | 3475 |
3476 /* | |
3477 * This function is used by the :cfile, :cgetfile and :caddfile | |
3478 * commands. | |
3479 * :cfile always creates a new quickfix list and jumps to the | |
3480 * first error. | |
3481 * :cgetfile creates a new quickfix list but doesn't jump to the | |
3482 * first error. | |
3483 * :caddfile adds to an existing quickfix list. If there is no | |
3484 * quickfix list then a new list is created. | |
3485 */ | |
644 | 3486 if (qf_init(wp, p_ef, p_efm, (eap->cmdidx != CMD_caddfile |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3487 && eap->cmdidx != CMD_laddfile), |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3488 *eap->cmdlinep) > 0 |
644 | 3489 && (eap->cmdidx == CMD_cfile |
3490 || eap->cmdidx == CMD_lfile)) | |
665 | 3491 { |
3404 | 3492 #ifdef FEAT_AUTOCMD |
3493 if (au_name != NULL) | |
3494 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf); | |
3495 #endif | |
665 | 3496 if (wp != NULL) |
3497 qi = GET_LOC_LIST(wp); | |
659 | 3498 qf_jump(qi, 0, 0, eap->forceit); /* display first error */ |
665 | 3499 } |
3404 | 3500 |
3501 else | |
3502 { | |
3503 #ifdef FEAT_AUTOCMD | |
3504 if (au_name != NULL) | |
3505 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf); | |
3506 #endif | |
3507 } | |
7 | 3508 } |
3509 | |
3510 /* | |
41 | 3511 * ":vimgrep {pattern} file(s)" |
657 | 3512 * ":vimgrepadd {pattern} file(s)" |
3513 * ":lvimgrep {pattern} file(s)" | |
3514 * ":lvimgrepadd {pattern} file(s)" | |
41 | 3515 */ |
3516 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3517 ex_vimgrep(exarg_T *eap) |
41 | 3518 { |
42 | 3519 regmmatch_T regmatch; |
153 | 3520 int fcount; |
41 | 3521 char_u **fnames; |
1411 | 3522 char_u *fname; |
8603
bfa74b84c41c
commit https://github.com/vim/vim/commit/5584df65a0ca2315d1eebc13c54a448bee4d0758
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
3523 char_u *title; |
153 | 3524 char_u *s; |
3525 char_u *p; | |
3526 int fi; | |
657 | 3527 qf_info_T *qi = &ql_info; |
4003 | 3528 #ifdef FEAT_AUTOCMD |
3529 qfline_T *cur_qf_start; | |
3530 #endif | |
230 | 3531 qfline_T *prevp = NULL; |
41 | 3532 long lnum; |
42 | 3533 buf_T *buf; |
3534 int duplicate_name = FALSE; | |
3535 int using_dummy; | |
1396 | 3536 int redraw_for_dummy = FALSE; |
42 | 3537 int found_match; |
123 | 3538 buf_T *first_match_buf = NULL; |
3539 time_t seconds = 0; | |
677 | 3540 int save_mls; |
123 | 3541 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) |
3542 char_u *save_ei = NULL; | |
677 | 3543 #endif |
123 | 3544 aco_save_T aco; |
170 | 3545 int flags = 0; |
3546 colnr_T col; | |
716 | 3547 long tomatch; |
2770 | 3548 char_u *dirname_start = NULL; |
3549 char_u *dirname_now = NULL; | |
1411 | 3550 char_u *target_dir = NULL; |
1683 | 3551 #ifdef FEAT_AUTOCMD |
3552 char_u *au_name = NULL; | |
161 | 3553 |
3554 switch (eap->cmdidx) | |
3555 { | |
2782 | 3556 case CMD_vimgrep: au_name = (char_u *)"vimgrep"; break; |
3557 case CMD_lvimgrep: au_name = (char_u *)"lvimgrep"; break; | |
3558 case CMD_vimgrepadd: au_name = (char_u *)"vimgrepadd"; break; | |
657 | 3559 case CMD_lvimgrepadd: au_name = (char_u *)"lvimgrepadd"; break; |
2782 | 3560 case CMD_grep: au_name = (char_u *)"grep"; break; |
3561 case CMD_lgrep: au_name = (char_u *)"lgrep"; break; | |
3562 case CMD_grepadd: au_name = (char_u *)"grepadd"; break; | |
3563 case CMD_lgrepadd: au_name = (char_u *)"lgrepadd"; break; | |
161 | 3564 default: break; |
3565 } | |
3566 if (au_name != NULL) | |
3567 { | |
3568 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, | |
3569 curbuf->b_fname, TRUE, curbuf); | |
3570 if (did_throw || force_abort) | |
3571 return; | |
3572 } | |
3573 #endif | |
41 | 3574 |
661 | 3575 if (eap->cmdidx == CMD_lgrep |
659 | 3576 || eap->cmdidx == CMD_lvimgrep |
3577 || eap->cmdidx == CMD_lgrepadd | |
3578 || eap->cmdidx == CMD_lvimgrepadd) | |
657 | 3579 { |
3580 qi = ll_get_or_alloc_list(curwin); | |
3581 if (qi == NULL) | |
3582 return; | |
3583 } | |
3584 | |
716 | 3585 if (eap->addr_count > 0) |
3586 tomatch = eap->line2; | |
3587 else | |
3588 tomatch = MAXLNUM; | |
3589 | |
42 | 3590 /* Get the search pattern: either white-separated or enclosed in // */ |
41 | 3591 regmatch.regprog = NULL; |
8603
bfa74b84c41c
commit https://github.com/vim/vim/commit/5584df65a0ca2315d1eebc13c54a448bee4d0758
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
3592 title = vim_strsave(*eap->cmdlinep); |
170 | 3593 p = skip_vimgrep_pat(eap->arg, &s, &flags); |
153 | 3594 if (p == NULL) |
41 | 3595 { |
282 | 3596 EMSG(_(e_invalpat)); |
153 | 3597 goto theend; |
41 | 3598 } |
4197 | 3599 |
3600 if (s != NULL && *s == NUL) | |
3601 { | |
3602 /* Pattern is empty, use last search pattern. */ | |
3603 if (last_search_pat() == NULL) | |
3604 { | |
3605 EMSG(_(e_noprevre)); | |
3606 goto theend; | |
3607 } | |
3608 regmatch.regprog = vim_regcomp(last_search_pat(), RE_MAGIC); | |
3609 } | |
3610 else | |
3611 regmatch.regprog = vim_regcomp(s, RE_MAGIC); | |
3612 | |
41 | 3613 if (regmatch.regprog == NULL) |
3614 goto theend; | |
95 | 3615 regmatch.rmm_ic = p_ic; |
410 | 3616 regmatch.rmm_maxcol = 0; |
41 | 3617 |
3618 p = skipwhite(p); | |
3619 if (*p == NUL) | |
3620 { | |
3621 EMSG(_("E683: File name missing or invalid pattern")); | |
3622 goto theend; | |
3623 } | |
3624 | |
661 | 3625 if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd && |
657 | 3626 eap->cmdidx != CMD_vimgrepadd && eap->cmdidx != CMD_lvimgrepadd) |
644 | 3627 || qi->qf_curlist == qi->qf_listcount) |
41 | 3628 /* make place for a new list */ |
8603
bfa74b84c41c
commit https://github.com/vim/vim/commit/5584df65a0ca2315d1eebc13c54a448bee4d0758
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
3629 qf_new_list(qi, title != NULL ? title : *eap->cmdlinep); |
644 | 3630 else if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
41 | 3631 /* Adding to existing list, find last entry. */ |
644 | 3632 for (prevp = qi->qf_lists[qi->qf_curlist].qf_start; |
41 | 3633 prevp->qf_next != prevp; prevp = prevp->qf_next) |
3634 ; | |
3635 | |
3636 /* parse the list of arguments */ | |
3620 | 3637 if (get_arglist_exp(p, &fcount, &fnames, TRUE) == FAIL) |
41 | 3638 goto theend; |
3639 if (fcount == 0) | |
3640 { | |
3641 EMSG(_(e_nomatch)); | |
3642 goto theend; | |
3643 } | |
3644 | |
7558
9a4c9dccd603
commit https://github.com/vim/vim/commit/b86a343280b08d6701da68ee0651e960a0a7a61c
Christian Brabandt <cb@256bit.org>
parents:
7515
diff
changeset
|
3645 dirname_start = alloc_id(MAXPATHL, aid_qf_dirname_start); |
9a4c9dccd603
commit https://github.com/vim/vim/commit/b86a343280b08d6701da68ee0651e960a0a7a61c
Christian Brabandt <cb@256bit.org>
parents:
7515
diff
changeset
|
3646 dirname_now = alloc_id(MAXPATHL, aid_qf_dirname_now); |
2770 | 3647 if (dirname_start == NULL || dirname_now == NULL) |
7662
4d34891e98f4
commit https://github.com/vim/vim/commit/61ff4dd6a4d47bd32383fe28087be2b37dec53f4
Christian Brabandt <cb@256bit.org>
parents:
7558
diff
changeset
|
3648 { |
4d34891e98f4
commit https://github.com/vim/vim/commit/61ff4dd6a4d47bd32383fe28087be2b37dec53f4
Christian Brabandt <cb@256bit.org>
parents:
7558
diff
changeset
|
3649 FreeWild(fcount, fnames); |
2770 | 3650 goto theend; |
7662
4d34891e98f4
commit https://github.com/vim/vim/commit/61ff4dd6a4d47bd32383fe28087be2b37dec53f4
Christian Brabandt <cb@256bit.org>
parents:
7558
diff
changeset
|
3651 } |
2770 | 3652 |
1411 | 3653 /* Remember the current directory, because a BufRead autocommand that does |
3654 * ":lcd %:p:h" changes the meaning of short path names. */ | |
3655 mch_dirname(dirname_start, MAXPATHL); | |
3656 | |
4003 | 3657 #ifdef FEAT_AUTOCMD |
4352 | 3658 /* Remember the value of qf_start, so that we can check for autocommands |
4003 | 3659 * changing the current quickfix list. */ |
3660 cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start; | |
3661 #endif | |
3662 | |
123 | 3663 seconds = (time_t)0; |
716 | 3664 for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) |
41 | 3665 { |
1411 | 3666 fname = shorten_fname1(fnames[fi]); |
123 | 3667 if (time(NULL) > seconds) |
3668 { | |
1411 | 3669 /* Display the file name every second or so, show the user we are |
3670 * working on it. */ | |
123 | 3671 seconds = time(NULL); |
3672 msg_start(); | |
1411 | 3673 p = msg_strtrunc(fname, TRUE); |
123 | 3674 if (p == NULL) |
1411 | 3675 msg_outtrans(fname); |
123 | 3676 else |
3677 { | |
3678 msg_outtrans(p); | |
3679 vim_free(p); | |
3680 } | |
3681 msg_clr_eos(); | |
3682 msg_didout = FALSE; /* overwrite this message */ | |
3683 msg_nowait = TRUE; /* don't wait for this message */ | |
3684 msg_col = 0; | |
3685 out_flush(); | |
3686 } | |
3687 | |
42 | 3688 buf = buflist_findname_exp(fnames[fi]); |
3689 if (buf == NULL || buf->b_ml.ml_mfp == NULL) | |
3690 { | |
3691 /* Remember that a buffer with this name already exists. */ | |
3692 duplicate_name = (buf != NULL); | |
123 | 3693 using_dummy = TRUE; |
1396 | 3694 redraw_for_dummy = TRUE; |
123 | 3695 |
3696 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) | |
3697 /* Don't do Filetype autocommands to avoid loading syntax and | |
3698 * indent scripts, a great speed improvement. */ | |
3699 save_ei = au_event_disable(",Filetype"); | |
3700 #endif | |
677 | 3701 /* Don't use modelines here, it's useless. */ |
3702 save_mls = p_mls; | |
3703 p_mls = 0; | |
42 | 3704 |
3705 /* Load file into a buffer, so that 'fileencoding' is detected, | |
3706 * autocommands applied, etc. */ | |
3490 | 3707 buf = load_dummy_buffer(fname, dirname_start, dirname_now); |
123 | 3708 |
677 | 3709 p_mls = save_mls; |
123 | 3710 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) |
3711 au_event_restore(save_ei); | |
3712 #endif | |
42 | 3713 } |
3714 else | |
3715 /* Use existing, loaded buffer. */ | |
3716 using_dummy = FALSE; | |
123 | 3717 |
4003 | 3718 #ifdef FEAT_AUTOCMD |
3719 if (cur_qf_start != qi->qf_lists[qi->qf_curlist].qf_start) | |
3720 { | |
3721 int idx; | |
3722 | |
3723 /* Autocommands changed the quickfix list. Find the one we were | |
3724 * using and restore it. */ | |
3725 for (idx = 0; idx < LISTCOUNT; ++idx) | |
3726 if (cur_qf_start == qi->qf_lists[idx].qf_start) | |
3727 { | |
3728 qi->qf_curlist = idx; | |
3729 break; | |
3730 } | |
3731 if (idx == LISTCOUNT) | |
3732 { | |
3733 /* List cannot be found, create a new one. */ | |
3734 qf_new_list(qi, *eap->cmdlinep); | |
3735 cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start; | |
3736 } | |
3737 } | |
3738 #endif | |
3739 | |
42 | 3740 if (buf == NULL) |
123 | 3741 { |
3742 if (!got_int) | |
1411 | 3743 smsg((char_u *)_("Cannot open file \"%s\""), fname); |
123 | 3744 } |
41 | 3745 else |
3746 { | |
717 | 3747 /* Try for a match in all lines of the buffer. |
3748 * For ":1vimgrep" look for first match only. */ | |
42 | 3749 found_match = FALSE; |
716 | 3750 for (lnum = 1; lnum <= buf->b_ml.ml_line_count && tomatch > 0; |
3751 ++lnum) | |
41 | 3752 { |
170 | 3753 col = 0; |
3754 while (vim_regexec_multi(®match, curwin, buf, lnum, | |
1521 | 3755 col, NULL) > 0) |
41 | 3756 { |
1411 | 3757 ; |
644 | 3758 if (qf_add_entry(qi, &prevp, |
41 | 3759 NULL, /* dir */ |
1411 | 3760 fname, |
1065 | 3761 0, |
42 | 3762 ml_get_buf(buf, |
3763 regmatch.startpos[0].lnum + lnum, FALSE), | |
3764 regmatch.startpos[0].lnum + lnum, | |
3765 regmatch.startpos[0].col + 1, | |
170 | 3766 FALSE, /* vis_col */ |
230 | 3767 NULL, /* search pattern */ |
856 | 3768 0, /* nr */ |
3769 0, /* type */ | |
3770 TRUE /* valid */ | |
41 | 3771 ) == FAIL) |
3772 { | |
3773 got_int = TRUE; | |
3774 break; | |
3775 } | |
716 | 3776 found_match = TRUE; |
3777 if (--tomatch == 0) | |
3778 break; | |
170 | 3779 if ((flags & VGR_GLOBAL) == 0 |
3780 || regmatch.endpos[0].lnum > 0) | |
3781 break; | |
3782 col = regmatch.endpos[0].col | |
3783 + (col == regmatch.endpos[0].col); | |
1883 | 3784 if (col > (colnr_T)STRLEN(ml_get_buf(buf, lnum, FALSE))) |
170 | 3785 break; |
41 | 3786 } |
3787 line_breakcheck(); | |
42 | 3788 if (got_int) |
3789 break; | |
41 | 3790 } |
4003 | 3791 #ifdef FEAT_AUTOCMD |
3792 cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start; | |
3793 #endif | |
42 | 3794 |
3795 if (using_dummy) | |
3796 { | |
123 | 3797 if (found_match && first_match_buf == NULL) |
3798 first_match_buf = buf; | |
42 | 3799 if (duplicate_name) |
123 | 3800 { |
42 | 3801 /* Never keep a dummy buffer if there is another buffer |
3802 * with the same name. */ | |
3490 | 3803 wipe_dummy_buffer(buf, dirname_start); |
123 | 3804 buf = NULL; |
3805 } | |
717 | 3806 else if (!cmdmod.hide |
3807 || buf->b_p_bh[0] == 'u' /* "unload" */ | |
3808 || buf->b_p_bh[0] == 'w' /* "wipe" */ | |
3809 || buf->b_p_bh[0] == 'd') /* "delete" */ | |
42 | 3810 { |
717 | 3811 /* When no match was found we don't need to remember the |
3812 * buffer, wipe it out. If there was a match and it | |
3813 * wasn't the first one or we won't jump there: only | |
3814 * unload the buffer. | |
3815 * Ignore 'hidden' here, because it may lead to having too | |
3816 * many swap files. */ | |
42 | 3817 if (!found_match) |
123 | 3818 { |
3490 | 3819 wipe_dummy_buffer(buf, dirname_start); |
123 | 3820 buf = NULL; |
3821 } | |
170 | 3822 else if (buf != first_match_buf || (flags & VGR_NOJUMP)) |
123 | 3823 { |
3490 | 3824 unload_dummy_buffer(buf, dirname_start); |
123 | 3825 buf = NULL; |
3826 } | |
42 | 3827 } |
123 | 3828 |
3829 if (buf != NULL) | |
3830 { | |
1411 | 3831 /* If the buffer is still loaded we need to use the |
3832 * directory we jumped to below. */ | |
3833 if (buf == first_match_buf | |
3834 && target_dir == NULL | |
3835 && STRCMP(dirname_start, dirname_now) != 0) | |
3836 target_dir = vim_strsave(dirname_now); | |
3837 | |
123 | 3838 /* The buffer is still loaded, the Filetype autocommands |
677 | 3839 * need to be done now, in that buffer. And the modelines |
717 | 3840 * need to be done (again). But not the window-local |
3841 * options! */ | |
123 | 3842 aucmd_prepbuf(&aco, buf); |
677 | 3843 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) |
123 | 3844 apply_autocmds(EVENT_FILETYPE, buf->b_p_ft, |
3845 buf->b_fname, TRUE, buf); | |
677 | 3846 #endif |
717 | 3847 do_modelines(OPT_NOWIN); |
123 | 3848 aucmd_restbuf(&aco); |
3849 } | |
42 | 3850 } |
41 | 3851 } |
3852 } | |
3853 | |
3854 FreeWild(fcount, fnames); | |
3855 | |
644 | 3856 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; |
3857 qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start; | |
3858 qi->qf_lists[qi->qf_curlist].qf_index = 1; | |
41 | 3859 |
3860 #ifdef FEAT_WINDOWS | |
8932
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
3861 qf_update_buffer(qi, TRUE); |
41 | 3862 #endif |
3863 | |
842 | 3864 #ifdef FEAT_AUTOCMD |
3865 if (au_name != NULL) | |
3866 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, | |
3867 curbuf->b_fname, TRUE, curbuf); | |
3868 #endif | |
3869 | |
41 | 3870 /* Jump to first match. */ |
644 | 3871 if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
170 | 3872 { |
3873 if ((flags & VGR_NOJUMP) == 0) | |
1396 | 3874 { |
3875 buf = curbuf; | |
659 | 3876 qf_jump(qi, 0, 0, eap->forceit); |
1396 | 3877 if (buf != curbuf) |
3878 /* If we jumped to another buffer redrawing will already be | |
3879 * taken care of. */ | |
3880 redraw_for_dummy = FALSE; | |
1411 | 3881 |
3882 /* Jump to the directory used after loading the buffer. */ | |
3883 if (curbuf == first_match_buf && target_dir != NULL) | |
3884 { | |
3885 exarg_T ea; | |
3886 | |
3887 ea.arg = target_dir; | |
3888 ea.cmdidx = CMD_lcd; | |
3889 ex_cd(&ea); | |
3890 } | |
1396 | 3891 } |
170 | 3892 } |
42 | 3893 else |
3894 EMSG2(_(e_nomatch2), s); | |
41 | 3895 |
1396 | 3896 /* If we loaded a dummy buffer into the current window, the autocommands |
3897 * may have messed up things, need to redraw and recompute folds. */ | |
3898 if (redraw_for_dummy) | |
3899 { | |
3900 #ifdef FEAT_FOLDING | |
3901 foldUpdateAll(curwin); | |
3902 #else | |
3903 redraw_later(NOT_VALID); | |
3904 #endif | |
3905 } | |
3906 | |
41 | 3907 theend: |
8603
bfa74b84c41c
commit https://github.com/vim/vim/commit/5584df65a0ca2315d1eebc13c54a448bee4d0758
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
3908 vim_free(title); |
2770 | 3909 vim_free(dirname_now); |
3910 vim_free(dirname_start); | |
1411 | 3911 vim_free(target_dir); |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4371
diff
changeset
|
3912 vim_regfree(regmatch.regprog); |
41 | 3913 } |
3914 | |
3915 /* | |
170 | 3916 * Skip over the pattern argument of ":vimgrep /pat/[g][j]". |
153 | 3917 * Put the start of the pattern in "*s", unless "s" is NULL. |
170 | 3918 * If "flags" is not NULL put the flags in it: VGR_GLOBAL, VGR_NOJUMP. |
3919 * If "s" is not NULL terminate the pattern with a NUL. | |
3920 * Return a pointer to the char just past the pattern plus flags. | |
153 | 3921 */ |
3922 char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3923 skip_vimgrep_pat(char_u *p, char_u **s, int *flags) |
153 | 3924 { |
3925 int c; | |
3926 | |
3927 if (vim_isIDc(*p)) | |
3928 { | |
170 | 3929 /* ":vimgrep pattern fname" */ |
153 | 3930 if (s != NULL) |
3931 *s = p; | |
170 | 3932 p = skiptowhite(p); |
3933 if (s != NULL && *p != NUL) | |
3934 *p++ = NUL; | |
153 | 3935 } |
170 | 3936 else |
3937 { | |
3938 /* ":vimgrep /pattern/[g][j] fname" */ | |
3939 if (s != NULL) | |
3940 *s = p + 1; | |
3941 c = *p; | |
3942 p = skip_regexp(p + 1, c, TRUE, NULL); | |
3943 if (*p != c) | |
3944 return NULL; | |
3945 | |
3946 /* Truncate the pattern. */ | |
3947 if (s != NULL) | |
3948 *p = NUL; | |
3949 ++p; | |
3950 | |
3951 /* Find the flags */ | |
3952 while (*p == 'g' || *p == 'j') | |
3953 { | |
3954 if (flags != NULL) | |
3955 { | |
3956 if (*p == 'g') | |
3957 *flags |= VGR_GLOBAL; | |
3958 else | |
3959 *flags |= VGR_NOJUMP; | |
3960 } | |
3961 ++p; | |
3962 } | |
3963 } | |
153 | 3964 return p; |
3965 } | |
3966 | |
3967 /* | |
3490 | 3968 * Restore current working directory to "dirname_start" if they differ, taking |
3969 * into account whether it is set locally or globally. | |
3970 */ | |
3971 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3972 restore_start_dir(char_u *dirname_start) |
3490 | 3973 { |
3974 char_u *dirname_now = alloc(MAXPATHL); | |
3975 | |
3976 if (NULL != dirname_now) | |
3977 { | |
3978 mch_dirname(dirname_now, MAXPATHL); | |
3979 if (STRCMP(dirname_start, dirname_now) != 0) | |
3980 { | |
3981 /* If the directory has changed, change it back by building up an | |
3982 * appropriate ex command and executing it. */ | |
3983 exarg_T ea; | |
3984 | |
3985 ea.arg = dirname_start; | |
3986 ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd; | |
3987 ex_cd(&ea); | |
3988 } | |
3974 | 3989 vim_free(dirname_now); |
3490 | 3990 } |
3991 } | |
3992 | |
3993 /* | |
3994 * Load file "fname" into a dummy buffer and return the buffer pointer, | |
3995 * placing the directory resulting from the buffer load into the | |
3996 * "resulting_dir" pointer. "resulting_dir" must be allocated by the caller | |
3997 * prior to calling this function. Restores directory to "dirname_start" prior | |
3998 * to returning, if autocmds or the 'autochdir' option have changed it. | |
3999 * | |
4000 * If creating the dummy buffer does not fail, must call unload_dummy_buffer() | |
4001 * or wipe_dummy_buffer() later! | |
4002 * | |
42 | 4003 * Returns NULL if it fails. |
4004 */ | |
4005 static buf_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4006 load_dummy_buffer( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4007 char_u *fname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4008 char_u *dirname_start, /* in: old directory */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4009 char_u *resulting_dir) /* out: new directory */ |
42 | 4010 { |
4011 buf_T *newbuf; | |
2646 | 4012 buf_T *newbuf_to_wipe = NULL; |
42 | 4013 int failed = TRUE; |
4014 aco_save_T aco; | |
4015 | |
4016 /* Allocate a buffer without putting it in the buffer list. */ | |
4017 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); | |
4018 if (newbuf == NULL) | |
4019 return NULL; | |
4020 | |
177 | 4021 /* Init the options. */ |
4022 buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP); | |
4023 | |
1918 | 4024 /* need to open the memfile before putting the buffer in a window */ |
4025 if (ml_open(newbuf) == OK) | |
42 | 4026 { |
1918 | 4027 /* set curwin/curbuf to buf and save a few things */ |
4028 aucmd_prepbuf(&aco, newbuf); | |
4029 | |
4030 /* Need to set the filename for autocommands. */ | |
4031 (void)setfname(curbuf, fname, NULL, FALSE); | |
4032 | |
42 | 4033 /* Create swap file now to avoid the ATTENTION message. */ |
4034 check_need_swap(TRUE); | |
4035 | |
4036 /* Remove the "dummy" flag, otherwise autocommands may not | |
4037 * work. */ | |
4038 curbuf->b_flags &= ~BF_DUMMY; | |
4039 | |
4040 if (readfile(fname, NULL, | |
4041 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, | |
4042 NULL, READ_NEW | READ_DUMMY) == OK | |
857 | 4043 && !got_int |
42 | 4044 && !(curbuf->b_flags & BF_NEW)) |
4045 { | |
4046 failed = FALSE; | |
4047 if (curbuf != newbuf) | |
4048 { | |
2646 | 4049 /* Bloody autocommands changed the buffer! Can happen when |
4050 * using netrw and editing a remote file. Use the current | |
4051 * buffer instead, delete the dummy one after restoring the | |
4052 * window stuff. */ | |
4053 newbuf_to_wipe = newbuf; | |
42 | 4054 newbuf = curbuf; |
4055 } | |
4056 } | |
1918 | 4057 |
4058 /* restore curwin/curbuf and a few other things */ | |
4059 aucmd_restbuf(&aco); | |
2646 | 4060 if (newbuf_to_wipe != NULL && buf_valid(newbuf_to_wipe)) |
4061 wipe_buffer(newbuf_to_wipe, FALSE); | |
42 | 4062 } |
4063 | |
3490 | 4064 /* |
4065 * When autocommands/'autochdir' option changed directory: go back. | |
4066 * Let the caller know what the resulting dir was first, in case it is | |
4067 * important. | |
4068 */ | |
4069 mch_dirname(resulting_dir, MAXPATHL); | |
4070 restore_start_dir(dirname_start); | |
4071 | |
42 | 4072 if (!buf_valid(newbuf)) |
4073 return NULL; | |
4074 if (failed) | |
4075 { | |
3490 | 4076 wipe_dummy_buffer(newbuf, dirname_start); |
42 | 4077 return NULL; |
4078 } | |
4079 return newbuf; | |
4080 } | |
4081 | |
4082 /* | |
3490 | 4083 * Wipe out the dummy buffer that load_dummy_buffer() created. Restores |
4084 * directory to "dirname_start" prior to returning, if autocmds or the | |
4085 * 'autochdir' option have changed it. | |
42 | 4086 */ |
4087 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4088 wipe_dummy_buffer(buf_T *buf, char_u *dirname_start) |
42 | 4089 { |
4090 if (curbuf != buf) /* safety check */ | |
857 | 4091 { |
4092 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
4093 cleanup_T cs; | |
4094 | |
4095 /* Reset the error/interrupt/exception state here so that aborting() | |
4096 * returns FALSE when wiping out the buffer. Otherwise it doesn't | |
4097 * work when got_int is set. */ | |
4098 enter_cleanup(&cs); | |
4099 #endif | |
4100 | |
42 | 4101 wipe_buffer(buf, FALSE); |
857 | 4102 |
4103 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
4104 /* Restore the error/interrupt/exception state if not discarded by a | |
4105 * new aborting error, interrupt, or uncaught exception. */ | |
4106 leave_cleanup(&cs); | |
4107 #endif | |
3490 | 4108 /* When autocommands/'autochdir' option changed directory: go back. */ |
4109 restore_start_dir(dirname_start); | |
857 | 4110 } |
42 | 4111 } |
4112 | |
4113 /* | |
3490 | 4114 * Unload the dummy buffer that load_dummy_buffer() created. Restores |
4115 * directory to "dirname_start" prior to returning, if autocmds or the | |
4116 * 'autochdir' option have changed it. | |
42 | 4117 */ |
4118 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4119 unload_dummy_buffer(buf_T *buf, char_u *dirname_start) |
42 | 4120 { |
4121 if (curbuf != buf) /* safety check */ | |
3490 | 4122 { |
3365 | 4123 close_buffer(NULL, buf, DOBUF_UNLOAD, FALSE); |
3490 | 4124 |
4125 /* When autocommands/'autochdir' option changed directory: go back. */ | |
4126 restore_start_dir(dirname_start); | |
4127 } | |
42 | 4128 } |
4129 | |
170 | 4130 #if defined(FEAT_EVAL) || defined(PROTO) |
4131 /* | |
4132 * Add each quickfix error to list "list" as a dictionary. | |
4133 */ | |
4134 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4135 get_errorlist(win_T *wp, list_T *list) |
170 | 4136 { |
644 | 4137 qf_info_T *qi = &ql_info; |
230 | 4138 dict_T *dict; |
4139 char_u buf[2]; | |
4140 qfline_T *qfp; | |
4141 int i; | |
1065 | 4142 int bufnum; |
170 | 4143 |
647 | 4144 if (wp != NULL) |
4145 { | |
4146 qi = GET_LOC_LIST(wp); | |
4147 if (qi == NULL) | |
4148 return FAIL; | |
4149 } | |
4150 | |
644 | 4151 if (qi->qf_curlist >= qi->qf_listcount |
712 | 4152 || qi->qf_lists[qi->qf_curlist].qf_count == 0) |
170 | 4153 return FAIL; |
4154 | |
644 | 4155 qfp = qi->qf_lists[qi->qf_curlist].qf_start; |
4156 for (i = 1; !got_int && i <= qi->qf_lists[qi->qf_curlist].qf_count; ++i) | |
170 | 4157 { |
1065 | 4158 /* Handle entries with a non-existing buffer number. */ |
4159 bufnum = qfp->qf_fnum; | |
4160 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) | |
4161 bufnum = 0; | |
4162 | |
170 | 4163 if ((dict = dict_alloc()) == NULL) |
4164 return FAIL; | |
4165 if (list_append_dict(list, dict) == FAIL) | |
4166 return FAIL; | |
4167 | |
4168 buf[0] = qfp->qf_type; | |
4169 buf[1] = NUL; | |
1065 | 4170 if ( dict_add_nr_str(dict, "bufnr", (long)bufnum, NULL) == FAIL |
170 | 4171 || dict_add_nr_str(dict, "lnum", (long)qfp->qf_lnum, NULL) == FAIL |
4172 || dict_add_nr_str(dict, "col", (long)qfp->qf_col, NULL) == FAIL | |
4173 || dict_add_nr_str(dict, "vcol", (long)qfp->qf_viscol, NULL) == FAIL | |
4174 || dict_add_nr_str(dict, "nr", (long)qfp->qf_nr, NULL) == FAIL | |
960 | 4175 || dict_add_nr_str(dict, "pattern", 0L, |
4176 qfp->qf_pattern == NULL ? (char_u *)"" : qfp->qf_pattern) == FAIL | |
4177 || dict_add_nr_str(dict, "text", 0L, | |
4178 qfp->qf_text == NULL ? (char_u *)"" : qfp->qf_text) == FAIL | |
170 | 4179 || dict_add_nr_str(dict, "type", 0L, buf) == FAIL |
4180 || dict_add_nr_str(dict, "valid", (long)qfp->qf_valid, NULL) == FAIL) | |
4181 return FAIL; | |
4182 | |
4183 qfp = qfp->qf_next; | |
4184 } | |
4185 return OK; | |
4186 } | |
230 | 4187 |
4188 /* | |
4189 * Populate the quickfix list with the items supplied in the list | |
2530
9fe4164cb586
Fix: :ltag command did not set w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2416
diff
changeset
|
4190 * of dictionaries. "title" will be copied to w:quickfix_title |
230 | 4191 */ |
4192 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4193 set_errorlist( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4194 win_T *wp, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4195 list_T *list, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4196 int action, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4197 char_u *title) |
230 | 4198 { |
4199 listitem_T *li; | |
4200 dict_T *d; | |
4201 char_u *filename, *pattern, *text, *type; | |
1065 | 4202 int bufnum; |
230 | 4203 long lnum; |
4204 int col, nr; | |
4205 int vcol; | |
4206 qfline_T *prevp = NULL; | |
4207 int valid, status; | |
4208 int retval = OK; | |
644 | 4209 qf_info_T *qi = &ql_info; |
1065 | 4210 int did_bufnr_emsg = FALSE; |
644 | 4211 |
647 | 4212 if (wp != NULL) |
4213 { | |
648 | 4214 qi = ll_get_or_alloc_list(wp); |
647 | 4215 if (qi == NULL) |
4216 return FAIL; | |
4217 } | |
4218 | |
644 | 4219 if (action == ' ' || qi->qf_curlist == qi->qf_listcount) |
277 | 4220 /* make place for a new list */ |
3965 | 4221 qf_new_list(qi, title); |
644 | 4222 else if (action == 'a' && qi->qf_lists[qi->qf_curlist].qf_count > 0) |
277 | 4223 /* Adding to existing list, find last entry. */ |
644 | 4224 for (prevp = qi->qf_lists[qi->qf_curlist].qf_start; |
277 | 4225 prevp->qf_next != prevp; prevp = prevp->qf_next) |
4226 ; | |
4227 else if (action == 'r') | |
6079 | 4228 { |
644 | 4229 qf_free(qi, qi->qf_curlist); |
6079 | 4230 qf_store_title(qi, title); |
4231 } | |
230 | 4232 |
4233 for (li = list->lv_first; li != NULL; li = li->li_next) | |
4234 { | |
4235 if (li->li_tv.v_type != VAR_DICT) | |
4236 continue; /* Skip non-dict items */ | |
4237 | |
4238 d = li->li_tv.vval.v_dict; | |
4239 if (d == NULL) | |
4240 continue; | |
4241 | |
659 | 4242 filename = get_dict_string(d, (char_u *)"filename", TRUE); |
1065 | 4243 bufnum = get_dict_number(d, (char_u *)"bufnr"); |
230 | 4244 lnum = get_dict_number(d, (char_u *)"lnum"); |
4245 col = get_dict_number(d, (char_u *)"col"); | |
4246 vcol = get_dict_number(d, (char_u *)"vcol"); | |
4247 nr = get_dict_number(d, (char_u *)"nr"); | |
659 | 4248 type = get_dict_string(d, (char_u *)"type", TRUE); |
4249 pattern = get_dict_string(d, (char_u *)"pattern", TRUE); | |
4250 text = get_dict_string(d, (char_u *)"text", TRUE); | |
230 | 4251 if (text == NULL) |
4252 text = vim_strsave((char_u *)""); | |
4253 | |
4254 valid = TRUE; | |
1065 | 4255 if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL)) |
230 | 4256 valid = FALSE; |
4257 | |
1065 | 4258 /* Mark entries with non-existing buffer number as not valid. Give the |
4259 * error message only once. */ | |
4260 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) | |
4261 { | |
4262 if (!did_bufnr_emsg) | |
4263 { | |
4264 did_bufnr_emsg = TRUE; | |
4265 EMSGN(_("E92: Buffer %ld not found"), bufnum); | |
4266 } | |
4267 valid = FALSE; | |
4268 bufnum = 0; | |
4269 } | |
4270 | |
644 | 4271 status = qf_add_entry(qi, &prevp, |
230 | 4272 NULL, /* dir */ |
4273 filename, | |
1065 | 4274 bufnum, |
230 | 4275 text, |
4276 lnum, | |
4277 col, | |
4278 vcol, /* vis_col */ | |
4279 pattern, /* search pattern */ | |
4280 nr, | |
4281 type == NULL ? NUL : *type, | |
4282 valid); | |
4283 | |
4284 vim_free(filename); | |
4285 vim_free(pattern); | |
4286 vim_free(text); | |
4287 vim_free(type); | |
4288 | |
4289 if (status == FAIL) | |
4290 { | |
4291 retval = FAIL; | |
4292 break; | |
4293 } | |
4294 } | |
4295 | |
2146
c17a42da3920
updated for version 7.2.428
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
4296 if (qi->qf_lists[qi->qf_curlist].qf_index == 0) |
2795 | 4297 /* no valid entry */ |
2146
c17a42da3920
updated for version 7.2.428
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
4298 qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE; |
c17a42da3920
updated for version 7.2.428
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
4299 else |
c17a42da3920
updated for version 7.2.428
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
4300 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; |
8932
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4301 if (action != 'a') { |
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4302 qi->qf_lists[qi->qf_curlist].qf_ptr = |
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4303 qi->qf_lists[qi->qf_curlist].qf_start; |
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4304 if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4305 qi->qf_lists[qi->qf_curlist].qf_index = 1; |
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4306 } |
230 | 4307 |
4308 #ifdef FEAT_WINDOWS | |
8932
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4309 /* Don't update the cursor in quickfix window when appending entries */ |
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4310 qf_update_buffer(qi, (action != 'a')); |
230 | 4311 #endif |
4312 | |
4313 return retval; | |
4314 } | |
170 | 4315 #endif |
4316 | |
42 | 4317 /* |
41 | 4318 * ":[range]cbuffer [bufnr]" command. |
657 | 4319 * ":[range]caddbuffer [bufnr]" command. |
798 | 4320 * ":[range]cgetbuffer [bufnr]" command. |
644 | 4321 * ":[range]lbuffer [bufnr]" command. |
657 | 4322 * ":[range]laddbuffer [bufnr]" command. |
798 | 4323 * ":[range]lgetbuffer [bufnr]" command. |
41 | 4324 */ |
4325 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4326 ex_cbuffer(exarg_T *eap) |
41 | 4327 { |
4328 buf_T *buf = NULL; | |
644 | 4329 qf_info_T *qi = &ql_info; |
4330 | |
798 | 4331 if (eap->cmdidx == CMD_lbuffer || eap->cmdidx == CMD_lgetbuffer |
4332 || eap->cmdidx == CMD_laddbuffer) | |
644 | 4333 { |
4334 qi = ll_get_or_alloc_list(curwin); | |
4335 if (qi == NULL) | |
4336 return; | |
4337 } | |
41 | 4338 |
4339 if (*eap->arg == NUL) | |
4340 buf = curbuf; | |
4341 else if (*skipwhite(skipdigits(eap->arg)) == NUL) | |
4342 buf = buflist_findnr(atoi((char *)eap->arg)); | |
4343 if (buf == NULL) | |
4344 EMSG(_(e_invarg)); | |
4345 else if (buf->b_ml.ml_mfp == NULL) | |
4346 EMSG(_("E681: Buffer is not loaded")); | |
4347 else | |
4348 { | |
4349 if (eap->addr_count == 0) | |
4350 { | |
4351 eap->line1 = 1; | |
4352 eap->line2 = buf->b_ml.ml_line_count; | |
4353 } | |
4354 if (eap->line1 < 1 || eap->line1 > buf->b_ml.ml_line_count | |
4355 || eap->line2 < 1 || eap->line2 > buf->b_ml.ml_line_count) | |
4356 EMSG(_(e_invrange)); | |
4357 else | |
661 | 4358 { |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4359 char_u *qf_title = *eap->cmdlinep; |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4360 |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4361 if (buf->b_sfname) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4362 { |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4363 vim_snprintf((char *)IObuff, IOSIZE, "%s (%s)", |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4364 (char *)qf_title, (char *)buf->b_sfname); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4365 qf_title = IObuff; |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4366 } |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4367 |
798 | 4368 if (qf_init_ext(qi, NULL, buf, NULL, p_efm, |
4369 (eap->cmdidx != CMD_caddbuffer | |
4370 && eap->cmdidx != CMD_laddbuffer), | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4371 eap->line1, eap->line2, |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4372 qf_title) > 0 |
798 | 4373 && (eap->cmdidx == CMD_cbuffer |
4374 || eap->cmdidx == CMD_lbuffer)) | |
661 | 4375 qf_jump(qi, 0, 0, eap->forceit); /* display first error */ |
4376 } | |
41 | 4377 } |
4378 } | |
4379 | |
532 | 4380 #if defined(FEAT_EVAL) || defined(PROTO) |
41 | 4381 /* |
798 | 4382 * ":cexpr {expr}", ":cgetexpr {expr}", ":caddexpr {expr}" command. |
4383 * ":lexpr {expr}", ":lgetexpr {expr}", ":laddexpr {expr}" command. | |
446 | 4384 */ |
4385 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4386 ex_cexpr(exarg_T *eap) |
446 | 4387 { |
4388 typval_T *tv; | |
644 | 4389 qf_info_T *qi = &ql_info; |
4390 | |
798 | 4391 if (eap->cmdidx == CMD_lexpr || eap->cmdidx == CMD_lgetexpr |
4392 || eap->cmdidx == CMD_laddexpr) | |
644 | 4393 { |
4394 qi = ll_get_or_alloc_list(curwin); | |
4395 if (qi == NULL) | |
4396 return; | |
4397 } | |
446 | 4398 |
625 | 4399 /* Evaluate the expression. When the result is a string or a list we can |
4400 * use it to fill the errorlist. */ | |
446 | 4401 tv = eval_expr(eap->arg, NULL); |
625 | 4402 if (tv != NULL) |
4403 { | |
4404 if ((tv->v_type == VAR_STRING && tv->vval.v_string != NULL) | |
4405 || (tv->v_type == VAR_LIST && tv->vval.v_list != NULL)) | |
4406 { | |
7701
075810b0cb6c
commit https://github.com/vim/vim/commit/d6357e8f93c50f984ffd69c3a0d247d8603f86c3
Christian Brabandt <cb@256bit.org>
parents:
7662
diff
changeset
|
4407 if (qf_init_ext(qi, NULL, NULL, tv, p_efm, |
798 | 4408 (eap->cmdidx != CMD_caddexpr |
4409 && eap->cmdidx != CMD_laddexpr), | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4410 (linenr_T)0, (linenr_T)0, *eap->cmdlinep) > 0 |
798 | 4411 && (eap->cmdidx == CMD_cexpr |
4412 || eap->cmdidx == CMD_lexpr)) | |
659 | 4413 qf_jump(qi, 0, 0, eap->forceit); /* display first error */ |
625 | 4414 } |
4415 else | |
626 | 4416 EMSG(_("E777: String or List expected")); |
625 | 4417 free_tv(tv); |
4418 } | |
446 | 4419 } |
532 | 4420 #endif |
446 | 4421 |
4422 /* | |
7 | 4423 * ":helpgrep {pattern}" |
4424 */ | |
4425 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4426 ex_helpgrep(exarg_T *eap) |
7 | 4427 { |
4428 regmatch_T regmatch; | |
4429 char_u *save_cpo; | |
4430 char_u *p; | |
4431 int fcount; | |
4432 char_u **fnames; | |
4433 FILE *fd; | |
4434 int fi; | |
230 | 4435 qfline_T *prevp = NULL; |
7 | 4436 long lnum; |
9 | 4437 #ifdef FEAT_MULTI_LANG |
4438 char_u *lang; | |
4439 #endif | |
644 | 4440 qf_info_T *qi = &ql_info; |
659 | 4441 int new_qi = FALSE; |
4442 win_T *wp; | |
3269 | 4443 #ifdef FEAT_AUTOCMD |
4444 char_u *au_name = NULL; | |
4445 #endif | |
7 | 4446 |
9 | 4447 #ifdef FEAT_MULTI_LANG |
4448 /* Check for a specified language */ | |
4449 lang = check_help_lang(eap->arg); | |
4450 #endif | |
4451 | |
3269 | 4452 #ifdef FEAT_AUTOCMD |
4453 switch (eap->cmdidx) | |
4454 { | |
4455 case CMD_helpgrep: au_name = (char_u *)"helpgrep"; break; | |
4456 case CMD_lhelpgrep: au_name = (char_u *)"lhelpgrep"; break; | |
4457 default: break; | |
4458 } | |
4459 if (au_name != NULL) | |
4460 { | |
4461 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, | |
4462 curbuf->b_fname, TRUE, curbuf); | |
4463 if (did_throw || force_abort) | |
4464 return; | |
4465 } | |
4466 #endif | |
4467 | |
4468 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ | |
4469 save_cpo = p_cpo; | |
4470 p_cpo = empty_option; | |
4471 | |
659 | 4472 if (eap->cmdidx == CMD_lhelpgrep) |
4473 { | |
4474 /* Find an existing help window */ | |
4475 FOR_ALL_WINDOWS(wp) | |
4476 if (wp->w_buffer != NULL && wp->w_buffer->b_help) | |
4477 break; | |
4478 | |
4479 if (wp == NULL) /* Help window not found */ | |
4480 qi = NULL; | |
4481 else | |
4482 qi = wp->w_llist; | |
4483 | |
4484 if (qi == NULL) | |
4485 { | |
4486 /* Allocate a new location list for help text matches */ | |
4487 if ((qi = ll_new_list()) == NULL) | |
4488 return; | |
4489 new_qi = TRUE; | |
4490 } | |
4491 } | |
4492 | |
7 | 4493 regmatch.regprog = vim_regcomp(eap->arg, RE_MAGIC + RE_STRING); |
4494 regmatch.rm_ic = FALSE; | |
4495 if (regmatch.regprog != NULL) | |
4496 { | |
3257 | 4497 #ifdef FEAT_MBYTE |
4498 vimconv_T vc; | |
4499 | |
4500 /* Help files are in utf-8 or latin1, convert lines when 'encoding' | |
4501 * differs. */ | |
4502 vc.vc_type = CONV_NONE; | |
4503 if (!enc_utf8) | |
4504 convert_setup(&vc, (char_u *)"utf-8", p_enc); | |
4505 #endif | |
4506 | |
7 | 4507 /* create a new quickfix list */ |
3965 | 4508 qf_new_list(qi, *eap->cmdlinep); |
7 | 4509 |
4510 /* Go through all directories in 'runtimepath' */ | |
4511 p = p_rtp; | |
4512 while (*p != NUL && !got_int) | |
4513 { | |
4514 copy_option_part(&p, NameBuff, MAXPATHL, ","); | |
4515 | |
4516 /* Find all "*.txt" and "*.??x" files in the "doc" directory. */ | |
4517 add_pathsep(NameBuff); | |
4518 STRCAT(NameBuff, "doc/*.\\(txt\\|??x\\)"); | |
4519 if (gen_expand_wildcards(1, &NameBuff, &fcount, | |
4520 &fnames, EW_FILE|EW_SILENT) == OK | |
4521 && fcount > 0) | |
4522 { | |
4523 for (fi = 0; fi < fcount && !got_int; ++fi) | |
4524 { | |
9 | 4525 #ifdef FEAT_MULTI_LANG |
4526 /* Skip files for a different language. */ | |
4527 if (lang != NULL | |
4528 && STRNICMP(lang, fnames[fi] | |
4529 + STRLEN(fnames[fi]) - 3, 2) != 0 | |
4530 && !(STRNICMP(lang, "en", 2) == 0 | |
4531 && STRNICMP("txt", fnames[fi] | |
4532 + STRLEN(fnames[fi]) - 3, 3) == 0)) | |
4533 continue; | |
4534 #endif | |
531 | 4535 fd = mch_fopen((char *)fnames[fi], "r"); |
7 | 4536 if (fd != NULL) |
4537 { | |
4538 lnum = 1; | |
4539 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) | |
4540 { | |
3257 | 4541 char_u *line = IObuff; |
4542 #ifdef FEAT_MBYTE | |
4543 /* Convert a line if 'encoding' is not utf-8 and | |
4544 * the line contains a non-ASCII character. */ | |
4545 if (vc.vc_type != CONV_NONE | |
4546 && has_non_ascii(IObuff)) { | |
4547 line = string_convert(&vc, IObuff, NULL); | |
4548 if (line == NULL) | |
4549 line = IObuff; | |
4550 } | |
4551 #endif | |
4552 | |
4553 if (vim_regexec(®match, line, (colnr_T)0)) | |
7 | 4554 { |
3257 | 4555 int l = (int)STRLEN(line); |
7 | 4556 |
4557 /* remove trailing CR, LF, spaces, etc. */ | |
3257 | 4558 while (l > 0 && line[l - 1] <= ' ') |
4559 line[--l] = NUL; | |
7 | 4560 |
644 | 4561 if (qf_add_entry(qi, &prevp, |
7 | 4562 NULL, /* dir */ |
4563 fnames[fi], | |
1065 | 4564 0, |
3257 | 4565 line, |
7 | 4566 lnum, |
3257 | 4567 (int)(regmatch.startp[0] - line) |
42 | 4568 + 1, /* col */ |
170 | 4569 FALSE, /* vis_col */ |
230 | 4570 NULL, /* search pattern */ |
7 | 4571 0, /* nr */ |
4572 1, /* type */ | |
4573 TRUE /* valid */ | |
4574 ) == FAIL) | |
4575 { | |
4576 got_int = TRUE; | |
3257 | 4577 #ifdef FEAT_MBYTE |
4578 if (line != IObuff) | |
4579 vim_free(line); | |
4580 #endif | |
7 | 4581 break; |
4582 } | |
4583 } | |
3257 | 4584 #ifdef FEAT_MBYTE |
4585 if (line != IObuff) | |
4586 vim_free(line); | |
4587 #endif | |
7 | 4588 ++lnum; |
4589 line_breakcheck(); | |
4590 } | |
4591 fclose(fd); | |
4592 } | |
4593 } | |
4594 FreeWild(fcount, fnames); | |
4595 } | |
4596 } | |
3257 | 4597 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4371
diff
changeset
|
4598 vim_regfree(regmatch.regprog); |
3257 | 4599 #ifdef FEAT_MBYTE |
4600 if (vc.vc_type != CONV_NONE) | |
4601 convert_setup(&vc, NULL, NULL); | |
4602 #endif | |
7 | 4603 |
644 | 4604 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; |
4605 qi->qf_lists[qi->qf_curlist].qf_ptr = | |
4606 qi->qf_lists[qi->qf_curlist].qf_start; | |
4607 qi->qf_lists[qi->qf_curlist].qf_index = 1; | |
7 | 4608 } |
4609 | |
1672 | 4610 if (p_cpo == empty_option) |
4611 p_cpo = save_cpo; | |
4612 else | |
4613 /* Darn, some plugin changed the value. */ | |
4614 free_string_option(save_cpo); | |
7 | 4615 |
4616 #ifdef FEAT_WINDOWS | |
8932
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4617 qf_update_buffer(qi, TRUE); |
7 | 4618 #endif |
4619 | |
3269 | 4620 #ifdef FEAT_AUTOCMD |
4621 if (au_name != NULL) | |
4622 { | |
4623 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, | |
4624 curbuf->b_fname, TRUE, curbuf); | |
4625 if (!new_qi && qi != &ql_info && qf_find_buf(qi) == NULL) | |
4626 /* autocommands made "qi" invalid */ | |
4627 return; | |
4628 } | |
4629 #endif | |
4630 | |
7 | 4631 /* Jump to first match. */ |
644 | 4632 if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
659 | 4633 qf_jump(qi, 0, 0, FALSE); |
9 | 4634 else |
4635 EMSG2(_(e_nomatch2), eap->arg); | |
659 | 4636 |
4637 if (eap->cmdidx == CMD_lhelpgrep) | |
4638 { | |
4639 /* If the help window is not opened or if it already points to the | |
661 | 4640 * correct location list, then free the new location list. */ |
659 | 4641 if (!curwin->w_buffer->b_help || curwin->w_llist == qi) |
4642 { | |
4643 if (new_qi) | |
4644 ll_free_all(&qi); | |
4645 } | |
4646 else if (curwin->w_llist == NULL) | |
4647 curwin->w_llist = qi; | |
4648 } | |
7 | 4649 } |
4650 | |
4651 #endif /* FEAT_QUICKFIX */ |