Mercurial > vim
annotate src/misc1.c @ 19747:1f4dc8bc8b24
Added tag v8.2.0429 for changeset 1da2fb80b512db615159a74b3fbf634847c2fbcc
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 22 Mar 2020 20:15:04 +0100 |
parents | 41a1ea967a97 |
children | aadd1cae2ff5 |
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_p_wrap) | |
368 return 1; | |
369 | |
370 if (wp->w_width == 0) | |
371 return 1; | |
372 | |
373 #ifdef FEAT_FOLDING | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
374 // A folded lines is handled just like an empty line. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
375 // NOTE: Caller must handle lines that are MAYBE folded. |
7 | 376 if (lineFolded(wp, lnum) == TRUE) |
377 return 1; | |
378 #endif | |
379 | |
380 lines = plines_win_nofold(wp, lnum); | |
381 if (winheight > 0 && lines > wp->w_height) | |
382 return (int)wp->w_height; | |
383 return lines; | |
384 } | |
385 | |
386 /* | |
387 * Return number of window lines physical line "lnum" will occupy in window | |
388 * "wp". Does not care about folding, 'wrap' or 'diff'. | |
389 */ | |
390 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
391 plines_win_nofold(win_T *wp, linenr_T lnum) |
7 | 392 { |
393 char_u *s; | |
394 long col; | |
395 int width; | |
396 | |
397 s = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
398 if (*s == NUL) // empty line |
7 | 399 return 1; |
400 col = win_linetabsize(wp, s, (colnr_T)MAXCOL); | |
401 | |
402 /* | |
403 * If list mode is on, then the '$' at the end of the line may take up one | |
404 * extra column. | |
405 */ | |
406 if (wp->w_p_list && lcs_eol != NUL) | |
407 col += 1; | |
408 | |
409 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2162
diff
changeset
|
410 * Add column offset for 'number', 'relativenumber' and 'foldcolumn'. |
7 | 411 */ |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
412 width = wp->w_width - win_col_off(wp); |
7 | 413 if (width <= 0) |
414 return 32000; | |
415 if (col <= width) | |
416 return 1; | |
417 col -= width; | |
418 width += win_col_off2(wp); | |
419 return (col + (width - 1)) / width + 1; | |
420 } | |
421 | |
422 /* | |
423 * Like plines_win(), but only reports the number of physical screen lines | |
424 * used from the start of the line to the given column number. | |
425 */ | |
426 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
427 plines_win_col(win_T *wp, linenr_T lnum, long column) |
7 | 428 { |
429 long col; | |
430 char_u *s; | |
431 int lines = 0; | |
432 int width; | |
5995 | 433 char_u *line; |
7 | 434 |
435 #ifdef FEAT_DIFF | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
436 // 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
|
437 // is one line anyway. |
7 | 438 lines = diff_check_fill(wp, lnum); |
439 #endif | |
440 | |
441 if (!wp->w_p_wrap) | |
442 return lines + 1; | |
443 | |
444 if (wp->w_width == 0) | |
445 return lines + 1; | |
446 | |
5995 | 447 line = s = ml_get_buf(wp->w_buffer, lnum, FALSE); |
7 | 448 |
449 col = 0; | |
450 while (*s != NUL && --column >= 0) | |
451 { | |
5995 | 452 col += win_lbr_chartabsize(wp, line, s, (colnr_T)col, NULL); |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
453 MB_PTR_ADV(s); |
7 | 454 } |
455 | |
456 /* | |
457 * If *s is a TAB, and the TAB is not displayed as ^I, and we're not in | |
458 * INSERT mode, then col must be adjusted so that it represents the last | |
459 * screen position of the TAB. This only fixes an error when the TAB wraps | |
460 * from one screen line to the next (when 'columns' is not a multiple of | |
461 * 'ts') -- webb. | |
462 */ | |
463 if (*s == TAB && (State & NORMAL) && (!wp->w_p_list || lcs_tab1)) | |
5995 | 464 col += win_lbr_chartabsize(wp, line, s, (colnr_T)col, NULL) - 1; |
7 | 465 |
466 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2162
diff
changeset
|
467 * Add column offset for 'number', 'relativenumber', 'foldcolumn', etc. |
7 | 468 */ |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
469 width = wp->w_width - win_col_off(wp); |
1023 | 470 if (width <= 0) |
471 return 9999; | |
472 | |
473 lines += 1; | |
474 if (col > width) | |
475 lines += (col - width) / (width + win_col_off2(wp)) + 1; | |
476 return lines; | |
7 | 477 } |
478 | |
479 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
480 plines_m_win(win_T *wp, linenr_T first, linenr_T last) |
7 | 481 { |
482 int count = 0; | |
483 | |
484 while (first <= last) | |
485 { | |
486 #ifdef FEAT_FOLDING | |
487 int x; | |
488 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
489 // 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
|
490 // that are maybe folded. |
7 | 491 x = foldedCount(wp, first, NULL); |
492 if (x > 0) | |
493 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
494 ++count; // count 1 for "+-- folded" line |
7 | 495 first += x; |
496 } | |
497 else | |
498 #endif | |
499 { | |
500 #ifdef FEAT_DIFF | |
501 if (first == wp->w_topline) | |
502 count += plines_win_nofill(wp, first, TRUE) + wp->w_topfill; | |
503 else | |
504 #endif | |
505 count += plines_win(wp, first, TRUE); | |
506 ++first; | |
507 } | |
508 } | |
509 return (count); | |
510 } | |
511 | |
512 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
513 gchar_pos(pos_T *pos) |
7 | 514 { |
13082
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
515 char_u *ptr; |
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
516 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
517 // 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
|
518 if (pos->col == MAXCOL) |
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
519 return NUL; |
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
520 ptr = ml_get_pos(pos); |
7 | 521 if (has_mbyte) |
522 return (*mb_ptr2char)(ptr); | |
523 return (int)*ptr; | |
524 } | |
525 | |
526 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
527 gchar_cursor(void) |
7 | 528 { |
529 if (has_mbyte) | |
530 return (*mb_ptr2char)(ml_get_cursor()); | |
531 return (int)*ml_get_cursor(); | |
532 } | |
533 | |
534 /* | |
535 * Write a character at the current cursor position. | |
536 * It is directly written into the block. | |
537 */ | |
538 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
539 pchar_cursor(int c) |
7 | 540 { |
541 *(ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE) | |
542 + curwin->w_cursor.col) = c; | |
543 } | |
544 | |
545 /* | |
546 * Skip to next part of an option argument: Skip space and comma. | |
547 */ | |
548 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
549 skip_to_option_part(char_u *p) |
7 | 550 { |
551 if (*p == ',') | |
552 ++p; | |
553 while (*p == ' ') | |
554 ++p; | |
555 return p; | |
556 } | |
557 | |
558 /* | |
559 * check_status: called when the status bars for the buffer 'buf' | |
560 * need to be updated | |
561 */ | |
562 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
563 check_status(buf_T *buf) |
7 | 564 { |
565 win_T *wp; | |
566 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
567 FOR_ALL_WINDOWS(wp) |
7 | 568 if (wp->w_buffer == buf && wp->w_status_height) |
569 { | |
570 wp->w_redr_status = TRUE; | |
571 if (must_redraw < VALID) | |
572 must_redraw = VALID; | |
573 } | |
574 } | |
575 | |
576 /* | |
577 * Ask for a reply from the user, a 'y' or a 'n'. | |
578 * No other characters are accepted, the message is repeated until a valid | |
579 * reply is entered or CTRL-C is hit. | |
580 * If direct is TRUE, don't use vgetc() but ui_inchar(), don't get characters | |
581 * from any buffers but directly from the user. | |
582 * | |
583 * return the 'y' or 'n' | |
584 */ | |
585 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
586 ask_yesno(char_u *str, int direct) |
7 | 587 { |
588 int r = ' '; | |
589 int save_State = State; | |
590 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
591 if (exiting) // put terminal in raw mode for this question |
7 | 592 settmode(TMODE_RAW); |
593 ++no_wait_return; | |
594 #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
|
595 dont_scroll = TRUE; // disallow scrolling here |
7 | 596 #endif |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18104
diff
changeset
|
597 State = CONFIRM; // mouse behaves like with :confirm |
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18104
diff
changeset
|
598 setmouse(); // disables mouse for xterm |
7 | 599 ++no_mapping; |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18104
diff
changeset
|
600 ++allow_keys; // no mapping here, but recognize keys |
7 | 601 |
602 while (r != 'y' && r != 'n') | |
603 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
604 // 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
|
605 smsg_attr(HL_ATTR(HLF_R), "%s (y/n)?", str); |
7 | 606 if (direct) |
607 r = get_keystroke(); | |
608 else | |
1474 | 609 r = plain_vgetc(); |
7 | 610 if (r == Ctrl_C || r == ESC) |
611 r = 'n'; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
612 msg_putchar(r); // show what you typed |
7 | 613 out_flush(); |
614 } | |
615 --no_wait_return; | |
616 State = save_State; | |
617 setmouse(); | |
618 --no_mapping; | |
619 --allow_keys; | |
620 | |
621 return r; | |
622 } | |
623 | |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
624 #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
|
625 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
626 /* |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
627 * "mode()" function |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
628 */ |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
629 void |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
630 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
|
631 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
632 char_u buf[4]; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
633 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
634 vim_memset(buf, 0, sizeof(buf)); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
635 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
636 if (time_for_testing == 93784) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
637 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
638 // Testing the two-character code. |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
639 buf[0] = 'x'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
640 buf[1] = '!'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
641 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
642 #ifdef FEAT_TERMINAL |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
643 else if (term_use_loop()) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
644 buf[0] = 't'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
645 #endif |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
646 else if (VIsual_active) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
647 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
648 if (VIsual_select) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
649 buf[0] = VIsual_mode + 's' - 'v'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
650 else |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
651 buf[0] = VIsual_mode; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
652 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
653 else if (State == HITRETURN || State == ASKMORE || State == SETWSIZE |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
654 || State == CONFIRM) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
655 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
656 buf[0] = 'r'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
657 if (State == ASKMORE) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
658 buf[1] = 'm'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
659 else if (State == CONFIRM) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
660 buf[1] = '?'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
661 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
662 else if (State == EXTERNCMD) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
663 buf[0] = '!'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
664 else if (State & INSERT) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
665 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
666 if (State & VREPLACE_FLAG) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
667 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
668 buf[0] = 'R'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
669 buf[1] = 'v'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
670 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
671 else |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
672 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
673 if (State & REPLACE_FLAG) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
674 buf[0] = 'R'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
675 else |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
676 buf[0] = 'i'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
677 if (ins_compl_active()) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
678 buf[1] = 'c'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
679 else if (ctrl_x_mode_not_defined_yet()) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
680 buf[1] = 'x'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
681 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
682 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
683 else if ((State & CMDLINE) || exmode_active) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
684 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
685 buf[0] = 'c'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
686 if (exmode_active == EXMODE_VIM) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
687 buf[1] = 'v'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
688 else if (exmode_active == EXMODE_NORMAL) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
689 buf[1] = 'e'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
690 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
691 else |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
692 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
693 buf[0] = 'n'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
694 if (finish_op) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
695 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
696 buf[1] = 'o'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
697 // to be able to detect force-linewise/blockwise/characterwise operations |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
698 buf[2] = motion_force; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
699 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
700 else if (restart_edit == 'I' || restart_edit == 'R' |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
701 || restart_edit == 'V') |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
702 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
703 buf[1] = 'i'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
704 buf[2] = restart_edit; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
705 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
706 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
707 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
708 // 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
|
709 // non-empty string. |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
710 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
|
711 buf[1] = NUL; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
712 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
713 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
|
714 rettv->v_type = VAR_STRING; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
715 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
716 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
717 static void |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
718 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
|
719 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
720 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
|
721 ga_append(gap, c); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
722 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
723 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
724 /* |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
725 * "state()" function |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
726 */ |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
727 void |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
728 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
|
729 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
730 garray_T ga; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
731 char_u *include = NULL; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
732 int i; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
733 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
734 ga_init2(&ga, 1, 20); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
735 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
|
736 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
|
737 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
738 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
|
739 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
|
740 if (op_pending()) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
741 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
|
742 if (autocmd_busy) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
743 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
|
744 if (ins_compl_active()) |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
745 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
|
746 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
747 # ifdef FEAT_JOB_CHANNEL |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
748 if (channel_in_blocking_wait()) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
749 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
|
750 # endif |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18104
diff
changeset
|
751 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
|
752 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
|
753 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
|
754 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
|
755 if (msg_scrolled > 0) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
756 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
|
757 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
758 rettv->v_type = VAR_STRING; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
759 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
|
760 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
761 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
762 #endif // FEAT_EVAL |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
763 |
7 | 764 /* |
765 * Get a key stroke directly from the user. | |
766 * Ignores mouse clicks and scrollbar events, except a click for the left | |
767 * button (used at the more prompt). | |
768 * Doesn't use vgetc(), because it syncs undo and eats mapped characters. | |
769 * Disadvantage: typeahead is ignored. | |
770 * Translates the interrupt character for unix to ESC. | |
771 */ | |
772 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
773 get_keystroke(void) |
7 | 774 { |
3328 | 775 char_u *buf = NULL; |
776 int buflen = 150; | |
777 int maxlen; | |
7 | 778 int len = 0; |
779 int n; | |
780 int save_mapped_ctrl_c = mapped_ctrl_c; | |
964 | 781 int waited = 0; |
7 | 782 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
783 mapped_ctrl_c = FALSE; // mappings are not used here |
7 | 784 for (;;) |
785 { | |
786 cursor_on(); | |
787 out_flush(); | |
788 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
789 // 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
|
790 // 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
|
791 // bytes. |
3328 | 792 maxlen = (buflen - 6 - len) / 3; |
793 if (buf == NULL) | |
794 buf = alloc(buflen); | |
795 else if (maxlen < 10) | |
796 { | |
6596 | 797 char_u *t_buf = buf; |
798 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
799 // 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
|
800 // escape sequence. |
3328 | 801 buflen += 100; |
802 buf = vim_realloc(buf, buflen); | |
6596 | 803 if (buf == NULL) |
804 vim_free(t_buf); | |
3328 | 805 maxlen = (buflen - 6 - len) / 3; |
806 } | |
807 if (buf == NULL) | |
808 { | |
809 do_outofmem_msg((long_u)buflen); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
810 return ESC; // panic! |
3328 | 811 } |
812 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
813 // 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
|
814 // terminal code to complete. |
3328 | 815 n = ui_inchar(buf + len, maxlen, len == 0 ? -1L : 100L, 0); |
7 | 816 if (n > 0) |
817 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
818 // 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
|
819 n = fix_input_buffer(buf + len, n); |
7 | 820 len += n; |
964 | 821 waited = 0; |
822 } | |
823 else if (len > 0) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
824 ++waited; // keep track of the waiting time |
964 | 825 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
826 // Incomplete termcode and not timed out yet: get more characters |
3328 | 827 if ((n = check_termcode(1, buf, buflen, &len)) < 0 |
964 | 828 && (!p_ttimeout || waited * 100L < (p_ttm < 0 ? p_tm : p_ttm))) |
7 | 829 continue; |
964 | 830 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
831 if (n == KEYLEN_REMOVED) // key code removed |
2721 | 832 { |
2723 | 833 if (must_redraw != 0 && !need_wait_return && (State & CMDLINE) == 0) |
2721 | 834 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
835 // Redrawing was postponed, do it now. |
2721 | 836 update_screen(0); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
837 setcursor(); // put cursor back where it belongs |
2721 | 838 } |
2672 | 839 continue; |
2721 | 840 } |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
841 if (n > 0) // found a termcode: adjust length |
7 | 842 len = n; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
843 if (len == 0) // nothing typed yet |
7 | 844 continue; |
845 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
846 // Handle modifier and/or special key code. |
7 | 847 n = buf[0]; |
848 if (n == K_SPECIAL) | |
849 { | |
850 n = TO_SPECIAL(buf[1], buf[2]); | |
851 if (buf[1] == KS_MODIFIER | |
852 || n == K_IGNORE | |
4221 | 853 || (is_mouse_key(n) && n != K_LEFTMOUSE) |
854 #ifdef FEAT_GUI | |
7 | 855 || n == K_VER_SCROLLBAR |
856 || n == K_HOR_SCROLLBAR | |
857 #endif | |
858 ) | |
859 { | |
860 if (buf[1] == KS_MODIFIER) | |
861 mod_mask = buf[2]; | |
862 len -= 3; | |
863 if (len > 0) | |
864 mch_memmove(buf, buf + 3, (size_t)len); | |
865 continue; | |
866 } | |
828 | 867 break; |
7 | 868 } |
869 if (has_mbyte) | |
870 { | |
871 if (MB_BYTE2LEN(n) > len) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
872 continue; // more bytes to get |
3328 | 873 buf[len >= buflen ? buflen - 1 : len] = NUL; |
7 | 874 n = (*mb_ptr2char)(buf); |
875 } | |
876 #ifdef UNIX | |
877 if (n == intr_char) | |
878 n = ESC; | |
879 #endif | |
880 break; | |
881 } | |
3328 | 882 vim_free(buf); |
7 | 883 |
884 mapped_ctrl_c = save_mapped_ctrl_c; | |
885 return n; | |
886 } | |
887 | |
888 /* | |
374 | 889 * Get a number from the user. |
890 * When "mouse_used" is not NULL allow using the mouse. | |
7 | 891 */ |
892 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
893 get_number( |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
894 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
|
895 int *mouse_used) |
7 | 896 { |
897 int n = 0; | |
898 int c; | |
810 | 899 int typed = 0; |
7 | 900 |
374 | 901 if (mouse_used != NULL) |
902 *mouse_used = FALSE; | |
903 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
904 // 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
|
905 // zero (as if CR was hit). |
7 | 906 if (msg_silent != 0) |
907 return 0; | |
908 | |
909 #ifdef USE_ON_FLY_SCROLL | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
910 dont_scroll = TRUE; // disallow scrolling here |
7 | 911 #endif |
912 ++no_mapping; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
913 ++allow_keys; // no mapping here, but recognize keys |
7 | 914 for (;;) |
915 { | |
916 windgoto(msg_row, msg_col); | |
917 c = safe_vgetc(); | |
918 if (VIM_ISDIGIT(c)) | |
919 { | |
920 n = n * 10 + c - '0'; | |
921 msg_putchar(c); | |
810 | 922 ++typed; |
7 | 923 } |
924 else if (c == K_DEL || c == K_KDEL || c == K_BS || c == Ctrl_H) | |
925 { | |
810 | 926 if (typed > 0) |
927 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
928 msg_puts("\b \b"); |
810 | 929 --typed; |
930 } | |
7 | 931 n /= 10; |
932 } | |
374 | 933 else if (mouse_used != NULL && c == K_LEFTMOUSE) |
934 { | |
935 *mouse_used = TRUE; | |
936 n = mouse_row + 1; | |
937 break; | |
938 } | |
7 | 939 else if (n == 0 && c == ':' && colon) |
940 { | |
941 stuffcharReadbuff(':'); | |
942 if (!exmode_active) | |
943 cmdline_row = msg_row; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
944 skip_redraw = TRUE; // skip redraw once |
7 | 945 do_redraw = FALSE; |
946 break; | |
947 } | |
948 else if (c == CAR || c == NL || c == Ctrl_C || c == ESC) | |
949 break; | |
950 } | |
951 --no_mapping; | |
952 --allow_keys; | |
953 return n; | |
954 } | |
955 | |
323 | 956 /* |
957 * Ask the user to enter a number. | |
374 | 958 * When "mouse_used" is not NULL allow using the mouse and in that case return |
959 * the line number. | |
323 | 960 */ |
961 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
962 prompt_for_number(int *mouse_used) |
323 | 963 { |
964 int i; | |
344 | 965 int save_cmdline_row; |
966 int save_State; | |
323 | 967 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
968 // When using ":silent" assume that <CR> was entered. |
375 | 969 if (mouse_used != NULL) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
970 msg_puts(_("Type number and <Enter> or click with mouse (empty cancels): ")); |
375 | 971 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
972 msg_puts(_("Type number and <Enter> (empty cancels): ")); |
344 | 973 |
14629
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
974 // 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
|
975 // 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
|
976 // is zero. |
344 | 977 save_cmdline_row = cmdline_row; |
957 | 978 cmdline_row = 0; |
344 | 979 save_State = State; |
14629
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
980 State = CMDLINE; |
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
981 // 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
|
982 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
|
983 |
374 | 984 i = get_number(TRUE, mouse_used); |
985 if (KeyTyped) | |
986 { | |
17018
b1263192461f
patch 8.1.1509: cmdline_row can become negative, causing a crash
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
987 // 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
|
988 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
|
989 cmdline_row = msg_row - 1; |
323 | 990 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
|
991 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
|
992 msg_didout = FALSE; |
323 | 993 } |
344 | 994 else |
995 cmdline_row = save_cmdline_row; | |
996 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
|
997 // 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
|
998 setmouse(); |
344 | 999 |
323 | 1000 return i; |
1001 } | |
1002 | |
7 | 1003 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1004 msgmore(long n) |
7 | 1005 { |
1006 long pn; | |
1007 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1008 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
|
1009 || !messaging()) // 'lazyredraw' set, don't do messages now |
7 | 1010 return; |
1011 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1012 // 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
|
1013 // 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
|
1014 // then "put" reports the last action. |
135 | 1015 if (keep_msg != NULL && !keep_msg_more) |
1016 return; | |
1017 | |
7 | 1018 if (n > 0) |
1019 pn = n; | |
1020 else | |
1021 pn = -n; | |
1022 | |
1023 if (pn > p_report) | |
1024 { | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
1025 if (n > 0) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1026 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
|
1027 NGETTEXT("%ld more line", "%ld more lines", pn), pn); |
7 | 1028 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1029 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
|
1030 NGETTEXT("%ld line less", "%ld fewer lines", pn), pn); |
7 | 1031 if (got_int) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1032 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
|
1033 MSG_BUF_LEN); |
7 | 1034 if (msg(msg_buf)) |
1035 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1036 set_keep_msg((char_u *)msg_buf, 0); |
135 | 1037 keep_msg_more = TRUE; |
7 | 1038 } |
1039 } | |
1040 } | |
1041 | |
1042 /* | |
1043 * flush map and typeahead buffers and give a warning for an error | |
1044 */ | |
1045 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1046 beep_flush(void) |
7 | 1047 { |
1048 if (emsg_silent == 0) | |
1049 { | |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1050 flush_buffers(FLUSH_MINIMAL); |
6949 | 1051 vim_beep(BO_ERROR); |
1052 } | |
1053 } | |
1054 | |
1055 /* | |
1056 * Give a warning for an error. | |
7 | 1057 */ |
1058 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1059 vim_beep( |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1060 unsigned val) // one of the BO_ values, e.g., BO_OPER |
7 | 1061 { |
13272
abaebba89fd4
patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1062 #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
|
1063 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
|
1064 #endif |
abaebba89fd4
patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1065 |
7 | 1066 if (emsg_silent == 0) |
1067 { | |
6949 | 1068 if (!((bo_flags & val) || (bo_flags & BO_ALL))) |
1069 { | |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1070 #ifdef ELAPSED_FUNC |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1071 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
|
1072 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
|
1073 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1074 // 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
|
1075 // would freeze Vim. |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1076 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
|
1077 { |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1078 did_init = TRUE; |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1079 ELAPSED_INIT(start_tv); |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1080 #endif |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1081 if (p_vb |
7 | 1082 #ifdef FEAT_GUI |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1083 // 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
|
1084 // 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
|
1085 && !(gui.in_use && gui.starting) |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1086 #endif |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1087 ) |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1088 { |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1089 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
|
1090 #ifdef FEAT_VTP |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1091 // 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
|
1092 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
|
1093 # 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
|
1094 && (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
|
1095 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1096 ) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1097 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1098 redraw_later(CLEAR); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1099 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
|
1100 redrawcmd(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1101 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1102 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1103 } |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1104 else |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1105 out_char(BELL); |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1106 #ifdef ELAPSED_FUNC |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1107 } |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1108 #endif |
7 | 1109 } |
169 | 1110 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1111 // 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
|
1112 // 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
|
1113 // comes from. |
169 | 1114 if (vim_strchr(p_debug, 'e') != NULL) |
1115 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1116 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
|
1117 msg_attr(_("Beep!"), HL_ATTR(HLF_W)); |
169 | 1118 } |
7 | 1119 } |
1120 } | |
1121 | |
1122 /* | |
1123 * To get the "real" home directory: | |
1124 * - get value of $HOME | |
1125 * For Unix: | |
1126 * - go to that directory | |
1127 * - do mch_dirname() to get the real name of that directory. | |
1128 * This also works with mounts and links. | |
1129 * 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
|
1130 * For Windows: |
c1be7c8bb602
patch 8.1.0534: MS-Windows installer uses different $HOME than Vim
Bram Moolenaar <Bram@vim.org>
parents:
14909
diff
changeset
|
1131 * This code is duplicated in init_homedir() in dosinst.c. Keep in sync! |
7 | 1132 */ |
1133 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1134 init_homedir(void) |
7 | 1135 { |
1136 char_u *var; | |
1137 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1138 // 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
|
1139 VIM_CLEAR(homedir); |
170 | 1140 |
7 | 1141 #ifdef VMS |
1142 var = mch_getenv((char_u *)"SYS$LOGIN"); | |
1143 #else | |
1144 var = mch_getenv((char_u *)"HOME"); | |
1145 #endif | |
1146 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15814
diff
changeset
|
1147 #ifdef MSWIN |
7 | 1148 /* |
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
|
1149 * 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
|
1150 * 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
|
1151 * 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
|
1152 * 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
|
1153 */ |
12269
d2373927d76d
patch 8.0.1014: old compiler doesn't know uint32_t
Christian Brabandt <cb@256bit.org>
parents:
12265
diff
changeset
|
1154 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
|
1155 { |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1156 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
|
1157 |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1158 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
|
1159 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
|
1160 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
|
1161 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
|
1162 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
|
1163 && 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
|
1164 { |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1165 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
|
1166 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
|
1167 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
|
1168 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1169 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1170 |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1171 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
|
1172 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
|
1173 |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1174 /* |
7 | 1175 * Weird but true: $HOME may contain an indirect reference to another |
1176 * variable, esp. "%USERPROFILE%". Happens when $USERPROFILE isn't set | |
1177 * when $HOME is being set. | |
1178 */ | |
1179 if (var != NULL && *var == '%') | |
1180 { | |
1181 char_u *p; | |
1182 char_u *exp; | |
1183 | |
1184 p = vim_strchr(var + 1, '%'); | |
1185 if (p != NULL) | |
1186 { | |
419 | 1187 vim_strncpy(NameBuff, var + 1, p - (var + 1)); |
7 | 1188 exp = mch_getenv(NameBuff); |
1189 if (exp != NULL && *exp != NUL | |
1190 && STRLEN(exp) + STRLEN(p) < MAXPATHL) | |
1191 { | |
274 | 1192 vim_snprintf((char *)NameBuff, MAXPATHL, "%s%s", exp, p + 1); |
7 | 1193 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
|
1194 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1195 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1196 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1197 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1198 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
|
1199 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
|
1200 |
170 | 1201 if (enc_utf8 && var != NULL) |
1202 { | |
1203 int len; | |
2786 | 1204 char_u *pp = NULL; |
170 | 1205 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1206 // 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
|
1207 // not done, because they would fail for non-ASCII characters. |
835 | 1208 acp_to_enc(var, (int)STRLEN(var), &pp, &len); |
170 | 1209 if (pp != NULL) |
1210 { | |
1211 homedir = pp; | |
1212 return; | |
1213 } | |
1214 } | |
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
|
1215 |
7 | 1216 /* |
1217 * Default home dir is C:/ | |
1218 * Best assumption we can make in such a situation. | |
1219 */ | |
1220 if (var == NULL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
1221 var = (char_u *)"C:/"; |
7 | 1222 #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
|
1223 |
7 | 1224 if (var != NULL) |
1225 { | |
1226 #ifdef UNIX | |
1227 /* | |
1228 * Change to the directory and get the actual path. This resolves | |
1229 * links. Don't do it when we can't return. | |
1230 */ | |
1231 if (mch_dirname(NameBuff, MAXPATHL) == OK | |
1232 && mch_chdir((char *)NameBuff) == 0) | |
1233 { | |
1234 if (!mch_chdir((char *)var) && mch_dirname(IObuff, IOSIZE) == OK) | |
1235 var = IObuff; | |
1236 if (mch_chdir((char *)NameBuff) != 0) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15420
diff
changeset
|
1237 emsg(_(e_prev_dir)); |
7 | 1238 } |
1239 #endif | |
1240 homedir = vim_strsave(var); | |
1241 } | |
1242 } | |
1243 | |
359 | 1244 #if defined(EXITFREE) || defined(PROTO) |
1245 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1246 free_homedir(void) |
359 | 1247 { |
1248 vim_free(homedir); | |
1249 } | |
3744 | 1250 |
1251 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1252 free_users(void) |
3744 | 1253 { |
1254 ga_clear_strings(&ga_users); | |
1255 } | |
359 | 1256 #endif |
1257 | |
7 | 1258 /* |
1408 | 1259 * Call expand_env() and store the result in an allocated string. |
1260 * This is not very memory efficient, this expects the result to be freed | |
1261 * again soon. | |
1262 */ | |
1263 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1264 expand_env_save(char_u *src) |
1408 | 1265 { |
1266 return expand_env_save_opt(src, FALSE); | |
1267 } | |
1268 | |
1269 /* | |
1270 * Idem, but when "one" is TRUE handle the string as one file name, only | |
1271 * expand "~" at the start. | |
1272 */ | |
1273 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1274 expand_env_save_opt(char_u *src, int one) |
1408 | 1275 { |
1276 char_u *p; | |
1277 | |
1278 p = alloc(MAXPATHL); | |
1279 if (p != NULL) | |
1280 expand_env_esc(src, p, MAXPATHL, FALSE, one, NULL); | |
1281 return p; | |
1282 } | |
1283 | |
1284 /* | |
7 | 1285 * Expand environment variable with path name. |
1286 * "~/" is also expanded, using $HOME. For Unix "~user/" is expanded. | |
1408 | 1287 * Skips over "\ ", "\~" and "\$" (not for Win32 though). |
7 | 1288 * If anything fails no expansion is done and dst equals src. |
1289 */ | |
1290 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1291 expand_env( |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1292 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
|
1293 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
|
1294 int dstlen) // maximum length of the result |
7 | 1295 { |
1408 | 1296 expand_env_esc(src, dst, dstlen, FALSE, FALSE, NULL); |
7 | 1297 } |
1298 | |
1299 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1300 expand_env_esc( |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1301 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
|
1302 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
|
1303 int dstlen, // maximum length of the result |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1304 int esc, // escape spaces in expanded variables |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1305 int one, // "srcp" is one file name |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1306 char_u *startstr) // start again after this (can be NULL) |
374 | 1307 { |
1308 char_u *src; | |
7 | 1309 char_u *tail; |
1310 int c; | |
1311 char_u *var; | |
1312 int copy_char; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1313 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
|
1314 int at_start = TRUE; // at start of a name |
374 | 1315 int startstr_len = 0; |
1316 | |
1317 if (startstr != NULL) | |
835 | 1318 startstr_len = (int)STRLEN(startstr); |
374 | 1319 |
1320 src = skipwhite(srcp); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1321 --dstlen; // leave one char space for "\," |
7 | 1322 while (*src && dstlen > 0) |
1323 { | |
7038
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1324 #ifdef FEAT_EVAL |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1325 // Skip over `=expr`. |
7038
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1326 if (src[0] == '`' && src[1] == '=') |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1327 { |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1328 size_t len; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1329 |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1330 var = src; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1331 src += 2; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1332 (void)skip_expr(&src); |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1333 if (*src == '`') |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1334 ++src; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1335 len = src - var; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1336 if (len > (size_t)dstlen) |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1337 len = dstlen; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1338 vim_strncpy(dst, var, len); |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1339 dst += len; |
7066
094c8ccdc279
commit https://github.com/vim/vim/commit/5df1ed2de3fa9dcace996b9a0a4c9b3cea79cf1e
Christian Brabandt <cb@256bit.org>
parents:
7038
diff
changeset
|
1340 dstlen -= (int)len; |
7038
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1341 continue; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1342 } |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1343 #endif |
7 | 1344 copy_char = TRUE; |
22 | 1345 if ((*src == '$' |
1346 #ifdef VMS | |
1347 && at_start | |
1348 #endif | |
1349 ) | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8163
diff
changeset
|
1350 #if defined(MSWIN) |
7 | 1351 || *src == '%' |
1352 #endif | |
1353 || (*src == '~' && at_start)) | |
1354 { | |
1355 mustfree = FALSE; | |
1356 | |
1357 /* | |
1358 * The variable name is copied into dst temporarily, because it may | |
1359 * be a string in read-only memory and a NUL needs to be appended. | |
1360 */ | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1361 if (*src != '~') // environment var |
7 | 1362 { |
1363 tail = src + 1; | |
1364 var = dst; | |
1365 c = dstlen - 1; | |
1366 | |
1367 #ifdef UNIX | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1368 // Unix has ${var-name} type environment vars |
7 | 1369 if (*tail == '{' && !vim_isIDc('{')) |
1370 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1371 tail++; // ignore '{' |
7 | 1372 while (c-- > 0 && *tail && *tail != '}') |
1373 *var++ = *tail++; | |
1374 } | |
1375 else | |
1376 #endif | |
1377 { | |
1378 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
|
1379 #if defined(MSWIN) |
7 | 1380 || (*src == '%' && *tail != '%') |
1381 #endif | |
1382 )) | |
1383 *var++ = *tail++; | |
1384 } | |
1385 | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8163
diff
changeset
|
1386 #if defined(MSWIN) || defined(UNIX) |
7 | 1387 # ifdef UNIX |
1388 if (src[1] == '{' && *tail != '}') | |
1389 # else | |
1390 if (*src == '%' && *tail != '%') | |
1391 # endif | |
1392 var = NULL; | |
1393 else | |
1394 { | |
1395 # ifdef UNIX | |
1396 if (src[1] == '{') | |
1397 # else | |
1398 if (*src == '%') | |
1399 #endif | |
1400 ++tail; | |
1401 #endif | |
1402 *var = NUL; | |
1403 var = vim_getenv(dst, &mustfree); | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8163
diff
changeset
|
1404 #if defined(MSWIN) || defined(UNIX) |
7 | 1405 } |
1406 #endif | |
1407 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1408 // home directory |
7 | 1409 else if ( src[1] == NUL |
1410 || vim_ispathsep(src[1]) | |
1411 || vim_strchr((char_u *)" ,\t\n", src[1]) != NULL) | |
1412 { | |
1413 var = homedir; | |
1414 tail = src + 1; | |
1415 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1416 else // user directory |
7 | 1417 { |
1418 #if defined(UNIX) || (defined(VMS) && defined(USER_HOME)) | |
1419 /* | |
1420 * Copy ~user to dst[], so we can put a NUL after it. | |
1421 */ | |
1422 tail = src; | |
1423 var = dst; | |
1424 c = dstlen - 1; | |
1425 while ( c-- > 0 | |
1426 && *tail | |
1427 && vim_isfilec(*tail) | |
1428 && !vim_ispathsep(*tail)) | |
1429 *var++ = *tail++; | |
1430 *var = NUL; | |
1431 # ifdef UNIX | |
1432 /* | |
1433 * If the system supports getpwnam(), use it. | |
1434 * Otherwise, or if getpwnam() fails, the shell is used to | |
1435 * expand ~user. This is slower and may fail if the shell | |
1436 * does not support ~user (old versions of /bin/sh). | |
1437 */ | |
1438 # if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H) | |
1439 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1440 // 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
|
1441 // 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
|
1442 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
|
1443 ? 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
|
1444 |
141fe140976c
patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
1445 var = (pw == NULL) ? NULL : (char_u *)pw->pw_dir; |
7 | 1446 } |
1447 if (var == NULL) | |
1448 # endif | |
1449 { | |
1450 expand_T xpc; | |
1451 | |
1452 ExpandInit(&xpc); | |
1453 xpc.xp_context = EXPAND_FILES; | |
1454 var = ExpandOne(&xpc, dst, NULL, | |
1455 WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE); | |
1456 mustfree = TRUE; | |
1457 } | |
1458 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1459 # else // !UNIX, thus VMS |
7 | 1460 /* |
1461 * USER_HOME is a comma-separated list of | |
1462 * directories to search for the user account in. | |
1463 */ | |
1464 { | |
1465 char_u test[MAXPATHL], paths[MAXPATHL]; | |
1466 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
|
1467 stat_T st; |
7 | 1468 |
1469 STRCPY(paths, USER_HOME); | |
1470 next_path = paths; | |
1471 while (*next_path) | |
1472 { | |
1473 for (path = next_path; *next_path && *next_path != ','; | |
1474 next_path++); | |
1475 if (*next_path) | |
1476 *next_path++ = NUL; | |
1477 STRCPY(test, path); | |
1478 STRCAT(test, "/"); | |
1479 STRCAT(test, dst + 1); | |
1480 if (mch_stat(test, &st) == 0) | |
1481 { | |
1482 var = alloc(STRLEN(test) + 1); | |
1483 STRCPY(var, test); | |
1484 mustfree = TRUE; | |
1485 break; | |
1486 } | |
1487 } | |
1488 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1489 # endif // UNIX |
7 | 1490 #else |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1491 // cannot expand user's home directory, so don't try |
7 | 1492 var = NULL; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1493 tail = (char_u *)""; // for gcc |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1494 #endif // UNIX || VMS |
7 | 1495 } |
1496 | |
1497 #ifdef BACKSLASH_IN_FILENAME | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1498 // 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
|
1499 // Can't use slash_adjust(), p_ssl may be set temporarily. |
7 | 1500 if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL) |
1501 { | |
1502 char_u *p = vim_strsave(var); | |
1503 | |
1504 if (p != NULL) | |
1505 { | |
1506 if (mustfree) | |
1507 vim_free(var); | |
1508 var = p; | |
1509 mustfree = TRUE; | |
1510 forward_slash(var); | |
1511 } | |
1512 } | |
1513 #endif | |
1514 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1515 // 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
|
1516 // Required for ":e ~/tt" when $HOME includes a space. |
7 | 1517 if (esc && var != NULL && vim_strpbrk(var, (char_u *)" \t") != NULL) |
1518 { | |
1519 char_u *p = vim_strsave_escaped(var, (char_u *)" \t"); | |
1520 | |
1521 if (p != NULL) | |
1522 { | |
1523 if (mustfree) | |
1524 vim_free(var); | |
1525 var = p; | |
1526 mustfree = TRUE; | |
1527 } | |
1528 } | |
1529 | |
1530 if (var != NULL && *var != NUL | |
1531 && (STRLEN(var) + STRLEN(tail) + 1 < (unsigned)dstlen)) | |
1532 { | |
1533 STRCPY(dst, var); | |
1534 dstlen -= (int)STRLEN(var); | |
835 | 1535 c = (int)STRLEN(var); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1536 // 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
|
1537 // with it, skip a character |
39 | 1538 if (*var != NUL && after_pathsep(dst, dst + c) |
7 | 1539 #if defined(BACKSLASH_IN_FILENAME) || defined(AMIGA) |
1540 && dst[-1] != ':' | |
1541 #endif | |
1542 && vim_ispathsep(*tail)) | |
1543 ++tail; | |
39 | 1544 dst += c; |
7 | 1545 src = tail; |
1546 copy_char = FALSE; | |
1547 } | |
1548 if (mustfree) | |
1549 vim_free(var); | |
1550 } | |
1551 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1552 if (copy_char) // copy at least one char |
7 | 1553 { |
1554 /* | |
1224 | 1555 * Recognize the start of a new name, for '~'. |
1408 | 1556 * Don't do this when "one" is TRUE, to avoid expanding "~" in |
1557 * ":edit foo ~ foo". | |
7 | 1558 */ |
1559 at_start = FALSE; | |
1560 if (src[0] == '\\' && src[1] != NUL) | |
1561 { | |
1562 *dst++ = *src++; | |
1563 --dstlen; | |
1564 } | |
1408 | 1565 else if ((src[0] == ' ' || src[0] == ',') && !one) |
7 | 1566 at_start = TRUE; |
12005
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1567 if (dstlen > 0) |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1568 { |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1569 *dst++ = *src++; |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1570 --dstlen; |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1571 |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1572 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
|
1573 && 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
|
1574 startstr_len) == 0) |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1575 at_start = TRUE; |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1576 } |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1577 } |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
1578 |
7 | 1579 } |
1580 *dst = NUL; | |
1581 } | |
1582 | |
1583 /* | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1584 * 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
|
1585 * 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
|
1586 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1587 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
|
1588 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
|
1589 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1590 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
|
1591 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
|
1592 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1593 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
|
1594 && 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
|
1595 && (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
|
1596 return newend; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1597 return pend; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1598 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1599 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1600 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1601 * 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
|
1602 * 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
|
1603 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1604 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
|
1605 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
|
1606 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1607 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
|
1608 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1609 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
|
1610 return NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1611 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
|
1612 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
|
1613 return p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1614 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
|
1615 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
|
1616 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
|
1617 return p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1618 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
|
1619 return NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1620 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1621 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1622 /* |
7 | 1623 * Vim's version of getenv(). |
1624 * Special handling of $HOME, $VIM and $VIMRUNTIME. | |
196 | 1625 * Also does ACP to 'enc' conversion for Win32. |
2786 | 1626 * "mustfree" is set to TRUE when returned is allocated, it must be |
1627 * initialized to FALSE by the caller. | |
7 | 1628 */ |
1629 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1630 vim_getenv(char_u *name, int *mustfree) |
7 | 1631 { |
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
|
1632 char_u *p = NULL; |
7 | 1633 char_u *pend; |
1634 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
|
1635 #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
|
1636 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
|
1637 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1638 // use "C:/" when $HOME is not set |
7 | 1639 if (STRCMP(name, "HOME") == 0) |
1640 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
|
1641 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1642 // 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
|
1643 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
|
1644 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
|
1645 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
|
1646 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1647 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
|
1648 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
|
1649 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1650 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
|
1651 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
|
1652 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1653 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
|
1654 { |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1655 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
|
1656 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
|
1657 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
|
1658 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1659 *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
|
1660 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
|
1661 } |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1662 #else |
7 | 1663 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
|
1664 if (p != NULL && *p == NUL) // empty is the same as not set |
7 | 1665 p = NULL; |
1666 | |
1667 if (p != NULL) | |
1668 return p; | |
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
|
1669 #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
|
1670 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1671 // handling $VIMRUNTIME and $VIM is below, bail out if it's another name. |
7 | 1672 vimruntime = (STRCMP(name, "VIMRUNTIME") == 0); |
1673 if (!vimruntime && STRCMP(name, "VIM") != 0) | |
19526
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
1674 #if defined(__HAIKU__) |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
1675 // special handling for user settings directory... |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
1676 if (STRCMP(name, "BE_USER_SETTINGS") == 0) |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
1677 { |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
1678 static char userSettingsPath[MAXPATHL] = {0}; |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
1679 |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
1680 if (B_OK == find_directory(B_USER_SETTINGS_DIRECTORY, 0, |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
1681 false, userSettingsPath, MAXPATHL)) |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
1682 return userSettingsPath; |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
1683 } |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
1684 else |
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19396
diff
changeset
|
1685 #endif |
7 | 1686 return NULL; |
1687 | |
1688 /* | |
1689 * When expanding $VIMRUNTIME fails, try using $VIM/vim<version> or $VIM. | |
1690 * Don't do this when default_vimruntime_dir is non-empty. | |
1691 */ | |
1692 if (vimruntime | |
1693 #ifdef HAVE_PATHDEF | |
1694 && *default_vimruntime_dir == NUL | |
1695 #endif | |
1696 ) | |
1697 { | |
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
|
1698 #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
|
1699 // 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
|
1700 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
|
1701 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
|
1702 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
|
1703 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
|
1704 { |
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 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
|
1706 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
|
1707 { |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1708 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
|
1709 *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
|
1710 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
|
1711 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
|
1712 } |
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 } |
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 #else |
7 | 1715 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
|
1716 if (p != NULL && *p == NUL) // empty is the same as not set |
7 | 1717 p = NULL; |
1718 if (p != NULL) | |
1719 { | |
1720 p = vim_version_dir(p); | |
1721 if (p != NULL) | |
1722 *mustfree = TRUE; | |
1723 else | |
1724 p = mch_getenv((char_u *)"VIM"); | |
1725 } | |
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
|
1726 #endif |
7 | 1727 } |
1728 | |
1729 /* | |
1730 * When expanding $VIM or $VIMRUNTIME fails, try using: | |
1731 * - the directory name from 'helpfile' (unless it contains '$') | |
1732 * - the executable name from argv[0] | |
1733 */ | |
1734 if (p == NULL) | |
1735 { | |
1736 if (p_hf != NULL && vim_strchr(p_hf, '$') == NULL) | |
1737 p = p_hf; | |
1738 #ifdef USE_EXE_NAME | |
1739 /* | |
1740 * Use the name of the executable, obtained from argv[0]. | |
1741 */ | |
1742 else | |
1743 p = exe_name; | |
1744 #endif | |
1745 if (p != NULL) | |
1746 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1747 // remove the file name |
7 | 1748 pend = gettail(p); |
1749 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1750 // remove "doc/" from 'helpfile', if present |
7 | 1751 if (p == p_hf) |
1752 pend = remove_tail(p, pend, (char_u *)"doc"); | |
1753 | |
1754 #ifdef USE_EXE_NAME | |
1755 # ifdef MACOS_X | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1756 // remove "MacOS" from exe_name and add "Resources/vim" |
7 | 1757 if (p == exe_name) |
1758 { | |
1759 char_u *pend1; | |
768 | 1760 char_u *pnew; |
1761 | |
1762 pend1 = remove_tail(p, pend, (char_u *)"MacOS"); | |
1763 if (pend1 != pend) | |
1764 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
1765 pnew = alloc(pend1 - p + 15); |
768 | 1766 if (pnew != NULL) |
1767 { | |
1768 STRNCPY(pnew, p, (pend1 - p)); | |
1769 STRCPY(pnew + (pend1 - p), "Resources/vim"); | |
1770 p = pnew; | |
1771 pend = p + STRLEN(p); | |
1772 } | |
1773 } | |
7 | 1774 } |
1775 # endif | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1776 // remove "src/" from exe_name, if present |
7 | 1777 if (p == exe_name) |
1778 pend = remove_tail(p, pend, (char_u *)"src"); | |
1779 #endif | |
1780 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1781 // for $VIM, remove "runtime/" or "vim54/", if present |
7 | 1782 if (!vimruntime) |
1783 { | |
1784 pend = remove_tail(p, pend, (char_u *)RUNTIME_DIRNAME); | |
1785 pend = remove_tail(p, pend, (char_u *)VIM_VERSION_NODOT); | |
1786 } | |
1787 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1788 // remove trailing path separator |
39 | 1789 if (pend > p && after_pathsep(p, pend)) |
7 | 1790 --pend; |
1791 | |
768 | 1792 #ifdef MACOS_X |
1793 if (p == exe_name || p == p_hf) | |
1794 #endif | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1795 // check that the result is a directory name |
768 | 1796 p = vim_strnsave(p, (int)(pend - p)); |
7 | 1797 |
1798 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
|
1799 VIM_CLEAR(p); |
7 | 1800 else |
1801 { | |
1802 #ifdef USE_EXE_NAME | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1803 // may add "/vim54" or "/runtime" if it exists |
7 | 1804 if (vimruntime && (pend = vim_version_dir(p)) != NULL) |
1805 { | |
1806 vim_free(p); | |
1807 p = pend; | |
1808 } | |
1809 #endif | |
1810 *mustfree = TRUE; | |
1811 } | |
1812 } | |
1813 } | |
1814 | |
1815 #ifdef HAVE_PATHDEF | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1816 // 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
|
1817 // default_vimruntime_dir |
7 | 1818 if (p == NULL) |
1819 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1820 // Only use default_vimruntime_dir when it is not empty |
7 | 1821 if (vimruntime && *default_vimruntime_dir != NUL) |
1822 { | |
1823 p = default_vimruntime_dir; | |
1824 *mustfree = FALSE; | |
1825 } | |
1826 else if (*default_vim_dir != NUL) | |
1827 { | |
1828 if (vimruntime && (p = vim_version_dir(default_vim_dir)) != NULL) | |
1829 *mustfree = TRUE; | |
1830 else | |
1831 { | |
1832 p = default_vim_dir; | |
1833 *mustfree = FALSE; | |
1834 } | |
1835 } | |
1836 } | |
1837 #endif | |
1838 | |
1839 /* | |
1840 * Set the environment variable, so that the new value can be found fast | |
1841 * next time, and others can also use it (e.g. Perl). | |
1842 */ | |
1843 if (p != NULL) | |
1844 { | |
1845 if (vimruntime) | |
1846 { | |
1847 vim_setenv((char_u *)"VIMRUNTIME", p); | |
1848 didset_vimruntime = TRUE; | |
1849 } | |
1850 else | |
1851 { | |
1852 vim_setenv((char_u *)"VIM", p); | |
1853 didset_vim = TRUE; | |
1854 } | |
1855 } | |
1856 return p; | |
1857 } | |
1858 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1859 #if defined(FEAT_EVAL) || defined(PROTO) |
13923
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1860 void |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1861 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
|
1862 { |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1863 #ifdef HAVE_UNSETENV |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1864 unsetenv((char *)var); |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1865 #else |
13942
a039c93f5ff7
patch 8.0.1841: HP-UX does not have setenv()
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
1866 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
|
1867 #endif |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1868 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1869 #endif |
13923
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1870 |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1871 |
7 | 1872 /* |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1873 * 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
|
1874 */ |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1875 void |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1876 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
|
1877 { |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1878 vim_setenv(name, val); |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1879 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
|
1880 init_homedir(); |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1881 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
|
1882 didset_vim = FALSE; |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1883 else if (didset_vimruntime |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1884 && STRICMP(name, "VIMRUNTIME") == 0) |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1885 didset_vimruntime = FALSE; |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1886 } |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1887 |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1888 /* |
7 | 1889 * Our portable version of setenv. |
1890 */ | |
1891 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1892 vim_setenv(char_u *name, char_u *val) |
7 | 1893 { |
1894 #ifdef HAVE_SETENV | |
1895 mch_setenv((char *)name, (char *)val, 1); | |
1896 #else | |
1897 char_u *envbuf; | |
1898 | |
1899 /* | |
1900 * Putenv does not copy the string, it has to remain | |
1901 * valid. The allocated memory will never be freed. | |
1902 */ | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
1903 envbuf = alloc(STRLEN(name) + STRLEN(val) + 2); |
7 | 1904 if (envbuf != NULL) |
1905 { | |
1906 sprintf((char *)envbuf, "%s=%s", name, val); | |
1907 putenv((char *)envbuf); | |
1908 } | |
1909 #endif | |
3382 | 1910 #ifdef FEAT_GETTEXT |
1911 /* | |
1912 * When setting $VIMRUNTIME adjust the directory to find message | |
1913 * translations to $VIMRUNTIME/lang. | |
1914 */ | |
1915 if (*val != NUL && STRICMP(name, "VIMRUNTIME") == 0) | |
1916 { | |
1917 char_u *buf = concat_str(val, (char_u *)"/lang"); | |
1918 | |
1919 if (buf != NULL) | |
1920 { | |
1921 bindtextdomain(VIMPACKAGE, (char *)buf); | |
1922 vim_free(buf); | |
1923 } | |
1924 } | |
1925 #endif | |
7 | 1926 } |
1927 | |
1928 /* | |
1929 * Function given to ExpandGeneric() to obtain an environment variable name. | |
1930 */ | |
1931 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1932 get_env_name( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1933 expand_T *xp UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1934 int idx) |
7 | 1935 { |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1936 # if defined(AMIGA) |
7 | 1937 /* |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1938 * No environ[] on the Amiga. |
7 | 1939 */ |
1940 return NULL; | |
1941 # else | |
1942 # ifndef __WIN32__ | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
1943 // Borland C++ 5.2 has this in a header file. |
7 | 1944 extern char **environ; |
1945 # endif | |
17 | 1946 # define ENVNAMELEN 100 |
1947 static char_u name[ENVNAMELEN]; | |
7 | 1948 char_u *str; |
1949 int n; | |
1950 | |
1951 str = (char_u *)environ[idx]; | |
1952 if (str == NULL) | |
1953 return NULL; | |
1954 | |
17 | 1955 for (n = 0; n < ENVNAMELEN - 1; ++n) |
7 | 1956 { |
1957 if (str[n] == '=' || str[n] == NUL) | |
1958 break; | |
1959 name[n] = str[n]; | |
1960 } | |
1961 name[n] = NUL; | |
1962 return name; | |
1963 # endif | |
1964 } | |
3744 | 1965 |
1966 /* | |
14698
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
1967 * 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
|
1968 * 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
|
1969 */ |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
1970 static void |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
1971 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
|
1972 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
1973 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
|
1974 ? vim_strsave(user) : user; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
1975 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
1976 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
|
1977 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
1978 if (need_copy) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
1979 vim_free(user); |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
1980 return; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
1981 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
1982 ((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
|
1983 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
1984 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
1985 /* |
3744 | 1986 * Find all user names for user completion. |
1987 * Done only once and then cached. | |
1988 */ | |
1989 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1990 init_users(void) |
4938
bcb84438bb5b
updated for version 7.3.1214
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1991 { |
3744 | 1992 static int lazy_init_done = FALSE; |
1993 | |
1994 if (lazy_init_done) | |
1995 return; | |
1996 | |
1997 lazy_init_done = TRUE; | |
1998 ga_init2(&ga_users, sizeof(char_u *), 20); | |
1999 | |
2000 # if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H) | |
2001 { | |
2002 struct passwd* pw; | |
2003 | |
2004 setpwent(); | |
2005 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
|
2006 add_user((char_u *)pw->pw_name, TRUE); |
3744 | 2007 endpwent(); |
2008 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15814
diff
changeset
|
2009 # 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
|
2010 { |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2011 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
|
2012 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
|
2013 |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2014 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
|
2015 &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
|
2016 { |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2017 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
|
2018 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
|
2019 |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2020 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
|
2021 } |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2022 } |
3744 | 2023 # endif |
14698
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2024 # if defined(HAVE_GETPWNAM) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2025 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2026 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
|
2027 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2028 // 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
|
2029 // 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
|
2030 // 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
|
2031 // 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
|
2032 // 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
|
2033 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2034 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
|
2035 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2036 int i; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2037 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2038 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
|
2039 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2040 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
|
2041 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2042 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
|
2043 break; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2044 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2045 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2046 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
|
2047 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2048 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
|
2049 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2050 if (pw != NULL) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2051 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
|
2052 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2053 } |
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 # endif |
3744 | 2056 } |
2057 | |
2058 /* | |
2059 * Function given to ExpandGeneric() to obtain an user names. | |
2060 */ | |
2061 char_u* | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2062 get_users(expand_T *xp UNUSED, int idx) |
3744 | 2063 { |
2064 init_users(); | |
2065 if (idx < ga_users.ga_len) | |
2066 return ((char_u **)ga_users.ga_data)[idx]; | |
2067 return NULL; | |
2068 } | |
2069 | |
2070 /* | |
2071 * Check whether name matches a user name. Return: | |
2072 * 0 if name does not match any user name. | |
2073 * 1 if name partially matches the beginning of a user name. | |
2074 * 2 is name fully matches a user name. | |
2075 */ | |
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
|
2076 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
|
2077 match_user(char_u *name) |
3744 | 2078 { |
2079 int i; | |
2080 int n = (int)STRLEN(name); | |
2081 int result = 0; | |
2082 | |
2083 init_users(); | |
2084 for (i = 0; i < ga_users.ga_len; i++) | |
2085 { | |
2086 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
|
2087 return 2; // full match |
3744 | 2088 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
|
2089 result = 1; // partial match |
3744 | 2090 } |
2091 return result; | |
2092 } | |
7 | 2093 |
2094 /* | |
115 | 2095 * Concatenate two strings and return the result in allocated memory. |
2096 * Returns NULL when out of memory. | |
2097 */ | |
2098 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2099 concat_str(char_u *str1, char_u *str2) |
115 | 2100 { |
2101 char_u *dest; | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
2102 size_t l = str1 == NULL ? 0 : STRLEN(str1); |
115 | 2103 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
2104 dest = alloc(l + (str2 == NULL ? 0 : STRLEN(str2)) + 1L); |
115 | 2105 if (dest != NULL) |
2106 { | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
2107 if (str1 == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
2108 *dest = NUL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
2109 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
2110 STRCPY(dest, str1); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
2111 if (str2 != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
2112 STRCPY(dest + l, str2); |
115 | 2113 } |
2114 return dest; | |
2115 } | |
2116 | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2117 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2118 prepare_to_exit(void) |
7 | 2119 { |
39 | 2120 #if defined(SIGHUP) && defined(SIG_IGN) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2121 // 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
|
2122 // 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
|
2123 // problems. |
36 | 2124 signal(SIGHUP, SIG_IGN); |
2125 #endif | |
2126 | |
7 | 2127 #ifdef FEAT_GUI |
2128 if (gui.in_use) | |
2129 { | |
2130 gui.dying = TRUE; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2131 out_trash(); // trash any pending output |
7 | 2132 } |
2133 else | |
2134 #endif | |
2135 { | |
2136 windgoto((int)Rows - 1, 0); | |
2137 | |
2138 /* | |
2139 * Switch terminal mode back now, so messages end up on the "normal" | |
2140 * screen (if there are two screens). | |
2141 */ | |
2142 settmode(TMODE_COOK); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10180
diff
changeset
|
2143 stoptermcap(); |
7 | 2144 out_flush(); |
2145 } | |
2146 } | |
2147 | |
2148 /* | |
2149 * Preserve files and exit. | |
2150 * When called IObuff must contain a message. | |
5338 | 2151 * NOTE: This may be called from deathtrap() in a signal handler, avoid unsafe |
2152 * functions, such as allocating memory. | |
7 | 2153 */ |
2154 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2155 preserve_exit(void) |
7 | 2156 { |
2157 buf_T *buf; | |
2158 | |
2159 prepare_to_exit(); | |
2160 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2161 // 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
|
2162 // recursively when free() was invoked with a bad pointer. |
625 | 2163 really_exiting = TRUE; |
2164 | |
7 | 2165 out_str(IObuff); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2166 screen_start(); // don't know where cursor is now |
7 | 2167 out_flush(); |
2168 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2169 ml_close_notmod(); // close all not-modified buffers |
7 | 2170 |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
2171 FOR_ALL_BUFFERS(buf) |
7 | 2172 { |
2173 if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) | |
2174 { | |
5338 | 2175 OUT_STR("Vim: preserving files...\n"); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2176 screen_start(); // don't know where cursor is now |
7 | 2177 out_flush(); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2178 ml_sync_all(FALSE, FALSE); // preserve all swap files |
7 | 2179 break; |
2180 } | |
2181 } | |
2182 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2183 ml_close_all(FALSE); // close all memfiles, without deleting |
7 | 2184 |
5338 | 2185 OUT_STR("Vim: Finished.\n"); |
7 | 2186 |
2187 getout(1); | |
2188 } | |
2189 | |
2190 /* | |
2191 * Check for CTRL-C pressed, but only once in a while. | |
2192 * Should be used instead of ui_breakcheck() for functions that check for | |
2193 * each line in the file. Calling ui_breakcheck() each time takes too much | |
2194 * time, because it can be a system call. | |
2195 */ | |
2196 | |
2197 #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
|
2198 # define BREAKCHECK_SKIP 1000 |
7 | 2199 #endif |
2200 | |
2201 static int breakcheck_count = 0; | |
2202 | |
2203 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2204 line_breakcheck(void) |
7 | 2205 { |
2206 if (++breakcheck_count >= BREAKCHECK_SKIP) | |
2207 { | |
2208 breakcheck_count = 0; | |
2209 ui_breakcheck(); | |
2210 } | |
2211 } | |
2212 | |
2213 /* | |
2214 * Like line_breakcheck() but check 10 times less often. | |
2215 */ | |
2216 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2217 fast_breakcheck(void) |
7 | 2218 { |
2219 if (++breakcheck_count >= BREAKCHECK_SKIP * 10) | |
2220 { | |
2221 breakcheck_count = 0; | |
2222 ui_breakcheck(); | |
2223 } | |
2224 } | |
2225 | |
19728
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2226 /* |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2227 * 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
|
2228 */ |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2229 void |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2230 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
|
2231 { |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2232 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
|
2233 { |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2234 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
|
2235 ui_breakcheck(); |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2236 } |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2237 } |
41a1ea967a97
patch 8.2.0420: Vim9: cannot interrupt a loop with CTRL-C
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
2238 |
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
|
2239 #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
|
2240 || (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
|
2241 || defined(PROTO) |
7 | 2242 |
2243 #ifndef SEEK_SET | |
2244 # define SEEK_SET 0 | |
2245 #endif | |
2246 #ifndef SEEK_END | |
2247 # define SEEK_END 2 | |
2248 #endif | |
2249 | |
2250 /* | |
2251 * Get the stdout of an external command. | |
5808 | 2252 * If "ret_len" is NULL replace NUL characters with NL. When "ret_len" is not |
2253 * NULL store the length there. | |
7 | 2254 * Returns an allocated string, or NULL for error. |
2255 */ | |
2256 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2257 get_cmd_output( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2258 char_u *cmd, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2259 char_u *infile, // optional input file name |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2260 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
|
2261 int *ret_len) |
7 | 2262 { |
2263 char_u *tempname; | |
2264 char_u *command; | |
2265 char_u *buffer = NULL; | |
2266 int len; | |
2267 int i = 0; | |
2268 FILE *fd; | |
2269 | |
2270 if (check_restricted() || check_secure()) | |
2271 return NULL; | |
2272 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2273 // get a name for the temp file |
6721 | 2274 if ((tempname = vim_tempname('o', FALSE)) == NULL) |
7 | 2275 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15420
diff
changeset
|
2276 emsg(_(e_notmp)); |
7 | 2277 return NULL; |
2278 } | |
2279 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2280 // Add the redirection stuff |
24 | 2281 command = make_filter_cmd(cmd, infile, tempname); |
7 | 2282 if (command == NULL) |
2283 goto done; | |
2284 | |
2285 /* | |
2286 * Call the shell to execute the command (errors are ignored). | |
2287 * Don't check timestamps here. | |
2288 */ | |
2289 ++no_check_timestamps; | |
2290 call_shell(command, SHELL_DOOUT | SHELL_EXPAND | flags); | |
2291 --no_check_timestamps; | |
2292 | |
2293 vim_free(command); | |
2294 | |
2295 /* | |
2296 * read the names from the file into memory | |
2297 */ | |
2298 # ifdef VMS | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2299 // created temporary file is not always readable as binary |
7 | 2300 fd = mch_fopen((char *)tempname, "r"); |
2301 # else | |
2302 fd = mch_fopen((char *)tempname, READBIN); | |
2303 # endif | |
2304 | |
2305 if (fd == NULL) | |
2306 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15420
diff
changeset
|
2307 semsg(_(e_notopen), tempname); |
7 | 2308 goto done; |
2309 } | |
2310 | |
2311 fseek(fd, 0L, SEEK_END); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2312 len = ftell(fd); // get size of temp file |
7 | 2313 fseek(fd, 0L, SEEK_SET); |
2314 | |
2315 buffer = alloc(len + 1); | |
2316 if (buffer != NULL) | |
2317 i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd); | |
2318 fclose(fd); | |
2319 mch_remove(tempname); | |
2320 if (buffer == NULL) | |
2321 goto done; | |
2322 #ifdef VMS | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2323 len = i; // VMS doesn't give us what we asked for... |
7 | 2324 #endif |
2325 if (i != len) | |
2326 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15420
diff
changeset
|
2327 semsg(_(e_notread), tempname); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
2328 VIM_CLEAR(buffer); |
7 | 2329 } |
5808 | 2330 else if (ret_len == NULL) |
5271
25f67b62afd8
updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2331 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2332 // 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
|
2333 for (i = 0; i < len; ++i) |
5275
3ddec3d25bd1
updated for version 7.4b.014
Bram Moolenaar <bram@vim.org>
parents:
5271
diff
changeset
|
2334 if (buffer[i] == NUL) |
3ddec3d25bd1
updated for version 7.4b.014
Bram Moolenaar <bram@vim.org>
parents:
5271
diff
changeset
|
2335 buffer[i] = 1; |
5271
25f67b62afd8
updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2336 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2337 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
|
2338 } |
5808 | 2339 else |
2340 *ret_len = len; | |
7 | 2341 |
2342 done: | |
2343 vim_free(tempname); | |
2344 return buffer; | |
2345 } | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2346 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2347 # 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
|
2348 |
18051
d1e77015f60b
patch 8.1.2021: some global functions can be local to the file
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
2349 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
|
2350 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
|
2351 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
|
2352 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
|
2353 int retlist) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2354 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2355 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
|
2356 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
|
2357 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
|
2358 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
|
2359 FILE *fd; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2360 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
|
2361 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
|
2362 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2363 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
|
2364 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
|
2365 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
|
2366 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2367 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2368 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
|
2369 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2370 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2371 * 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
|
2372 * command. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2373 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2374 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
|
2375 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2376 emsg(_(e_notmp)); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2377 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2378 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2379 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2380 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
|
2381 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
|
2382 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2383 semsg(_(e_notopen), infile); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2384 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2385 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2386 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
|
2387 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2388 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
|
2389 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
|
2390 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2391 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
|
2392 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
|
2393 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2394 semsg(_(e_nobufnr), 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
|
2395 fclose(fd); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2396 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2397 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2398 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2399 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
|
2400 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2401 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
|
2402 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
|
2403 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2404 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2405 break; |
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 (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
|
2408 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2409 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2410 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2411 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2412 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2413 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2414 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
|
2415 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2416 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
|
2417 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2418 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2419 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2420 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2421 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
|
2422 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
|
2423 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2424 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
|
2425 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
|
2426 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2427 fclose(fd); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2428 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
|
2429 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2430 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
|
2431 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
|
2432 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2433 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2434 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
|
2435 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2436 if (err) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2437 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2438 emsg(_("E677: Error writing temp file")); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2439 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2440 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2441 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2442 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2443 // 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
|
2444 // 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
|
2445 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
|
2446 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
|
2447 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2448 if (retlist) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2449 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2450 int len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2451 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
|
2452 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
|
2453 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
|
2454 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
|
2455 int i; |
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 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
|
2458 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
|
2459 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2460 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2461 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
|
2462 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
|
2463 goto errret; |
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 (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
|
2466 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2467 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
|
2468 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
|
2469 ++i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2470 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
|
2471 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2472 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
|
2473 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
|
2474 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2475 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2476 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
|
2477 *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
|
2478 *p = NUL; |
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 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
|
2481 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
|
2482 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2483 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
|
2484 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2485 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2486 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
|
2487 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
|
2488 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
|
2489 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
|
2490 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2491 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2492 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
|
2493 list = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2494 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2495 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2496 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2497 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
|
2498 #ifdef USE_CRNL |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2499 // 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
|
2500 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
|
2501 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2502 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
|
2503 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2504 d = res; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2505 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
|
2506 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2507 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
|
2508 ++s; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2509 *d++ = *s; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2510 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2511 *d = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2512 } |
7 | 2513 #endif |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2514 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
|
2515 res = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2516 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2517 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2518 errret: |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2519 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
|
2520 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2521 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
|
2522 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
|
2523 } |
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 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
|
2526 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
|
2527 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
|
2528 } |
7 | 2529 |
2530 /* | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2531 * "system()" function |
7 | 2532 */ |
2533 void | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2534 f_system(typval_T *argvars, typval_T *rettv) |
7 | 2535 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2536 get_cmd_output_as_rettv(argvars, rettv, FALSE); |
7 | 2537 } |
2538 | |
2539 /* | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2540 * "systemlist()" function |
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 void |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2543 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
|
2544 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2545 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
|
2546 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2547 # 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
|
2548 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2549 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2550 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2551 /* |
2302
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
2552 * Return TRUE when need to go to Insert mode because of 'insertmode'. |
7 | 2553 * Don't do this when still processing a command or a mapping. |
2554 * Don't do this when inside a ":normal" command. | |
2555 */ | |
2556 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2557 goto_im(void) |
7 | 2558 { |
2559 return (p_im && stuff_empty() && typebuf_typed()); | |
2560 } | |
5867 | 2561 |
2562 /* | |
5911 | 2563 * Returns the isolated name of the shell in allocated memory: |
5867 | 2564 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f". |
2565 * - Remove any argument. E.g., "csh -f" -> "csh". | |
2566 * But don't allow a space in the path, so that this works: | |
2567 * "/usr/bin/csh --rcfile ~/.cshrc" | |
2568 * But don't do that for Windows, it's common to have a space in the path. | |
2569 */ | |
2570 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2571 get_isolated_shell_name(void) |
5867 | 2572 { |
2573 char_u *p; | |
2574 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15814
diff
changeset
|
2575 #ifdef MSWIN |
5867 | 2576 p = gettail(p_sh); |
2577 p = vim_strnsave(p, (int)(skiptowhite(p) - p)); | |
2578 #else | |
2579 p = skiptowhite(p_sh); | |
2580 if (*p == NUL) | |
2581 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2582 // No white space, use the tail. |
5867 | 2583 p = vim_strsave(gettail(p_sh)); |
2584 } | |
2585 else | |
2586 { | |
2587 char_u *p1, *p2; | |
2588 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18528
diff
changeset
|
2589 // Find the last path separator before the space. |
5867 | 2590 p1 = p_sh; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2591 for (p2 = p_sh; p2 < p; MB_PTR_ADV(p2)) |
5867 | 2592 if (vim_ispathsep(*p2)) |
2593 p1 = p2 + 1; | |
2594 p = vim_strnsave(p1, (int)(p - p1)); | |
2595 } | |
2596 #endif | |
2597 return p; | |
2598 } | |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2599 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2600 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2601 * 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
|
2602 * 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
|
2603 * URL_BACKSLASH. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2604 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2605 int |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2606 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
|
2607 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2608 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
|
2609 return URL_SLASH; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2610 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
|
2611 return URL_BACKSLASH; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2612 return 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2613 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2614 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2615 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2616 * Check if "fname" starts with "name://". Return URL_SLASH if it does. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2617 * Return URL_BACKSLASH for "name:\\". |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2618 * Return zero otherwise. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2619 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2620 int |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2621 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
|
2622 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2623 char_u *p; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2624 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2625 for (p = fname; isalpha(*p); ++p) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2626 ; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
2627 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
|
2628 } |