Mercurial > vim
annotate src/misc1.c @ 30176:042513ec99d7 v9.0.0424
patch 9.0.0424: gitattributes files are not recognized
Commit: https://github.com/vim/vim/commit/7d56cfc861e57145f003315efd835cf5dfd5b145
Author: ObserverOfTime <chronobserver@disroot.org>
Date: Fri Sep 9 14:11:41 2022 +0100
patch 9.0.0424: gitattributes files are not recognized
Problem: gitattributes files are not recognized.
Solution: Add patterns to match gitattributes files. (closes https://github.com/vim/vim/issues/11085)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 09 Sep 2022 15:15:03 +0200 |
parents | 4fcf816aa806 |
children | 0d084880276a |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10002
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * misc1.c: functions that didn't seem to fit elsewhere | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 #include "version.h" | |
16 | |
19526
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
17 #if defined(__HAIKU__) |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
18 # include <storage/FindDirectory.h> |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
19 #endif |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
20 |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17452
diff
changeset
|
21 #if defined(MSWIN) |
14133
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
22 # include <lm.h> |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
23 #endif |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
24 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
25 #define URL_SLASH 1 // path_is_url() has found "://" |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
26 #define URL_BACKSLASH 2 // path_is_url() has found ":\\" |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
27 |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17452
diff
changeset
|
28 // All user names (for ~user completion as done by shell). |
3744 | 29 static garray_T ga_users; |
30 | |
7 | 31 /* |
5403 | 32 * get_leader_len() returns the length in bytes of the prefix of the given |
33 * string which introduces a comment. If this string is not a comment then | |
34 * 0 is returned. | |
7 | 35 * When "flags" is not NULL, it is set to point to the flags of the recognized |
36 * comment leader. | |
37 * "backward" must be true for the "O" command. | |
3562 | 38 * If "include_space" is set, include trailing whitespace while calculating the |
39 * length. | |
7 | 40 */ |
41 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
42 get_leader_len( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
43 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
44 char_u **flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
45 int backward, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
46 int include_space) |
7 | 47 { |
48 int i, j; | |
3562 | 49 int result; |
7 | 50 int got_com = FALSE; |
51 int found_one; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
52 char_u part_buf[COM_MAX_LEN]; // buffer for one option part |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
53 char_u *string; // pointer to comment string |
7 | 54 char_u *list; |
2809 | 55 int middle_match_len = 0; |
56 char_u *prev_list; | |
2813 | 57 char_u *saved_flags = NULL; |
7 | 58 |
3562 | 59 result = i = 0; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
60 while (VIM_ISWHITE(line[i])) // leading white space is ignored |
7 | 61 ++i; |
62 | |
63 /* | |
64 * Repeat to match several nested comment strings. | |
65 */ | |
2809 | 66 while (line[i] != NUL) |
7 | 67 { |
68 /* | |
69 * scan through the 'comments' option for a match | |
70 */ | |
71 found_one = FALSE; | |
72 for (list = curbuf->b_p_com; *list; ) | |
73 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
74 // Get one option part into part_buf[]. Advance "list" to next |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
75 // one. Put "string" at start of string. |
2809 | 76 if (!got_com && flags != NULL) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
77 *flags = list; // remember where flags started |
2809 | 78 prev_list = list; |
7 | 79 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); |
80 string = vim_strchr(part_buf, ':'); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
81 if (string == NULL) // missing ':', ignore this part |
7 | 82 continue; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
83 *string++ = NUL; // isolate flags from string |
7 | 84 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
85 // If we found a middle match previously, use that match when this |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
86 // is not a middle or end. |
2809 | 87 if (middle_match_len != 0 |
88 && vim_strchr(part_buf, COM_MIDDLE) == NULL | |
89 && vim_strchr(part_buf, COM_END) == NULL) | |
90 break; | |
91 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
92 // When we already found a nested comment, only accept further |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
93 // nested comments. |
7 | 94 if (got_com && vim_strchr(part_buf, COM_NEST) == NULL) |
95 continue; | |
96 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
97 // When 'O' flag present and using "O" command skip this one. |
7 | 98 if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL) |
99 continue; | |
100 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
101 // Line contents and string must match. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
102 // When string starts with white space, must have some white space |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
103 // (but the amount does not need to match, there might be a mix of |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
104 // TABs and spaces). |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
105 if (VIM_ISWHITE(string[0])) |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
106 { |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
107 if (i == 0 || !VIM_ISWHITE(line[i - 1])) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
108 continue; // missing white space |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
109 while (VIM_ISWHITE(string[0])) |
7 | 110 ++string; |
111 } | |
112 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) | |
113 ; | |
114 if (string[j] != NUL) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
115 continue; // string doesn't match |
2809 | 116 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
117 // When 'b' flag used, there must be white space or an |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
118 // end-of-line after the string in the line. |
7 | 119 if (vim_strchr(part_buf, COM_BLANK) != NULL |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
120 && !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL) |
7 | 121 continue; |
122 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
123 // We have found a match, stop searching unless this is a middle |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
124 // comment. The middle comment can be a substring of the end |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
125 // comment in which case it's better to return the length of the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
126 // end comment and its flags. Thus we keep searching with middle |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
127 // and end matches and use an end match if it matches better. |
2809 | 128 if (vim_strchr(part_buf, COM_MIDDLE) != NULL) |
129 { | |
130 if (middle_match_len == 0) | |
131 { | |
132 middle_match_len = j; | |
133 saved_flags = prev_list; | |
134 } | |
135 continue; | |
136 } | |
137 if (middle_match_len != 0 && j > middle_match_len) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
138 // Use this match instead of the middle match, since it's a |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
139 // longer thus better match. |
2809 | 140 middle_match_len = 0; |
141 | |
142 if (middle_match_len == 0) | |
143 i += j; | |
7 | 144 found_one = TRUE; |
145 break; | |
146 } | |
147 | |
2809 | 148 if (middle_match_len != 0) |
149 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
150 // Use the previously found middle match after failing to find a |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
151 // match with an end. |
2809 | 152 if (!got_com && flags != NULL) |
153 *flags = saved_flags; | |
154 i += middle_match_len; | |
155 found_one = TRUE; | |
156 } | |
157 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
158 // No match found, stop scanning. |
7 | 159 if (!found_one) |
160 break; | |
161 | |
3562 | 162 result = i; |
163 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
164 // Include any trailing white space. |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
165 while (VIM_ISWHITE(line[i])) |
7 | 166 ++i; |
167 | |
3562 | 168 if (include_space) |
169 result = i; | |
170 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
171 // If this comment doesn't nest, stop here. |
2809 | 172 got_com = TRUE; |
7 | 173 if (vim_strchr(part_buf, COM_NEST) == NULL) |
174 break; | |
175 } | |
3562 | 176 return result; |
177 } | |
178 | |
179 /* | |
180 * Return the offset at which the last comment in line starts. If there is no | |
181 * comment in the whole line, -1 is returned. | |
182 * | |
183 * When "flags" is not null, it is set to point to the flags describing the | |
184 * recognized comment leader. | |
185 */ | |
186 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
187 get_last_leader_offset(char_u *line, char_u **flags) |
3562 | 188 { |
189 int result = -1; | |
190 int i, j; | |
191 int lower_check_bound = 0; | |
192 char_u *string; | |
193 char_u *com_leader; | |
194 char_u *com_flags; | |
195 char_u *list; | |
196 int found_one; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
197 char_u part_buf[COM_MAX_LEN]; // buffer for one option part |
3562 | 198 |
199 /* | |
200 * Repeat to match several nested comment strings. | |
201 */ | |
202 i = (int)STRLEN(line); | |
203 while (--i >= lower_check_bound) | |
204 { | |
205 /* | |
206 * scan through the 'comments' option for a match | |
207 */ | |
208 found_one = FALSE; | |
209 for (list = curbuf->b_p_com; *list; ) | |
210 { | |
211 char_u *flags_save = list; | |
212 | |
213 /* | |
214 * Get one option part into part_buf[]. Advance list to next one. | |
215 * put string at start of string. | |
216 */ | |
217 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); | |
218 string = vim_strchr(part_buf, ':'); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
219 if (string == NULL) // If everything is fine, this cannot actually |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
220 // happen. |
3562 | 221 continue; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
222 *string++ = NUL; // Isolate flags from string. |
3562 | 223 com_leader = string; |
224 | |
225 /* | |
226 * Line contents and string must match. | |
227 * When string starts with white space, must have some white space | |
228 * (but the amount does not need to match, there might be a mix of | |
229 * TABs and spaces). | |
230 */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
231 if (VIM_ISWHITE(string[0])) |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
232 { |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
233 if (i == 0 || !VIM_ISWHITE(line[i - 1])) |
3562 | 234 continue; |
15119
6e9f37bf987b
patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents:
15046
diff
changeset
|
235 while (VIM_ISWHITE(*string)) |
3562 | 236 ++string; |
237 } | |
238 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) | |
239 /* do nothing */; | |
240 if (string[j] != NUL) | |
241 continue; | |
242 | |
243 /* | |
244 * When 'b' flag used, there must be white space or an | |
245 * end-of-line after the string in the line. | |
246 */ | |
247 if (vim_strchr(part_buf, COM_BLANK) != NULL | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
248 && !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL) |
3562 | 249 continue; |
15119
6e9f37bf987b
patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents:
15046
diff
changeset
|
250 |
15127
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
251 if (vim_strchr(part_buf, COM_MIDDLE) != NULL) |
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
252 { |
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
253 // For a middlepart comment, only consider it to match if |
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
254 // everything before the current position in the line is |
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
255 // whitespace. Otherwise we would think we are inside a |
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
256 // comment if the middle part appears somewhere in the middle |
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
257 // of the line. E.g. for C the "*" appears often. |
15119
6e9f37bf987b
patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents:
15046
diff
changeset
|
258 for (j = 0; VIM_ISWHITE(line[j]) && j <= i; j++) |
6e9f37bf987b
patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents:
15046
diff
changeset
|
259 ; |
6e9f37bf987b
patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents:
15046
diff
changeset
|
260 if (j < i) |
6e9f37bf987b
patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents:
15046
diff
changeset
|
261 continue; |
3562 | 262 } |
263 | |
264 /* | |
265 * We have found a match, stop searching. | |
266 */ | |
267 found_one = TRUE; | |
268 | |
269 if (flags) | |
270 *flags = flags_save; | |
271 com_flags = flags_save; | |
272 | |
273 break; | |
274 } | |
275 | |
276 if (found_one) | |
277 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
278 char_u part_buf2[COM_MAX_LEN]; // buffer for one option part |
3562 | 279 int len1, len2, off; |
280 | |
281 result = i; | |
282 /* | |
283 * If this comment nests, continue searching. | |
284 */ | |
285 if (vim_strchr(part_buf, COM_NEST) != NULL) | |
286 continue; | |
287 | |
288 lower_check_bound = i; | |
289 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
290 // Let's verify whether the comment leader found is a substring |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
291 // of other comment leaders. If it is, let's adjust the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
292 // lower_check_bound so that we make sure that we have determined |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
293 // the comment leader correctly. |
3562 | 294 |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
295 while (VIM_ISWHITE(*com_leader)) |
3562 | 296 ++com_leader; |
297 len1 = (int)STRLEN(com_leader); | |
298 | |
299 for (list = curbuf->b_p_com; *list; ) | |
300 { | |
301 char_u *flags_save = list; | |
302 | |
303 (void)copy_option_part(&list, part_buf2, COM_MAX_LEN, ","); | |
304 if (flags_save == com_flags) | |
305 continue; | |
306 string = vim_strchr(part_buf2, ':'); | |
307 ++string; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
308 while (VIM_ISWHITE(*string)) |
3562 | 309 ++string; |
310 len2 = (int)STRLEN(string); | |
311 if (len2 == 0) | |
312 continue; | |
313 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
314 // Now we have to verify whether string ends with a substring |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
315 // beginning the com_leader. |
3562 | 316 for (off = (len2 > i ? i : len2); off > 0 && off + len1 > len2;) |
317 { | |
318 --off; | |
319 if (!STRNCMP(string + off, com_leader, len2 - off)) | |
320 { | |
321 if (i - off < lower_check_bound) | |
322 lower_check_bound = i - off; | |
323 } | |
324 } | |
325 } | |
326 } | |
327 } | |
328 return result; | |
7 | 329 } |
330 | |
331 /* | |
332 * Return the number of window lines occupied by buffer line "lnum". | |
333 */ | |
334 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
335 plines(linenr_T lnum) |
7 | 336 { |
337 return plines_win(curwin, lnum, TRUE); | |
338 } | |
339 | |
340 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
341 plines_win( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
342 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
343 linenr_T lnum, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
344 int winheight) // when TRUE limit to window height |
7 | 345 { |
346 #if defined(FEAT_DIFF) || defined(PROTO) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
347 // Check for filler lines above this buffer line. When folded the result |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
348 // is one line anyway. |
7 | 349 return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum); |
350 } | |
351 | |
352 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
353 plines_nofill(linenr_T lnum) |
7 | 354 { |
355 return plines_win_nofill(curwin, lnum, TRUE); | |
356 } | |
357 | |
358 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
359 plines_win_nofill( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
360 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
361 linenr_T lnum, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
362 int winheight) // when TRUE limit to window height |
7 | 363 { |
364 #endif | |
365 int lines; | |
366 | |
367 if (wp->w_width == 0) | |
368 return 1; | |
369 | |
370 #ifdef FEAT_FOLDING | |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
371 // Folded lines are handled just like an empty line. |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
372 // NOTE: Caller must handle lines that are MAYBE folded. |
7 | 373 if (lineFolded(wp, lnum) == TRUE) |
374 return 1; | |
375 #endif | |
376 | |
29621
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
377 if (!wp->w_p_wrap) |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
378 lines = 1 |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
379 #ifdef FEAT_PROP_POPUP |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
380 // add a line for each "below" aligned text property |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
381 + prop_count_below(wp->w_buffer, lnum) |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
382 #endif |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
383 ; |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
384 else |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
385 lines = plines_win_nofold(wp, lnum); |
f1ed6f520d09
patch 9.0.0151: a "below" aligned text property does not work with 'nowrap'
Bram Moolenaar <Bram@vim.org>
parents:
29451
diff
changeset
|
386 |
7 | 387 if (winheight > 0 && lines > wp->w_height) |
27426
41e0dcf38521
patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
388 return wp->w_height; |
7 | 389 return lines; |
390 } | |
391 | |
392 /* | |
393 * Return number of window lines physical line "lnum" will occupy in window | |
394 * "wp". Does not care about folding, 'wrap' or 'diff'. | |
395 */ | |
396 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
397 plines_win_nofold(win_T *wp, linenr_T lnum) |
7 | 398 { |
399 char_u *s; | |
400 long col; | |
401 int width; | |
29678
fc0f93590fd4
patch 9.0.0179: cursor pos wrong with wrapping virtual text in empty line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
402 chartabsize_T cts; |
7 | 403 |
404 s = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
29678
fc0f93590fd4
patch 9.0.0179: cursor pos wrong with wrapping virtual text in empty line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
405 init_chartabsize_arg(&cts, wp, lnum, 0, s, s); |
fc0f93590fd4
patch 9.0.0179: cursor pos wrong with wrapping virtual text in empty line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
406 if (*s == NUL |
fc0f93590fd4
patch 9.0.0179: cursor pos wrong with wrapping virtual text in empty line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
407 #ifdef FEAT_PROP_POPUP |
fc0f93590fd4
patch 9.0.0179: cursor pos wrong with wrapping virtual text in empty line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
408 && !cts.cts_has_prop_with_text |
fc0f93590fd4
patch 9.0.0179: cursor pos wrong with wrapping virtual text in empty line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
409 #endif |
fc0f93590fd4
patch 9.0.0179: cursor pos wrong with wrapping virtual text in empty line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
410 ) |
fc0f93590fd4
patch 9.0.0179: cursor pos wrong with wrapping virtual text in empty line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
411 return 1; // be quick for an empty line |
fc0f93590fd4
patch 9.0.0179: cursor pos wrong with wrapping virtual text in empty line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
412 win_linetabsize_cts(&cts, (colnr_T)MAXCOL); |
fc0f93590fd4
patch 9.0.0179: cursor pos wrong with wrapping virtual text in empty line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
413 clear_chartabsize_arg(&cts); |
fc0f93590fd4
patch 9.0.0179: cursor pos wrong with wrapping virtual text in empty line
Bram Moolenaar <Bram@vim.org>
parents:
29621
diff
changeset
|
414 col = (int)cts.cts_vcol; |
7 | 415 |
29812
68ef14b21d01
patch 9.0.0245: mechanism to prevent recursive screen updating is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
416 // If list mode is on, then the '$' at the end of the line may take up one |
68ef14b21d01
patch 9.0.0245: mechanism to prevent recursive screen updating is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
417 // extra column. |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
418 if (wp->w_p_list && wp->w_lcs_chars.eol != NUL) |
7 | 419 col += 1; |
420 | |
421 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2162
diff
changeset
|
422 * Add column offset for 'number', 'relativenumber' and 'foldcolumn'. |
7 | 423 */ |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
424 width = wp->w_width - win_col_off(wp); |
7 | 425 if (width <= 0) |
426 return 32000; | |
427 if (col <= width) | |
428 return 1; | |
429 col -= width; | |
430 width += win_col_off2(wp); | |
431 return (col + (width - 1)) / width + 1; | |
432 } | |
433 | |
434 /* | |
435 * Like plines_win(), but only reports the number of physical screen lines | |
436 * used from the start of the line to the given column number. | |
437 */ | |
438 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
439 plines_win_col(win_T *wp, linenr_T lnum, long column) |
7 | 440 { |
441 long col; | |
442 int lines = 0; | |
443 int width; | |
5995 | 444 char_u *line; |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
445 chartabsize_T cts; |
7 | 446 |
447 #ifdef FEAT_DIFF | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
448 // Check for filler lines above this buffer line. When folded the result |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
449 // is one line anyway. |
7 | 450 lines = diff_check_fill(wp, lnum); |
451 #endif | |
452 | |
453 if (!wp->w_p_wrap) | |
454 return lines + 1; | |
455 | |
456 if (wp->w_width == 0) | |
457 return lines + 1; | |
458 | |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
459 line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
7 | 460 |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
461 init_chartabsize_arg(&cts, wp, lnum, 0, line, line); |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
462 while (*cts.cts_ptr != NUL && --column >= 0) |
7 | 463 { |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
464 cts.cts_vcol += win_lbr_chartabsize(&cts, NULL); |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
465 MB_PTR_ADV(cts.cts_ptr); |
7 | 466 } |
467 | |
468 /* | |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
469 * If *cts.cts_ptr is a TAB, and the TAB is not displayed as ^I, and we're |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
470 * not in MODE_INSERT state, then col must be adjusted so that it |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
471 * represents the last screen position of the TAB. This only fixes an |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
472 * error when the TAB wraps from one screen line to the next (when |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
473 * 'columns' is not a multiple of 'ts') -- webb. |
7 | 474 */ |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
475 col = cts.cts_vcol; |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
476 if (*cts.cts_ptr == TAB && (State & MODE_NORMAL) |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28643
diff
changeset
|
477 && (!wp->w_p_list || wp->w_lcs_chars.tab1)) |
29451
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
478 col += win_lbr_chartabsize(&cts, NULL) - 1; |
057c26b5c33a
patch 9.0.0067: cannot show virtual text
Bram Moolenaar <Bram@vim.org>
parents:
29371
diff
changeset
|
479 clear_chartabsize_arg(&cts); |
7 | 480 |
481 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2162
diff
changeset
|
482 * Add column offset for 'number', 'relativenumber', 'foldcolumn', etc. |
7 | 483 */ |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
484 width = wp->w_width - win_col_off(wp); |
1023 | 485 if (width <= 0) |
486 return 9999; | |
487 | |
488 lines += 1; | |
489 if (col > width) | |
490 lines += (col - width) / (width + win_col_off2(wp)) + 1; | |
491 return lines; | |
7 | 492 } |
493 | |
494 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
495 plines_m_win(win_T *wp, linenr_T first, linenr_T last) |
7 | 496 { |
497 int count = 0; | |
498 | |
499 while (first <= last) | |
500 { | |
501 #ifdef FEAT_FOLDING | |
502 int x; | |
503 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
504 // Check if there are any really folded lines, but also included lines |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
505 // that are maybe folded. |
7 | 506 x = foldedCount(wp, first, NULL); |
507 if (x > 0) | |
508 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
509 ++count; // count 1 for "+-- folded" line |
7 | 510 first += x; |
511 } | |
512 else | |
513 #endif | |
514 { | |
515 #ifdef FEAT_DIFF | |
516 if (first == wp->w_topline) | |
517 count += plines_win_nofill(wp, first, TRUE) + wp->w_topfill; | |
518 else | |
519 #endif | |
520 count += plines_win(wp, first, TRUE); | |
521 ++first; | |
522 } | |
523 } | |
524 return (count); | |
525 } | |
526 | |
527 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
528 gchar_pos(pos_T *pos) |
7 | 529 { |
13082
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
530 char_u *ptr; |
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
531 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
532 // When searching columns is sometimes put at the end of a line. |
13082
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
533 if (pos->col == MAXCOL) |
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
534 return NUL; |
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
535 ptr = ml_get_pos(pos); |
7 | 536 if (has_mbyte) |
537 return (*mb_ptr2char)(ptr); | |
538 return (int)*ptr; | |
539 } | |
540 | |
541 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
542 gchar_cursor(void) |
7 | 543 { |
544 if (has_mbyte) | |
545 return (*mb_ptr2char)(ml_get_cursor()); | |
546 return (int)*ml_get_cursor(); | |
547 } | |
548 | |
549 /* | |
550 * Write a character at the current cursor position. | |
551 * It is directly written into the block. | |
552 */ | |
553 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
554 pchar_cursor(int c) |
7 | 555 { |
556 *(ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE) | |
557 + curwin->w_cursor.col) = c; | |
558 } | |
559 | |
560 /* | |
561 * Skip to next part of an option argument: Skip space and comma. | |
562 */ | |
563 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
564 skip_to_option_part(char_u *p) |
7 | 565 { |
566 if (*p == ',') | |
567 ++p; | |
568 while (*p == ' ') | |
569 ++p; | |
570 return p; | |
571 } | |
572 | |
573 /* | |
574 * check_status: called when the status bars for the buffer 'buf' | |
575 * need to be updated | |
576 */ | |
577 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
578 check_status(buf_T *buf) |
7 | 579 { |
580 win_T *wp; | |
581 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
582 FOR_ALL_WINDOWS(wp) |
7 | 583 if (wp->w_buffer == buf && wp->w_status_height) |
584 { | |
585 wp->w_redr_status = TRUE; | |
29812
68ef14b21d01
patch 9.0.0245: mechanism to prevent recursive screen updating is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
586 set_must_redraw(UPD_VALID); |
7 | 587 } |
588 } | |
589 | |
590 /* | |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
591 * Ask for a reply from the user, a 'y' or a 'n', with prompt "str" (which |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
592 * should have been translated already). |
7 | 593 * No other characters are accepted, the message is repeated until a valid |
594 * reply is entered or CTRL-C is hit. | |
595 * If direct is TRUE, don't use vgetc() but ui_inchar(), don't get characters | |
596 * from any buffers but directly from the user. | |
597 * | |
598 * return the 'y' or 'n' | |
599 */ | |
600 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
601 ask_yesno(char_u *str, int direct) |
7 | 602 { |
603 int r = ' '; | |
604 int save_State = State; | |
605 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
606 if (exiting) // put terminal in raw mode for this question |
7 | 607 settmode(TMODE_RAW); |
608 ++no_wait_return; | |
609 #ifdef USE_ON_FLY_SCROLL | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18104
diff
changeset
|
610 dont_scroll = TRUE; // disallow scrolling here |
7 | 611 #endif |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28643
diff
changeset
|
612 State = MODE_CONFIRM; // mouse behaves like with :confirm |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18104
diff
changeset
|
613 setmouse(); // disables mouse for xterm |
7 | 614 ++no_mapping; |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18104
diff
changeset
|
615 ++allow_keys; // no mapping here, but recognize keys |
7 | 616 |
617 while (r != 'y' && r != 'n') | |
618 { | |
29960
4fcf816aa806
patch 9.0.0318: clearing screen causes flicker
Bram Moolenaar <Bram@vim.org>
parents:
29892
diff
changeset
|
619 // same highlighting as for wait_return() |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15420
diff
changeset
|
620 smsg_attr(HL_ATTR(HLF_R), "%s (y/n)?", str); |
7 | 621 if (direct) |
622 r = get_keystroke(); | |
623 else | |
1474 | 624 r = plain_vgetc(); |
7 | 625 if (r == Ctrl_C || r == ESC) |
626 r = 'n'; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
627 msg_putchar(r); // show what you typed |
7 | 628 out_flush(); |
629 } | |
630 --no_wait_return; | |
631 State = save_State; | |
632 setmouse(); | |
633 --no_mapping; | |
634 --allow_keys; | |
635 | |
636 return r; | |
637 } | |
638 | |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
639 #if defined(FEAT_EVAL) || defined(PROTO) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
640 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
641 /* |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
642 * Returns the current mode as a string in "buf[MODE_MAX_LENGTH]", NUL |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
643 * terminated. |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
644 * The first character represents the major mode, the following ones the minor |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
645 * ones. |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
646 */ |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
647 void |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
648 get_mode(char_u *buf) |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
649 { |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
650 int i = 0; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
651 |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
652 if (time_for_testing == 93784) |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
653 { |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
654 // Testing the two-character code. |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
655 buf[i++] = 'x'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
656 buf[i++] = '!'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
657 } |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
658 #ifdef FEAT_TERMINAL |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
659 else if (term_use_loop()) |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
660 buf[i++] = 't'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
661 #endif |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
662 else if (VIsual_active) |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
663 { |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
664 if (VIsual_select) |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
665 buf[i++] = VIsual_mode + 's' - 'v'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
666 else |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
667 { |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
668 buf[i++] = VIsual_mode; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
669 if (restart_VIsual_select) |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
670 buf[i++] = 's'; |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
671 } |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
672 } |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28643
diff
changeset
|
673 else if (State == MODE_HITRETURN || State == MODE_ASKMORE |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28643
diff
changeset
|
674 || State == MODE_SETWSIZE |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28643
diff
changeset
|
675 || State == MODE_CONFIRM) |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
676 { |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
677 buf[i++] = 'r'; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28643
diff
changeset
|
678 if (State == MODE_ASKMORE) |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
679 buf[i++] = 'm'; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28643
diff
changeset
|
680 else if (State == MODE_CONFIRM) |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
681 buf[i++] = '?'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
682 } |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28643
diff
changeset
|
683 else if (State == MODE_EXTERNCMD) |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
684 buf[i++] = '!'; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28643
diff
changeset
|
685 else if (State & MODE_INSERT) |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
686 { |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
687 if (State & VREPLACE_FLAG) |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
688 { |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
689 buf[i++] = 'R'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
690 buf[i++] = 'v'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
691 } |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
692 else |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
693 { |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
694 if (State & REPLACE_FLAG) |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
695 buf[i++] = 'R'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
696 else |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
697 buf[i++] = 'i'; |
28643
5be5151ad510
patch 8.2.4845: duplicate code
Bram Moolenaar <Bram@vim.org>
parents:
28497
diff
changeset
|
698 } |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
699 |
28643
5be5151ad510
patch 8.2.4845: duplicate code
Bram Moolenaar <Bram@vim.org>
parents:
28497
diff
changeset
|
700 if (ins_compl_active()) |
5be5151ad510
patch 8.2.4845: duplicate code
Bram Moolenaar <Bram@vim.org>
parents:
28497
diff
changeset
|
701 buf[i++] = 'c'; |
5be5151ad510
patch 8.2.4845: duplicate code
Bram Moolenaar <Bram@vim.org>
parents:
28497
diff
changeset
|
702 else if (ctrl_x_mode_not_defined_yet()) |
5be5151ad510
patch 8.2.4845: duplicate code
Bram Moolenaar <Bram@vim.org>
parents:
28497
diff
changeset
|
703 buf[i++] = 'x'; |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
704 } |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28643
diff
changeset
|
705 else if ((State & MODE_CMDLINE) || exmode_active) |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
706 { |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
707 buf[i++] = 'c'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
708 if (exmode_active == EXMODE_VIM) |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
709 buf[i++] = 'v'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
710 else if (exmode_active == EXMODE_NORMAL) |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
711 buf[i++] = 'e'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
712 } |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
713 else |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
714 { |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
715 buf[i++] = 'n'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
716 if (finish_op) |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
717 { |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
718 buf[i++] = 'o'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
719 // to be able to detect force-linewise/blockwise/characterwise |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
720 // operations |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
721 buf[i++] = motion_force; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
722 } |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
723 else if (restart_edit == 'I' || restart_edit == 'R' |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
724 || restart_edit == 'V') |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
725 { |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
726 buf[i++] = 'i'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
727 buf[i++] = restart_edit; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
728 } |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
729 #ifdef FEAT_TERMINAL |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
730 else if (term_in_normal_mode()) |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
731 buf[i++] = 't'; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
732 #endif |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
733 } |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
734 |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
735 buf[i] = NUL; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
736 } |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
737 |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
738 /* |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
739 * "mode()" function |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
740 */ |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
741 void |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
742 f_mode(typval_T *argvars, typval_T *rettv) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
743 { |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
744 char_u buf[MODE_MAX_LENGTH]; |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
745 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
746 if (in_vim9script() && check_for_opt_bool_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
747 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
748 |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
749 get_mode(buf); |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
750 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
751 // Clear out the minor mode when the argument is not a non-zero number or |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
752 // non-empty string. |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
753 if (!non_zero_arg(&argvars[0])) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
754 buf[1] = NUL; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
755 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
756 rettv->vval.v_string = vim_strsave(buf); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
757 rettv->v_type = VAR_STRING; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
758 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
759 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
760 static void |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
761 may_add_state_char(garray_T *gap, char_u *include, int c) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
762 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
763 if (include == NULL || vim_strchr(include, c) != NULL) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
764 ga_append(gap, c); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
765 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
766 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
767 /* |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
768 * "state()" function |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
769 */ |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
770 void |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
771 f_state(typval_T *argvars, typval_T *rettv) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
772 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
773 garray_T ga; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
774 char_u *include = NULL; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
775 int i; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
776 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
777 if (in_vim9script() && check_for_opt_string_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
778 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
779 |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
780 ga_init2(&ga, 1, 20); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
781 if (argvars[0].v_type != VAR_UNKNOWN) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
782 include = tv_get_string(&argvars[0]); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
783 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
784 if (!(stuff_empty() && typebuf.tb_len == 0 && scriptin[curscript] == NULL)) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
785 may_add_state_char(&ga, include, 'm'); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
786 if (op_pending()) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
787 may_add_state_char(&ga, include, 'o'); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
788 if (autocmd_busy) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
789 may_add_state_char(&ga, include, 'x'); |
18143
2416e1a887ca
patch 8.1.2066: no tests for state()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
790 if (ins_compl_active()) |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
791 may_add_state_char(&ga, include, 'a'); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
792 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
793 # ifdef FEAT_JOB_CHANNEL |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
794 if (channel_in_blocking_wait()) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
795 may_add_state_char(&ga, include, 'w'); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
796 # endif |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18104
diff
changeset
|
797 if (!get_was_safe_state()) |
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18104
diff
changeset
|
798 may_add_state_char(&ga, include, 'S'); |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
799 for (i = 0; i < get_callback_depth() && i < 3; ++i) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
800 may_add_state_char(&ga, include, 'c'); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
801 if (msg_scrolled > 0) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
802 may_add_state_char(&ga, include, 's'); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
803 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
804 rettv->v_type = VAR_STRING; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
805 rettv->vval.v_string = ga.ga_data; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
806 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
807 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
808 #endif // FEAT_EVAL |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
809 |
7 | 810 /* |
811 * Get a key stroke directly from the user. | |
812 * Ignores mouse clicks and scrollbar events, except a click for the left | |
813 * button (used at the more prompt). | |
814 * Doesn't use vgetc(), because it syncs undo and eats mapped characters. | |
815 * Disadvantage: typeahead is ignored. | |
816 * Translates the interrupt character for unix to ESC. | |
817 */ | |
818 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
819 get_keystroke(void) |
7 | 820 { |
3328 | 821 char_u *buf = NULL; |
822 int buflen = 150; | |
823 int maxlen; | |
7 | 824 int len = 0; |
825 int n; | |
826 int save_mapped_ctrl_c = mapped_ctrl_c; | |
964 | 827 int waited = 0; |
7 | 828 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
829 mapped_ctrl_c = FALSE; // mappings are not used here |
7 | 830 for (;;) |
831 { | |
832 cursor_on(); | |
833 out_flush(); | |
834 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
835 // Leave some room for check_termcode() to insert a key code into (max |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
836 // 5 chars plus NUL). And fix_input_buffer() can triple the number of |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
837 // bytes. |
3328 | 838 maxlen = (buflen - 6 - len) / 3; |
839 if (buf == NULL) | |
840 buf = alloc(buflen); | |
841 else if (maxlen < 10) | |
842 { | |
6596 | 843 char_u *t_buf = buf; |
844 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
845 // Need some more space. This might happen when receiving a long |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
846 // escape sequence. |
3328 | 847 buflen += 100; |
848 buf = vim_realloc(buf, buflen); | |
6596 | 849 if (buf == NULL) |
850 vim_free(t_buf); | |
3328 | 851 maxlen = (buflen - 6 - len) / 3; |
852 } | |
853 if (buf == NULL) | |
854 { | |
855 do_outofmem_msg((long_u)buflen); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
856 return ESC; // panic! |
3328 | 857 } |
858 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
859 // First time: blocking wait. Second time: wait up to 100ms for a |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
860 // terminal code to complete. |
3328 | 861 n = ui_inchar(buf + len, maxlen, len == 0 ? -1L : 100L, 0); |
7 | 862 if (n > 0) |
863 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
864 // Replace zero and CSI by a special key code. |
9896
7b39615c0db1
commit https://github.com/vim/vim/commit/6bff02eb530aa29aafa2cb5627399837be7a5dd5
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
865 n = fix_input_buffer(buf + len, n); |
7 | 866 len += n; |
964 | 867 waited = 0; |
868 } | |
869 else if (len > 0) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
870 ++waited; // keep track of the waiting time |
964 | 871 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
872 // Incomplete termcode and not timed out yet: get more characters |
3328 | 873 if ((n = check_termcode(1, buf, buflen, &len)) < 0 |
964 | 874 && (!p_ttimeout || waited * 100L < (p_ttm < 0 ? p_tm : p_ttm))) |
7 | 875 continue; |
964 | 876 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
877 if (n == KEYLEN_REMOVED) // key code removed |
2721 | 878 { |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28643
diff
changeset
|
879 if (must_redraw != 0 && !need_wait_return && (State |
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28643
diff
changeset
|
880 & (MODE_CMDLINE | MODE_HITRETURN | MODE_ASKMORE)) == 0) |
2721 | 881 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
882 // Redrawing was postponed, do it now. |
2721 | 883 update_screen(0); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
884 setcursor(); // put cursor back where it belongs |
2721 | 885 } |
2672 | 886 continue; |
2721 | 887 } |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
888 if (n > 0) // found a termcode: adjust length |
7 | 889 len = n; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
890 if (len == 0) // nothing typed yet |
7 | 891 continue; |
892 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
893 // Handle modifier and/or special key code. |
7 | 894 n = buf[0]; |
895 if (n == K_SPECIAL) | |
896 { | |
897 n = TO_SPECIAL(buf[1], buf[2]); | |
898 if (buf[1] == KS_MODIFIER | |
899 || n == K_IGNORE | |
4221 | 900 || (is_mouse_key(n) && n != K_LEFTMOUSE) |
901 #ifdef FEAT_GUI | |
7 | 902 || n == K_VER_SCROLLBAR |
903 || n == K_HOR_SCROLLBAR | |
904 #endif | |
905 ) | |
906 { | |
907 if (buf[1] == KS_MODIFIER) | |
908 mod_mask = buf[2]; | |
909 len -= 3; | |
910 if (len > 0) | |
911 mch_memmove(buf, buf + 3, (size_t)len); | |
912 continue; | |
913 } | |
828 | 914 break; |
7 | 915 } |
916 if (has_mbyte) | |
917 { | |
918 if (MB_BYTE2LEN(n) > len) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
919 continue; // more bytes to get |
3328 | 920 buf[len >= buflen ? buflen - 1 : len] = NUL; |
7 | 921 n = (*mb_ptr2char)(buf); |
922 } | |
923 #ifdef UNIX | |
924 if (n == intr_char) | |
925 n = ESC; | |
926 #endif | |
927 break; | |
928 } | |
3328 | 929 vim_free(buf); |
7 | 930 |
931 mapped_ctrl_c = save_mapped_ctrl_c; | |
932 return n; | |
933 } | |
934 | |
935 /* | |
374 | 936 * Get a number from the user. |
937 * When "mouse_used" is not NULL allow using the mouse. | |
7 | 938 */ |
939 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
940 get_number( |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
941 int colon, // allow colon to abort |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
942 int *mouse_used) |
7 | 943 { |
944 int n = 0; | |
945 int c; | |
810 | 946 int typed = 0; |
7 | 947 |
374 | 948 if (mouse_used != NULL) |
949 *mouse_used = FALSE; | |
950 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
951 // When not printing messages, the user won't know what to type, return a |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
952 // zero (as if CR was hit). |
7 | 953 if (msg_silent != 0) |
954 return 0; | |
955 | |
956 #ifdef USE_ON_FLY_SCROLL | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
957 dont_scroll = TRUE; // disallow scrolling here |
7 | 958 #endif |
959 ++no_mapping; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
960 ++allow_keys; // no mapping here, but recognize keys |
7 | 961 for (;;) |
962 { | |
963 windgoto(msg_row, msg_col); | |
964 c = safe_vgetc(); | |
965 if (VIM_ISDIGIT(c)) | |
966 { | |
967 n = n * 10 + c - '0'; | |
968 msg_putchar(c); | |
810 | 969 ++typed; |
7 | 970 } |
971 else if (c == K_DEL || c == K_KDEL || c == K_BS || c == Ctrl_H) | |
972 { | |
810 | 973 if (typed > 0) |
974 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
975 msg_puts("\b \b"); |
810 | 976 --typed; |
977 } | |
7 | 978 n /= 10; |
979 } | |
374 | 980 else if (mouse_used != NULL && c == K_LEFTMOUSE) |
981 { | |
982 *mouse_used = TRUE; | |
983 n = mouse_row + 1; | |
984 break; | |
985 } | |
7 | 986 else if (n == 0 && c == ':' && colon) |
987 { | |
988 stuffcharReadbuff(':'); | |
989 if (!exmode_active) | |
990 cmdline_row = msg_row; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
991 skip_redraw = TRUE; // skip redraw once |
7 | 992 do_redraw = FALSE; |
993 break; | |
994 } | |
24673
53fd6370e4fd
patch 8.2.2875: cancelling inputlist() after a digit does not return zero
Bram Moolenaar <Bram@vim.org>
parents:
23952
diff
changeset
|
995 else if (c == Ctrl_C || c == ESC || c == 'q') |
53fd6370e4fd
patch 8.2.2875: cancelling inputlist() after a digit does not return zero
Bram Moolenaar <Bram@vim.org>
parents:
23952
diff
changeset
|
996 { |
53fd6370e4fd
patch 8.2.2875: cancelling inputlist() after a digit does not return zero
Bram Moolenaar <Bram@vim.org>
parents:
23952
diff
changeset
|
997 n = 0; |
53fd6370e4fd
patch 8.2.2875: cancelling inputlist() after a digit does not return zero
Bram Moolenaar <Bram@vim.org>
parents:
23952
diff
changeset
|
998 break; |
53fd6370e4fd
patch 8.2.2875: cancelling inputlist() after a digit does not return zero
Bram Moolenaar <Bram@vim.org>
parents:
23952
diff
changeset
|
999 } |
53fd6370e4fd
patch 8.2.2875: cancelling inputlist() after a digit does not return zero
Bram Moolenaar <Bram@vim.org>
parents:
23952
diff
changeset
|
1000 else if (c == CAR || c == NL ) |
7 | 1001 break; |
1002 } | |
1003 --no_mapping; | |
1004 --allow_keys; | |
1005 return n; | |
1006 } | |
1007 | |
323 | 1008 /* |
1009 * Ask the user to enter a number. | |
374 | 1010 * When "mouse_used" is not NULL allow using the mouse and in that case return |
1011 * the line number. | |
323 | 1012 */ |
1013 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1014 prompt_for_number(int *mouse_used) |
323 | 1015 { |
1016 int i; | |
344 | 1017 int save_cmdline_row; |
1018 int save_State; | |
323 | 1019 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1020 // When using ":silent" assume that <CR> was entered. |
375 | 1021 if (mouse_used != NULL) |
20788
072ad890c227
patch 8.2.0946: cannot use "q" to cancel a number prompt
Bram Moolenaar <Bram@vim.org>
parents:
20345
diff
changeset
|
1022 msg_puts(_("Type number and <Enter> or click with the mouse (q or empty cancels): ")); |
375 | 1023 else |
20788
072ad890c227
patch 8.2.0946: cannot use "q" to cancel a number prompt
Bram Moolenaar <Bram@vim.org>
parents:
20345
diff
changeset
|
1024 msg_puts(_("Type number and <Enter> (q or empty cancels): ")); |
344 | 1025 |
14629
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1026 // Set the state such that text can be selected/copied/pasted and we still |
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1027 // get mouse events. redraw_after_callback() will not redraw if cmdline_row |
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1028 // is zero. |
344 | 1029 save_cmdline_row = cmdline_row; |
957 | 1030 cmdline_row = 0; |
344 | 1031 save_State = State; |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28643
diff
changeset
|
1032 State = MODE_CMDLINE; |
14629
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1033 // May show different mouse shape. |
13768
bcef80912112
patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1034 setmouse(); |
bcef80912112
patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1035 |
374 | 1036 i = get_number(TRUE, mouse_used); |
1037 if (KeyTyped) | |
1038 { | |
17018
b1263192461f
patch 8.1.1509: cmdline_row can become negative, causing a crash
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1039 // don't call wait_return() now |
b1263192461f
patch 8.1.1509: cmdline_row can become negative, causing a crash
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1040 if (msg_row > 0) |
b1263192461f
patch 8.1.1509: cmdline_row can become negative, causing a crash
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1041 cmdline_row = msg_row - 1; |
323 | 1042 need_wait_return = FALSE; |
18528
6ad15a9b7c89
patch 8.1.2258: may get hit-enter prompt after entering a number
Bram Moolenaar <Bram@vim.org>
parents:
18463
diff
changeset
|
1043 msg_didany = FALSE; |
6ad15a9b7c89
patch 8.1.2258: may get hit-enter prompt after entering a number
Bram Moolenaar <Bram@vim.org>
parents:
18463
diff
changeset
|
1044 msg_didout = FALSE; |
323 | 1045 } |
344 | 1046 else |
1047 cmdline_row = save_cmdline_row; | |
1048 State = save_State; | |
14629
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1049 // May need to restore mouse shape. |
13768
bcef80912112
patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1050 setmouse(); |
344 | 1051 |
323 | 1052 return i; |
1053 } | |
1054 | |
7 | 1055 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1056 msgmore(long n) |
7 | 1057 { |
1058 long pn; | |
1059 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1060 if (global_busy // no messages now, wait until global is finished |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1061 || !messaging()) // 'lazyredraw' set, don't do messages now |
7 | 1062 return; |
1063 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1064 // We don't want to overwrite another important message, but do overwrite |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1065 // a previous "more lines" or "fewer lines" message, so that "5dd" and |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1066 // then "put" reports the last action. |
135 | 1067 if (keep_msg != NULL && !keep_msg_more) |
1068 return; | |
1069 | |
7 | 1070 if (n > 0) |
1071 pn = n; | |
1072 else | |
1073 pn = -n; | |
1074 | |
1075 if (pn > p_report) | |
1076 { | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
1077 if (n > 0) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1078 vim_snprintf(msg_buf, MSG_BUF_LEN, |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
1079 NGETTEXT("%ld more line", "%ld more lines", pn), pn); |
7 | 1080 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1081 vim_snprintf(msg_buf, MSG_BUF_LEN, |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
1082 NGETTEXT("%ld line less", "%ld fewer lines", pn), pn); |
7 | 1083 if (got_int) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1084 vim_strcat((char_u *)msg_buf, (char_u *)_(" (Interrupted)"), |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1085 MSG_BUF_LEN); |
7 | 1086 if (msg(msg_buf)) |
1087 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1088 set_keep_msg((char_u *)msg_buf, 0); |
135 | 1089 keep_msg_more = TRUE; |
7 | 1090 } |
1091 } | |
1092 } | |
1093 | |
1094 /* | |
1095 * flush map and typeahead buffers and give a warning for an error | |
1096 */ | |
1097 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1098 beep_flush(void) |
7 | 1099 { |
1100 if (emsg_silent == 0) | |
1101 { | |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1102 flush_buffers(FLUSH_MINIMAL); |
6949 | 1103 vim_beep(BO_ERROR); |
1104 } | |
1105 } | |
1106 | |
1107 /* | |
28441
f4d2dcfd18ac
patch 8.2.4745: using wrong flag for using bell in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
28397
diff
changeset
|
1108 * Give a warning for an error. "val" is one of the BO_ values, e.g., BO_OPER. |
7 | 1109 */ |
1110 void | |
28441
f4d2dcfd18ac
patch 8.2.4745: using wrong flag for using bell in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
28397
diff
changeset
|
1111 vim_beep(unsigned val) |
7 | 1112 { |
13272
abaebba89fd4
patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1113 #ifdef FEAT_EVAL |
abaebba89fd4
patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1114 called_vim_beep = TRUE; |
abaebba89fd4
patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1115 #endif |
abaebba89fd4
patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1116 |
22742
f7f2d73ff85e
patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents:
22685
diff
changeset
|
1117 if (emsg_silent == 0 && !in_assert_fails) |
7 | 1118 { |
6949 | 1119 if (!((bo_flags & val) || (bo_flags & BO_ALL))) |
1120 { | |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1121 #ifdef ELAPSED_FUNC |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1122 static int did_init = FALSE; |
15525
3ef31ce9d9f9
patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1123 static elapsed_T start_tv; |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1124 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1125 // Only beep once per half a second, otherwise a sequence of beeps |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1126 // would freeze Vim. |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1127 if (!did_init || ELAPSED_FUNC(start_tv) > 500) |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1128 { |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1129 did_init = TRUE; |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1130 ELAPSED_INIT(start_tv); |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1131 #endif |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1132 if (p_vb |
7 | 1133 #ifdef FEAT_GUI |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1134 // While the GUI is starting up the termcap is set for |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1135 // the GUI but the output still goes to a terminal. |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1136 && !(gui.in_use && gui.starting) |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1137 #endif |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1138 ) |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1139 { |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1140 out_str_cf(T_VB); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1141 #ifdef FEAT_VTP |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1142 // No restore color information, refresh the screen. |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1143 if (has_vtp_working() != 0 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1144 # ifdef FEAT_TERMGUICOLORS |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
1145 && (p_tgc || (!p_tgc && t_colors >= 256)) |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1146 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1147 ) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1148 { |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29678
diff
changeset
|
1149 redraw_later(UPD_CLEAR); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1150 update_screen(0); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1151 redrawcmd(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1152 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1153 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1154 } |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1155 else |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1156 out_char(BELL); |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1157 #ifdef ELAPSED_FUNC |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1158 } |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1159 #endif |
7 | 1160 } |
169 | 1161 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1162 // When 'debug' contains "beep" produce a message. If we are sourcing |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1163 // a script or executing a function give the user a hint where the beep |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1164 // comes from. |
169 | 1165 if (vim_strchr(p_debug, 'e') != NULL) |
1166 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1167 msg_source(HL_ATTR(HLF_W)); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1168 msg_attr(_("Beep!"), HL_ATTR(HLF_W)); |
169 | 1169 } |
7 | 1170 } |
1171 } | |
1172 | |
1173 /* | |
1174 * To get the "real" home directory: | |
1175 * - get value of $HOME | |
1176 * For Unix: | |
1177 * - go to that directory | |
1178 * - do mch_dirname() to get the real name of that directory. | |
1179 * This also works with mounts and links. | |
1180 * Don't do this for MS-DOS, it will change the "current dir" for a drive. | |
15046
c1be7c8bb602
patch 8.1.0534: MS-Windows installer uses different $HOME than Vim
Bram Moolenaar <Bram@vim.org>
parents:
14909
diff
changeset
|
1181 * For Windows: |
c1be7c8bb602
patch 8.1.0534: MS-Windows installer uses different $HOME than Vim
Bram Moolenaar <Bram@vim.org>
parents:
14909
diff
changeset
|
1182 * This code is duplicated in init_homedir() in dosinst.c. Keep in sync! |
7 | 1183 */ |
1184 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1185 init_homedir(void) |
7 | 1186 { |
1187 char_u *var; | |
1188 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1189 // In case we are called a second time (when 'encoding' changes). |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
1190 VIM_CLEAR(homedir); |
170 | 1191 |
7 | 1192 #ifdef VMS |
1193 var = mch_getenv((char_u *)"SYS$LOGIN"); | |
1194 #else | |
1195 var = mch_getenv((char_u *)"HOME"); | |
1196 #endif | |
1197 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15814
diff
changeset
|
1198 #ifdef MSWIN |
7 | 1199 /* |
12265
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1200 * Typically, $HOME is not defined on Windows, unless the user has |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1201 * specifically defined it for Vim's sake. However, on Windows NT |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1202 * platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1203 * each user. Try constructing $HOME from these. |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1204 */ |
12269
d2373927d76d
patch 8.0.1014: old compiler doesn't know uint32_t
Christian Brabandt <cb@256bit.org>
parents:
12265
diff
changeset
|
1205 if (var == NULL || *var == NUL) |
12265
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1206 { |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1207 char_u *homedrive, *homepath; |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1208 |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1209 homedrive = mch_getenv((char_u *)"HOMEDRIVE"); |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1210 homepath = mch_getenv((char_u *)"HOMEPATH"); |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1211 if (homepath == NULL || *homepath == NUL) |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1212 homepath = (char_u *)"\\"; |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1213 if (homedrive != NULL |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1214 && STRLEN(homedrive) + STRLEN(homepath) < MAXPATHL) |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1215 { |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1216 sprintf((char *)NameBuff, "%s%s", homedrive, homepath); |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1217 if (NameBuff[0] != NUL) |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1218 var = NameBuff; |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1219 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1220 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1221 |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1222 if (var == NULL) |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1223 var = mch_getenv((char_u *)"USERPROFILE"); |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1224 |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1225 /* |
7 | 1226 * Weird but true: $HOME may contain an indirect reference to another |
1227 * variable, esp. "%USERPROFILE%". Happens when $USERPROFILE isn't set | |
1228 * when $HOME is being set. | |
1229 */ | |
1230 if (var != NULL && *var == '%') | |
1231 { | |
1232 char_u *p; | |
1233 char_u *exp; | |
1234 | |
1235 p = vim_strchr(var + 1, '%'); | |
1236 if (p != NULL) | |
1237 { | |
419 | 1238 vim_strncpy(NameBuff, var + 1, p - (var + 1)); |
7 | 1239 exp = mch_getenv(NameBuff); |
1240 if (exp != NULL && *exp != NUL | |
1241 && STRLEN(exp) + STRLEN(p) < MAXPATHL) | |
1242 { | |
274 | 1243 vim_snprintf((char *)NameBuff, MAXPATHL, "%s%s", exp, p + 1); |
7 | 1244 var = NameBuff; |
12265
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1245 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1246 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1247 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1248 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1249 if (var != NULL && *var == NUL) // empty is same as not set |
12265
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1250 var = NULL; |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1251 |
170 | 1252 if (enc_utf8 && var != NULL) |
1253 { | |
1254 int len; | |
2786 | 1255 char_u *pp = NULL; |
170 | 1256 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1257 // Convert from active codepage to UTF-8. Other conversions are |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1258 // not done, because they would fail for non-ASCII characters. |
835 | 1259 acp_to_enc(var, (int)STRLEN(var), &pp, &len); |
170 | 1260 if (pp != NULL) |
1261 { | |
1262 homedir = pp; | |
1263 return; | |
1264 } | |
1265 } | |
12265
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1266 |
7 | 1267 /* |
1268 * Default home dir is C:/ | |
1269 * Best assumption we can make in such a situation. | |
1270 */ | |
1271 if (var == NULL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
1272 var = (char_u *)"C:/"; |
7 | 1273 #endif |
12265
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1274 |
7 | 1275 if (var != NULL) |
1276 { | |
1277 #ifdef UNIX | |
1278 /* | |
1279 * Change to the directory and get the actual path. This resolves | |
1280 * links. Don't do it when we can't return. | |
1281 */ | |
1282 if (mch_dirname(NameBuff, MAXPATHL) == OK | |
1283 && mch_chdir((char *)NameBuff) == 0) | |
1284 { | |
1285 if (!mch_chdir((char *)var) && mch_dirname(IObuff, IOSIZE) == OK) | |
1286 var = IObuff; | |
1287 if (mch_chdir((char *)NameBuff) != 0) | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1288 emsg(_(e_cannot_go_back_to_previous_directory)); |
7 | 1289 } |
1290 #endif | |
1291 homedir = vim_strsave(var); | |
1292 } | |
1293 } | |
1294 | |
359 | 1295 #if defined(EXITFREE) || defined(PROTO) |
1296 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1297 free_homedir(void) |
359 | 1298 { |
1299 vim_free(homedir); | |
1300 } | |
3744 | 1301 |
1302 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1303 free_users(void) |
3744 | 1304 { |
1305 ga_clear_strings(&ga_users); | |
1306 } | |
359 | 1307 #endif |
1308 | |
7 | 1309 /* |
1408 | 1310 * Call expand_env() and store the result in an allocated string. |
1311 * This is not very memory efficient, this expects the result to be freed | |
1312 * again soon. | |
1313 */ | |
1314 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1315 expand_env_save(char_u *src) |
1408 | 1316 { |
1317 return expand_env_save_opt(src, FALSE); | |
1318 } | |
1319 | |
1320 /* | |
1321 * Idem, but when "one" is TRUE handle the string as one file name, only | |
1322 * expand "~" at the start. | |
1323 */ | |
1324 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1325 expand_env_save_opt(char_u *src, int one) |
1408 | 1326 { |
1327 char_u *p; | |
1328 | |
1329 p = alloc(MAXPATHL); | |
1330 if (p != NULL) | |
1331 expand_env_esc(src, p, MAXPATHL, FALSE, one, NULL); | |
1332 return p; | |
1333 } | |
1334 | |
1335 /* | |
7 | 1336 * Expand environment variable with path name. |
1337 * "~/" is also expanded, using $HOME. For Unix "~user/" is expanded. | |
1408 | 1338 * Skips over "\ ", "\~" and "\$" (not for Win32 though). |
7 | 1339 * If anything fails no expansion is done and dst equals src. |
1340 */ | |
1341 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1342 expand_env( |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1343 char_u *src, // input string e.g. "$HOME/vim.hlp" |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1344 char_u *dst, // where to put the result |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1345 int dstlen) // maximum length of the result |
7 | 1346 { |
1408 | 1347 expand_env_esc(src, dst, dstlen, FALSE, FALSE, NULL); |
7 | 1348 } |
1349 | |
1350 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1351 expand_env_esc( |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1352 char_u *srcp, // input string e.g. "$HOME/vim.hlp" |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1353 char_u *dst, // where to put the result |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1354 int dstlen, // maximum length of the result |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1355 int esc, // escape spaces in expanded variables |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1356 int one, // "srcp" is one file name |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1357 char_u *startstr) // start again after this (can be NULL) |
374 | 1358 { |
1359 char_u *src; | |
7 | 1360 char_u *tail; |
1361 int c; | |
1362 char_u *var; | |
1363 int copy_char; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1364 int mustfree; // var was allocated, need to free it later |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1365 int at_start = TRUE; // at start of a name |
374 | 1366 int startstr_len = 0; |
29113
495d55210aac
patch 8.2.5077: various warnings from clang on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1367 #if defined(BACKSLASH_IN_FILENAME) || defined(AMIGA) |
495d55210aac
patch 8.2.5077: various warnings from clang on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1368 char_u *save_dst = dst; |
495d55210aac
patch 8.2.5077: various warnings from clang on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1369 #endif |
374 | 1370 |
1371 if (startstr != NULL) | |
835 | 1372 startstr_len = (int)STRLEN(startstr); |
374 | 1373 |
1374 src = skipwhite(srcp); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1375 --dstlen; // leave one char space for "\," |
7 | 1376 while (*src && dstlen > 0) |
1377 { | |
7038
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1378 #ifdef FEAT_EVAL |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1379 // Skip over `=expr`. |
7038
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1380 if (src[0] == '`' && src[1] == '=') |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1381 { |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1382 size_t len; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1383 |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1384 var = src; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1385 src += 2; |
22685
80b4e604d1d5
patch 8.2.1891: Vim9: skipping over expression doesn't handle line breaks
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1386 (void)skip_expr(&src, NULL); |
7038
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1387 if (*src == '`') |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1388 ++src; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1389 len = src - var; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1390 if (len > (size_t)dstlen) |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1391 len = dstlen; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1392 vim_strncpy(dst, var, len); |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1393 dst += len; |
7066
094c8ccdc279
commit https://github.com/vim/vim/commit/5df1ed2de3fa9dcace996b9a0a4c9b3cea79cf1e
Christian Brabandt <cb@256bit.org>
parents:
7038
diff
changeset
|
1394 dstlen -= (int)len; |
7038
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1395 continue; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1396 } |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1397 #endif |
7 | 1398 copy_char = TRUE; |
22 | 1399 if ((*src == '$' |
1400 #ifdef VMS | |
1401 && at_start | |
1402 #endif | |
1403 ) | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8163
diff
changeset
|
1404 #if defined(MSWIN) |
7 | 1405 || *src == '%' |
1406 #endif | |
1407 || (*src == '~' && at_start)) | |
1408 { | |
1409 mustfree = FALSE; | |
1410 | |
1411 /* | |
1412 * The variable name is copied into dst temporarily, because it may | |
1413 * be a string in read-only memory and a NUL needs to be appended. | |
1414 */ | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1415 if (*src != '~') // environment var |
7 | 1416 { |
1417 tail = src + 1; | |
1418 var = dst; | |
1419 c = dstlen - 1; | |
1420 | |
1421 #ifdef UNIX | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1422 // Unix has ${var-name} type environment vars |
7 | 1423 if (*tail == '{' && !vim_isIDc('{')) |
1424 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1425 tail++; // ignore '{' |
7 | 1426 while (c-- > 0 && *tail && *tail != '}') |
1427 *var++ = *tail++; | |
1428 } | |
1429 else | |
1430 #endif | |
1431 { | |
1432 while (c-- > 0 && *tail != NUL && ((vim_isIDc(*tail)) | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8163
diff
changeset
|
1433 #if defined(MSWIN) |
7 | 1434 || (*src == '%' && *tail != '%') |
1435 #endif | |
1436 )) | |
1437 *var++ = *tail++; | |
1438 } | |
1439 | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8163
diff
changeset
|
1440 #if defined(MSWIN) || defined(UNIX) |
7 | 1441 # ifdef UNIX |
1442 if (src[1] == '{' && *tail != '}') | |
1443 # else | |
1444 if (*src == '%' && *tail != '%') | |
1445 # endif | |
1446 var = NULL; | |
1447 else | |
1448 { | |
1449 # ifdef UNIX | |
1450 if (src[1] == '{') | |
1451 # else | |
1452 if (*src == '%') | |
1453 #endif | |
1454 ++tail; | |
1455 #endif | |
1456 *var = NUL; | |
1457 var = vim_getenv(dst, &mustfree); | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8163
diff
changeset
|
1458 #if defined(MSWIN) || defined(UNIX) |
7 | 1459 } |
1460 #endif | |
1461 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1462 // home directory |
7 | 1463 else if ( src[1] == NUL |
1464 || vim_ispathsep(src[1]) | |
1465 || vim_strchr((char_u *)" ,\t\n", src[1]) != NULL) | |
1466 { | |
1467 var = homedir; | |
1468 tail = src + 1; | |
1469 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1470 else // user directory |
7 | 1471 { |
1472 #if defined(UNIX) || (defined(VMS) && defined(USER_HOME)) | |
1473 /* | |
1474 * Copy ~user to dst[], so we can put a NUL after it. | |
1475 */ | |
1476 tail = src; | |
1477 var = dst; | |
1478 c = dstlen - 1; | |
1479 while ( c-- > 0 | |
1480 && *tail | |
1481 && vim_isfilec(*tail) | |
1482 && !vim_ispathsep(*tail)) | |
1483 *var++ = *tail++; | |
1484 *var = NUL; | |
1485 # ifdef UNIX | |
1486 /* | |
1487 * If the system supports getpwnam(), use it. | |
1488 * Otherwise, or if getpwnam() fails, the shell is used to | |
1489 * expand ~user. This is slower and may fail if the shell | |
1490 * does not support ~user (old versions of /bin/sh). | |
1491 */ | |
1492 # if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H) | |
1493 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1494 // Note: memory allocated by getpwnam() is never freed. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1495 // Calling endpwent() apparently doesn't help. |
10932
141fe140976c
patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
1496 struct passwd *pw = (*dst == NUL) |
141fe140976c
patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
1497 ? NULL : getpwnam((char *)dst + 1); |
141fe140976c
patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
1498 |
141fe140976c
patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
1499 var = (pw == NULL) ? NULL : (char_u *)pw->pw_dir; |
7 | 1500 } |
1501 if (var == NULL) | |
1502 # endif | |
1503 { | |
1504 expand_T xpc; | |
1505 | |
1506 ExpandInit(&xpc); | |
1507 xpc.xp_context = EXPAND_FILES; | |
1508 var = ExpandOne(&xpc, dst, NULL, | |
1509 WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE); | |
1510 mustfree = TRUE; | |
1511 } | |
1512 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1513 # else // !UNIX, thus VMS |
7 | 1514 /* |
1515 * USER_HOME is a comma-separated list of | |
1516 * directories to search for the user account in. | |
1517 */ | |
1518 { | |
1519 char_u test[MAXPATHL], paths[MAXPATHL]; | |
1520 char_u *path, *next_path, *ptr; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1521 stat_T st; |
7 | 1522 |
1523 STRCPY(paths, USER_HOME); | |
1524 next_path = paths; | |
1525 while (*next_path) | |
1526 { | |
1527 for (path = next_path; *next_path && *next_path != ','; | |
1528 next_path++); | |
1529 if (*next_path) | |
1530 *next_path++ = NUL; | |
1531 STRCPY(test, path); | |
1532 STRCAT(test, "/"); | |
1533 STRCAT(test, dst + 1); | |
1534 if (mch_stat(test, &st) == 0) | |
1535 { | |
1536 var = alloc(STRLEN(test) + 1); | |
1537 STRCPY(var, test); | |
1538 mustfree = TRUE; | |
1539 break; | |
1540 } | |
1541 } | |
1542 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1543 # endif // UNIX |
7 | 1544 #else |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1545 // cannot expand user's home directory, so don't try |
7 | 1546 var = NULL; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1547 tail = (char_u *)""; // for gcc |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1548 #endif // UNIX || VMS |
7 | 1549 } |
1550 | |
1551 #ifdef BACKSLASH_IN_FILENAME | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1552 // If 'shellslash' is set change backslashes to forward slashes. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1553 // Can't use slash_adjust(), p_ssl may be set temporarily. |
7 | 1554 if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL) |
1555 { | |
1556 char_u *p = vim_strsave(var); | |
1557 | |
1558 if (p != NULL) | |
1559 { | |
1560 if (mustfree) | |
1561 vim_free(var); | |
1562 var = p; | |
1563 mustfree = TRUE; | |
1564 forward_slash(var); | |
1565 } | |
1566 } | |
1567 #endif | |
1568 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1569 // If "var" contains white space, escape it with a backslash. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1570 // Required for ":e ~/tt" when $HOME includes a space. |
7 | 1571 if (esc && var != NULL && vim_strpbrk(var, (char_u *)" \t") != NULL) |
1572 { | |
1573 char_u *p = vim_strsave_escaped(var, (char_u *)" \t"); | |
1574 | |
1575 if (p != NULL) | |
1576 { | |
1577 if (mustfree) | |
1578 vim_free(var); | |
1579 var = p; | |
1580 mustfree = TRUE; | |
1581 } | |
1582 } | |
1583 | |
1584 if (var != NULL && *var != NUL | |
1585 && (STRLEN(var) + STRLEN(tail) + 1 < (unsigned)dstlen)) | |
1586 { | |
1587 STRCPY(dst, var); | |
1588 dstlen -= (int)STRLEN(var); | |
835 | 1589 c = (int)STRLEN(var); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1590 // if var[] ends in a path separator and tail[] starts |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1591 // with it, skip a character |
28451
e015d650ea9f
patch 8.2.4750: small pieces of dead code
Bram Moolenaar <Bram@vim.org>
parents:
28441
diff
changeset
|
1592 if (after_pathsep(dst, dst + c) |
7 | 1593 #if defined(BACKSLASH_IN_FILENAME) || defined(AMIGA) |
29113
495d55210aac
patch 8.2.5077: various warnings from clang on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1594 && (dst == save_dst || dst[-1] != ':') |
7 | 1595 #endif |
1596 && vim_ispathsep(*tail)) | |
1597 ++tail; | |
39 | 1598 dst += c; |
7 | 1599 src = tail; |
1600 copy_char = FALSE; | |
1601 } | |
1602 if (mustfree) | |
1603 vim_free(var); | |
1604 } | |
1605 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1606 if (copy_char) // copy at least one char |
7 | 1607 { |
1608 /* | |
1224 | 1609 * Recognize the start of a new name, for '~'. |
1408 | 1610 * Don't do this when "one" is TRUE, to avoid expanding "~" in |
1611 * ":edit foo ~ foo". | |
7 | 1612 */ |
1613 at_start = FALSE; | |
1614 if (src[0] == '\\' && src[1] != NUL) | |
1615 { | |
1616 *dst++ = *src++; | |
1617 --dstlen; | |
1618 } | |
1408 | 1619 else if ((src[0] == ' ' || src[0] == ',') && !one) |
7 | 1620 at_start = TRUE; |
12005
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1621 if (dstlen > 0) |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1622 { |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1623 *dst++ = *src++; |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1624 --dstlen; |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1625 |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1626 if (startstr != NULL && src - startstr_len >= srcp |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1627 && STRNCMP(src - startstr_len, startstr, |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1628 startstr_len) == 0) |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1629 at_start = TRUE; |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1630 } |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1631 } |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1632 |
7 | 1633 } |
1634 *dst = NUL; | |
1635 } | |
1636 | |
1637 /* | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1638 * If the string between "p" and "pend" ends in "name/", return "pend" minus |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1639 * the length of "name/". Otherwise return "pend". |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1640 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1641 static char_u * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1642 remove_tail(char_u *p, char_u *pend, char_u *name) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1643 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1644 int len = (int)STRLEN(name) + 1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1645 char_u *newend = pend - len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1646 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1647 if (newend >= p |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1648 && fnamencmp(newend, name, len - 1) == 0 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1649 && (newend == p || after_pathsep(p, newend))) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1650 return newend; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1651 return pend; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1652 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1653 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1654 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1655 * Check if the directory "vimdir/<version>" or "vimdir/runtime" exists. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1656 * Return NULL if not, return its name in allocated memory otherwise. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1657 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1658 static char_u * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1659 vim_version_dir(char_u *vimdir) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1660 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1661 char_u *p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1662 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1663 if (vimdir == NULL || *vimdir == NUL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1664 return NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1665 p = concat_fnames(vimdir, (char_u *)VIM_VERSION_NODOT, TRUE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1666 if (p != NULL && mch_isdir(p)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1667 return p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1668 vim_free(p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1669 p = concat_fnames(vimdir, (char_u *)RUNTIME_DIRNAME, TRUE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1670 if (p != NULL && mch_isdir(p)) |
29371
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1671 { |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1672 char_u *fname = concat_fnames(p, (char_u *)"defaults.vim", TRUE); |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1673 |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1674 // Check that "defaults.vim" exists in this directory, to avoid picking |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1675 // up a stray "runtime" directory, it would make many tests fail in |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1676 // mysterious ways. |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1677 if (fname != NULL) |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1678 { |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1679 int exists = file_is_readable(fname); |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1680 |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1681 vim_free(fname); |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1682 if (exists) |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1683 return p; |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1684 } |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29308
diff
changeset
|
1685 } |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1686 vim_free(p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1687 return NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1688 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1689 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1690 /* |
7 | 1691 * Vim's version of getenv(). |
1692 * Special handling of $HOME, $VIM and $VIMRUNTIME. | |
196 | 1693 * Also does ACP to 'enc' conversion for Win32. |
2786 | 1694 * "mustfree" is set to TRUE when returned is allocated, it must be |
1695 * initialized to FALSE by the caller. | |
7 | 1696 */ |
1697 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1698 vim_getenv(char_u *name, int *mustfree) |
7 | 1699 { |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1700 char_u *p = NULL; |
7 | 1701 char_u *pend; |
1702 int vimruntime; | |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1703 #ifdef MSWIN |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1704 WCHAR *wn, *wp; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1705 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1706 // use "C:/" when $HOME is not set |
7 | 1707 if (STRCMP(name, "HOME") == 0) |
1708 return homedir; | |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1709 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1710 // Use Wide function |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1711 wn = enc_to_utf16(name, NULL); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1712 if (wn == NULL) |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1713 return NULL; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1714 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1715 wp = _wgetenv(wn); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1716 vim_free(wn); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1717 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1718 if (wp != NULL && *wp == NUL) // empty is the same as not set |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1719 wp = NULL; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1720 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1721 if (wp != NULL) |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1722 { |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1723 p = utf16_to_enc(wp, NULL); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1724 if (p == NULL) |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1725 return NULL; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1726 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1727 *mustfree = TRUE; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1728 return p; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1729 } |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1730 #else |
7 | 1731 p = mch_getenv(name); |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1732 if (p != NULL && *p == NUL) // empty is the same as not set |
7 | 1733 p = NULL; |
1734 | |
1735 if (p != NULL) | |
1736 return p; | |
20277
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1737 |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1738 # ifdef __HAIKU__ |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1739 // special handling for user settings directory... |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1740 if (STRCMP(name, "BE_USER_SETTINGS") == 0) |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1741 { |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1742 static char userSettingsPath[MAXPATHL]; |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1743 |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1744 if (find_directory(B_USER_SETTINGS_DIRECTORY, 0, false, |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1745 userSettingsPath, MAXPATHL) == B_OK) |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1746 return (char_u *)userSettingsPath; |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1747 else |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1748 return NULL; |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1749 } |
8a694c9447d7
patch 8.2.0694: Haiku: channel and terminal do not work
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1750 # endif |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1751 #endif |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1752 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1753 // handling $VIMRUNTIME and $VIM is below, bail out if it's another name. |
7 | 1754 vimruntime = (STRCMP(name, "VIMRUNTIME") == 0); |
1755 if (!vimruntime && STRCMP(name, "VIM") != 0) | |
1756 return NULL; | |
1757 | |
1758 /* | |
1759 * When expanding $VIMRUNTIME fails, try using $VIM/vim<version> or $VIM. | |
1760 * Don't do this when default_vimruntime_dir is non-empty. | |
1761 */ | |
1762 if (vimruntime | |
1763 #ifdef HAVE_PATHDEF | |
1764 && *default_vimruntime_dir == NUL | |
1765 #endif | |
1766 ) | |
1767 { | |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1768 #ifdef MSWIN |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1769 // Use Wide function |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1770 wp = _wgetenv(L"VIM"); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1771 if (wp != NULL && *wp == NUL) // empty is the same as not set |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1772 wp = NULL; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1773 if (wp != NULL) |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1774 { |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1775 char_u *q = utf16_to_enc(wp, NULL); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1776 if (q != NULL) |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1777 { |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1778 p = vim_version_dir(q); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1779 *mustfree = TRUE; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1780 if (p == NULL) |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1781 p = q; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1782 } |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1783 } |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1784 #else |
7 | 1785 p = mch_getenv((char_u *)"VIM"); |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1786 if (p != NULL && *p == NUL) // empty is the same as not set |
7 | 1787 p = NULL; |
1788 if (p != NULL) | |
1789 { | |
1790 p = vim_version_dir(p); | |
1791 if (p != NULL) | |
1792 *mustfree = TRUE; | |
1793 else | |
1794 p = mch_getenv((char_u *)"VIM"); | |
1795 } | |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1796 #endif |
7 | 1797 } |
1798 | |
1799 /* | |
1800 * When expanding $VIM or $VIMRUNTIME fails, try using: | |
1801 * - the directory name from 'helpfile' (unless it contains '$') | |
1802 * - the executable name from argv[0] | |
1803 */ | |
1804 if (p == NULL) | |
1805 { | |
1806 if (p_hf != NULL && vim_strchr(p_hf, '$') == NULL) | |
1807 p = p_hf; | |
1808 #ifdef USE_EXE_NAME | |
1809 /* | |
1810 * Use the name of the executable, obtained from argv[0]. | |
1811 */ | |
1812 else | |
1813 p = exe_name; | |
1814 #endif | |
1815 if (p != NULL) | |
1816 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1817 // remove the file name |
7 | 1818 pend = gettail(p); |
1819 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1820 // remove "doc/" from 'helpfile', if present |
7 | 1821 if (p == p_hf) |
1822 pend = remove_tail(p, pend, (char_u *)"doc"); | |
1823 | |
1824 #ifdef USE_EXE_NAME | |
1825 # ifdef MACOS_X | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1826 // remove "MacOS" from exe_name and add "Resources/vim" |
7 | 1827 if (p == exe_name) |
1828 { | |
1829 char_u *pend1; | |
768 | 1830 char_u *pnew; |
1831 | |
1832 pend1 = remove_tail(p, pend, (char_u *)"MacOS"); | |
1833 if (pend1 != pend) | |
1834 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
1835 pnew = alloc(pend1 - p + 15); |
768 | 1836 if (pnew != NULL) |
1837 { | |
1838 STRNCPY(pnew, p, (pend1 - p)); | |
1839 STRCPY(pnew + (pend1 - p), "Resources/vim"); | |
1840 p = pnew; | |
1841 pend = p + STRLEN(p); | |
1842 } | |
1843 } | |
7 | 1844 } |
1845 # endif | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1846 // remove "src/" from exe_name, if present |
7 | 1847 if (p == exe_name) |
1848 pend = remove_tail(p, pend, (char_u *)"src"); | |
1849 #endif | |
1850 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1851 // for $VIM, remove "runtime/" or "vim54/", if present |
7 | 1852 if (!vimruntime) |
1853 { | |
1854 pend = remove_tail(p, pend, (char_u *)RUNTIME_DIRNAME); | |
1855 pend = remove_tail(p, pend, (char_u *)VIM_VERSION_NODOT); | |
1856 } | |
1857 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1858 // remove trailing path separator |
39 | 1859 if (pend > p && after_pathsep(p, pend)) |
7 | 1860 --pend; |
1861 | |
768 | 1862 #ifdef MACOS_X |
1863 if (p == exe_name || p == p_hf) | |
1864 #endif | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1865 // check that the result is a directory name |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20788
diff
changeset
|
1866 p = vim_strnsave(p, pend - p); |
7 | 1867 |
1868 if (p != NULL && !mch_isdir(p)) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
1869 VIM_CLEAR(p); |
7 | 1870 else |
1871 { | |
1872 #ifdef USE_EXE_NAME | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1873 // may add "/vim54" or "/runtime" if it exists |
7 | 1874 if (vimruntime && (pend = vim_version_dir(p)) != NULL) |
1875 { | |
1876 vim_free(p); | |
1877 p = pend; | |
1878 } | |
1879 #endif | |
1880 *mustfree = TRUE; | |
1881 } | |
1882 } | |
1883 } | |
1884 | |
1885 #ifdef HAVE_PATHDEF | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1886 // When there is a pathdef.c file we can use default_vim_dir and |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1887 // default_vimruntime_dir |
7 | 1888 if (p == NULL) |
1889 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1890 // Only use default_vimruntime_dir when it is not empty |
7 | 1891 if (vimruntime && *default_vimruntime_dir != NUL) |
1892 { | |
1893 p = default_vimruntime_dir; | |
1894 *mustfree = FALSE; | |
1895 } | |
1896 else if (*default_vim_dir != NUL) | |
1897 { | |
1898 if (vimruntime && (p = vim_version_dir(default_vim_dir)) != NULL) | |
1899 *mustfree = TRUE; | |
1900 else | |
1901 { | |
1902 p = default_vim_dir; | |
1903 *mustfree = FALSE; | |
1904 } | |
1905 } | |
1906 } | |
1907 #endif | |
1908 | |
1909 /* | |
1910 * Set the environment variable, so that the new value can be found fast | |
1911 * next time, and others can also use it (e.g. Perl). | |
1912 */ | |
1913 if (p != NULL) | |
1914 { | |
1915 if (vimruntime) | |
1916 { | |
1917 vim_setenv((char_u *)"VIMRUNTIME", p); | |
1918 didset_vimruntime = TRUE; | |
1919 } | |
1920 else | |
1921 { | |
1922 vim_setenv((char_u *)"VIM", p); | |
1923 didset_vim = TRUE; | |
1924 } | |
1925 } | |
1926 return p; | |
1927 } | |
1928 | |
13923
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1929 void |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1930 vim_unsetenv(char_u *var) |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1931 { |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1932 #ifdef HAVE_UNSETENV |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1933 unsetenv((char *)var); |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1934 #else |
13942
a039c93f5ff7
patch 8.0.1841: HP-UX does not have setenv()
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
1935 vim_setenv(var, (char_u *)""); |
13923
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1936 #endif |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1937 } |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1938 |
28459
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1939 /* |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1940 * Removes environment variable "name" and take care of side effects. |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1941 */ |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1942 void |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1943 vim_unsetenv_ext(char_u *var) |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1944 { |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1945 vim_unsetenv(var); |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1946 |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1947 // "homedir" is not cleared, keep using the old value until $HOME is set. |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1948 if (STRICMP(var, "VIM") == 0) |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1949 didset_vim = FALSE; |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1950 else if (STRICMP(var, "VIMRUNTIME") == 0) |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1951 didset_vimruntime = FALSE; |
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1952 } |
13923
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1953 |
28463
8bf3198ca147
patch 8.2.4756: build error without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
1954 #if defined(FEAT_EVAL) || defined(PROTO) |
7 | 1955 /* |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1956 * Set environment variable "name" and take care of side effects. |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1957 */ |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1958 void |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1959 vim_setenv_ext(char_u *name, char_u *val) |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1960 { |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1961 vim_setenv(name, val); |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1962 if (STRICMP(name, "HOME") == 0) |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1963 init_homedir(); |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1964 else if (didset_vim && STRICMP(name, "VIM") == 0) |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1965 didset_vim = FALSE; |
28459
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28451
diff
changeset
|
1966 else if (didset_vimruntime && STRICMP(name, "VIMRUNTIME") == 0) |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1967 didset_vimruntime = FALSE; |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1968 } |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
1969 #endif |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1970 |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1971 /* |
7 | 1972 * Our portable version of setenv. |
1973 */ | |
1974 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1975 vim_setenv(char_u *name, char_u *val) |
7 | 1976 { |
1977 #ifdef HAVE_SETENV | |
1978 mch_setenv((char *)name, (char *)val, 1); | |
1979 #else | |
1980 char_u *envbuf; | |
1981 | |
1982 /* | |
1983 * Putenv does not copy the string, it has to remain | |
1984 * valid. The allocated memory will never be freed. | |
1985 */ | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
1986 envbuf = alloc(STRLEN(name) + STRLEN(val) + 2); |
7 | 1987 if (envbuf != NULL) |
1988 { | |
1989 sprintf((char *)envbuf, "%s=%s", name, val); | |
1990 putenv((char *)envbuf); | |
1991 } | |
1992 #endif | |
3382 | 1993 #ifdef FEAT_GETTEXT |
1994 /* | |
1995 * When setting $VIMRUNTIME adjust the directory to find message | |
1996 * translations to $VIMRUNTIME/lang. | |
1997 */ | |
1998 if (*val != NUL && STRICMP(name, "VIMRUNTIME") == 0) | |
1999 { | |
2000 char_u *buf = concat_str(val, (char_u *)"/lang"); | |
2001 | |
2002 if (buf != NULL) | |
2003 { | |
2004 bindtextdomain(VIMPACKAGE, (char *)buf); | |
2005 vim_free(buf); | |
2006 } | |
2007 } | |
2008 #endif | |
7 | 2009 } |
2010 | |
2011 /* | |
2012 * Function given to ExpandGeneric() to obtain an environment variable name. | |
2013 */ | |
2014 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2015 get_env_name( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2016 expand_T *xp UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2017 int idx) |
7 | 2018 { |
29892
db0939444c96
patch 9.0.0284: using static buffer for multiple completion functions
Bram Moolenaar <Bram@vim.org>
parents:
29812
diff
changeset
|
2019 #if defined(AMIGA) |
db0939444c96
patch 9.0.0284: using static buffer for multiple completion functions
Bram Moolenaar <Bram@vim.org>
parents:
29812
diff
changeset
|
2020 // No environ[] on the Amiga. |
7 | 2021 return NULL; |
29892
db0939444c96
patch 9.0.0284: using static buffer for multiple completion functions
Bram Moolenaar <Bram@vim.org>
parents:
29812
diff
changeset
|
2022 #else |
7 | 2023 # ifndef __WIN32__ |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2024 // Borland C++ 5.2 has this in a header file. |
7 | 2025 extern char **environ; |
2026 # endif | |
2027 char_u *str; | |
2028 int n; | |
2029 | |
2030 str = (char_u *)environ[idx]; | |
2031 if (str == NULL) | |
2032 return NULL; | |
2033 | |
29892
db0939444c96
patch 9.0.0284: using static buffer for multiple completion functions
Bram Moolenaar <Bram@vim.org>
parents:
29812
diff
changeset
|
2034 for (n = 0; n < EXPAND_BUF_LEN - 1; ++n) |
7 | 2035 { |
2036 if (str[n] == '=' || str[n] == NUL) | |
2037 break; | |
29892
db0939444c96
patch 9.0.0284: using static buffer for multiple completion functions
Bram Moolenaar <Bram@vim.org>
parents:
29812
diff
changeset
|
2038 xp->xp_buf[n] = str[n]; |
7 | 2039 } |
29892
db0939444c96
patch 9.0.0284: using static buffer for multiple completion functions
Bram Moolenaar <Bram@vim.org>
parents:
29812
diff
changeset
|
2040 xp->xp_buf[n] = NUL; |
db0939444c96
patch 9.0.0284: using static buffer for multiple completion functions
Bram Moolenaar <Bram@vim.org>
parents:
29812
diff
changeset
|
2041 return xp->xp_buf; |
db0939444c96
patch 9.0.0284: using static buffer for multiple completion functions
Bram Moolenaar <Bram@vim.org>
parents:
29812
diff
changeset
|
2042 #endif |
7 | 2043 } |
3744 | 2044 |
2045 /* | |
14698
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2046 * Add a user name to the list of users in ga_users. |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2047 * Do nothing if user name is NULL or empty. |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2048 */ |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2049 static void |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2050 add_user(char_u *user, int need_copy) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2051 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2052 char_u *user_copy = (user != NULL && need_copy) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2053 ? vim_strsave(user) : user; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2054 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2055 if (user_copy == NULL || *user_copy == NUL || ga_grow(&ga_users, 1) == FAIL) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2056 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2057 if (need_copy) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2058 vim_free(user); |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2059 return; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2060 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2061 ((char_u **)(ga_users.ga_data))[ga_users.ga_len++] = user_copy; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2062 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2063 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2064 /* |
3744 | 2065 * Find all user names for user completion. |
2066 * Done only once and then cached. | |
2067 */ | |
2068 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2069 init_users(void) |
4938
bcb84438bb5b
updated for version 7.3.1214
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2070 { |
3744 | 2071 static int lazy_init_done = FALSE; |
2072 | |
2073 if (lazy_init_done) | |
2074 return; | |
2075 | |
2076 lazy_init_done = TRUE; | |
2077 ga_init2(&ga_users, sizeof(char_u *), 20); | |
2078 | |
2079 # if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H) | |
2080 { | |
2081 struct passwd* pw; | |
2082 | |
2083 setpwent(); | |
2084 while ((pw = getpwent()) != NULL) | |
14698
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2085 add_user((char_u *)pw->pw_name, TRUE); |
3744 | 2086 endpwent(); |
2087 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15814
diff
changeset
|
2088 # elif defined(MSWIN) |
14133
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2089 { |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2090 DWORD nusers = 0, ntotal = 0, i; |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2091 PUSER_INFO_0 uinfo; |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2092 |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2093 if (NetUserEnum(NULL, 0, 0, (LPBYTE *) &uinfo, MAX_PREFERRED_LENGTH, |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2094 &nusers, &ntotal, NULL) == NERR_Success) |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2095 { |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2096 for (i = 0; i < nusers; i++) |
14698
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2097 add_user(utf16_to_enc(uinfo[i].usri0_name, NULL), FALSE); |
14133
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2098 |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2099 NetApiBufferFree(uinfo); |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2100 } |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2101 } |
3744 | 2102 # endif |
14698
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2103 # if defined(HAVE_GETPWNAM) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2104 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2105 char_u *user_env = mch_getenv((char_u *)"USER"); |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2106 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2107 // The $USER environment variable may be a valid remote user name (NIS, |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2108 // LDAP) not already listed by getpwent(), as getpwent() only lists |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2109 // local user names. If $USER is not already listed, check whether it |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2110 // is a valid remote user name using getpwnam() and if it is, add it to |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2111 // the list of user names. |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2112 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2113 if (user_env != NULL && *user_env != NUL) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2114 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2115 int i; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2116 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2117 for (i = 0; i < ga_users.ga_len; i++) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2118 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2119 char_u *local_user = ((char_u **)ga_users.ga_data)[i]; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2120 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2121 if (STRCMP(local_user, user_env) == 0) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2122 break; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2123 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2124 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2125 if (i == ga_users.ga_len) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2126 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2127 struct passwd *pw = getpwnam((char *)user_env); |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2128 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2129 if (pw != NULL) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2130 add_user((char_u *)pw->pw_name, TRUE); |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2131 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2132 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2133 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2134 # endif |
3744 | 2135 } |
2136 | |
2137 /* | |
2138 * Function given to ExpandGeneric() to obtain an user names. | |
2139 */ | |
2140 char_u* | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2141 get_users(expand_T *xp UNUSED, int idx) |
3744 | 2142 { |
2143 init_users(); | |
2144 if (idx < ga_users.ga_len) | |
2145 return ((char_u **)ga_users.ga_data)[idx]; | |
2146 return NULL; | |
2147 } | |
2148 | |
2149 /* | |
2150 * Check whether name matches a user name. Return: | |
2151 * 0 if name does not match any user name. | |
2152 * 1 if name partially matches the beginning of a user name. | |
2153 * 2 is name fully matches a user name. | |
2154 */ | |
14286
95030c543411
patch 8.1.0159: completion for user names does not work for a prefix.
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
2155 int |
95030c543411
patch 8.1.0159: completion for user names does not work for a prefix.
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
2156 match_user(char_u *name) |
3744 | 2157 { |
2158 int i; | |
2159 int n = (int)STRLEN(name); | |
2160 int result = 0; | |
2161 | |
2162 init_users(); | |
2163 for (i = 0; i < ga_users.ga_len; i++) | |
2164 { | |
2165 if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2166 return 2; // full match |
3744 | 2167 if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2168 result = 1; // partial match |
3744 | 2169 } |
2170 return result; | |
2171 } | |
7 | 2172 |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2173 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2174 prepare_to_exit(void) |
7 | 2175 { |
39 | 2176 #if defined(SIGHUP) && defined(SIG_IGN) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2177 // Ignore SIGHUP, because a dropped connection causes a read error, which |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2178 // makes Vim exit and then handling SIGHUP causes various reentrance |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2179 // problems. |
36 | 2180 signal(SIGHUP, SIG_IGN); |
2181 #endif | |
2182 | |
7 | 2183 #ifdef FEAT_GUI |
2184 if (gui.in_use) | |
2185 { | |
2186 gui.dying = TRUE; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2187 out_trash(); // trash any pending output |
7 | 2188 } |
2189 else | |
2190 #endif | |
2191 { | |
2192 windgoto((int)Rows - 1, 0); | |
2193 | |
2194 /* | |
2195 * Switch terminal mode back now, so messages end up on the "normal" | |
2196 * screen (if there are two screens). | |
2197 */ | |
2198 settmode(TMODE_COOK); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10180
diff
changeset
|
2199 stoptermcap(); |
7 | 2200 out_flush(); |
2201 } | |
2202 } | |
2203 | |
2204 /* | |
2205 * Preserve files and exit. | |
2206 * When called IObuff must contain a message. | |
5338 | 2207 * NOTE: This may be called from deathtrap() in a signal handler, avoid unsafe |
2208 * functions, such as allocating memory. | |
7 | 2209 */ |
2210 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2211 preserve_exit(void) |
7 | 2212 { |
2213 buf_T *buf; | |
2214 | |
2215 prepare_to_exit(); | |
2216 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2217 // Setting this will prevent free() calls. That avoids calling free() |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2218 // recursively when free() was invoked with a bad pointer. |
625 | 2219 really_exiting = TRUE; |
2220 | |
7 | 2221 out_str(IObuff); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2222 screen_start(); // don't know where cursor is now |
7 | 2223 out_flush(); |
2224 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2225 ml_close_notmod(); // close all not-modified buffers |
7 | 2226 |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
2227 FOR_ALL_BUFFERS(buf) |
7 | 2228 { |
2229 if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) | |
2230 { | |
20345
d636f5e76347
patch 8.2.0728: messages about a deadly signal are not left aligned
Bram Moolenaar <Bram@vim.org>
parents:
20277
diff
changeset
|
2231 OUT_STR("Vim: preserving files...\r\n"); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2232 screen_start(); // don't know where cursor is now |
7 | 2233 out_flush(); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2234 ml_sync_all(FALSE, FALSE); // preserve all swap files |
7 | 2235 break; |
2236 } | |
2237 } | |
2238 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2239 ml_close_all(FALSE); // close all memfiles, without deleting |
7 | 2240 |
20345
d636f5e76347
patch 8.2.0728: messages about a deadly signal are not left aligned
Bram Moolenaar <Bram@vim.org>
parents:
20277
diff
changeset
|
2241 OUT_STR("Vim: Finished.\r\n"); |
7 | 2242 |
2243 getout(1); | |
2244 } | |
2245 | |
2246 /* | |
2247 * Check for CTRL-C pressed, but only once in a while. | |
2248 * Should be used instead of ui_breakcheck() for functions that check for | |
2249 * each line in the file. Calling ui_breakcheck() each time takes too much | |
2250 * time, because it can be a system call. | |
2251 */ | |
2252 | |
2253 #ifndef BREAKCHECK_SKIP | |
17452
f12745505a23
patch 8.1.1724: too much overhead checking for CTRL-C while processing text
Bram Moolenaar <Bram@vim.org>
parents:
17018
diff
changeset
|
2254 # define BREAKCHECK_SKIP 1000 |
7 | 2255 #endif |
2256 | |
2257 static int breakcheck_count = 0; | |
2258 | |
2259 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2260 line_breakcheck(void) |
7 | 2261 { |
2262 if (++breakcheck_count >= BREAKCHECK_SKIP) | |
2263 { | |
2264 breakcheck_count = 0; | |
2265 ui_breakcheck(); | |
2266 } | |
2267 } | |
2268 | |
2269 /* | |
2270 * Like line_breakcheck() but check 10 times less often. | |
2271 */ | |
2272 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2273 fast_breakcheck(void) |
7 | 2274 { |
2275 if (++breakcheck_count >= BREAKCHECK_SKIP * 10) | |
2276 { | |
2277 breakcheck_count = 0; | |
2278 ui_breakcheck(); | |
2279 } | |
2280 } | |
2281 | |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
2282 # if defined(FEAT_SPELL) || defined(PROTO) |
19728
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2283 /* |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2284 * Like line_breakcheck() but check 100 times less often. |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2285 */ |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2286 void |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2287 veryfast_breakcheck(void) |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2288 { |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2289 if (++breakcheck_count >= BREAKCHECK_SKIP * 100) |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2290 { |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2291 breakcheck_count = 0; |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2292 ui_breakcheck(); |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2293 } |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2294 } |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
2295 #endif |
19728
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2296 |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17452
diff
changeset
|
2297 #if defined(VIM_BACKTICK) || defined(FEAT_EVAL) \ |
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17452
diff
changeset
|
2298 || (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17452
diff
changeset
|
2299 || defined(PROTO) |
7 | 2300 |
2301 #ifndef SEEK_SET | |
2302 # define SEEK_SET 0 | |
2303 #endif | |
2304 #ifndef SEEK_END | |
2305 # define SEEK_END 2 | |
2306 #endif | |
2307 | |
2308 /* | |
2309 * Get the stdout of an external command. | |
5808 | 2310 * If "ret_len" is NULL replace NUL characters with NL. When "ret_len" is not |
2311 * NULL store the length there. | |
7 | 2312 * Returns an allocated string, or NULL for error. |
2313 */ | |
2314 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2315 get_cmd_output( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2316 char_u *cmd, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2317 char_u *infile, // optional input file name |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2318 int flags, // can be SHELL_SILENT |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2319 int *ret_len) |
7 | 2320 { |
2321 char_u *tempname; | |
2322 char_u *command; | |
2323 char_u *buffer = NULL; | |
2324 int len; | |
2325 int i = 0; | |
2326 FILE *fd; | |
2327 | |
2328 if (check_restricted() || check_secure()) | |
2329 return NULL; | |
2330 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2331 // get a name for the temp file |
6721 | 2332 if ((tempname = vim_tempname('o', FALSE)) == NULL) |
7 | 2333 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
2334 emsg(_(e_cant_get_temp_file_name)); |
7 | 2335 return NULL; |
2336 } | |
2337 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2338 // Add the redirection stuff |
24 | 2339 command = make_filter_cmd(cmd, infile, tempname); |
7 | 2340 if (command == NULL) |
2341 goto done; | |
2342 | |
2343 /* | |
2344 * Call the shell to execute the command (errors are ignored). | |
2345 * Don't check timestamps here. | |
2346 */ | |
2347 ++no_check_timestamps; | |
2348 call_shell(command, SHELL_DOOUT | SHELL_EXPAND | flags); | |
2349 --no_check_timestamps; | |
2350 | |
2351 vim_free(command); | |
2352 | |
2353 /* | |
2354 * read the names from the file into memory | |
2355 */ | |
2356 # ifdef VMS | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2357 // created temporary file is not always readable as binary |
7 | 2358 fd = mch_fopen((char *)tempname, "r"); |
2359 # else | |
2360 fd = mch_fopen((char *)tempname, READBIN); | |
2361 # endif | |
2362 | |
28495
f285dd00704e
patch 8.2.4772: old Coverity warning for not checking ftell() return value
Bram Moolenaar <Bram@vim.org>
parents:
28463
diff
changeset
|
2363 // Not being able to seek means we can't read the file. |
f285dd00704e
patch 8.2.4772: old Coverity warning for not checking ftell() return value
Bram Moolenaar <Bram@vim.org>
parents:
28463
diff
changeset
|
2364 if (fd == NULL |
f285dd00704e
patch 8.2.4772: old Coverity warning for not checking ftell() return value
Bram Moolenaar <Bram@vim.org>
parents:
28463
diff
changeset
|
2365 || fseek(fd, 0L, SEEK_END) == -1 |
f285dd00704e
patch 8.2.4772: old Coverity warning for not checking ftell() return value
Bram Moolenaar <Bram@vim.org>
parents:
28463
diff
changeset
|
2366 || (len = ftell(fd)) == -1 // get size of temp file |
f285dd00704e
patch 8.2.4772: old Coverity warning for not checking ftell() return value
Bram Moolenaar <Bram@vim.org>
parents:
28463
diff
changeset
|
2367 || fseek(fd, 0L, SEEK_SET) == -1) // back to the start |
7 | 2368 { |
28497
7c4a9e20c178
patch 8.2.4773: build failure without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
28495
diff
changeset
|
2369 semsg(_(e_cannot_read_from_str_2), tempname); |
28495
f285dd00704e
patch 8.2.4772: old Coverity warning for not checking ftell() return value
Bram Moolenaar <Bram@vim.org>
parents:
28463
diff
changeset
|
2370 if (fd != NULL) |
f285dd00704e
patch 8.2.4772: old Coverity warning for not checking ftell() return value
Bram Moolenaar <Bram@vim.org>
parents:
28463
diff
changeset
|
2371 fclose(fd); |
7 | 2372 goto done; |
2373 } | |
2374 | |
2375 buffer = alloc(len + 1); | |
2376 if (buffer != NULL) | |
2377 i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd); | |
2378 fclose(fd); | |
2379 mch_remove(tempname); | |
2380 if (buffer == NULL) | |
2381 goto done; | |
2382 #ifdef VMS | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2383 len = i; // VMS doesn't give us what we asked for... |
7 | 2384 #endif |
2385 if (i != len) | |
2386 { | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
2387 semsg(_(e_cant_read_file_str), tempname); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
2388 VIM_CLEAR(buffer); |
7 | 2389 } |
5808 | 2390 else if (ret_len == NULL) |
5271
25f67b62afd8
updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2391 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2392 // Change NUL into SOH, otherwise the string is truncated. |
5271
25f67b62afd8
updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2393 for (i = 0; i < len; ++i) |
5275
3ddec3d25bd1
updated for version 7.4b.014
Bram Moolenaar <bram@vim.org>
parents:
5271
diff
changeset
|
2394 if (buffer[i] == NUL) |
3ddec3d25bd1
updated for version 7.4b.014
Bram Moolenaar <bram@vim.org>
parents:
5271
diff
changeset
|
2395 buffer[i] = 1; |
5271
25f67b62afd8
updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2396 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2397 buffer[len] = NUL; // make sure the buffer is terminated |
5271
25f67b62afd8
updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2398 } |
5808 | 2399 else |
2400 *ret_len = len; | |
7 | 2401 |
2402 done: | |
2403 vim_free(tempname); | |
2404 return buffer; | |
2405 } | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2406 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2407 # if defined(FEAT_EVAL) || defined(PROTO) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2408 |
18051
d1e77015f60b
patch 8.1.2021: some global functions can be local to the file
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
2409 static void |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2410 get_cmd_output_as_rettv( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2411 typval_T *argvars, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2412 typval_T *rettv, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2413 int retlist) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2414 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2415 char_u *res = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2416 char_u *p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2417 char_u *infile = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2418 int err = FALSE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2419 FILE *fd; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2420 list_T *list = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2421 int flags = SHELL_SILENT; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2422 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2423 rettv->v_type = VAR_STRING; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2424 rettv->vval.v_string = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2425 if (check_restricted() || check_secure()) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2426 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2427 |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25234
diff
changeset
|
2428 if (in_vim9script() |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25234
diff
changeset
|
2429 && (check_for_string_arg(argvars, 0) == FAIL |
29308
b1304512c036
patch 8.2.5170: tiny issues
Bram Moolenaar <Bram@vim.org>
parents:
29113
diff
changeset
|
2430 || check_for_opt_string_or_number_or_list_arg(argvars, 1) |
b1304512c036
patch 8.2.5170: tiny issues
Bram Moolenaar <Bram@vim.org>
parents:
29113
diff
changeset
|
2431 == FAIL)) |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25234
diff
changeset
|
2432 return; |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25234
diff
changeset
|
2433 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2434 if (argvars[1].v_type != VAR_UNKNOWN) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2435 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2436 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2437 * Write the text to a temp file, to be used for input of the shell |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2438 * command. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2439 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2440 if ((infile = vim_tempname('i', TRUE)) == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2441 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
2442 emsg(_(e_cant_get_temp_file_name)); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2443 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2444 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2445 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2446 fd = mch_fopen((char *)infile, WRITEBIN); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2447 if (fd == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2448 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
2449 semsg(_(e_cant_open_file_str), infile); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2450 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2451 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2452 if (argvars[1].v_type == VAR_NUMBER) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2453 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2454 linenr_T lnum; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2455 buf_T *buf; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2456 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2457 buf = buflist_findnr(argvars[1].vval.v_number); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2458 if (buf == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2459 { |
26439
b18f3b0f317c
patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents:
26414
diff
changeset
|
2460 semsg(_(e_buffer_nr_does_not_exist), argvars[1].vval.v_number); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2461 fclose(fd); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2462 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2463 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2464 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2465 for (lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2466 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2467 for (p = ml_get_buf(buf, lnum, FALSE); *p != NUL; ++p) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2468 if (putc(*p == '\n' ? NUL : *p, fd) == EOF) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2469 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2470 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2471 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2472 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2473 if (putc(NL, fd) == EOF) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2474 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2475 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2476 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2477 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2478 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2479 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2480 else if (argvars[1].v_type == VAR_LIST) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2481 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2482 if (write_list(fd, argvars[1].vval.v_list, TRUE) == FAIL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2483 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2484 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2485 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2486 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2487 size_t len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2488 char_u buf[NUMBUFLEN]; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2489 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2490 p = tv_get_string_buf_chk(&argvars[1], buf); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2491 if (p == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2492 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2493 fclose(fd); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2494 goto errret; // type error; errmsg already given |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2495 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2496 len = STRLEN(p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2497 if (len > 0 && fwrite(p, len, 1, fd) != 1) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2498 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2499 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2500 if (fclose(fd) != 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2501 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2502 if (err) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2503 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
2504 emsg(_(e_error_writing_temp_file)); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2505 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2506 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2507 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2508 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2509 // Omit SHELL_COOKED when invoked with ":silent". Avoids that the shell |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2510 // echoes typeahead, that messes up the display. |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2511 if (!msg_silent) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2512 flags += SHELL_COOKED; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2513 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2514 if (retlist) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2515 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2516 int len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2517 listitem_T *li; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2518 char_u *s = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2519 char_u *start; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2520 char_u *end; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2521 int i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2522 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2523 res = get_cmd_output(tv_get_string(&argvars[0]), infile, flags, &len); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2524 if (res == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2525 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2526 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2527 list = list_alloc(); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2528 if (list == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2529 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2530 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2531 for (i = 0; i < len; ++i) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2532 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2533 start = res + i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2534 while (i < len && res[i] != NL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2535 ++i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2536 end = res + i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2537 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2538 s = alloc(end - start + 1); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2539 if (s == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2540 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2541 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2542 for (p = s; start < end; ++p, ++start) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2543 *p = *start == NUL ? NL : *start; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2544 *p = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2545 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2546 li = listitem_alloc(); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2547 if (li == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2548 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2549 vim_free(s); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2550 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2551 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2552 li->li_tv.v_type = VAR_STRING; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2553 li->li_tv.v_lock = 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2554 li->li_tv.vval.v_string = s; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2555 list_append(list, li); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2556 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2557 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2558 rettv_list_set(rettv, list); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2559 list = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2560 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2561 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2562 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2563 res = get_cmd_output(tv_get_string(&argvars[0]), infile, flags, NULL); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2564 #ifdef USE_CRNL |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2565 // translate <CR><NL> into <NL> |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2566 if (res != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2567 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2568 char_u *s, *d; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2569 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2570 d = res; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2571 for (s = res; *s; ++s) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2572 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2573 if (s[0] == CAR && s[1] == NL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2574 ++s; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2575 *d++ = *s; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2576 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2577 *d = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2578 } |
7 | 2579 #endif |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2580 rettv->vval.v_string = res; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2581 res = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2582 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2583 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2584 errret: |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2585 if (infile != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2586 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2587 mch_remove(infile); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2588 vim_free(infile); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2589 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2590 if (res != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2591 vim_free(res); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2592 if (list != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2593 list_free(list); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2594 } |
7 | 2595 |
2596 /* | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2597 * "system()" function |
7 | 2598 */ |
2599 void | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2600 f_system(typval_T *argvars, typval_T *rettv) |
7 | 2601 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2602 get_cmd_output_as_rettv(argvars, rettv, FALSE); |
7 | 2603 } |
2604 | |
2605 /* | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2606 * "systemlist()" function |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2607 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2608 void |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2609 f_systemlist(typval_T *argvars, typval_T *rettv) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2610 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2611 get_cmd_output_as_rettv(argvars, rettv, TRUE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2612 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2613 # endif // FEAT_EVAL |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2614 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2615 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2616 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2617 /* |
2302
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
2618 * Return TRUE when need to go to Insert mode because of 'insertmode'. |
7 | 2619 * Don't do this when still processing a command or a mapping. |
2620 * Don't do this when inside a ":normal" command. | |
2621 */ | |
2622 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2623 goto_im(void) |
7 | 2624 { |
2625 return (p_im && stuff_empty() && typebuf_typed()); | |
2626 } | |
5867 | 2627 |
2628 /* | |
5911 | 2629 * Returns the isolated name of the shell in allocated memory: |
5867 | 2630 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f". |
2631 * - Remove any argument. E.g., "csh -f" -> "csh". | |
2632 * But don't allow a space in the path, so that this works: | |
2633 * "/usr/bin/csh --rcfile ~/.cshrc" | |
2634 * But don't do that for Windows, it's common to have a space in the path. | |
22742
f7f2d73ff85e
patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents:
22685
diff
changeset
|
2635 * Returns NULL when out of memory. |
5867 | 2636 */ |
2637 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2638 get_isolated_shell_name(void) |
5867 | 2639 { |
2640 char_u *p; | |
2641 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15814
diff
changeset
|
2642 #ifdef MSWIN |
5867 | 2643 p = gettail(p_sh); |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20788
diff
changeset
|
2644 p = vim_strnsave(p, skiptowhite(p) - p); |
5867 | 2645 #else |
2646 p = skiptowhite(p_sh); | |
2647 if (*p == NUL) | |
2648 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2649 // No white space, use the tail. |
5867 | 2650 p = vim_strsave(gettail(p_sh)); |
2651 } | |
2652 else | |
2653 { | |
2654 char_u *p1, *p2; | |
2655 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2656 // Find the last path separator before the space. |
5867 | 2657 p1 = p_sh; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2658 for (p2 = p_sh; p2 < p; MB_PTR_ADV(p2)) |
5867 | 2659 if (vim_ispathsep(*p2)) |
2660 p1 = p2 + 1; | |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20788
diff
changeset
|
2661 p = vim_strnsave(p1, p - p1); |
5867 | 2662 } |
2663 #endif | |
2664 return p; | |
2665 } | |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2666 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2667 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2668 * Check if the "://" of a URL is at the pointer, return URL_SLASH. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2669 * Also check for ":\\", which MS Internet Explorer accepts, return |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2670 * URL_BACKSLASH. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2671 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2672 int |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2673 path_is_url(char_u *p) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2674 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2675 if (STRNCMP(p, "://", (size_t)3) == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2676 return URL_SLASH; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2677 else if (STRNCMP(p, ":\\\\", (size_t)3) == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2678 return URL_BACKSLASH; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2679 return 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2680 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2681 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2682 /* |
25234
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2683 * Check if "fname" starts with "name://" or "name:\\". |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2684 * Return URL_SLASH for "name://", URL_BACKSLASH for "name:\\". |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2685 * Return zero otherwise. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2686 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2687 int |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2688 path_with_url(char_u *fname) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2689 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2690 char_u *p; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2691 |
25234
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2692 // We accept alphabetic characters and a dash in scheme part. |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2693 // RFC 3986 allows for more, but it increases the risk of matching |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2694 // non-URL text. |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2695 |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2696 // first character must be alpha |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2697 if (!isalpha(*fname)) |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2698 return 0; |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2699 |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2700 // check body: alpha or dash |
26034
9b2c6cea573c
patch 8.2.3551: checking first character of url twice
Bram Moolenaar <Bram@vim.org>
parents:
25864
diff
changeset
|
2701 for (p = fname + 1; (isalpha(*p) || (*p == '-')); ++p) |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2702 ; |
25234
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2703 |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2704 // check last char is not a dash |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2705 if (p[-1] == '-') |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2706 return 0; |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2707 |
34a6db7af738
patch 8.2.3153: URLs with a dash in the scheme are not recognized
Bram Moolenaar <Bram@vim.org>
parents:
25206
diff
changeset
|
2708 // "://" or ":\\" must follow |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2709 return path_is_url(p); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2710 } |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2711 |
26155
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2712 #if defined(FEAT_EVAL) || defined(PROTO) |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2713 /* |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2714 * Return the dictionary of v:event. |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2715 * Save and clear the value in case it already has items. |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2716 */ |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2717 dict_T * |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2718 get_v_event(save_v_event_T *sve) |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2719 { |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2720 dict_T *v_event = get_vim_var_dict(VV_EVENT); |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2721 |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2722 if (v_event->dv_hashtab.ht_used > 0) |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2723 { |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2724 // recursive use of v:event, save, make empty and restore later |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2725 sve->sve_did_save = TRUE; |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2726 sve->sve_hashtab = v_event->dv_hashtab; |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2727 hash_init(&v_event->dv_hashtab); |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2728 } |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2729 else |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2730 sve->sve_did_save = FALSE; |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2731 return v_event; |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2732 } |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2733 |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2734 void |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2735 restore_v_event(dict_T *v_event, save_v_event_T *sve) |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2736 { |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2737 dict_free_contents(v_event); |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2738 if (sve->sve_did_save) |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2739 v_event->dv_hashtab = sve->sve_hashtab; |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2740 else |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2741 hash_init(&v_event->dv_hashtab); |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2742 } |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2743 #endif |
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2744 |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2745 /* |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2746 * Fires a ModeChanged autocmd event if appropriate. |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2747 */ |
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2748 void |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2749 may_trigger_modechanged() |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2750 { |
26155
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2751 #ifdef FEAT_EVAL |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2752 dict_T *v_event; |
26155
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2753 save_v_event_T save_v_event; |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2754 char_u curr_mode[MODE_MAX_LENGTH]; |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2755 char_u pattern_buf[2 * MODE_MAX_LENGTH]; |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2756 |
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2757 if (!has_modechanged()) |
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2758 return; |
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2759 |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2760 get_mode(curr_mode); |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2761 if (STRCMP(curr_mode, last_mode) == 0) |
26042
6b39ab99e367
patch 8.2.3555: ModeChanged is not triggered on every mode change
Bram Moolenaar <Bram@vim.org>
parents:
26034
diff
changeset
|
2762 return; |
6b39ab99e367
patch 8.2.3555: ModeChanged is not triggered on every mode change
Bram Moolenaar <Bram@vim.org>
parents:
26034
diff
changeset
|
2763 |
26155
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2764 v_event = get_v_event(&save_v_event); |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2765 (void)dict_add_string(v_event, "new_mode", curr_mode); |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2766 (void)dict_add_string(v_event, "old_mode", last_mode); |
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2767 dict_set_items_ro(v_event); |
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2768 |
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2769 // concatenate modes in format "old_mode:new_mode" |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2770 vim_snprintf((char *)pattern_buf, sizeof(pattern_buf), "%s:%s", last_mode, |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2771 curr_mode); |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2772 |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2773 apply_autocmds(EVENT_MODECHANGED, pattern_buf, NULL, FALSE, curbuf); |
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27426
diff
changeset
|
2774 STRCPY(last_mode, curr_mode); |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2775 |
26155
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
2776 restore_v_event(v_event, &save_v_event); |
25790
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2777 #endif |
16a7d1154be8
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Bram Moolenaar <Bram@vim.org>
parents:
25398
diff
changeset
|
2778 } |