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