annotate src/if_cscope.c @ 30579:e298ce7862f7

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