annotate src/misc1.c @ 17956:1f6d5f9ddeb0 v8.1.1974

patch 8.1.1974: Coverity warns for using pointer as array Commit: https://github.com/vim/vim/commit/1f3165bc34c6c608584a73f13faec27dd7c7e2fa Author: Bram Moolenaar <Bram@vim.org> Date: Wed Sep 4 13:21:26 2019 +0200 patch 8.1.1974: Coverity warns for using pointer as array Problem: Coverity warns for using pointer as array. Solution: Call var2fpos() directly instead of using f_line().
author Bram Moolenaar <Bram@vim.org>
date Wed, 04 Sep 2019 13:30:03 +0200
parents 6582dda76821
children 46f95606b9ec
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
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
17 #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
18 # 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
19 #endif
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
20
7803
37c929c4a073 commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents: 7641
diff changeset
21 static char_u *vim_version_dir(char_u *vimdir);
37c929c4a073 commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents: 7641
diff changeset
22 static char_u *remove_tail(char_u *p, char_u *pend, char_u *name);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
15814
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
24 #define URL_SLASH 1 /* path_is_url() has found "://" */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
25 #define URL_BACKSLASH 2 /* path_is_url() has found ":\\" */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
26
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
27 // 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
28 static garray_T ga_users;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
29
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 * Count the size (in window cells) of the indent in the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
34 get_indent(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 {
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
36 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
37 return get_indent_str_vtab(ml_get_curline(), (int)curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
38 curbuf->b_p_vts_array, FALSE);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
39 #else
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
40 return get_indent_str(ml_get_curline(), (int)curbuf->b_p_ts, FALSE);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
41 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 * Count the size (in window cells) of the indent in line "lnum".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
48 get_indent_lnum(linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 {
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
50 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
51 return get_indent_str_vtab(ml_get(lnum), (int)curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
52 curbuf->b_p_vts_array, FALSE);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
53 #else
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
54 return get_indent_str(ml_get(lnum), (int)curbuf->b_p_ts, FALSE);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
55 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 #if defined(FEAT_FOLDING) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 * Count the size (in window cells) of the indent in line "lnum" of buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 * "buf".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
64 get_indent_buf(buf_T *buf, linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 {
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
66 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
67 return get_indent_str_vtab(ml_get_buf(buf, lnum, FALSE),
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
68 (int)curbuf->b_p_ts, buf->b_p_vts_array, FALSE);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
69 #else
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
70 return get_indent_str(ml_get_buf(buf, lnum, FALSE), (int)buf->b_p_ts, FALSE);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
71 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 * count the size (in window cells) of the indent in line "ptr", with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 * 'tabstop' at "ts"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 */
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 135
diff changeset
79 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
80 get_indent_str(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
81 char_u *ptr,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
82 int ts,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
83 int list) /* if TRUE, count only screen size for tabs */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 for ( ; *ptr; ++ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 {
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
89 if (*ptr == TAB)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
90 {
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
91 if (!list || lcs_tab1) /* count a tab for what it is worth */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
92 count += ts - (count % ts);
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
93 else
6174
96a4fa8e530c updated for version 7.4.423
Bram Moolenaar <bram@vim.org>
parents: 6114
diff changeset
94 /* In list mode, when tab is not set, count screen char width
96a4fa8e530c updated for version 7.4.423
Bram Moolenaar <bram@vim.org>
parents: 6114
diff changeset
95 * for Tab, displays: ^I */
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
96 count += ptr2cells(ptr);
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
97 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 else if (*ptr == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 ++count; /* count a space for one */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 }
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 135
diff changeset
103 return count;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
106 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
107 /*
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
108 * Count the size (in window cells) of the indent in line "ptr", using
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
109 * variable tabstops.
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
110 * if "list" is TRUE, count only screen size for tabs.
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
111 */
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
112 int
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
113 get_indent_str_vtab(char_u *ptr, int ts, int *vts, int list)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
114 {
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
115 int count = 0;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
116
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
117 for ( ; *ptr; ++ptr)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
118 {
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
119 if (*ptr == TAB) /* count a tab for what it is worth */
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
120 {
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
121 if (!list || lcs_tab1)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
122 count += tabstop_padding(count, ts, vts);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
123 else
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
124 /* In list mode, when tab is not set, count screen char width
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
125 * for Tab, displays: ^I */
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
126 count += ptr2cells(ptr);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
127 }
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
128 else if (*ptr == ' ')
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
129 ++count; /* count a space for one */
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
130 else
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
131 break;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
132 }
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
133 return count;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
134 }
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
135 #endif
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
136
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 * Set the indent of the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 * Leaves the cursor on the first non-blank in the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 * Caller must take care of undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 * "flags":
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 * SIN_CHANGED: call changed_bytes() if the line was changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 * SIN_INSERT: insert the indent in front of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 * SIN_UNDO: save line for undo before changing it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 * Returns TRUE if the line was changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
148 set_indent(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
149 int size, /* measured in spaces */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
150 int flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 char_u *newline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 char_u *oldline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 int todo;
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
157 int ind_len; /* measured in characters */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 int line_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 int doit = FALSE;
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
160 int ind_done = 0; /* measured in spaces */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
161 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
162 int ind_col = 0;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
163 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 int tab_pad;
217
89114a6baf3c updated for version 7.0061
vimboss
parents: 196
diff changeset
165 int retval = FALSE;
1359
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
166 int orig_char_len = -1; /* number of initial whitespace chars when
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
167 'et' and 'pi' are both set */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 * First check if there is anything to do and compute the number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 * characters needed for the indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 todo = size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 ind_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 p = oldline = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 /* Calculate the buffer size for the new indent, and check to see if it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 * isn't already set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
180 /* if 'expandtab' isn't set: use TABs; if both 'expandtab' and
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
181 * 'preserveindent' are set count the number of characters at the
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
182 * beginning of the line to be copied */
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
183 if (!curbuf->b_p_et || (!(flags & SIN_INSERT) && curbuf->b_p_pi))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 /* If 'preserveindent' is set then reuse as much as possible of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 * the existing indent structure for the new indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 if (!(flags & SIN_INSERT) && curbuf->b_p_pi)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 ind_done = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 /* count as many characters as we can use */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
192 while (todo > 0 && VIM_ISWHITE(*p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 if (*p == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 {
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
196 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
197 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
198 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
199 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 tab_pad = (int)curbuf->b_p_ts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 - (ind_done % (int)curbuf->b_p_ts);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
202 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 /* stop if this tab will overshoot the target */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 if (todo < tab_pad)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 ind_done += tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 ++ind_done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
219 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
220 /* These diverge from this point. */
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
221 ind_col = ind_done;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
222 #endif
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
223 /* Set initial number of whitespace chars to copy if we are
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
224 * preserving indent but expandtab is set */
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
225 if (curbuf->b_p_et)
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
226 orig_char_len = ind_len;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
227
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 /* Fill to next tabstop with a tab, if possible */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
229 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
230 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
231 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
232 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
234 #endif
1359
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
235 if (todo >= tab_pad && orig_char_len == -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 doit = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 /* ind_done += tab_pad; */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
241 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
242 ind_col += tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
243 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 /* count tabs required for indent */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
248 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
249 for (;;)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
250 {
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
251 tab_pad = tabstop_padding(ind_col, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
252 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
253 if (todo < tab_pad)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
254 break;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
255 if (*p != TAB)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
256 doit = TRUE;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
257 else
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
258 ++p;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
259 todo -= tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
260 ++ind_len;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
261 ind_col += tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
262 }
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
263 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 while (todo >= (int)curbuf->b_p_ts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 if (*p != TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 doit = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 todo -= (int)curbuf->b_p_ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 /* ind_done += (int)curbuf->b_p_ts; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 }
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
274 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 /* count spaces required for indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 while (todo > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 if (*p != ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 doit = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 /* ++ind_done; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 /* Return if the indent is OK already. */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
289 if (!doit && !VIM_ISWHITE(*p) && !(flags & SIN_INSERT))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 /* Allocate memory for the new line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 if (flags & SIN_INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 p = oldline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 p = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 line_len = (int)STRLEN(p) + 1;
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
298
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
299 /* If 'preserveindent' and 'expandtab' are both set keep the original
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
300 * characters and allocate accordingly. We will fill the rest with spaces
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
301 * after the if (!curbuf->b_p_et) below. */
1359
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
302 if (orig_char_len != -1)
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
303 {
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
304 newline = alloc(orig_char_len + size - ind_done + line_len);
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
305 if (newline == NULL)
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
306 return FALSE;
1359
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
307 todo = size - ind_done;
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
308 ind_len = orig_char_len + todo; /* Set total length of indent in
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
309 * characters, which may have been
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
310 * undercounted until now */
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
311 p = oldline;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
312 s = newline;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
313 while (orig_char_len > 0)
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
314 {
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
315 *s++ = *p++;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
316 orig_char_len--;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
317 }
1474
276244befa5b updated for version 7.1-189
vimboss
parents: 1470
diff changeset
318
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
319 /* Skip over any additional white space (useful when newindent is less
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
320 * than old) */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
321 while (VIM_ISWHITE(*p))
1474
276244befa5b updated for version 7.1-189
vimboss
parents: 1470
diff changeset
322 ++p;
1348
17a83c0532e8 updated for version 7.1-062
vimboss
parents: 1341
diff changeset
323
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
324 }
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
325 else
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
326 {
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
327 todo = size;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
328 newline = alloc(ind_len + line_len);
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
329 if (newline == NULL)
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
330 return FALSE;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
331 s = newline;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
332 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 /* Put the characters in the new line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 /* if 'expandtab' isn't set: use TABs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 if (!curbuf->b_p_et)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 /* If 'preserveindent' is set then reuse as much as possible of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 * the existing indent structure for the new indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 if (!(flags & SIN_INSERT) && curbuf->b_p_pi)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 p = oldline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 ind_done = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
345 while (todo > 0 && VIM_ISWHITE(*p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 if (*p == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 {
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
349 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
350 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
351 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
352 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 tab_pad = (int)curbuf->b_p_ts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 - (ind_done % (int)curbuf->b_p_ts);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
355 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 /* stop if this tab will overshoot the target */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 if (todo < tab_pad)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 ind_done += tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 ++ind_done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 *s++ = *p++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 /* Fill to next tabstop with a tab, if possible */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
371 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
372 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
373 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
374 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
376 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 if (todo >= tab_pad)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 *s++ = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 todo -= tab_pad;
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
381 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
382 ind_done += tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
383 #endif
7
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 p = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
389 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
390 for (;;)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
391 {
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
392 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
393 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
394 if (todo < tab_pad)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
395 break;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
396 *s++ = TAB;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
397 todo -= tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
398 ind_done += tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
399 }
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
400 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 while (todo >= (int)curbuf->b_p_ts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 *s++ = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 todo -= (int)curbuf->b_p_ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 }
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
406 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 while (todo > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 *s++ = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 mch_memmove(s, p, (size_t)line_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414
15398
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
415 // Replace the line (unless undo fails).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 if (!(flags & SIN_UNDO) || u_savesub(curwin->w_cursor.lnum) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 ml_replace(curwin->w_cursor.lnum, newline, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 if (flags & SIN_CHANGED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 changed_bytes(curwin->w_cursor.lnum, 0);
15398
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
421
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
422 // Correct saved cursor position if it is in this line.
5403
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
423 if (saved_cursor.lnum == curwin->w_cursor.lnum)
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
424 {
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
425 if (saved_cursor.col >= (colnr_T)(p - oldline))
15398
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
426 // cursor was after the indent, adjust for the number of
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
427 // bytes added/removed
5403
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
428 saved_cursor.col += ind_len - (colnr_T)(p - oldline);
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
429 else if (saved_cursor.col >= (colnr_T)(s - newline))
15398
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
430 // cursor was in the indent, and is now after it, put it back
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
431 // at the start of the indent (replacing spaces with TAB)
5403
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
432 saved_cursor.col = (colnr_T)(s - newline);
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
433 }
15398
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
434 #ifdef FEAT_TEXT_PROP
16682
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16632
diff changeset
435 {
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16632
diff changeset
436 int added = ind_len - (colnr_T)(p - oldline);
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16632
diff changeset
437
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16632
diff changeset
438 // When increasing indent this behaves like spaces were inserted at
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16632
diff changeset
439 // the old indent, when decreasing indent it behaves like spaces
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16632
diff changeset
440 // were deleted at the new indent.
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16632
diff changeset
441 adjust_prop_columns(curwin->w_cursor.lnum,
16714
ba592f30c082 patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
442 (colnr_T)(added > 0 ? (p - oldline) : ind_len), added, 0);
16682
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16632
diff changeset
443 }
15398
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
444 #endif
217
89114a6baf3c updated for version 7.0061
vimboss
parents: 196
diff changeset
445 retval = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 vim_free(newline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 curwin->w_cursor.col = ind_len;
217
89114a6baf3c updated for version 7.0061
vimboss
parents: 196
diff changeset
451 return retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 * Return the indent of the current line after a number. Return -1 if no
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 * number was found. Used for 'n' in 'formatoptions': numbered list.
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
457 * Since a pattern is used it can actually handle more than numbers.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
460 get_number_indent(linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464
3632
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
465 regmatch_T regmatch;
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
466 int lead_len = 0; /* length of comment leader */
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
467
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 if (lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 return -1;
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
470 pos.lnum = 0;
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
471
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
472 #ifdef FEAT_COMMENTS
3632
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
473 /* In format_lines() (i.e. not insert mode), fo+=q is needed too... */
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
474 if ((State & INSERT) || has_format_option(FO_Q_COMS))
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
475 lead_len = get_leader_len(ml_get(lnum), NULL, FALSE, TRUE);
3632
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
476 #endif
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
477 regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
478 if (regmatch.regprog != NULL)
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
479 {
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
480 regmatch.rm_ic = FALSE;
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
481
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
482 /* vim_regexec() expects a pointer to a line. This lets us
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
483 * start matching for the flp beyond any comment leader... */
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
484 if (vim_regexec(&regmatch, ml_get(lnum) + lead_len, (colnr_T)0))
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
485 {
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
486 pos.lnum = lnum;
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
487 pos.col = (colnr_T)(*regmatch.endp - ml_get(lnum));
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
488 pos.coladd = 0;
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
489 }
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4752
diff changeset
490 vim_regfree(regmatch.regprog);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4752
diff changeset
491 }
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
492
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
493 if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 getvcol(curwin, &pos, &col, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 return (int)col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
499 #if defined(FEAT_LINEBREAK) || defined(PROTO)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
500 /*
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
501 * Return appropriate space number for breakindent, taking influencing
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
502 * parameters into account. Window must be specified, since it is not
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
503 * necessarily always the current one.
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
504 */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
505 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
506 get_breakindent_win(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
507 win_T *wp,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
508 char_u *line) /* start of the line */
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
509 {
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
510 static int prev_indent = 0; /* cached indent value */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
511 static long prev_ts = 0L; /* cached tabstop value */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
512 static char_u *prev_line = NULL; /* cached pointer to line */
10889
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10807
diff changeset
513 static varnumber_T prev_tick = 0; /* changedtick of cached value */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
514 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
515 static int *prev_vts = NULL; /* cached vartabs values */
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
516 #endif
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
517 int bri = 0;
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
518 /* window width minus window margin space, i.e. what rests for text */
12515
972ea22c946f patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
519 const int eff_wwidth = wp->w_width
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
520 - ((wp->w_p_nu || wp->w_p_rnu)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
521 && (vim_strchr(p_cpo, CPO_NUMCOL) == NULL)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
522 ? number_width(wp) + 1 : 0);
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
523
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
524 /* used cached indent, unless pointer or 'tabstop' changed */
6010
ea2c5dfee1b0 updated for version 7.4.345
Bram Moolenaar <bram@vim.org>
parents: 5995
diff changeset
525 if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
526 || prev_tick != CHANGEDTICK(wp->w_buffer)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
527 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
528 || prev_vts != wp->w_buffer->b_p_vts_array
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
529 #endif
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
530 )
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
531 {
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
532 prev_line = line;
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
533 prev_ts = wp->w_buffer->b_p_ts;
10952
835604f3c37a patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents: 10932
diff changeset
534 prev_tick = CHANGEDTICK(wp->w_buffer);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
535 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
536 prev_vts = wp->w_buffer->b_p_vts_array;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
537 prev_indent = get_indent_str_vtab(line,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
538 (int)wp->w_buffer->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
539 wp->w_buffer->b_p_vts_array, wp->w_p_list);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
540 #else
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
541 prev_indent = get_indent_str(line,
6012
3248c6e40aee updated for version 7.4.346
Bram Moolenaar <bram@vim.org>
parents: 6010
diff changeset
542 (int)wp->w_buffer->b_p_ts, wp->w_p_list);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
543 #endif
6012
3248c6e40aee updated for version 7.4.346
Bram Moolenaar <bram@vim.org>
parents: 6010
diff changeset
544 }
3248c6e40aee updated for version 7.4.346
Bram Moolenaar <bram@vim.org>
parents: 6010
diff changeset
545 bri = prev_indent + wp->w_p_brishift;
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
546
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
547 /* indent minus the length of the showbreak string */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
548 if (wp->w_p_brisbr)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
549 bri -= vim_strsize(p_sbr);
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
550
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
551 /* Add offset for number column, if 'n' is in 'cpoptions' */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
552 bri += win_col_off2(wp);
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
553
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
554 /* never indent past left window margin */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
555 if (bri < 0)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
556 bri = 0;
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
557 /* always leave at least bri_min characters on the left,
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
558 * if text width is sufficient */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
559 else if (bri > eff_wwidth - wp->w_p_brimin)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
560 bri = (eff_wwidth - wp->w_p_brimin < 0)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
561 ? 0 : eff_wwidth - wp->w_p_brimin;
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
562
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
563 return bri;
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
564 }
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
565 #endif
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
566
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 #if defined(FEAT_COMMENTS) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 /*
5403
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
569 * 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
570 * 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
571 * 0 is returned.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 * 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
573 * comment leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 * "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
575 * 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
576 * length.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
579 get_leader_len(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
580 char_u *line,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
581 char_u **flags,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
582 int backward,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
583 int include_space)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 int i, j;
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
586 int result;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 int got_com = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 int found_one;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 char_u *string; /* pointer to comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 char_u *list;
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
592 int middle_match_len = 0;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
593 char_u *prev_list;
2813
21346361ce6c updated for version 7.3.182
Bram Moolenaar <bram@vim.org>
parents: 2809
diff changeset
594 char_u *saved_flags = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
596 result = i = 0;
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
597 while (VIM_ISWHITE(line[i])) /* leading white space is ignored */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 * Repeat to match several nested comment strings.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 */
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
603 while (line[i] != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 * scan through the 'comments' option for a match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 found_one = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 for (list = curbuf->b_p_com; *list; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 {
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
611 /* Get one option part into part_buf[]. Advance "list" to next
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
612 * one. Put "string" at start of string. */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
613 if (!got_com && flags != NULL)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
614 *flags = list; /* remember where flags started */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
615 prev_list = list;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 string = vim_strchr(part_buf, ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 if (string == NULL) /* missing ':', ignore this part */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 *string++ = NUL; /* isolate flags from string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
622 /* If we found a middle match previously, use that match when this
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
623 * is not a middle or end. */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
624 if (middle_match_len != 0
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
625 && vim_strchr(part_buf, COM_MIDDLE) == NULL
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
626 && vim_strchr(part_buf, COM_END) == NULL)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
627 break;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
628
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
629 /* When we already found a nested comment, only accept further
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
630 * nested comments. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 if (got_com && vim_strchr(part_buf, COM_NEST) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
634 /* When 'O' flag present and using "O" command skip this one. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
638 /* Line contents and string must match.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 * When string starts with white space, must have some white space
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 * (but the amount does not need to match, there might be a mix of
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
641 * TABs and spaces). */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
642 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
643 {
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
644 if (i == 0 || !VIM_ISWHITE(line[i - 1]))
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4342
diff changeset
645 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
646 while (VIM_ISWHITE(string[0]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 ++string;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 if (string[j] != NUL)
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
652 continue; /* string doesn't match */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
653
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
654 /* When 'b' flag used, there must be white space or an
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
655 * end-of-line after the string in the line. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 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
657 && !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
660 /* We have found a match, stop searching unless this is a middle
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
661 * comment. The middle comment can be a substring of the end
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
662 * comment in which case it's better to return the length of the
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
663 * end comment and its flags. Thus we keep searching with middle
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
664 * and end matches and use an end match if it matches better. */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
665 if (vim_strchr(part_buf, COM_MIDDLE) != NULL)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
666 {
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
667 if (middle_match_len == 0)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
668 {
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
669 middle_match_len = j;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
670 saved_flags = prev_list;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
671 }
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
672 continue;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
673 }
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
674 if (middle_match_len != 0 && j > middle_match_len)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
675 /* Use this match instead of the middle match, since it's a
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
676 * longer thus better match. */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
677 middle_match_len = 0;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
678
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
679 if (middle_match_len == 0)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
680 i += j;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 found_one = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
685 if (middle_match_len != 0)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
686 {
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
687 /* Use the previously found middle match after failing to find a
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
688 * match with an end. */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
689 if (!got_com && flags != NULL)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
690 *flags = saved_flags;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
691 i += middle_match_len;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
692 found_one = TRUE;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
693 }
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
694
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
695 /* No match found, stop scanning. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 if (!found_one)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
699 result = i;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
700
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
701 /* 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
702 while (VIM_ISWHITE(line[i]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
705 if (include_space)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
706 result = i;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
707
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
708 /* If this comment doesn't nest, stop here. */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
709 got_com = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 if (vim_strchr(part_buf, COM_NEST) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 }
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
713 return result;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
714 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
715
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
716 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
717 * 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
718 * comment in the whole line, -1 is returned.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
719 *
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
720 * 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
721 * recognized comment leader.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
722 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
723 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
724 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
725 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
726 int result = -1;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
727 int i, j;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
728 int lower_check_bound = 0;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
729 char_u *string;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
730 char_u *com_leader;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
731 char_u *com_flags;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
732 char_u *list;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
733 int found_one;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
734 char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
735
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
736 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
737 * Repeat to match several nested comment strings.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
738 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
739 i = (int)STRLEN(line);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
740 while (--i >= lower_check_bound)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
741 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
742 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
743 * scan through the 'comments' option for a match
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
744 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
745 found_one = FALSE;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
746 for (list = curbuf->b_p_com; *list; )
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
747 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
748 char_u *flags_save = list;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
749
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
750 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
751 * 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
752 * put string at start of string.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
753 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
754 (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
755 string = vim_strchr(part_buf, ':');
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
756 if (string == NULL) /* If everything is fine, this cannot actually
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
757 * happen. */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
758 continue;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
759 *string++ = NUL; /* Isolate flags from string. */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
760 com_leader = string;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
761
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
762 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
763 * Line contents and string must match.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
764 * 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
765 * (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
766 * TABs and spaces).
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
767 */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
768 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
769 {
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
770 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
771 continue;
15119
6e9f37bf987b patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents: 15046
diff changeset
772 while (VIM_ISWHITE(*string))
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
773 ++string;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
774 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
775 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
776 /* do nothing */;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
777 if (string[j] != NUL)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
778 continue;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
779
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
780 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
781 * 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
782 * 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
783 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
784 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
785 && !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
786 continue;
15119
6e9f37bf987b patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents: 15046
diff changeset
787
15127
31a0127813cb patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents: 15119
diff changeset
788 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
789 {
31a0127813cb patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents: 15119
diff changeset
790 // 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
791 // 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
792 // 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
793 // 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
794 // 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
795 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
796 ;
6e9f37bf987b patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents: 15046
diff changeset
797 if (j < i)
6e9f37bf987b patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents: 15046
diff changeset
798 continue;
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
799 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
800
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
801 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
802 * We have found a match, stop searching.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
803 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
804 found_one = TRUE;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
805
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
806 if (flags)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
807 *flags = flags_save;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
808 com_flags = flags_save;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
809
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
810 break;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
811 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
812
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
813 if (found_one)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
814 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
815 char_u part_buf2[COM_MAX_LEN]; /* buffer for one option part */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
816 int len1, len2, off;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
817
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
818 result = i;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
819 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
820 * If this comment nests, continue searching.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
821 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
822 if (vim_strchr(part_buf, COM_NEST) != NULL)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
823 continue;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
824
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
825 lower_check_bound = i;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
826
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
827 /* Let's verify whether the comment leader found is a substring
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
828 * of other comment leaders. If it is, let's adjust the
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
829 * lower_check_bound so that we make sure that we have determined
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
830 * the comment leader correctly.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
831 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
832
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
833 while (VIM_ISWHITE(*com_leader))
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
834 ++com_leader;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
835 len1 = (int)STRLEN(com_leader);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
836
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
837 for (list = curbuf->b_p_com; *list; )
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
838 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
839 char_u *flags_save = list;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
840
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
841 (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
842 if (flags_save == com_flags)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
843 continue;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
844 string = vim_strchr(part_buf2, ':');
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
845 ++string;
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
846 while (VIM_ISWHITE(*string))
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
847 ++string;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
848 len2 = (int)STRLEN(string);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
849 if (len2 == 0)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
850 continue;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
851
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
852 /* Now we have to verify whether string ends with a substring
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
853 * beginning the com_leader. */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
854 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
855 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
856 --off;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
857 if (!STRNCMP(string + off, com_leader, len2 - off))
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
858 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
859 if (i - off < lower_check_bound)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
860 lower_check_bound = i - off;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
861 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
862 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
863 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
864 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
865 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
866 return result;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 * Return the number of window lines occupied by buffer line "lnum".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
874 plines(linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 return plines_win(curwin, lnum, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
880 plines_win(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
881 win_T *wp,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
882 linenr_T lnum,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
883 int winheight) /* when TRUE limit to window height */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 #if defined(FEAT_DIFF) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 /* Check for filler lines above this buffer line. When folded the result
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 * is one line anyway. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
892 plines_nofill(linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 return plines_win_nofill(curwin, lnum, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
898 plines_win_nofill(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
899 win_T *wp,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
900 linenr_T lnum,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
901 int winheight) /* when TRUE limit to window height */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 int lines;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 if (!wp->w_p_wrap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 if (wp->w_width == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 /* A folded lines is handled just like an empty line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 /* NOTE: Caller must handle lines that are MAYBE folded. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 if (lineFolded(wp, lnum) == TRUE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 lines = plines_win_nofold(wp, lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 if (winheight > 0 && lines > wp->w_height)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 return (int)wp->w_height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 return lines;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 * Return number of window lines physical line "lnum" will occupy in window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 * "wp". Does not care about folding, 'wrap' or 'diff'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
930 plines_win_nofold(win_T *wp, linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933 long col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934 int width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 s = ml_get_buf(wp->w_buffer, lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 if (*s == NUL) /* empty line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 col = win_linetabsize(wp, s, (colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942 * 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
943 * extra column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 if (wp->w_p_list && lcs_eol != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 col += 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 /*
2178
c6f1aa1e9f32 Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents: 2162
diff changeset
949 * Add column offset for 'number', 'relativenumber' and 'foldcolumn'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 */
12515
972ea22c946f patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
951 width = wp->w_width - win_col_off(wp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 if (width <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 return 32000;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954 if (col <= width)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956 col -= width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 width += win_col_off2(wp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958 return (col + (width - 1)) / width + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 * Like plines_win(), but only reports the number of physical screen lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963 * used from the start of the line to the given column number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
966 plines_win_col(win_T *wp, linenr_T lnum, long column)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 long col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 int lines = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 int width;
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
972 char_u *line;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
975 /* Check for filler lines above this buffer line. When folded the result
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976 * is one line anyway. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977 lines = diff_check_fill(wp, lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 if (!wp->w_p_wrap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981 return lines + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 if (wp->w_width == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984 return lines + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
985
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
986 line = s = ml_get_buf(wp->w_buffer, lnum, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988 col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989 while (*s != NUL && --column >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 {
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
991 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
992 MB_PTR_ADV(s);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 * 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
997 * INSERT mode, then col must be adjusted so that it represents the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 * screen position of the TAB. This only fixes an error when the TAB wraps
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 * from one screen line to the next (when 'columns' is not a multiple of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 * 'ts') -- webb.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 if (*s == TAB && (State & NORMAL) && (!wp->w_p_list || lcs_tab1))
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
1003 col += win_lbr_chartabsize(wp, line, s, (colnr_T)col, NULL) - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 /*
2178
c6f1aa1e9f32 Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents: 2162
diff changeset
1006 * Add column offset for 'number', 'relativenumber', 'foldcolumn', etc.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 */
12515
972ea22c946f patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
1008 width = wp->w_width - win_col_off(wp);
1023
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1009 if (width <= 0)
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1010 return 9999;
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1011
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1012 lines += 1;
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1013 if (col > width)
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1014 lines += (col - width) / (width + win_col_off2(wp)) + 1;
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1015 return lines;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1019 plines_m_win(win_T *wp, linenr_T first, linenr_T last)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023 while (first <= last)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 int x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 /* Check if there are any really folded lines, but also included lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029 * that are maybe folded. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 x = foldedCount(wp, first, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 if (x > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 ++count; /* count 1 for "+-- folded" line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 first += x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 if (first == wp->w_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 count += plines_win_nofill(wp, first, TRUE) + wp->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 count += plines_win(wp, first, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045 ++first;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 return (count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1052 gchar_pos(pos_T *pos)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 {
13082
a80082fd1a1d patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
1054 char_u *ptr;
a80082fd1a1d patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
1055
a80082fd1a1d patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
1056 /* When searching columns is sometimes put at the end of a line. */
a80082fd1a1d patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
1057 if (pos->col == MAXCOL)
a80082fd1a1d patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
1058 return NUL;
a80082fd1a1d patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
1059 ptr = ml_get_pos(pos);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 return (*mb_ptr2char)(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 return (int)*ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1066 gchar_cursor(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 return (*mb_ptr2char)(ml_get_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 return (int)*ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 * Write a character at the current cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 * It is directly written into the block.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1078 pchar_cursor(int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 *(ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 + curwin->w_cursor.col) = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 * When extra == 0: Return TRUE if the cursor is before or on the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 * non-blank in the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 * When extra == 1: Return TRUE if the cursor is before the first non-blank in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 * the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1091 inindent(int extra)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1096 for (col = 0, ptr = ml_get_curline(); VIM_ISWHITE(*ptr); ++col)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 if (col >= curwin->w_cursor.col + extra)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 * Skip to next part of an option argument: Skip space and comma.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1108 skip_to_option_part(char_u *p)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110 if (*p == ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 while (*p == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118 * check_status: called when the status bars for the buffer 'buf'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 * need to be updated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1122 check_status(buf_T *buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9536
diff changeset
1126 FOR_ALL_WINDOWS(wp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 if (wp->w_buffer == buf && wp->w_status_height)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 wp->w_redr_status = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 if (must_redraw < VALID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 must_redraw = VALID;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 * Ask for a reply from the user, a 'y' or a 'n'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 * No other characters are accepted, the message is repeated until a valid
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138 * reply is entered or CTRL-C is hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 * 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
1140 * from any buffers but directly from the user.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 * return the 'y' or 'n'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1145 ask_yesno(char_u *str, int direct)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 int r = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 int save_State = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 if (exiting) /* put terminal in raw mode for this question */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 settmode(TMODE_RAW);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 ++no_wait_return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 State = CONFIRM; /* mouse behaves like with :confirm */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 setmouse(); /* disables mouse for xterm */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 ++allow_keys; /* no mapping here, but recognize keys */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 while (r != 'y' && r != 'n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 /* 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
1166 smsg_attr(HL_ATTR(HLF_R), "%s (y/n)?", str);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 if (direct)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 r = get_keystroke();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 else
1474
276244befa5b updated for version 7.1-189
vimboss
parents: 1470
diff changeset
1170 r = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 if (r == Ctrl_C || r == ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 r = 'n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 msg_putchar(r); /* show what you typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 --no_wait_return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 State = save_State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 setmouse();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 return r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186
4221
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1187 #if defined(FEAT_MOUSE) || defined(PROTO)
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1188 /*
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1189 * Return TRUE if "c" is a mouse key.
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1190 */
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1191 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1192 is_mouse_key(int c)
4221
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1193 {
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1194 return c == K_LEFTMOUSE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1195 || c == K_LEFTMOUSE_NM
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1196 || c == K_LEFTDRAG
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1197 || c == K_LEFTRELEASE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1198 || c == K_LEFTRELEASE_NM
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12716
diff changeset
1199 || c == K_MOUSEMOVE
4221
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1200 || c == K_MIDDLEMOUSE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1201 || c == K_MIDDLEDRAG
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1202 || c == K_MIDDLERELEASE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1203 || c == K_RIGHTMOUSE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1204 || c == K_RIGHTDRAG
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1205 || c == K_RIGHTRELEASE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1206 || c == K_MOUSEDOWN
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1207 || c == K_MOUSEUP
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1208 || c == K_MOUSELEFT
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1209 || c == K_MOUSERIGHT
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1210 || c == K_X1MOUSE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1211 || c == K_X1DRAG
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1212 || c == K_X1RELEASE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1213 || c == K_X2MOUSE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1214 || c == K_X2DRAG
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1215 || c == K_X2RELEASE;
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1216 }
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1217 #endif
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1218
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 * Get a key stroke directly from the user.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 * Ignores mouse clicks and scrollbar events, except a click for the left
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 * button (used at the more prompt).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 * Doesn't use vgetc(), because it syncs undo and eats mapped characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 * Disadvantage: typeahead is ignored.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 * Translates the interrupt character for unix to ESC.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1228 get_keystroke(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 {
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1230 char_u *buf = NULL;
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1231 int buflen = 150;
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1232 int maxlen;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 int len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 int save_mapped_ctrl_c = mapped_ctrl_c;
964
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
1236 int waited = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 mapped_ctrl_c = FALSE; /* mappings are not used here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 cursor_on();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1244 /* Leave some room for check_termcode() to insert a key code into (max
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1245 * 5 chars plus NUL). And fix_input_buffer() can triple the number of
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1246 * bytes. */
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1247 maxlen = (buflen - 6 - len) / 3;
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1248 if (buf == NULL)
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1249 buf = alloc(buflen);
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1250 else if (maxlen < 10)
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1251 {
6596
f8f2a61e538d updated for version 7.4.624
Bram Moolenaar <bram@vim.org>
parents: 6174
diff changeset
1252 char_u *t_buf = buf;
f8f2a61e538d updated for version 7.4.624
Bram Moolenaar <bram@vim.org>
parents: 6174
diff changeset
1253
3596
34724dc5172b updated for version 7.3.558
Bram Moolenaar <bram@vim.org>
parents: 3592
diff changeset
1254 /* Need some more space. This might happen when receiving a long
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1255 * escape sequence. */
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1256 buflen += 100;
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1257 buf = vim_realloc(buf, buflen);
6596
f8f2a61e538d updated for version 7.4.624
Bram Moolenaar <bram@vim.org>
parents: 6174
diff changeset
1258 if (buf == NULL)
f8f2a61e538d updated for version 7.4.624
Bram Moolenaar <bram@vim.org>
parents: 6174
diff changeset
1259 vim_free(t_buf);
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1260 maxlen = (buflen - 6 - len) / 3;
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1261 }
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1262 if (buf == NULL)
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1263 {
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1264 do_outofmem_msg((long_u)buflen);
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1265 return ESC; /* panic! */
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1266 }
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1267
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 /* First time: blocking wait. Second time: wait up to 100ms for a
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1269 * terminal code to complete. */
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1270 n = ui_inchar(buf + len, maxlen, len == 0 ? -1L : 100L, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 /* 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
1274 n = fix_input_buffer(buf + len, n);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 len += n;
964
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
1276 waited = 0;
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
1277 }
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
1278 else if (len > 0)
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
1279 ++waited; /* keep track of the waiting time */
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
1280
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
1281 /* 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
1282 if ((n = check_termcode(1, buf, buflen, &len)) < 0
964
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
1283 && (!p_ttimeout || waited * 100L < (p_ttm < 0 ? p_tm : p_ttm)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 continue;
964
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
1285
2672
6a2e4860134b updated for version 7.3.091
Bram Moolenaar <bram@vim.org>
parents: 2652
diff changeset
1286 if (n == KEYLEN_REMOVED) /* key code removed */
2721
417c04135ca2 updated for version 7.3.137
Bram Moolenaar <bram@vim.org>
parents: 2685
diff changeset
1287 {
2723
2e72d84e8965 updated for version 7.3.139
Bram Moolenaar <bram@vim.org>
parents: 2721
diff changeset
1288 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
1289 {
417c04135ca2 updated for version 7.3.137
Bram Moolenaar <bram@vim.org>
parents: 2685
diff changeset
1290 /* Redrawing was postponed, do it now. */
417c04135ca2 updated for version 7.3.137
Bram Moolenaar <bram@vim.org>
parents: 2685
diff changeset
1291 update_screen(0);
417c04135ca2 updated for version 7.3.137
Bram Moolenaar <bram@vim.org>
parents: 2685
diff changeset
1292 setcursor(); /* put cursor back where it belongs */
417c04135ca2 updated for version 7.3.137
Bram Moolenaar <bram@vim.org>
parents: 2685
diff changeset
1293 }
2672
6a2e4860134b updated for version 7.3.091
Bram Moolenaar <bram@vim.org>
parents: 2652
diff changeset
1294 continue;
2721
417c04135ca2 updated for version 7.3.137
Bram Moolenaar <bram@vim.org>
parents: 2685
diff changeset
1295 }
2672
6a2e4860134b updated for version 7.3.091
Bram Moolenaar <bram@vim.org>
parents: 2652
diff changeset
1296 if (n > 0) /* found a termcode: adjust length */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1297 len = n;
2672
6a2e4860134b updated for version 7.3.091
Bram Moolenaar <bram@vim.org>
parents: 2652
diff changeset
1298 if (len == 0) /* nothing typed yet */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 /* Handle modifier and/or special key code. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302 n = buf[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303 if (n == K_SPECIAL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305 n = TO_SPECIAL(buf[1], buf[2]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 if (buf[1] == KS_MODIFIER
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1307 || n == K_IGNORE
4225
a82ef37d38c0 updated for version 7.3.864
Bram Moolenaar <bram@vim.org>
parents: 4221
diff changeset
1308 #ifdef FEAT_MOUSE
4221
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1309 || (is_mouse_key(n) && n != K_LEFTMOUSE)
4225
a82ef37d38c0 updated for version 7.3.864
Bram Moolenaar <bram@vim.org>
parents: 4221
diff changeset
1310 #endif
4221
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
1311 #ifdef FEAT_GUI
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 || n == K_VER_SCROLLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 || n == K_HOR_SCROLLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 if (buf[1] == KS_MODIFIER)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 mod_mask = buf[2];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 len -= 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 if (len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 mch_memmove(buf, buf + 3, (size_t)len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 }
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
1324 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 if (MB_BYTE2LEN(n) > len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 continue; /* more bytes to get */
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1330 buf[len >= buflen ? buflen - 1 : len] = NUL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 n = (*mb_ptr2char)(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1333 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1334 if (n == intr_char)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 n = ESC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 }
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
1339 vim_free(buf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341 mapped_ctrl_c = save_mapped_ctrl_c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 return n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1344
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 /*
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1346 * Get a number from the user.
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1347 * When "mouse_used" is not NULL allow using the mouse.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1350 get_number(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1351 int colon, /* allow colon to abort */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1352 int *mouse_used)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 int n = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 int c;
810
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
1356 int typed = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1358 if (mouse_used != NULL)
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1359 *mouse_used = FALSE;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1360
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 /* When not printing messages, the user won't know what to type, return a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362 * zero (as if CR was hit). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 if (msg_silent != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 ++allow_keys; /* no mapping here, but recognize keys */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 windgoto(msg_row, msg_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374 c = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 if (VIM_ISDIGIT(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 n = n * 10 + c - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 msg_putchar(c);
810
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
1379 ++typed;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 else if (c == K_DEL || c == K_KDEL || c == K_BS || c == Ctrl_H)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 {
810
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
1383 if (typed > 0)
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
1384 {
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
1385 msg_puts("\b \b");
810
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
1386 --typed;
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
1387 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 n /= 10;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 }
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1390 #ifdef FEAT_MOUSE
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1391 else if (mouse_used != NULL && c == K_LEFTMOUSE)
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1392 {
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1393 *mouse_used = TRUE;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1394 n = mouse_row + 1;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1395 break;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1396 }
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1397 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 else if (n == 0 && c == ':' && colon)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 stuffcharReadbuff(':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 if (!exmode_active)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 cmdline_row = msg_row;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 skip_redraw = TRUE; /* skip redraw once */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 do_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407 else if (c == CAR || c == NL || c == Ctrl_C || c == ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412 return n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1415 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1416 * Ask the user to enter a number.
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1417 * 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
1418 * the line number.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1419 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1420 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1421 prompt_for_number(int *mouse_used)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1422 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1423 int i;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
1424 int save_cmdline_row;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
1425 int save_State;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1426
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1427 /* When using ":silent" assume that <CR> was entered. */
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 374
diff changeset
1428 if (mouse_used != NULL)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
1429 msg_puts(_("Type number and <Enter> or click with mouse (empty cancels): "));
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 374
diff changeset
1430 else
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
1431 msg_puts(_("Type number and <Enter> (empty cancels): "));
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
1432
14629
100a44722322 patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents: 14585
diff changeset
1433 // 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
1434 // 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
1435 // is zero.
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
1436 save_cmdline_row = cmdline_row;
957
3dc6072e0a25 updated for version 7.0-083
vimboss
parents: 927
diff changeset
1437 cmdline_row = 0;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
1438 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
1439 State = CMDLINE;
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
1440 #ifdef FEAT_MOUSE
14629
100a44722322 patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents: 14585
diff changeset
1441 // 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
1442 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
1443 #endif
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
1444
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1445 i = get_number(TRUE, mouse_used);
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1446 if (KeyTyped)
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1447 {
17018
b1263192461f patch 8.1.1509: cmdline_row can become negative, causing a crash
Bram Moolenaar <Bram@vim.org>
parents: 16782
diff changeset
1448 // 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
1449 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
1450 cmdline_row = msg_row - 1;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1451 need_wait_return = FALSE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1452 msg_didany = FALSE;
1938
5ed9395c1864 updated for version 7.2-235
vimboss
parents: 1937
diff changeset
1453 msg_didout = FALSE;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1454 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
1455 else
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
1456 cmdline_row = save_cmdline_row;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
1457 State = save_State;
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
1458 #ifdef FEAT_MOUSE
14629
100a44722322 patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents: 14585
diff changeset
1459 // 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
1460 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
1461 #endif
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
1462
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1463 return i;
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1464 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
1465
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1467 msgmore(long n)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469 long pn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1471 if (global_busy /* no messages now, wait until global is finished */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1472 || !messaging()) /* 'lazyredraw' set, don't do messages now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
1475 /* We don't want to overwrite another important message, but do overwrite
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
1476 * a previous "more lines" or "fewer lines" message, so that "5dd" and
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
1477 * then "put" reports the last action. */
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
1478 if (keep_msg != NULL && !keep_msg_more)
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
1479 return;
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
1480
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482 pn = n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484 pn = -n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 if (pn > p_report)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 {
14585
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
1488 if (n > 0)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
1489 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
1490 NGETTEXT("%ld more line", "%ld more lines", pn), pn);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 else
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
1492 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
1493 NGETTEXT("%ld line less", "%ld fewer lines", pn), pn);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494 if (got_int)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
1495 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
1496 MSG_BUF_LEN);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 if (msg(msg_buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 {
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
1499 set_keep_msg((char_u *)msg_buf, 0);
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
1500 keep_msg_more = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502 }
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 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506 * flush map and typeahead buffers and give a warning for an error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1509 beep_flush(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 if (emsg_silent == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 {
14909
c97b4b537572 patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
1513 flush_buffers(FLUSH_MINIMAL);
6949
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
1514 vim_beep(BO_ERROR);
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
1515 }
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
1516 }
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
1517
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
1518 /*
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
1519 * Give a warning for an error.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1522 vim_beep(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1523 unsigned val) /* one of the BO_ values, e.g., BO_OPER */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524 {
13272
abaebba89fd4 patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
1525 #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
1526 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
1527 #endif
abaebba89fd4 patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
1528
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 if (emsg_silent == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 {
6949
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
1531 if (!((bo_flags & val) || (bo_flags & BO_ALL)))
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
1532 {
11601
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1533 #ifdef ELAPSED_FUNC
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1534 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
1535 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
1536
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1537 /* Only beep once per half a second, otherwise a sequence of beeps
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1538 * would freeze Vim. */
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1539 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
1540 {
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1541 did_init = TRUE;
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1542 ELAPSED_INIT(start_tv);
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1543 #endif
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1544 if (p_vb
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 #ifdef FEAT_GUI
11601
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1546 /* While the GUI is starting up the termcap is set for
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1547 * the GUI but the output still goes to a terminal. */
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1548 && !(gui.in_use && gui.starting)
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1549 #endif
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1550 )
13314
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
1551 {
11601
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1552 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
1553 #ifdef FEAT_VTP
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
1554 /* No restore color information, refresh the screen. */
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
1555 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
1556 # 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
1557 && (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
1558 # endif
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
1559 )
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
1560 {
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
1561 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
1562 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
1563 redrawcmd();
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
1564 }
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
1565 #endif
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
1566 }
11601
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1567 else
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1568 out_char(BELL);
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1569 #ifdef ELAPSED_FUNC
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1570 }
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
1571 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 }
169
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
1573
13272
abaebba89fd4 patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
1574 /* When 'debug' contains "beep" produce a message. If we are sourcing
abaebba89fd4 patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
1575 * a script or executing a function give the user a hint where the beep
abaebba89fd4 patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
1576 * comes from. */
169
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
1577 if (vim_strchr(p_debug, 'e') != NULL)
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
1578 {
11158
501f46f7644c patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents: 11129
diff changeset
1579 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
1580 msg_attr(_("Beep!"), HL_ATTR(HLF_W));
169
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
1581 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 * To get the "real" home directory:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 * - get value of $HOME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588 * For Unix:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1589 * - go to that directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 * - do mch_dirname() to get the real name of that directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 * This also works with mounts and links.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 * 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
1593 * For Windows:
c1be7c8bb602 patch 8.1.0534: MS-Windows installer uses different $HOME than Vim
Bram Moolenaar <Bram@vim.org>
parents: 14909
diff changeset
1594 * This code is duplicated in init_homedir() in dosinst.c. Keep in sync!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 static char_u *homedir = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1599 init_homedir(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 char_u *var;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1603 /* 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
1604 VIM_CLEAR(homedir);
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1605
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606 #ifdef VMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 var = mch_getenv((char_u *)"SYS$LOGIN");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 var = mch_getenv((char_u *)"HOME");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15814
diff changeset
1612 #ifdef MSWIN
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 /*
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
1614 * 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
1615 * 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
1616 * 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
1617 * 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
1618 */
12269
d2373927d76d patch 8.0.1014: old compiler doesn't know uint32_t
Christian Brabandt <cb@256bit.org>
parents: 12265
diff changeset
1619 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
1620 {
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
1621 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
1622
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
1623 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
1624 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
1625 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
1626 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
1627 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
1628 && 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
1629 {
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
1630 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
1631 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
1632 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
1633 }
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
1634 }
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
1635
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
1636 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
1637 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
1638
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
1639 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 * Weird but true: $HOME may contain an indirect reference to another
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 * variable, esp. "%USERPROFILE%". Happens when $USERPROFILE isn't set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 * when $HOME is being set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 if (var != NULL && *var == '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 char_u *exp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 p = vim_strchr(var + 1, '%');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 {
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 410
diff changeset
1652 vim_strncpy(NameBuff, var + 1, p - (var + 1));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 exp = mch_getenv(NameBuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 if (exp != NULL && *exp != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 && STRLEN(exp) + STRLEN(p) < MAXPATHL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 {
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 265
diff changeset
1657 vim_snprintf((char *)NameBuff, MAXPATHL, "%s%s", exp, p + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 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
1659 }
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
1660 }
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
1661 }
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
1662
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
1663 if (var != NULL && *var == NUL) /* empty is same as not set */
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
1664 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
1665
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1666 if (enc_utf8 && var != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1667 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1668 int len;
2786
5f45bacf31ef updated for version 7.3.169
Bram Moolenaar <bram@vim.org>
parents: 2776
diff changeset
1669 char_u *pp = NULL;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1670
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1671 /* Convert from active codepage to UTF-8. Other conversions are
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1672 * not done, because they would fail for non-ASCII characters. */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
1673 acp_to_enc(var, (int)STRLEN(var), &pp, &len);
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1674 if (pp != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1675 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1676 homedir = pp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1677 return;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1678 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
1679 }
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
1680
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 * Default home dir is C:/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 * Best assumption we can make in such a situation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 if (var == NULL)
8080
b6cb94ad97a4 commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
1686 var = (char_u *)"C:/";
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 #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
1688
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 if (var != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 * Change to the directory and get the actual path. This resolves
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 * links. Don't do it when we can't return.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 if (mch_dirname(NameBuff, MAXPATHL) == OK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 && mch_chdir((char *)NameBuff) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 if (!mch_chdir((char *)var) && mch_dirname(IObuff, IOSIZE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 var = IObuff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 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
1702 emsg(_(e_prev_dir));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 homedir = vim_strsave(var);
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
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
1709 #if defined(EXITFREE) || defined(PROTO)
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
1710 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1711 free_homedir(void)
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
1712 {
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
1713 vim_free(homedir);
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
1714 }
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
1715
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
1716 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1717 free_users(void)
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
1718 {
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
1719 ga_clear_strings(&ga_users);
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
1720 }
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
1721 #endif
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
1722
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 /*
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1724 * Call expand_env() and store the result in an allocated string.
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1725 * 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
1726 * again soon.
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1727 */
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1728 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1729 expand_env_save(char_u *src)
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1730 {
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1731 return expand_env_save_opt(src, FALSE);
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1732 }
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1733
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1734 /*
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1735 * 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
1736 * expand "~" at the start.
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1737 */
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1738 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1739 expand_env_save_opt(char_u *src, int one)
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1740 {
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1741 char_u *p;
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1742
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1743 p = alloc(MAXPATHL);
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1744 if (p != NULL)
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1745 expand_env_esc(src, p, MAXPATHL, FALSE, one, NULL);
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1746 return p;
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1747 }
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1748
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1749 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 * Expand environment variable with path name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 * "~/" is also expanded, using $HOME. For Unix "~user/" is expanded.
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1752 * Skips over "\ ", "\~" and "\$" (not for Win32 though).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 * If anything fails no expansion is done and dst equals src.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1756 expand_env(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1757 char_u *src, /* input string e.g. "$HOME/vim.hlp" */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1758 char_u *dst, /* where to put the result */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1759 int dstlen) /* maximum length of the result */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 {
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
1761 expand_env_esc(src, dst, dstlen, FALSE, FALSE, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1765 expand_env_esc(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1766 char_u *srcp, /* input string e.g. "$HOME/vim.hlp" */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1767 char_u *dst, /* where to put the result */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1768 int dstlen, /* maximum length of the result */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1769 int esc, /* escape spaces in expanded variables */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1770 int one, /* "srcp" is one file name */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1771 char_u *startstr) /* start again after this (can be NULL) */
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1772 {
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1773 char_u *src;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 char_u *tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 char_u *var;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 int copy_char;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 int mustfree; /* var was allocated, need to free it later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 int at_start = TRUE; /* at start of a name */
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1780 int startstr_len = 0;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1781
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1782 if (startstr != NULL)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
1783 startstr_len = (int)STRLEN(startstr);
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1784
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
1785 src = skipwhite(srcp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 --dstlen; /* leave one char space for "\," */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 while (*src && dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 {
7038
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1789 #ifdef FEAT_EVAL
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1790 /* Skip over `=expr`. */
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1791 if (src[0] == '`' && src[1] == '=')
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1792 {
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1793 size_t len;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1794
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1795 var = src;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1796 src += 2;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1797 (void)skip_expr(&src);
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1798 if (*src == '`')
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1799 ++src;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1800 len = src - var;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1801 if (len > (size_t)dstlen)
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1802 len = dstlen;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1803 vim_strncpy(dst, var, len);
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1804 dst += len;
7066
094c8ccdc279 commit https://github.com/vim/vim/commit/5df1ed2de3fa9dcace996b9a0a4c9b3cea79cf1e
Christian Brabandt <cb@256bit.org>
parents: 7038
diff changeset
1805 dstlen -= (int)len;
7038
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1806 continue;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1807 }
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
1808 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 copy_char = TRUE;
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
1810 if ((*src == '$'
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
1811 #ifdef VMS
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
1812 && at_start
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
1813 #endif
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
1814 )
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
1815 #if defined(MSWIN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816 || *src == '%'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 || (*src == '~' && at_start))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 mustfree = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 * The variable name is copied into dst temporarily, because it may
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824 * be a string in read-only memory and a NUL needs to be appended.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826 if (*src != '~') /* environment var */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 tail = src + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 var = dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 c = dstlen - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 /* Unix has ${var-name} type environment vars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834 if (*tail == '{' && !vim_isIDc('{'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 tail++; /* ignore '{' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 while (c-- > 0 && *tail && *tail != '}')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 *var++ = *tail++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 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
1844 #if defined(MSWIN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 || (*src == '%' && *tail != '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 *var++ = *tail++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
1851 #if defined(MSWIN) || defined(UNIX)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 if (src[1] == '{' && *tail != '}')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855 if (*src == '%' && *tail != '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 var = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 if (src[1] == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 if (*src == '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1865 ++tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867 *var = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 var = vim_getenv(dst, &mustfree);
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
1869 #if defined(MSWIN) || defined(UNIX)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873 /* home directory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 else if ( src[1] == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 || vim_ispathsep(src[1])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 || vim_strchr((char_u *)" ,\t\n", src[1]) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 var = homedir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 tail = src + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 else /* user directory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 #if defined(UNIX) || (defined(VMS) && defined(USER_HOME))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1885 * Copy ~user to dst[], so we can put a NUL after it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 tail = src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888 var = dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889 c = dstlen - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890 while ( c-- > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 && *tail
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 && vim_isfilec(*tail)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 && !vim_ispathsep(*tail))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 *var++ = *tail++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 *var = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1898 * If the system supports getpwnam(), use it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 * Otherwise, or if getpwnam() fails, the shell is used to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900 * expand ~user. This is slower and may fail if the shell
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 * does not support ~user (old versions of /bin/sh).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903 # if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904 {
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1905 /* Note: memory allocated by getpwnam() is never freed.
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1906 * 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
1907 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
1908 ? 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
1909
141fe140976c patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents: 10889
diff changeset
1910 var = (pw == NULL) ? NULL : (char_u *)pw->pw_dir;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912 if (var == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 expand_T xpc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 ExpandInit(&xpc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 xpc.xp_context = EXPAND_FILES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 var = ExpandOne(&xpc, dst, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920 WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1921 mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924 # else /* !UNIX, thus VMS */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1925 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 * USER_HOME is a comma-separated list of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 * directories to search for the user account in.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1928 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 char_u test[MAXPATHL], paths[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1931 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
1932 stat_T st;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 STRCPY(paths, USER_HOME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935 next_path = paths;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 while (*next_path)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 for (path = next_path; *next_path && *next_path != ',';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 next_path++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940 if (*next_path)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941 *next_path++ = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 STRCPY(test, path);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943 STRCAT(test, "/");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 STRCAT(test, dst + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945 if (mch_stat(test, &st) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1946 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 var = alloc(STRLEN(test) + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948 STRCPY(var, test);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1949 mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1950 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1953 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 # endif /* UNIX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956 /* cannot expand user's home directory, so don't try */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957 var = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958 tail = (char_u *)""; /* for gcc */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959 #endif /* UNIX || VMS */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1960 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1962 #ifdef BACKSLASH_IN_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963 /* If 'shellslash' is set change backslashes to forward slashes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964 * Can't use slash_adjust(), p_ssl may be set temporarily. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1966 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967 char_u *p = vim_strsave(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1971 if (mustfree)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1972 vim_free(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1973 var = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975 forward_slash(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1978 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1980 /* If "var" contains white space, escape it with a backslash.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1981 * Required for ":e ~/tt" when $HOME includes a space. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982 if (esc && var != NULL && vim_strpbrk(var, (char_u *)" \t") != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984 char_u *p = vim_strsave_escaped(var, (char_u *)" \t");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988 if (mustfree)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 vim_free(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 var = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1991 mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1994
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1995 if (var != NULL && *var != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1996 && (STRLEN(var) + STRLEN(tail) + 1 < (unsigned)dstlen))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1997 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1998 STRCPY(dst, var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1999 dstlen -= (int)STRLEN(var);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
2000 c = (int)STRLEN(var);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 /* if var[] ends in a path separator and tail[] starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 * with it, skip a character */
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2003 if (*var != NUL && after_pathsep(dst, dst + c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 #if defined(BACKSLASH_IN_FILENAME) || defined(AMIGA)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 && dst[-1] != ':'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2006 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 && vim_ispathsep(*tail))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 ++tail;
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2009 dst += c;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2010 src = tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2011 copy_char = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2012 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2013 if (mustfree)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2014 vim_free(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2015 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2016
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017 if (copy_char) /* copy at least one char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2019 /*
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
2020 * Recognize the start of a new name, for '~'.
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
2021 * Don't do this when "one" is TRUE, to avoid expanding "~" in
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
2022 * ":edit foo ~ foo".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 at_start = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2025 if (src[0] == '\\' && src[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2026 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2027 *dst++ = *src++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028 --dstlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 }
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
2030 else if ((src[0] == ' ' || src[0] == ',') && !one)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2031 at_start = TRUE;
12005
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
2032 if (dstlen > 0)
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
2033 {
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
2034 *dst++ = *src++;
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
2035 --dstlen;
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
2036
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
2037 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
2038 && 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
2039 startstr_len) == 0)
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
2040 at_start = TRUE;
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
2041 }
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
2042 }
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
2043
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2044 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2045 *dst = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2046 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2047
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2048 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2049 * Vim's version of getenv().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2050 * Special handling of $HOME, $VIM and $VIMRUNTIME.
196
991a7623a1fe updated for version 7.0058
vimboss
parents: 191
diff changeset
2051 * 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
2052 * "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
2053 * initialized to FALSE by the caller.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2056 vim_getenv(char_u *name, int *mustfree)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2057 {
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
2058 char_u *p = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 char_u *pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 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
2061 #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
2062 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
2063
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2064 // use "C:/" when $HOME is not set
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065 if (STRCMP(name, "HOME") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 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
2067
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2068 // 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
2069 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
2070 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
2071 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
2072
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2073 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
2074 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
2075
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2076 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
2077 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
2078
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2079 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
2080 {
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2081 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
2082 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
2083 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
2084
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2085 *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
2086 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
2087 }
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2088 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 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
2090 if (p != NULL && *p == NUL) // empty is the same as not set
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2092
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094 return p;
16172
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2095 #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
2096
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2097 // handling $VIMRUNTIME and $VIM is below, bail out if it's another name.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2098 vimruntime = (STRCMP(name, "VIMRUNTIME") == 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2099 if (!vimruntime && STRCMP(name, "VIM") != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2100 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2101
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2102 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2103 * When expanding $VIMRUNTIME fails, try using $VIM/vim<version> or $VIM.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104 * Don't do this when default_vimruntime_dir is non-empty.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2106 if (vimruntime
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2107 #ifdef HAVE_PATHDEF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2108 && *default_vimruntime_dir == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2109 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2110 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2111 {
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
2112 #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
2113 // 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
2114 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
2115 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
2116 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
2117 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
2118 {
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2119 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
2120 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
2121 {
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2122 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
2123 *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
2124 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
2125 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
2126 }
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2127 }
6b0836727cf3 patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2128 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2129 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
2130 if (p != NULL && *p == NUL) // empty is the same as not set
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2131 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2132 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2133 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2134 p = vim_version_dir(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2135 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2136 *mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2137 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2138 p = mch_getenv((char_u *)"VIM");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2139 }
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
2140 #endif
7
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 * When expanding $VIM or $VIMRUNTIME fails, try using:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2145 * - the directory name from 'helpfile' (unless it contains '$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 * - the executable name from argv[0]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2147 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2149 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 if (p_hf != NULL && vim_strchr(p_hf, '$') == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2151 p = p_hf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2152 #ifdef USE_EXE_NAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154 * Use the name of the executable, obtained from argv[0].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157 p = exe_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 /* remove the file name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2162 pend = gettail(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2164 /* remove "doc/" from 'helpfile', if present */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 if (p == p_hf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2166 pend = remove_tail(p, pend, (char_u *)"doc");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2168 #ifdef USE_EXE_NAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2169 # ifdef MACOS_X
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2170 /* remove "MacOS" from exe_name and add "Resources/vim" */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2171 if (p == exe_name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2172 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2173 char_u *pend1;
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2174 char_u *pnew;
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2175
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2176 pend1 = remove_tail(p, pend, (char_u *)"MacOS");
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2177 if (pend1 != pend)
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2178 {
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16738
diff changeset
2179 pnew = alloc(pend1 - p + 15);
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2180 if (pnew != NULL)
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2181 {
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2182 STRNCPY(pnew, p, (pend1 - p));
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2183 STRCPY(pnew + (pend1 - p), "Resources/vim");
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2184 p = pnew;
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2185 pend = p + STRLEN(p);
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2186 }
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2187 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2188 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2189 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2190 /* remove "src/" from exe_name, if present */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2191 if (p == exe_name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2192 pend = remove_tail(p, pend, (char_u *)"src");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2193 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195 /* for $VIM, remove "runtime/" or "vim54/", if present */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2196 if (!vimruntime)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2197 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2198 pend = remove_tail(p, pend, (char_u *)RUNTIME_DIRNAME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 pend = remove_tail(p, pend, (char_u *)VIM_VERSION_NODOT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2202 /* remove trailing path separator */
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2203 if (pend > p && after_pathsep(p, pend))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2204 --pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2205
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2206 #ifdef MACOS_X
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2207 if (p == exe_name || p == p_hf)
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2208 #endif
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2209 /* check that the result is a directory name */
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
2210 p = vim_strnsave(p, (int)(pend - p));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 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
2213 VIM_CLEAR(p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2214 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2215 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 #ifdef USE_EXE_NAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217 /* may add "/vim54" or "/runtime" if it exists */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 if (vimruntime && (pend = vim_version_dir(p)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2219 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2220 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 p = pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2222 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2223 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2224 *mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 #ifdef HAVE_PATHDEF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 /* When there is a pathdef.c file we can use default_vim_dir and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 * default_vimruntime_dir */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 /* Only use default_vimruntime_dir when it is not empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 if (vimruntime && *default_vimruntime_dir != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 p = default_vimruntime_dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 *mustfree = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240 else if (*default_vim_dir != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2242 if (vimruntime && (p = vim_version_dir(default_vim_dir)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 *mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 p = default_vim_dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247 *mustfree = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2248 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2249 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 * Set the environment variable, so that the new value can be found fast
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255 * next time, and others can also use it (e.g. Perl).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 if (vimruntime)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2261 vim_setenv((char_u *)"VIMRUNTIME", p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 didset_vimruntime = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266 vim_setenv((char_u *)"VIM", p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 didset_vim = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2270 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2273 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 * Check if the directory "vimdir/<version>" or "vimdir/runtime" exists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275 * Return NULL if not, return its name in allocated memory otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2276 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 static char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2278 vim_version_dir(char_u *vimdir)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2279 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2280 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282 if (vimdir == NULL || *vimdir == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284 p = concat_fnames(vimdir, (char_u *)VIM_VERSION_NODOT, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 if (p != NULL && mch_isdir(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 p = concat_fnames(vimdir, (char_u *)RUNTIME_DIRNAME, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 if (p != NULL && mch_isdir(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2292 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2295 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296 * If the string between "p" and "pend" ends in "name/", return "pend" minus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297 * the length of "name/". Otherwise return "pend".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 static char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2300 remove_tail(char_u *p, char_u *pend, char_u *name)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2301 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2302 int len = (int)STRLEN(name) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2303 char_u *newend = pend - len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305 if (newend >= p
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306 && fnamencmp(newend, name, len - 1) == 0
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2307 && (newend == p || after_pathsep(p, newend)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308 return newend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2309 return pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2310 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
2312 #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
2313 void
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
2314 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
2315 {
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
2316 #ifdef HAVE_UNSETENV
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
2317 unsetenv((char *)var);
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
2318 #else
13942
a039c93f5ff7 patch 8.0.1841: HP-UX does not have setenv()
Christian Brabandt <cb@256bit.org>
parents: 13923
diff changeset
2319 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
2320 #endif
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
2321 }
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
2322 #endif
13923
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
2323
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
2324
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326 * Our portable version of setenv.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2329 vim_setenv(char_u *name, char_u *val)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2331 #ifdef HAVE_SETENV
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2332 mch_setenv((char *)name, (char *)val, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2334 char_u *envbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2336 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2337 * Putenv does not copy the string, it has to remain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338 * valid. The allocated memory will never be freed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339 */
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16738
diff changeset
2340 envbuf = alloc(STRLEN(name) + STRLEN(val) + 2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2341 if (envbuf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2342 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2343 sprintf((char *)envbuf, "%s=%s", name, val);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2344 putenv((char *)envbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2345 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346 #endif
3382
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2347 #ifdef FEAT_GETTEXT
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2348 /*
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2349 * 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
2350 * translations to $VIMRUNTIME/lang.
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2351 */
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2352 if (*val != NUL && STRICMP(name, "VIMRUNTIME") == 0)
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2353 {
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2354 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
2355
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2356 if (buf != NULL)
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2357 {
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2358 bindtextdomain(VIMPACKAGE, (char *)buf);
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2359 vim_free(buf);
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2360 }
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2361 }
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
2362 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2363 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2364
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2365 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2366 * Function given to ExpandGeneric() to obtain an environment variable name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2367 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2368 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2369 get_env_name(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2370 expand_T *xp UNUSED,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2371 int idx)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2372 {
12716
351cf7c67bbe patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
2373 # if defined(AMIGA)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2374 /*
12716
351cf7c67bbe patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
2375 * No environ[] on the Amiga.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2376 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2377 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2378 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2379 # ifndef __WIN32__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2380 /* Borland C++ 5.2 has this in a header file. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2381 extern char **environ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2382 # endif
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
2383 # define ENVNAMELEN 100
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
2384 static char_u name[ENVNAMELEN];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2385 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2386 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2387
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2388 str = (char_u *)environ[idx];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2389 if (str == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2390 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2391
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
2392 for (n = 0; n < ENVNAMELEN - 1; ++n)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2393 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2394 if (str[n] == '=' || str[n] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2395 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2396 name[n] = str[n];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2397 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 name[n] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2399 return name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401 }
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2402
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2403 /*
14698
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2404 * 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
2405 * 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
2406 */
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2407 static void
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2408 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
2409 {
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2410 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
2411 ? vim_strsave(user) : user;
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2412
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2413 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
2414 {
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2415 if (need_copy)
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2416 vim_free(user);
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2417 return;
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2418 }
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2419 ((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
2420 }
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2421
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2422 /*
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2423 * Find all user names for user completion.
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2424 * Done only once and then cached.
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2425 */
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2426 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2427 init_users(void)
4938
bcb84438bb5b updated for version 7.3.1214
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2428 {
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2429 static int lazy_init_done = FALSE;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2430
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2431 if (lazy_init_done)
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2432 return;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2433
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2434 lazy_init_done = TRUE;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2435 ga_init2(&ga_users, sizeof(char_u *), 20);
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2436
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2437 # if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H)
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2438 {
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2439 struct passwd* pw;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2440
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2441 setpwent();
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2442 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
2443 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
2444 endpwent();
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2445 }
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15814
diff changeset
2446 # 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
2447 {
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
2448 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
2449 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
2450
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
2451 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
2452 &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
2453 {
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
2454 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
2455 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
2456
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
2457 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
2458 }
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
2459 }
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2460 # endif
14698
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2461 # if defined(HAVE_GETPWNAM)
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2462 {
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2463 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
2464
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2465 // 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
2466 // 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
2467 // 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
2468 // 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
2469 // 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
2470
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2471 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
2472 {
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2473 int i;
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2474
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2475 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
2476 {
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2477 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
2478
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2479 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
2480 break;
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2481 }
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2482
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2483 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
2484 {
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2485 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
2486
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2487 if (pw != NULL)
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2488 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
2489 }
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2490 }
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2491 }
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
2492 # endif
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2493 }
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2494
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2495 /*
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2496 * 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
2497 */
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2498 char_u*
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2499 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
2500 {
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2501 init_users();
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2502 if (idx < ga_users.ga_len)
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2503 return ((char_u **)ga_users.ga_data)[idx];
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2504 return NULL;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2505 }
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2506
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2507 /*
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2508 * Check whether name matches a user name. Return:
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2509 * 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
2510 * 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
2511 * 2 is name fully matches a user name.
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2512 */
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
2513 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
2514 match_user(char_u *name)
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2515 {
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2516 int i;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2517 int n = (int)STRLEN(name);
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2518 int result = 0;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2519
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2520 init_users();
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2521 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
2522 {
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2523 if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0)
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2524 return 2; /* full match */
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2525 if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0)
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2526 result = 1; /* partial match */
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2527 }
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
2528 return result;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
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 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2532 * Replace home directory by "~" in each space or comma separated file name in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2533 * 'src'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2534 * If anything fails (except when out of space) dst equals src.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2535 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2536 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2537 home_replace(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2538 buf_T *buf, /* when not NULL, check for help files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2539 char_u *src, /* input file name */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2540 char_u *dst, /* where to put the result */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2541 int dstlen, /* maximum length of the result */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2542 int one) /* if TRUE, only replace one file name, include
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2543 spaces and commas in the file name. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2544 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2545 size_t dirlen = 0, envlen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546 size_t len;
3598
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2547 char_u *homedir_env, *homedir_env_orig;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2548 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2549
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550 if (src == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552 *dst = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2553 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2554 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2555
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2556 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2557 * If the file is a help file, remove the path completely.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2558 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2559 if (buf != NULL && buf->b_help)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2560 {
11989
0aae4df3ed8e patch 8.0.0875: crash with weird command sequence
Christian Brabandt <cb@256bit.org>
parents: 11943
diff changeset
2561 vim_snprintf((char *)dst, dstlen, "%s", gettail(src));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2562 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2563 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2565 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2566 * We check both the value of the $HOME environment variable and the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2567 * "real" home directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2568 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2569 if (homedir != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2570 dirlen = STRLEN(homedir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2571
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2572 #ifdef VMS
3598
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2573 homedir_env_orig = homedir_env = mch_getenv((char_u *)"SYS$LOGIN");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2574 #else
3598
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2575 homedir_env_orig = homedir_env = mch_getenv((char_u *)"HOME");
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2576 #endif
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15814
diff changeset
2577 #ifdef MSWIN
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
2578 if (homedir_env == 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
2579 homedir_env_orig = homedir_env = 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
2580 #endif
3658
e82937b753a8 updated for version 7.3.589
Bram Moolenaar <bram@vim.org>
parents: 3632
diff changeset
2581 /* Empty is the same as not set. */
e82937b753a8 updated for version 7.3.589
Bram Moolenaar <bram@vim.org>
parents: 3632
diff changeset
2582 if (homedir_env != NULL && *homedir_env == NUL)
e82937b753a8 updated for version 7.3.589
Bram Moolenaar <bram@vim.org>
parents: 3632
diff changeset
2583 homedir_env = NULL;
e82937b753a8 updated for version 7.3.589
Bram Moolenaar <bram@vim.org>
parents: 3632
diff changeset
2584
4752
77ecab3bb207 updated for version 7.3.1123
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
2585 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL)
15308
d7a8f390f6d2 patch 8.1.0662: needlessly searching for tilde in string
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2586 if (homedir_env != NULL && *homedir_env == '~')
3598
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2587 {
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2588 int usedlen = 0;
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2589 int flen;
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2590 char_u *fbuf = NULL;
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2591
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2592 flen = (int)STRLEN(homedir_env);
14393
c62601adad69 patch 8.1.0211: expanding a file name "~" results in $HOME
Christian Brabandt <cb@256bit.org>
parents: 14286
diff changeset
2593 (void)modify_fname((char_u *)":p", FALSE, &usedlen,
3608
683de9306096 updated for version 7.3.564
Bram Moolenaar <bram@vim.org>
parents: 3598
diff changeset
2594 &homedir_env, &fbuf, &flen);
3598
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2595 flen = (int)STRLEN(homedir_env);
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2596 if (flen > 0 && vim_ispathsep(homedir_env[flen - 1]))
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2597 /* Remove the trailing / that is added to a directory. */
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2598 homedir_env[flen - 1] = NUL;
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2599 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2600 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2601
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2602 if (homedir_env != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2603 envlen = STRLEN(homedir_env);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2604
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2605 if (!one)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2606 src = skipwhite(src);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2607 while (*src && dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2608 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2609 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2610 * Here we are at the beginning of a file name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2611 * First, check to see if the beginning of the file name matches
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2612 * $HOME or the "real" home directory. Check that there is a '/'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2613 * after the match (so that if e.g. the file is "/home/pieter/bla",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2614 * and the home directory is "/home/piet", the file does not end up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2615 * as "~er/bla" (which would seem to indicate the file "bla" in user
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2616 * er's home directory)).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2617 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2618 p = homedir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2619 len = dirlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2620 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2621 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2622 if ( len
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2623 && fnamencmp(src, p, len) == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2624 && (vim_ispathsep(src[len])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2625 || (!one && (src[len] == ',' || src[len] == ' '))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2626 || src[len] == NUL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2627 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2628 src += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2629 if (--dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2630 *dst++ = '~';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2631
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2632 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2633 * If it's just the home directory, add "/".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2634 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2635 if (!vim_ispathsep(src[0]) && --dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2636 *dst++ = '/';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2637 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2638 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2639 if (p == homedir_env)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2640 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2641 p = homedir_env;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2642 len = envlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2643 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2644
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2645 /* if (!one) skip to separator: space or comma */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2646 while (*src && (one || (*src != ',' && *src != ' ')) && --dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2647 *dst++ = *src++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2648 /* skip separator */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2649 while ((*src == ' ' || *src == ',') && --dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2650 *dst++ = *src++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2651 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2652 /* if (dstlen == 0) out of space, what to do??? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2653
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2654 *dst = NUL;
3598
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2655
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2656 if (homedir_env != homedir_env_orig)
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
2657 vim_free(homedir_env);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2658 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2659
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2660 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2661 * Like home_replace, store the replaced string in allocated memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2662 * When something fails, NULL is returned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2663 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2664 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2665 home_replace_save(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2666 buf_T *buf, /* when not NULL, check for help files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2667 char_u *src) /* input file name */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2668 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2669 char_u *dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2670 unsigned len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2671
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2672 len = 3; /* space for "~/" and trailing NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2673 if (src != NULL) /* just in case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2674 len += (unsigned)STRLEN(src);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2675 dst = alloc(len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2676 if (dst != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2677 home_replace(buf, src, dst, len, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2678 return dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2679 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2680
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2681 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2682 * Compare two file names and return:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2683 * FPC_SAME if they both exist and are the same file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2684 * FPC_SAMEX if they both don't exist and have the same file name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2685 * FPC_DIFF if they both exist and are different files.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2686 * FPC_NOTX if they both don't exist.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2687 * FPC_DIFFX if one of them doesn't exist.
16738
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2688 * For the first name environment variables are expanded if "expandenv" is
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2689 * TRUE.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2690 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2691 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2692 fullpathcmp(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2693 char_u *s1,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2694 char_u *s2,
16738
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2695 int checkname, // when both don't exist, check file names
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2696 int expandenv)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2697 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2698 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2699 char_u exp1[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2700 char_u full1[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2701 char_u full2[MAXPATHL];
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9225
diff changeset
2702 stat_T st1, st2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2703 int r1, r2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2704
16738
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2705 if (expandenv)
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2706 expand_env(s1, exp1, MAXPATHL);
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2707 else
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2708 vim_strncpy(exp1, s1, MAXPATHL - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2709 r1 = mch_stat((char *)exp1, &st1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2710 r2 = mch_stat((char *)s2, &st2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2711 if (r1 != 0 && r2 != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2712 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2713 /* if mch_stat() doesn't work, may compare the names */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2714 if (checkname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2715 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2716 if (fnamecmp(exp1, s2) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2717 return FPC_SAMEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2718 r1 = vim_FullName(exp1, full1, MAXPATHL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2719 r2 = vim_FullName(s2, full2, MAXPATHL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2720 if (r1 == OK && r2 == OK && fnamecmp(full1, full2) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2721 return FPC_SAMEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2722 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2723 return FPC_NOTX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2724 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2725 if (r1 != 0 || r2 != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2726 return FPC_DIFFX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2727 if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2728 return FPC_SAME;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2729 return FPC_DIFF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2730 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2731 char_u *exp1; /* expanded s1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2732 char_u *full1; /* full path of s1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2733 char_u *full2; /* full path of s2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2734 int retval = FPC_DIFF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2735 int r1, r2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2736
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2737 /* allocate one buffer to store three paths (alloc()/free() is slow!) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2738 if ((exp1 = alloc(MAXPATHL * 3)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2739 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2740 full1 = exp1 + MAXPATHL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2741 full2 = full1 + MAXPATHL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2742
16738
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2743 if (expandenv)
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2744 expand_env(s1, exp1, MAXPATHL);
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2745 else
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2746 vim_strncpy(exp1, s1, MAXPATHL - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2747 r1 = vim_FullName(exp1, full1, MAXPATHL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2748 r2 = vim_FullName(s2, full2, MAXPATHL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2749
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2750 /* If vim_FullName() fails, the file probably doesn't exist. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2751 if (r1 != OK && r2 != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2752 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2753 if (checkname && fnamecmp(exp1, s2) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2754 retval = FPC_SAMEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2755 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2756 retval = FPC_NOTX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2757 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2758 else if (r1 != OK || r2 != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2759 retval = FPC_DIFFX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2760 else if (fnamecmp(full1, full2))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2761 retval = FPC_DIFF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2762 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2763 retval = FPC_SAME;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2764 vim_free(exp1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2765 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2766 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2767 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2768 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2770 /*
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
2771 * Get the tail of a path: the file name.
2549
c210e31a2ec5 More fixes for :find completion. (mostly by Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2542
diff changeset
2772 * When the path ends in a path separator the tail is the NUL after it.
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
2773 * Fail safe: never returns NULL.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2774 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2775 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2776 gettail(char_u *fname)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2777 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2778 char_u *p1, *p2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2779
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2780 if (fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2781 return (char_u *)"";
5432
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2782 for (p1 = p2 = get_past_head(fname); *p2; ) /* find last part of path */
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2783 {
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2784 if (vim_ispathsep_nocolon(*p2))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2785 p1 = p2 + 1;
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
2786 MB_PTR_ADV(p2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2787 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2788 return p1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2789 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2790
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2791 /*
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2792 * Get pointer to tail of "fname", including path separators. Putting a NUL
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2793 * here leaves the directory name. Takes care of "c:/" and "//".
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2794 * Always returns a valid pointer.
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2795 */
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2796 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2797 gettail_sep(char_u *fname)
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2798 {
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2799 char_u *p;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2800 char_u *t;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2801
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2802 p = get_past_head(fname); /* don't remove the '/' from "c:/file" */
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2803 t = gettail(fname);
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2804 while (t > p && after_pathsep(fname, t))
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2805 --t;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2806 #ifdef VMS
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2807 /* path separator is part of the path */
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2808 ++t;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2809 #endif
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2810 return t;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2811 }
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2812
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2813 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2814 * get the next path component (just after the next path separator).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2815 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2816 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2817 getnextcomp(char_u *fname)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2818 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2819 while (*fname && !vim_ispathsep(*fname))
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
2820 MB_PTR_ADV(fname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2821 if (*fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2822 ++fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2823 return fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2824 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2825
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2826 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2827 * Get a pointer to one character past the head of a path name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2828 * Unix: after "/"; DOS: after "c:\"; Amiga: after "disk:/"; Mac: no head.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2829 * If there is no head, path is returned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2830 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2831 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2832 get_past_head(char_u *path)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2833 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2834 char_u *retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2835
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
2836 #if defined(MSWIN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2837 /* may skip "c:" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2838 if (isalpha(path[0]) && path[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2839 retval = path + 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2840 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2841 retval = path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2842 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2843 # if defined(AMIGA)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2844 /* may skip "label:" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2845 retval = vim_strchr(path, ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2846 if (retval == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2847 retval = path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2848 # else /* Unix */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2849 retval = path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2850 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2851 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2852
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2853 while (vim_ispathsep(*retval))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2854 ++retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2855
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2856 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2857 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2858
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2859 /*
5432
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2860 * Return TRUE if 'c' is a path separator.
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2861 * Note that for MS-Windows this includes the colon.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2862 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2863 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2864 vim_ispathsep(int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2865 {
2823
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
2866 #ifdef UNIX
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2867 return (c == '/'); /* UNIX has ':' inside file names */
2823
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
2868 #else
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
2869 # ifdef BACKSLASH_IN_FILENAME
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2870 return (c == ':' || c == '/' || c == '\\');
2823
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
2871 # else
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
2872 # ifdef VMS
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2873 /* server"user passwd"::device:[full.path.name]fname.extension;version" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2874 return (c == ':' || c == '[' || c == ']' || c == '/'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2875 || c == '<' || c == '>' || c == '"' );
2823
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
2876 # else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2877 return (c == ':' || c == '/');
2823
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
2878 # endif /* VMS */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2879 # endif
2823
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
2880 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2881 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2882
5432
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2883 /*
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2884 * Like vim_ispathsep(c), but exclude the colon for MS-Windows.
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2885 */
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2886 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2887 vim_ispathsep_nocolon(int c)
5432
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2888 {
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2889 return vim_ispathsep(c)
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2890 #ifdef BACKSLASH_IN_FILENAME
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2891 && c != ':'
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2892 #endif
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2893 ;
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2894 }
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2895
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2896 /*
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2897 * Shorten the path of a file from "~/foo/../.bar/fname" to "~/f/../.b/fname"
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2898 * It's done in-place.
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2899 */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2900 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2901 shorten_dir(char_u *str)
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2902 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2903 char_u *tail, *s, *d;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2904 int skip = FALSE;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2905
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2906 tail = gettail(str);
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2907 d = str;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2908 for (s = str; ; ++s)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2909 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2910 if (s >= tail) /* copy the whole tail */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2911 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2912 *d++ = *s;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2913 if (*s == NUL)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2914 break;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2915 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2916 else if (vim_ispathsep(*s)) /* copy '/' and next char */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2917 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2918 *d++ = *s;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2919 skip = FALSE;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2920 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2921 else if (!skip)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2922 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2923 *d++ = *s; /* copy next char */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2924 if (*s != '~' && *s != '.') /* and leading "~" and "." */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2925 skip = TRUE;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2926 if (has_mbyte)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2927 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2928 int l = mb_ptr2len(s);
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2929
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2930 while (--l > 0)
927
6632670ff6fc updated for version 7.0-053
vimboss
parents: 856
diff changeset
2931 *d++ = *++s;
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2932 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2933 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2934 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2935 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2936
594
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2937 /*
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2938 * Return TRUE if the directory of "fname" exists, FALSE otherwise.
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2939 * Also returns TRUE if there is no directory name.
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2940 * "fname" must be writable!.
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2941 */
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2942 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2943 dir_of_file_exists(char_u *fname)
594
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2944 {
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2945 char_u *p;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2946 int c;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2947 int retval;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2948
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2949 p = gettail_sep(fname);
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2950 if (p == fname)
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2951 return TRUE;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2952 c = *p;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2953 *p = NUL;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2954 retval = mch_isdir(fname);
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2955 *p = c;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2956 return retval;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2957 }
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
2958
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
2959 /*
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
2960 * Versions of fnamecmp() and fnamencmp() that handle '/' and '\' equally
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
2961 * and deal with 'fileignorecase'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2962 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2963 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2964 vim_fnamecmp(char_u *x, char_u *y)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2965 {
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
2966 #ifdef BACKSLASH_IN_FILENAME
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2967 return vim_fnamencmp(x, y, MAXPATHL);
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
2968 #else
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
2969 if (p_fic)
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
2970 return MB_STRICMP(x, y);
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
2971 return STRCMP(x, y);
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
2972 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2973 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2974
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2975 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2976 vim_fnamencmp(char_u *x, char_u *y, size_t len)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2977 {
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
2978 #ifdef BACKSLASH_IN_FILENAME
4246
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2979 char_u *px = x;
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2980 char_u *py = y;
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2981 int cx = NUL;
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2982 int cy = NUL;
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2983
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2984 while (len > 0)
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2985 {
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2986 cx = PTR2CHAR(px);
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2987 cy = PTR2CHAR(py);
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2988 if (cx == NUL || cy == NUL
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2989 || ((p_fic ? MB_TOLOWER(cx) != MB_TOLOWER(cy) : cx != cy)
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2990 && !(cx == '/' && cy == '\\')
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2991 && !(cx == '\\' && cy == '/')))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2992 break;
4246
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2993 len -= MB_PTR2LEN(px);
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2994 px += MB_PTR2LEN(px);
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2995 py += MB_PTR2LEN(py);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2996 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2997 if (len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2998 return 0;
4246
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
2999 return (cx - cy);
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
3000 #else
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
3001 if (p_fic)
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
3002 return MB_STRNICMP(x, y, len);
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
3003 return STRNCMP(x, y, len);
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
3004 #endif
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
3005 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3006
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3007 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3008 * Concatenate file names fname1 and fname2 into allocated memory.
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
3009 * Only add a '/' or '\\' when 'sep' is TRUE and it is necessary.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3010 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3011 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3012 concat_fnames(char_u *fname1, char_u *fname2, int sep)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3013 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3014 char_u *dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3015
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16738
diff changeset
3016 dest = alloc(STRLEN(fname1) + STRLEN(fname2) + 3);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3017 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3018 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3019 STRCPY(dest, fname1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3020 if (sep)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3021 add_pathsep(dest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3022 STRCAT(dest, fname2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3023 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3024 return dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3025 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3026
115
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3027 /*
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3028 * Concatenate two strings and return the result in allocated memory.
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3029 * Returns NULL when out of memory.
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3030 */
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3031 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3032 concat_str(char_u *str1, char_u *str2)
115
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3033 {
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3034 char_u *dest;
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3035 size_t l = STRLEN(str1);
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3036
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16738
diff changeset
3037 dest = alloc(l + STRLEN(str2) + 1L);
115
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3038 if (dest != NULL)
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3039 {
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3040 STRCPY(dest, str1);
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3041 STRCPY(dest + l, str2);
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3042 }
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3043 return dest;
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3044 }
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
3045
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3046 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3047 * Add a path separator to a file name, unless it already ends in a path
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3048 * separator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3049 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3050 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3051 add_pathsep(char_u *p)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3052 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
3053 if (*p != NUL && !after_pathsep(p, p + STRLEN(p)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3054 STRCAT(p, PATHSEPSTR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3055 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3056
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3057 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3058 * FullName_save - Make an allocated copy of a full file name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3059 * Returns NULL when out of memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3060 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3061 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3062 FullName_save(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3063 char_u *fname,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3064 int force) /* force expansion, even when it already looks
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
3065 * like a full path name */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3066 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3067 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3068 char_u *new_fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3069
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3070 if (fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3071 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3072
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16738
diff changeset
3073 buf = alloc(MAXPATHL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3074 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3075 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3076 if (vim_FullName(fname, buf, MAXPATHL, force) != FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3077 new_fname = vim_strsave(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3078 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3079 new_fname = vim_strsave(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3080 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3081 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3082 return new_fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3083 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3084
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 17781
diff changeset
3085 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3086 prepare_to_exit(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3087 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
3088 #if defined(SIGHUP) && defined(SIG_IGN)
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
3089 /* Ignore SIGHUP, because a dropped connection causes a read error, which
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
3090 * makes Vim exit and then handling SIGHUP causes various reentrance
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
3091 * problems. */
36
125e80798a85 updated for version 7.0021
vimboss
parents: 24
diff changeset
3092 signal(SIGHUP, SIG_IGN);
125e80798a85 updated for version 7.0021
vimboss
parents: 24
diff changeset
3093 #endif
125e80798a85 updated for version 7.0021
vimboss
parents: 24
diff changeset
3094
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3095 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3096 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3097 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3098 gui.dying = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3099 out_trash(); /* trash any pending output */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3100 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3101 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3102 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3103 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3104 windgoto((int)Rows - 1, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3106 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3107 * Switch terminal mode back now, so messages end up on the "normal"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3108 * screen (if there are two screens).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3109 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3110 settmode(TMODE_COOK);
10264
c036c0f636d5 commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents: 10180
diff changeset
3111 stoptermcap();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3112 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3113 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3114 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3116 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3117 * Preserve files and exit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3118 * When called IObuff must contain a message.
5338
965044860b7f updated for version 7.4.022
Bram Moolenaar <bram@vim.org>
parents: 5275
diff changeset
3119 * 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
3120 * functions, such as allocating memory.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3121 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3122 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3123 preserve_exit(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3124 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3125 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3127 prepare_to_exit();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3128
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 613
diff changeset
3129 /* Setting this will prevent free() calls. That avoids calling free()
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 613
diff changeset
3130 * recursively when free() was invoked with a bad pointer. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 613
diff changeset
3131 really_exiting = TRUE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 613
diff changeset
3132
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3133 out_str(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3134 screen_start(); /* don't know where cursor is now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3135 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3137 ml_close_notmod(); /* close all not-modified buffers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3138
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9536
diff changeset
3139 FOR_ALL_BUFFERS(buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3140 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3141 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
3142 {
5338
965044860b7f updated for version 7.4.022
Bram Moolenaar <bram@vim.org>
parents: 5275
diff changeset
3143 OUT_STR("Vim: preserving files...\n");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3144 screen_start(); /* don't know where cursor is now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3145 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3146 ml_sync_all(FALSE, FALSE); /* preserve all swap files */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3147 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3148 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3149 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3151 ml_close_all(FALSE); /* close all memfiles, without deleting */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3152
5338
965044860b7f updated for version 7.4.022
Bram Moolenaar <bram@vim.org>
parents: 5275
diff changeset
3153 OUT_STR("Vim: Finished.\n");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3154
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3155 getout(1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3156 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3157
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3158 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3159 * return TRUE if "fname" exists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3160 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3161 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3162 vim_fexists(char_u *fname)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3163 {
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9225
diff changeset
3164 stat_T st;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3165
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3166 if (mch_stat((char *)fname, &st))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3167 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3168 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3169 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3171 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3172 * Check for CTRL-C pressed, but only once in a while.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3173 * Should be used instead of ui_breakcheck() for functions that check for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3174 * each line in the file. Calling ui_breakcheck() each time takes too much
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3175 * time, because it can be a system call.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3176 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3177
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3178 #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
3179 # define BREAKCHECK_SKIP 1000
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3180 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3181
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3182 static int breakcheck_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3183
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3184 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3185 line_breakcheck(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3186 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3187 if (++breakcheck_count >= BREAKCHECK_SKIP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3188 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3189 breakcheck_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3190 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3191 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3192 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3193
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3194 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3195 * Like line_breakcheck() but check 10 times less often.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3196 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3197 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3198 fast_breakcheck(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3199 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3200 if (++breakcheck_count >= BREAKCHECK_SKIP * 10)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3201 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3202 breakcheck_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3203 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3204 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3205 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3207 /*
2016
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3208 * Invoke expand_wildcards() for one pattern.
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3209 * Expand items like "%:h" before the expansion.
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3210 * Returns OK or FAIL.
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3211 */
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3212 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3213 expand_wildcards_eval(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3214 char_u **pat, /* pointer to input pattern */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3215 int *num_file, /* resulting number of files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3216 char_u ***file, /* array of resulting files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3217 int flags) /* EW_DIR, etc. */
2016
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3218 {
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3219 int ret = FAIL;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3220 char_u *eval_pat = NULL;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3221 char_u *exp_pat = *pat;
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15420
diff changeset
3222 char *ignored_msg;
2016
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3223 int usedlen;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3224
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3225 if (*exp_pat == '%' || *exp_pat == '#' || *exp_pat == '<')
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3226 {
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3227 ++emsg_off;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3228 eval_pat = eval_vars(exp_pat, exp_pat, &usedlen,
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3229 NULL, &ignored_msg, NULL);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3230 --emsg_off;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3231 if (eval_pat != NULL)
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3232 exp_pat = concat_str(eval_pat, exp_pat + usedlen);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3233 }
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3234
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3235 if (exp_pat != NULL)
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3236 ret = expand_wildcards(1, &exp_pat, num_file, file, flags);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3237
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3238 if (eval_pat != NULL)
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3239 {
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3240 vim_free(exp_pat);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3241 vim_free(eval_pat);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3242 }
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3243
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3244 return ret;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3245 }
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3246
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
3247 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3248 * Expand wildcards. Calls gen_expand_wildcards() and removes files matching
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3249 * 'wildignore'.
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3250 * Returns OK or FAIL. When FAIL then "num_files" won't be set.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3251 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3252 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3253 expand_wildcards(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3254 int num_pat, /* number of input patterns */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3255 char_u **pat, /* array of input patterns */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3256 int *num_files, /* resulting number of files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3257 char_u ***files, /* array of resulting files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3258 int flags) /* EW_DIR, etc. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3259 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3260 int retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3261 int i, j;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3262 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3263 int non_suf_match; /* number without matching suffix */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3264
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3265 retval = gen_expand_wildcards(num_pat, pat, num_files, files, flags);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3266
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3267 /* When keeping all matches, return here */
2354
f4440cdd59ae Fixed: crash with ":find " completion, using uninitialized count.
Bram Moolenaar <bram@vim.org>
parents: 2328
diff changeset
3268 if ((flags & EW_KEEPALL) || retval == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3269 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3271 #ifdef FEAT_WILDIGN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3272 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3273 * Remove names that match 'wildignore'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3274 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3275 if (*p_wig)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3276 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3277 char_u *ffname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3278
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3279 /* check all files in (*files)[] */
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3280 for (i = 0; i < *num_files; ++i)
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3281 {
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3282 ffname = FullName_save((*files)[i], FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3283 if (ffname == NULL) /* out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3284 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3285 # ifdef VMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3286 vms_remove_version(ffname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3287 # endif
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3288 if (match_file_list(p_wig, (*files)[i], ffname))
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3289 {
10932
141fe140976c patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents: 10889
diff changeset
3290 /* remove this matching file from the list */
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3291 vim_free((*files)[i]);
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3292 for (j = i; j + 1 < *num_files; ++j)
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3293 (*files)[j] = (*files)[j + 1];
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3294 --*num_files;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3295 --i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3296 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3297 vim_free(ffname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3298 }
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3299
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3300 /* If the number of matches is now zero, we fail. */
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3301 if (*num_files == 0)
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3302 {
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13188
diff changeset
3303 VIM_CLEAR(*files);
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3304 return FAIL;
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3305 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3306 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3307 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3308
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3309 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3310 * Move the names where 'suffixes' match to the end.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3311 */
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3312 if (*num_files > 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3313 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3314 non_suf_match = 0;
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3315 for (i = 0; i < *num_files; ++i)
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3316 {
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3317 if (!match_suffix((*files)[i]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3318 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3319 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3320 * Move the name without matching suffix to the front
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3321 * of the list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3322 */
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3323 p = (*files)[i];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3324 for (j = i; j > non_suf_match; --j)
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3325 (*files)[j] = (*files)[j - 1];
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
3326 (*files)[non_suf_match++] = p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3327 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3328 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3329 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3330
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3331 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3332 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3333
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3334 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3335 * Return TRUE if "fname" matches with an entry in 'suffixes'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3336 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3337 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3338 match_suffix(char_u *fname)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3339 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3340 int fnamelen, setsuflen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3341 char_u *setsuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3342 #define MAXSUFLEN 30 /* maximum length of a file suffix */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3343 char_u suf_buf[MAXSUFLEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3344
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3345 fnamelen = (int)STRLEN(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3346 setsuflen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3347 for (setsuf = p_su; *setsuf; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3348 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3349 setsuflen = copy_option_part(&setsuf, suf_buf, MAXSUFLEN, ".,");
1937
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3350 if (setsuflen == 0)
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3351 {
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3352 char_u *tail = gettail(fname);
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3353
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3354 /* empty entry: match name without a '.' */
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3355 if (vim_strchr(tail, '.') == NULL)
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3356 {
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3357 setsuflen = 1;
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3358 break;
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3359 }
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3360 }
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3361 else
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3362 {
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3363 if (fnamelen >= setsuflen
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3364 && fnamencmp(suf_buf, fname + fnamelen - setsuflen,
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3365 (size_t)setsuflen) == 0)
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3366 break;
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3367 setsuflen = 0;
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
3368 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3369 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3370 return (setsuflen != 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3371 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3373 #if !defined(NO_EXPANDPATH) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3374
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3375 # ifdef VIM_BACKTICK
7803
37c929c4a073 commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents: 7641
diff changeset
3376 static int vim_backtick(char_u *p);
37c929c4a073 commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents: 7641
diff changeset
3377 static int expand_backtick(garray_T *gap, char_u *pat, int flags);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3378 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3379
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15814
diff changeset
3380 # if defined(MSWIN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3381 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3382 * File name expansion code for MS-DOS, Win16 and Win32. It's here because
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3383 * it's shared between these systems.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3384 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3385
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3386 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3387 * comparison function for qsort in dos_expandpath()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3388 */
16606
7e733046db1d patch 8.1.1306: Borland support is outdated and doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 16277
diff changeset
3389 static int
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3390 pstrcmp(const void *a, const void *b)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3391 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
3392 return (pathcmp(*(char **)a, *(char **)b, -1));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3393 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3394
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3395 /*
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3396 * Recursively expand one path component into all matching files and/or
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3397 * directories. Adds matches to "gap". Handles "*", "?", "[a-z]", "**", etc.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3398 * Return the number of matches found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3399 * "path" has backslashes before chars that are not to be expanded, starting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3400 * at "path[wildoff]".
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3401 * Return the number of matches found.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3402 * NOTE: much of this is identical to unix_expandpath(), keep in sync!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3403 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3404 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3405 dos_expandpath(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3406 garray_T *gap,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3407 char_u *path,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3408 int wildoff,
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3409 int flags, /* EW_* flags */
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
3410 int didstar) /* expanded "**" once already */
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3411 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3412 char_u *buf;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3413 char_u *path_end;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3414 char_u *p, *s, *e;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3415 int start_len = gap->ga_len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3416 char_u *pat;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3417 regmatch_T regmatch;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3418 int starts_with_dot;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3419 int matches;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3420 int len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3421 int starstar = FALSE;
16196
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3422 static int stardepth = 0; // depth for "**" expansion
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3423 HANDLE hFind = INVALID_HANDLE_VALUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3424 WIN32_FIND_DATAW wfb;
16196
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3425 WCHAR *wn = NULL; // UCS-2 name, NULL when not used.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3426 char_u *matchname;
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3427 int ok;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3428
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3429 /* Expanding "**" may take a long time, check for CTRL-C. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3430 if (stardepth > 0)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3431 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3432 ui_breakcheck();
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3433 if (got_int)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3434 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3435 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3436
15597
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
3437 // Make room for file name. When doing encoding conversion the actual
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
3438 // length may be quite a bit longer, thus use the maximum possible length.
16782
fc58fee685e2 patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
3439 buf = alloc(MAXPATHL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3440 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3441 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3442
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3443 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3444 * Find the first part in the path name that contains a wildcard or a ~1.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3445 * Copy it into buf, including the preceding characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3446 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3447 p = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3448 s = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3449 e = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3450 path_end = path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3451 while (*path_end != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3452 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3453 /* May ignore a wildcard that has a backslash before it; it will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3454 * be removed by rem_backslash() or file_pat_to_reg_pat() below. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3455 if (path_end >= path + wildoff && rem_backslash(path_end))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3456 *p++ = *path_end++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3457 else if (*path_end == '\\' || *path_end == ':' || *path_end == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3458 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3459 if (e != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3460 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3461 s = p + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3462 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3463 else if (path_end >= path + wildoff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3464 && vim_strchr((char_u *)"*?[~", *path_end) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3465 e = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3466 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3467 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
3468 len = (*mb_ptr2len)(path_end);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3469 STRNCPY(p, path_end, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3470 p += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3471 path_end += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3472 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3473 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3474 *p++ = *path_end++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3475 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3476 e = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3477 *e = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3478
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3479 /* now we have one wildcard component between s and e */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3480 /* Remove backslashes between "wildoff" and the start of the wildcard
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3481 * component. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3482 for (p = buf + wildoff; p < s; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3483 if (rem_backslash(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3484 {
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1617
diff changeset
3485 STRMOVE(p, p + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3486 --e;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3487 --s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3488 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3489
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3490 /* Check for "**" between "s" and "e". */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3491 for (p = s; p < e; ++p)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3492 if (p[0] == '*' && p[1] == '*')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3493 starstar = TRUE;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3494
7635
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
3495 starts_with_dot = *s == '.';
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3496 pat = file_pat_to_reg_pat(s, e, NULL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3497 if (pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3498 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3499 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3500 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3501 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3502
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3503 /* compile the regexp into a program */
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
3504 if (flags & (EW_NOERROR | EW_NOTWILD))
2966
aa998de9f959 updated for version 7.3.255
Bram Moolenaar <bram@vim.org>
parents: 2953
diff changeset
3505 ++emsg_silent;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3506 regmatch.rm_ic = TRUE; /* Always ignore case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3507 regmatch.regprog = vim_regcomp(pat, RE_MAGIC);
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
3508 if (flags & (EW_NOERROR | EW_NOTWILD))
2966
aa998de9f959 updated for version 7.3.255
Bram Moolenaar <bram@vim.org>
parents: 2953
diff changeset
3509 --emsg_silent;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3510 vim_free(pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3511
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
3512 if (regmatch.regprog == NULL && (flags & EW_NOTWILD) == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3513 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3514 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3515 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3516 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3517
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3518 /* remember the pattern or file name being looked for */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3519 matchname = vim_strsave(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3520
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3521 /* If "**" is by itself, this is the first time we encounter it and more
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3522 * is following then find matches without any directory. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3523 if (!didstar && stardepth < 100 && starstar && e - s == 2
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3524 && *path_end == '/')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3525 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3526 STRCPY(s, path_end + 1);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3527 ++stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3528 (void)dos_expandpath(gap, buf, (int)(s - buf), flags, TRUE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3529 --stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3530 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3531
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3532 /* Scan all files in the directory with "dir/ *.*" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3533 STRCPY(s, "*.*");
16196
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3534 wn = enc_to_utf16(buf, NULL);
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3535 if (wn != NULL)
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3536 hFind = FindFirstFileW(wn, &wfb);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3537 ok = (hFind != INVALID_HANDLE_VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3538
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3539 while (ok)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3540 {
16196
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3541 p = utf16_to_enc(wfb.cFileName, NULL); // p is allocated here
16231
0761a4c111a7 patch 8.1.1120: cannot easily get directory entry matches
Bram Moolenaar <Bram@vim.org>
parents: 16196
diff changeset
3542 if (p == NULL)
0761a4c111a7 patch 8.1.1120: cannot easily get directory entry matches
Bram Moolenaar <Bram@vim.org>
parents: 16196
diff changeset
3543 break; // out of memory
0761a4c111a7 patch 8.1.1120: cannot easily get directory entry matches
Bram Moolenaar <Bram@vim.org>
parents: 16196
diff changeset
3544
16196
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3545 // Ignore entries starting with a dot, unless when asked for. Accept
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3546 // all entries found with "matchname".
7635
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
3547 if ((p[0] != '.' || starts_with_dot
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
3548 || ((flags & EW_DODOT)
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
3549 && p[1] != NUL && (p[1] != '.' || p[2] != NUL)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3550 && (matchname == NULL
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
3551 || (regmatch.regprog != NULL
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
3552 && vim_regexec(&regmatch, p, (colnr_T)0))
2984
aa40bddeea9a updated for version 7.3.264
Bram Moolenaar <bram@vim.org>
parents: 2966
diff changeset
3553 || ((flags & EW_NOTWILD)
aa40bddeea9a updated for version 7.3.264
Bram Moolenaar <bram@vim.org>
parents: 2966
diff changeset
3554 && fnamencmp(path + (s - buf), p, e - s) == 0)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3555 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3556 STRCPY(s, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3557 len = (int)STRLEN(buf);
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3558
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3559 if (starstar && stardepth < 100)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3560 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3561 /* For "**" in the pattern first go deeper in the tree to
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3562 * find matches. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3563 STRCPY(buf + len, "/**");
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3564 STRCPY(buf + len + 3, path_end);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3565 ++stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3566 (void)dos_expandpath(gap, buf, len + 1, flags, TRUE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3567 --stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3568 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3569
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3570 STRCPY(buf + len, path_end);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3571 if (mch_has_exp_wildcard(path_end))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3572 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3573 /* need to expand another component of the path */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3574 /* remove backslashes for the remaining components only */
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3575 (void)dos_expandpath(gap, buf, len + 1, flags, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3576 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3577 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3578 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3579 /* no more wildcards, check if there is a match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3580 /* remove backslashes for the remaining components only */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3581 if (*path_end != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3582 backslash_halve(buf + len + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3583 if (mch_getperm(buf) >= 0) /* add existing file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3584 addfile(gap, buf, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3585 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3586 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3587
16196
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3588 vim_free(p);
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3589 ok = FindNextFileW(hFind, &wfb);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3590
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3591 /* If no more matches and no match was used, try expanding the name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3592 * itself. Finds the long name of a short filename. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3593 if (!ok && matchname != NULL && gap->ga_len == start_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3594 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3595 STRCPY(s, matchname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3596 FindClose(hFind);
16196
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3597 vim_free(wn);
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3598 wn = enc_to_utf16(buf, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3599 if (wn != NULL)
16196
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3600 hFind = FindFirstFileW(wn, &wfb);
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3601 else
973070a30381 patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 16172
diff changeset
3602 hFind = INVALID_HANDLE_VALUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3603 ok = (hFind != INVALID_HANDLE_VALUE);
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13188
diff changeset
3604 VIM_CLEAR(matchname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3605 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3606 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3607
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3608 FindClose(hFind);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3609 vim_free(wn);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3610 vim_free(buf);
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4752
diff changeset
3611 vim_regfree(regmatch.regprog);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3612 vim_free(matchname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3613
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3614 matches = gap->ga_len - start_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3615 if (matches > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3616 qsort(((char_u **)gap->ga_data) + start_len, (size_t)matches,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3617 sizeof(char_u *), pstrcmp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3618 return matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3619 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3620
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3621 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3622 mch_expandpath(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3623 garray_T *gap,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3624 char_u *path,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3625 int flags) /* EW_* flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3626 {
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3627 return dos_expandpath(gap, path, 0, flags, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3628 }
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15814
diff changeset
3629 # endif // MSWIN
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3630
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3631 #if (defined(UNIX) && !defined(VMS)) || defined(USE_UNIXFILENAME) \
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3632 || defined(PROTO)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3633 /*
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3634 * Unix style wildcard expansion code.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3635 * It's here because it's used both for Unix and Mac.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3636 */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3637 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3638 pstrcmp(const void *a, const void *b)
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3639 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3640 return (pathcmp(*(char **)a, *(char **)b, -1));
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3641 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3642
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3643 /*
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3644 * Recursively expand one path component into all matching files and/or
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3645 * directories. Adds matches to "gap". Handles "*", "?", "[a-z]", "**", etc.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3646 * "path" has backslashes before chars that are not to be expanded, starting
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3647 * at "path + wildoff".
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3648 * Return the number of matches found.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3649 * NOTE: much of this is identical to dos_expandpath(), keep in sync!
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3650 */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3651 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3652 unix_expandpath(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3653 garray_T *gap,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3654 char_u *path,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3655 int wildoff,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3656 int flags, /* EW_* flags */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3657 int didstar) /* expanded "**" once already */
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3658 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3659 char_u *buf;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3660 char_u *path_end;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3661 char_u *p, *s, *e;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3662 int start_len = gap->ga_len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3663 char_u *pat;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3664 regmatch_T regmatch;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3665 int starts_with_dot;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3666 int matches;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3667 int len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3668 int starstar = FALSE;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3669 static int stardepth = 0; /* depth for "**" expansion */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3670
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3671 DIR *dirp;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3672 struct dirent *dp;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3673
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3674 /* Expanding "**" may take a long time, check for CTRL-C. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3675 if (stardepth > 0)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3676 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3677 ui_breakcheck();
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3678 if (got_int)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3679 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3680 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3681
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3682 /* make room for file name */
16782
fc58fee685e2 patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
3683 buf = alloc(STRLEN(path) + BASENAMELEN + 5);
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3684 if (buf == NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3685 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3686
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3687 /*
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3688 * Find the first part in the path name that contains a wildcard.
3505
6c318419e331 updated for version 7.3.515
Bram Moolenaar <bram@vim.org>
parents: 3461
diff changeset
3689 * When EW_ICASE is set every letter is considered to be a wildcard.
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3690 * Copy it into "buf", including the preceding characters.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3691 */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3692 p = buf;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3693 s = buf;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3694 e = NULL;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3695 path_end = path;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3696 while (*path_end != NUL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3697 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3698 /* May ignore a wildcard that has a backslash before it; it will
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3699 * be removed by rem_backslash() or file_pat_to_reg_pat() below. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3700 if (path_end >= path + wildoff && rem_backslash(path_end))
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3701 *p++ = *path_end++;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3702 else if (*path_end == '/')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3703 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3704 if (e != NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3705 break;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3706 s = p + 1;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3707 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3708 else if (path_end >= path + wildoff
3505
6c318419e331 updated for version 7.3.515
Bram Moolenaar <bram@vim.org>
parents: 3461
diff changeset
3709 && (vim_strchr((char_u *)"*?[{~$", *path_end) != NULL
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
3710 || (!p_fic && (flags & EW_ICASE)
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
3711 && isalpha(PTR2CHAR(path_end)))))
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3712 e = p;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3713 if (has_mbyte)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3714 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
3715 len = (*mb_ptr2len)(path_end);
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3716 STRNCPY(p, path_end, len);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3717 p += len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3718 path_end += len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3719 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3720 else
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3721 *p++ = *path_end++;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3722 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3723 e = p;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3724 *e = NUL;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3725
2984
aa40bddeea9a updated for version 7.3.264
Bram Moolenaar <bram@vim.org>
parents: 2966
diff changeset
3726 /* Now we have one wildcard component between "s" and "e". */
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3727 /* Remove backslashes between "wildoff" and the start of the wildcard
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3728 * component. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3729 for (p = buf + wildoff; p < s; ++p)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3730 if (rem_backslash(p))
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3731 {
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1617
diff changeset
3732 STRMOVE(p, p + 1);
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3733 --e;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3734 --s;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3735 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3736
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3737 /* Check for "**" between "s" and "e". */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3738 for (p = s; p < e; ++p)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3739 if (p[0] == '*' && p[1] == '*')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3740 starstar = TRUE;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3741
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3742 /* convert the file pattern to a regexp pattern */
7635
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
3743 starts_with_dot = *s == '.';
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3744 pat = file_pat_to_reg_pat(s, e, NULL, FALSE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3745 if (pat == NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3746 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3747 vim_free(buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3748 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3749 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3750
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3751 /* compile the regexp into a program */
2652
b2a7d143abe2 updated for version 7.3.072
Bram Moolenaar <bram@vim.org>
parents: 2577
diff changeset
3752 if (flags & EW_ICASE)
b2a7d143abe2 updated for version 7.3.072
Bram Moolenaar <bram@vim.org>
parents: 2577
diff changeset
3753 regmatch.rm_ic = TRUE; /* 'wildignorecase' set */
b2a7d143abe2 updated for version 7.3.072
Bram Moolenaar <bram@vim.org>
parents: 2577
diff changeset
3754 else
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
3755 regmatch.rm_ic = p_fic; /* ignore case when 'fileignorecase' is set */
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
3756 if (flags & (EW_NOERROR | EW_NOTWILD))
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
3757 ++emsg_silent;
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3758 regmatch.regprog = vim_regcomp(pat, RE_MAGIC);
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
3759 if (flags & (EW_NOERROR | EW_NOTWILD))
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
3760 --emsg_silent;
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3761 vim_free(pat);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3762
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
3763 if (regmatch.regprog == NULL && (flags & EW_NOTWILD) == 0)
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3764 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3765 vim_free(buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3766 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3767 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3768
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3769 /* If "**" is by itself, this is the first time we encounter it and more
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3770 * is following then find matches without any directory. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3771 if (!didstar && stardepth < 100 && starstar && e - s == 2
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3772 && *path_end == '/')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3773 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3774 STRCPY(s, path_end + 1);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3775 ++stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3776 (void)unix_expandpath(gap, buf, (int)(s - buf), flags, TRUE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3777 --stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3778 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3779
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3780 /* open the directory for scanning */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3781 *s = NUL;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3782 dirp = opendir(*buf == NUL ? "." : (char *)buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3783
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3784 /* Find all matching entries */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3785 if (dirp != NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3786 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3787 for (;;)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3788 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3789 dp = readdir(dirp);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3790 if (dp == NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3791 break;
7635
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
3792 if ((dp->d_name[0] != '.' || starts_with_dot
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
3793 || ((flags & EW_DODOT)
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
3794 && dp->d_name[1] != NUL
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
3795 && (dp->d_name[1] != '.' || dp->d_name[2] != NUL)))
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
3796 && ((regmatch.regprog != NULL && vim_regexec(&regmatch,
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
3797 (char_u *)dp->d_name, (colnr_T)0))
2984
aa40bddeea9a updated for version 7.3.264
Bram Moolenaar <bram@vim.org>
parents: 2966
diff changeset
3798 || ((flags & EW_NOTWILD)
aa40bddeea9a updated for version 7.3.264
Bram Moolenaar <bram@vim.org>
parents: 2966
diff changeset
3799 && fnamencmp(path + (s - buf), dp->d_name, e - s) == 0)))
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3800 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3801 STRCPY(s, dp->d_name);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3802 len = STRLEN(buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3803
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3804 if (starstar && stardepth < 100)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3805 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3806 /* For "**" in the pattern first go deeper in the tree to
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3807 * find matches. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3808 STRCPY(buf + len, "/**");
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3809 STRCPY(buf + len + 3, path_end);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3810 ++stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3811 (void)unix_expandpath(gap, buf, len + 1, flags, TRUE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3812 --stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3813 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3814
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3815 STRCPY(buf + len, path_end);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3816 if (mch_has_exp_wildcard(path_end)) /* handle more wildcards */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3817 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3818 /* need to expand another component of the path */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3819 /* remove backslashes for the remaining components only */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3820 (void)unix_expandpath(gap, buf, len + 1, flags, FALSE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3821 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3822 else
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3823 {
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9225
diff changeset
3824 stat_T sb;
6663
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
3825
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3826 /* no more wildcards, check if there is a match */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3827 /* remove backslashes for the remaining components only */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3828 if (*path_end != NUL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3829 backslash_halve(buf + len + 1);
6663
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
3830 /* add existing file or symbolic link */
6665
9fda0c52db0b updated for version 7.4.657
Bram Moolenaar <bram@vim.org>
parents: 6663
diff changeset
3831 if ((flags & EW_ALLLINKS) ? mch_lstat((char *)buf, &sb) >= 0
6663
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
3832 : mch_getperm(buf) >= 0)
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3833 {
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
3834 #ifdef MACOS_CONVERT
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3835 size_t precomp_len = STRLEN(buf)+1;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3836 char_u *precomp_buf =
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3837 mac_precompose_path(buf, precomp_len, &precomp_len);
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
3838
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3839 if (precomp_buf)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3840 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3841 mch_memmove(buf, precomp_buf, precomp_len);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3842 vim_free(precomp_buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3843 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3844 #endif
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3845 addfile(gap, buf, flags);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3846 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3847 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3848 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3849 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3850
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3851 closedir(dirp);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3852 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3853
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3854 vim_free(buf);
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4752
diff changeset
3855 vim_regfree(regmatch.regprog);
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3856
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3857 matches = gap->ga_len - start_len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3858 if (matches > 0)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3859 qsort(((char_u **)gap->ga_data) + start_len, matches,
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3860 sizeof(char_u *), pstrcmp);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3861 return matches;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3862 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3863 #endif
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
3864
2433
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3865 /*
2559
7850c8c12347 Cleanup in :find completion code. Make it work for "./subdir" in 'path'.
Bram Moolenaar <bram@vim.org>
parents: 2549
diff changeset
3866 * Sort "gap" and remove duplicate entries. "gap" is expected to contain a
7850c8c12347 Cleanup in :find completion code. Make it work for "./subdir" in 'path'.
Bram Moolenaar <bram@vim.org>
parents: 2549
diff changeset
3867 * list of file names in allocated memory.
2433
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3868 */
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3869 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3870 remove_duplicates(garray_T *gap)
2433
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3871 {
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3872 int i;
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3873 int j;
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3874 char_u **fnames = (char_u **)gap->ga_data;
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3875
2559
7850c8c12347 Cleanup in :find completion code. Make it work for "./subdir" in 'path'.
Bram Moolenaar <bram@vim.org>
parents: 2549
diff changeset
3876 sort_strings(fnames, gap->ga_len);
2433
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3877 for (i = gap->ga_len - 1; i > 0; --i)
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3878 if (fnamecmp(fnames[i - 1], fnames[i]) == 0)
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3879 {
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3880 vim_free(fnames[i]);
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3881 for (j = i + 1; j < gap->ga_len; ++j)
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3882 fnames[j - 1] = fnames[j];
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3883 --gap->ga_len;
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3884 }
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3885 }
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
3886
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3887 /*
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3888 * Return TRUE if "p" contains what looks like an environment variable.
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3889 * Allowing for escaping.
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3890 */
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3891 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3892 has_env_var(char_u *p)
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3893 {
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
3894 for ( ; *p; MB_PTR_ADV(p))
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3895 {
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3896 if (*p == '\\' && p[1] != NUL)
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3897 ++p;
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3898 else if (vim_strchr((char_u *)
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
3899 #if defined(MSWIN)
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3900 "$%"
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3901 #else
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3902 "$"
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3903 #endif
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3904 , *p) != NULL)
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3905 return TRUE;
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3906 }
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3907 return FALSE;
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3908 }
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3909
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3910 #ifdef SPECIAL_WILDCHAR
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3911 /*
10932
141fe140976c patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents: 10889
diff changeset
3912 * Return TRUE if "p" contains a special wildcard character, one that Vim
141fe140976c patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents: 10889
diff changeset
3913 * cannot expand, requires using a shell.
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3914 */
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3915 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3916 has_special_wildchar(char_u *p)
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3917 {
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
3918 for ( ; *p; MB_PTR_ADV(p))
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3919 {
16277
5ef25fa57f71 patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents: 16231
diff changeset
3920 // Disallow line break characters.
5ef25fa57f71 patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents: 16231
diff changeset
3921 if (*p == '\r' || *p == '\n')
5ef25fa57f71 patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents: 16231
diff changeset
3922 break;
5ef25fa57f71 patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents: 16231
diff changeset
3923 // Allow for escaping.
5ef25fa57f71 patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents: 16231
diff changeset
3924 if (*p == '\\' && p[1] != NUL && p[1] != '\r' && p[1] != '\n')
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3925 ++p;
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3926 else if (vim_strchr((char_u *)SPECIAL_WILDCHAR, *p) != NULL)
16277
5ef25fa57f71 patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents: 16231
diff changeset
3927 {
5ef25fa57f71 patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents: 16231
diff changeset
3928 // A { must be followed by a matching }.
5ef25fa57f71 patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents: 16231
diff changeset
3929 if (*p == '{' && vim_strchr(p, '}') == NULL)
5ef25fa57f71 patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents: 16231
diff changeset
3930 continue;
5ef25fa57f71 patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents: 16231
diff changeset
3931 // A quote and backtick must be followed by another one.
5ef25fa57f71 patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents: 16231
diff changeset
3932 if ((*p == '`' || *p == '\'') && vim_strchr(p, *p) == NULL)
5ef25fa57f71 patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents: 16231
diff changeset
3933 continue;
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3934 return TRUE;
16277
5ef25fa57f71 patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents: 16231
diff changeset
3935 }
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3936 }
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3937 return FALSE;
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3938 }
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3939 #endif
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3940
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3941 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3942 * Generic wildcard expansion code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3943 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3944 * Characters in "pat" that should not be expanded must be preceded with a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3945 * backslash. E.g., "/path\ with\ spaces/my\*star*"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3946 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3947 * Return FAIL when no single file was found. In this case "num_file" is not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3948 * set, and "file" may contain an error message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3949 * Return OK when some files found. "num_file" is set to the number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3950 * matches, "file" to the array of matches. Call FreeWild() later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3951 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3952 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3953 gen_expand_wildcards(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3954 int num_pat, /* number of input patterns */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3955 char_u **pat, /* array of input patterns */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3956 int *num_file, /* resulting number of files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3957 char_u ***file, /* array of resulting files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3958 int flags) /* EW_* flags */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3959 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3960 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3961 garray_T ga;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3962 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3963 static int recursive = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3964 int add_pat;
7036
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
3965 int retval = OK;
2568
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
3966 #if defined(FEAT_SEARCHPATH)
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
3967 int did_expand_in_path = FALSE;
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
3968 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3969
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3970 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3971 * expand_env() is called to expand things like "~user". If this fails,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3972 * it calls ExpandOne(), which brings us back here. In this case, always
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3973 * call the machine specific expansion function, if possible. Otherwise,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3974 * return FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3975 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3976 if (recursive)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3977 #ifdef SPECIAL_WILDCHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3978 return mch_expand_wildcards(num_pat, pat, num_file, file, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3979 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3980 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3981 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3982
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3983 #ifdef SPECIAL_WILDCHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3984 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3985 * If there are any special wildcard characters which we cannot handle
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3986 * here, call machine specific function for all the expansion. This
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3987 * avoids starting the shell for each argument separately.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3988 * For `=expr` do use the internal function.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3989 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3990 for (i = 0; i < num_pat; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3991 {
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
3992 if (has_special_wildchar(pat[i])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3993 # ifdef VIM_BACKTICK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3994 && !(vim_backtick(pat[i]) && pat[i][1] == '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3995 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3996 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3997 return mch_expand_wildcards(num_pat, pat, num_file, file, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3998 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3999 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4001 recursive = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4002
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4003 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4004 * The matching file names are stored in a growarray. Init it empty.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4005 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4006 ga_init2(&ga, (int)sizeof(char_u *), 30);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4007
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4008 for (i = 0; i < num_pat; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4009 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4010 add_pat = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4011 p = pat[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4012
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4013 #ifdef VIM_BACKTICK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4014 if (vim_backtick(p))
7036
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
4015 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4016 add_pat = expand_backtick(&ga, p, flags);
7036
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
4017 if (add_pat == -1)
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
4018 retval = FAIL;
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
4019 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4020 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4021 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4022 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4023 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4024 * First expand environment variables, "~/" and "~user/".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4025 */
16738
b52ea9c5f1db patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
4026 if ((has_env_var(p) && !(flags & EW_NOTENV)) || *p == '~')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4027 {
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
4028 p = expand_env_save_opt(p, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4029 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4030 p = pat[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4031 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4032 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4033 * On Unix, if expand_env() can't expand an environment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4034 * variable, use the shell to do that. Discard previously
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4035 * found file names and start all over again.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4036 */
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
4037 else if (has_env_var(p) || *p == '~')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4038 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4039 vim_free(p);
1914
28641f0ed9de updated for version 7.2-211
vimboss
parents: 1883
diff changeset
4040 ga_clear_strings(&ga);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4041 i = mch_expand_wildcards(num_pat, pat, num_file, file,
6174
96a4fa8e530c updated for version 7.4.423
Bram Moolenaar <bram@vim.org>
parents: 6114
diff changeset
4042 flags|EW_KEEPDOLLAR);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4043 recursive = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4044 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4045 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4046 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4047 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4048
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4049 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4050 * If there are wildcards: Expand file names and add each match to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4051 * the list. If there is no match, and EW_NOTFOUND is given, add
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4052 * the pattern.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4053 * If there are no wildcards: Add the file name if it exists or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4054 * when EW_NOTFOUND is given.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4055 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4056 if (mch_has_exp_wildcard(p))
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
4057 {
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
4058 #if defined(FEAT_SEARCHPATH)
2568
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
4059 if ((flags & EW_PATH)
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
4060 && !mch_isFullName(p)
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
4061 && !(p[0] == '.'
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
4062 && (vim_ispathsep(p[1])
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
4063 || (p[1] == '.' && vim_ispathsep(p[2]))))
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
4064 )
2487
7ec9ada2cd81 Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents: 2481
diff changeset
4065 {
2568
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
4066 /* :find completion where 'path' is used.
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
4067 * Recursiveness is OK here. */
2487
7ec9ada2cd81 Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents: 2481
diff changeset
4068 recursive = FALSE;
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
4069 add_pat = expand_in_path(&ga, p, flags);
2487
7ec9ada2cd81 Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents: 2481
diff changeset
4070 recursive = TRUE;
2568
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
4071 did_expand_in_path = TRUE;
2487
7ec9ada2cd81 Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents: 2481
diff changeset
4072 }
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
4073 else
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
4074 #endif
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
4075 add_pat = mch_expandpath(&ga, p, flags);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
4076 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4077 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4078
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4079 if (add_pat == -1 || (add_pat == 0 && (flags & EW_NOTFOUND)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4080 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4081 char_u *t = backslash_halve_save(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4082
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4083 /* When EW_NOTFOUND is used, always add files and dirs. Makes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4084 * "vim c:/" work. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4085 if (flags & EW_NOTFOUND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4086 addfile(&ga, t, flags | EW_DIR | EW_FILE);
9420
9f78f3f0c81f commit https://github.com/vim/vim/commit/00efded1064427ab3f84e4d57af62e0aab876fc6
Christian Brabandt <cb@256bit.org>
parents: 9389
diff changeset
4087 else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4088 addfile(&ga, t, flags);
17801
6582dda76821 patch 8.1.1897: may free memory twice when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
4089
6582dda76821 patch 8.1.1897: may free memory twice when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
4090 if (t != p)
6582dda76821 patch 8.1.1897: may free memory twice when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
4091 vim_free(t);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4092 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4093
2313
e382b66b936d Fix using freed memory in :find completion.
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
4094 #if defined(FEAT_SEARCHPATH)
2568
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
4095 if (did_expand_in_path && ga.ga_len > 0 && (flags & EW_PATH))
2313
e382b66b936d Fix using freed memory in :find completion.
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
4096 uniquefy_paths(&ga, p);
e382b66b936d Fix using freed memory in :find completion.
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
4097 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4098 if (p != pat[i])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4099 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4100 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4101
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4102 *num_file = ga.ga_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4103 *file = (ga.ga_data != NULL) ? (char_u **)ga.ga_data : (char_u **)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4104
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4105 recursive = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4106
7641
b44fc33ef92a commit https://github.com/vim/vim/commit/336bd622c31e1805495c034e1a8cfadcc0bbabc7
Christian Brabandt <cb@256bit.org>
parents: 7635
diff changeset
4107 return ((flags & EW_EMPTYOK) || ga.ga_data != NULL) ? retval : FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4108 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4110 # ifdef VIM_BACKTICK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4112 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4113 * Return TRUE if we can expand this backtick thing here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4114 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4115 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4116 vim_backtick(char_u *p)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4117 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4118 return (*p == '`' && *(p + 1) != NUL && *(p + STRLEN(p) - 1) == '`');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4119 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4121 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4122 * Expand an item in `backticks` by executing it as a command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4123 * Currently only works when pat[] starts and ends with a `.
7036
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
4124 * Returns number of file names found, -1 if an error is encountered.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4125 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4126 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4127 expand_backtick(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4128 garray_T *gap,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4129 char_u *pat,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4130 int flags) /* EW_* flags */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4131 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4132 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4133 char_u *cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4134 char_u *buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4135 int cnt = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4136 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4137
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4138 /* Create the command: lop off the backticks. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4139 cmd = vim_strnsave(pat + 1, (int)STRLEN(pat) - 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4140 if (cmd == NULL)
7036
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
4141 return -1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4142
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4143 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4144 if (*cmd == '=') /* `={expr}`: Expand expression */
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 694
diff changeset
4145 buffer = eval_to_string(cmd + 1, &p, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4146 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4147 #endif
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 22
diff changeset
4148 buffer = get_cmd_output(cmd, NULL,
5808
e5f1f2ea0b4a updated for version 7.4.248
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
4149 (flags & EW_SILENT) ? SHELL_SILENT : 0, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4150 vim_free(cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4151 if (buffer == NULL)
7036
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
4152 return -1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4154 cmd = buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4155 while (*cmd != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4156 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4157 cmd = skipwhite(cmd); /* skip over white space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4158 p = cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4159 while (*p != NUL && *p != '\r' && *p != '\n') /* skip over entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4160 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4161 /* add an entry if it is not empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4162 if (p > cmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4163 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4164 i = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4165 *p = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4166 addfile(gap, cmd, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4167 *p = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4168 ++cnt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4169 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4170 cmd = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4171 while (*cmd != NUL && (*cmd == '\r' || *cmd == '\n'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4172 ++cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4173 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4175 vim_free(buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4176 return cnt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4177 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4178 # endif /* VIM_BACKTICK */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4179
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4180 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4181 * Add a file to a file list. Accepted flags:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4182 * EW_DIR add directories
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4183 * EW_FILE add files
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
4184 * EW_EXEC add executable files
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4185 * EW_NOTFOUND add even when it doesn't exist
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4186 * EW_ADDSLASH add slash after directory name
6663
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
4187 * EW_ALLLINKS add symlink also when the referred file does not exist
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4188 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4189 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4190 addfile(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4191 garray_T *gap,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4192 char_u *f, /* filename */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4193 int flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4194 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4195 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4196 int isdir;
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9225
diff changeset
4197 stat_T sb;
6663
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
4198
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
4199 /* if the file/dir/link doesn't exist, may not add it */
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
4200 if (!(flags & EW_NOTFOUND) && ((flags & EW_ALLLINKS)
6665
9fda0c52db0b updated for version 7.4.657
Bram Moolenaar <bram@vim.org>
parents: 6663
diff changeset
4201 ? mch_lstat((char *)f, &sb) < 0 : mch_getperm(f) < 0))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4202 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4203
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4204 #ifdef FNAME_ILLEGAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4205 /* if the file/dir contains illegal characters, don't add it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4206 if (vim_strpbrk(f, (char_u *)FNAME_ILLEGAL) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4207 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4208 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4209
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4210 isdir = mch_isdir(f);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4211 if ((isdir && !(flags & EW_DIR)) || (!isdir && !(flags & EW_FILE)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4212 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4213
6695
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 6691
diff changeset
4214 /* If the file isn't executable, may not add it. Do accept directories.
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 6691
diff changeset
4215 * When invoked from expand_shellcmd() do not use $PATH. */
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 6691
diff changeset
4216 if (!isdir && (flags & EW_EXEC)
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 6691
diff changeset
4217 && !mch_can_exe(f, NULL, !(flags & EW_SHELLCMD)))
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
4218 return;
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
4219
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4220 /* Make room for another item in the file list. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4221 if (ga_grow(gap, 1) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4222 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4223
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16738
diff changeset
4224 p = alloc(STRLEN(f) + 1 + isdir);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4225 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4226 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4227
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4228 STRCPY(p, f);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4229 #ifdef BACKSLASH_IN_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4230 slash_adjust(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4231 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4232 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4233 * Append a slash or backslash after directory names if none is present.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4234 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4235 #ifndef DONT_ADD_PATHSEP_TO_DIR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4236 if (isdir && (flags & EW_ADDSLASH))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4237 add_pathsep(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4238 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4239 ((char_u **)gap->ga_data)[gap->ga_len++] = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4240 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4241 #endif /* !NO_EXPANDPATH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4242
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
4243 #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
4244 || (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
4245 || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4246
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4247 #ifndef SEEK_SET
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4248 # define SEEK_SET 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4249 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4250 #ifndef SEEK_END
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4251 # define SEEK_END 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4252 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4254 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4255 * Get the stdout of an external command.
5808
e5f1f2ea0b4a updated for version 7.4.248
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
4256 * 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
4257 * NULL store the length there.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4258 * Returns an allocated string, or NULL for error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4259 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4260 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4261 get_cmd_output(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4262 char_u *cmd,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4263 char_u *infile, /* optional input file name */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4264 int flags, /* can be SHELL_SILENT */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4265 int *ret_len)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4266 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4267 char_u *tempname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4268 char_u *command;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4269 char_u *buffer = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4270 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4271 int i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4272 FILE *fd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4273
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4274 if (check_restricted() || check_secure())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4275 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4276
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4277 /* get a name for the temp file */
6721
7347229a646a updated for version 7.4.684
Bram Moolenaar <bram@vim.org>
parents: 6695
diff changeset
4278 if ((tempname = vim_tempname('o', FALSE)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4279 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15420
diff changeset
4280 emsg(_(e_notmp));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4281 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4282 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4283
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4284 /* Add the redirection stuff */
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 22
diff changeset
4285 command = make_filter_cmd(cmd, infile, tempname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4286 if (command == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4287 goto done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4288
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4289 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4290 * Call the shell to execute the command (errors are ignored).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4291 * Don't check timestamps here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4292 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4293 ++no_check_timestamps;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4294 call_shell(command, SHELL_DOOUT | SHELL_EXPAND | flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4295 --no_check_timestamps;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4296
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4297 vim_free(command);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4298
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4299 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4300 * read the names from the file into memory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4301 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4302 # ifdef VMS
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
4303 /* created temporary file is not always readable as binary */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4304 fd = mch_fopen((char *)tempname, "r");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4305 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4306 fd = mch_fopen((char *)tempname, READBIN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4307 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4308
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4309 if (fd == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4310 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15420
diff changeset
4311 semsg(_(e_notopen), tempname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4312 goto done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4313 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4315 fseek(fd, 0L, SEEK_END);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4316 len = ftell(fd); /* get size of temp file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4317 fseek(fd, 0L, SEEK_SET);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4318
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4319 buffer = alloc(len + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4320 if (buffer != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4321 i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4322 fclose(fd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4323 mch_remove(tempname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4324 if (buffer == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4325 goto done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4326 #ifdef VMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4327 len = i; /* VMS doesn't give us what we asked for... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4328 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4329 if (i != len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4330 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15420
diff changeset
4331 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
4332 VIM_CLEAR(buffer);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4333 }
5808
e5f1f2ea0b4a updated for version 7.4.248
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
4334 else if (ret_len == NULL)
5271
25f67b62afd8 updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
4335 {
25f67b62afd8 updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
4336 /* Change NUL into SOH, otherwise the string is truncated. */
25f67b62afd8 updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
4337 for (i = 0; i < len; ++i)
5275
3ddec3d25bd1 updated for version 7.4b.014
Bram Moolenaar <bram@vim.org>
parents: 5271
diff changeset
4338 if (buffer[i] == NUL)
3ddec3d25bd1 updated for version 7.4b.014
Bram Moolenaar <bram@vim.org>
parents: 5271
diff changeset
4339 buffer[i] = 1;
5271
25f67b62afd8 updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
4340
2429
7ce8b24450dc Improvements for ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2409
diff changeset
4341 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
4342 }
5808
e5f1f2ea0b4a updated for version 7.4.248
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
4343 else
e5f1f2ea0b4a updated for version 7.4.248
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
4344 *ret_len = len;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4346 done:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4347 vim_free(tempname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4348 return buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4349 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4350 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4352 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4353 * Free the list of files returned by expand_wildcards() or other expansion
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4354 * functions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4355 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4356 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4357 FreeWild(int count, char_u **files)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4358 {
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
4359 if (count <= 0 || files == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4360 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4361 while (count--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4362 vim_free(files[count]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4363 vim_free(files);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4364 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4365
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4366 /*
2302
488be8cbe19c Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents: 2297
diff changeset
4367 * Return TRUE when need to go to Insert mode because of 'insertmode'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4368 * Don't do this when still processing a command or a mapping.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4369 * Don't do this when inside a ":normal" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4370 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4371 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4372 goto_im(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4373 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4374 return (p_im && stuff_empty() && typebuf_typed());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4375 }
5867
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4376
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4377 /*
5911
81f5a056b2a5 updated for version 7.4.297
Bram Moolenaar <bram@vim.org>
parents: 5885
diff changeset
4378 * 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
4379 * - 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
4380 * - Remove any argument. E.g., "csh -f" -> "csh".
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4381 * 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
4382 * "/usr/bin/csh --rcfile ~/.cshrc"
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4383 * But don't do that for Windows, it's common to have a space in the path.
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4384 */
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4385 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4386 get_isolated_shell_name(void)
5867
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4387 {
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4388 char_u *p;
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4389
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15814
diff changeset
4390 #ifdef MSWIN
5867
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4391 p = gettail(p_sh);
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4392 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4393 #else
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4394 p = skiptowhite(p_sh);
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4395 if (*p == NUL)
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4396 {
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4397 /* No white space, use the tail. */
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4398 p = vim_strsave(gettail(p_sh));
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4399 }
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4400 else
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4401 {
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4402 char_u *p1, *p2;
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4403
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4404 /* Find the last path separator before the space. */
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4405 p1 = p_sh;
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
4406 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
4407 if (vim_ispathsep(*p2))
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4408 p1 = p2 + 1;
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4409 p = vim_strnsave(p1, (int)(p - p1));
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4410 }
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4411 #endif
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4412 return p;
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
4413 }
15814
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4414
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4415 /*
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4416 * 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
4417 * 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
4418 * URL_BACKSLASH.
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4419 */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4420 int
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4421 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
4422 {
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4423 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
4424 return URL_SLASH;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4425 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
4426 return URL_BACKSLASH;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4427 return 0;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4428 }
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4429
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4430 /*
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4431 * Check if "fname" starts with "name://". Return URL_SLASH if it does.
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4432 * Return URL_BACKSLASH for "name:\\".
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4433 * Return zero otherwise.
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4434 */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4435 int
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4436 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
4437 {
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4438 char_u *p;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4439
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4440 for (p = fname; isalpha(*p); ++p)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4441 ;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4442 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
4443 }
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4444
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4445 /*
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4446 * Return TRUE if "name" is a full (absolute) path name or URL.
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4447 */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4448 int
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4449 vim_isAbsName(char_u *name)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4450 {
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4451 return (path_with_url(name) != 0 || mch_isFullName(name));
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4452 }
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4453
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4454 /*
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4455 * Get absolute file name into buffer "buf[len]".
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4456 *
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4457 * return FAIL for failure, OK otherwise
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4458 */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4459 int
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4460 vim_FullName(
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4461 char_u *fname,
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4462 char_u *buf,
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4463 int len,
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4464 int force) /* force expansion even when already absolute */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4465 {
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4466 int retval = OK;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4467 int url;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4468
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4469 *buf = NUL;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4470 if (fname == NULL)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4471 return FAIL;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4472
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4473 url = path_with_url(fname);
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4474 if (!url)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4475 retval = mch_FullName(fname, buf, len, force);
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4476 if (url || retval == FAIL)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4477 {
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4478 /* something failed; use the file name (truncate when too long) */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4479 vim_strncpy(buf, fname, len - 1);
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4480 }
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4481 #if defined(MSWIN)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4482 slash_adjust(buf);
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4483 #endif
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4484 return retval;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4485 }