annotate src/if_cscope.c @ 49:000769ce6c9d default tip

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