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