Mercurial > vim
annotate src/if_cscope.c @ 17986:5c8906f653f5 v8.1.1989
patch 8.1.1989: the evalfunc.c file is still too big
Commit: https://github.com/vim/vim/commit/af7645d3733fdd3cd2df03ec7b653601d26969ef
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 5 22:33:28 2019 +0200
patch 8.1.1989: the evalfunc.c file is still too big
Problem: The evalfunc.c file is still too big.
Solution: Move f_pathshorten() to filepath.c. Move f_cscope_connection() to
if_cscope.c. Move diff_ functions to diff.c. Move timer_
functions to ex_cmds2.c. move callback functions to evalvars.c.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 05 Sep 2019 22:45:04 +0200 |
parents | 46f95606b9ec |
children | 8976c3a3803a |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9418
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * CSCOPE support for Vim added by Andy Kahn <kahn@zk3.dec.com> | |
148 | 4 * Ported to Win32 by Sergey Khorev <sergey.khorev@gmail.com> |
7 | 5 * |
6 * The basic idea/structure of cscope for Vim was borrowed from Nvi. There | |
7 * might be a few lines of code that look similar to what Nvi has. | |
8 * | |
9 * See README.txt for an overview of the Vim source code. | |
10 */ | |
11 | |
12 #include "vim.h" | |
13 | |
14 #if defined(FEAT_CSCOPE) || defined(PROTO) | |
15 | |
16 #include <sys/types.h> | |
17 #include <sys/stat.h> | |
18 #if defined(UNIX) | |
19 # include <sys/wait.h> | |
20 #endif | |
21 #include "if_cscope.h" | |
22 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
23 static int cs_add(exarg_T *eap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
24 static int cs_add_common(char *, char *, char *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
25 static int cs_check_for_connections(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
26 static int cs_check_for_tags(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
27 static int cs_cnt_connections(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
28 static int cs_create_connection(int i); |
636 | 29 #ifdef FEAT_QUICKFIX |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
30 static void cs_file_results(FILE *, int *); |
636 | 31 #endif |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
32 static void cs_fill_results(char *, int , int *, char ***, |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
33 char ***, int *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
34 static int cs_find(exarg_T *eap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
35 static int cs_find_common(char *opt, char *pat, int, int, int, char_u *cmdline); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
36 static int cs_help(exarg_T *eap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
37 static int cs_insert_filelist(char *, char *, char *, |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9340
diff
changeset
|
38 stat_T *); |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
39 static int cs_kill(exarg_T *eap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
40 static void cs_kill_execute(int, char *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
41 static cscmd_T * cs_lookup_cmd(exarg_T *eap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
42 static char * cs_make_vim_style_matches(char *, char *, |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
43 char *, char *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
44 static char * cs_manage_matches(char **, char **, int, mcmd_e); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
45 static void cs_print_tags_priv(char **, char **, int); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
46 static int cs_read_prompt(int); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
47 static void cs_release_csp(int, int freefnpp); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
48 static int cs_reset(exarg_T *eap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
49 static char * cs_resolve_file(int, char *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
50 static int cs_show(exarg_T *eap); |
7 | 51 |
52 | |
1931 | 53 static csinfo_T * csinfo = NULL; |
54 static int csinfo_size = 0; /* number of items allocated in | |
55 csinfo[] */ | |
56 | |
1372 | 57 static int eap_arg_len; /* length of eap->arg, set in |
58 cs_lookup_cmd() */ | |
7 | 59 static cscmd_T cs_cmds[] = |
60 { | |
61 { "add", cs_add, | |
62 N_("Add a new database"), "add file|dir [pre-path] [flags]", 0 }, | |
63 { "find", cs_find, | |
9418
6d213bd46cc3
commit https://github.com/vim/vim/commit/80632db65e8f5f775dadbbc10c5ba6c173ebb24f
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
64 N_("Query for a pattern"), "find a|c|d|e|f|g|i|s|t name", 1 }, |
7 | 65 { "help", cs_help, |
66 N_("Show this message"), "help", 0 }, | |
67 { "kill", cs_kill, | |
68 N_("Kill a connection"), "kill #", 0 }, | |
69 { "reset", cs_reset, | |
70 N_("Reinit all connections"), "reset", 0 }, | |
71 { "show", cs_show, | |
72 N_("Show connections"), "show", 0 }, | |
1880 | 73 { NULL, NULL, NULL, NULL, 0 } |
7 | 74 }; |
75 | |
76 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
77 cs_usage_msg(csid_e x) |
7 | 78 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
79 (void)semsg(_("E560: Usage: cs[cope] %s"), cs_cmds[(int)x].usage); |
7 | 80 } |
81 | |
1845 | 82 static enum |
83 { | |
84 EXP_CSCOPE_SUBCMD, /* expand ":cscope" sub-commands */ | |
1858 | 85 EXP_SCSCOPE_SUBCMD, /* expand ":scscope" sub-commands */ |
1845 | 86 EXP_CSCOPE_FIND, /* expand ":cscope find" arguments */ |
87 EXP_CSCOPE_KILL /* expand ":cscope kill" arguments */ | |
88 } expand_what; | |
89 | |
90 /* | |
91 * Function given to ExpandGeneric() to obtain the cscope command | |
92 * expansion. | |
93 */ | |
94 char_u * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
95 get_cscope_name(expand_T *xp UNUSED, int idx) |
1845 | 96 { |
1858 | 97 int current_idx; |
98 int i; | |
99 | |
1845 | 100 switch (expand_what) |
101 { | |
102 case EXP_CSCOPE_SUBCMD: | |
103 /* Complete with sub-commands of ":cscope": | |
104 * add, find, help, kill, reset, show */ | |
105 return (char_u *)cs_cmds[idx].name; | |
1858 | 106 case EXP_SCSCOPE_SUBCMD: |
107 /* Complete with sub-commands of ":scscope": same sub-commands as | |
108 * ":cscope" but skip commands which don't support split windows */ | |
109 for (i = 0, current_idx = 0; cs_cmds[i].name != NULL; i++) | |
110 if (cs_cmds[i].cansplit) | |
111 if (current_idx++ == idx) | |
112 break; | |
113 return (char_u *)cs_cmds[i].name; | |
1845 | 114 case EXP_CSCOPE_FIND: |
115 { | |
116 const char *query_type[] = | |
117 { | |
9418
6d213bd46cc3
commit https://github.com/vim/vim/commit/80632db65e8f5f775dadbbc10c5ba6c173ebb24f
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
118 "a", "c", "d", "e", "f", "g", "i", "s", "t", NULL |
1845 | 119 }; |
120 | |
121 /* Complete with query type of ":cscope find {query_type}". | |
9340
387cd517939f
commit https://github.com/vim/vim/commit/b12e7ef956e0b0344778b7ef93d41f4b4ed2a670
Christian Brabandt <cb@256bit.org>
parents:
8234
diff
changeset
|
122 * {query_type} can be letters (c, d, ... a) or numbers (0, 1, |
387cd517939f
commit https://github.com/vim/vim/commit/b12e7ef956e0b0344778b7ef93d41f4b4ed2a670
Christian Brabandt <cb@256bit.org>
parents:
8234
diff
changeset
|
123 * ..., 9) but only complete with letters, since numbers are |
1845 | 124 * redundant. */ |
125 return (char_u *)query_type[idx]; | |
126 } | |
127 case EXP_CSCOPE_KILL: | |
128 { | |
1931 | 129 static char connection[5]; |
1845 | 130 |
131 /* ":cscope kill" accepts connection numbers or partial names of | |
132 * the pathname of the cscope database as argument. Only complete | |
133 * with connection numbers. -1 can also be used to kill all | |
134 * connections. */ | |
1931 | 135 for (i = 0, current_idx = 0; i < csinfo_size; i++) |
1845 | 136 { |
137 if (csinfo[i].fname == NULL) | |
138 continue; | |
139 if (current_idx++ == idx) | |
140 { | |
1931 | 141 vim_snprintf(connection, sizeof(connection), "%d", i); |
142 return (char_u *)connection; | |
1845 | 143 } |
144 } | |
145 return (current_idx == idx && idx > 0) ? (char_u *)"-1" : NULL; | |
146 } | |
147 default: | |
148 return NULL; | |
149 } | |
150 } | |
151 | |
152 /* | |
153 * Handle command line completion for :cscope command. | |
154 */ | |
155 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
156 set_context_in_cscope_cmd( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
157 expand_T *xp, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
158 char_u *arg, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
159 cmdidx_T cmdidx) |
1845 | 160 { |
161 char_u *p; | |
162 | |
163 /* Default: expand subcommands */ | |
164 xp->xp_context = EXPAND_CSCOPE; | |
165 xp->xp_pattern = arg; | |
1858 | 166 expand_what = (cmdidx == CMD_scscope) |
167 ? EXP_SCSCOPE_SUBCMD : EXP_CSCOPE_SUBCMD; | |
1845 | 168 |
169 /* (part of) subcommand already typed */ | |
170 if (*arg != NUL) | |
171 { | |
172 p = skiptowhite(arg); | |
173 if (*p != NUL) /* past first word */ | |
174 { | |
175 xp->xp_pattern = skipwhite(p); | |
176 if (*skiptowhite(xp->xp_pattern) != NUL) | |
177 xp->xp_context = EXPAND_NOTHING; | |
178 else if (STRNICMP(arg, "add", p - arg) == 0) | |
179 xp->xp_context = EXPAND_FILES; | |
180 else if (STRNICMP(arg, "kill", p - arg) == 0) | |
181 expand_what = EXP_CSCOPE_KILL; | |
182 else if (STRNICMP(arg, "find", p - arg) == 0) | |
183 expand_what = EXP_CSCOPE_FIND; | |
184 else | |
185 xp->xp_context = EXPAND_NOTHING; | |
186 } | |
187 } | |
188 } | |
189 | |
7 | 190 /* |
1845 | 191 * Find the command, print help if invalid, and then call the corresponding |
192 * command function. | |
7 | 193 */ |
194 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
195 do_cscope_general( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
196 exarg_T *eap, |
10605
9279c939391b
patch 8.0.0192: cannot build with tiny features
Christian Brabandt <cb@256bit.org>
parents:
10373
diff
changeset
|
197 int make_split UNUSED) /* whether to split window */ |
7 | 198 { |
199 cscmd_T *cmdp; | |
200 | |
201 if ((cmdp = cs_lookup_cmd(eap)) == NULL) | |
202 { | |
203 cs_help(eap); | |
204 return; | |
205 } | |
206 | |
207 if (make_split) | |
208 { | |
209 if (!cmdp->cansplit) | |
210 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
211 (void)msg_puts(_("This cscope command does not support splitting the window.\n")); |
7 | 212 return; |
213 } | |
214 postponed_split = -1; | |
215 postponed_split_flags = cmdmod.split; | |
1090 | 216 postponed_split_tab = cmdmod.tab; |
7 | 217 } |
218 | |
219 cmdp->func(eap); | |
220 | |
221 postponed_split_flags = 0; | |
1090 | 222 postponed_split_tab = 0; |
7 | 223 } |
224 | |
225 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
226 * Implementation of ":cscope" and ":lcscope" |
7 | 227 */ |
228 void | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
229 ex_cscope(exarg_T *eap) |
7 | 230 { |
231 do_cscope_general(eap, FALSE); | |
232 } | |
233 | |
234 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
235 * Implementation of ":scscope". Same as ex_cscope(), but splits window, too. |
7 | 236 */ |
237 void | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
238 ex_scscope(exarg_T *eap) |
7 | 239 { |
240 do_cscope_general(eap, TRUE); | |
241 } | |
242 | |
243 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
244 * Implementation of ":cstag" |
7 | 245 */ |
246 void | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
247 ex_cstag(exarg_T *eap) |
7 | 248 { |
249 int ret = FALSE; | |
250 | |
1621 | 251 if (*eap->arg == NUL) |
7 | 252 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
253 (void)emsg(_("E562: Usage: cstag <ident>")); |
7 | 254 return; |
255 } | |
256 | |
257 switch (p_csto) | |
258 { | |
259 case 0 : | |
260 if (cs_check_for_connections()) | |
261 { | |
665 | 262 ret = cs_find_common("g", (char *)(eap->arg), eap->forceit, FALSE, |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
263 FALSE, *eap->cmdlinep); |
7 | 264 if (ret == FALSE) |
265 { | |
266 cs_free_tags(); | |
267 if (msg_col) | |
268 msg_putchar('\n'); | |
269 | |
270 if (cs_check_for_tags()) | |
271 ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE); | |
272 } | |
273 } | |
274 else if (cs_check_for_tags()) | |
275 { | |
276 ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE); | |
277 } | |
278 break; | |
279 case 1 : | |
280 if (cs_check_for_tags()) | |
281 { | |
282 ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE); | |
283 if (ret == FALSE) | |
284 { | |
285 if (msg_col) | |
286 msg_putchar('\n'); | |
287 | |
288 if (cs_check_for_connections()) | |
289 { | |
290 ret = cs_find_common("g", (char *)(eap->arg), eap->forceit, | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
291 FALSE, FALSE, *eap->cmdlinep); |
7 | 292 if (ret == FALSE) |
293 cs_free_tags(); | |
294 } | |
295 } | |
296 } | |
297 else if (cs_check_for_connections()) | |
298 { | |
665 | 299 ret = cs_find_common("g", (char *)(eap->arg), eap->forceit, FALSE, |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
300 FALSE, *eap->cmdlinep); |
7 | 301 if (ret == FALSE) |
302 cs_free_tags(); | |
303 } | |
304 break; | |
305 default : | |
306 break; | |
307 } | |
308 | |
309 if (!ret) | |
310 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
311 (void)emsg(_("E257: cstag: tag not found")); |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
312 #if defined(FEAT_QUICKFIX) |
7 | 313 g_do_tagpreview = 0; |
314 #endif | |
315 } | |
316 | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
317 } |
7 | 318 |
319 | |
320 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
321 * This simulates a vim_fgets(), but for cscope, returns the next line |
7 | 322 * from the cscope output. should only be called from find_tags() |
323 * | |
324 * returns TRUE if eof, FALSE otherwise | |
325 */ | |
326 int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
327 cs_fgets(char_u *buf, int size) |
7 | 328 { |
329 char *p; | |
330 | |
331 if ((p = cs_manage_matches(NULL, NULL, -1, Get)) == NULL) | |
332 return TRUE; | |
1372 | 333 vim_strncpy(buf, (char_u *)p, size - 1); |
7 | 334 |
335 return FALSE; | |
336 } /* cs_fgets */ | |
337 | |
338 | |
339 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
340 * Called only from do_tag(), when popping the tag stack. |
7 | 341 */ |
342 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
343 cs_free_tags(void) |
7 | 344 { |
345 cs_manage_matches(NULL, NULL, -1, Free); | |
346 } | |
347 | |
348 | |
349 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
350 * Called from do_tag(). |
7 | 351 */ |
352 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
353 cs_print_tags(void) |
7 | 354 { |
355 cs_manage_matches(NULL, NULL, -1, Print); | |
356 } | |
357 | |
358 | |
359 /* | |
360 * "cscope_connection([{num} , {dbpath} [, {prepend}]])" function | |
361 * | |
362 * Checks for the existence of a |cscope| connection. If no | |
363 * parameters are specified, then the function returns: | |
364 * | |
365 * 0, if cscope was not available (not compiled in), or if there | |
366 * are no cscope connections; or | |
367 * 1, if there is at least one cscope connection. | |
368 * | |
369 * If parameters are specified, then the value of {num} | |
370 * determines how existence of a cscope connection is checked: | |
371 * | |
372 * {num} Description of existence check | |
373 * ----- ------------------------------ | |
374 * 0 Same as no parameters (e.g., "cscope_connection()"). | |
375 * 1 Ignore {prepend}, and use partial string matches for | |
376 * {dbpath}. | |
377 * 2 Ignore {prepend}, and use exact string matches for | |
378 * {dbpath}. | |
379 * 3 Use {prepend}, use partial string matches for both | |
380 * {dbpath} and {prepend}. | |
381 * 4 Use {prepend}, use exact string matches for both | |
382 * {dbpath} and {prepend}. | |
383 * | |
384 * Note: All string comparisons are case sensitive! | |
385 */ | |
386 #if defined(FEAT_EVAL) || defined(PROTO) | |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
387 static int |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
388 cs_connection(int num, char_u *dbpath, char_u *ppath) |
7 | 389 { |
390 int i; | |
391 | |
392 if (num < 0 || num > 4 || (num > 0 && !dbpath)) | |
393 return FALSE; | |
394 | |
1931 | 395 for (i = 0; i < csinfo_size; i++) |
7 | 396 { |
397 if (!csinfo[i].fname) | |
398 continue; | |
399 | |
400 if (num == 0) | |
401 return TRUE; | |
402 | |
403 switch (num) | |
404 { | |
405 case 1: | |
406 if (strstr(csinfo[i].fname, (char *)dbpath)) | |
407 return TRUE; | |
408 break; | |
409 case 2: | |
410 if (strcmp(csinfo[i].fname, (char *)dbpath) == 0) | |
411 return TRUE; | |
412 break; | |
413 case 3: | |
414 if (strstr(csinfo[i].fname, (char *)dbpath) | |
415 && ((!ppath && !csinfo[i].ppath) | |
416 || (ppath | |
417 && csinfo[i].ppath | |
418 && strstr(csinfo[i].ppath, (char *)ppath)))) | |
419 return TRUE; | |
420 break; | |
421 case 4: | |
422 if ((strcmp(csinfo[i].fname, (char *)dbpath) == 0) | |
423 && ((!ppath && !csinfo[i].ppath) | |
424 || (ppath | |
425 && csinfo[i].ppath | |
426 && (strcmp(csinfo[i].ppath, (char *)ppath) == 0)))) | |
427 return TRUE; | |
428 break; | |
429 } | |
430 } | |
431 | |
432 return FALSE; | |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
433 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
434 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
435 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
436 * "cscope_connection([{num} , {dbpath} [, {prepend}]])" function |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
437 * |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
438 * Checks the existence of a cscope connection. |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
439 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
440 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
441 f_cscope_connection(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
442 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
443 #ifdef FEAT_CSCOPE |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
444 int num = 0; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
445 char_u *dbpath = NULL; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
446 char_u *prepend = NULL; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
447 char_u buf[NUMBUFLEN]; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
448 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
449 if (argvars[0].v_type != VAR_UNKNOWN |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
450 && argvars[1].v_type != VAR_UNKNOWN) |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
451 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
452 num = (int)tv_get_number(&argvars[0]); |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
453 dbpath = tv_get_string(&argvars[1]); |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
454 if (argvars[2].v_type != VAR_UNKNOWN) |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
455 prepend = tv_get_string_buf(&argvars[2], buf); |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
456 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
457 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
458 rettv->vval.v_number = cs_connection(num, dbpath, prepend); |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
459 #endif |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
460 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
461 |
7 | 462 #endif |
463 | |
464 | |
465 /* | |
466 * PRIVATE functions | |
467 ****************************************************************************/ | |
468 | |
469 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
470 * Add cscope database or a directory name (to look for cscope.out) |
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
471 * to the cscope connection list. |
7 | 472 */ |
473 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
474 cs_add(exarg_T *eap UNUSED) |
7 | 475 { |
476 char *fname, *ppath, *flags = NULL; | |
477 | |
478 if ((fname = strtok((char *)NULL, (const char *)" ")) == NULL) | |
479 { | |
480 cs_usage_msg(Add); | |
481 return CSCOPE_FAILURE; | |
482 } | |
483 if ((ppath = strtok((char *)NULL, (const char *)" ")) != NULL) | |
484 flags = strtok((char *)NULL, (const char *)" "); | |
485 | |
486 return cs_add_common(fname, ppath, flags); | |
487 } | |
488 | |
489 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
490 cs_stat_emsg(char *fname) |
7 | 491 { |
492 char *stat_emsg = _("E563: stat(%s) error: %d"); | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
493 char *buf = alloc(strlen(stat_emsg) + MAXPATHL + 10); |
7 | 494 |
495 if (buf != NULL) | |
496 { | |
497 (void)sprintf(buf, stat_emsg, fname, errno); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
498 (void)emsg(buf); |
7 | 499 vim_free(buf); |
500 } | |
501 else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
502 (void)emsg(_("E563: stat error")); |
7 | 503 } |
504 | |
505 | |
506 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
507 * The common routine to add a new cscope connection. Called by |
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
508 * cs_add() and cs_reset(). I really don't like to do this, but this |
7 | 509 * routine uses a number of goto statements. |
510 */ | |
511 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
512 cs_add_common( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
513 char *arg1, /* filename - may contain environment variables */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
514 char *arg2, /* prepend path - may contain environment variables */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
515 char *flags) |
7 | 516 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9340
diff
changeset
|
517 stat_T statbuf; |
12 | 518 int ret; |
519 char *fname = NULL; | |
520 char *fname2 = NULL; | |
521 char *ppath = NULL; | |
522 int i; | |
4867
04b8912a9c85
updated for version 7.3.1180
Bram Moolenaar <bram@vim.org>
parents:
4581
diff
changeset
|
523 int len; |
04b8912a9c85
updated for version 7.3.1180
Bram Moolenaar <bram@vim.org>
parents:
4581
diff
changeset
|
524 int usedlen = 0; |
04b8912a9c85
updated for version 7.3.1180
Bram Moolenaar <bram@vim.org>
parents:
4581
diff
changeset
|
525 char_u *fbuf = NULL; |
7 | 526 |
527 /* get the filename (arg1), expand it, and try to stat it */ | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
528 if ((fname = alloc(MAXPATHL + 1)) == NULL) |
7 | 529 goto add_err; |
530 | |
531 expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL); | |
4867
04b8912a9c85
updated for version 7.3.1180
Bram Moolenaar <bram@vim.org>
parents:
4581
diff
changeset
|
532 len = (int)STRLEN(fname); |
04b8912a9c85
updated for version 7.3.1180
Bram Moolenaar <bram@vim.org>
parents:
4581
diff
changeset
|
533 fbuf = (char_u *)fname; |
14393
c62601adad69
patch 8.1.0211: expanding a file name "~" results in $HOME
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
534 (void)modify_fname((char_u *)":p", FALSE, &usedlen, |
4867
04b8912a9c85
updated for version 7.3.1180
Bram Moolenaar <bram@vim.org>
parents:
4581
diff
changeset
|
535 (char_u **)&fname, &fbuf, &len); |
04b8912a9c85
updated for version 7.3.1180
Bram Moolenaar <bram@vim.org>
parents:
4581
diff
changeset
|
536 if (fname == NULL) |
04b8912a9c85
updated for version 7.3.1180
Bram Moolenaar <bram@vim.org>
parents:
4581
diff
changeset
|
537 goto add_err; |
04b8912a9c85
updated for version 7.3.1180
Bram Moolenaar <bram@vim.org>
parents:
4581
diff
changeset
|
538 fname = (char *)vim_strnsave((char_u *)fname, len); |
04b8912a9c85
updated for version 7.3.1180
Bram Moolenaar <bram@vim.org>
parents:
4581
diff
changeset
|
539 vim_free(fbuf); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
540 |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9340
diff
changeset
|
541 ret = mch_stat(fname, &statbuf); |
7 | 542 if (ret < 0) |
543 { | |
544 staterr: | |
545 if (p_csverbose) | |
546 cs_stat_emsg(fname); | |
547 goto add_err; | |
548 } | |
549 | |
550 /* get the prepend path (arg2), expand it, and try to stat it */ | |
551 if (arg2 != NULL) | |
552 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9340
diff
changeset
|
553 stat_T statbuf2; |
7 | 554 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
555 if ((ppath = alloc(MAXPATHL + 1)) == NULL) |
7 | 556 goto add_err; |
557 | |
558 expand_env((char_u *)arg2, (char_u *)ppath, MAXPATHL); | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9340
diff
changeset
|
559 ret = mch_stat(ppath, &statbuf2); |
7 | 560 if (ret < 0) |
561 goto staterr; | |
562 } | |
563 | |
564 /* if filename is a directory, append the cscope database name to it */ | |
14509
80f715651c4c
patch 8.1.0268: file type checking has too many #ifdef
Christian Brabandt <cb@256bit.org>
parents:
14393
diff
changeset
|
565 if (S_ISDIR(statbuf.st_mode)) |
7 | 566 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
567 fname2 = alloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2); |
7 | 568 if (fname2 == NULL) |
569 goto add_err; | |
570 | |
571 while (fname[strlen(fname)-1] == '/' | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
572 #ifdef MSWIN |
7 | 573 || fname[strlen(fname)-1] == '\\' |
574 #endif | |
575 ) | |
576 { | |
577 fname[strlen(fname)-1] = '\0'; | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2151
diff
changeset
|
578 if (fname[0] == '\0') |
7 | 579 break; |
580 } | |
581 if (fname[0] == '\0') | |
582 (void)sprintf(fname2, "/%s", CSCOPE_DBFILE); | |
583 else | |
584 (void)sprintf(fname2, "%s/%s", fname, CSCOPE_DBFILE); | |
585 | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9340
diff
changeset
|
586 ret = mch_stat(fname2, &statbuf); |
7 | 587 if (ret < 0) |
588 { | |
589 if (p_csverbose) | |
590 cs_stat_emsg(fname2); | |
591 goto add_err; | |
592 } | |
593 | |
594 i = cs_insert_filelist(fname2, ppath, flags, &statbuf); | |
595 } | |
596 else if (S_ISREG(statbuf.st_mode) || S_ISLNK(statbuf.st_mode)) | |
597 { | |
598 i = cs_insert_filelist(fname, ppath, flags, &statbuf); | |
599 } | |
600 else | |
601 { | |
602 if (p_csverbose) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
603 (void)semsg( |
7 | 604 _("E564: %s is not a directory or a valid cscope database"), |
605 fname); | |
606 goto add_err; | |
607 } | |
608 | |
609 if (i != -1) | |
610 { | |
611 if (cs_create_connection(i) == CSCOPE_FAILURE | |
612 || cs_read_prompt(i) == CSCOPE_FAILURE) | |
613 { | |
614 cs_release_csp(i, TRUE); | |
615 goto add_err; | |
616 } | |
617 | |
618 if (p_csverbose) | |
619 { | |
620 msg_clr_eos(); | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
621 (void)smsg_attr(HL_ATTR(HLF_R), |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
622 _("Added cscope database %s"), |
7 | 623 csinfo[i].fname); |
624 } | |
625 } | |
626 | |
627 vim_free(fname); | |
628 vim_free(fname2); | |
629 vim_free(ppath); | |
630 return CSCOPE_SUCCESS; | |
631 | |
632 add_err: | |
633 vim_free(fname2); | |
634 vim_free(fname); | |
635 vim_free(ppath); | |
636 return CSCOPE_FAILURE; | |
637 } /* cs_add_common */ | |
638 | |
639 | |
640 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
641 cs_check_for_connections(void) |
7 | 642 { |
643 return (cs_cnt_connections() > 0); | |
644 } /* cs_check_for_connections */ | |
645 | |
646 | |
647 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
648 cs_check_for_tags(void) |
7 | 649 { |
301 | 650 return (p_tags[0] != NUL && curbuf->b_p_tags != NULL); |
7 | 651 } /* cs_check_for_tags */ |
652 | |
653 | |
654 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
655 * Count the number of cscope connections. |
7 | 656 */ |
657 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
658 cs_cnt_connections(void) |
7 | 659 { |
660 short i; | |
661 short cnt = 0; | |
662 | |
1931 | 663 for (i = 0; i < csinfo_size; i++) |
7 | 664 { |
665 if (csinfo[i].fname != NULL) | |
666 cnt++; | |
667 } | |
668 return cnt; | |
669 } /* cs_cnt_connections */ | |
670 | |
671 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
672 cs_reading_emsg( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
673 int idx) /* connection index */ |
7 | 674 { |
15490
98c35d312987
patch 8.1.0753: printf format not checked for semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
675 semsg(_("E262: error reading cscope connection %d"), idx); |
7 | 676 } |
677 | |
678 #define CSREAD_BUFSIZE 2048 | |
679 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
680 * Count the number of matches for a given cscope connection. |
7 | 681 */ |
682 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
683 cs_cnt_matches(int idx) |
7 | 684 { |
685 char *stok; | |
686 char *buf; | |
13130
161b5fe12b11
patch 8.0.1439: if cscope fails a search Vim may hang
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
687 int nlines = 0; |
7 | 688 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
689 buf = alloc(CSREAD_BUFSIZE); |
7 | 690 if (buf == NULL) |
691 return 0; | |
692 for (;;) | |
693 { | |
694 if (!fgets(buf, CSREAD_BUFSIZE, csinfo[idx].fr_fp)) | |
695 { | |
696 if (feof(csinfo[idx].fr_fp)) | |
697 errno = EIO; | |
698 | |
699 cs_reading_emsg(idx); | |
700 | |
701 vim_free(buf); | |
702 return -1; | |
703 } | |
704 | |
705 /* | |
706 * If the database is out of date, or there's some other problem, | |
707 * cscope will output error messages before the number-of-lines output. | |
708 * Display/discard any output that doesn't match what we want. | |
1058 | 709 * Accept "\S*cscope: X lines", also matches "mlcscope". |
13130
161b5fe12b11
patch 8.0.1439: if cscope fails a search Vim may hang
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
710 * Bail out for the "Unable to search" error. |
7 | 711 */ |
13136
bc735a129ea9
patch 8.0.1442: using pointer before it is set
Christian Brabandt <cb@256bit.org>
parents:
13130
diff
changeset
|
712 if (strstr((const char *)buf, "Unable to search database") != NULL) |
13130
161b5fe12b11
patch 8.0.1439: if cscope fails a search Vim may hang
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
713 break; |
7 | 714 if ((stok = strtok(buf, (const char *)" ")) == NULL) |
715 continue; | |
1058 | 716 if (strstr((const char *)stok, "cscope:") == NULL) |
7 | 717 continue; |
718 | |
719 if ((stok = strtok(NULL, (const char *)" ")) == NULL) | |
720 continue; | |
721 nlines = atoi(stok); | |
722 if (nlines < 0) | |
723 { | |
724 nlines = 0; | |
725 break; | |
726 } | |
727 | |
728 if ((stok = strtok(NULL, (const char *)" ")) == NULL) | |
729 continue; | |
730 if (strncmp((const char *)stok, "lines", 5)) | |
731 continue; | |
732 | |
733 break; | |
734 } | |
735 | |
736 vim_free(buf); | |
737 return nlines; | |
738 } /* cs_cnt_matches */ | |
739 | |
740 | |
741 /* | |
742 * Creates the actual cscope command query from what the user entered. | |
743 */ | |
744 static char * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
745 cs_create_cmd(char *csoption, char *pattern) |
7 | 746 { |
747 char *cmd; | |
748 short search; | |
1847 | 749 char *pat; |
7 | 750 |
751 switch (csoption[0]) | |
752 { | |
753 case '0' : case 's' : | |
754 search = 0; | |
755 break; | |
756 case '1' : case 'g' : | |
757 search = 1; | |
758 break; | |
759 case '2' : case 'd' : | |
760 search = 2; | |
761 break; | |
762 case '3' : case 'c' : | |
763 search = 3; | |
764 break; | |
765 case '4' : case 't' : | |
766 search = 4; | |
767 break; | |
768 case '6' : case 'e' : | |
769 search = 6; | |
770 break; | |
771 case '7' : case 'f' : | |
772 search = 7; | |
773 break; | |
774 case '8' : case 'i' : | |
775 search = 8; | |
776 break; | |
9340
387cd517939f
commit https://github.com/vim/vim/commit/b12e7ef956e0b0344778b7ef93d41f4b4ed2a670
Christian Brabandt <cb@256bit.org>
parents:
8234
diff
changeset
|
777 case '9' : case 'a' : |
387cd517939f
commit https://github.com/vim/vim/commit/b12e7ef956e0b0344778b7ef93d41f4b4ed2a670
Christian Brabandt <cb@256bit.org>
parents:
8234
diff
changeset
|
778 search = 9; |
387cd517939f
commit https://github.com/vim/vim/commit/b12e7ef956e0b0344778b7ef93d41f4b4ed2a670
Christian Brabandt <cb@256bit.org>
parents:
8234
diff
changeset
|
779 break; |
7 | 780 default : |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
781 (void)emsg(_("E561: unknown cscope search type")); |
7 | 782 cs_usage_msg(Find); |
783 return NULL; | |
784 } | |
785 | |
1847 | 786 /* Skip white space before the patter, except for text and pattern search, |
787 * they may want to use the leading white space. */ | |
788 pat = pattern; | |
789 if (search != 4 && search != 6) | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11063
diff
changeset
|
790 while VIM_ISWHITE(*pat) |
1847 | 791 ++pat; |
792 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
793 if ((cmd = alloc(strlen(pat) + 2)) == NULL) |
7 | 794 return NULL; |
795 | |
1847 | 796 (void)sprintf(cmd, "%d%s", search, pat); |
7 | 797 |
798 return cmd; | |
799 } /* cs_create_cmd */ | |
800 | |
801 | |
802 /* | |
803 * This piece of code was taken/adapted from nvi. do we need to add | |
804 * the BSD license notice? | |
805 */ | |
806 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
807 cs_create_connection(int i) |
7 | 808 { |
1385 | 809 #ifdef UNIX |
810 int to_cs[2], from_cs[2]; | |
811 #endif | |
812 int len; | |
813 char *prog, *cmd, *ppath = NULL; | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
814 #ifdef MSWIN |
1385 | 815 int fd; |
816 SECURITY_ATTRIBUTES sa; | |
817 PROCESS_INFORMATION pi; | |
818 STARTUPINFO si; | |
819 BOOL pipe_stdin = FALSE, pipe_stdout = FALSE; | |
820 HANDLE stdin_rd, stdout_rd; | |
821 HANDLE stdout_wr, stdin_wr; | |
822 BOOL created; | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
823 # if (defined(_MSC_VER) && (_MSC_VER >= 1300)) || defined(__MINGW32__) |
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
824 # define OPEN_OH_ARGTYPE intptr_t |
1393 | 825 # else |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
826 # define OPEN_OH_ARGTYPE long |
1393 | 827 # endif |
7 | 828 #endif |
829 | |
1385 | 830 #if defined(UNIX) |
7 | 831 /* |
832 * Cscope reads from to_cs[0] and writes to from_cs[1]; vi reads from | |
833 * from_cs[0] and writes to to_cs[1]. | |
834 */ | |
835 to_cs[0] = to_cs[1] = from_cs[0] = from_cs[1] = -1; | |
836 if (pipe(to_cs) < 0 || pipe(from_cs) < 0) | |
837 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
838 (void)emsg(_("E566: Could not create cscope pipes")); |
7 | 839 err_closing: |
840 if (to_cs[0] != -1) | |
841 (void)close(to_cs[0]); | |
842 if (to_cs[1] != -1) | |
843 (void)close(to_cs[1]); | |
844 if (from_cs[0] != -1) | |
845 (void)close(from_cs[0]); | |
846 if (from_cs[1] != -1) | |
847 (void)close(from_cs[1]); | |
848 return CSCOPE_FAILURE; | |
849 } | |
850 | |
851 switch (csinfo[i].pid = fork()) | |
852 { | |
853 case -1: | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
854 (void)emsg(_("E622: Could not fork for cscope")); |
7 | 855 goto err_closing; |
856 case 0: /* child: run cscope. */ | |
857 if (dup2(to_cs[0], STDIN_FILENO) == -1) | |
858 PERROR("cs_create_connection 1"); | |
859 if (dup2(from_cs[1], STDOUT_FILENO) == -1) | |
860 PERROR("cs_create_connection 2"); | |
861 if (dup2(from_cs[1], STDERR_FILENO) == -1) | |
862 PERROR("cs_create_connection 3"); | |
863 | |
864 /* close unused */ | |
865 (void)close(to_cs[1]); | |
866 (void)close(from_cs[0]); | |
867 #else | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
868 /* MSWIN */ |
1385 | 869 /* Create pipes to communicate with cscope */ |
870 sa.nLength = sizeof(SECURITY_ATTRIBUTES); | |
871 sa.bInheritHandle = TRUE; | |
872 sa.lpSecurityDescriptor = NULL; | |
873 | |
874 if (!(pipe_stdin = CreatePipe(&stdin_rd, &stdin_wr, &sa, 0)) | |
875 || !(pipe_stdout = CreatePipe(&stdout_rd, &stdout_wr, &sa, 0))) | |
876 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
877 (void)emsg(_("E566: Could not create cscope pipes")); |
1385 | 878 err_closing: |
879 if (pipe_stdin) | |
880 { | |
881 CloseHandle(stdin_rd); | |
882 CloseHandle(stdin_wr); | |
883 } | |
884 if (pipe_stdout) | |
885 { | |
886 CloseHandle(stdout_rd); | |
887 CloseHandle(stdout_wr); | |
888 } | |
889 return CSCOPE_FAILURE; | |
890 } | |
7 | 891 #endif |
892 /* expand the cscope exec for env var's */ | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
893 if ((prog = alloc(MAXPATHL + 1)) == NULL) |
7 | 894 { |
895 #ifdef UNIX | |
896 return CSCOPE_FAILURE; | |
897 #else | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
898 /* MSWIN */ |
7 | 899 goto err_closing; |
900 #endif | |
901 } | |
902 expand_env((char_u *)p_csprg, (char_u *)prog, MAXPATHL); | |
903 | |
904 /* alloc space to hold the cscope command */ | |
835 | 905 len = (int)(strlen(prog) + strlen(csinfo[i].fname) + 32); |
7 | 906 if (csinfo[i].ppath) |
907 { | |
908 /* expand the prepend path for env var's */ | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
909 if ((ppath = alloc(MAXPATHL + 1)) == NULL) |
7 | 910 { |
911 vim_free(prog); | |
912 #ifdef UNIX | |
913 return CSCOPE_FAILURE; | |
914 #else | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
915 /* MSWIN */ |
7 | 916 goto err_closing; |
917 #endif | |
918 } | |
919 expand_env((char_u *)csinfo[i].ppath, (char_u *)ppath, MAXPATHL); | |
920 | |
835 | 921 len += (int)strlen(ppath); |
7 | 922 } |
923 | |
924 if (csinfo[i].flags) | |
835 | 925 len += (int)strlen(csinfo[i].flags); |
7 | 926 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
927 if ((cmd = alloc(len)) == NULL) |
7 | 928 { |
929 vim_free(prog); | |
930 vim_free(ppath); | |
931 #ifdef UNIX | |
932 return CSCOPE_FAILURE; | |
933 #else | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
934 /* MSWIN */ |
7 | 935 goto err_closing; |
936 #endif | |
937 } | |
938 | |
939 /* run the cscope command; is there execl for non-unix systems? */ | |
940 #if defined(UNIX) | |
941 (void)sprintf(cmd, "exec %s -dl -f %s", prog, csinfo[i].fname); | |
942 #else | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
943 /* MSWIN */ |
7 | 944 (void)sprintf(cmd, "%s -dl -f %s", prog, csinfo[i].fname); |
945 #endif | |
946 if (csinfo[i].ppath != NULL) | |
947 { | |
948 (void)strcat(cmd, " -P"); | |
949 (void)strcat(cmd, csinfo[i].ppath); | |
950 } | |
951 if (csinfo[i].flags != NULL) | |
952 { | |
953 (void)strcat(cmd, " "); | |
954 (void)strcat(cmd, csinfo[i].flags); | |
955 } | |
956 # ifdef UNIX | |
957 /* on Win32 we still need prog */ | |
958 vim_free(prog); | |
959 # endif | |
960 vim_free(ppath); | |
961 | |
962 #if defined(UNIX) | |
5066
d2f9f67924e7
updated for version 7.3.1276
Bram Moolenaar <bram@vim.org>
parents:
4867
diff
changeset
|
963 # if defined(HAVE_SETSID) || defined(HAVE_SETPGID) |
d2f9f67924e7
updated for version 7.3.1276
Bram Moolenaar <bram@vim.org>
parents:
4867
diff
changeset
|
964 /* Change our process group to avoid cscope receiving SIGWINCH. */ |
d2f9f67924e7
updated for version 7.3.1276
Bram Moolenaar <bram@vim.org>
parents:
4867
diff
changeset
|
965 # if defined(HAVE_SETSID) |
d2f9f67924e7
updated for version 7.3.1276
Bram Moolenaar <bram@vim.org>
parents:
4867
diff
changeset
|
966 (void)setsid(); |
d2f9f67924e7
updated for version 7.3.1276
Bram Moolenaar <bram@vim.org>
parents:
4867
diff
changeset
|
967 # else |
d2f9f67924e7
updated for version 7.3.1276
Bram Moolenaar <bram@vim.org>
parents:
4867
diff
changeset
|
968 if (setpgid(0, 0) == -1) |
d2f9f67924e7
updated for version 7.3.1276
Bram Moolenaar <bram@vim.org>
parents:
4867
diff
changeset
|
969 PERROR(_("cs_create_connection setpgid failed")); |
d2f9f67924e7
updated for version 7.3.1276
Bram Moolenaar <bram@vim.org>
parents:
4867
diff
changeset
|
970 # endif |
d2f9f67924e7
updated for version 7.3.1276
Bram Moolenaar <bram@vim.org>
parents:
4867
diff
changeset
|
971 # endif |
1878 | 972 if (execl("/bin/sh", "sh", "-c", cmd, (char *)NULL) == -1) |
7 | 973 PERROR(_("cs_create_connection exec failed")); |
974 | |
975 exit(127); | |
976 /* NOTREACHED */ | |
977 default: /* parent. */ | |
978 /* | |
979 * Save the file descriptors for later duplication, and | |
980 * reopen as streams. | |
981 */ | |
982 if ((csinfo[i].to_fp = fdopen(to_cs[1], "w")) == NULL) | |
983 PERROR(_("cs_create_connection: fdopen for to_fp failed")); | |
984 if ((csinfo[i].fr_fp = fdopen(from_cs[0], "r")) == NULL) | |
985 PERROR(_("cs_create_connection: fdopen for fr_fp failed")); | |
986 | |
987 /* close unused */ | |
988 (void)close(to_cs[0]); | |
989 (void)close(from_cs[1]); | |
990 | |
991 break; | |
992 } | |
1385 | 993 |
7 | 994 #else |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
995 /* MSWIN */ |
1385 | 996 /* Create a new process to run cscope and use pipes to talk with it */ |
997 GetStartupInfo(&si); | |
998 si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; | |
999 si.wShowWindow = SW_HIDE; /* Hide child application window */ | |
1000 si.hStdOutput = stdout_wr; | |
1001 si.hStdError = stdout_wr; | |
1002 si.hStdInput = stdin_rd; | |
1003 created = CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, | |
1004 NULL, NULL, &si, &pi); | |
1005 vim_free(prog); | |
1006 vim_free(cmd); | |
1007 | |
1008 if (!created) | |
1009 { | |
1010 PERROR(_("cs_create_connection exec failed")); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1011 (void)emsg(_("E623: Could not spawn cscope process")); |
1385 | 1012 goto err_closing; |
1013 } | |
1014 /* else */ | |
1015 csinfo[i].pid = pi.dwProcessId; | |
1016 csinfo[i].hProc = pi.hProcess; | |
1017 CloseHandle(pi.hThread); | |
1018 | |
1019 /* TODO - tidy up after failure to create files on pipe handles. */ | |
1393 | 1020 if (((fd = _open_osfhandle((OPEN_OH_ARGTYPE)stdin_wr, |
1021 _O_TEXT|_O_APPEND)) < 0) | |
1385 | 1022 || ((csinfo[i].to_fp = _fdopen(fd, "w")) == NULL)) |
1023 PERROR(_("cs_create_connection: fdopen for to_fp failed")); | |
1393 | 1024 if (((fd = _open_osfhandle((OPEN_OH_ARGTYPE)stdout_rd, |
1025 _O_TEXT|_O_RDONLY)) < 0) | |
1385 | 1026 || ((csinfo[i].fr_fp = _fdopen(fd, "r")) == NULL)) |
1027 PERROR(_("cs_create_connection: fdopen for fr_fp failed")); | |
1028 | |
1029 /* Close handles for file descriptors inherited by the cscope process */ | |
1030 CloseHandle(stdin_rd); | |
1031 CloseHandle(stdout_wr); | |
1032 | |
1033 #endif /* !UNIX */ | |
1034 | |
7 | 1035 return CSCOPE_SUCCESS; |
1036 } /* cs_create_connection */ | |
1037 | |
1038 | |
1039 /* | |
7009 | 1040 * Query cscope using command line interface. Parse the output and use tselect |
1041 * to allow choices. Like Nvi, creates a pipe to send to/from query/cscope. | |
7 | 1042 * |
1043 * returns TRUE if we jump to a tag or abort, FALSE if not. | |
1044 */ | |
1045 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1046 cs_find(exarg_T *eap) |
7 | 1047 { |
1048 char *opt, *pat; | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1049 int i; |
7 | 1050 |
1051 if (cs_check_for_connections() == FALSE) | |
1052 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1053 (void)emsg(_("E567: no cscope connections")); |
7 | 1054 return FALSE; |
1055 } | |
1056 | |
1057 if ((opt = strtok((char *)NULL, (const char *)" ")) == NULL) | |
1058 { | |
1059 cs_usage_msg(Find); | |
1060 return FALSE; | |
1061 } | |
1062 | |
1063 pat = opt + strlen(opt) + 1; | |
1372 | 1064 if (pat >= (char *)eap->arg + eap_arg_len) |
7 | 1065 { |
1066 cs_usage_msg(Find); | |
1067 return FALSE; | |
1068 } | |
1069 | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1070 /* |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1071 * Let's replace the NULs written by strtok() with spaces - we need the |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1072 * spaces to correctly display the quickfix/location list window's title. |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1073 */ |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1074 for (i = 0; i < eap_arg_len; ++i) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1075 if (NUL == eap->arg[i]) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1076 eap->arg[i] = ' '; |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1077 |
665 | 1078 return cs_find_common(opt, pat, eap->forceit, TRUE, |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1079 eap->cmdidx == CMD_lcscope, *eap->cmdlinep); |
7 | 1080 } /* cs_find */ |
1081 | |
1082 | |
1083 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1084 * Common code for cscope find, shared by cs_find() and ex_cstag(). |
7 | 1085 */ |
1086 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1087 cs_find_common( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1088 char *opt, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1089 char *pat, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1090 int forceit, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1091 int verbose, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1092 int use_ll UNUSED, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1093 char_u *cmdline UNUSED) |
7 | 1094 { |
1095 int i; | |
1096 char *cmd; | |
1931 | 1097 int *nummatches; |
1098 int totmatches; | |
7 | 1099 #ifdef FEAT_QUICKFIX |
1100 char cmdletter; | |
1101 char *qfpos; | |
2151
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1102 |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1103 /* get cmd letter */ |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1104 switch (opt[0]) |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1105 { |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1106 case '0' : |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1107 cmdletter = 's'; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1108 break; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1109 case '1' : |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1110 cmdletter = 'g'; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1111 break; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1112 case '2' : |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1113 cmdletter = 'd'; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1114 break; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1115 case '3' : |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1116 cmdletter = 'c'; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1117 break; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1118 case '4' : |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1119 cmdletter = 't'; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1120 break; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1121 case '6' : |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1122 cmdletter = 'e'; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1123 break; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1124 case '7' : |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1125 cmdletter = 'f'; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1126 break; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1127 case '8' : |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1128 cmdletter = 'i'; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1129 break; |
9340
387cd517939f
commit https://github.com/vim/vim/commit/b12e7ef956e0b0344778b7ef93d41f4b4ed2a670
Christian Brabandt <cb@256bit.org>
parents:
8234
diff
changeset
|
1130 case '9' : |
387cd517939f
commit https://github.com/vim/vim/commit/b12e7ef956e0b0344778b7ef93d41f4b4ed2a670
Christian Brabandt <cb@256bit.org>
parents:
8234
diff
changeset
|
1131 cmdletter = 'a'; |
387cd517939f
commit https://github.com/vim/vim/commit/b12e7ef956e0b0344778b7ef93d41f4b4ed2a670
Christian Brabandt <cb@256bit.org>
parents:
8234
diff
changeset
|
1132 break; |
2151
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1133 default : |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1134 cmdletter = opt[0]; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1135 } |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1136 |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1137 qfpos = (char *)vim_strchr(p_csqf, cmdletter); |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1138 if (qfpos != NULL) |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1139 { |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1140 qfpos++; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1141 /* next symbol must be + or - */ |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1142 if (strchr(CSQF_FLAGS, *qfpos) == NULL) |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1143 { |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1144 char *nf = _("E469: invalid cscopequickfix flag %c for %c"); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1145 char *buf = alloc(strlen(nf)); |
2151
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1146 |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1147 /* strlen will be enough because we use chars */ |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1148 if (buf != NULL) |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1149 { |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1150 sprintf(buf, nf, *qfpos, *(qfpos-1)); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1151 (void)emsg(buf); |
2151
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1152 vim_free(buf); |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1153 } |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1154 return FALSE; |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1155 } |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1156 |
10346
d52d97bf675e
commit https://github.com/vim/vim/commit/21662be2211675824df1771c7f169948ede40c41
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
1157 if (*qfpos != '0' |
d52d97bf675e
commit https://github.com/vim/vim/commit/21662be2211675824df1771c7f169948ede40c41
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
1158 && apply_autocmds(EVENT_QUICKFIXCMDPRE, (char_u *)"cscope", |
d52d97bf675e
commit https://github.com/vim/vim/commit/21662be2211675824df1771c7f169948ede40c41
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
1159 curbuf->b_fname, TRUE, curbuf)) |
2151
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1160 { |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1161 # ifdef FEAT_EVAL |
10346
d52d97bf675e
commit https://github.com/vim/vim/commit/21662be2211675824df1771c7f169948ede40c41
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
1162 if (aborting()) |
2151
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1163 return FALSE; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1164 # endif |
2151
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1165 } |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1166 } |
7 | 1167 #endif |
1168 | |
1169 /* create the actual command to send to cscope */ | |
1170 cmd = cs_create_cmd(opt, pat); | |
1171 if (cmd == NULL) | |
1172 return FALSE; | |
1173 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1174 nummatches = ALLOC_MULT(int, csinfo_size); |
1931 | 1175 if (nummatches == NULL) |
7009 | 1176 { |
1177 vim_free(cmd); | |
1931 | 1178 return FALSE; |
7009 | 1179 } |
1931 | 1180 |
4352 | 1181 /* Send query to all open connections, then count the total number |
1182 * of matches so we can alloc all in one swell foop. */ | |
1931 | 1183 for (i = 0; i < csinfo_size; i++) |
7 | 1184 nummatches[i] = 0; |
1185 totmatches = 0; | |
1931 | 1186 for (i = 0; i < csinfo_size; i++) |
7 | 1187 { |
1040 | 1188 if (csinfo[i].fname == NULL || csinfo[i].to_fp == NULL) |
7 | 1189 continue; |
1190 | |
1191 /* send cmd to cscope */ | |
1192 (void)fprintf(csinfo[i].to_fp, "%s\n", cmd); | |
1193 (void)fflush(csinfo[i].to_fp); | |
1194 | |
1195 nummatches[i] = cs_cnt_matches(i); | |
1196 | |
1197 if (nummatches[i] > -1) | |
1198 totmatches += nummatches[i]; | |
1199 | |
1200 if (nummatches[i] == 0) | |
1201 (void)cs_read_prompt(i); | |
1202 } | |
1203 vim_free(cmd); | |
1204 | |
1205 if (totmatches == 0) | |
1206 { | |
1207 char *nf = _("E259: no matches found for cscope query %s of %s"); | |
1208 char *buf; | |
1209 | |
1210 if (!verbose) | |
1931 | 1211 { |
1212 vim_free(nummatches); | |
7 | 1213 return FALSE; |
1931 | 1214 } |
7 | 1215 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1216 buf = alloc(strlen(opt) + strlen(pat) + strlen(nf)); |
7 | 1217 if (buf == NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1218 (void)emsg(nf); |
7 | 1219 else |
1220 { | |
1221 sprintf(buf, nf, opt, pat); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1222 (void)emsg(buf); |
7 | 1223 vim_free(buf); |
1224 } | |
1931 | 1225 vim_free(nummatches); |
7 | 1226 return FALSE; |
1227 } | |
1228 | |
1229 #ifdef FEAT_QUICKFIX | |
36 | 1230 if (qfpos != NULL && *qfpos != '0' && totmatches > 0) |
7 | 1231 { |
1232 /* fill error list */ | |
1027 | 1233 FILE *f; |
6721 | 1234 char_u *tmp = vim_tempname('c', TRUE); |
665 | 1235 qf_info_T *qi = NULL; |
1236 win_T *wp = NULL; | |
7 | 1237 |
531 | 1238 f = mch_fopen((char *)tmp, "w"); |
1027 | 1239 if (f == NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1240 semsg(_(e_notopen), tmp); |
1027 | 1241 else |
7 | 1242 { |
1027 | 1243 cs_file_results(f, nummatches); |
1244 fclose(f); | |
1245 if (use_ll) /* Use location list */ | |
1246 wp = curwin; | |
1247 /* '-' starts a new error list */ | |
1248 if (qf_init(wp, tmp, (char_u *)"%f%*\\t%l%*\\t%m", | |
11063
e71d3bdf3bc3
patch 8.0.0420: text garbled when the system encoding differs from 'encoding'
Christian Brabandt <cb@256bit.org>
parents:
10605
diff
changeset
|
1249 *qfpos == '-', cmdline, NULL) > 0) |
1027 | 1250 { |
1251 if (postponed_split != 0) | |
1252 { | |
7009 | 1253 (void)win_split(postponed_split > 0 ? postponed_split : 0, |
7 | 1254 postponed_split_flags); |
2583 | 1255 RESET_BINDING(curwin); |
1027 | 1256 postponed_split = 0; |
1257 } | |
2151
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1258 |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1259 apply_autocmds(EVENT_QUICKFIXCMDPOST, (char_u *)"cscope", |
ae22c450546c
updated for version 7.2.433
Bram Moolenaar <bram@zimbu.org>
parents:
2087
diff
changeset
|
1260 curbuf->b_fname, TRUE, curbuf); |
1027 | 1261 if (use_ll) |
1262 /* | |
1263 * In the location list window, use the displayed location | |
1264 * list. Otherwise, use the location list for the window. | |
1265 */ | |
1266 qi = (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL) | |
1267 ? wp->w_llist_ref : wp->w_llist; | |
1268 qf_jump(qi, 0, 0, forceit); | |
1269 } | |
7 | 1270 } |
1271 mch_remove(tmp); | |
1272 vim_free(tmp); | |
1931 | 1273 vim_free(nummatches); |
7 | 1274 return TRUE; |
1275 } | |
1276 else | |
1277 #endif /* FEAT_QUICKFIX */ | |
1278 { | |
944 | 1279 char **matches = NULL, **contexts = NULL; |
1280 int matched = 0; | |
1281 | |
7 | 1282 /* read output */ |
1283 cs_fill_results((char *)pat, totmatches, nummatches, &matches, | |
1284 &contexts, &matched); | |
1931 | 1285 vim_free(nummatches); |
7 | 1286 if (matches == NULL) |
1287 return FALSE; | |
1288 | |
293 | 1289 (void)cs_manage_matches(matches, contexts, matched, Store); |
7 | 1290 |
1291 return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose); | |
1292 } | |
1293 | |
1294 } /* cs_find_common */ | |
1295 | |
1296 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1297 * Print help. |
7 | 1298 */ |
1299 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1300 cs_help(exarg_T *eap UNUSED) |
7 | 1301 { |
1302 cscmd_T *cmdp = cs_cmds; | |
1303 | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
1304 (void)msg_puts(_("cscope commands:\n")); |
7 | 1305 while (cmdp->name != NULL) |
1306 { | |
1793 | 1307 char *help = _(cmdp->help); |
1308 int space_cnt = 30 - vim_strsize((char_u *)help); | |
1309 | |
1310 /* Use %*s rather than %30s to ensure proper alignment in utf-8 */ | |
1311 if (space_cnt < 0) | |
1312 space_cnt = 0; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1313 (void)smsg(_("%-5s: %s%*s (Usage: %s)"), |
1793 | 1314 cmdp->name, |
1315 help, space_cnt, " ", | |
1316 cmdp->usage); | |
7 | 1317 if (strcmp(cmdp->name, "find") == 0) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
1318 msg_puts(_("\n" |
9418
6d213bd46cc3
commit https://github.com/vim/vim/commit/80632db65e8f5f775dadbbc10c5ba6c173ebb24f
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1319 " a: Find assignments to this symbol\n" |
1706 | 1320 " c: Find functions calling this function\n" |
1321 " d: Find functions called by this function\n" | |
1322 " e: Find this egrep pattern\n" | |
1323 " f: Find this file\n" | |
1324 " g: Find this definition\n" | |
1325 " i: Find files #including this file\n" | |
1326 " s: Find this C symbol\n" | |
9418
6d213bd46cc3
commit https://github.com/vim/vim/commit/80632db65e8f5f775dadbbc10c5ba6c173ebb24f
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1327 " t: Find this text string\n")); |
1706 | 1328 |
7 | 1329 cmdp++; |
1330 } | |
1331 | |
1332 wait_return(TRUE); | |
1333 return 0; | |
1334 } /* cs_help */ | |
1335 | |
1336 | |
1337 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1338 clear_csinfo(int i) |
7 | 1339 { |
1340 csinfo[i].fname = NULL; | |
1341 csinfo[i].ppath = NULL; | |
1342 csinfo[i].flags = NULL; | |
1343 #if defined(UNIX) | |
1344 csinfo[i].st_dev = (dev_t)0; | |
1345 csinfo[i].st_ino = (ino_t)0; | |
1346 #else | |
1347 csinfo[i].nVolume = 0; | |
1348 csinfo[i].nIndexHigh = 0; | |
1349 csinfo[i].nIndexLow = 0; | |
1350 #endif | |
1621 | 1351 csinfo[i].pid = 0; |
7 | 1352 csinfo[i].fr_fp = NULL; |
1353 csinfo[i].to_fp = NULL; | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1354 #if defined(MSWIN) |
301 | 1355 csinfo[i].hProc = NULL; |
1356 #endif | |
7 | 1357 } |
1358 | |
1359 #ifndef UNIX | |
1360 static char * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1361 GetWin32Error(void) |
7 | 1362 { |
1363 char *msg = NULL; | |
1364 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, | |
1365 NULL, GetLastError(), 0, (LPSTR)&msg, 0, NULL); | |
1366 if (msg != NULL) | |
1367 { | |
1368 /* remove trailing \r\n */ | |
1369 char *pcrlf = strstr(msg, "\r\n"); | |
1370 if (pcrlf != NULL) | |
1371 *pcrlf = '\0'; | |
1372 } | |
1373 return msg; | |
1374 } | |
1375 #endif | |
323 | 1376 |
7 | 1377 /* |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1378 * Insert a new cscope database filename into the filelist. |
7 | 1379 */ |
1380 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1381 cs_insert_filelist( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1382 char *fname, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1383 char *ppath, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1384 char *flags, |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9340
diff
changeset
|
1385 stat_T *sb UNUSED) |
7 | 1386 { |
1387 short i, j; | |
1388 #ifndef UNIX | |
1389 BY_HANDLE_FILE_INFORMATION bhfi; | |
1390 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1391 switch (win32_fileinfo((char_u *)fname, &bhfi)) |
7 | 1392 { |
2793 | 1393 case FILEINFO_ENC_FAIL: /* enc_to_utf16() failed */ |
1394 case FILEINFO_READ_FAIL: /* CreateFile() failed */ | |
7 | 1395 if (p_csverbose) |
1396 { | |
1397 char *cant_msg = _("E625: cannot open cscope database: %s"); | |
1398 char *winmsg = GetWin32Error(); | |
1399 | |
1400 if (winmsg != NULL) | |
1401 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1402 (void)semsg(cant_msg, winmsg); |
7 | 1403 LocalFree(winmsg); |
1404 } | |
1405 else | |
1406 /* subst filename if can't get error text */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1407 (void)semsg(cant_msg, fname); |
7 | 1408 } |
1409 return -1; | |
2793 | 1410 |
1411 case FILEINFO_INFO_FAIL: /* GetFileInformationByHandle() failed */ | |
7 | 1412 if (p_csverbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1413 (void)emsg(_("E626: cannot get cscope database information")); |
7 | 1414 return -1; |
1415 } | |
1416 #endif | |
1417 | |
1418 i = -1; /* can be set to the index of an empty item in csinfo */ | |
1931 | 1419 for (j = 0; j < csinfo_size; j++) |
7 | 1420 { |
1421 if (csinfo[j].fname != NULL | |
1422 #if defined(UNIX) | |
1423 && csinfo[j].st_dev == sb->st_dev && csinfo[j].st_ino == sb->st_ino | |
1424 #else | |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1425 // compare pathnames first |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
1426 && ((fullpathcmp((char_u *)csinfo[j].fname, |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1427 (char_u *)fname, FALSE, TRUE) & FPC_SAME) |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1428 // test index file attributes too |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1429 || (csinfo[j].nVolume == bhfi.dwVolumeSerialNumber |
7 | 1430 && csinfo[j].nIndexHigh == bhfi.nFileIndexHigh |
1431 && csinfo[j].nIndexLow == bhfi.nFileIndexLow)) | |
1432 #endif | |
1433 ) | |
1434 { | |
1435 if (p_csverbose) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1436 (void)emsg(_("E568: duplicate cscope database not added")); |
7 | 1437 return -1; |
1438 } | |
1439 | |
1440 if (csinfo[j].fname == NULL && i == -1) | |
1441 i = j; /* remember first empty entry */ | |
1442 } | |
1443 | |
1444 if (i == -1) | |
1445 { | |
1931 | 1446 i = csinfo_size; |
1447 if (csinfo_size == 0) | |
1448 { | |
1449 /* First time allocation: allocate only 1 connection. It should | |
1450 * be enough for most users. If more is needed, csinfo will be | |
1451 * reallocated. */ | |
1452 csinfo_size = 1; | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1453 csinfo = ALLOC_CLEAR_ONE(csinfo_T); |
1931 | 1454 } |
1455 else | |
1456 { | |
6596 | 1457 csinfo_T *t_csinfo = csinfo; |
1458 | |
1931 | 1459 /* Reallocate space for more connections. */ |
1460 csinfo_size *= 2; | |
1461 csinfo = vim_realloc(csinfo, sizeof(csinfo_T)*csinfo_size); | |
6596 | 1462 if (csinfo == NULL) |
1463 { | |
1464 vim_free(t_csinfo); | |
1465 csinfo_size = 0; | |
1466 } | |
1931 | 1467 } |
1468 if (csinfo == NULL) | |
1469 return -1; | |
1470 for (j = csinfo_size/2; j < csinfo_size; j++) | |
1471 clear_csinfo(j); | |
7 | 1472 } |
1473 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1474 if ((csinfo[i].fname = alloc(strlen(fname)+1)) == NULL) |
7 | 1475 return -1; |
1476 | |
1477 (void)strcpy(csinfo[i].fname, (const char *)fname); | |
1478 | |
1479 if (ppath != NULL) | |
1480 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1481 if ((csinfo[i].ppath = alloc(strlen(ppath) + 1)) == NULL) |
7 | 1482 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13136
diff
changeset
|
1483 VIM_CLEAR(csinfo[i].fname); |
7 | 1484 return -1; |
1485 } | |
1486 (void)strcpy(csinfo[i].ppath, (const char *)ppath); | |
1487 } else | |
1488 csinfo[i].ppath = NULL; | |
1489 | |
1490 if (flags != NULL) | |
1491 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1492 if ((csinfo[i].flags = alloc(strlen(flags) + 1)) == NULL) |
7 | 1493 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13136
diff
changeset
|
1494 VIM_CLEAR(csinfo[i].fname); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13136
diff
changeset
|
1495 VIM_CLEAR(csinfo[i].ppath); |
7 | 1496 return -1; |
1497 } | |
1498 (void)strcpy(csinfo[i].flags, (const char *)flags); | |
1499 } else | |
1500 csinfo[i].flags = NULL; | |
1501 | |
1502 #if defined(UNIX) | |
1503 csinfo[i].st_dev = sb->st_dev; | |
1504 csinfo[i].st_ino = sb->st_ino; | |
1505 | |
1506 #else | |
1507 csinfo[i].nVolume = bhfi.dwVolumeSerialNumber; | |
1508 csinfo[i].nIndexLow = bhfi.nFileIndexLow; | |
1509 csinfo[i].nIndexHigh = bhfi.nFileIndexHigh; | |
1510 #endif | |
1511 return i; | |
1512 } /* cs_insert_filelist */ | |
1513 | |
1514 | |
1515 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1516 * Find cscope command in command table. |
7 | 1517 */ |
1518 static cscmd_T * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1519 cs_lookup_cmd(exarg_T *eap) |
7 | 1520 { |
1521 cscmd_T *cmdp; | |
1522 char *stok; | |
1523 size_t len; | |
1524 | |
1525 if (eap->arg == NULL) | |
1526 return NULL; | |
1527 | |
1372 | 1528 /* Store length of eap->arg before it gets modified by strtok(). */ |
1570 | 1529 eap_arg_len = (int)STRLEN(eap->arg); |
1372 | 1530 |
7 | 1531 if ((stok = strtok((char *)(eap->arg), (const char *)" ")) == NULL) |
1532 return NULL; | |
1533 | |
1534 len = strlen(stok); | |
1535 for (cmdp = cs_cmds; cmdp->name != NULL; ++cmdp) | |
1536 { | |
1537 if (strncmp((const char *)(stok), cmdp->name, len) == 0) | |
1538 return (cmdp); | |
1539 } | |
1540 return NULL; | |
1541 } /* cs_lookup_cmd */ | |
1542 | |
1543 | |
1544 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1545 * Nuke em. |
7 | 1546 */ |
1547 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1548 cs_kill(exarg_T *eap UNUSED) |
7 | 1549 { |
1550 char *stok; | |
1551 short i; | |
1552 | |
1553 if ((stok = strtok((char *)NULL, (const char *)" ")) == NULL) | |
1554 { | |
1555 cs_usage_msg(Kill); | |
1556 return CSCOPE_FAILURE; | |
1557 } | |
1558 | |
1559 /* only single digit positive and negative integers are allowed */ | |
1560 if ((strlen(stok) < 2 && VIM_ISDIGIT((int)(stok[0]))) | |
1561 || (strlen(stok) < 3 && stok[0] == '-' | |
1562 && VIM_ISDIGIT((int)(stok[1])))) | |
1563 i = atoi(stok); | |
1564 else | |
1565 { | |
1566 /* It must be part of a name. We will try to find a match | |
1567 * within all the names in the csinfo data structure | |
1568 */ | |
1931 | 1569 for (i = 0; i < csinfo_size; i++) |
7 | 1570 { |
1571 if (csinfo[i].fname != NULL && strstr(csinfo[i].fname, stok)) | |
1572 break; | |
1573 } | |
1574 } | |
1575 | |
1931 | 1576 if ((i != -1) && (i >= csinfo_size || i < -1 || csinfo[i].fname == NULL)) |
7 | 1577 { |
1578 if (p_csverbose) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1579 (void)semsg(_("E261: cscope connection %s not found"), stok); |
7 | 1580 } |
1581 else | |
1582 { | |
1583 if (i == -1) | |
1584 { | |
1931 | 1585 for (i = 0; i < csinfo_size; i++) |
7 | 1586 { |
1587 if (csinfo[i].fname) | |
1588 cs_kill_execute(i, csinfo[i].fname); | |
1589 } | |
1590 } | |
1591 else | |
1592 cs_kill_execute(i, stok); | |
1593 } | |
1594 | |
1595 return 0; | |
1596 } /* cs_kill */ | |
1597 | |
1598 | |
1599 /* | |
1600 * Actually kills a specific cscope connection. | |
1601 */ | |
1602 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1603 cs_kill_execute( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1604 int i, /* cscope table index */ |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1605 char *cname) /* cscope database name */ |
7 | 1606 { |
1607 if (p_csverbose) | |
1608 { | |
1609 msg_clr_eos(); | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1610 (void)smsg_attr(HL_ATTR(HLF_R) | MSG_HIST, |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1611 _("cscope connection %s closed"), cname); |
7 | 1612 } |
1613 cs_release_csp(i, TRUE); | |
1614 } | |
1615 | |
1616 | |
1617 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1618 * Convert the cscope output into a ctags style entry (as might be found |
7 | 1619 * in a ctags tags file). there's one catch though: cscope doesn't tell you |
1620 * the type of the tag you are looking for. for example, in Darren Hiebert's | |
1621 * ctags (the one that comes with vim), #define's use a line number to find the | |
1622 * tag in a file while function definitions use a regexp search pattern. | |
1623 * | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1624 * I'm going to always use the line number because cscope does something |
7 | 1625 * quirky (and probably other things i don't know about): |
1626 * | |
1627 * if you have "# define" in your source file, which is | |
1628 * perfectly legal, cscope thinks you have "#define". this | |
1629 * will result in a failed regexp search. :( | |
1630 * | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1631 * Besides, even if this particular case didn't happen, the search pattern |
7 | 1632 * would still have to be modified to escape all the special regular expression |
1633 * characters to comply with ctags formatting. | |
1634 */ | |
1635 static char * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1636 cs_make_vim_style_matches( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1637 char *fname, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1638 char *slno, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1639 char *search, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1640 char *tagstr) |
7 | 1641 { |
1642 /* vim style is ctags: | |
1643 * | |
1644 * <tagstr>\t<filename>\t<linenum_or_search>"\t<extra> | |
1645 * | |
1646 * but as mentioned above, we'll always use the line number and | |
1647 * put the search pattern (if one exists) as "extra" | |
1648 * | |
1649 * buf is used as part of vim's method of handling tags, and | |
1650 * (i think) vim frees it when you pop your tags and get replaced | |
1651 * by new ones on the tag stack. | |
1652 */ | |
1653 char *buf; | |
1654 int amt; | |
1655 | |
1656 if (search != NULL) | |
1657 { | |
835 | 1658 amt = (int)(strlen(fname) + strlen(slno) + strlen(tagstr) + strlen(search)+6); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1659 if ((buf = alloc(amt)) == NULL) |
7 | 1660 return NULL; |
1661 | |
1662 (void)sprintf(buf, "%s\t%s\t%s;\"\t%s", tagstr, fname, slno, search); | |
1663 } | |
1664 else | |
1665 { | |
835 | 1666 amt = (int)(strlen(fname) + strlen(slno) + strlen(tagstr) + 5); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1667 if ((buf = alloc(amt)) == NULL) |
7 | 1668 return NULL; |
1669 | |
1670 (void)sprintf(buf, "%s\t%s\t%s;\"", tagstr, fname, slno); | |
1671 } | |
1672 | |
1673 return buf; | |
1674 } /* cs_make_vim_style_matches */ | |
1675 | |
1676 | |
1677 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1678 * This is kind of hokey, but i don't see an easy way round this. |
7 | 1679 * |
1680 * Store: keep a ptr to the (malloc'd) memory of matches originally | |
1681 * generated from cs_find(). the matches are originally lines directly | |
1682 * from cscope output, but transformed to look like something out of a | |
1683 * ctags. see cs_make_vim_style_matches for more details. | |
1684 * | |
1685 * Get: used only from cs_fgets(), this simulates a vim_fgets() to return | |
1686 * the next line from the cscope output. it basically keeps track of which | |
1687 * lines have been "used" and returns the next one. | |
1688 * | |
1689 * Free: frees up everything and resets | |
1690 * | |
1691 * Print: prints the tags | |
1692 */ | |
1693 static char * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1694 cs_manage_matches( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1695 char **matches, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1696 char **contexts, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1697 int totmatches, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1698 mcmd_e cmd) |
7 | 1699 { |
1700 static char **mp = NULL; | |
1701 static char **cp = NULL; | |
1702 static int cnt = -1; | |
1703 static int next = -1; | |
1704 char *p = NULL; | |
1705 | |
1706 switch (cmd) | |
1707 { | |
1708 case Store: | |
1709 assert(matches != NULL); | |
1710 assert(totmatches > 0); | |
1711 if (mp != NULL || cp != NULL) | |
1712 (void)cs_manage_matches(NULL, NULL, -1, Free); | |
1713 mp = matches; | |
1714 cp = contexts; | |
1715 cnt = totmatches; | |
1716 next = 0; | |
1717 break; | |
1718 case Get: | |
1719 if (next >= cnt) | |
1720 return NULL; | |
1721 | |
1722 p = mp[next]; | |
1723 next++; | |
1724 break; | |
1725 case Free: | |
1726 if (mp != NULL) | |
1727 { | |
1728 if (cnt > 0) | |
1729 while (cnt--) | |
1730 { | |
1731 vim_free(mp[cnt]); | |
1732 if (cp != NULL) | |
1733 vim_free(cp[cnt]); | |
1734 } | |
1735 vim_free(mp); | |
1736 vim_free(cp); | |
1737 } | |
1738 mp = NULL; | |
1739 cp = NULL; | |
1740 cnt = 0; | |
1741 next = 0; | |
1742 break; | |
1743 case Print: | |
1744 cs_print_tags_priv(mp, cp, cnt); | |
1745 break; | |
1746 default: /* should not reach here */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1747 iemsg(_("E570: fatal error in cs_manage_matches")); |
7 | 1748 return NULL; |
1749 } | |
1750 | |
1751 return p; | |
1752 } /* cs_manage_matches */ | |
1753 | |
1754 | |
1755 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1756 * Parse cscope output. |
7 | 1757 */ |
1758 static char * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1759 cs_parse_results( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1760 int cnumber, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1761 char *buf, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1762 int bufsize, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1763 char **context, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1764 char **linenumber, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1765 char **search) |
7 | 1766 { |
1767 int ch; | |
1768 char *p; | |
1769 char *name; | |
1770 | |
1771 if (fgets(buf, bufsize, csinfo[cnumber].fr_fp) == NULL) | |
1772 { | |
1773 if (feof(csinfo[cnumber].fr_fp)) | |
1774 errno = EIO; | |
1775 | |
1776 cs_reading_emsg(cnumber); | |
1777 | |
1778 return NULL; | |
1779 } | |
1780 | |
1781 /* If the line's too long for the buffer, discard it. */ | |
1782 if ((p = strchr(buf, '\n')) == NULL) | |
1783 { | |
1784 while ((ch = getc(csinfo[cnumber].fr_fp)) != EOF && ch != '\n') | |
1785 ; | |
1786 return NULL; | |
1787 } | |
1788 *p = '\0'; | |
1789 | |
1790 /* | |
1791 * cscope output is in the following format: | |
1792 * | |
1793 * <filename> <context> <line number> <pattern> | |
1794 */ | |
1795 if ((name = strtok((char *)buf, (const char *)" ")) == NULL) | |
1796 return NULL; | |
1797 if ((*context = strtok(NULL, (const char *)" ")) == NULL) | |
1798 return NULL; | |
1799 if ((*linenumber = strtok(NULL, (const char *)" ")) == NULL) | |
1800 return NULL; | |
1801 *search = *linenumber + strlen(*linenumber) + 1; /* +1 to skip \0 */ | |
1802 | |
1803 /* --- nvi --- | |
1804 * If the file is older than the cscope database, that is, | |
1805 * the database was built since the file was last modified, | |
1806 * or there wasn't a search string, use the line number. | |
1807 */ | |
1808 if (strcmp(*search, "<unknown>") == 0) | |
1809 *search = NULL; | |
1810 | |
1811 name = cs_resolve_file(cnumber, name); | |
1812 return name; | |
1813 } | |
1814 | |
636 | 1815 #ifdef FEAT_QUICKFIX |
7 | 1816 /* |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1817 * Write cscope find results to file. |
7 | 1818 */ |
1819 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1820 cs_file_results(FILE *f, int *nummatches_a) |
7 | 1821 { |
1822 int i, j; | |
1823 char *buf; | |
1824 char *search, *slno; | |
1825 char *fullname; | |
1826 char *cntx; | |
1827 char *context; | |
1828 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1829 buf = alloc(CSREAD_BUFSIZE); |
7 | 1830 if (buf == NULL) |
1831 return; | |
1832 | |
1931 | 1833 for (i = 0; i < csinfo_size; i++) |
7 | 1834 { |
1835 if (nummatches_a[i] < 1) | |
1836 continue; | |
1837 | |
1838 for (j = 0; j < nummatches_a[i]; j++) | |
1839 { | |
293 | 1840 if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx, |
1841 &slno, &search)) == NULL) | |
7 | 1842 continue; |
1843 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1844 context = alloc(strlen(cntx)+5); |
1027 | 1845 if (context == NULL) |
7 | 1846 continue; |
1847 | |
1848 if (strcmp(cntx, "<global>")==0) | |
1849 strcpy(context, "<<global>>"); | |
1850 else | |
1851 sprintf(context, "<<%s>>", cntx); | |
1852 | |
1027 | 1853 if (search == NULL) |
7 | 1854 fprintf(f, "%s\t%s\t%s\n", fullname, slno, context); |
1855 else | |
1856 fprintf(f, "%s\t%s\t%s %s\n", fullname, slno, context, search); | |
1857 | |
1858 vim_free(context); | |
1859 vim_free(fullname); | |
1860 } /* for all matches */ | |
1861 | |
1862 (void)cs_read_prompt(i); | |
1863 | |
1864 } /* for all cscope connections */ | |
1865 vim_free(buf); | |
1866 } | |
636 | 1867 #endif |
7 | 1868 |
1869 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1870 * Get parsed cscope output and calls cs_make_vim_style_matches to convert |
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1871 * into ctags format. |
297 | 1872 * When there are no matches sets "*matches_p" to NULL. |
7 | 1873 */ |
1874 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1875 cs_fill_results( |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1876 char *tagstr, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1877 int totmatches, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1878 int *nummatches_a, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1879 char ***matches_p, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1880 char ***cntxts_p, |
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1881 int *matched) |
7 | 1882 { |
1883 int i, j; | |
1884 char *buf; | |
1885 char *search, *slno; | |
1886 int totsofar = 0; | |
1887 char **matches = NULL; | |
1888 char **cntxts = NULL; | |
1889 char *fullname; | |
1890 char *cntx; | |
1891 | |
1892 assert(totmatches > 0); | |
1893 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1894 buf = alloc(CSREAD_BUFSIZE); |
7 | 1895 if (buf == NULL) |
1896 return; | |
1897 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1898 if ((matches = ALLOC_MULT(char *, totmatches)) == NULL) |
7 | 1899 goto parse_out; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1900 if ((cntxts = ALLOC_MULT(char *, totmatches)) == NULL) |
7 | 1901 goto parse_out; |
1902 | |
1931 | 1903 for (i = 0; i < csinfo_size; i++) |
7 | 1904 { |
1905 if (nummatches_a[i] < 1) | |
1906 continue; | |
1907 | |
1908 for (j = 0; j < nummatches_a[i]; j++) | |
1909 { | |
1910 if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx, | |
1911 &slno, &search)) == NULL) | |
1912 continue; | |
1913 | |
1914 matches[totsofar] = cs_make_vim_style_matches(fullname, slno, | |
1915 search, tagstr); | |
1916 | |
1917 vim_free(fullname); | |
1918 | |
1919 if (strcmp(cntx, "<global>") == 0) | |
1920 cntxts[totsofar] = NULL; | |
1921 else | |
1922 /* note: if vim_strsave returns NULL, then the context | |
1923 * will be "<global>", which is misleading. | |
1924 */ | |
1925 cntxts[totsofar] = (char *)vim_strsave((char_u *)cntx); | |
1926 | |
1927 if (matches[totsofar] != NULL) | |
1928 totsofar++; | |
1929 | |
1930 } /* for all matches */ | |
1931 | |
1932 (void)cs_read_prompt(i); | |
1933 | |
1934 } /* for all cscope connections */ | |
1935 | |
1936 parse_out: | |
297 | 1937 if (totsofar == 0) |
1938 { | |
1939 /* No matches, free the arrays and return NULL in "*matches_p". */ | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13136
diff
changeset
|
1940 VIM_CLEAR(matches); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13136
diff
changeset
|
1941 VIM_CLEAR(cntxts); |
297 | 1942 } |
7 | 1943 *matched = totsofar; |
1944 *matches_p = matches; | |
1945 *cntxts_p = cntxts; | |
297 | 1946 |
7 | 1947 vim_free(buf); |
1948 } /* cs_fill_results */ | |
1949 | |
1950 | |
1951 /* get the requested path components */ | |
1952 static char * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1953 cs_pathcomponents(char *path) |
7 | 1954 { |
1955 int i; | |
1956 char *s; | |
1957 | |
1958 if (p_cspc == 0) | |
1959 return path; | |
1960 | |
1961 s = path + strlen(path) - 1; | |
1962 for (i = 0; i < p_cspc; ++i) | |
1963 while (s > path && *--s != '/' | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1964 #ifdef MSWIN |
7 | 1965 && *--s != '\\' |
1966 #endif | |
1967 ) | |
1968 ; | |
1969 if ((s > path && *s == '/') | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1970 #ifdef MSWIN |
7 | 1971 || (s > path && *s == '\\') |
1972 #endif | |
1973 ) | |
1974 ++s; | |
1975 return s; | |
1976 } | |
1977 | |
1978 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1979 * Called from cs_manage_matches(). |
7 | 1980 */ |
1981 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1982 cs_print_tags_priv(char **matches, char **cntxts, int num_matches) |
7 | 1983 { |
1984 char *buf = NULL; | |
6596 | 1985 char *t_buf; |
7 | 1986 int bufsize = 0; /* Track available bufsize */ |
1987 int newsize = 0; | |
1988 char *ptag; | |
1989 char *fname, *lno, *extra, *tbuf; | |
1990 int i, idx, num; | |
1991 char *globalcntx = "GLOBAL"; | |
1992 char *cntxformat = " <<%s>>"; | |
1993 char *context; | |
1994 char *cstag_msg = _("Cscope tag: %s"); | |
1995 char *csfmt_str = "%4d %6s "; | |
1996 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1997 assert(num_matches > 0); |
7 | 1998 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1999 if ((tbuf = alloc(strlen(matches[0]) + 1)) == NULL) |
7 | 2000 return; |
2001 | |
2002 strcpy(tbuf, matches[0]); | |
2003 ptag = strtok(tbuf, "\t"); | |
7009 | 2004 if (ptag == NULL) |
8234
dc72f4a463e4
commit https://github.com/vim/vim/commit/42dd7aee41ffcc5afdbf9bb83d70e7123261cada
Christian Brabandt <cb@256bit.org>
parents:
8226
diff
changeset
|
2005 { |
dc72f4a463e4
commit https://github.com/vim/vim/commit/42dd7aee41ffcc5afdbf9bb83d70e7123261cada
Christian Brabandt <cb@256bit.org>
parents:
8226
diff
changeset
|
2006 vim_free(tbuf); |
7009 | 2007 return; |
8234
dc72f4a463e4
commit https://github.com/vim/vim/commit/42dd7aee41ffcc5afdbf9bb83d70e7123261cada
Christian Brabandt <cb@256bit.org>
parents:
8226
diff
changeset
|
2008 } |
7 | 2009 |
835 | 2010 newsize = (int)(strlen(cstag_msg) + strlen(ptag)); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2011 buf = alloc(newsize); |
7 | 2012 if (buf != NULL) |
2013 { | |
2014 bufsize = newsize; | |
2015 (void)sprintf(buf, cstag_msg, ptag); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
2016 msg_puts_attr(buf, HL_ATTR(HLF_T)); |
7 | 2017 } |
2018 | |
2019 vim_free(tbuf); | |
2020 | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
2021 msg_puts_attr(_("\n # line"), HL_ATTR(HLF_T)); /* strlen is 7 */ |
7 | 2022 msg_advance(msg_col + 2); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
2023 msg_puts_attr(_("filename / context / line\n"), HL_ATTR(HLF_T)); |
7 | 2024 |
2025 num = 1; | |
2026 for (i = 0; i < num_matches; i++) | |
2027 { | |
2028 idx = i; | |
2029 | |
2030 /* if we really wanted to, we could avoid this malloc and strcpy | |
2031 * by parsing matches[i] on the fly and placing stuff into buf | |
2032 * directly, but that's too much of a hassle | |
2033 */ | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2034 if ((tbuf = alloc(strlen(matches[idx]) + 1)) == NULL) |
7 | 2035 continue; |
2036 (void)strcpy(tbuf, matches[idx]); | |
2037 | |
8226
cb0edf7bd0a4
commit https://github.com/vim/vim/commit/e16e5a9d8d6d3159107541a259c6823ade18fd08
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2038 if (strtok(tbuf, (const char *)"\t") == NULL |
cb0edf7bd0a4
commit https://github.com/vim/vim/commit/e16e5a9d8d6d3159107541a259c6823ade18fd08
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2039 || (fname = strtok(NULL, (const char *)"\t")) == NULL |
cb0edf7bd0a4
commit https://github.com/vim/vim/commit/e16e5a9d8d6d3159107541a259c6823ade18fd08
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2040 || (lno = strtok(NULL, (const char *)"\t")) == NULL) |
cb0edf7bd0a4
commit https://github.com/vim/vim/commit/e16e5a9d8d6d3159107541a259c6823ade18fd08
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2041 { |
cb0edf7bd0a4
commit https://github.com/vim/vim/commit/e16e5a9d8d6d3159107541a259c6823ade18fd08
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2042 vim_free(tbuf); |
7 | 2043 continue; |
8226
cb0edf7bd0a4
commit https://github.com/vim/vim/commit/e16e5a9d8d6d3159107541a259c6823ade18fd08
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2044 } |
1078 | 2045 extra = strtok(NULL, (const char *)"\t"); |
7 | 2046 |
2047 lno[strlen(lno)-2] = '\0'; /* ignore ;" at the end */ | |
2048 | |
2049 /* hopefully 'num' (num of matches) will be less than 10^16 */ | |
835 | 2050 newsize = (int)(strlen(csfmt_str) + 16 + strlen(lno)); |
7 | 2051 if (bufsize < newsize) |
2052 { | |
6596 | 2053 t_buf = buf; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2054 buf = vim_realloc(buf, newsize); |
7 | 2055 if (buf == NULL) |
6596 | 2056 { |
7 | 2057 bufsize = 0; |
6596 | 2058 vim_free(t_buf); |
2059 } | |
7 | 2060 else |
2061 bufsize = newsize; | |
2062 } | |
2063 if (buf != NULL) | |
2064 { | |
2065 /* csfmt_str = "%4d %6s "; */ | |
2066 (void)sprintf(buf, csfmt_str, num, lno); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
2067 msg_puts_attr(buf, HL_ATTR(HLF_CM)); |
7 | 2068 } |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
2069 msg_outtrans_long_attr((char_u *)cs_pathcomponents(fname), |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
2070 HL_ATTR(HLF_CM)); |
7 | 2071 |
2072 /* compute the required space for the context */ | |
2073 if (cntxts[idx] != NULL) | |
2074 context = cntxts[idx]; | |
2075 else | |
2076 context = globalcntx; | |
835 | 2077 newsize = (int)(strlen(context) + strlen(cntxformat)); |
7 | 2078 |
2079 if (bufsize < newsize) | |
2080 { | |
6596 | 2081 t_buf = buf; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2082 buf = vim_realloc(buf, newsize); |
7 | 2083 if (buf == NULL) |
6596 | 2084 { |
7 | 2085 bufsize = 0; |
6596 | 2086 vim_free(t_buf); |
2087 } | |
7 | 2088 else |
2089 bufsize = newsize; | |
2090 } | |
2091 if (buf != NULL) | |
2092 { | |
2093 (void)sprintf(buf, cntxformat, context); | |
2094 | |
2095 /* print the context only if it fits on the same line */ | |
2096 if (msg_col + (int)strlen(buf) >= (int)Columns) | |
2097 msg_putchar('\n'); | |
2098 msg_advance(12); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
2099 msg_outtrans_long_attr((char_u *)buf, 0); |
7 | 2100 msg_putchar('\n'); |
2101 } | |
2102 if (extra != NULL) | |
2103 { | |
2104 msg_advance(13); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
2105 msg_outtrans_long_attr((char_u *)extra, 0); |
7 | 2106 } |
2107 | |
2108 vim_free(tbuf); /* only after printing extra due to strtok use */ | |
2109 | |
2110 if (msg_col) | |
2111 msg_putchar('\n'); | |
2112 | |
2113 ui_breakcheck(); | |
2114 if (got_int) | |
2115 { | |
2116 got_int = FALSE; /* don't print any more matches */ | |
2117 break; | |
2118 } | |
2119 | |
2120 num++; | |
2121 } /* for all matches */ | |
2122 | |
2123 vim_free(buf); | |
2124 } /* cs_print_tags_priv */ | |
2125 | |
2126 | |
2127 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
2128 * Read a cscope prompt (basically, skip over the ">> "). |
7 | 2129 */ |
2130 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2131 cs_read_prompt(int i) |
7 | 2132 { |
2133 int ch; | |
2134 char *buf = NULL; /* buffer for possible error message from cscope */ | |
2135 int bufpos = 0; | |
2136 char *cs_emsg; | |
2137 int maxlen; | |
2138 static char *eprompt = "Press the RETURN key to continue:"; | |
835 | 2139 int epromptlen = (int)strlen(eprompt); |
7 | 2140 int n; |
2141 | |
2142 cs_emsg = _("E609: Cscope error: %s"); | |
2143 /* compute maximum allowed len for Cscope error message */ | |
2144 maxlen = (int)(IOSIZE - strlen(cs_emsg)); | |
2145 | |
2146 for (;;) | |
2147 { | |
2148 while ((ch = getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0]) | |
2149 /* if there is room and char is printable */ | |
2150 if (bufpos < maxlen - 1 && vim_isprintc(ch)) | |
2151 { | |
2152 if (buf == NULL) /* lazy buffer allocation */ | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2153 buf = alloc(maxlen); |
7 | 2154 if (buf != NULL) |
2155 { | |
2156 /* append character to the message */ | |
2157 buf[bufpos++] = ch; | |
2158 buf[bufpos] = NUL; | |
2159 if (bufpos >= epromptlen | |
2160 && strcmp(&buf[bufpos - epromptlen], eprompt) == 0) | |
2161 { | |
2162 /* remove eprompt from buf */ | |
2163 buf[bufpos - epromptlen] = NUL; | |
2164 | |
2165 /* print message to user */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2166 (void)semsg(cs_emsg, buf); |
7 | 2167 |
2168 /* send RETURN to cscope */ | |
2169 (void)putc('\n', csinfo[i].to_fp); | |
2170 (void)fflush(csinfo[i].to_fp); | |
2171 | |
2172 /* clear buf */ | |
2173 bufpos = 0; | |
2174 buf[bufpos] = NUL; | |
2175 } | |
2176 } | |
2177 } | |
2178 | |
2179 for (n = 0; n < (int)strlen(CSCOPE_PROMPT); ++n) | |
2180 { | |
2181 if (n > 0) | |
2182 ch = getc(csinfo[i].fr_fp); | |
2183 if (ch == EOF) | |
2184 { | |
2185 PERROR("cs_read_prompt EOF"); | |
2186 if (buf != NULL && buf[0] != NUL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2187 (void)semsg(cs_emsg, buf); |
7 | 2188 else if (p_csverbose) |
2189 cs_reading_emsg(i); /* don't have additional information */ | |
2190 cs_release_csp(i, TRUE); | |
2191 vim_free(buf); | |
2192 return CSCOPE_FAILURE; | |
2193 } | |
2194 | |
2195 if (ch != CSCOPE_PROMPT[n]) | |
2196 { | |
2197 ch = EOF; | |
2198 break; | |
2199 } | |
2200 } | |
2201 | |
2202 if (ch == EOF) | |
2203 continue; /* didn't find the prompt */ | |
2204 break; /* did find the prompt */ | |
2205 } | |
2206 | |
2207 vim_free(buf); | |
2208 return CSCOPE_SUCCESS; | |
2209 } | |
2210 | |
1566 | 2211 #if defined(UNIX) && defined(SIGALRM) |
2212 /* | |
2213 * Used to catch and ignore SIGALRM below. | |
2214 */ | |
2215 static RETSIGTYPE | |
2216 sig_handler SIGDEFARG(sigarg) | |
2217 { | |
2218 /* do nothing */ | |
2219 SIGRETURN; | |
2220 } | |
2221 #endif | |
7 | 2222 |
2223 /* | |
1385 | 2224 * Does the actual free'ing for the cs ptr with an optional flag of whether |
2225 * or not to free the filename. Called by cs_kill and cs_reset. | |
7 | 2226 */ |
2227 static void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2228 cs_release_csp(int i, int freefnpp) |
7 | 2229 { |
2230 /* | |
2231 * Trying to exit normally (not sure whether it is fit to UNIX cscope | |
2232 */ | |
2233 if (csinfo[i].to_fp != NULL) | |
2234 { | |
2235 (void)fputs("q\n", csinfo[i].to_fp); | |
2236 (void)fflush(csinfo[i].to_fp); | |
2237 } | |
1566 | 2238 #if defined(UNIX) |
2239 { | |
1575 | 2240 int waitpid_errno; |
1566 | 2241 int pstat; |
2242 pid_t pid; | |
2243 | |
2244 # if defined(HAVE_SIGACTION) | |
2245 struct sigaction sa, old; | |
2246 | |
1568 | 2247 /* Use sigaction() to limit the waiting time to two seconds. */ |
2248 sigemptyset(&sa.sa_mask); | |
1566 | 2249 sa.sa_handler = sig_handler; |
2087
3112fcc89238
updated for version 7.2.371
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
2250 # ifdef SA_NODEFER |
1566 | 2251 sa.sa_flags = SA_NODEFER; |
2087
3112fcc89238
updated for version 7.2.371
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
2252 # else |
3112fcc89238
updated for version 7.2.371
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
2253 sa.sa_flags = 0; |
3112fcc89238
updated for version 7.2.371
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
2254 # endif |
1566 | 2255 sigaction(SIGALRM, &sa, &old); |
2256 alarm(2); /* 2 sec timeout */ | |
2257 | |
2258 /* Block until cscope exits or until timer expires */ | |
2259 pid = waitpid(csinfo[i].pid, &pstat, 0); | |
1575 | 2260 waitpid_errno = errno; |
1566 | 2261 |
2262 /* cancel pending alarm if still there and restore signal */ | |
2263 alarm(0); | |
2264 sigaction(SIGALRM, &old, NULL); | |
2265 # else | |
2266 int waited; | |
2267 | |
2268 /* Can't use sigaction(), loop for two seconds. First yield the CPU | |
2269 * to give cscope a chance to exit quickly. */ | |
2270 sleep(0); | |
2271 for (waited = 0; waited < 40; ++waited) | |
2272 { | |
2273 pid = waitpid(csinfo[i].pid, &pstat, WNOHANG); | |
1575 | 2274 waitpid_errno = errno; |
1566 | 2275 if (pid != 0) |
2276 break; /* break unless the process is still running */ | |
1578 | 2277 mch_delay(50L, FALSE); /* sleep 50 ms */ |
1566 | 2278 } |
2279 # endif | |
2280 /* | |
2281 * If the cscope process is still running: kill it. | |
2282 * Safety check: If the PID would be zero here, the entire X session | |
2283 * would be killed. -1 and 1 are dangerous as well. | |
2284 */ | |
2285 if (pid < 0 && csinfo[i].pid > 1) | |
2286 { | |
1575 | 2287 # ifdef ECHILD |
2288 int alive = TRUE; | |
2289 | |
2290 if (waitpid_errno == ECHILD) | |
2291 { | |
2292 /* | |
2293 * When using 'vim -g', vim is forked and cscope process is | |
2294 * no longer a child process but a sibling. So waitpid() | |
2295 * fails with errno being ECHILD (No child processes). | |
2296 * Don't send SIGKILL to cscope immediately but wait | |
2297 * (polling) for it to exit normally as result of sending | |
2298 * the "q" command, hence giving it a chance to clean up | |
2299 * its temporary files. | |
2300 */ | |
2301 int waited; | |
2302 | |
2303 sleep(0); | |
2304 for (waited = 0; waited < 40; ++waited) | |
2305 { | |
2306 /* Check whether cscope process is still alive */ | |
2307 if (kill(csinfo[i].pid, 0) != 0) | |
2308 { | |
2309 alive = FALSE; /* cscope process no longer exists */ | |
2310 break; | |
2311 } | |
1578 | 2312 mch_delay(50L, FALSE); /* sleep 50ms */ |
1575 | 2313 } |
2314 } | |
2315 if (alive) | |
2316 # endif | |
2317 { | |
2318 kill(csinfo[i].pid, SIGKILL); | |
2319 (void)waitpid(csinfo[i].pid, &pstat, 0); | |
2320 } | |
1566 | 2321 } |
2322 } | |
2323 #else /* !UNIX */ | |
1385 | 2324 if (csinfo[i].hProc != NULL) |
2325 { | |
2326 /* Give cscope a chance to exit normally */ | |
2327 if (WaitForSingleObject(csinfo[i].hProc, 1000) == WAIT_TIMEOUT) | |
2328 TerminateProcess(csinfo[i].hProc, 0); | |
2329 CloseHandle(csinfo[i].hProc); | |
2330 } | |
7 | 2331 #endif |
2332 | |
2333 if (csinfo[i].fr_fp != NULL) | |
2334 (void)fclose(csinfo[i].fr_fp); | |
2335 if (csinfo[i].to_fp != NULL) | |
2336 (void)fclose(csinfo[i].to_fp); | |
2337 | |
2338 if (freefnpp) | |
2339 { | |
2340 vim_free(csinfo[i].fname); | |
2341 vim_free(csinfo[i].ppath); | |
2342 vim_free(csinfo[i].flags); | |
2343 } | |
2344 | |
2345 clear_csinfo(i); | |
2346 } /* cs_release_csp */ | |
2347 | |
2348 | |
2349 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
2350 * Calls cs_kill on all cscope connections then reinits. |
7 | 2351 */ |
2352 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2353 cs_reset(exarg_T *eap UNUSED) |
7 | 2354 { |
2355 char **dblist = NULL, **pplist = NULL, **fllist = NULL; | |
2356 int i; | |
273 | 2357 char buf[20]; /* for sprintf " (#%d)" */ |
7 | 2358 |
1931 | 2359 if (csinfo_size == 0) |
2360 return CSCOPE_SUCCESS; | |
2361 | |
7 | 2362 /* malloc our db and ppath list */ |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2363 dblist = ALLOC_MULT(char *, csinfo_size); |
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2364 pplist = ALLOC_MULT(char *, csinfo_size); |
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2365 fllist = ALLOC_MULT(char *, csinfo_size); |
7 | 2366 if (dblist == NULL || pplist == NULL || fllist == NULL) |
2367 { | |
2368 vim_free(dblist); | |
2369 vim_free(pplist); | |
2370 vim_free(fllist); | |
2371 return CSCOPE_FAILURE; | |
2372 } | |
2373 | |
1931 | 2374 for (i = 0; i < csinfo_size; i++) |
7 | 2375 { |
2376 dblist[i] = csinfo[i].fname; | |
2377 pplist[i] = csinfo[i].ppath; | |
2378 fllist[i] = csinfo[i].flags; | |
2379 if (csinfo[i].fname != NULL) | |
2380 cs_release_csp(i, FALSE); | |
2381 } | |
2382 | |
2383 /* rebuild the cscope connection list */ | |
1931 | 2384 for (i = 0; i < csinfo_size; i++) |
7 | 2385 { |
2386 if (dblist[i] != NULL) | |
2387 { | |
2388 cs_add_common(dblist[i], pplist[i], fllist[i]); | |
2389 if (p_csverbose) | |
2390 { | |
1372 | 2391 /* don't use smsg_attr() because we want to display the |
7 | 2392 * connection number in the same line as |
2393 * "Added cscope database..." | |
2394 */ | |
2395 sprintf(buf, " (#%d)", i); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
2396 msg_puts_attr(buf, HL_ATTR(HLF_R)); |
7 | 2397 } |
2398 } | |
2399 vim_free(dblist[i]); | |
2400 vim_free(pplist[i]); | |
2401 vim_free(fllist[i]); | |
2402 } | |
2403 vim_free(dblist); | |
2404 vim_free(pplist); | |
2405 vim_free(fllist); | |
2406 | |
2407 if (p_csverbose) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
2408 msg_attr(_("All cscope databases reset"), HL_ATTR(HLF_R) | MSG_HIST); |
7 | 2409 return CSCOPE_SUCCESS; |
2410 } /* cs_reset */ | |
2411 | |
2412 | |
2413 /* | |
4581
6a73ac422c67
updated for version 7.3.1038
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2414 * Construct the full pathname to a file found in the cscope database. |
7 | 2415 * (Prepends ppath, if there is one and if it's not already prepended, |
2416 * otherwise just uses the name found.) | |
2417 * | |
4581
6a73ac422c67
updated for version 7.3.1038
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2418 * We need to prepend the prefix because on some cscope's (e.g., the one that |
7 | 2419 * ships with Solaris 2.6), the output never has the prefix prepended. |
4581
6a73ac422c67
updated for version 7.3.1038
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2420 * Contrast this with my development system (Digital Unix), which does. |
7 | 2421 */ |
2422 static char * | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2423 cs_resolve_file(int i, char *name) |
7 | 2424 { |
2873 | 2425 char *fullname; |
2426 int len; | |
2427 char_u *csdir = NULL; | |
7 | 2428 |
2429 /* | |
2873 | 2430 * Ppath is freed when we destroy the cscope connection. |
2431 * Fullname is freed after cs_make_vim_style_matches, after it's been | |
2432 * copied into the tag buffer used by Vim. | |
7 | 2433 */ |
835 | 2434 len = (int)(strlen(name) + 2); |
7 | 2435 if (csinfo[i].ppath != NULL) |
835 | 2436 len += (int)strlen(csinfo[i].ppath); |
2873 | 2437 else if (p_csre && csinfo[i].fname != NULL) |
2438 { | |
2439 /* If 'cscoperelative' is set and ppath is not set, use cscope.out | |
2440 * path in path resolution. */ | |
2441 csdir = alloc(MAXPATHL); | |
2442 if (csdir != NULL) | |
2443 { | |
2444 vim_strncpy(csdir, (char_u *)csinfo[i].fname, | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13136
diff
changeset
|
2445 gettail((char_u *)csinfo[i].fname) |
4581
6a73ac422c67
updated for version 7.3.1038
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2446 - (char_u *)csinfo[i].fname); |
2873 | 2447 len += (int)STRLEN(csdir); |
2448 } | |
2449 } | |
7 | 2450 |
2873 | 2451 /* Note/example: this won't work if the cscope output already starts |
7 | 2452 * "../.." and the prefix path is also "../..". if something like this |
2873 | 2453 * happens, you are screwed up and need to fix how you're using cscope. */ |
2454 if (csinfo[i].ppath != NULL | |
2455 && (strncmp(name, csinfo[i].ppath, strlen(csinfo[i].ppath)) != 0) | |
2456 && (name[0] != '/') | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2457 #ifdef MSWIN |
2873 | 2458 && name[0] != '\\' && name[1] != ':' |
7 | 2459 #endif |
2873 | 2460 ) |
4581
6a73ac422c67
updated for version 7.3.1038
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2461 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2462 if ((fullname = alloc(len)) != NULL) |
4581
6a73ac422c67
updated for version 7.3.1038
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2463 (void)sprintf(fullname, "%s/%s", csinfo[i].ppath, name); |
6a73ac422c67
updated for version 7.3.1038
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2464 } |
6a73ac422c67
updated for version 7.3.1038
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2465 else if (csdir != NULL && csinfo[i].fname != NULL && *csdir != NUL) |
2873 | 2466 { |
2467 /* Check for csdir to be non empty to avoid empty path concatenated to | |
4581
6a73ac422c67
updated for version 7.3.1038
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2468 * cscope output. */ |
2875 | 2469 fullname = (char *)concat_fnames(csdir, (char_u *)name, TRUE); |
2873 | 2470 } |
7 | 2471 else |
4581
6a73ac422c67
updated for version 7.3.1038
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2472 { |
6a73ac422c67
updated for version 7.3.1038
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2473 fullname = (char *)vim_strsave((char_u *)name); |
6a73ac422c67
updated for version 7.3.1038
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2474 } |
7 | 2475 |
2873 | 2476 vim_free(csdir); |
7 | 2477 return fullname; |
2873 | 2478 } |
7 | 2479 |
2480 | |
2481 /* | |
10373
bd674706408a
commit https://github.com/vim/vim/commit/d4db7719bdfbc54df396eac08d8cbb2389feacf4
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
2482 * Show all cscope connections. |
7 | 2483 */ |
2484 static int | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2485 cs_show(exarg_T *eap UNUSED) |
7 | 2486 { |
2487 short i; | |
2488 if (cs_cnt_connections() == 0) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
2489 msg_puts(_("no cscope connections\n")); |
7 | 2490 else |
2491 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
2492 msg_puts_attr( |
7 | 2493 _(" # pid database name prepend path\n"), |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2494 HL_ATTR(HLF_T)); |
1931 | 2495 for (i = 0; i < csinfo_size; i++) |
7 | 2496 { |
2497 if (csinfo[i].fname == NULL) | |
2498 continue; | |
2499 | |
2500 if (csinfo[i].ppath != NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2501 (void)smsg("%2d %-5ld %-34s %-32s", |
7 | 2502 i, (long)csinfo[i].pid, csinfo[i].fname, csinfo[i].ppath); |
2503 else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2504 (void)smsg("%2d %-5ld %-34s <none>", |
7 | 2505 i, (long)csinfo[i].pid, csinfo[i].fname); |
2506 } | |
2507 } | |
2508 | |
2509 wait_return(TRUE); | |
2510 return CSCOPE_SUCCESS; | |
2511 } /* cs_show */ | |
2512 | |
1385 | 2513 |
2514 /* | |
2515 * Only called when VIM exits to quit any cscope sessions. | |
2516 */ | |
2517 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2518 cs_end(void) |
1385 | 2519 { |
2520 int i; | |
2521 | |
1931 | 2522 for (i = 0; i < csinfo_size; i++) |
1385 | 2523 cs_release_csp(i, TRUE); |
1931 | 2524 vim_free(csinfo); |
2525 csinfo_size = 0; | |
1385 | 2526 } |
2527 | |
7 | 2528 #endif /* FEAT_CSCOPE */ |
2529 | |
2530 /* the end */ |