annotate src/if_cscope.c @ 1297:e2680bc6a180 v7.1.011

updated for version 7.1-011
author vimboss
date Tue, 19 Jun 2007 18:27:18 +0000
parents 9a3b65713280
children 76a42a81f685
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * CSCOPE support for Vim added by Andy Kahn <kahn@zk3.dec.com>
148
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 36
diff changeset
4 * Ported to Win32 by Sergey Khorev <sergey.khorev@gmail.com>
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * The basic idea/structure of cscope for Vim was borrowed from Nvi. There
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * might be a few lines of code that look similar to what Nvi has.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 #if defined(FEAT_CSCOPE) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 #include <string.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 #include <errno.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 #include <assert.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 #include <sys/types.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 #include <sys/stat.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 #if defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 # include <sys/wait.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 /* not UNIX, must be WIN32 */
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 665
diff changeset
25 # include "vimio.h"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 # include <fcntl.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 # include <process.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 # define STDIN_FILENO 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 # define STDOUT_FILENO 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 # define STDERR_FILENO 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 # define pipe(fds) _pipe(fds, 256, O_TEXT|O_NOINHERIT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 #include "if_cscope.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 static void cs_usage_msg __ARGS((csid_e x));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 static int cs_add __ARGS((exarg_T *eap));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 static void cs_stat_emsg __ARGS((char *fname));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 static int cs_add_common __ARGS((char *, char *, char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 static int cs_check_for_connections __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 static int cs_check_for_tags __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 static int cs_cnt_connections __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 static void cs_reading_emsg __ARGS((int idx));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 static int cs_cnt_matches __ARGS((int idx));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 static char * cs_create_cmd __ARGS((char *csoption, char *pattern));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 static int cs_create_connection __ARGS((int i));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 static void do_cscope_general __ARGS((exarg_T *eap, int make_split));
636
5ad3b5d4ecc0 updated for version 7.0184
vimboss
parents: 531
diff changeset
47 #ifdef FEAT_QUICKFIX
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 static void cs_file_results __ARGS((FILE *, int *));
636
5ad3b5d4ecc0 updated for version 7.0184
vimboss
parents: 531
diff changeset
49 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 static void cs_fill_results __ARGS((char *, int , int *, char ***,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 char ***, int *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 static int cs_find __ARGS((exarg_T *eap));
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 644
diff changeset
53 static int cs_find_common __ARGS((char *opt, char *pat, int, int, int));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 static int cs_help __ARGS((exarg_T *eap));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 static void cs_init __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 static void clear_csinfo __ARGS((int i));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 static int cs_insert_filelist __ARGS((char *, char *, char *,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 struct stat *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 static int cs_kill __ARGS((exarg_T *eap));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 static void cs_kill_execute __ARGS((int, char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 static cscmd_T * cs_lookup_cmd __ARGS((exarg_T *eap));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 static char * cs_make_vim_style_matches __ARGS((char *, char *,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 char *, char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 static char * cs_manage_matches __ARGS((char **, char **, int, mcmd_e));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 static char * cs_parse_results __ARGS((int cnumber, char *buf, int bufsize, char **context, char **linenumber, char **search));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 static char * cs_pathcomponents __ARGS((char *path));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 static void cs_print_tags_priv __ARGS((char **, char **, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 static int cs_read_prompt __ARGS((int ));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 static void cs_release_csp __ARGS((int, int freefnpp));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 static int cs_reset __ARGS((exarg_T *eap));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 static char * cs_resolve_file __ARGS((int, char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 static int cs_show __ARGS((exarg_T *eap));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 static csinfo_T csinfo[CSCOPE_MAX_CONNECTIONS];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 static cscmd_T cs_cmds[] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 { "add", cs_add,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 N_("Add a new database"), "add file|dir [pre-path] [flags]", 0 },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 { "find", cs_find,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 N_("Query for a pattern"), FIND_USAGE, 1 },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 { "help", cs_help,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 N_("Show this message"), "help", 0 },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 { "kill", cs_kill,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 N_("Kill a connection"), "kill #", 0 },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 { "reset", cs_reset,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 N_("Reinit all connections"), "reset", 0 },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 { "show", cs_show,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 N_("Show connections"), "show", 0 },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 { NULL }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 cs_usage_msg(x)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 csid_e x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 (void)EMSG2(_("E560: Usage: cs[cope] %s"), cs_cmds[(int)x].usage);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 * PRIVATE: do_cscope_general
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 * find the command, print help if invalid, and the then call the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 * corresponding command function,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 * called from do_cscope and do_scscope
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 do_cscope_general(eap, make_split)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 int make_split; /* whether to split window */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 cscmd_T *cmdp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 cs_init();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 if ((cmdp = cs_lookup_cmd(eap)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 cs_help(eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 if (make_split)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 if (!cmdp->cansplit)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 (void)MSG_PUTS(_("This cscope command does not support splitting the window.\n"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 postponed_split = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 postponed_split_flags = cmdmod.split;
1090
9a3b65713280 updated for version 7.0-216
vimboss
parents: 1078
diff changeset
131 postponed_split_tab = cmdmod.tab;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 cmdp->func(eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 postponed_split_flags = 0;
1090
9a3b65713280 updated for version 7.0-216
vimboss
parents: 1078
diff changeset
139 postponed_split_tab = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 * PUBLIC: do_cscope
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 do_cscope(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 do_cscope_general(eap, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 * PUBLIC: do_scscope
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 * same as do_cscope, but splits window, too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 do_scscope(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 do_cscope_general(eap, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 * PUBLIC: do_cstag
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 do_cstag(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 int ret = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 cs_init();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 if (eap->arg == NULL || strlen((const char *)(eap->arg)) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 (void)EMSG(_("E562: Usage: cstag <ident>"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 switch (p_csto)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 case 0 :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 if (cs_check_for_connections())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 {
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 644
diff changeset
188 ret = cs_find_common("g", (char *)(eap->arg), eap->forceit, FALSE,
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 644
diff changeset
189 FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 if (ret == FALSE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 cs_free_tags();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 if (msg_col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 msg_putchar('\n');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 if (cs_check_for_tags())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 else if (cs_check_for_tags())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 case 1 :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 if (cs_check_for_tags())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 if (ret == FALSE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 if (msg_col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 msg_putchar('\n');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 if (cs_check_for_connections())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 ret = cs_find_common("g", (char *)(eap->arg), eap->forceit,
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 644
diff changeset
217 FALSE, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 if (ret == FALSE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 cs_free_tags();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 else if (cs_check_for_connections())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 {
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 644
diff changeset
225 ret = cs_find_common("g", (char *)(eap->arg), eap->forceit, FALSE,
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 644
diff changeset
226 FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 if (ret == FALSE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 cs_free_tags();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 default :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 if (!ret)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 (void)EMSG(_("E257: cstag: tag not found"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 g_do_tagpreview = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 } /* do_cscope */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 * PUBLIC: cs_find
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 * this simulates a vim_fgets(), but for cscope, returns the next line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 * from the cscope output. should only be called from find_tags()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 * returns TRUE if eof, FALSE otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 cs_fgets(buf, size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 int size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 char *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 if ((p = cs_manage_matches(NULL, NULL, -1, Get)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 if ((int)strlen(p) > size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 strncpy((char *)buf, p, size - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 buf[size] = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 (void)strcpy((char *)buf, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 } /* cs_fgets */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 * PUBLIC: cs_free_tags
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 * called only from do_tag(), when popping the tag stack
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 cs_free_tags()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 cs_manage_matches(NULL, NULL, -1, Free);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 * PUBLIC: cs_print_tags
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 * called from do_tag()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 cs_print_tags()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 cs_manage_matches(NULL, NULL, -1, Print);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 * "cscope_connection([{num} , {dbpath} [, {prepend}]])" function
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 * Checks for the existence of a |cscope| connection. If no
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 * parameters are specified, then the function returns:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 * 0, if cscope was not available (not compiled in), or if there
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 * are no cscope connections; or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 * 1, if there is at least one cscope connection.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 * If parameters are specified, then the value of {num}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 * determines how existence of a cscope connection is checked:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 * {num} Description of existence check
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 * ----- ------------------------------
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 * 0 Same as no parameters (e.g., "cscope_connection()").
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 * 1 Ignore {prepend}, and use partial string matches for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 * {dbpath}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 * 2 Ignore {prepend}, and use exact string matches for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 * {dbpath}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 * 3 Use {prepend}, use partial string matches for both
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 * {dbpath} and {prepend}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 * 4 Use {prepend}, use exact string matches for both
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 * {dbpath} and {prepend}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 * Note: All string comparisons are case sensitive!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 #if defined(FEAT_EVAL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 cs_connection(num, dbpath, ppath)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 int num;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 char_u *dbpath;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 char_u *ppath;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 if (num < 0 || num > 4 || (num > 0 && !dbpath))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 if (!csinfo[i].fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 if (num == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 switch (num)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 case 1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 if (strstr(csinfo[i].fname, (char *)dbpath))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 case 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 if (strcmp(csinfo[i].fname, (char *)dbpath) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 case 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 if (strstr(csinfo[i].fname, (char *)dbpath)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 && ((!ppath && !csinfo[i].ppath)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 || (ppath
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 && csinfo[i].ppath
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 && strstr(csinfo[i].ppath, (char *)ppath))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 case 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 if ((strcmp(csinfo[i].fname, (char *)dbpath) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 && ((!ppath && !csinfo[i].ppath)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 || (ppath
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 && csinfo[i].ppath
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 && (strcmp(csinfo[i].ppath, (char *)ppath) == 0))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 } /* cs_connection */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 * PRIVATE functions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 ****************************************************************************/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 * PRIVATE: cs_add
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 * add cscope database or a directory name (to look for cscope.out)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 * the the cscope connection list
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 * MAXPATHL 256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 /* ARGSUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 cs_add(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 char *fname, *ppath, *flags = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 if ((fname = strtok((char *)NULL, (const char *)" ")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 cs_usage_msg(Add);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 return CSCOPE_FAILURE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 if ((ppath = strtok((char *)NULL, (const char *)" ")) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 flags = strtok((char *)NULL, (const char *)" ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 return cs_add_common(fname, ppath, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 cs_stat_emsg(fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 char *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 char *stat_emsg = _("E563: stat(%s) error: %d");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 char *buf = (char *)alloc((unsigned)strlen(stat_emsg) + MAXPATHL + 10);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 (void)sprintf(buf, stat_emsg, fname, errno);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 (void)EMSG(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 (void)EMSG(_("E563: stat error"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 * PRIVATE: cs_add_common
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 * the common routine to add a new cscope connection. called by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 * cs_add() and cs_reset(). i really don't like to do this, but this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 * routine uses a number of goto statements.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 cs_add_common(arg1, arg2, flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 char *arg1; /* filename - may contain environment variables */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 char *arg2; /* prepend path - may contain environment variables */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 char *flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 struct stat statbuf;
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 7
diff changeset
443 int ret;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 7
diff changeset
444 char *fname = NULL;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 7
diff changeset
445 char *fname2 = NULL;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 7
diff changeset
446 char *ppath = NULL;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 7
diff changeset
447 int i;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 /* get the filename (arg1), expand it, and try to stat it */
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 7
diff changeset
450 if ((fname = (char *)alloc(MAXPATHL + 1)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 goto add_err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 ret = stat(fname, &statbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 if (ret < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 staterr:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 if (p_csverbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 cs_stat_emsg(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 goto add_err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 /* get the prepend path (arg2), expand it, and try to stat it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 if (arg2 != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 struct stat statbuf2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 7
diff changeset
468 if ((ppath = (char *)alloc(MAXPATHL + 1)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 goto add_err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 expand_env((char_u *)arg2, (char_u *)ppath, MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 ret = stat(ppath, &statbuf2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 if (ret < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 goto staterr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 /* if filename is a directory, append the cscope database name to it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
480 fname2 = (char *)alloc((unsigned)(strlen(CSCOPE_DBFILE) + strlen(fname) + 2));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 if (fname2 == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 goto add_err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 while (fname[strlen(fname)-1] == '/'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 #ifdef WIN32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 || fname[strlen(fname)-1] == '\\'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 fname[strlen(fname)-1] = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 if (strlen(fname) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 if (fname[0] == '\0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 (void)sprintf(fname2, "/%s", CSCOPE_DBFILE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 (void)sprintf(fname2, "%s/%s", fname, CSCOPE_DBFILE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 ret = stat(fname2, &statbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 if (ret < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 if (p_csverbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 cs_stat_emsg(fname2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 goto add_err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 i = cs_insert_filelist(fname2, ppath, flags, &statbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 #if defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 else if (S_ISREG(statbuf.st_mode) || S_ISLNK(statbuf.st_mode))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 /* substitute define S_ISREG from os_unix.h */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 else if (((statbuf.st_mode) & S_IFMT) == S_IFREG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 i = cs_insert_filelist(fname, ppath, flags, &statbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 if (p_csverbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 (void)EMSG2(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 _("E564: %s is not a directory or a valid cscope database"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 goto add_err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 if (i != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 if (cs_create_connection(i) == CSCOPE_FAILURE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 || cs_read_prompt(i) == CSCOPE_FAILURE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 cs_release_csp(i, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 goto add_err;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 if (p_csverbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 msg_clr_eos();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 (void)smsg_attr(hl_attr(HLF_R),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 (char_u *)_("Added cscope database %s"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 csinfo[i].fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 vim_free(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 vim_free(fname2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 vim_free(ppath);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 return CSCOPE_SUCCESS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 add_err:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 vim_free(fname2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 vim_free(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 vim_free(ppath);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 return CSCOPE_FAILURE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 } /* cs_add_common */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 cs_check_for_connections()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 return (cs_cnt_connections() > 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 } /* cs_check_for_connections */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 cs_check_for_tags()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 {
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
568 return (p_tags[0] != NUL && curbuf->b_p_tags != NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 } /* cs_check_for_tags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 * PRIVATE: cs_cnt_connections
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 * count the number of cscope connections
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 cs_cnt_connections()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 short i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 short cnt = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 if (csinfo[i].fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 cnt++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 return cnt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 } /* cs_cnt_connections */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 cs_reading_emsg(idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 int idx; /* connection index */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 EMSGN(_("E262: error reading cscope connection %ld"), idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 #define CSREAD_BUFSIZE 2048
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 * PRIVATE: cs_cnt_matches
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 * count the number of matches for a given cscope connection.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 cs_cnt_matches(idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 int idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 char *stok;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 char *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 int nlines;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 buf = (char *)alloc(CSREAD_BUFSIZE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 if (!fgets(buf, CSREAD_BUFSIZE, csinfo[idx].fr_fp))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 if (feof(csinfo[idx].fr_fp))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 errno = EIO;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 cs_reading_emsg(idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 * If the database is out of date, or there's some other problem,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 * cscope will output error messages before the number-of-lines output.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 * Display/discard any output that doesn't match what we want.
1058
a565175274f6 updated for version 7.0-184
vimboss
parents: 1040
diff changeset
632 * Accept "\S*cscope: X lines", also matches "mlcscope".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 if ((stok = strtok(buf, (const char *)" ")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 continue;
1058
a565175274f6 updated for version 7.0-184
vimboss
parents: 1040
diff changeset
636 if (strstr((const char *)stok, "cscope:") == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 if ((stok = strtok(NULL, (const char *)" ")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 nlines = atoi(stok);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 if (nlines < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 nlines = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 if ((stok = strtok(NULL, (const char *)" ")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 if (strncmp((const char *)stok, "lines", 5))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 return nlines;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 } /* cs_cnt_matches */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 * PRIVATE: cs_create_cmd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 * Creates the actual cscope command query from what the user entered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 static char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 cs_create_cmd(csoption, pattern)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 char *csoption;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 char *pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 char *cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 short search;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 switch (csoption[0])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 case '0' : case 's' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 search = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 case '1' : case 'g' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 search = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 case '2' : case 'd' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 search = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 case '3' : case 'c' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 search = 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 case '4' : case 't' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 search = 4;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 case '6' : case 'e' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 search = 6;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 case '7' : case 'f' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 search = 7;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 case '8' : case 'i' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 search = 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 default :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 (void)EMSG(_("E561: unknown cscope search type"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 cs_usage_msg(Find);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
706 if ((cmd = (char *)alloc((unsigned)(strlen(pattern) + 2))) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 (void)sprintf(cmd, "%d%s", search, pattern);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 return cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 } /* cs_create_cmd */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 * PRIVATE: cs_create_connection
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 * This piece of code was taken/adapted from nvi. do we need to add
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 * the BSD license notice?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 cs_create_connection(i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 int to_cs[2], from_cs[2], len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 char *prog, *cmd, *ppath = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 #ifndef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 int in_save, out_save, err_save;
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
729 long_i ph;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 # ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 HWND activewnd = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 HWND consolewnd = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 * Cscope reads from to_cs[0] and writes to from_cs[1]; vi reads from
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 * from_cs[0] and writes to to_cs[1].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 to_cs[0] = to_cs[1] = from_cs[0] = from_cs[1] = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 if (pipe(to_cs) < 0 || pipe(from_cs) < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 (void)EMSG(_("E566: Could not create cscope pipes"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 err_closing:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 if (to_cs[0] != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 (void)close(to_cs[0]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 if (to_cs[1] != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 (void)close(to_cs[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 if (from_cs[0] != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 (void)close(from_cs[0]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 if (from_cs[1] != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 (void)close(from_cs[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 return CSCOPE_FAILURE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 #if defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 switch (csinfo[i].pid = fork())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 case -1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 (void)EMSG(_("E622: Could not fork for cscope"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 goto err_closing;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 case 0: /* child: run cscope. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 in_save = dup(STDIN_FILENO);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 out_save = dup(STDOUT_FILENO);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 err_save = dup(STDERR_FILENO);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 if (dup2(to_cs[0], STDIN_FILENO) == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 PERROR("cs_create_connection 1");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 if (dup2(from_cs[1], STDOUT_FILENO) == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 PERROR("cs_create_connection 2");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 if (dup2(from_cs[1], STDERR_FILENO) == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 PERROR("cs_create_connection 3");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 /* close unused */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 #if defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 (void)close(to_cs[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 (void)close(from_cs[0]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 /* On win32 we must close opposite ends because we are the parent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 (void)close(to_cs[0]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 to_cs[0] = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 (void)close(from_cs[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 from_cs[1] = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 /* expand the cscope exec for env var's */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 if ((prog = (char *)alloc(MAXPATHL + 1)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 return CSCOPE_FAILURE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 goto err_closing;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 expand_env((char_u *)p_csprg, (char_u *)prog, MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 /* alloc space to hold the cscope command */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
798 len = (int)(strlen(prog) + strlen(csinfo[i].fname) + 32);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 if (csinfo[i].ppath)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 /* expand the prepend path for env var's */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 if ((ppath = (char *)alloc(MAXPATHL + 1)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 vim_free(prog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 return CSCOPE_FAILURE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 goto err_closing;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 expand_env((char_u *)csinfo[i].ppath, (char_u *)ppath, MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
813 len += (int)strlen(ppath);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 if (csinfo[i].flags)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
817 len += (int)strlen(csinfo[i].flags);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 if ((cmd = (char *)alloc(len)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 vim_free(prog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 vim_free(ppath);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 return CSCOPE_FAILURE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 goto err_closing;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 /* run the cscope command; is there execl for non-unix systems? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 #if defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 (void)sprintf(cmd, "exec %s -dl -f %s", prog, csinfo[i].fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 (void)sprintf(cmd, "%s -dl -f %s", prog, csinfo[i].fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 if (csinfo[i].ppath != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 (void)strcat(cmd, " -P");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 (void)strcat(cmd, csinfo[i].ppath);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 if (csinfo[i].flags != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 (void)strcat(cmd, " ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 (void)strcat(cmd, csinfo[i].flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 /* on Win32 we still need prog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 vim_free(prog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 vim_free(ppath);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 #if defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 if (execl("/bin/sh", "sh", "-c", cmd, NULL) == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 PERROR(_("cs_create_connection exec failed"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 exit(127);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 /* NOTREACHED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 default: /* parent. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 # ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 activewnd = GetForegroundWindow(); /* on win9x cscope steals focus */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 /* Dirty hack to hide annoying console window */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 if (AllocConsole())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 char *title;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 title = (char *)alloc(1024);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 if (title == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 FreeConsole();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 GetConsoleTitle(title, 1024); /* save for future restore */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 SetConsoleTitle(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 "GVIMCS{5499421B-CBEF-45b0-85EF-38167FDEA5C5}GVIMCS");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 Sleep(40); /* as stated in MS KB we must wait 40 ms */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 consolewnd = FindWindow(NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 "GVIMCS{5499421B-CBEF-45b0-85EF-38167FDEA5C5}GVIMCS");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 if (consolewnd != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 ShowWindow(consolewnd, SW_HIDE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 SetConsoleTitle(title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 vim_free(title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 /* May be use &shell, &shellquote etc */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 # ifdef __BORLANDC__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 /* BCC 5.5 uses a different function name for spawnlp */
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
887 ph = (long_i)spawnlp(P_NOWAIT, prog, cmd, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 # else
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
889 ph = (long_i)_spawnlp(_P_NOWAIT, prog, cmd, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 vim_free(prog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 vim_free(cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 # ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 /* Dirty hack part two */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 if (activewnd != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 /* restoring focus */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 SetForegroundWindow(activewnd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 if (consolewnd != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 FreeConsole();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 if (ph == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 PERROR(_("cs_create_connection exec failed"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 (void)EMSG(_("E623: Could not spawn cscope process"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 goto err_closing;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 /* else */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 csinfo[i].pid = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 csinfo[i].hProc = (HANDLE)ph;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 #endif /* !UNIX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 * Save the file descriptors for later duplication, and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 * reopen as streams.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917 if ((csinfo[i].to_fp = fdopen(to_cs[1], "w")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 PERROR(_("cs_create_connection: fdopen for to_fp failed"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 if ((csinfo[i].fr_fp = fdopen(from_cs[0], "r")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 PERROR(_("cs_create_connection: fdopen for fr_fp failed"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 #if defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 /* close unused */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 (void)close(to_cs[0]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 (void)close(from_cs[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 /* restore stdhandles */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 dup2(in_save, STDIN_FILENO);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932 dup2(out_save, STDOUT_FILENO);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933 dup2(err_save, STDERR_FILENO);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934 close(in_save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935 close(out_save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 close(err_save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 return CSCOPE_SUCCESS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 } /* cs_create_connection */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943 * PRIVATE: cs_find
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 * query cscope using command line interface. parse the output and use tselect
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 * to allow choices. like Nvi, creates a pipe to send to/from query/cscope.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 * returns TRUE if we jump to a tag or abort, FALSE if not.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
949 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951 cs_find(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954 char *opt, *pat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956 if (cs_check_for_connections() == FALSE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958 (void)EMSG(_("E567: no cscope connections"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 if ((opt = strtok((char *)NULL, (const char *)" ")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964 cs_usage_msg(Find);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 pat = opt + strlen(opt) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969 if (pat == NULL || (pat != NULL && pat[0] == '\0'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 cs_usage_msg(Find);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 644
diff changeset
975 return cs_find_common(opt, pat, eap->forceit, TRUE,
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 644
diff changeset
976 eap->cmdidx == CMD_lcscope);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977 } /* cs_find */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981 * PRIVATE: cs_find_common
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 * common code for cscope find, shared by cs_find() and do_cstag()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
985 static int
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 644
diff changeset
986 cs_find_common(opt, pat, forceit, verbose, use_ll)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987 char *opt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988 char *pat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989 int forceit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 int verbose;
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 644
diff changeset
991 int use_ll;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994 char *cmd;
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 836
diff changeset
995 int nummatches[CSCOPE_MAX_CONNECTIONS], totmatches;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 #ifdef FEAT_QUICKFIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 char cmdletter;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 char *qfpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 /* create the actual command to send to cscope */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 cmd = cs_create_cmd(opt, pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 if (cmd == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 /* send query to all open connections, then count the total number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 * of matches so we can alloc matchesp all in one swell foop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 nummatches[i] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 totmatches = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 {
1040
65e0c2e3a352 updated for version 7.0-166
vimboss
parents: 1027
diff changeset
1014 if (csinfo[i].fname == NULL || csinfo[i].to_fp == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 /* send cmd to cscope */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 (void)fprintf(csinfo[i].to_fp, "%s\n", cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019 (void)fflush(csinfo[i].to_fp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 nummatches[i] = cs_cnt_matches(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023 if (nummatches[i] > -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 totmatches += nummatches[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 if (nummatches[i] == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 (void)cs_read_prompt(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029 vim_free(cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 if (totmatches == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 char *nf = _("E259: no matches found for cscope query %s of %s");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 char *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036 if (!verbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
1039 buf = (char *)alloc((unsigned)(strlen(opt) + strlen(pat) + strlen(nf)));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 (void)EMSG(nf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 sprintf(buf, nf, opt, pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045 (void)EMSG(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 #ifdef FEAT_QUICKFIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 /* get cmd letter */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 switch (opt[0])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 case '0' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056 cmdletter = 's';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 case '1' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 cmdletter = 'g';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 case '2' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 cmdletter = 'd';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 case '3' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 cmdletter = 'c';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 case '4' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 cmdletter = 't';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 case '6' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 cmdletter = 'e';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 case '7' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 cmdletter = 'f';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 case '8' :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 cmdletter = 'i';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 default :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 cmdletter = opt[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 qfpos = (char *)vim_strchr(p_csqf, cmdletter);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 if (qfpos != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 qfpos++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 /* next symbol must be + or - */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 if (strchr(CSQF_FLAGS, *qfpos) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 char *nf = _("E469: invalid cscopequickfix flag %c for %c");
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
1091 char *buf = (char *)alloc((unsigned)strlen(nf));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 /* strlen will be enough because we use chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 sprintf(buf, nf, *qfpos, *(qfpos-1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 (void)EMSG(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 }
36
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
1103 if (qfpos != NULL && *qfpos != '0' && totmatches > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 /* fill error list */
1027
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1106 FILE *f;
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1107 char_u *tmp = vim_tempname('c');
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 644
diff changeset
1108 qf_info_T *qi = NULL;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 644
diff changeset
1109 win_T *wp = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110
531
da9142bd190a updated for version 7.0149
vimboss
parents: 323
diff changeset
1111 f = mch_fopen((char *)tmp, "w");
1027
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1112 if (f == NULL)
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1113 EMSG2(_(e_notopen), tmp);
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1114 else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115 {
1027
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1116 cs_file_results(f, nummatches);
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1117 fclose(f);
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1118 if (use_ll) /* Use location list */
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1119 wp = curwin;
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1120 /* '-' starts a new error list */
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1121 if (qf_init(wp, tmp, (char_u *)"%f%*\\t%l%*\\t%m",
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1122 *qfpos == '-') > 0)
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1123 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 # ifdef FEAT_WINDOWS
1027
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1125 if (postponed_split != 0)
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1126 {
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1127 win_split(postponed_split > 0 ? postponed_split : 0,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 postponed_split_flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 # ifdef FEAT_SCROLLBIND
1027
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1130 curwin->w_p_scb = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 # endif
1027
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1132 postponed_split = 0;
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1133 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 # endif
1027
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1135 if (use_ll)
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1136 /*
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1137 * In the location list window, use the displayed location
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1138 * list. Otherwise, use the location list for the window.
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1139 */
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1140 qi = (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL)
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1141 ? wp->w_llist_ref : wp->w_llist;
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1142 qf_jump(qi, 0, 0, forceit);
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1143 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 mch_remove(tmp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 vim_free(tmp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 #endif /* FEAT_QUICKFIX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 {
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 836
diff changeset
1152 char **matches = NULL, **contexts = NULL;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 836
diff changeset
1153 int matched = 0;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 836
diff changeset
1154
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 /* read output */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 cs_fill_results((char *)pat, totmatches, nummatches, &matches,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 &contexts, &matched);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 if (matches == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160
293
f811be6fa9b5 updated for version 7.0077
vimboss
parents: 273
diff changeset
1161 (void)cs_manage_matches(matches, contexts, matched, Store);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 } /* cs_find_common */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 * PRIVATE: cs_help
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 * print help
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 /* ARGSUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 cs_help(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 cscmd_T *cmdp = cs_cmds;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 (void)MSG_PUTS(_("cscope commands:\n"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 while (cmdp->name != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 (void)smsg((char_u *)_("%-5s: %-30s (Usage: %s)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 cmdp->name, _(cmdp->help), cmdp->usage);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 if (strcmp(cmdp->name, "find") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 MSG_PUTS(FIND_HELP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 cmdp++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 wait_return(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 } /* cs_help */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 * PRIVATE: cs_init
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 * initialize cscope structure if not already
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 cs_init()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 short i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 static int init_already = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 if (init_already)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 clear_csinfo(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 init_already = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 } /* cs_init */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 clear_csinfo(i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 csinfo[i].fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 csinfo[i].ppath = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 csinfo[i].flags = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 #if defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 csinfo[i].st_dev = (dev_t)0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 csinfo[i].st_ino = (ino_t)0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 csinfo[i].nVolume = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 csinfo[i].nIndexHigh = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 csinfo[i].nIndexLow = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 csinfo[i].pid = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 csinfo[i].fr_fp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 csinfo[i].to_fp = NULL;
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
1233 #if defined(WIN32)
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
1234 csinfo[i].hProc = NULL;
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
1235 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 #ifndef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 static char *GetWin32Error __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 static char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 GetWin32Error()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 char *msg = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 NULL, GetLastError(), 0, (LPSTR)&msg, 0, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 if (msg != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 /* remove trailing \r\n */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 char *pcrlf = strstr(msg, "\r\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 if (pcrlf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 *pcrlf = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 return msg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 301
diff changeset
1257
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 * PRIVATE: cs_insert_filelist
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 * insert a new cscope database filename into the filelist
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 301
diff changeset
1263 /*ARGSUSED*/
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 cs_insert_filelist(fname, ppath, flags, sb)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 char *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 char *ppath;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 char *flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 struct stat *sb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 short i, j;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 #ifndef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 HANDLE hFile;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 BY_HANDLE_FILE_INFORMATION bhfi;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 vim_memset(&bhfi, 0, sizeof(bhfi));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 /* On windows 9x GetFileInformationByHandle doesn't work, so skip it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 if (!mch_windows95())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 hFile = CreateFile(fname, FILE_READ_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281 FILE_ATTRIBUTE_NORMAL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 if (hFile == INVALID_HANDLE_VALUE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 if (p_csverbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 char *cant_msg = _("E625: cannot open cscope database: %s");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 char *winmsg = GetWin32Error();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 if (winmsg != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 (void)EMSG2(cant_msg, winmsg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 LocalFree(winmsg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 /* subst filename if can't get error text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296 (void)EMSG2(cant_msg, fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1297 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 if (!GetFileInformationByHandle(hFile, &bhfi))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302 CloseHandle(hFile);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303 if (p_csverbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 (void)EMSG(_("E626: cannot get cscope database information"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1307 CloseHandle(hFile);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1309 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 i = -1; /* can be set to the index of an empty item in csinfo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 for (j = 0; j < CSCOPE_MAX_CONNECTIONS; j++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 if (csinfo[j].fname != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 #if defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 && csinfo[j].st_dev == sb->st_dev && csinfo[j].st_ino == sb->st_ino
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 /* compare pathnames first */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 && ((fullpathcmp(csinfo[j].fname, fname, FALSE) & FPC_SAME)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 /* if not Windows 9x, test index file atributes too */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 || (!mch_windows95()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 && csinfo[j].nVolume == bhfi.dwVolumeSerialNumber
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 && csinfo[j].nIndexHigh == bhfi.nFileIndexHigh
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1324 && csinfo[j].nIndexLow == bhfi.nFileIndexLow))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 if (p_csverbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 (void)EMSG(_("E568: duplicate cscope database not added"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1333 if (csinfo[j].fname == NULL && i == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1334 i = j; /* remember first empty entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 if (i == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339 if (p_csverbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340 (void)EMSG(_("E569: maximum number of cscope connections reached"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
1344 if ((csinfo[i].fname = (char *)alloc((unsigned)strlen(fname)+1)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 (void)strcpy(csinfo[i].fname, (const char *)fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 if (ppath != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
1351 if ((csinfo[i].ppath = (char *)alloc((unsigned)strlen(ppath) + 1)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 vim_free(csinfo[i].fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 csinfo[i].fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357 (void)strcpy(csinfo[i].ppath, (const char *)ppath);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1358 } else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 csinfo[i].ppath = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 if (flags != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
1363 if ((csinfo[i].flags = (char *)alloc((unsigned)strlen(flags) + 1)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 vim_free(csinfo[i].fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 vim_free(csinfo[i].ppath);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 csinfo[i].fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 csinfo[i].ppath = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 (void)strcpy(csinfo[i].flags, (const char *)flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 } else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 csinfo[i].flags = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 #if defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 csinfo[i].st_dev = sb->st_dev;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 csinfo[i].st_ino = sb->st_ino;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 csinfo[i].nVolume = bhfi.dwVolumeSerialNumber;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 csinfo[i].nIndexLow = bhfi.nFileIndexLow;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 csinfo[i].nIndexHigh = bhfi.nFileIndexHigh;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 } /* cs_insert_filelist */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 * PRIVATE: cs_lookup_cmd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 * find cscope command in command table
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 static cscmd_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394 cs_lookup_cmd(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 cscmd_T *cmdp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 char *stok;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 size_t len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 if (eap->arg == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 if ((stok = strtok((char *)(eap->arg), (const char *)" ")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407 len = strlen(stok);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 for (cmdp = cs_cmds; cmdp->name != NULL; ++cmdp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410 if (strncmp((const char *)(stok), cmdp->name, len) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411 return (cmdp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414 } /* cs_lookup_cmd */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 * PRIVATE: cs_kill
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420 * nuke em
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422 /* ARGSUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 cs_kill(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 char *stok;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428 short i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 if ((stok = strtok((char *)NULL, (const char *)" ")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 cs_usage_msg(Kill);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 return CSCOPE_FAILURE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 /* only single digit positive and negative integers are allowed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437 if ((strlen(stok) < 2 && VIM_ISDIGIT((int)(stok[0])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438 || (strlen(stok) < 3 && stok[0] == '-'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439 && VIM_ISDIGIT((int)(stok[1]))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440 i = atoi(stok);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1442 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1443 /* It must be part of a name. We will try to find a match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1444 * within all the names in the csinfo data structure
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1446 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 if (csinfo[i].fname != NULL && strstr(csinfo[i].fname, stok))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453 if ((i >= CSCOPE_MAX_CONNECTIONS || i < -1 || csinfo[i].fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454 && i != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456 if (p_csverbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457 (void)EMSG2(_("E261: cscope connection %s not found"), stok);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1459 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 if (i == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1463 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1464 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465 if (csinfo[i].fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 cs_kill_execute(i, csinfo[i].fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470 cs_kill_execute(i, stok);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1471 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1472
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474 } /* cs_kill */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 * PRIVATE: cs_kill_execute
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 * Actually kills a specific cscope connection.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 cs_kill_execute(i, cname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484 int i; /* cscope table index */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 char *cname; /* cscope database name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 if (p_csverbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 msg_clr_eos();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 (void)smsg_attr(hl_attr(HLF_R) | MSG_HIST,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 (char_u *)_("cscope connection %s closed"), cname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 cs_release_csp(i, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 * PRIVATE: cs_make_vim_style_matches
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 * convert the cscope output into into a ctags style entry (as might be found
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 * in a ctags tags file). there's one catch though: cscope doesn't tell you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502 * the type of the tag you are looking for. for example, in Darren Hiebert's
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503 * ctags (the one that comes with vim), #define's use a line number to find the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 * tag in a file while function definitions use a regexp search pattern.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506 * i'm going to always use the line number because cscope does something
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 * quirky (and probably other things i don't know about):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509 * if you have "# define" in your source file, which is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 * perfectly legal, cscope thinks you have "#define". this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 * will result in a failed regexp search. :(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 * besides, even if this particular case didn't happen, the search pattern
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514 * would still have to be modified to escape all the special regular expression
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1515 * characters to comply with ctags formatting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1516 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517 static char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1518 cs_make_vim_style_matches(fname, slno, search, tagstr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519 char *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 char *slno;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 char *search;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522 char *tagstr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524 /* vim style is ctags:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1525 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526 * <tagstr>\t<filename>\t<linenum_or_search>"\t<extra>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1527 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528 * but as mentioned above, we'll always use the line number and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 * put the search pattern (if one exists) as "extra"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531 * buf is used as part of vim's method of handling tags, and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532 * (i think) vim frees it when you pop your tags and get replaced
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 * by new ones on the tag stack.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 char *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536 int amt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538 if (search != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
1540 amt = (int)(strlen(fname) + strlen(slno) + strlen(tagstr) + strlen(search)+6);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 if ((buf = (char *)alloc(amt)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 (void)sprintf(buf, "%s\t%s\t%s;\"\t%s", tagstr, fname, slno, search);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
1548 amt = (int)(strlen(fname) + strlen(slno) + strlen(tagstr) + 5);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549 if ((buf = (char *)alloc(amt)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1550 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1551
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552 (void)sprintf(buf, "%s\t%s\t%s;\"", tagstr, fname, slno);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 return buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1556 } /* cs_make_vim_style_matches */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560 * PRIVATE: cs_manage_matches
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 * this is kind of hokey, but i don't see an easy way round this..
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564 * Store: keep a ptr to the (malloc'd) memory of matches originally
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565 * generated from cs_find(). the matches are originally lines directly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1566 * from cscope output, but transformed to look like something out of a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 * ctags. see cs_make_vim_style_matches for more details.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569 * Get: used only from cs_fgets(), this simulates a vim_fgets() to return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570 * the next line from the cscope output. it basically keeps track of which
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 * lines have been "used" and returns the next one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 * Free: frees up everything and resets
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 * Print: prints the tags
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 static char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578 cs_manage_matches(matches, contexts, totmatches, cmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 char **matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 char **contexts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 int totmatches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 mcmd_e cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 static char **mp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 static char **cp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 static int cnt = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 static int next = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588 char *p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1589
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 switch (cmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 case Store:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 assert(matches != NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 assert(totmatches > 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 if (mp != NULL || cp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 (void)cs_manage_matches(NULL, NULL, -1, Free);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 mp = matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598 cp = contexts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 cnt = totmatches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 next = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 case Get:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 if (next >= cnt)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606 p = mp[next];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 next++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 case Free:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 if (mp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 if (cnt > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 while (cnt--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 vim_free(mp[cnt]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 if (cp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 vim_free(cp[cnt]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 vim_free(mp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 vim_free(cp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 mp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 cp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624 cnt = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 next = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 case Print:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 cs_print_tags_priv(mp, cp, cnt);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 default: /* should not reach here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 (void)EMSG(_("E570: fatal error in cs_manage_matches"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 } /* cs_manage_matches */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 * PRIVATE: cs_parse_results
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 * parse cscope output
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 static char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 cs_parse_results(cnumber, buf, bufsize, context, linenumber, search)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 int cnumber;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 char *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 int bufsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 char **context;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 char **linenumber;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 char **search;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 int ch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 char *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 char *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657 if (fgets(buf, bufsize, csinfo[cnumber].fr_fp) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1659 if (feof(csinfo[cnumber].fr_fp))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1660 errno = EIO;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1661
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662 cs_reading_emsg(cnumber);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 /* If the line's too long for the buffer, discard it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 if ((p = strchr(buf, '\n')) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 while ((ch = getc(csinfo[cnumber].fr_fp)) != EOF && ch != '\n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 *p = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 * cscope output is in the following format:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 * <filename> <context> <line number> <pattern>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681 if ((name = strtok((char *)buf, (const char *)" ")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 if ((*context = strtok(NULL, (const char *)" ")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 if ((*linenumber = strtok(NULL, (const char *)" ")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 *search = *linenumber + strlen(*linenumber) + 1; /* +1 to skip \0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 /* --- nvi ---
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 * If the file is older than the cscope database, that is,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 * the database was built since the file was last modified,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 * or there wasn't a search string, use the line number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 if (strcmp(*search, "<unknown>") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 *search = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 name = cs_resolve_file(cnumber, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 return name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700
636
5ad3b5d4ecc0 updated for version 7.0184
vimboss
parents: 531
diff changeset
1701 #ifdef FEAT_QUICKFIX
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 * PRIVATE: cs_file_results
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 * write cscope find results to file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 cs_file_results(f, nummatches_a)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 FILE *f;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 int *nummatches_a;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 int i, j;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 char *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 char *search, *slno;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 char *fullname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 char *cntx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 char *context;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 buf = (char *)alloc(CSREAD_BUFSIZE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 if (nummatches_a[i] < 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 for (j = 0; j < nummatches_a[i]; j++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 {
293
f811be6fa9b5 updated for version 7.0077
vimboss
parents: 273
diff changeset
1730 if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx,
f811be6fa9b5 updated for version 7.0077
vimboss
parents: 273
diff changeset
1731 &slno, &search)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1732 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
1734 context = (char *)alloc((unsigned)strlen(cntx)+5);
1027
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1735 if (context == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1738 if (strcmp(cntx, "<global>")==0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1739 strcpy(context, "<<global>>");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 sprintf(context, "<<%s>>", cntx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742
1027
c37ed44f014f updated for version 7.0-153
vimboss
parents: 944
diff changeset
1743 if (search == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744 fprintf(f, "%s\t%s\t%s\n", fullname, slno, context);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1745 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 fprintf(f, "%s\t%s\t%s %s\n", fullname, slno, context, search);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 vim_free(context);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749 vim_free(fullname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 } /* for all matches */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752 (void)cs_read_prompt(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 } /* for all cscope connections */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 }
636
5ad3b5d4ecc0 updated for version 7.0184
vimboss
parents: 531
diff changeset
1757 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 * PRIVATE: cs_fill_results
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 * get parsed cscope output and calls cs_make_vim_style_matches to convert
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 * into ctags format
297
9a1c2a8186b7 updated for version 7.0078
vimboss
parents: 293
diff changeset
1764 * When there are no matches sets "*matches_p" to NULL.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 cs_fill_results(tagstr, totmatches, nummatches_a, matches_p, cntxts_p, matched)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 char *tagstr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 int totmatches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 int *nummatches_a;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771 char ***matches_p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 char ***cntxts_p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 int *matched;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 int i, j;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 char *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 char *search, *slno;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 int totsofar = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 char **matches = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 char **cntxts = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 char *fullname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 char *cntx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 assert(totmatches > 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 buf = (char *)alloc(CSREAD_BUFSIZE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 if ((matches = (char **)alloc(sizeof(char *) * totmatches)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 goto parse_out;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 if ((cntxts = (char **)alloc(sizeof(char *) * totmatches)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 goto parse_out;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 if (nummatches_a[i] < 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 for (j = 0; j < nummatches_a[i]; j++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 &slno, &search)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 matches[totsofar] = cs_make_vim_style_matches(fullname, slno,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 search, tagstr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 vim_free(fullname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 if (strcmp(cntx, "<global>") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 cntxts[totsofar] = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 /* note: if vim_strsave returns NULL, then the context
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 * will be "<global>", which is misleading.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 cntxts[totsofar] = (char *)vim_strsave((char_u *)cntx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 if (matches[totsofar] != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 totsofar++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 } /* for all matches */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824 (void)cs_read_prompt(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826 } /* for all cscope connections */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 parse_out:
297
9a1c2a8186b7 updated for version 7.0078
vimboss
parents: 293
diff changeset
1829 if (totsofar == 0)
9a1c2a8186b7 updated for version 7.0078
vimboss
parents: 293
diff changeset
1830 {
9a1c2a8186b7 updated for version 7.0078
vimboss
parents: 293
diff changeset
1831 /* No matches, free the arrays and return NULL in "*matches_p". */
9a1c2a8186b7 updated for version 7.0078
vimboss
parents: 293
diff changeset
1832 vim_free(matches);
9a1c2a8186b7 updated for version 7.0078
vimboss
parents: 293
diff changeset
1833 matches = NULL;
9a1c2a8186b7 updated for version 7.0078
vimboss
parents: 293
diff changeset
1834 vim_free(cntxts);
9a1c2a8186b7 updated for version 7.0078
vimboss
parents: 293
diff changeset
1835 cntxts = NULL;
9a1c2a8186b7 updated for version 7.0078
vimboss
parents: 293
diff changeset
1836 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 *matched = totsofar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 *matches_p = matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 *cntxts_p = cntxts;
297
9a1c2a8186b7 updated for version 7.0078
vimboss
parents: 293
diff changeset
1840
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 } /* cs_fill_results */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 /* get the requested path components */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 static char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 cs_pathcomponents(path)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 char *path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 char *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 if (p_cspc == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 return path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 s = path + strlen(path) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 for (i = 0; i < p_cspc; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 while (s > path && *--s != '/'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859 #ifdef WIN32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 && *--s != '\\'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864 if ((s > path && *s == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1865 #ifdef WIN32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 || (s > path && *s == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 ++s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 return s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 * PRIVATE: cs_print_tags_priv
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 * called from cs_manage_matches()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 cs_print_tags_priv(matches, cntxts, num_matches)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880 char **matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 char **cntxts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 int num_matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884 char *buf = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1885 int bufsize = 0; /* Track available bufsize */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 int newsize = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 char *ptag;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888 char *fname, *lno, *extra, *tbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889 int i, idx, num;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890 char *globalcntx = "GLOBAL";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 char *cntxformat = " <<%s>>";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 char *context;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 char *cstag_msg = _("Cscope tag: %s");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 char *csfmt_str = "%4d %6s ";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 assert (num_matches > 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
1898 if ((tbuf = (char *)alloc((unsigned)strlen(matches[0]) + 1)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 strcpy(tbuf, matches[0]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 ptag = strtok(tbuf, "\t");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
1904 newsize = (int)(strlen(cstag_msg) + strlen(ptag));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 buf = (char *)alloc(newsize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 bufsize = newsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 (void)sprintf(buf, cstag_msg, ptag);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 MSG_PUTS_ATTR(buf, hl_attr(HLF_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 vim_free(tbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 MSG_PUTS_ATTR(_("\n # line"), hl_attr(HLF_T)); /* strlen is 7 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916 msg_advance(msg_col + 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 MSG_PUTS_ATTR(_("filename / context / line\n"), hl_attr(HLF_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 num = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920 for (i = 0; i < num_matches; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1921 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922 idx = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924 /* if we really wanted to, we could avoid this malloc and strcpy
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1925 * by parsing matches[i] on the fly and placing stuff into buf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 * directly, but that's too much of a hassle
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
1928 if ((tbuf = (char *)alloc((unsigned)strlen(matches[idx]) + 1)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 (void)strcpy(tbuf, matches[idx]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1931
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1932 if ((fname = strtok(tbuf, (const char *)"\t")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 if ((fname = strtok(NULL, (const char *)"\t")) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 if ((lno = strtok(NULL, (const char *)"\t")) == NULL)
1078
a36d21d4a875 updated for version 7.0-204
vimboss
parents: 1058
diff changeset
1937 continue;
a36d21d4a875 updated for version 7.0-204
vimboss
parents: 1058
diff changeset
1938 extra = strtok(NULL, (const char *)"\t");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940 lno[strlen(lno)-2] = '\0'; /* ignore ;" at the end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 /* hopefully 'num' (num of matches) will be less than 10^16 */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
1943 newsize = (int)(strlen(csfmt_str) + 16 + strlen(lno));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 if (bufsize < newsize)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1946 buf = (char *)vim_realloc(buf, newsize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948 bufsize = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1949 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1950 bufsize = newsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1953 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 /* csfmt_str = "%4d %6s "; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 (void)sprintf(buf, csfmt_str, num, lno);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956 MSG_PUTS_ATTR(buf, hl_attr(HLF_CM));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958 MSG_PUTS_LONG_ATTR(cs_pathcomponents(fname), hl_attr(HLF_CM));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1960 /* compute the required space for the context */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961 if (cntxts[idx] != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1962 context = cntxts[idx];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964 context = globalcntx;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
1965 newsize = (int)(strlen(context) + strlen(cntxformat));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1966
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967 if (bufsize < newsize)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969 buf = (char *)vim_realloc(buf, newsize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1971 bufsize = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1972 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1973 bufsize = newsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 (void)sprintf(buf, cntxformat, context);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1978
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979 /* print the context only if it fits on the same line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1980 if (msg_col + (int)strlen(buf) >= (int)Columns)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1981 msg_putchar('\n');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982 msg_advance(12);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 MSG_PUTS_LONG(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984 msg_putchar('\n');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986 if (extra != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988 msg_advance(13);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 MSG_PUTS_LONG(extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1991
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 vim_free(tbuf); /* only after printing extra due to strtok use */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1994 if (msg_col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1995 msg_putchar('\n');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1996
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1997 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1998 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1999 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2000 got_int = FALSE; /* don't print any more matches */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2003
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 num++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 } /* for all matches */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2006
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 } /* cs_print_tags_priv */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2009
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2010
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2011 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2012 * PRIVATE: cs_read_prompt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2013 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2014 * read a cscope prompt (basically, skip over the ">> ")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2015 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2016 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017 cs_read_prompt(i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2019 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2020 int ch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2021 char *buf = NULL; /* buffer for possible error message from cscope */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2022 int bufpos = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023 char *cs_emsg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 int maxlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2025 static char *eprompt = "Press the RETURN key to continue:";
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
2026 int epromptlen = (int)strlen(eprompt);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2027 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 cs_emsg = _("E609: Cscope error: %s");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2030 /* compute maximum allowed len for Cscope error message */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2031 maxlen = (int)(IOSIZE - strlen(cs_emsg));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2032
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2033 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2034 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2035 while ((ch = getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2036 /* if there is room and char is printable */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2037 if (bufpos < maxlen - 1 && vim_isprintc(ch))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2038 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2039 if (buf == NULL) /* lazy buffer allocation */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2040 buf = (char *)alloc(maxlen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2041 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2042 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2043 /* append character to the message */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2044 buf[bufpos++] = ch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2045 buf[bufpos] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2046 if (bufpos >= epromptlen
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2047 && strcmp(&buf[bufpos - epromptlen], eprompt) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2048 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2049 /* remove eprompt from buf */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2050 buf[bufpos - epromptlen] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2051
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2052 /* print message to user */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2053 (void)EMSG2(cs_emsg, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 /* send RETURN to cscope */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 (void)putc('\n', csinfo[i].to_fp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2057 (void)fflush(csinfo[i].to_fp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2058
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 /* clear buf */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 bufpos = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2061 buf[bufpos] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2062 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2063 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2064 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 for (n = 0; n < (int)strlen(CSCOPE_PROMPT); ++n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2068 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2069 ch = getc(csinfo[i].fr_fp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2070 if (ch == EOF)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2071 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2072 PERROR("cs_read_prompt EOF");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2073 if (buf != NULL && buf[0] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2074 (void)EMSG2(cs_emsg, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2075 else if (p_csverbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076 cs_reading_emsg(i); /* don't have additional information */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2077 cs_release_csp(i, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2078 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2079 return CSCOPE_FAILURE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2080 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2081
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2082 if (ch != CSCOPE_PROMPT[n])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2083 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2084 ch = EOF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2085 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2086 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2087 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2088
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 if (ch == EOF)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2090 continue; /* didn't find the prompt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091 break; /* did find the prompt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2092 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2095 return CSCOPE_SUCCESS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2096 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2097
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2098
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2099 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2100 * PRIVATE: cs_release_csp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2101 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2102 * does the actual free'ing for the cs ptr with an optional flag of whether
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2103 * or not to free the filename. called by cs_kill and cs_reset.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2106 cs_release_csp(i, freefnpp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2107 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2108 int freefnpp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2109 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2110 #if defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2111 int pstat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2112 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2113 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2114 * Trying to exit normally (not sure whether it is fit to UNIX cscope
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2115 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2116 if (csinfo[i].to_fp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2117 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2118 (void)fputs("q\n", csinfo[i].to_fp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2119 (void)fflush(csinfo[i].to_fp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2120 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2121 /* give cscope chance to exit normally */
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
2122 if (csinfo[i].hProc != NULL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2123 && WaitForSingleObject(csinfo[i].hProc, 1000) == WAIT_TIMEOUT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2124 TerminateProcess(csinfo[i].hProc, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2125 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2127 if (csinfo[i].fr_fp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2128 (void)fclose(csinfo[i].fr_fp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2129 if (csinfo[i].to_fp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2130 (void)fclose(csinfo[i].to_fp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2132 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2133 * Safety check: If the PID would be zero here, the entire X session would
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2134 * be killed. -1 and 1 are dangerous as well.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2135 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2136 #if defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2137 if (csinfo[i].pid > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2138 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2139 kill(csinfo[i].pid, SIGTERM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2140 (void)waitpid(csinfo[i].pid, &pstat, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2141 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2142 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2143
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2144 if (freefnpp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2145 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 vim_free(csinfo[i].fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2147 vim_free(csinfo[i].ppath);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 vim_free(csinfo[i].flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2149 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2151 clear_csinfo(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2152 } /* cs_release_csp */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 * PRIVATE: cs_reset
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 * calls cs_kill on all cscope connections then reinits
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160 /* ARGSUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2162 cs_reset(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2164 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 char **dblist = NULL, **pplist = NULL, **fllist = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2166 int i;
273
2463194c8cdd updated for version 7.0073
vimboss
parents: 148
diff changeset
2167 char buf[20]; /* for sprintf " (#%d)" */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2169 /* malloc our db and ppath list */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2170 dblist = (char **)alloc(CSCOPE_MAX_CONNECTIONS * sizeof(char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2171 pplist = (char **)alloc(CSCOPE_MAX_CONNECTIONS * sizeof(char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2172 fllist = (char **)alloc(CSCOPE_MAX_CONNECTIONS * sizeof(char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2173 if (dblist == NULL || pplist == NULL || fllist == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2174 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2175 vim_free(dblist);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2176 vim_free(pplist);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2177 vim_free(fllist);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2178 return CSCOPE_FAILURE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2179 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2180
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2181 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2182 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2183 dblist[i] = csinfo[i].fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2184 pplist[i] = csinfo[i].ppath;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2185 fllist[i] = csinfo[i].flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2186 if (csinfo[i].fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2187 cs_release_csp(i, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2188 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2189
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2190 /* rebuild the cscope connection list */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2191 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2192 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2193 if (dblist[i] != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2194 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195 cs_add_common(dblist[i], pplist[i], fllist[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2196 if (p_csverbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2197 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2198 /* dont' use smsg_attr because want to display
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 * connection number in the same line as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200 * "Added cscope database..."
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2201 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2202 sprintf(buf, " (#%d)", i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2203 MSG_PUTS_ATTR(buf, hl_attr(HLF_R));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2204 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2205 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2206 vim_free(dblist[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2207 vim_free(pplist[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2208 vim_free(fllist[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2210 vim_free(dblist);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2211 vim_free(pplist);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 vim_free(fllist);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2213
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2214 if (p_csverbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2215 MSG_ATTR(_("All cscope databases reset"), hl_attr(HLF_R) | MSG_HIST);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 return CSCOPE_SUCCESS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217 } /* cs_reset */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2219
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2220 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 * PRIVATE: cs_resolve_file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2222 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2223 * construct the full pathname to a file found in the cscope database.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2224 * (Prepends ppath, if there is one and if it's not already prepended,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225 * otherwise just uses the name found.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 * we need to prepend the prefix because on some cscope's (e.g., the one that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228 * ships with Solaris 2.6), the output never has the prefix prepended.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 * contrast this with my development system (Digital Unix), which does.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 static char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 cs_resolve_file(i, name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 char *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 char *fullname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240 * ppath is freed when we destroy the cscope connection.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241 * fullname is freed after cs_make_vim_style_matches, after it's been
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2242 * copied into the tag buffer used by vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
2244 len = (int)(strlen(name) + 2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 if (csinfo[i].ppath != NULL)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 714
diff changeset
2246 len += (int)strlen(csinfo[i].ppath);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2248 if ((fullname = (char *)alloc(len)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2249 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252 * note/example: this won't work if the cscope output already starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 * "../.." and the prefix path is also "../..". if something like this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 * happens, you are screwed up and need to fix how you're using cscope.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 if (csinfo[i].ppath != NULL &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 (strncmp(name, csinfo[i].ppath, strlen(csinfo[i].ppath)) != 0) &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 (name[0] != '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 #ifdef WIN32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260 && name[0] != '\\' && name[1] != ':'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2261 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 (void)sprintf(fullname, "%s/%s", csinfo[i].ppath, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 (void)sprintf(fullname, "%s", name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 return fullname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 } /* cs_resolve_file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 * PRIVATE: cs_show
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2273 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 * show all cscope connections
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2276 /* ARGSUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278 cs_show(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2279 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2280 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2281 short i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282 if (cs_cnt_connections() == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283 MSG_PUTS(_("no cscope connections\n"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 MSG_PUTS_ATTR(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287 _(" # pid database name prepend path\n"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 hl_attr(HLF_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291 if (csinfo[i].fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2292 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294 if (csinfo[i].ppath != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2295 (void)smsg((char_u *)"%2d %-5ld %-34s %-32s",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296 i, (long)csinfo[i].pid, csinfo[i].fname, csinfo[i].ppath);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298 (void)smsg((char_u *)"%2d %-5ld %-34s <none>",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 i, (long)csinfo[i].pid, csinfo[i].fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2301 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2302
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2303 wait_return(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304 return CSCOPE_SUCCESS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305 } /* cs_show */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2307 #endif /* FEAT_CSCOPE */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2309 /* the end */