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