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