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