annotate src/if_cscope.c @ 2139:35effbd07a25 v7.2.421

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