annotate src/if_cscope.c @ 1445:54a6b47d473e v7.1.160

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