annotate src/misc1.c @ 25790:16a7d1154be8 v8.2.3430

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