annotate src/if_cscope.c @ 412:53c36fa7dc29

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